├── .gitattributes ├── .github └── workflows │ └── build.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── libs └── touhoulittlemaid-1.21.1-release-1.2.2.jar ├── settings.gradle └── src └── main ├── java └── com │ └── github │ └── argon4w │ └── acceleratedrendering │ ├── AcceleratedRenderingModEntry.java │ ├── compat │ ├── AbstractCompatMixinPlugin.java │ └── iris │ │ ├── IAcceleratedUnwrap.java │ │ ├── IShadowBufferSourceGetter.java │ │ ├── IrisCompatBuffers.java │ │ ├── IrisCompatFeature.java │ │ ├── IrisRenderType.java │ │ ├── environments │ │ └── IrisBufferEnvironment.java │ │ ├── mixins │ │ ├── acceleratedrendering │ │ │ ├── AcceleratedBufferSourceMixin.java │ │ │ ├── AcceleratedRenderingModEntryMixin.java │ │ │ ├── IBufferEnvironmentPresetsMixin.java │ │ │ ├── RedirectingBufferSourceMixin.java │ │ │ └── RenderTypeUtilsMixin.java │ │ ├── iris │ │ │ ├── IrisVertexFormatsMixin.java │ │ │ ├── ModelToEntityVertexSerializerMixin.java │ │ │ ├── ShadowRendererMixin.java │ │ │ └── WrappableRenderTypeMixin.java │ │ ├── plugin │ │ │ └── IrisCompatMixinPlugin.java │ │ └── vanilla │ │ │ ├── LevelRendererMixin.java │ │ │ └── RenderTypeMixin.java │ │ └── programs │ │ ├── IrisPrograms.java │ │ ├── culling │ │ ├── IrisCullingProgramDispatcher.java │ │ └── IrisCullingProgramSelector.java │ │ └── processing │ │ ├── IrisExtraVertexData.java │ │ └── IrisPolygonProcessor.java │ ├── configs │ ├── FeatureConfig.java │ ├── FeatureStatus.java │ └── PipelineSetting.java │ ├── core │ ├── CoreBuffers.java │ ├── CoreFeature.java │ ├── backends │ │ ├── DebugOutput.java │ │ ├── Sync.java │ │ ├── VertexArray.java │ │ ├── buffers │ │ │ ├── IClientBuffer.java │ │ │ ├── IServerBuffer.java │ │ │ ├── ImmutableBuffer.java │ │ │ ├── MappedBuffer.java │ │ │ ├── MutableBuffer.java │ │ │ └── SegmentBuffer.java │ │ └── programs │ │ │ ├── BarrierFlags.java │ │ │ ├── ComputeProgram.java │ │ │ ├── ComputeShader.java │ │ │ └── Uniform.java │ ├── buffers │ │ ├── RedirectingBufferSource.java │ │ ├── SimpleCrumblingBufferSource.java │ │ ├── SimpleOutlineBufferSource.java │ │ ├── accelerated │ │ │ ├── AcceleratedBufferSetPool.java │ │ │ ├── AcceleratedBufferSource.java │ │ │ ├── IAcceleratedBufferSource.java │ │ │ ├── builders │ │ │ │ ├── AcceleratedBufferBuilder.java │ │ │ │ ├── AcceleratedEntityOutlineGenerator.java │ │ │ │ ├── AcceleratedSheetedDecalTextureGenerator.java │ │ │ │ ├── AcceleratedSpriteCoordinateExpander.java │ │ │ │ └── IAcceleratedVertexConsumer.java │ │ │ ├── pools │ │ │ │ ├── DrawContextPool.java │ │ │ │ ├── ElementBufferPool.java │ │ │ │ ├── MappedBufferPool.java │ │ │ │ └── VertexBufferPool.java │ │ │ └── renderers │ │ │ │ ├── DecoratedRenderer.java │ │ │ │ ├── IAcceleratedRenderer.java │ │ │ │ ├── IBufferDecorator.java │ │ │ │ └── SheetedDecalTextureRenderer.java │ │ ├── environments │ │ │ ├── IBufferEnvironment.java │ │ │ └── VanillaBufferEnvironment.java │ │ └── graphs │ │ │ ├── BlankBufferGraph.java │ │ │ ├── DecalBufferGraph.java │ │ │ ├── IBufferGraph.java │ │ │ ├── OutlineBufferGraph.java │ │ │ └── SpriteBufferGraph.java │ ├── meshes │ │ ├── ClientMesh.java │ │ ├── EmptyMesh.java │ │ ├── IMesh.java │ │ ├── MeshType.java │ │ ├── ServerMesh.java │ │ └── collectors │ │ │ ├── MeshCollector.java │ │ │ └── MeshCollectorCuller.java │ ├── mixins │ │ ├── EntityOutlineGeneratorMixin.java │ │ ├── LevelRendererMixin.java │ │ ├── MinecraftMixin.java │ │ ├── SheetedDecalTextureGeneratorMixin.java │ │ ├── SpriteCoordinateExpanderMixin.java │ │ ├── VertexConsumerMixin.java │ │ └── VertexDoubleConsumerMixin.java │ ├── programs │ │ ├── ComputeShaderProgramLoader.java │ │ ├── ComputeShaderPrograms.java │ │ ├── LoadComputeShaderEvent.java │ │ ├── culling │ │ │ ├── ICullingProgramSelector.java │ │ │ ├── LoadCullingProgramSelectorEvent.java │ │ │ ├── PassThroughCullingProgramDispatcher.java │ │ │ └── PassThroughCullingProgramSelector.java │ │ ├── dispatchers │ │ │ ├── EmptyProgramDispatcher.java │ │ │ ├── FixedPolygonProgramDispatcher.java │ │ │ ├── IPolygonProgramDispatcher.java │ │ │ └── TransformProgramDispatcher.java │ │ ├── extras │ │ │ ├── CompositeExtraVertex.java │ │ │ ├── EmptyExtraVertexData.java │ │ │ ├── FlagsExtraVertexData.java │ │ │ └── IExtraVertexData.java │ │ └── processing │ │ │ ├── EmptyPolygonProcessor.java │ │ │ ├── IPolygonProcessor.java │ │ │ └── LoadPolygonProcessorEvent.java │ └── utils │ │ ├── CullerUtils.java │ │ ├── DirectionUtils.java │ │ ├── IntLazyMap.java │ │ ├── LazyMap.java │ │ ├── MemUtils.java │ │ ├── MutableSize.java │ │ ├── RenderTypeUtils.java │ │ ├── ResourceLocationUtils.java │ │ ├── SimpleResetPool.java │ │ ├── TextureUtils.java │ │ ├── Vertex.java │ │ └── VertexFormatUtils.java │ └── features │ ├── blocks │ ├── AcceleratedBlockEntityRenderingFeature.java │ └── mixins │ │ ├── LevelRendererMixin.java │ │ ├── ShadowRendererMixin.java │ │ └── SodiumWorldRendererMixin.java │ ├── culling │ ├── OrientationCullingFeature.java │ ├── OrientationCullingProgramDispatcher.java │ ├── OrientationCullingProgramSelector.java │ └── OrientationCullingPrograms.java │ ├── entities │ ├── AcceleratedEntityRenderingFeature.java │ ├── AcceleratedEntityShadowRenderer.java │ └── mixins │ │ ├── EntityRenderDispatcherMixin.java │ │ ├── LevelRendererMixin.java │ │ └── ShadowRendererMixin.java │ ├── items │ ├── AcceleratedItemRenderContext.java │ ├── AcceleratedItemRenderingFeature.java │ ├── EmptyItemColor.java │ ├── IAcceleratedBakedModel.java │ ├── IAcceleratedBakedQuad.java │ └── mixins │ │ ├── BakedModelMixin.java │ │ ├── BakedQuadMixin.java │ │ ├── ItemColorsAccessor.java │ │ ├── ItemRendererMixin.java │ │ └── SimpleBakedModelMixin.java │ ├── modelparts │ └── mixins │ │ └── ModelPartMixin.java │ ├── text │ ├── AcceleratedBakedGlyphRenderer.java │ ├── AcceleratedTextRenderingFeature.java │ └── mixins │ │ └── BakedGlyphMixin.java │ └── touhoulittlemaid │ └── mixins │ ├── BedrockPartMixin.java │ ├── GeoBoneMixin.java │ └── IGeoRendererMixin.java └── resources ├── META-INF ├── accesstransformer.cfg └── neoforge.mods.toml ├── acceleratedrendering.compat.iris.mixins.json ├── acceleratedrendering.core.mixins.json ├── acceleratedrendering.feature.blocks.mixins.json ├── acceleratedrendering.feature.entities.mixins.json ├── acceleratedrendering.feature.items.mixins.json ├── acceleratedrendering.feature.modelparts.mixins.json ├── acceleratedrendering.feature.text.mixins.json ├── acceleratedrendering.feature.touhoulittlemaid.mixins.json └── assets └── acceleratedrendering ├── lang ├── en_us.json └── zh_cn.json └── shaders ├── compat ├── culling │ ├── iris_block_quad_culling_shader.compute │ ├── iris_block_triangle_culling_shader.compute │ ├── iris_entity_quad_culling_shader.compute │ └── iris_entity_triangle_culling_shader.compute ├── processing │ ├── iris_block_quad_processing_shader.compute │ ├── iris_block_triangle_processing_shader.compute │ ├── iris_entity_quad_processing_shader.compute │ ├── iris_entity_triangle_processing_shader.compute │ ├── iris_glyph_quad_processing_shader.compute │ └── iris_glyph_triangle_processing_shader.compute └── transform │ ├── iris_block_vertex_transform_shader.compute │ ├── iris_entity_vertex_transform_shader.compute │ └── iris_glyph_vertex_transform_shader.compute └── core ├── culling ├── block_quad_culling_shader.compute ├── block_triangle_culling_shader.compute ├── entity_quad_culling_shader.compute ├── entity_triangle_culling_shader.compute ├── pass_through_quad_culling_shader.compute ├── pass_through_triangle_culling_shader.compute ├── pos_tex_color_quad_culling_shader.compute ├── pos_tex_color_triangle_culling_shader.compute ├── pos_tex_quad_culling_shader.compute └── pos_tex_triangle_culling_shader.compute └── transform ├── block_vertex_transform_shader.compute ├── entity_vertex_transform_shader.compute ├── pos_color_tex_light_vertex_transform_shader.compute ├── pos_tex_color_vertex_transform_shader.compute └── pos_tex_vertex_transform_shader.compute /.gitattributes: -------------------------------------------------------------------------------- 1 | # Disable autocrlf on generated files, they always generate with LF 2 | # Add any extra files or paths here to make git stop saying they 3 | # are changed when only line endings change. 4 | src/generated/**/.cache/cache text eol=lf 5 | src/generated/**/*.json text eol=lf 6 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: [push, pull_request, workflow_dispatch] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-22.04 8 | steps: 9 | - name: Checkout 10 | uses: actions/checkout@v4 11 | 12 | - name: Setup Java 21 13 | uses: actions/setup-java@v4 14 | with: 15 | distribution: 'temurin' 16 | java-version: 21 17 | 18 | - name: Get Short Identifier 19 | uses: benjlevesque/short-sha@v2.2 20 | id: short-sha 21 | 22 | - name: Build 23 | id: build 24 | run: | 25 | chmod +x ./gradlew 26 | ./gradlew build 27 | VERSION_IDENTIFIER=SNAPSHOT+${{ steps.short-sha.outputs.sha }} 28 | FILE_NAME="$(ls ./build/libs -1 | head -n 1)" 29 | NEW_NAME="${FILE_NAME%.jar}-${VERSION_IDENTIFIER}.jar" 30 | mv "./build/libs/$FILE_NAME" "./build/libs/$NEW_NAME" 31 | echo "artifact_name=$NEW_NAME" >> "$GITHUB_OUTPUT" 32 | echo "artifact_path=./build/libs/$NEW_NAME" >> "$GITHUB_OUTPUT" 33 | 34 | - name: GitHub Action Artifact 35 | uses: actions/upload-artifact@v4 36 | with: 37 | name: ${{ steps.build.outputs.artifact_name }} 38 | path: ${{ steps.build.outputs.artifact_path }} 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # eclipse 2 | bin 3 | *.launch 4 | .settings 5 | .metadata 6 | .classpath 7 | .project 8 | 9 | # idea 10 | out 11 | *.ipr 12 | *.iws 13 | *.iml 14 | .idea 15 | 16 | # gradle 17 | build 18 | .gradle 19 | 20 | # other 21 | eclipse 22 | run 23 | runs 24 | run-data 25 | 26 | repo -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Argon4W 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | Installation information 3 | ======= 4 | 5 | This template repository can be directly cloned to get you started with a new 6 | mod. Simply create a new repository cloned from this one, by following the 7 | instructions at [github](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template). 8 | 9 | Once you have your clone, simply open the repository in the IDE of your choice. The usual recommendation for an IDE is either IntelliJ IDEA or Eclipse. 10 | 11 | > **Note**: For Eclipse, use tasks in `Launch Group` instead of ones founds in `Java Application`. A preparation task must run before launching the game. NeoGradle uses launch groups to do these subsequently. 12 | 13 | If at any point you are missing libraries in your IDE, or you've run into problems you can 14 | run `gradlew --refresh-dependencies` to refresh the local cache. `gradlew clean` to reset everything 15 | {this does not affect your code} and then start the process again. 16 | 17 | Mapping Names: 18 | ============ 19 | By default, the MDK is configured to use the official mapping names from Mojang for methods and fields 20 | in the Minecraft codebase. These names are covered by a specific license. All modders should be aware of this 21 | license. For the latest license text, refer to the mapping file itself, or the reference copy here: 22 | https://github.com/NeoForged/NeoForm/blob/main/Mojang.md 23 | 24 | Additional Resources: 25 | ========== 26 | Community Documentation: https://docs.neoforged.net/ 27 | NeoForged Discord: https://discord.neoforged.net/ 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Sets default memory used for gradle commands. Can be overridden by user or command line properties. 2 | org.gradle.jvmargs=-Xmx1G 3 | org.gradle.daemon=false 4 | org.gradle.debug=false 5 | 6 | #read more on this at https://github.com/neoforged/NeoGradle/blob/NG_7.0/README.md#apply-parchment-mappings 7 | # you can also find the latest versions at: https://parchmentmc.org/docs/getting-started 8 | neogradle.subsystems.parchment.minecraftVersion=1.21.1 9 | neogradle.subsystems.parchment.mappingsVersion=2024.11.17 10 | # Environment Properties 11 | # You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge 12 | # The Minecraft version must agree with the Neo version to get a valid artifact 13 | minecraft_version=1.21.1 14 | # The Minecraft version range can use any release version of Minecraft as bounds. 15 | # Snapshots, pre-releases, and release candidates are not guaranteed to sort properly 16 | # as they do not follow standard versioning conventions. 17 | minecraft_version_range=[1.21,1.21.2) 18 | # The Neo version must agree with the Minecraft version to get a valid artifact 19 | neo_version=21.1.138 20 | # The Neo version range can use any version of Neo as bounds 21 | neo_version_range=[21.0.0,) 22 | # The loader version range can only use the major version of FML as bounds 23 | loader_version_range=[4,) 24 | 25 | ## Mod Properties 26 | 27 | # The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63} 28 | # Must match the String constant located in the main mod class annotated with @Mod. 29 | mod_id=acceleratedrendering 30 | # The human-readable display name for the mod. 31 | mod_name=Accelerated Rendering 32 | # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. 33 | mod_license=MIT 34 | # The mod version. See https://semver.org/ 35 | mod_version=1.0.0 36 | # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. 37 | # This should match the base package used for the mod sources. 38 | # See https://maven.apache.org/guides/mini/guide-naming-conventions.html 39 | mod_group_id=com.github.argon4w 40 | # The authors of the mod. This is a simple text string that is used for display purposes in the mod list. 41 | mod_authors=Argon4W 42 | # The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list. 43 | mod_description=Fast vertex transform and caching using compute shader. 44 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Argon4W/AcceleratedRendering/d5a308ca6a8cc780e85715f08bb6b122bae83854/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /libs/touhoulittlemaid-1.21.1-release-1.2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Argon4W/AcceleratedRendering/d5a308ca6a8cc780e85715f08bb6b122bae83854/libs/touhoulittlemaid-1.21.1-release-1.2.2.jar -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | mavenLocal() 4 | gradlePluginPortal() 5 | maven { url = 'https://maven.neoforged.net/releases' } 6 | } 7 | } 8 | 9 | plugins { 10 | id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/AcceleratedRenderingModEntry.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering; 2 | 3 | import com.github.argon4w.acceleratedrendering.configs.FeatureConfig; 4 | import com.mojang.logging.LogUtils; 5 | import net.neoforged.api.distmarker.Dist; 6 | import net.neoforged.bus.api.IEventBus; 7 | import net.neoforged.fml.ModContainer; 8 | import net.neoforged.fml.common.Mod; 9 | import net.neoforged.fml.config.ModConfig; 10 | import net.neoforged.neoforge.client.gui.ConfigurationScreen; 11 | import net.neoforged.neoforge.client.gui.IConfigScreenFactory; 12 | import org.slf4j.Logger; 13 | 14 | @Mod(value = AcceleratedRenderingModEntry.MOD_ID, dist = Dist.CLIENT) 15 | public class AcceleratedRenderingModEntry { 16 | 17 | public static final String MOD_ID = "acceleratedrendering"; 18 | public static final Logger LOGGER = LogUtils.getLogger(); 19 | 20 | public AcceleratedRenderingModEntry(IEventBus modEventBus, ModContainer modContainer) { 21 | modContainer.registerConfig(ModConfig.Type.CLIENT, FeatureConfig.SPEC); 22 | modContainer.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/AbstractCompatMixinPlugin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat; 2 | 3 | import net.neoforged.fml.loading.LoadingModList; 4 | import org.objectweb.asm.tree.ClassNode; 5 | import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; 6 | import org.spongepowered.asm.mixin.extensibility.IMixinInfo; 7 | 8 | import java.util.List; 9 | import java.util.Set; 10 | 11 | public abstract class AbstractCompatMixinPlugin implements IMixinConfigPlugin { 12 | 13 | protected abstract String getModID(); 14 | 15 | @Override 16 | public void onLoad(String mixinPackage) { 17 | 18 | } 19 | 20 | @Override 21 | public String getRefMapperConfig() { 22 | return null; 23 | } 24 | 25 | @Override 26 | public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { 27 | return LoadingModList.get().getModFileById(getModID()) != null; 28 | } 29 | 30 | @Override 31 | public void acceptTargets(Set myTargets, Set otherTargets) { 32 | 33 | } 34 | 35 | @Override 36 | public List getMixins() { 37 | return null; 38 | } 39 | 40 | @Override 41 | public void preApply( 42 | String targetClassName, 43 | ClassNode targetClass, 44 | String mixinClassName, 45 | IMixinInfo mixinInfo 46 | ) { 47 | 48 | } 49 | 50 | @Override 51 | public void postApply( 52 | String targetClassName, 53 | ClassNode targetClass, 54 | String mixinClassName, 55 | IMixinInfo mixinInfo 56 | ) { 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/IAcceleratedUnwrap.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris; 2 | 3 | import net.minecraft.client.renderer.RenderType; 4 | 5 | public interface IAcceleratedUnwrap { 6 | 7 | default RenderType unwrapFast() { 8 | return (RenderType) this; 9 | } 10 | 11 | default boolean isAccelerated() { 12 | return false; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/IShadowBufferSourceGetter.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris; 2 | 3 | import net.minecraft.client.renderer.MultiBufferSource; 4 | 5 | public interface IShadowBufferSourceGetter { 6 | 7 | MultiBufferSource.BufferSource getShadowBufferSource(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/IrisCompatBuffers.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.AcceleratedBufferSource; 4 | import com.github.argon4w.acceleratedrendering.core.buffers.environments.IBufferEnvironment; 5 | 6 | public class IrisCompatBuffers { 7 | 8 | public static final AcceleratedBufferSource BLOCK_SHADOW = new AcceleratedBufferSource(IBufferEnvironment.Presets.BLOCK); 9 | public static final AcceleratedBufferSource ENTITY_SHADOW = new AcceleratedBufferSource(IBufferEnvironment.Presets.ENTITY); 10 | public static final AcceleratedBufferSource GLYPH_SHADOW = new AcceleratedBufferSource(IBufferEnvironment.Presets.POS_COLOR_TEX_LIGHT); 11 | public static final AcceleratedBufferSource POS_TEX_SHADOW = new AcceleratedBufferSource(IBufferEnvironment.Presets.POS_TEX); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/IrisRenderType.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.utils.VertexFormatUtils; 4 | import com.google.common.base.Objects; 5 | import com.mojang.blaze3d.vertex.VertexFormat; 6 | import net.irisshaders.batchedentityrendering.impl.WrappableRenderType; 7 | import net.minecraft.client.renderer.RenderType; 8 | 9 | import java.util.Optional; 10 | 11 | public class IrisRenderType extends RenderType implements WrappableRenderType, IAcceleratedUnwrap { 12 | 13 | private final RenderType renderType; 14 | private final VertexFormat vertexFormat; 15 | private final int hashCode; 16 | 17 | public IrisRenderType(RenderType renderType, VertexFormat vertexFormat) { 18 | super( 19 | renderType.name, 20 | vertexFormat, 21 | renderType.mode, 22 | renderType.bufferSize, 23 | renderType.affectsCrumbling, 24 | renderType.sortOnUpload, 25 | renderType.setupState, 26 | renderType.clearState 27 | ); 28 | 29 | this.renderType = renderType; 30 | this.vertexFormat = vertexFormat; 31 | this.hashCode = Objects.hashCode(renderType, VertexFormatUtils.hashCodeFast(vertexFormat)); 32 | } 33 | 34 | @Override 35 | public Optional outline() { 36 | return renderType.outline(); 37 | } 38 | 39 | @Override 40 | public boolean isOutline() { 41 | return renderType.isOutline(); 42 | } 43 | 44 | @Override 45 | public RenderType unwrap() { 46 | return renderType; 47 | } 48 | 49 | @Override 50 | public RenderType unwrapFast() { 51 | return renderType; 52 | } 53 | 54 | @Override 55 | public boolean isAccelerated() { 56 | return true; 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | return hashCode; 62 | } 63 | 64 | @Override 65 | public boolean equals(Object o) { 66 | if (this == o) { 67 | return true; 68 | } 69 | 70 | if (o == null) { 71 | return false; 72 | } 73 | 74 | if (getClass() != o.getClass()) { 75 | return false; 76 | } 77 | 78 | IrisRenderType that = (IrisRenderType) o; 79 | 80 | return Objects.equal(renderType, that.renderType) 81 | && Objects.equal(vertexFormat, that.vertexFormat); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/mixins/acceleratedrendering/AcceleratedBufferSourceMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris.mixins.acceleratedrendering; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.AcceleratedBufferSource; 4 | import com.github.argon4w.acceleratedrendering.core.buffers.environments.IBufferEnvironment; 5 | import net.minecraft.client.renderer.RenderType; 6 | import org.spongepowered.asm.mixin.Final; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.Shadow; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.ModifyVariable; 11 | 12 | @Mixin(AcceleratedBufferSource.class) 13 | public abstract class AcceleratedBufferSourceMixin { 14 | 15 | @Shadow @Final private IBufferEnvironment bufferEnvironment; 16 | 17 | @ModifyVariable(method = "getBuffer", at = @At("HEAD"), ordinal = 0, argsOnly = true) 18 | public RenderType unwrapIrisRenderType(RenderType renderType) { 19 | return bufferEnvironment.getRenderType(renderType); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/mixins/acceleratedrendering/AcceleratedRenderingModEntryMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris.mixins.acceleratedrendering; 2 | 3 | import com.github.argon4w.acceleratedrendering.AcceleratedRenderingModEntry; 4 | import com.github.argon4w.acceleratedrendering.compat.iris.programs.IrisPrograms; 5 | import net.neoforged.bus.api.IEventBus; 6 | import net.neoforged.fml.ModContainer; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Inject; 10 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 11 | 12 | @Mixin(AcceleratedRenderingModEntry.class) 13 | public class AcceleratedRenderingModEntryMixin { 14 | 15 | @Inject(method = "", at = @At("TAIL")) 16 | public void registerIrisEvents( 17 | IEventBus modEventBus, 18 | ModContainer modContainer, 19 | CallbackInfo ci 20 | ) { 21 | modEventBus.register(IrisPrograms.class); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/mixins/acceleratedrendering/RedirectingBufferSourceMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris.mixins.acceleratedrendering; 2 | 3 | import com.github.argon4w.acceleratedrendering.compat.iris.IAcceleratedUnwrap; 4 | import com.github.argon4w.acceleratedrendering.compat.iris.IrisCompatFeature; 5 | import com.github.argon4w.acceleratedrendering.core.buffers.RedirectingBufferSource; 6 | import com.llamalad7.mixinextras.injector.wrapoperation.Operation; 7 | import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; 8 | import net.irisshaders.batchedentityrendering.impl.WrappableRenderType; 9 | import net.minecraft.client.renderer.RenderType; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | 13 | @Mixin(RedirectingBufferSource.class) 14 | public class RedirectingBufferSourceMixin { 15 | 16 | @WrapOperation(method = "getBuffer", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/RenderType;name:Ljava/lang/String;")) 17 | public String unwrapIrisRenderType(RenderType instance, Operation original) { 18 | IAcceleratedUnwrap fast = (IAcceleratedUnwrap) instance; 19 | 20 | if (IrisCompatFeature.isFastRenderTypeCheckEnabled()) { 21 | return original.call(fast.unwrapFast()); 22 | } 23 | 24 | if (instance instanceof WrappableRenderType wrapped) { 25 | return original.call(wrapped.unwrap()); 26 | } 27 | 28 | if (fast.isAccelerated()) { 29 | return original.call(fast.unwrapFast()); 30 | } 31 | 32 | return original.call(instance); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/mixins/acceleratedrendering/RenderTypeUtilsMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris.mixins.acceleratedrendering; 2 | 3 | import com.github.argon4w.acceleratedrendering.compat.iris.IAcceleratedUnwrap; 4 | import com.github.argon4w.acceleratedrendering.compat.iris.IrisCompatFeature; 5 | import com.github.argon4w.acceleratedrendering.core.utils.RenderTypeUtils; 6 | import net.irisshaders.batchedentityrendering.impl.WrappableRenderType; 7 | import net.minecraft.client.renderer.RenderType; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.ModifyVariable; 11 | 12 | @Mixin(RenderTypeUtils.class) 13 | public class RenderTypeUtilsMixin { 14 | 15 | @ModifyVariable(method = "getTextureLocation", at = @At("HEAD"), ordinal = 0, argsOnly = true) 16 | private static RenderType unwrapIrisRenderType1(RenderType renderType) { 17 | IAcceleratedUnwrap fast = (IAcceleratedUnwrap) renderType; 18 | 19 | if (IrisCompatFeature.isFastRenderTypeCheckEnabled()) { 20 | return fast.unwrapFast(); 21 | } 22 | 23 | if (renderType instanceof WrappableRenderType wrapped) { 24 | return wrapped.unwrap(); 25 | } 26 | 27 | if (fast.isAccelerated()) { 28 | return fast.unwrapFast(); 29 | } 30 | 31 | return renderType; 32 | } 33 | 34 | @ModifyVariable(method = "isCulled", at = @At("HEAD"), ordinal = 0, argsOnly = true) 35 | private static RenderType unwrapIrisRenderType2(RenderType renderType) { 36 | IAcceleratedUnwrap fast = (IAcceleratedUnwrap) renderType; 37 | 38 | if (IrisCompatFeature.isFastRenderTypeCheckEnabled()) { 39 | return fast.unwrapFast(); 40 | } 41 | 42 | if (renderType instanceof WrappableRenderType wrapped) { 43 | return wrapped.unwrap(); 44 | } 45 | 46 | if (fast.isAccelerated()) { 47 | return fast.unwrapFast(); 48 | } 49 | 50 | return renderType; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/mixins/iris/IrisVertexFormatsMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris.mixins.iris; 2 | 3 | import com.llamalad7.mixinextras.injector.wrapoperation.Operation; 4 | import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; 5 | import com.mojang.blaze3d.vertex.VertexFormat; 6 | import com.mojang.blaze3d.vertex.VertexFormatElement; 7 | import net.irisshaders.iris.vertices.IrisVertexFormats; 8 | import org.objectweb.asm.Opcodes; 9 | import org.spongepowered.asm.mixin.Final; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.Mutable; 12 | import org.spongepowered.asm.mixin.Shadow; 13 | import org.spongepowered.asm.mixin.injection.At; 14 | 15 | @Mixin(value = IrisVertexFormats.class, priority = Integer.MAX_VALUE) 16 | public class IrisVertexFormatsMixin { 17 | 18 | @Shadow @Final @Mutable public static VertexFormat ENTITY; 19 | @Shadow @Final @Mutable public static VertexFormat GLYPH; 20 | @Shadow @Final public static VertexFormatElement ENTITY_ID_ELEMENT; 21 | @Shadow @Final public static VertexFormatElement MID_TEXTURE_ELEMENT; 22 | @Shadow @Final public static VertexFormatElement TANGENT_ELEMENT; 23 | 24 | @WrapOperation(method = "", at = @At(value = "FIELD", target = "Lnet/irisshaders/iris/vertices/IrisVertexFormats;ENTITY:Lcom/mojang/blaze3d/vertex/VertexFormat;", opcode = Opcodes.PUTSTATIC)) 25 | private static void addPaddingForEntityFormat(VertexFormat value, Operation original) { 26 | original.call(VertexFormat 27 | .builder() 28 | .add("Position", VertexFormatElement.POSITION) 29 | .add("Color", VertexFormatElement.COLOR) 30 | .add("UV0", VertexFormatElement.UV0) 31 | .add("UV1", VertexFormatElement.UV1) 32 | .add("UV2", VertexFormatElement.UV2) 33 | .add("Normal", VertexFormatElement.NORMAL) 34 | .padding(1) 35 | .add("iris_Entity", ENTITY_ID_ELEMENT) 36 | .padding(2) 37 | .add("mc_midTexCoord", MID_TEXTURE_ELEMENT) 38 | .add("at_tangent", TANGENT_ELEMENT) 39 | .build() 40 | ); 41 | } 42 | 43 | @WrapOperation(method = "", at = @At(value = "FIELD", target = "Lnet/irisshaders/iris/vertices/IrisVertexFormats;GLYPH:Lcom/mojang/blaze3d/vertex/VertexFormat;", opcode = Opcodes.PUTSTATIC)) 44 | private static void addPaddingForGlyphFormat(VertexFormat value, Operation original) { 45 | original.call(VertexFormat 46 | .builder() 47 | .add("Position", VertexFormatElement.POSITION) 48 | .add("Color", VertexFormatElement.COLOR) 49 | .add("UV0", VertexFormatElement.UV0) 50 | .add("UV2", VertexFormatElement.UV2) 51 | .add("Normal", VertexFormatElement.NORMAL) 52 | .padding(1) 53 | .add("iris_Entity", ENTITY_ID_ELEMENT) 54 | .padding(2) 55 | .add("mc_midTexCoord", MID_TEXTURE_ELEMENT) 56 | .add("at_tangent", TANGENT_ELEMENT) 57 | .build()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/mixins/iris/ModelToEntityVertexSerializerMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris.mixins.iris; 2 | 3 | import net.irisshaders.iris.vertices.sodium.ModelToEntityVertexSerializer; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.injection.Constant; 6 | import org.spongepowered.asm.mixin.injection.ModifyConstant; 7 | 8 | @Mixin(ModelToEntityVertexSerializer.class) 9 | public class ModelToEntityVertexSerializerMixin { 10 | 11 | @ModifyConstant(method = "serialize", constant = @Constant(longValue = 42L)) 12 | public long redirectMidU(long constant) { 13 | return 44L; 14 | } 15 | 16 | @ModifyConstant(method = "serialize", constant = @Constant(longValue = 46L)) 17 | public long redirectMidV(long constant) { 18 | return 48L; 19 | } 20 | 21 | @ModifyConstant(method = "serialize", constant = @Constant(longValue = 50L)) 22 | public long redirectTangent(long constant) { 23 | return 52L; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/mixins/iris/ShadowRendererMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris.mixins.iris; 2 | 3 | import com.github.argon4w.acceleratedrendering.compat.iris.IShadowBufferSourceGetter; 4 | import com.github.argon4w.acceleratedrendering.compat.iris.IrisCompatBuffers; 5 | import com.github.argon4w.acceleratedrendering.core.buffers.RedirectingBufferSource; 6 | import com.google.common.base.Suppliers; 7 | import com.mojang.blaze3d.vertex.VertexFormat; 8 | import net.irisshaders.iris.mixin.LevelRendererAccessor; 9 | import net.irisshaders.iris.shadows.ShadowRenderer; 10 | import net.minecraft.client.Camera; 11 | import net.minecraft.client.renderer.MultiBufferSource; 12 | import net.minecraft.client.renderer.RenderBuffers; 13 | import org.spongepowered.asm.mixin.Final; 14 | import org.spongepowered.asm.mixin.Mixin; 15 | import org.spongepowered.asm.mixin.Shadow; 16 | import org.spongepowered.asm.mixin.Unique; 17 | import org.spongepowered.asm.mixin.injection.At; 18 | import org.spongepowered.asm.mixin.injection.Inject; 19 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 20 | 21 | import java.util.function.Supplier; 22 | 23 | @Mixin(ShadowRenderer.class) 24 | public class ShadowRendererMixin implements IShadowBufferSourceGetter { 25 | 26 | @Shadow @Final private RenderBuffers buffers; 27 | 28 | @Unique 29 | private final Supplier SHADOW = Suppliers.memoize(() -> RedirectingBufferSource.builder() 30 | .fallback(buffers.bufferSource()) 31 | .bufferSource(IrisCompatBuffers.BLOCK_SHADOW) 32 | .bufferSource(IrisCompatBuffers.ENTITY_SHADOW) 33 | .bufferSource(IrisCompatBuffers.GLYPH_SHADOW) 34 | .bufferSource(IrisCompatBuffers.POS_TEX_SHADOW) 35 | .mode(VertexFormat.Mode.QUADS) 36 | .mode(VertexFormat.Mode.TRIANGLES) 37 | .fallbackName("breeze_wind") 38 | .fallbackName("energy_swirl") 39 | .build()); 40 | 41 | @Inject(method = "renderShadows", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch()V")) 42 | public void endAllBatches( 43 | LevelRendererAccessor levelRenderer, 44 | Camera playerCamera, 45 | CallbackInfo ci 46 | ) { 47 | IrisCompatBuffers.BLOCK_SHADOW.drawBuffers(); 48 | IrisCompatBuffers.ENTITY_SHADOW.drawBuffers(); 49 | IrisCompatBuffers.GLYPH_SHADOW.drawBuffers(); 50 | IrisCompatBuffers.POS_TEX_SHADOW.drawBuffers(); 51 | 52 | IrisCompatBuffers.BLOCK_SHADOW.clearBuffers(); 53 | IrisCompatBuffers.ENTITY_SHADOW.clearBuffers(); 54 | IrisCompatBuffers.POS_TEX_SHADOW.clearBuffers(); 55 | IrisCompatBuffers.GLYPH_SHADOW.clearBuffers(); 56 | } 57 | 58 | @Unique 59 | @Override 60 | public MultiBufferSource.BufferSource getShadowBufferSource() { 61 | return SHADOW.get(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/mixins/iris/WrappableRenderTypeMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris.mixins.iris; 2 | 3 | import com.github.argon4w.acceleratedrendering.compat.iris.IAcceleratedUnwrap; 4 | import net.irisshaders.batchedentityrendering.impl.WrappableRenderType; 5 | import net.minecraft.client.renderer.RenderType; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.Shadow; 8 | import org.spongepowered.asm.mixin.Unique; 9 | 10 | @Mixin(WrappableRenderType.class) 11 | public interface WrappableRenderTypeMixin extends IAcceleratedUnwrap { 12 | 13 | @Shadow RenderType unwrap(); 14 | 15 | @Unique 16 | @Override 17 | default RenderType unwrapFast() { 18 | return unwrap(); 19 | } 20 | 21 | @Unique 22 | @Override 23 | default boolean isAccelerated() { 24 | return true; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/mixins/plugin/IrisCompatMixinPlugin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris.mixins.plugin; 2 | 3 | import com.github.argon4w.acceleratedrendering.compat.AbstractCompatMixinPlugin; 4 | 5 | public class IrisCompatMixinPlugin extends AbstractCompatMixinPlugin { 6 | 7 | @Override 8 | protected String getModID() { 9 | return "iris"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/mixins/vanilla/LevelRendererMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris.mixins.vanilla; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.CoreBuffers; 4 | import com.llamalad7.mixinextras.injector.wrapoperation.Operation; 5 | import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; 6 | import net.minecraft.client.Camera; 7 | import net.minecraft.client.DeltaTracker; 8 | import net.minecraft.client.renderer.GameRenderer; 9 | import net.minecraft.client.renderer.LevelRenderer; 10 | import net.minecraft.client.renderer.LightTexture; 11 | import net.minecraft.client.renderer.MultiBufferSource; 12 | import org.joml.Matrix4f; 13 | import org.spongepowered.asm.mixin.Mixin; 14 | import org.spongepowered.asm.mixin.injection.At; 15 | import org.spongepowered.asm.mixin.injection.Inject; 16 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 17 | 18 | @Mixin(value = LevelRenderer.class, priority = 999) 19 | public class LevelRendererMixin { 20 | 21 | @Inject(method = "renderLevel", at = @At(value = "CONSTANT", args = "stringValue=translucent")) 22 | public void drawIrisCoreBuffers( 23 | DeltaTracker pDeltaTracker, 24 | boolean pRenderBlockOutline, 25 | Camera pCamera, 26 | GameRenderer pGameRenderer, 27 | LightTexture pLightTexture, 28 | Matrix4f pFrustumMatrix, 29 | Matrix4f pProjectionMatrix, 30 | CallbackInfo ci 31 | ) { 32 | CoreBuffers.ENTITY.drawBuffers(); 33 | CoreBuffers.BLOCK.drawBuffers(); 34 | CoreBuffers.POS_TEX.drawBuffers(); 35 | CoreBuffers.POS_COLOR_TEX_LIGHT.drawBuffers(); 36 | 37 | CoreBuffers.ENTITY.clearBuffers(); 38 | CoreBuffers.BLOCK.clearBuffers(); 39 | CoreBuffers.POS_TEX.clearBuffers(); 40 | CoreBuffers.POS_COLOR_TEX_LIGHT.clearBuffers(); 41 | } 42 | 43 | @WrapOperation(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endLastBatch()V")) 44 | public void preventDrawCoreBuffers(MultiBufferSource.BufferSource instance, Operation original) { 45 | instance.endLastBatch(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/mixins/vanilla/RenderTypeMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris.mixins.vanilla; 2 | 3 | import com.github.argon4w.acceleratedrendering.compat.iris.IAcceleratedUnwrap; 4 | import net.minecraft.client.renderer.RenderType; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | 7 | @Mixin(RenderType.class) 8 | public class RenderTypeMixin implements IAcceleratedUnwrap { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/programs/culling/IrisCullingProgramDispatcher.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris.programs.culling; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.backends.programs.ComputeProgram; 4 | import com.github.argon4w.acceleratedrendering.core.backends.programs.Uniform; 5 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.AcceleratedBufferBuilder; 6 | import com.github.argon4w.acceleratedrendering.core.programs.ComputeShaderProgramLoader; 7 | import com.github.argon4w.acceleratedrendering.core.programs.dispatchers.IPolygonProgramDispatcher; 8 | import com.mojang.blaze3d.systems.RenderSystem; 9 | import com.mojang.blaze3d.vertex.VertexFormat; 10 | import net.irisshaders.iris.shadows.ShadowRenderer; 11 | import net.irisshaders.iris.shadows.ShadowRenderingState; 12 | import net.minecraft.resources.ResourceLocation; 13 | 14 | public class IrisCullingProgramDispatcher implements IPolygonProgramDispatcher { 15 | 16 | private static final int GROUP_SIZE = 128; 17 | 18 | private final VertexFormat.Mode mode; 19 | private final ComputeProgram program; 20 | private final Uniform viewMatrixUniform; 21 | private final Uniform projectMatrixUniform; 22 | private final Uniform polygonCountUniform; 23 | private final Uniform vertexOffsetUniform; 24 | 25 | public IrisCullingProgramDispatcher(VertexFormat.Mode mode, ResourceLocation key) { 26 | this.mode = mode; 27 | this.program = ComputeShaderProgramLoader.getProgram(key); 28 | this.viewMatrixUniform = program.getUniform("viewMatrix"); 29 | this.projectMatrixUniform = this.program.getUniform("projectMatrix"); 30 | this.polygonCountUniform = program.getUniform("polygonCount"); 31 | this.vertexOffsetUniform = program.getUniform("vertexOffset"); 32 | } 33 | 34 | @Override 35 | public int dispatch(AcceleratedBufferBuilder builder) { 36 | int vertexCount = builder.getVertexCount(); 37 | int vertexOffset = builder.getVertexOffset(); 38 | int polygonCount = vertexCount / mode.primitiveLength; 39 | 40 | viewMatrixUniform.uploadMatrix4f(ShadowRenderingState.areShadowsCurrentlyBeingRendered() ? ShadowRenderer.MODELVIEW : RenderSystem.getModelViewMatrix()); 41 | projectMatrixUniform.uploadMatrix4f(ShadowRenderingState.areShadowsCurrentlyBeingRendered() ? ShadowRenderer.PROJECTION : RenderSystem.getProjectionMatrix()); 42 | polygonCountUniform.uploadUnsignedInt(polygonCount); 43 | vertexOffsetUniform.uploadUnsignedInt(vertexOffset); 44 | 45 | program.useProgram(); 46 | program.dispatch((polygonCount + GROUP_SIZE - 1) / GROUP_SIZE); 47 | program.resetProgram(); 48 | 49 | return program.getBarrierFlags(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/programs/processing/IrisExtraVertexData.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris.programs.processing; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.programs.extras.IExtraVertexData; 4 | import com.mojang.blaze3d.vertex.VertexFormat; 5 | import net.irisshaders.iris.uniforms.CapturedRenderingState; 6 | import net.irisshaders.iris.vertices.IrisVertexFormats; 7 | import org.lwjgl.system.MemoryUtil; 8 | 9 | public class IrisExtraVertexData implements IExtraVertexData { 10 | 11 | private final int entityOffset; 12 | private final int entityIdOffset; 13 | 14 | public IrisExtraVertexData(VertexFormat vertexFormat) { 15 | this.entityOffset = vertexFormat.getOffset(IrisVertexFormats.ENTITY_ELEMENT); 16 | this.entityIdOffset = vertexFormat.getOffset(IrisVertexFormats.ENTITY_ID_ELEMENT); 17 | } 18 | 19 | @Override 20 | public void addExtraVertex(long address) { 21 | if (entityOffset != -1) { 22 | MemoryUtil.memPutShort(address + entityOffset + 0L, (short) -1); 23 | MemoryUtil.memPutShort(address + entityOffset + 2L, (short) -1); 24 | } 25 | 26 | if (entityIdOffset != -1) { 27 | MemoryUtil.memPutShort(address + entityIdOffset + 0L, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedEntity()); 28 | MemoryUtil.memPutShort(address + entityIdOffset + 2L, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity()); 29 | MemoryUtil.memPutShort(address + entityIdOffset + 4L, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedItem()); 30 | } 31 | } 32 | 33 | @Override 34 | public void addExtraVarying(long address) { 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/compat/iris/programs/processing/IrisPolygonProcessor.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.compat.iris.programs.processing; 2 | 3 | import com.github.argon4w.acceleratedrendering.compat.iris.IrisCompatFeature; 4 | import com.github.argon4w.acceleratedrendering.core.programs.dispatchers.FixedPolygonProgramDispatcher; 5 | import com.github.argon4w.acceleratedrendering.core.programs.dispatchers.IPolygonProgramDispatcher; 6 | import com.github.argon4w.acceleratedrendering.core.programs.extras.IExtraVertexData; 7 | import com.github.argon4w.acceleratedrendering.core.programs.processing.IPolygonProcessor; 8 | import com.mojang.blaze3d.vertex.VertexFormat; 9 | import net.minecraft.resources.ResourceLocation; 10 | 11 | public class IrisPolygonProcessor implements IPolygonProcessor { 12 | 13 | private final IPolygonProcessor parent; 14 | private final VertexFormat.Mode mode; 15 | private final IPolygonProgramDispatcher dispatcher; 16 | private final IExtraVertexData extraVertexData; 17 | 18 | public IrisPolygonProcessor( 19 | IPolygonProcessor parent, 20 | VertexFormat vertexFormat, 21 | VertexFormat.Mode mode, 22 | ResourceLocation key 23 | ) { 24 | this.parent = parent; 25 | this.mode = mode; 26 | this.dispatcher = new FixedPolygonProgramDispatcher(mode, key); 27 | this.extraVertexData = new IrisExtraVertexData(vertexFormat); 28 | } 29 | 30 | @Override 31 | public IPolygonProgramDispatcher select(VertexFormat.Mode mode) { 32 | if (!IrisCompatFeature.isEnabled()) { 33 | return parent.select(mode); 34 | } 35 | 36 | if (!IrisCompatFeature.isPolygonProcessingEnabled()) { 37 | return parent.select(mode); 38 | } 39 | 40 | if (this.mode != mode) { 41 | return parent.select(mode); 42 | } 43 | 44 | return dispatcher; 45 | } 46 | 47 | @Override 48 | public IExtraVertexData getExtraVertex(VertexFormat.Mode mode) { 49 | if (!IrisCompatFeature.isEnabled()) { 50 | return parent.getExtraVertex(mode); 51 | } 52 | 53 | if (!IrisCompatFeature.isPolygonProcessingEnabled()) { 54 | return parent.getExtraVertex(mode); 55 | } 56 | 57 | if (this.mode != mode) { 58 | return parent.getExtraVertex(mode); 59 | } 60 | 61 | return extraVertexData; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/configs/FeatureStatus.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.configs; 2 | 3 | public enum FeatureStatus { 4 | 5 | DISABLED, ENABLED 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/configs/PipelineSetting.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.configs; 2 | 3 | public enum PipelineSetting { 4 | 5 | VANILLA, ACCELERATED 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/CoreBuffers.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.RedirectingBufferSource; 4 | import com.github.argon4w.acceleratedrendering.core.buffers.SimpleOutlineBufferSource; 5 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.AcceleratedBufferSource; 6 | import com.github.argon4w.acceleratedrendering.core.buffers.environments.IBufferEnvironment; 7 | import com.mojang.blaze3d.vertex.VertexFormat; 8 | import net.minecraft.client.Minecraft; 9 | 10 | public class CoreBuffers { 11 | 12 | public static final AcceleratedBufferSource BLOCK = new AcceleratedBufferSource(IBufferEnvironment.Presets.BLOCK); 13 | public static final AcceleratedBufferSource ENTITY = new AcceleratedBufferSource(IBufferEnvironment.Presets.ENTITY); 14 | public static final AcceleratedBufferSource POS_TEX = new AcceleratedBufferSource(IBufferEnvironment.Presets.POS_TEX); 15 | public static final AcceleratedBufferSource POS_COLOR_TEX_LIGHT = new AcceleratedBufferSource(IBufferEnvironment.Presets.POS_COLOR_TEX_LIGHT); 16 | public static final AcceleratedBufferSource POS_TEX_COLOR = new AcceleratedBufferSource(IBufferEnvironment.Presets.POS_TEX_COLOR); 17 | 18 | public static final RedirectingBufferSource CORE = RedirectingBufferSource 19 | .builder() 20 | .fallback(Minecraft.getInstance().renderBuffers().bufferSource()) 21 | .bufferSource(BLOCK) 22 | .bufferSource(ENTITY) 23 | .bufferSource(POS_TEX) 24 | .bufferSource(POS_COLOR_TEX_LIGHT) 25 | .mode(VertexFormat.Mode.QUADS) 26 | .mode(VertexFormat.Mode.TRIANGLES) 27 | .fallbackName("breeze_wind") 28 | .fallbackName("energy_swirl") 29 | .build(); 30 | 31 | public static final RedirectingBufferSource OUTLINE = RedirectingBufferSource 32 | .builder() 33 | .fallback(Minecraft.getInstance().renderBuffers().outlineBufferSource()) 34 | .bufferSource(POS_TEX_COLOR) 35 | .mode(VertexFormat.Mode.QUADS) 36 | .mode(VertexFormat.Mode.TRIANGLES) 37 | .fallbackName("breeze_wind") 38 | .fallbackName("energy_swirl") 39 | .build(); 40 | 41 | public static final SimpleOutlineBufferSource CORE_OUTLINE = new SimpleOutlineBufferSource(CORE, OUTLINE); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/backends/DebugOutput.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.backends; 2 | 3 | import static org.lwjgl.opengl.GL46.GL_DEBUG_OUTPUT_SYNCHRONOUS; 4 | import static org.lwjgl.opengl.GL46.glEnable; 5 | 6 | public class DebugOutput { 7 | 8 | public static void enable() { 9 | glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/backends/Sync.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.backends; 2 | 3 | import static org.lwjgl.opengl.GL46.*; 4 | 5 | public class Sync { 6 | 7 | private long syncHandle; 8 | 9 | public Sync() { 10 | this.syncHandle = -1; 11 | } 12 | 13 | public boolean isSyncSet() { 14 | return syncHandle != -1; 15 | } 16 | 17 | public boolean isSyncSignaled() { 18 | return glGetSynci(syncHandle, GL_SYNC_STATUS, null) == GL_SIGNALED; 19 | } 20 | 21 | public void waitSync() { 22 | glClientWaitSync(syncHandle, GL_SYNC_FLUSH_COMMANDS_BIT, Long.MAX_VALUE); 23 | } 24 | 25 | public void setSync() { 26 | syncHandle = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); 27 | } 28 | 29 | public void resetSync() { 30 | glDeleteSync(syncHandle); 31 | syncHandle = -1; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/backends/VertexArray.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.backends; 2 | 3 | import static org.lwjgl.opengl.GL46.*; 4 | 5 | public class VertexArray { 6 | 7 | private final int vaoHandle; 8 | 9 | public VertexArray() { 10 | this.vaoHandle = glCreateVertexArrays(); 11 | } 12 | 13 | public void bindVertexArray() { 14 | glBindVertexArray(vaoHandle); 15 | } 16 | 17 | public void unbindVertexArray() { 18 | glBindVertexArray(0); 19 | } 20 | 21 | public void delete() { 22 | glDeleteVertexArrays(vaoHandle); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/backends/buffers/IClientBuffer.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.backends.buffers; 2 | 3 | public interface IClientBuffer { 4 | 5 | long reserve(long bytes); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/backends/buffers/IServerBuffer.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.backends.buffers; 2 | 3 | public interface IServerBuffer { 4 | 5 | int getOffset(); 6 | int getBufferHandle(); 7 | void bind(int target); 8 | void clearInteger(long offset, int value); 9 | void clearBytes(long offset, long size); 10 | void subData(long offset, int[] data); 11 | void bindBase(int target, int index); 12 | void bindRange(int target, int index, long offset, long size); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/backends/buffers/MappedBuffer.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.backends.buffers; 2 | 3 | import static org.lwjgl.opengl.GL46.*; 4 | 5 | public class MappedBuffer extends MutableBuffer implements IClientBuffer { 6 | 7 | public static final int AUTO_FLUSH_BITS = GL_DYNAMIC_STORAGE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_WRITE_BIT | GL_MAP_COHERENT_BIT; 8 | public static final int VERB_FLUSH_BITS = GL_DYNAMIC_STORAGE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_WRITE_BIT; 9 | 10 | public static final int AUTO_FLUSH_MAP_BITS = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT; 11 | public static final int VERB_FLUSH_MAP_BITS = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_FLUSH_EXPLICIT_BIT; 12 | 13 | private final int mapBits; 14 | 15 | protected long address; 16 | protected long position; 17 | 18 | public MappedBuffer(long initialSize, boolean autoFlush) { 19 | super(initialSize, autoFlush ? AUTO_FLUSH_BITS : VERB_FLUSH_BITS); 20 | 21 | this.mapBits = autoFlush ? AUTO_FLUSH_MAP_BITS : VERB_FLUSH_MAP_BITS; 22 | this.address = map(); 23 | this.position = 0L; 24 | } 25 | 26 | public MappedBuffer(long initialSize) { 27 | this(initialSize, false); 28 | } 29 | 30 | @Override 31 | public long reserve(long bytes) { 32 | long position = this.position; 33 | this.position += bytes; 34 | 35 | if (this.position <= size) { 36 | return address + position; 37 | } 38 | 39 | resize(this.position); 40 | return address + position; 41 | } 42 | 43 | @Override 44 | public void beforeExpand() { 45 | unmap(); 46 | } 47 | 48 | @Override 49 | public void afterExpand() { 50 | address = map(); 51 | } 52 | 53 | @Override 54 | public void bind(int target) { 55 | throw new IllegalStateException("Buffer is mapped."); 56 | } 57 | 58 | public void flush() { 59 | glBuffer.flush(position); 60 | } 61 | 62 | public long map() { 63 | return map(mapBits); 64 | } 65 | 66 | public void reset() { 67 | position = 0; 68 | } 69 | 70 | public long getPosition() { 71 | return position; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/backends/buffers/MutableBuffer.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.backends.buffers; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.utils.MutableSize; 4 | 5 | public class MutableBuffer extends MutableSize implements IServerBuffer { 6 | 7 | private final int bits; 8 | 9 | protected ImmutableBuffer glBuffer; 10 | 11 | public MutableBuffer(long initialSize, int bits) { 12 | super(initialSize); 13 | this.bits = bits; 14 | this.glBuffer = new ImmutableBuffer(this.size, bits); 15 | this.glBuffer.clearBytes(0L, this.size); 16 | } 17 | 18 | @Override 19 | public void doExpand(long size, long bytes) { 20 | long newSize = size + bytes; 21 | 22 | ImmutableBuffer newBuffer = new ImmutableBuffer(newSize, bits); 23 | newBuffer.clearBytes(0L, newSize); 24 | 25 | glBuffer.copyTo(newBuffer, size); 26 | glBuffer.delete(); 27 | glBuffer = newBuffer; 28 | } 29 | 30 | public long map(int flags) { 31 | return glBuffer.map(size, flags); 32 | } 33 | 34 | public void unmap() { 35 | glBuffer.unmap(); 36 | } 37 | 38 | public void delete() { 39 | glBuffer.delete(); 40 | } 41 | 42 | @Override 43 | public int getOffset() { 44 | return 0; 45 | } 46 | 47 | @Override 48 | public int getBufferHandle() { 49 | return glBuffer.getBufferHandle(); 50 | } 51 | 52 | @Override 53 | public void bind(int target) { 54 | glBuffer.bind(target); 55 | } 56 | 57 | @Override 58 | public void clearInteger(long offset, int value) { 59 | glBuffer.clearInteger(offset, value); 60 | } 61 | 62 | @Override 63 | public void clearBytes(long offset, long size) { 64 | glBuffer.clearBytes(offset, size); 65 | } 66 | 67 | @Override 68 | public void subData(long offset, int[] data) { 69 | glBuffer.subData(offset, data); 70 | } 71 | 72 | @Override 73 | public void bindBase(int target, int index) { 74 | glBuffer.bindBase(target, index); 75 | } 76 | 77 | @Override 78 | public void bindRange( 79 | int target, 80 | int index, 81 | long offset, 82 | long size 83 | ) { 84 | glBuffer.bindRange( 85 | target, 86 | index, 87 | offset, 88 | size 89 | ); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/backends/programs/BarrierFlags.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.backends.programs; 2 | 3 | import static org.lwjgl.opengl.GL46.*; 4 | 5 | public enum BarrierFlags { 6 | 7 | SHADER_STORAGE(GL_SHADER_STORAGE_BARRIER_BIT), 8 | ATOMIC_COUNTER(GL_ATOMIC_COUNTER_BARRIER_BIT), 9 | ELEMENT_ARRAY(GL_ELEMENT_ARRAY_BARRIER_BIT), 10 | COMMAND(GL_COMMAND_BARRIER_BIT); 11 | 12 | private final int flag; 13 | 14 | BarrierFlags(int flag) { 15 | this.flag = flag; 16 | } 17 | 18 | public static int getFlags(BarrierFlags... barrierFlags) { 19 | int intFlags = 0; 20 | 21 | for (BarrierFlags barrierFlag : barrierFlags) { 22 | intFlags = intFlags | barrierFlag.flag; 23 | } 24 | 25 | return intFlags; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/backends/programs/ComputeProgram.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.backends.programs; 2 | 3 | import static org.lwjgl.opengl.GL46.*; 4 | 5 | public class ComputeProgram { 6 | 7 | private final int programHandle; 8 | private final int barrierFlags; 9 | 10 | public ComputeProgram(int barrierFlags) { 11 | this.programHandle = glCreateProgram(); 12 | this.barrierFlags = barrierFlags; 13 | } 14 | 15 | public void dispatch(int count) { 16 | glDispatchCompute( 17 | count, 18 | 1, 19 | 1 20 | ); 21 | } 22 | 23 | public boolean linkProgram() { 24 | glLinkProgram(programHandle); 25 | return glGetProgrami(programHandle, GL_LINK_STATUS) == GL_TRUE; 26 | } 27 | 28 | public void useProgram() { 29 | glUseProgram(programHandle); 30 | } 31 | 32 | public void resetProgram() { 33 | glUseProgram(0); 34 | } 35 | 36 | public void attachShader(ComputeShader computeShader) { 37 | glAttachShader(programHandle, computeShader.getShaderHandle()); 38 | } 39 | 40 | public void waitBarriers() { 41 | glMemoryBarrier(barrierFlags); 42 | } 43 | 44 | public int getBarrierFlags() { 45 | return barrierFlags; 46 | } 47 | 48 | public int getUniformLocation(String name) { 49 | return glGetUniformLocation(programHandle, name); 50 | } 51 | 52 | public Uniform getUniform(String name) { 53 | return new Uniform(programHandle, getUniformLocation(name)); 54 | } 55 | 56 | public String getInfoLog() { 57 | return glGetProgramInfoLog(programHandle); 58 | } 59 | 60 | public int getProgramHandle() { 61 | return programHandle; 62 | } 63 | 64 | public void delete() { 65 | glDeleteProgram(programHandle); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/backends/programs/ComputeShader.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.backends.programs; 2 | 3 | import static org.lwjgl.opengl.GL46.*; 4 | 5 | public class ComputeShader { 6 | 7 | private final int shaderHandle; 8 | 9 | public ComputeShader() { 10 | this.shaderHandle = glCreateShader(GL_COMPUTE_SHADER); 11 | } 12 | 13 | public void setShaderSource(String source) { 14 | glShaderSource(shaderHandle, source); 15 | } 16 | 17 | public boolean compileShader() { 18 | glCompileShader(shaderHandle); 19 | return glGetShaderi(shaderHandle, GL_COMPILE_STATUS) == GL_TRUE; 20 | } 21 | 22 | public String getInfoLog() { 23 | return glGetShaderInfoLog(shaderHandle); 24 | } 25 | 26 | public void delete() { 27 | glDeleteShader(shaderHandle); 28 | } 29 | 30 | public int getShaderHandle() { 31 | return shaderHandle; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/backends/programs/Uniform.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.backends.programs; 2 | 3 | import org.joml.Matrix4f; 4 | import org.lwjgl.system.MemoryStack; 5 | 6 | import static org.lwjgl.opengl.GL41.glProgramUniform1ui; 7 | import static org.lwjgl.opengl.GL46.glProgramUniformMatrix4fv; 8 | 9 | public class Uniform { 10 | 11 | private final int programHandle; 12 | private final int uniformLocation; 13 | 14 | public Uniform(int programHandle, int uniformLocation) { 15 | this.programHandle = programHandle; 16 | this.uniformLocation = uniformLocation; 17 | } 18 | 19 | public void uploadMatrix4f(Matrix4f matrix) { 20 | try (MemoryStack stack = MemoryStack.stackPush()) { 21 | glProgramUniformMatrix4fv( 22 | programHandle, 23 | uniformLocation, 24 | false, 25 | matrix.get(stack.callocFloat(16)) 26 | ); 27 | } 28 | } 29 | 30 | public void uploadUnsignedInt(int value) { 31 | glProgramUniform1ui( 32 | programHandle, 33 | uniformLocation, 34 | value 35 | ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/SimpleCrumblingBufferSource.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers; 2 | 3 | import com.mojang.blaze3d.vertex.PoseStack; 4 | import com.mojang.blaze3d.vertex.SheetedDecalTextureGenerator; 5 | import com.mojang.blaze3d.vertex.VertexConsumer; 6 | import com.mojang.blaze3d.vertex.VertexMultiConsumer; 7 | import net.minecraft.client.renderer.MultiBufferSource; 8 | import net.minecraft.client.renderer.RenderType; 9 | 10 | public class SimpleCrumblingBufferSource implements MultiBufferSource { 11 | 12 | private final MultiBufferSource bufferSource; 13 | private final VertexConsumer crumblingBuffer; 14 | 15 | public SimpleCrumblingBufferSource( 16 | MultiBufferSource bufferSource, 17 | VertexConsumer crumblingBuffer, 18 | PoseStack.Pose globalTransform, 19 | float textureScale 20 | ) { 21 | this.bufferSource = bufferSource; 22 | this.crumblingBuffer = new SheetedDecalTextureGenerator( 23 | crumblingBuffer, 24 | globalTransform, 25 | textureScale 26 | ); 27 | } 28 | 29 | @Override 30 | public VertexConsumer getBuffer(RenderType pRenderType) { 31 | VertexConsumer buffer = bufferSource.getBuffer(pRenderType); 32 | 33 | if (!pRenderType.affectsCrumbling) { 34 | return buffer; 35 | } 36 | 37 | return VertexMultiConsumer.create(crumblingBuffer, buffer); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/SimpleOutlineBufferSource.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers; 2 | 3 | import com.mojang.blaze3d.vertex.VertexConsumer; 4 | import com.mojang.blaze3d.vertex.VertexMultiConsumer; 5 | import net.minecraft.client.renderer.MultiBufferSource; 6 | import net.minecraft.client.renderer.OutlineBufferSource; 7 | import net.minecraft.client.renderer.RenderType; 8 | 9 | import java.util.Optional; 10 | 11 | public class SimpleOutlineBufferSource implements MultiBufferSource { 12 | 13 | private final MultiBufferSource bufferSource; 14 | private final MultiBufferSource outlineBufferSource; 15 | 16 | private int color; 17 | 18 | public SimpleOutlineBufferSource(MultiBufferSource bufferSource, MultiBufferSource outlineBufferSource) { 19 | this.bufferSource = bufferSource; 20 | this.outlineBufferSource = outlineBufferSource; 21 | } 22 | 23 | @Override 24 | public VertexConsumer getBuffer(RenderType pRenderType) { 25 | if (pRenderType.isOutline()) { 26 | return new OutlineBufferSource.EntityOutlineGenerator(outlineBufferSource.getBuffer(pRenderType), color); 27 | } 28 | 29 | Optional outline = pRenderType.outline(); 30 | VertexConsumer buffer = bufferSource.getBuffer(pRenderType); 31 | 32 | if (outline.isEmpty()) { 33 | return buffer; 34 | } 35 | 36 | return VertexMultiConsumer.create(buffer, new OutlineBufferSource.EntityOutlineGenerator(outlineBufferSource.getBuffer(outline.get()), color)); 37 | } 38 | 39 | public void setColor(int color) { 40 | this.color = color; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/accelerated/IAcceleratedBufferSource.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.accelerated; 2 | 3 | import net.minecraft.client.renderer.MultiBufferSource; 4 | import net.minecraft.client.renderer.RenderType; 5 | 6 | public interface IAcceleratedBufferSource extends MultiBufferSource { 7 | 8 | boolean isAccelerated(RenderType renderType); 9 | void drawBuffers(); 10 | void clearBuffers(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/accelerated/builders/IAcceleratedVertexConsumer.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.renderers.IAcceleratedRenderer; 4 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.renderers.IBufferDecorator; 5 | import com.github.argon4w.acceleratedrendering.core.buffers.graphs.IBufferGraph; 6 | import net.minecraft.client.renderer.RenderType; 7 | import org.joml.Matrix3f; 8 | import org.joml.Matrix4f; 9 | 10 | import java.nio.ByteBuffer; 11 | 12 | public interface IAcceleratedVertexConsumer extends IBufferDecorator { 13 | 14 | void beginTransform(Matrix4f transform, Matrix3f normal); 15 | void endTransform(); 16 | boolean isAccelerated(); 17 | IBufferGraph getBufferGraph(); 18 | RenderType getRenderType(); 19 | void doRender(IAcceleratedRenderer renderer, T context, Matrix4f transform, Matrix3f normal, int light, int overlay, int color); 20 | void addClientMesh(ByteBuffer meshBuffer, int size, int color, int light, int overlay); 21 | void addServerMesh(int offset, int size, int color, int light, int overlay); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/accelerated/pools/DrawContextPool.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.accelerated.pools; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.backends.buffers.IServerBuffer; 4 | import com.github.argon4w.acceleratedrendering.core.backends.buffers.SegmentBuffer; 5 | import com.github.argon4w.acceleratedrendering.core.utils.SimpleResetPool; 6 | import com.mojang.blaze3d.vertex.VertexFormat; 7 | 8 | import static org.lwjgl.opengl.GL46.*; 9 | 10 | public class DrawContextPool extends SimpleResetPool { 11 | 12 | public DrawContextPool(int size) { 13 | super(size, new SegmentBuffer(20L * size, size)); 14 | } 15 | 16 | public void bindCommandBuffer() { 17 | getContext().bind(GL_DRAW_INDIRECT_BUFFER); 18 | } 19 | 20 | @Override 21 | protected IndirectDrawContext create(SegmentBuffer buffer, int i) { 22 | return new IndirectDrawContext(buffer.getSegment(20L)); 23 | } 24 | 25 | @Override 26 | protected void reset(IndirectDrawContext drawContext) { 27 | 28 | } 29 | 30 | @Override 31 | protected void delete(IndirectDrawContext drawContext) { 32 | 33 | } 34 | 35 | @Override 36 | public void delete() { 37 | super.getContext().delete(); 38 | } 39 | 40 | public static void waitBarriers() { 41 | glMemoryBarrier(GL_ELEMENT_ARRAY_BARRIER_BIT | GL_COMMAND_BARRIER_BIT); 42 | } 43 | 44 | public static class IndirectDrawContext { 45 | 46 | private final long commandOffset; 47 | private final IServerBuffer commandBuffer; 48 | 49 | private int cachedOffset; 50 | 51 | public IndirectDrawContext(IServerBuffer commandBuffer) { 52 | this.commandOffset = commandBuffer.getOffset(); 53 | this.commandBuffer = commandBuffer; 54 | this.commandBuffer.subData(0, new int[] {0, 1, 0, 0, 0}); 55 | 56 | this.cachedOffset = -1; 57 | } 58 | 59 | public void bindComputeBuffers(ElementBufferPool.ElementSegment elementSegmentIn) { 60 | IServerBuffer elementBufferOut = elementSegmentIn.getBuffer(); 61 | int elementOffset = elementBufferOut.getOffset(); 62 | 63 | if (cachedOffset != elementOffset) { 64 | cachedOffset = elementOffset; 65 | commandBuffer.clearInteger(8, elementOffset / 4); 66 | } 67 | 68 | commandBuffer.clearInteger(0, 0); 69 | commandBuffer.bindBase(GL_ATOMIC_COUNTER_BUFFER, 0); 70 | elementBufferOut.bindBase(GL_SHADER_STORAGE_BUFFER, 6); 71 | } 72 | 73 | public void drawElements(VertexFormat.Mode mode) { 74 | glDrawElementsIndirect( 75 | mode.asGLMode, 76 | GL_UNSIGNED_INT, 77 | commandOffset 78 | ); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/accelerated/pools/ElementBufferPool.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.accelerated.pools; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.backends.buffers.IServerBuffer; 4 | import com.github.argon4w.acceleratedrendering.core.backends.buffers.SegmentBuffer; 5 | import com.github.argon4w.acceleratedrendering.core.utils.MutableSize; 6 | import com.github.argon4w.acceleratedrendering.core.utils.SimpleResetPool; 7 | import org.apache.commons.lang3.mutable.MutableLong; 8 | 9 | import static org.lwjgl.opengl.GL46.GL_ELEMENT_ARRAY_BUFFER; 10 | 11 | public class ElementBufferPool extends SimpleResetPool { 12 | 13 | private final SegmentBuffer elementBufferOut; 14 | private final MutableLong elementBufferOutSize; 15 | 16 | public ElementBufferPool(int size) { 17 | super(size, null); 18 | 19 | this.elementBufferOut = new SegmentBuffer(64L * size, size); 20 | this.elementBufferOutSize = new MutableLong(64L * size); 21 | } 22 | 23 | public void prepare() { 24 | elementBufferOut.resizeTo(elementBufferOutSize.getValue()); 25 | elementBufferOut.clearSegment(); 26 | } 27 | 28 | public void bindElementBuffer() { 29 | elementBufferOut.bind(GL_ELEMENT_ARRAY_BUFFER); 30 | } 31 | 32 | public void resetResized() { 33 | elementBufferOut.resetResized(); 34 | } 35 | 36 | public boolean isResized() { 37 | return elementBufferOut.isResized(); 38 | } 39 | 40 | @Override 41 | public void delete() { 42 | elementBufferOut.delete(); 43 | super.delete(); 44 | } 45 | 46 | @Override 47 | protected ElementSegment create(Void value, int i) { 48 | return new ElementSegment(); 49 | } 50 | 51 | @Override 52 | protected void reset(ElementSegment elementSegment) { 53 | elementSegment.reset(); 54 | } 55 | 56 | @Override 57 | protected void delete(ElementSegment elementSegment) { 58 | 59 | } 60 | 61 | public class ElementSegment extends MutableSize { 62 | 63 | private long elementBytes; 64 | 65 | public ElementSegment() { 66 | super(64L); 67 | this.elementBytes = 0L; 68 | } 69 | 70 | @Override 71 | public void onExpand(long bytes) { 72 | elementBufferOutSize.add(bytes); 73 | } 74 | 75 | public IServerBuffer getBuffer() { 76 | return elementBufferOut.getSegment(size); 77 | } 78 | 79 | public long getElementBytes() { 80 | return elementBytes; 81 | } 82 | 83 | public int getElementCount() { 84 | return (int) elementBytes / 4; 85 | } 86 | 87 | private void reset() { 88 | elementBytes = 0L; 89 | } 90 | 91 | public void countPolygons(int count) { 92 | elementBytes += count * 4L; 93 | 94 | if (elementBytes > size) { 95 | resize(elementBytes); 96 | } 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/accelerated/pools/MappedBufferPool.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.accelerated.pools; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.backends.buffers.MappedBuffer; 4 | import com.github.argon4w.acceleratedrendering.core.utils.SimpleResetPool; 5 | 6 | public class MappedBufferPool extends SimpleResetPool { 7 | 8 | public MappedBufferPool(int size) { 9 | super(size, null); 10 | } 11 | 12 | @Override 13 | protected Pooled create(Void context, int i) { 14 | return new Pooled(64L); 15 | } 16 | 17 | @Override 18 | protected void reset(Pooled pooled) { 19 | pooled.poolReset(); 20 | } 21 | 22 | @Override 23 | protected void delete(Pooled pooled) { 24 | pooled.poolDelete(); 25 | } 26 | 27 | public static class Pooled extends MappedBuffer { 28 | 29 | public Pooled(long initialSize) { 30 | super(initialSize); 31 | } 32 | 33 | @Override 34 | public void delete() { 35 | throw new IllegalStateException("Pooled buffers cannot be deleted directly."); 36 | } 37 | 38 | @Override 39 | public void reset() { 40 | throw new IllegalStateException("Pooled buffers cannot be reset directly."); 41 | } 42 | 43 | private void poolDelete() { 44 | super.delete(); 45 | } 46 | 47 | private void poolReset() { 48 | super.reset(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/accelerated/renderers/DecoratedRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.accelerated.renderers; 2 | 3 | import com.mojang.blaze3d.vertex.VertexConsumer; 4 | import org.joml.Matrix3f; 5 | import org.joml.Matrix4f; 6 | 7 | public class DecoratedRenderer implements IAcceleratedRenderer { 8 | 9 | private final IAcceleratedRenderer renderer; 10 | private final IBufferDecorator bufferDecorator; 11 | 12 | public DecoratedRenderer(IAcceleratedRenderer renderer, IBufferDecorator bufferDecorator) { 13 | this.renderer = renderer; 14 | this.bufferDecorator = bufferDecorator; 15 | } 16 | 17 | @Override 18 | public void render( 19 | VertexConsumer vertexConsumer, 20 | T context, 21 | Matrix4f transform, 22 | Matrix3f normal, 23 | int light, 24 | int overlay, 25 | int color 26 | ) { 27 | renderer.render( 28 | bufferDecorator.decorate( 29 | vertexConsumer 30 | ), 31 | context, 32 | transform, 33 | normal, 34 | light, 35 | overlay, 36 | color 37 | ); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/accelerated/renderers/IAcceleratedRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.accelerated.renderers; 2 | 3 | import com.mojang.blaze3d.vertex.VertexConsumer; 4 | import org.joml.Matrix3f; 5 | import org.joml.Matrix4f; 6 | 7 | public interface IAcceleratedRenderer { 8 | 9 | void render(VertexConsumer vertexConsumer, T context, Matrix4f transform, Matrix3f normal, int light, int overlay, int color); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/accelerated/renderers/IBufferDecorator.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.accelerated.renderers; 2 | 3 | import com.mojang.blaze3d.vertex.VertexConsumer; 4 | 5 | public interface IBufferDecorator { 6 | 7 | VertexConsumer decorate(VertexConsumer buffer); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/accelerated/renderers/SheetedDecalTextureRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.accelerated.renderers; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.AcceleratedSheetedDecalTextureGenerator; 4 | import com.mojang.blaze3d.vertex.VertexConsumer; 5 | import org.joml.Matrix3f; 6 | import org.joml.Matrix4f; 7 | 8 | public class SheetedDecalTextureRenderer implements IAcceleratedRenderer { 9 | 10 | private final IAcceleratedRenderer renderer; 11 | private final Matrix4f cameraInverse; 12 | private final Matrix3f normalInverse; 13 | private final float textureScale; 14 | 15 | public SheetedDecalTextureRenderer( 16 | IAcceleratedRenderer renderer, 17 | Matrix4f cameraInverse, 18 | Matrix3f normalInverse, 19 | float textureScale 20 | ) { 21 | this.renderer = renderer; 22 | this.cameraInverse = cameraInverse; 23 | this.normalInverse = normalInverse; 24 | this.textureScale = textureScale; 25 | } 26 | 27 | @Override 28 | public void render( 29 | VertexConsumer vertexConsumer, 30 | T context, 31 | Matrix4f transform, 32 | Matrix3f normal, 33 | int light, 34 | int overlay, 35 | int color 36 | ) { 37 | renderer.render( 38 | new AcceleratedSheetedDecalTextureGenerator( 39 | vertexConsumer, 40 | new Matrix4f(cameraInverse).mul(transform), 41 | new Matrix3f(normalInverse).mul(normal), 42 | textureScale 43 | ), 44 | context, 45 | transform, 46 | normal, 47 | light, 48 | overlay, 49 | color 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/environments/IBufferEnvironment.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.environments; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.backends.buffers.IServerBuffer; 4 | import com.github.argon4w.acceleratedrendering.core.programs.ComputeShaderPrograms; 5 | import com.github.argon4w.acceleratedrendering.core.programs.dispatchers.IPolygonProgramDispatcher; 6 | import com.github.argon4w.acceleratedrendering.core.programs.dispatchers.TransformProgramDispatcher; 7 | import com.github.argon4w.acceleratedrendering.core.programs.extras.IExtraVertexData; 8 | import com.mojang.blaze3d.vertex.DefaultVertexFormat; 9 | import com.mojang.blaze3d.vertex.VertexFormat; 10 | import com.mojang.blaze3d.vertex.VertexFormatElement; 11 | import net.minecraft.client.renderer.RenderType; 12 | 13 | public interface IBufferEnvironment { 14 | 15 | void setupBufferState(); 16 | boolean isAccelerated(VertexFormat vertexFormat); 17 | IExtraVertexData getExtraVertex(VertexFormat.Mode mode); 18 | VertexFormat getActiveFormat(); 19 | IServerBuffer getServerMeshBuffer(); 20 | TransformProgramDispatcher selectTransformProgramDispatcher(); 21 | IPolygonProgramDispatcher selectCullProgramDispatcher(RenderType renderType); 22 | IPolygonProgramDispatcher selectProcessingProgramDispatcher(VertexFormat.Mode mode); 23 | RenderType getRenderType(RenderType renderType); 24 | int getOffset(VertexFormatElement element); 25 | int getVertexSize(); 26 | 27 | class Presets { 28 | 29 | public static final IBufferEnvironment BLOCK = new VanillaBufferEnvironment(DefaultVertexFormat.BLOCK, ComputeShaderPrograms.CORE_BLOCK_VERTEX_TRANSFORM_KEY); 30 | public static final IBufferEnvironment ENTITY = new VanillaBufferEnvironment(DefaultVertexFormat.NEW_ENTITY, ComputeShaderPrograms.CORE_ENTITY_VERTEX_TRANSFORM_KEY); 31 | public static final IBufferEnvironment POS_TEX_COLOR = new VanillaBufferEnvironment(DefaultVertexFormat.POSITION_TEX_COLOR, ComputeShaderPrograms.CORE_POS_TEX_COLOR_VERTEX_TRANSFORM_KEY); 32 | public static final IBufferEnvironment POS_TEX = new VanillaBufferEnvironment(DefaultVertexFormat.POSITION_TEX, ComputeShaderPrograms.CORE_POS_TEX_VERTEX_TRANSFORM_KEY); 33 | public static final IBufferEnvironment POS_COLOR_TEX_LIGHT = new VanillaBufferEnvironment(DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, ComputeShaderPrograms.CORE_POS_COLOR_TEX_LIGHT_VERTEX_TRANSFORM_KEY); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/graphs/BlankBufferGraph.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.graphs; 2 | 3 | import net.minecraft.client.renderer.RenderType; 4 | 5 | public class BlankBufferGraph implements IBufferGraph { 6 | 7 | private final RenderType renderType; 8 | 9 | public BlankBufferGraph(RenderType renderType) { 10 | this.renderType = renderType; 11 | } 12 | 13 | @Override 14 | public int hashCode() { 15 | return renderType.hashCode(); 16 | } 17 | 18 | @Override 19 | public boolean equals(Object obj) { 20 | if (obj == this) { 21 | return true; 22 | } 23 | 24 | if (obj == null) { 25 | return false; 26 | } 27 | 28 | if (obj.getClass() != this.getClass()) { 29 | return false; 30 | } 31 | 32 | return renderType.equals(((BlankBufferGraph) obj).renderType); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/graphs/DecalBufferGraph.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.graphs; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | import java.util.Objects; 6 | 7 | public class DecalBufferGraph implements IBufferGraph { 8 | 9 | private final IBufferGraph parent; 10 | private final Matrix4f localTransform; 11 | 12 | public DecalBufferGraph(IBufferGraph parent, Matrix4f localTransform) { 13 | this.parent = parent; 14 | this.localTransform = localTransform; 15 | } 16 | 17 | @Override 18 | public int hashCode() { 19 | return parent.hashCode() ^ localTransform.hashCode(); 20 | } 21 | 22 | @Override 23 | public boolean equals(Object obj) { 24 | if (obj == this) { 25 | return true; 26 | } 27 | 28 | if (obj == null) { 29 | return false; 30 | } 31 | 32 | if (obj.getClass() != this.getClass()) { 33 | return false; 34 | } 35 | 36 | DecalBufferGraph that = (DecalBufferGraph) obj; 37 | 38 | return Objects.equals(parent, that.parent) 39 | && localTransform.equals(that.localTransform, 1e-5f); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/graphs/IBufferGraph.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.graphs; 2 | 3 | public interface IBufferGraph { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/graphs/OutlineBufferGraph.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.graphs; 2 | 3 | import java.util.Objects; 4 | 5 | public class OutlineBufferGraph implements IBufferGraph { 6 | 7 | private final IBufferGraph parent; 8 | private final int color; 9 | 10 | public OutlineBufferGraph(IBufferGraph parent, int color) { 11 | this.parent = parent; 12 | this.color = color; 13 | } 14 | 15 | @Override 16 | public int hashCode() { 17 | return parent.hashCode() ^ color; 18 | } 19 | 20 | @Override 21 | public boolean equals(Object obj) { 22 | if (obj == this) { 23 | return true; 24 | } 25 | 26 | if (obj == null) { 27 | return false; 28 | } 29 | 30 | if (obj.getClass() != this.getClass()) { 31 | return false; 32 | } 33 | 34 | OutlineBufferGraph that = (OutlineBufferGraph) obj; 35 | 36 | return Objects.equals(parent, that.parent) 37 | && Objects.equals(color, that.color); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/buffers/graphs/SpriteBufferGraph.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.buffers.graphs; 2 | 3 | import net.minecraft.client.renderer.texture.TextureAtlasSprite; 4 | 5 | import java.util.Objects; 6 | 7 | public class SpriteBufferGraph implements IBufferGraph { 8 | 9 | private final IBufferGraph parent; 10 | private final TextureAtlasSprite sprite; 11 | 12 | public SpriteBufferGraph(IBufferGraph parent, TextureAtlasSprite sprite) { 13 | this.parent = parent; 14 | this.sprite = sprite; 15 | } 16 | 17 | @Override 18 | public int hashCode() { 19 | return parent.hashCode() ^ sprite.hashCode(); 20 | } 21 | 22 | @Override 23 | public boolean equals(Object obj) { 24 | if (obj == this) { 25 | return true; 26 | } 27 | 28 | if (obj == null) { 29 | return false; 30 | } 31 | 32 | if (obj.getClass() != this.getClass()) { 33 | return false; 34 | } 35 | 36 | SpriteBufferGraph that = (SpriteBufferGraph) obj; 37 | 38 | return Objects.equals(parent, that.parent) 39 | && Objects.equals(sprite, that.sprite); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/meshes/ClientMesh.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.meshes; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.IAcceleratedVertexConsumer; 4 | import com.github.argon4w.acceleratedrendering.core.meshes.collectors.MeshCollector; 5 | import com.mojang.blaze3d.vertex.ByteBufferBuilder; 6 | import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet; 7 | 8 | import java.nio.ByteBuffer; 9 | import java.util.Set; 10 | 11 | public class ClientMesh implements IMesh { 12 | 13 | private final int size; 14 | private final ByteBuffer vertexBuffer; 15 | 16 | public ClientMesh(int size, ByteBuffer vertexBuffer) { 17 | this.size = size; 18 | this.vertexBuffer = vertexBuffer; 19 | } 20 | 21 | @Override 22 | public void write( 23 | IAcceleratedVertexConsumer extension, 24 | int color, 25 | int light, 26 | int overlay 27 | ) { 28 | extension.addClientMesh( 29 | vertexBuffer, 30 | size, 31 | color, 32 | light, 33 | overlay 34 | ); 35 | } 36 | 37 | public static class Builder implements IMesh.Builder { 38 | 39 | public static final Builder INSTANCE = new Builder(); 40 | 41 | private final Set builders; 42 | 43 | private Builder() { 44 | this.builders = new ReferenceLinkedOpenHashSet<>(); 45 | } 46 | 47 | @Override 48 | public IMesh build(MeshCollector collector) { 49 | int vertexCount = collector.getVertexCount(); 50 | 51 | if (vertexCount == 0) { 52 | return EmptyMesh.INSTANCE; 53 | } 54 | 55 | ByteBufferBuilder builder = collector.getBuffer(); 56 | ByteBufferBuilder.Result result = builder.build(); 57 | 58 | if (result == null) { 59 | builder.close(); 60 | return EmptyMesh.INSTANCE; 61 | } 62 | 63 | builders.add(builder); 64 | return new ClientMesh(vertexCount, result.byteBuffer()); 65 | } 66 | 67 | @Override 68 | public void close() { 69 | for (ByteBufferBuilder builder : builders) { 70 | builder.close(); 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/meshes/EmptyMesh.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.meshes; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.IAcceleratedVertexConsumer; 4 | 5 | public class EmptyMesh implements IMesh { 6 | 7 | public static final EmptyMesh INSTANCE = new EmptyMesh(); 8 | 9 | @Override 10 | public void write( 11 | IAcceleratedVertexConsumer extension, 12 | int color, 13 | int light, 14 | int overlay 15 | ) { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/meshes/IMesh.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.meshes; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.IAcceleratedVertexConsumer; 4 | import com.github.argon4w.acceleratedrendering.core.meshes.collectors.MeshCollector; 5 | 6 | public interface IMesh { 7 | 8 | void write(IAcceleratedVertexConsumer extension, int color, int light, int overlay); 9 | 10 | interface Builder { 11 | 12 | IMesh build(MeshCollector collector); 13 | void close(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/meshes/MeshType.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.meshes; 2 | 3 | public enum MeshType { 4 | 5 | SERVER(ServerMesh.Builder.INSTANCE), 6 | CLIENT(ClientMesh.Builder.INSTANCE); 7 | 8 | private final IMesh.Builder builder; 9 | 10 | MeshType(IMesh.Builder builder) { 11 | this.builder = builder; 12 | } 13 | 14 | public IMesh.Builder getBuilder() { 15 | return builder; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/meshes/ServerMesh.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.meshes; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.backends.buffers.MappedBuffer; 4 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.IAcceleratedVertexConsumer; 5 | import com.github.argon4w.acceleratedrendering.core.meshes.collectors.MeshCollector; 6 | import com.github.argon4w.acceleratedrendering.core.utils.LazyMap; 7 | import com.mojang.blaze3d.vertex.ByteBufferBuilder; 8 | import com.mojang.blaze3d.vertex.VertexFormat; 9 | import org.lwjgl.system.MemoryUtil; 10 | 11 | import java.nio.ByteBuffer; 12 | import java.util.Map; 13 | 14 | public class ServerMesh implements IMesh { 15 | 16 | private final int size; 17 | private final int offset; 18 | 19 | public ServerMesh(int size, int offset) { 20 | this.size = size; 21 | this.offset = offset; 22 | } 23 | 24 | @Override 25 | public void write( 26 | IAcceleratedVertexConsumer extension, 27 | int color, 28 | int light, 29 | int overlay 30 | ) { 31 | extension.addServerMesh( 32 | offset, 33 | size, 34 | color, 35 | light, 36 | overlay 37 | ); 38 | } 39 | 40 | public static class Builder implements IMesh.Builder { 41 | 42 | public static final Builder INSTANCE = new Builder(); 43 | 44 | public final Map storageBuffers; 45 | 46 | private Builder() { 47 | this.storageBuffers = new LazyMap<>(() -> new MappedBuffer(1024L, true)); 48 | } 49 | 50 | @Override 51 | public IMesh build(MeshCollector collector) { 52 | int vertexCount = collector.getVertexCount(); 53 | 54 | if (vertexCount == 0) { 55 | return EmptyMesh.INSTANCE; 56 | } 57 | 58 | ByteBufferBuilder builder = collector.getBuffer(); 59 | ByteBufferBuilder.Result result = builder.build(); 60 | 61 | if (result == null) { 62 | builder.close(); 63 | return EmptyMesh.INSTANCE; 64 | } 65 | 66 | ByteBuffer clientBuffer = result.byteBuffer(); 67 | MappedBuffer serverBuffer = storageBuffers.get(collector.getVertexFormat()); 68 | 69 | long capacity = clientBuffer.capacity(); 70 | long position = serverBuffer.getPosition(); 71 | 72 | MemoryUtil.memCopy( 73 | MemoryUtil.memAddress0(clientBuffer), 74 | serverBuffer.reserve(capacity), 75 | capacity 76 | ); 77 | 78 | builder.close(); 79 | return new ServerMesh(vertexCount, (int) position); 80 | } 81 | 82 | @Override 83 | public void close() { 84 | for (MappedBuffer buffer : storageBuffers.values()) { 85 | buffer.delete(); 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/mixins/LevelRendererMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.mixins; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.CoreBuffers; 4 | import com.llamalad7.mixinextras.injector.wrapoperation.Operation; 5 | import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; 6 | import net.minecraft.client.Camera; 7 | import net.minecraft.client.DeltaTracker; 8 | import net.minecraft.client.renderer.GameRenderer; 9 | import net.minecraft.client.renderer.LevelRenderer; 10 | import net.minecraft.client.renderer.LightTexture; 11 | import net.minecraft.client.renderer.MultiBufferSource; 12 | import org.joml.Matrix4f; 13 | import org.spongepowered.asm.mixin.Mixin; 14 | import org.spongepowered.asm.mixin.injection.At; 15 | import org.spongepowered.asm.mixin.injection.Inject; 16 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 17 | 18 | @Mixin(value = LevelRenderer.class, priority = 998) 19 | public class LevelRendererMixin { 20 | 21 | @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/OutlineBufferSource;endOutlineBatch()V")) 22 | public void endOutlineBatches( 23 | DeltaTracker pDeltaTracker, 24 | boolean pRenderBlockOutline, 25 | Camera pCamera, 26 | GameRenderer pGameRenderer, 27 | LightTexture pLightTexture, 28 | Matrix4f pFrustumMatrix, 29 | Matrix4f pProjectionMatrix, 30 | CallbackInfo ci 31 | ) { 32 | CoreBuffers.POS_TEX_COLOR.drawBuffers(); 33 | CoreBuffers.POS_TEX_COLOR.clearBuffers(); 34 | } 35 | 36 | @WrapOperation(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endLastBatch()V")) 37 | public void drawCoreBuffers(MultiBufferSource.BufferSource instance, Operation original) { 38 | CoreBuffers.ENTITY.drawBuffers(); 39 | CoreBuffers.BLOCK.drawBuffers(); 40 | CoreBuffers.POS_TEX.drawBuffers(); 41 | CoreBuffers.POS_COLOR_TEX_LIGHT.drawBuffers(); 42 | 43 | CoreBuffers.ENTITY.clearBuffers(); 44 | CoreBuffers.BLOCK.clearBuffers(); 45 | CoreBuffers.POS_TEX.clearBuffers(); 46 | CoreBuffers.POS_COLOR_TEX_LIGHT.clearBuffers(); 47 | 48 | original.call(instance); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/mixins/MinecraftMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.mixins; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.CoreFeature; 4 | import com.github.argon4w.acceleratedrendering.core.backends.DebugOutput; 5 | import net.minecraft.client.Minecraft; 6 | import net.minecraft.client.main.GameConfig; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Inject; 10 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 11 | 12 | @Mixin(Minecraft.class) 13 | public class MinecraftMixin { 14 | 15 | @Inject(method = "", at = @At("TAIL")) 16 | public void setDebugContext(GameConfig gameConfig, CallbackInfo ci) { 17 | if (CoreFeature.isDebugContextEnabled()) { 18 | DebugOutput.enable(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/mixins/VertexConsumerMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.mixins; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.IAcceleratedVertexConsumer; 4 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.renderers.IAcceleratedRenderer; 5 | import com.github.argon4w.acceleratedrendering.core.buffers.graphs.IBufferGraph; 6 | import com.mojang.blaze3d.vertex.VertexConsumer; 7 | import net.minecraft.client.renderer.RenderType; 8 | import org.joml.Matrix3f; 9 | import org.joml.Matrix4f; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.Unique; 12 | 13 | import java.nio.ByteBuffer; 14 | 15 | @Mixin(VertexConsumer.class) 16 | public interface VertexConsumerMixin extends IAcceleratedVertexConsumer { 17 | 18 | @Unique 19 | @Override 20 | default VertexConsumer decorate(VertexConsumer buffer) { 21 | throw new UnsupportedOperationException("Unsupported Operation."); 22 | } 23 | 24 | @Unique 25 | @Override 26 | default void beginTransform(Matrix4f transform, Matrix3f normal) { 27 | throw new UnsupportedOperationException("Unsupported Operation."); 28 | } 29 | 30 | @Unique 31 | @Override 32 | default void endTransform() { 33 | throw new UnsupportedOperationException("Unsupported Operation."); 34 | } 35 | 36 | @Unique 37 | @Override 38 | default boolean isAccelerated() { 39 | return false; 40 | } 41 | 42 | @Unique 43 | @Override 44 | default IBufferGraph getBufferGraph() { 45 | throw new UnsupportedOperationException("Unsupported Operation."); 46 | } 47 | 48 | @Unique 49 | @Override 50 | default RenderType getRenderType() { 51 | throw new UnsupportedOperationException("Unsupported Operation."); 52 | } 53 | 54 | @Unique 55 | @Override 56 | default void addClientMesh( 57 | ByteBuffer meshBuffer, 58 | int size, 59 | int color, 60 | int light, 61 | int overlay 62 | ) { 63 | throw new UnsupportedOperationException("Unsupported Operation."); 64 | } 65 | 66 | @Unique 67 | @Override 68 | default void addServerMesh( 69 | int offset, 70 | int size, 71 | int color, 72 | int light, 73 | int overlay 74 | ) { 75 | throw new UnsupportedOperationException("Unsupported Operation."); 76 | } 77 | 78 | @Unique 79 | @Override 80 | default void doRender( 81 | IAcceleratedRenderer renderer, 82 | T context, 83 | Matrix4f transform, 84 | Matrix3f normal, 85 | int light, 86 | int overlay, 87 | int color 88 | ) { 89 | throw new UnsupportedOperationException("Unsupported Operation."); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/LoadComputeShaderEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.backends.programs.BarrierFlags; 4 | import com.google.common.collect.ImmutableMap; 5 | import net.minecraft.resources.ResourceLocation; 6 | import net.neoforged.bus.api.Event; 7 | import net.neoforged.fml.event.IModBusEvent; 8 | 9 | public class LoadComputeShaderEvent extends Event implements IModBusEvent { 10 | 11 | private final ImmutableMap.Builder shaderLocations; 12 | 13 | public LoadComputeShaderEvent(ImmutableMap.Builder builder) { 14 | this.shaderLocations = builder; 15 | } 16 | 17 | public void loadComputeShader( 18 | ResourceLocation key, 19 | ResourceLocation location, 20 | BarrierFlags... barrierFlags 21 | ) { 22 | shaderLocations.put(key, new ComputeShaderProgramLoader.ShaderDefinition(location, BarrierFlags.getFlags(barrierFlags))); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/culling/ICullingProgramSelector.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.culling; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.programs.dispatchers.IPolygonProgramDispatcher; 4 | import com.github.argon4w.acceleratedrendering.core.programs.extras.IExtraVertexData; 5 | import com.mojang.blaze3d.vertex.VertexFormat; 6 | import net.minecraft.client.renderer.RenderType; 7 | 8 | public interface ICullingProgramSelector { 9 | 10 | IPolygonProgramDispatcher select(RenderType renderType); 11 | IExtraVertexData getExtraVertex(VertexFormat.Mode mode); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/culling/LoadCullingProgramSelectorEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.culling; 2 | 3 | import com.mojang.blaze3d.vertex.VertexFormat; 4 | import net.neoforged.bus.api.Event; 5 | import net.neoforged.fml.event.IModBusEvent; 6 | 7 | import java.util.function.UnaryOperator; 8 | 9 | public class LoadCullingProgramSelectorEvent extends Event implements IModBusEvent { 10 | 11 | private final VertexFormat vertexFormat; 12 | 13 | private ICullingProgramSelector selector; 14 | 15 | public LoadCullingProgramSelectorEvent(VertexFormat vertexFormat) { 16 | this.vertexFormat = vertexFormat; 17 | this.selector = PassThroughCullingProgramSelector.INSTANCE; 18 | } 19 | 20 | public void loadFor(VertexFormat vertexFormat, UnaryOperator selector) { 21 | if (this.vertexFormat == vertexFormat) { 22 | this.selector = selector.apply(this.selector); 23 | } 24 | } 25 | 26 | public ICullingProgramSelector getSelector() { 27 | return selector; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/culling/PassThroughCullingProgramDispatcher.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.culling; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.backends.programs.ComputeProgram; 4 | import com.github.argon4w.acceleratedrendering.core.backends.programs.Uniform; 5 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.AcceleratedBufferBuilder; 6 | import com.github.argon4w.acceleratedrendering.core.programs.ComputeShaderProgramLoader; 7 | import com.github.argon4w.acceleratedrendering.core.programs.ComputeShaderPrograms; 8 | import com.github.argon4w.acceleratedrendering.core.programs.dispatchers.IPolygonProgramDispatcher; 9 | import com.mojang.blaze3d.vertex.VertexFormat; 10 | import net.minecraft.resources.ResourceLocation; 11 | 12 | public class PassThroughCullingProgramDispatcher implements IPolygonProgramDispatcher { 13 | 14 | public static final PassThroughCullingProgramDispatcher QUAD = new PassThroughCullingProgramDispatcher(VertexFormat.Mode.QUADS, ComputeShaderPrograms.CORE_PASS_THROUGH_QUAD_CULLING_KEY); 15 | public static final PassThroughCullingProgramDispatcher TRIANGLE = new PassThroughCullingProgramDispatcher(VertexFormat.Mode.TRIANGLES, ComputeShaderPrograms.CORE_PASS_THROUGH_TRIANGLE_CULLING_KEY); 16 | 17 | private static final int GROUP_SIZE = 128; 18 | 19 | private final VertexFormat.Mode mode; 20 | private final ComputeProgram program; 21 | private final Uniform polygonCountUniform; 22 | private final Uniform vertexOffsetUniform; 23 | 24 | public PassThroughCullingProgramDispatcher(VertexFormat.Mode mode, ResourceLocation key) { 25 | this.mode = mode; 26 | this.program = ComputeShaderProgramLoader.getProgram(key); 27 | this.polygonCountUniform = program.getUniform("polygonCount"); 28 | this.vertexOffsetUniform = program.getUniform("vertexOffset"); 29 | } 30 | 31 | @Override 32 | public int dispatch(AcceleratedBufferBuilder builder) { 33 | int vertexCount = builder.getVertexCount(); 34 | int vertexOffset = builder.getVertexOffset(); 35 | int polygonCount = vertexCount / mode.primitiveLength; 36 | 37 | polygonCountUniform.uploadUnsignedInt(polygonCount); 38 | vertexOffsetUniform.uploadUnsignedInt(vertexOffset); 39 | 40 | program.useProgram(); 41 | program.dispatch((polygonCount + GROUP_SIZE - 1) / GROUP_SIZE); 42 | program.resetProgram(); 43 | 44 | return program.getBarrierFlags(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/culling/PassThroughCullingProgramSelector.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.culling; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.programs.dispatchers.IPolygonProgramDispatcher; 4 | import com.github.argon4w.acceleratedrendering.core.programs.extras.FlagsExtraVertexData; 5 | import com.github.argon4w.acceleratedrendering.core.programs.extras.IExtraVertexData; 6 | import com.mojang.blaze3d.vertex.VertexFormat; 7 | import net.minecraft.client.renderer.RenderType; 8 | 9 | public class PassThroughCullingProgramSelector implements ICullingProgramSelector { 10 | 11 | public static final ICullingProgramSelector INSTANCE = new PassThroughCullingProgramSelector(); 12 | public static final FlagsExtraVertexData EMPTY = new FlagsExtraVertexData(); 13 | 14 | @Override 15 | public IPolygonProgramDispatcher select(RenderType renderType) { 16 | VertexFormat.Mode mode = renderType.mode; 17 | 18 | if (mode == VertexFormat.Mode.QUADS) { 19 | return PassThroughCullingProgramDispatcher.QUAD; 20 | } 21 | 22 | if (mode == VertexFormat.Mode.TRIANGLES) { 23 | return PassThroughCullingProgramDispatcher.TRIANGLE; 24 | } 25 | 26 | throw new IllegalArgumentException("Unsupported mode: " + mode); 27 | } 28 | 29 | @Override 30 | public IExtraVertexData getExtraVertex(VertexFormat.Mode mode) { 31 | return EMPTY; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/dispatchers/EmptyProgramDispatcher.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.dispatchers; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.AcceleratedBufferBuilder; 4 | 5 | public class EmptyProgramDispatcher implements IPolygonProgramDispatcher { 6 | 7 | public static final EmptyProgramDispatcher INSTANCE = new EmptyProgramDispatcher(); 8 | 9 | @Override 10 | public int dispatch(AcceleratedBufferBuilder builder) { 11 | return 0; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/dispatchers/FixedPolygonProgramDispatcher.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.dispatchers; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.backends.programs.ComputeProgram; 4 | import com.github.argon4w.acceleratedrendering.core.backends.programs.Uniform; 5 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.AcceleratedBufferBuilder; 6 | import com.github.argon4w.acceleratedrendering.core.programs.ComputeShaderProgramLoader; 7 | import com.mojang.blaze3d.vertex.VertexFormat; 8 | import net.minecraft.resources.ResourceLocation; 9 | 10 | import static org.lwjgl.opengl.GL43.GL_SHADER_STORAGE_BUFFER; 11 | 12 | public class FixedPolygonProgramDispatcher implements IPolygonProgramDispatcher { 13 | 14 | private static final int GROUP_SIZE = 128; 15 | 16 | private final VertexFormat.Mode mode; 17 | private final ComputeProgram program; 18 | private final Uniform polygonCountUniform; 19 | private final Uniform vertexOffsetUniform; 20 | 21 | public FixedPolygonProgramDispatcher(VertexFormat.Mode mode, ComputeProgram program) { 22 | this.mode = mode; 23 | this.program = program; 24 | this.polygonCountUniform = this.program.getUniform("polygonCount"); 25 | this.vertexOffsetUniform = program.getUniform("vertexOffset"); 26 | } 27 | 28 | public FixedPolygonProgramDispatcher(VertexFormat.Mode mode, ResourceLocation key) { 29 | this(mode, ComputeShaderProgramLoader.getProgram(key)); 30 | } 31 | 32 | @Override 33 | public int dispatch(AcceleratedBufferBuilder builder) { 34 | int vertexCount = builder.getVertexCount(); 35 | int vertexOffset = builder.getVertexOffset(); 36 | int polygonCount = vertexCount / mode.primitiveLength; 37 | 38 | builder.getVaryingBuffer().bindBase(GL_SHADER_STORAGE_BUFFER, 3); 39 | 40 | polygonCountUniform.uploadUnsignedInt(polygonCount); 41 | vertexOffsetUniform.uploadUnsignedInt(vertexOffset); 42 | 43 | program.useProgram(); 44 | program.dispatch((polygonCount + GROUP_SIZE - 1) / GROUP_SIZE); 45 | program.resetProgram(); 46 | 47 | return program.getBarrierFlags(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/dispatchers/IPolygonProgramDispatcher.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.dispatchers; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.AcceleratedBufferBuilder; 4 | 5 | public interface IPolygonProgramDispatcher { 6 | 7 | int dispatch(AcceleratedBufferBuilder builder); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/dispatchers/TransformProgramDispatcher.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.dispatchers; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.backends.buffers.MappedBuffer; 4 | import com.github.argon4w.acceleratedrendering.core.backends.programs.ComputeProgram; 5 | import com.github.argon4w.acceleratedrendering.core.backends.programs.Uniform; 6 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.AcceleratedBufferBuilder; 7 | import com.github.argon4w.acceleratedrendering.core.programs.ComputeShaderProgramLoader; 8 | import net.minecraft.resources.ResourceLocation; 9 | 10 | import java.util.Collection; 11 | 12 | import static org.lwjgl.opengl.GL46.GL_SHADER_STORAGE_BUFFER; 13 | 14 | public class TransformProgramDispatcher { 15 | 16 | private static final int GROUP_SIZE = 128; 17 | 18 | private final ComputeProgram program; 19 | private final Uniform vertexCountUniform; 20 | private final Uniform vertexOffsetUniform; 21 | 22 | public TransformProgramDispatcher(ResourceLocation key) { 23 | this.program = ComputeShaderProgramLoader.getProgram(key); 24 | this.vertexCountUniform = program.getUniform("vertexCount"); 25 | this.vertexOffsetUniform = program.getUniform("vertexOffset"); 26 | } 27 | 28 | public void dispatch(Collection builders) { 29 | program.useProgram(); 30 | 31 | for (AcceleratedBufferBuilder builder : builders) { 32 | int vertexCount = builder.getVertexCount(); 33 | MappedBuffer vertexBuffer = builder.getVertexBuffer(); 34 | MappedBuffer varyingBuffer = builder.getVaryingBuffer(); 35 | 36 | vertexBuffer.flush(); 37 | varyingBuffer.flush(); 38 | 39 | vertexBuffer.bindBase(GL_SHADER_STORAGE_BUFFER, 0); 40 | varyingBuffer.bindBase(GL_SHADER_STORAGE_BUFFER, 3); 41 | 42 | vertexCountUniform.uploadUnsignedInt(vertexCount); 43 | vertexOffsetUniform.uploadUnsignedInt(builder.getVertexOffset()); 44 | 45 | program.dispatch((vertexCount + GROUP_SIZE - 1) / GROUP_SIZE); 46 | } 47 | 48 | program.resetProgram(); 49 | program.waitBarriers(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/extras/CompositeExtraVertex.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.extras; 2 | 3 | public class CompositeExtraVertex implements IExtraVertexData { 4 | 5 | private final IExtraVertexData left; 6 | private final IExtraVertexData right; 7 | 8 | public CompositeExtraVertex(IExtraVertexData left, IExtraVertexData right) { 9 | this.left = left; 10 | this.right = right; 11 | } 12 | 13 | @Override 14 | public void addExtraVertex(long address) { 15 | left.addExtraVertex(address); 16 | right.addExtraVertex(address); 17 | } 18 | 19 | @Override 20 | public void addExtraVarying(long address) { 21 | left.addExtraVarying(address); 22 | right.addExtraVarying(address); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/extras/EmptyExtraVertexData.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.extras; 2 | 3 | public class EmptyExtraVertexData implements IExtraVertexData { 4 | 5 | public static final EmptyExtraVertexData INSTANCE = new EmptyExtraVertexData(); 6 | 7 | @Override 8 | public void addExtraVertex(long address) { 9 | 10 | } 11 | 12 | @Override 13 | public void addExtraVarying(long address) { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/extras/FlagsExtraVertexData.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.extras; 2 | 3 | import org.lwjgl.system.MemoryUtil; 4 | 5 | public class FlagsExtraVertexData implements IExtraVertexData { 6 | 7 | private int data; 8 | 9 | public FlagsExtraVertexData() { 10 | this.data = 0; 11 | } 12 | 13 | public FlagsExtraVertexData(int bit) { 14 | this.data = 1 << bit; 15 | } 16 | 17 | public void set(int bit) { 18 | data |= 1 << bit; 19 | } 20 | 21 | public void reset(int bit) { 22 | data &= ~(1 << bit); 23 | } 24 | 25 | public void clear() { 26 | data = 0; 27 | } 28 | 29 | @Override 30 | public void addExtraVarying(long address) { 31 | MemoryUtil.memPutInt(address + 3L * 4L, data); 32 | } 33 | 34 | @Override 35 | public void addExtraVertex(long address) { 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/extras/IExtraVertexData.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.extras; 2 | 3 | public interface IExtraVertexData { 4 | 5 | void addExtraVertex(long address); 6 | void addExtraVarying(long address); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/processing/EmptyPolygonProcessor.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.processing; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.programs.dispatchers.EmptyProgramDispatcher; 4 | import com.github.argon4w.acceleratedrendering.core.programs.dispatchers.IPolygonProgramDispatcher; 5 | import com.github.argon4w.acceleratedrendering.core.programs.extras.EmptyExtraVertexData; 6 | import com.github.argon4w.acceleratedrendering.core.programs.extras.IExtraVertexData; 7 | import com.mojang.blaze3d.vertex.VertexFormat; 8 | 9 | public class EmptyPolygonProcessor implements IPolygonProcessor { 10 | 11 | public static final EmptyPolygonProcessor INSTANCE = new EmptyPolygonProcessor(); 12 | 13 | @Override 14 | public IPolygonProgramDispatcher select(VertexFormat.Mode mode) { 15 | return EmptyProgramDispatcher.INSTANCE; 16 | } 17 | 18 | @Override 19 | public IExtraVertexData getExtraVertex(VertexFormat.Mode mode) { 20 | return EmptyExtraVertexData.INSTANCE; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/processing/IPolygonProcessor.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.processing; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.programs.dispatchers.IPolygonProgramDispatcher; 4 | import com.github.argon4w.acceleratedrendering.core.programs.extras.IExtraVertexData; 5 | import com.mojang.blaze3d.vertex.VertexFormat; 6 | 7 | public interface IPolygonProcessor { 8 | 9 | IPolygonProgramDispatcher select(VertexFormat.Mode mode); 10 | IExtraVertexData getExtraVertex(VertexFormat.Mode mode); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/programs/processing/LoadPolygonProcessorEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.programs.processing; 2 | 3 | import com.mojang.blaze3d.vertex.VertexFormat; 4 | import net.neoforged.bus.api.Event; 5 | import net.neoforged.fml.event.IModBusEvent; 6 | 7 | import java.util.function.UnaryOperator; 8 | 9 | public class LoadPolygonProcessorEvent extends Event implements IModBusEvent { 10 | 11 | private final VertexFormat vertexFormat; 12 | 13 | private IPolygonProcessor processor; 14 | 15 | public LoadPolygonProcessorEvent(VertexFormat vertexFormat) { 16 | this.vertexFormat = vertexFormat; 17 | this.processor = EmptyPolygonProcessor.INSTANCE; 18 | } 19 | 20 | public void loadFor(VertexFormat vertexFormat, UnaryOperator selector) { 21 | if (this.vertexFormat == vertexFormat) { 22 | this.processor = selector.apply(this.processor); 23 | } 24 | } 25 | 26 | public IPolygonProcessor getProcessor() { 27 | return processor; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/utils/CullerUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.utils; 2 | 3 | import com.mojang.blaze3d.platform.NativeImage; 4 | import net.minecraft.util.FastColor; 5 | import net.minecraft.util.Mth; 6 | import org.joml.Vector2f; 7 | import org.joml.Vector3f; 8 | 9 | public class CullerUtils { 10 | 11 | public static boolean shouldCull(Vertex[] vertices, NativeImage texture) { 12 | if (texture == null) { 13 | return false; 14 | } 15 | 16 | if (vertices.length == 4) { 17 | Vector3f vertex0 = new Vector3f(vertices[0].getPosition()); 18 | Vector3f vector1 = new Vector3f(vertices[1].getPosition()).sub(vertex0); 19 | Vector3f vector2 = new Vector3f(vertices[2].getPosition()).sub(vertex0); 20 | Vector3f vector3 = new Vector3f(vertices[3].getPosition()).sub(vertex0); 21 | 22 | float length1 = vector1.cross(vector2).length(); 23 | float length2 = vector1.cross(vector3).length(); 24 | 25 | if (length1 == 0 && length2 == 0) { 26 | return true; 27 | } 28 | } 29 | 30 | float minU = 1.0f; 31 | float minV = 1.0f; 32 | 33 | float maxU = 0.0f; 34 | float maxV = 0.0f; 35 | 36 | for (Vertex vertex : vertices) { 37 | Vector2f uv = vertex.getUV(); 38 | 39 | float u = uv.x; 40 | float v = uv.y; 41 | 42 | u = u < 0 ? 1.0f + u : u; 43 | v = v < 0 ? 1.0f + v : v; 44 | 45 | minU = Math.min(minU, u); 46 | minV = Math.min(minV, v); 47 | maxU = Math.max(maxU, u); 48 | maxV = Math.max(maxV, v); 49 | } 50 | 51 | int minX = Math.max(0, Mth.floor(minU * texture.getWidth())); 52 | int minY = Math.max(0, Mth.floor(minV * texture.getHeight())); 53 | 54 | int maxX = Math.min(texture.getWidth(), Mth.ceil(maxU * texture.getWidth())); 55 | int maxY = Math.min(texture.getHeight(), Mth.ceil(maxV * texture.getHeight())); 56 | 57 | for (int x = minX; x < maxX; x++) { 58 | for (int y = minY; y < maxY; y++) { 59 | if (FastColor.ABGR32.alpha(texture.getPixelRGBA(x, y)) != 0) { 60 | return false; 61 | } 62 | } 63 | } 64 | 65 | return true; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/utils/DirectionUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.utils; 2 | 3 | import net.minecraft.core.Direction; 4 | 5 | public class DirectionUtils { 6 | 7 | public static final Direction[] FULL = new Direction[] { 8 | null, 9 | Direction.DOWN, 10 | Direction.UP, 11 | Direction.NORTH, 12 | Direction.SOUTH, 13 | Direction.WEST, 14 | Direction.EAST 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/utils/MemUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.utils; 2 | 3 | import net.minecraft.util.Mth; 4 | import org.joml.Matrix3f; 5 | import org.joml.Matrix4f; 6 | import org.lwjgl.system.MemoryUtil; 7 | 8 | public class MemUtils { 9 | 10 | public static void putNormal(long address, float value) { 11 | MemoryUtil.memPutByte(address, (byte) ((int) (Mth.clamp(value, -1.0F, 1.0F) * 127.0F) & 0xFF)); 12 | } 13 | 14 | public static void putMatrix3x4f(long address, Matrix3f matrix) { 15 | MemoryUtil.memPutFloat(address + 0L * 4L, matrix.m00()); 16 | MemoryUtil.memPutFloat(address + 1L * 4L, matrix.m01()); 17 | MemoryUtil.memPutFloat(address + 2L * 4L, matrix.m02()); 18 | 19 | MemoryUtil.memPutFloat(address + 4L * 4L, matrix.m10()); 20 | MemoryUtil.memPutFloat(address + 5L * 4L, matrix.m11()); 21 | MemoryUtil.memPutFloat(address + 6L * 4L, matrix.m12()); 22 | 23 | MemoryUtil.memPutFloat(address + 8L * 4L, matrix.m20()); 24 | MemoryUtil.memPutFloat(address + 9L * 4L, matrix.m21()); 25 | MemoryUtil.memPutFloat(address + 10L * 4L, matrix.m22()); 26 | } 27 | 28 | public static void putMatrix4f(long address, Matrix4f matrix) { 29 | MemoryUtil.memPutFloat(address + 0L * 4L, matrix.m00()); 30 | MemoryUtil.memPutFloat(address + 1L * 4L, matrix.m01()); 31 | MemoryUtil.memPutFloat(address + 2L * 4L, matrix.m02()); 32 | MemoryUtil.memPutFloat(address + 3L * 4L, matrix.m03()); 33 | 34 | MemoryUtil.memPutFloat(address + 4L * 4L, matrix.m10()); 35 | MemoryUtil.memPutFloat(address + 5L * 4L, matrix.m11()); 36 | MemoryUtil.memPutFloat(address + 6L * 4L, matrix.m12()); 37 | MemoryUtil.memPutFloat(address + 7L * 4L, matrix.m13()); 38 | 39 | MemoryUtil.memPutFloat(address + 8L * 4L, matrix.m20()); 40 | MemoryUtil.memPutFloat(address + 9L * 4L, matrix.m21()); 41 | MemoryUtil.memPutFloat(address + 10L * 4L, matrix.m22()); 42 | MemoryUtil.memPutFloat(address + 11L * 4L, matrix.m23()); 43 | 44 | MemoryUtil.memPutFloat(address + 12L * 4L, matrix.m30()); 45 | MemoryUtil.memPutFloat(address + 13L * 4L, matrix.m31()); 46 | MemoryUtil.memPutFloat(address + 14L * 4L, matrix.m32()); 47 | MemoryUtil.memPutFloat(address + 15L * 4L, matrix.m33()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/utils/MutableSize.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.utils; 2 | 3 | public class MutableSize { 4 | 5 | protected boolean resized; 6 | protected long size; 7 | 8 | public MutableSize(long initialSize) { 9 | this.resized = false; 10 | this.size = initialSize; 11 | } 12 | 13 | public void expand(long bytes) { 14 | if (bytes <= 0) { 15 | return; 16 | } 17 | 18 | beforeExpand(); 19 | onExpand(bytes); 20 | doExpand(size, bytes); 21 | 22 | resized = true; 23 | size += bytes; 24 | 25 | afterExpand(); 26 | } 27 | 28 | public void onExpand(long bytes) { 29 | 30 | } 31 | 32 | public void doExpand(long size, long bytes) { 33 | 34 | } 35 | 36 | public void beforeExpand() { 37 | 38 | } 39 | 40 | public void afterExpand() { 41 | 42 | } 43 | 44 | public void resize(long atLeast) { 45 | resizeTo(Long.highestOneBit(atLeast) << 1); 46 | } 47 | 48 | public void resizeTo(long newBufferSize) { 49 | expand(newBufferSize - size); 50 | } 51 | 52 | public long getSize() { 53 | return size; 54 | } 55 | 56 | public boolean isResized() { 57 | return resized; 58 | } 59 | 60 | public void resetResized() { 61 | resized = false; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/utils/RenderTypeUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.utils; 2 | 3 | import net.minecraft.client.renderer.RenderType; 4 | import net.minecraft.resources.ResourceLocation; 5 | 6 | public class RenderTypeUtils { 7 | 8 | public static ResourceLocation getTextureLocation(RenderType renderType) { 9 | if (renderType == null) { 10 | return null; 11 | } 12 | 13 | if (!(renderType instanceof RenderType.CompositeRenderType composite)) { 14 | return null; 15 | } 16 | 17 | return composite 18 | .state 19 | .textureState 20 | .cutoutTexture() 21 | .orElse(null); 22 | } 23 | 24 | public static boolean isCulled(RenderType renderType) { 25 | if (renderType == null) { 26 | return false; 27 | } 28 | 29 | if (!(renderType instanceof RenderType.CompositeRenderType composite)) { 30 | return false; 31 | } 32 | 33 | return composite 34 | .state 35 | .cullState 36 | .enabled; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/utils/ResourceLocationUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.utils; 2 | 3 | import com.github.argon4w.acceleratedrendering.AcceleratedRenderingModEntry; 4 | import net.minecraft.resources.ResourceLocation; 5 | 6 | public class ResourceLocationUtils { 7 | 8 | public static ResourceLocation create(String path) { 9 | return ResourceLocation.fromNamespaceAndPath(AcceleratedRenderingModEntry.MOD_ID, path); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/utils/SimpleResetPool.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.utils; 2 | 3 | public abstract class SimpleResetPool { 4 | 5 | private final int size; 6 | private final Object[] pool; 7 | private final C context; 8 | 9 | private int cursor; 10 | 11 | public SimpleResetPool(int size, C context) { 12 | this.size = size; 13 | this.pool = new Object[size]; 14 | this.context = context; 15 | 16 | this.cursor = 0; 17 | 18 | for (int i = 0; i < this.size; i++) { 19 | this.pool[i] = create(this.context, i); 20 | } 21 | } 22 | 23 | protected abstract T create(C context, int i); 24 | protected abstract void reset(T t); 25 | protected abstract void delete(T t); 26 | 27 | @SuppressWarnings("unchecked") 28 | public T get() { 29 | if (cursor < size) { 30 | return (T) pool[cursor ++]; 31 | } 32 | 33 | return fail(); 34 | } 35 | 36 | @SuppressWarnings("unchecked") 37 | public void reset() { 38 | for (int i = 0; i < cursor; i++) { 39 | reset((T) pool[i]); 40 | } 41 | 42 | cursor = 0; 43 | } 44 | 45 | @SuppressWarnings("unchecked") 46 | public void delete() { 47 | for (int i = 0; i < size; i++) { 48 | delete((T) pool[i]); 49 | } 50 | } 51 | 52 | public T fail() { 53 | return null; 54 | } 55 | 56 | public C getContext() { 57 | return context; 58 | } 59 | } -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/utils/TextureUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.utils; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.CoreFeature; 4 | import com.mojang.blaze3d.platform.NativeImage; 5 | import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; 6 | import net.minecraft.client.Minecraft; 7 | import net.minecraft.client.renderer.RenderType; 8 | import net.minecraft.resources.ResourceLocation; 9 | import org.lwjgl.system.MemoryStack; 10 | 11 | import java.nio.IntBuffer; 12 | 13 | import static org.lwjgl.opengl.GL46.*; 14 | 15 | public class TextureUtils { 16 | 17 | private static final Object2ObjectLinkedOpenHashMap IMAGES = new Object2ObjectLinkedOpenHashMap<>(); 18 | 19 | public static NativeImage downloadTexture(RenderType renderType, int mipmapLevel) { 20 | ResourceLocation textureResourceLocation = RenderTypeUtils.getTextureLocation(renderType); 21 | 22 | if (textureResourceLocation == null) { 23 | return null; 24 | } 25 | 26 | 27 | NativeImage image = IMAGES.getAndMoveToFirst(textureResourceLocation); 28 | 29 | if (image != null) { 30 | return image; 31 | } 32 | 33 | Minecraft 34 | .getInstance() 35 | .getTextureManager() 36 | .getTexture(textureResourceLocation) 37 | .bind(); 38 | 39 | try (MemoryStack stack = MemoryStack.stackPush()) { 40 | IntBuffer widthBuffer = stack.callocInt(1); 41 | IntBuffer heightBuffer = stack.callocInt(1); 42 | 43 | glGetTexLevelParameteriv( 44 | GL_TEXTURE_2D, 45 | mipmapLevel, 46 | GL_TEXTURE_WIDTH, 47 | widthBuffer 48 | ); 49 | 50 | glGetTexLevelParameteriv( 51 | GL_TEXTURE_2D, 52 | mipmapLevel, 53 | GL_TEXTURE_HEIGHT, 54 | heightBuffer 55 | ); 56 | 57 | int width = widthBuffer.get(0); 58 | int height = heightBuffer.get(0); 59 | 60 | if (width == 0 || height == 0) { 61 | return null; 62 | } 63 | 64 | NativeImage nativeImage = new NativeImage( 65 | width, 66 | height, 67 | false 68 | ); 69 | 70 | nativeImage.downloadTexture(mipmapLevel, false); 71 | 72 | IMAGES.putAndMoveToFirst(textureResourceLocation, nativeImage); 73 | 74 | if (IMAGES.size() > CoreFeature.getCachedImageSize()) { 75 | IMAGES.removeLast().close(); 76 | } 77 | 78 | return nativeImage; 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/utils/Vertex.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.utils; 2 | 3 | import net.minecraft.util.FastColor; 4 | import org.joml.Vector2f; 5 | import org.joml.Vector2i; 6 | import org.joml.Vector3f; 7 | import org.joml.Vector4i; 8 | 9 | public class Vertex { 10 | 11 | private final Vector3f position; 12 | private final Vector2f uv; 13 | private final Vector4i color; 14 | private final Vector2i light; 15 | private final Vector3f normal; 16 | 17 | public Vertex() { 18 | this.position = new Vector3f(); 19 | this.uv = new Vector2f(); 20 | this.color = new Vector4i(); 21 | this.light = new Vector2i(); 22 | this.normal = new Vector3f(); 23 | } 24 | 25 | public Vector3f getPosition() { 26 | return position; 27 | } 28 | 29 | public Vector2f getUV() { 30 | return uv; 31 | } 32 | 33 | public Vector3f getNormal() { 34 | return normal; 35 | } 36 | 37 | public Vector4i getColor() { 38 | return color; 39 | } 40 | 41 | public Vector2i getLight() { 42 | return light; 43 | } 44 | 45 | public int getPackedLight() { 46 | return light.x | light.y << 16; 47 | } 48 | 49 | public int getPackedColor() { 50 | return FastColor.ARGB32.color( 51 | color.w, 52 | color.x, 53 | color.y, 54 | color.z 55 | ); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/core/utils/VertexFormatUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.core.utils; 2 | 3 | import com.mojang.blaze3d.vertex.VertexFormat; 4 | import it.unimi.dsi.fastutil.objects.Reference2IntMap; 5 | import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap; 6 | 7 | public class VertexFormatUtils { 8 | 9 | private static final Reference2IntMap CACHE = new Reference2IntOpenHashMap<>(); 10 | 11 | public static int hashCodeFast(VertexFormat format) { 12 | int result = CACHE.getInt(format); 13 | 14 | if (result == 0) { 15 | result = format.hashCode(); 16 | CACHE.put(format, result); 17 | } 18 | 19 | return result; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/blocks/AcceleratedBlockEntityRenderingFeature.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.blocks; 2 | 3 | import com.github.argon4w.acceleratedrendering.configs.FeatureConfig; 4 | import com.github.argon4w.acceleratedrendering.configs.FeatureStatus; 5 | import com.github.argon4w.acceleratedrendering.configs.PipelineSetting; 6 | import com.github.argon4w.acceleratedrendering.core.meshes.IMesh; 7 | import com.github.argon4w.acceleratedrendering.core.meshes.MeshType; 8 | 9 | import java.util.ArrayDeque; 10 | import java.util.Deque; 11 | 12 | public class AcceleratedBlockEntityRenderingFeature { 13 | 14 | private static final Deque PIPELINE_CONTROLLER_STACK = new ArrayDeque<>(); 15 | 16 | public static boolean isEnabled() { 17 | return FeatureConfig.CONFIG.acceleratedBlockEntityRenderingFeatureStatus.get() == FeatureStatus.ENABLED; 18 | } 19 | 20 | public static boolean shouldUseAcceleratedPipeline() { 21 | return getPipelineSetting() == PipelineSetting.ACCELERATED; 22 | } 23 | 24 | public static MeshType getMeshType() { 25 | return FeatureConfig.CONFIG.acceleratedBlockEntityRenderingMeshType.get(); 26 | } 27 | 28 | public static IMesh.Builder getMeshBuilder() { 29 | return getMeshType().getBuilder(); 30 | } 31 | 32 | public static void useVanillaPipeline() { 33 | PIPELINE_CONTROLLER_STACK.push(PipelineSetting.VANILLA); 34 | } 35 | 36 | public static void forceUseAcceleratedPipeline() { 37 | PIPELINE_CONTROLLER_STACK.push(PipelineSetting.ACCELERATED); 38 | } 39 | 40 | public static void forceSetPipeline(PipelineSetting pipeline) { 41 | PIPELINE_CONTROLLER_STACK.push(pipeline); 42 | } 43 | 44 | public static void resetPipelineSetting() { 45 | PIPELINE_CONTROLLER_STACK.pop(); 46 | } 47 | 48 | public static PipelineSetting getPipelineSetting() { 49 | return PIPELINE_CONTROLLER_STACK.isEmpty() ? getDefaultPipelineSetting() : PIPELINE_CONTROLLER_STACK.peek(); 50 | } 51 | 52 | public static PipelineSetting getDefaultPipelineSetting() { 53 | return FeatureConfig.CONFIG.acceleratedBlockEntityRenderingDefaultPipeline.get(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/culling/OrientationCullingFeature.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.culling; 2 | 3 | import com.github.argon4w.acceleratedrendering.configs.FeatureConfig; 4 | import com.github.argon4w.acceleratedrendering.configs.FeatureStatus; 5 | 6 | import java.util.ArrayDeque; 7 | import java.util.Deque; 8 | 9 | public class OrientationCullingFeature { 10 | 11 | private static final Deque CULLING_CONTROLLER_STACK = new ArrayDeque<>(); 12 | 13 | public static boolean isEnabled() { 14 | return FeatureConfig.CONFIG.orientationCullingFeatureStatus.get() == FeatureStatus.ENABLED; 15 | } 16 | 17 | public static boolean shouldIgnoreCullState() { 18 | return FeatureConfig.CONFIG.orientationCullingIgnoreCullState.get() == FeatureStatus.ENABLED; 19 | } 20 | 21 | public static boolean shouldCull() { 22 | return getCullingSetting() == FeatureStatus.ENABLED; 23 | } 24 | 25 | public static void disableCulling() { 26 | CULLING_CONTROLLER_STACK.push(FeatureStatus.DISABLED); 27 | } 28 | 29 | public static void forceEnableCulling() { 30 | CULLING_CONTROLLER_STACK.push(FeatureStatus.ENABLED); 31 | } 32 | 33 | public static void forceSetCulling(FeatureStatus culling) { 34 | CULLING_CONTROLLER_STACK.push(culling); 35 | } 36 | 37 | public static void resetCullingSetting() { 38 | CULLING_CONTROLLER_STACK.pop(); 39 | } 40 | 41 | public static FeatureStatus getCullingSetting() { 42 | return CULLING_CONTROLLER_STACK.isEmpty() ? getDefaultCullingSetting() : CULLING_CONTROLLER_STACK.peek(); 43 | } 44 | 45 | public static FeatureStatus getDefaultCullingSetting() { 46 | return FeatureConfig.CONFIG.orientationCullingDefaultCulling.get(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/culling/OrientationCullingProgramDispatcher.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.culling; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.backends.programs.ComputeProgram; 4 | import com.github.argon4w.acceleratedrendering.core.backends.programs.Uniform; 5 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.AcceleratedBufferBuilder; 6 | import com.github.argon4w.acceleratedrendering.core.programs.ComputeShaderProgramLoader; 7 | import com.github.argon4w.acceleratedrendering.core.programs.dispatchers.IPolygonProgramDispatcher; 8 | import com.mojang.blaze3d.systems.RenderSystem; 9 | import com.mojang.blaze3d.vertex.VertexFormat; 10 | import net.minecraft.resources.ResourceLocation; 11 | 12 | public class OrientationCullingProgramDispatcher implements IPolygonProgramDispatcher { 13 | 14 | private static final int GROUP_SIZE = 128; 15 | 16 | private final VertexFormat.Mode mode; 17 | private final ComputeProgram program; 18 | private final Uniform viewMatrixUniform; 19 | private final Uniform projectMatrixUniform; 20 | private final Uniform polygonCountUniform; 21 | private final Uniform vertexOffsetUniform; 22 | 23 | public OrientationCullingProgramDispatcher(VertexFormat.Mode mode, ResourceLocation key) { 24 | this.mode = mode; 25 | this.program = ComputeShaderProgramLoader.getProgram(key); 26 | this.viewMatrixUniform = this.program.getUniform("viewMatrix"); 27 | this.projectMatrixUniform = this.program.getUniform("projectMatrix"); 28 | this.polygonCountUniform = this.program.getUniform("polygonCount"); 29 | this.vertexOffsetUniform = program.getUniform("vertexOffset"); 30 | } 31 | 32 | @Override 33 | public int dispatch(AcceleratedBufferBuilder builder) { 34 | int vertexCount = builder.getVertexCount(); 35 | int vertexOffset = builder.getVertexOffset(); 36 | int polygonCount = vertexCount / mode.primitiveLength; 37 | 38 | viewMatrixUniform.uploadMatrix4f(RenderSystem.getModelViewMatrix()); 39 | projectMatrixUniform.uploadMatrix4f(RenderSystem.getProjectionMatrix()); 40 | polygonCountUniform.uploadUnsignedInt(polygonCount); 41 | vertexOffsetUniform.uploadUnsignedInt(vertexOffset); 42 | 43 | program.useProgram(); 44 | program.dispatch((polygonCount + GROUP_SIZE - 1) / GROUP_SIZE); 45 | program.resetProgram(); 46 | 47 | return program.getBarrierFlags(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/culling/OrientationCullingProgramSelector.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.culling; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.programs.culling.ICullingProgramSelector; 4 | import com.github.argon4w.acceleratedrendering.core.programs.dispatchers.IPolygonProgramDispatcher; 5 | import com.github.argon4w.acceleratedrendering.core.programs.extras.FlagsExtraVertexData; 6 | import com.github.argon4w.acceleratedrendering.core.programs.extras.IExtraVertexData; 7 | import com.github.argon4w.acceleratedrendering.core.utils.RenderTypeUtils; 8 | import com.mojang.blaze3d.vertex.VertexFormat; 9 | import net.minecraft.client.renderer.RenderType; 10 | import net.minecraft.resources.ResourceLocation; 11 | 12 | public class OrientationCullingProgramSelector implements ICullingProgramSelector { 13 | 14 | public static final FlagsExtraVertexData EMPTY = new FlagsExtraVertexData(); 15 | public static final FlagsExtraVertexData NO_CULL = new FlagsExtraVertexData(0); 16 | 17 | private final ICullingProgramSelector parent; 18 | private final VertexFormat.Mode mode; 19 | private final IPolygonProgramDispatcher dispatcher; 20 | 21 | public OrientationCullingProgramSelector( 22 | ICullingProgramSelector parent, 23 | VertexFormat.Mode mode, 24 | ResourceLocation key 25 | ) { 26 | this.parent = parent; 27 | this.mode = mode; 28 | this.dispatcher = new OrientationCullingProgramDispatcher(mode, key); 29 | } 30 | 31 | @Override 32 | public IPolygonProgramDispatcher select(RenderType renderType) { 33 | if (!OrientationCullingFeature.isEnabled()) { 34 | return parent.select(renderType); 35 | } 36 | 37 | if (this.mode != renderType.mode) { 38 | return parent.select(renderType); 39 | } 40 | 41 | if (OrientationCullingFeature.shouldIgnoreCullState()) { 42 | return dispatcher; 43 | } 44 | 45 | if (RenderTypeUtils.isCulled(renderType)) { 46 | return dispatcher; 47 | } 48 | 49 | return parent.select(renderType); 50 | } 51 | 52 | @Override 53 | public IExtraVertexData getExtraVertex(VertexFormat.Mode mode) { 54 | if (!OrientationCullingFeature.isEnabled()) { 55 | return parent.getExtraVertex(mode); 56 | } 57 | 58 | if (this.mode != mode) { 59 | return parent.getExtraVertex(mode); 60 | } 61 | 62 | if (!OrientationCullingFeature.shouldCull()) { 63 | return EMPTY; 64 | } 65 | 66 | return NO_CULL; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/entities/AcceleratedEntityRenderingFeature.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.entities; 2 | 3 | import com.github.argon4w.acceleratedrendering.configs.FeatureConfig; 4 | import com.github.argon4w.acceleratedrendering.configs.FeatureStatus; 5 | import com.github.argon4w.acceleratedrendering.configs.PipelineSetting; 6 | import com.github.argon4w.acceleratedrendering.core.meshes.MeshType; 7 | 8 | import java.util.ArrayDeque; 9 | import java.util.Deque; 10 | 11 | public class AcceleratedEntityRenderingFeature { 12 | 13 | private static final Deque PIPELINE_CONTROLLER_STACK = new ArrayDeque<>(); 14 | 15 | public static boolean isEnabled() { 16 | return FeatureConfig.CONFIG.acceleratedEntityRenderingFeatureStatus.get() == FeatureStatus.ENABLED; 17 | } 18 | 19 | public static boolean shouldUseAcceleratedPipeline() { 20 | return getPipelineSetting() == PipelineSetting.ACCELERATED; 21 | } 22 | 23 | public static MeshType getMeshType() { 24 | return FeatureConfig.CONFIG.acceleratedEntityRenderingMeshType.get(); 25 | } 26 | 27 | public static void useVanillaPipeline() { 28 | PIPELINE_CONTROLLER_STACK.push(PipelineSetting.VANILLA); 29 | } 30 | 31 | public static void forceUseAcceleratedPipeline() { 32 | PIPELINE_CONTROLLER_STACK.push(PipelineSetting.ACCELERATED); 33 | } 34 | 35 | public static void forceSetPipeline(PipelineSetting pipeline) { 36 | PIPELINE_CONTROLLER_STACK.push(pipeline); 37 | } 38 | 39 | public static void resetPipelineSetting() { 40 | PIPELINE_CONTROLLER_STACK.pop(); 41 | } 42 | 43 | public static PipelineSetting getPipelineSetting() { 44 | return PIPELINE_CONTROLLER_STACK.isEmpty() ? getDefaultPipelineSetting() : PIPELINE_CONTROLLER_STACK.peek(); 45 | } 46 | 47 | public static PipelineSetting getDefaultPipelineSetting() { 48 | return FeatureConfig.CONFIG.acceleratedEntityRenderingDefaultPipeline.get(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/entities/mixins/EntityRenderDispatcherMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.entities.mixins; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.IAcceleratedVertexConsumer; 4 | import com.github.argon4w.acceleratedrendering.features.entities.AcceleratedEntityRenderingFeature; 5 | import com.github.argon4w.acceleratedrendering.features.entities.AcceleratedEntityShadowRenderer; 6 | import com.mojang.blaze3d.vertex.PoseStack; 7 | import com.mojang.blaze3d.vertex.VertexConsumer; 8 | import net.minecraft.client.renderer.LightTexture; 9 | import net.minecraft.client.renderer.entity.EntityRenderDispatcher; 10 | import net.minecraft.client.renderer.texture.OverlayTexture; 11 | import net.minecraft.core.BlockPos; 12 | import net.minecraft.world.level.LevelReader; 13 | import net.minecraft.world.level.chunk.ChunkAccess; 14 | import org.joml.Matrix3f; 15 | import org.joml.Vector3f; 16 | import org.spongepowered.asm.mixin.Mixin; 17 | import org.spongepowered.asm.mixin.Unique; 18 | import org.spongepowered.asm.mixin.injection.At; 19 | import org.spongepowered.asm.mixin.injection.Inject; 20 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 21 | 22 | @Mixin(value = EntityRenderDispatcher.class, priority = 999) 23 | public class EntityRenderDispatcherMixin { 24 | 25 | @Unique private static final Matrix3f SHADOW_NORMAL_MATRIX = new Matrix3f().identity(); 26 | @Unique private static final AcceleratedEntityShadowRenderer SHADOW_RENDERER = new AcceleratedEntityShadowRenderer(); 27 | 28 | @Inject(method = "renderBlockShadow", at = @At("HEAD"), cancellable = true) 29 | private static void fastBlockShadow( 30 | PoseStack.Pose pPose, 31 | VertexConsumer pVertexConsumer, 32 | ChunkAccess pChunk, 33 | LevelReader pLevel, 34 | BlockPos pPos, 35 | double pX, 36 | double pY, 37 | double pZ, 38 | float pSize, 39 | float pWeight, 40 | CallbackInfo ci 41 | ) { 42 | IAcceleratedVertexConsumer extension = (IAcceleratedVertexConsumer) pVertexConsumer; 43 | 44 | if (!AcceleratedEntityRenderingFeature.isEnabled()) { 45 | return; 46 | } 47 | 48 | if (!AcceleratedEntityRenderingFeature.shouldUseAcceleratedPipeline()) { 49 | return; 50 | } 51 | 52 | if (!extension.isAccelerated()) { 53 | return; 54 | } 55 | 56 | ci.cancel(); 57 | extension.doRender( 58 | SHADOW_RENDERER, 59 | new AcceleratedEntityShadowRenderer.Context( 60 | pLevel, 61 | pChunk, 62 | pPos, 63 | new Vector3f((float) pX, (float) pY, (float) pZ), 64 | pSize, 65 | pWeight 66 | ), 67 | pPose.pose(), 68 | SHADOW_NORMAL_MATRIX, 69 | LightTexture.FULL_BRIGHT, 70 | OverlayTexture.NO_OVERLAY, 71 | -1 72 | ); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/entities/mixins/ShadowRendererMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.entities.mixins; 2 | 3 | import com.github.argon4w.acceleratedrendering.compat.iris.IShadowBufferSourceGetter; 4 | import com.github.argon4w.acceleratedrendering.compat.iris.IrisCompatFeature; 5 | import com.github.argon4w.acceleratedrendering.features.entities.AcceleratedEntityRenderingFeature; 6 | import net.irisshaders.iris.shadows.ShadowRenderer; 7 | import net.minecraft.client.renderer.MultiBufferSource; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.Pseudo; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.ModifyArg; 12 | 13 | @Pseudo 14 | @Mixin(ShadowRenderer.class) 15 | public class ShadowRendererMixin { 16 | 17 | @ModifyArg(method = "renderShadows", at = @At(value = "INVOKE", target = "Lnet/irisshaders/iris/shadows/ShadowRenderer;renderEntities(Lnet/irisshaders/iris/mixin/LevelRendererAccessor;Lnet/minecraft/client/renderer/entity/EntityRenderDispatcher;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lcom/mojang/blaze3d/vertex/PoseStack;FLnet/minecraft/client/renderer/culling/Frustum;DDD)I"), index = 2) 18 | public MultiBufferSource.BufferSource useAcceleratedBufferSource(MultiBufferSource.BufferSource bufferSource) { 19 | if (!IrisCompatFeature.isIrisCompatEntitiesEnabled()) { 20 | return bufferSource; 21 | } 22 | 23 | if (!AcceleratedEntityRenderingFeature.isEnabled()) { 24 | return bufferSource; 25 | } 26 | 27 | return ((IShadowBufferSourceGetter) this).getShadowBufferSource(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/items/AcceleratedItemRenderContext.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.items; 2 | 3 | import com.github.argon4w.acceleratedrendering.features.items.mixins.ItemColorsAccessor; 4 | import net.minecraft.client.Minecraft; 5 | import net.minecraft.client.color.item.ItemColor; 6 | import net.minecraft.client.resources.model.BakedModel; 7 | import net.minecraft.util.RandomSource; 8 | import net.minecraft.world.item.ItemStack; 9 | 10 | public class AcceleratedItemRenderContext { 11 | 12 | private final ItemStack itemStack; 13 | private final ItemColor itemColor; 14 | private final BakedModel bakedModel; 15 | private final RandomSource random; 16 | 17 | public AcceleratedItemRenderContext( 18 | ItemStack itemStack, 19 | BakedModel bakedModel, 20 | RandomSource random 21 | ) { 22 | this.itemStack = itemStack; 23 | this.itemColor = ((ItemColorsAccessor) Minecraft.getInstance().getItemColors()).getItemColors().getOrDefault(itemStack.getItem(), EmptyItemColor.INSTANCE); 24 | this.bakedModel = bakedModel; 25 | this.random = random; 26 | } 27 | 28 | public ItemStack getItemStack() { 29 | return itemStack; 30 | } 31 | 32 | public ItemColor getItemColor() { 33 | return itemColor; 34 | } 35 | 36 | public BakedModel getBakedModel() { 37 | return bakedModel; 38 | } 39 | 40 | public RandomSource getRandom() { 41 | return random; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/items/AcceleratedItemRenderingFeature.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.items; 2 | 3 | import com.github.argon4w.acceleratedrendering.configs.FeatureConfig; 4 | import com.github.argon4w.acceleratedrendering.configs.FeatureStatus; 5 | import com.github.argon4w.acceleratedrendering.configs.PipelineSetting; 6 | import com.github.argon4w.acceleratedrendering.core.meshes.MeshType; 7 | 8 | import java.util.ArrayDeque; 9 | import java.util.Deque; 10 | 11 | public class AcceleratedItemRenderingFeature { 12 | 13 | private static final Deque PIPELINE_CONTROLLER_STACK = new ArrayDeque<>(); 14 | private static final Deque BAKE_QUAD_MESH_CONTROLLER_STACK = new ArrayDeque<>(); 15 | 16 | public static boolean isEnabled() { 17 | return FeatureConfig.CONFIG.acceleratedItemRenderingFeatureStatus.get() == FeatureStatus.ENABLED; 18 | } 19 | 20 | public static boolean shouldUseAcceleratedPipeline() { 21 | return getPipelineSetting() == PipelineSetting.ACCELERATED; 22 | } 23 | 24 | public static boolean shouldBakeMeshForQuad() { 25 | return getBakeQuadMeshSetting() == FeatureStatus.ENABLED; 26 | } 27 | 28 | public static MeshType getMeshType() { 29 | return FeatureConfig.CONFIG.acceleratedItemRenderingMeshType.get(); 30 | } 31 | 32 | public static void useVanillaPipeline() { 33 | PIPELINE_CONTROLLER_STACK.push(PipelineSetting.VANILLA); 34 | } 35 | 36 | public static void dontBakeMeshForQuad() { 37 | BAKE_QUAD_MESH_CONTROLLER_STACK.push(FeatureStatus.DISABLED); 38 | } 39 | 40 | public static void forceUseAcceleratedPipeline() { 41 | PIPELINE_CONTROLLER_STACK.push(PipelineSetting.ACCELERATED); 42 | } 43 | 44 | public static void forceBakeMeshForQuad() { 45 | BAKE_QUAD_MESH_CONTROLLER_STACK.push(FeatureStatus.ENABLED); 46 | } 47 | 48 | public static void forceSetPipeline(PipelineSetting pipeline) { 49 | PIPELINE_CONTROLLER_STACK.push(pipeline); 50 | } 51 | 52 | public static void forceSetBakeQuadMeshSetting(FeatureStatus status) { 53 | BAKE_QUAD_MESH_CONTROLLER_STACK.push(status); 54 | } 55 | 56 | public static void resetPipelineSetting() { 57 | PIPELINE_CONTROLLER_STACK.pop(); 58 | } 59 | 60 | public static void resetBakeQuadMeshSetting() { 61 | BAKE_QUAD_MESH_CONTROLLER_STACK.pop(); 62 | } 63 | 64 | public static PipelineSetting getPipelineSetting() { 65 | return PIPELINE_CONTROLLER_STACK.isEmpty() ? getDefaultPipelineSetting() : PIPELINE_CONTROLLER_STACK.peek(); 66 | } 67 | 68 | public static FeatureStatus getBakeQuadMeshSetting() { 69 | return BAKE_QUAD_MESH_CONTROLLER_STACK.isEmpty() ? getDefaultBakeQuadMeshSetting() : BAKE_QUAD_MESH_CONTROLLER_STACK.peek(); 70 | } 71 | 72 | public static PipelineSetting getDefaultPipelineSetting() { 73 | return FeatureConfig.CONFIG.acceleratedItemRenderingDefaultPipeline.get(); 74 | } 75 | 76 | public static FeatureStatus getDefaultBakeQuadMeshSetting() { 77 | return FeatureConfig.CONFIG.acceleratedItemRenderingBakeMeshForQuads.get(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/items/EmptyItemColor.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.items; 2 | 3 | import net.minecraft.client.color.item.ItemColor; 4 | import net.minecraft.world.item.ItemStack; 5 | 6 | public class EmptyItemColor implements ItemColor { 7 | 8 | public static final ItemColor INSTANCE = new EmptyItemColor(); 9 | 10 | @Override 11 | public int getColor(ItemStack pStack, int pTintIndex) { 12 | return -1; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/items/IAcceleratedBakedModel.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.items; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.IAcceleratedVertexConsumer; 4 | import com.mojang.blaze3d.vertex.PoseStack; 5 | import net.minecraft.world.item.ItemStack; 6 | 7 | public interface IAcceleratedBakedModel { 8 | 9 | void renderItemFast(ItemStack itemStack, PoseStack poseStack, IAcceleratedVertexConsumer extension, int combinedLight, int combinedOverlay); 10 | boolean isAccelerated(); 11 | int getCustomColor(int layer, int color); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/items/IAcceleratedBakedQuad.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.items; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.IAcceleratedVertexConsumer; 4 | import org.joml.Matrix3f; 5 | import org.joml.Matrix4f; 6 | 7 | public interface IAcceleratedBakedQuad { 8 | 9 | void renderFast(Matrix4f transform, Matrix3f normal, IAcceleratedVertexConsumer extension, int combinedLight, int combinedOverlay, int color); 10 | int getCustomColor(int color); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/items/mixins/BakedModelMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.items.mixins; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.IAcceleratedVertexConsumer; 4 | import com.github.argon4w.acceleratedrendering.features.items.IAcceleratedBakedModel; 5 | import com.mojang.blaze3d.vertex.PoseStack; 6 | import net.minecraft.client.resources.model.BakedModel; 7 | import net.minecraft.world.item.ItemStack; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.Unique; 10 | 11 | @Mixin(BakedModel.class) 12 | public interface BakedModelMixin extends IAcceleratedBakedModel { 13 | 14 | @Unique 15 | @Override 16 | default void renderItemFast( 17 | ItemStack itemStack, 18 | PoseStack poseStack, 19 | IAcceleratedVertexConsumer vertexConsumer, 20 | int combinedLight, 21 | int combinedOverlay 22 | ) { 23 | throw new UnsupportedOperationException("Unsupported Operation."); 24 | } 25 | 26 | @Override 27 | default boolean isAccelerated() { 28 | return false; 29 | } 30 | 31 | @Unique 32 | @Override 33 | default int getCustomColor(int layer, int color) { 34 | return color; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/items/mixins/ItemColorsAccessor.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.items.mixins; 2 | 3 | import net.minecraft.client.color.item.ItemColor; 4 | import net.minecraft.client.color.item.ItemColors; 5 | import net.minecraft.world.item.Item; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.gen.Accessor; 8 | 9 | import java.util.Map; 10 | 11 | @Mixin(ItemColors.class) 12 | public interface ItemColorsAccessor { 13 | 14 | @Accessor("itemColors") 15 | Map getItemColors(); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/text/AcceleratedTextRenderingFeature.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.text; 2 | 3 | import com.github.argon4w.acceleratedrendering.configs.FeatureConfig; 4 | import com.github.argon4w.acceleratedrendering.configs.FeatureStatus; 5 | import com.github.argon4w.acceleratedrendering.configs.PipelineSetting; 6 | import com.github.argon4w.acceleratedrendering.core.meshes.MeshType; 7 | 8 | import java.util.ArrayDeque; 9 | import java.util.Deque; 10 | 11 | public class AcceleratedTextRenderingFeature { 12 | 13 | private static final Deque PIPELINE_CONTROLLER_STACK = new ArrayDeque<>(); 14 | 15 | public static boolean isEnabled() { 16 | return FeatureConfig.CONFIG.acceleratedTextRenderingFeatureStatus.get() == FeatureStatus.ENABLED; 17 | } 18 | 19 | public static boolean shouldUseAcceleratedPipeline() { 20 | return getPipelineSetting() == PipelineSetting.ACCELERATED; 21 | } 22 | 23 | public static MeshType getMeshType() { 24 | return FeatureConfig.CONFIG.acceleratedTextRenderingMeshType.get(); 25 | } 26 | 27 | public static void useVanillaPipeline() { 28 | PIPELINE_CONTROLLER_STACK.push(PipelineSetting.VANILLA); 29 | } 30 | 31 | public static void forceUseAcceleratedPipeline() { 32 | PIPELINE_CONTROLLER_STACK.push(PipelineSetting.ACCELERATED); 33 | } 34 | 35 | public static void forceSetPipeline(PipelineSetting pipeline) { 36 | PIPELINE_CONTROLLER_STACK.push(pipeline); 37 | } 38 | 39 | public static void resetPipelineSetting() { 40 | PIPELINE_CONTROLLER_STACK.pop(); 41 | } 42 | 43 | public static PipelineSetting getPipelineSetting() { 44 | return PIPELINE_CONTROLLER_STACK.isEmpty() ? getDefaultPipelineSetting() : PIPELINE_CONTROLLER_STACK.peek(); 45 | } 46 | 47 | public static PipelineSetting getDefaultPipelineSetting() { 48 | return FeatureConfig.CONFIG.acceleratedTextRenderingDefaultPipeline.get(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/text/mixins/BakedGlyphMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.text.mixins; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.IAcceleratedVertexConsumer; 4 | import com.github.argon4w.acceleratedrendering.features.text.AcceleratedBakedGlyphRenderer; 5 | import com.github.argon4w.acceleratedrendering.features.text.AcceleratedTextRenderingFeature; 6 | import com.mojang.blaze3d.vertex.VertexConsumer; 7 | import net.minecraft.client.gui.font.glyphs.BakedGlyph; 8 | import net.minecraft.util.FastColor; 9 | import org.joml.Matrix3f; 10 | import org.joml.Matrix4f; 11 | import org.spongepowered.asm.mixin.Mixin; 12 | import org.spongepowered.asm.mixin.Unique; 13 | import org.spongepowered.asm.mixin.injection.At; 14 | import org.spongepowered.asm.mixin.injection.Inject; 15 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 16 | 17 | @Mixin(value = BakedGlyph.class, priority = Integer.MIN_VALUE) 18 | public class BakedGlyphMixin { 19 | 20 | @Unique private static final Matrix4f TRANSFORM = new Matrix4f(); 21 | @Unique private static final Matrix3f NORMAL = new Matrix3f(); 22 | 23 | @Unique private final AcceleratedBakedGlyphRenderer normalRenderer = new AcceleratedBakedGlyphRenderer((BakedGlyph) (Object) this, false); 24 | @Unique private final AcceleratedBakedGlyphRenderer italicRenderer = new AcceleratedBakedGlyphRenderer((BakedGlyph) (Object) this, true); 25 | 26 | @Inject(method = "render", at = @At("HEAD"), cancellable = true) 27 | public void renderFast( 28 | boolean pItalic, 29 | float pX, 30 | float pY, 31 | Matrix4f pMatrix, 32 | VertexConsumer pBuffer, 33 | float pRed, 34 | float pGreen, 35 | float pBlue, 36 | float pAlpha, 37 | int pPackedLight, 38 | CallbackInfo ci 39 | ) { 40 | IAcceleratedVertexConsumer extension = (IAcceleratedVertexConsumer) pBuffer; 41 | 42 | if (!AcceleratedTextRenderingFeature.isEnabled()) { 43 | return; 44 | } 45 | 46 | if (!AcceleratedTextRenderingFeature.shouldUseAcceleratedPipeline()) { 47 | return; 48 | } 49 | 50 | if (!extension.isAccelerated()) { 51 | return; 52 | } 53 | 54 | ci.cancel(); 55 | 56 | TRANSFORM 57 | .set(pMatrix) 58 | .translate(pX, pY, 0.0f); 59 | 60 | int color = FastColor.ABGR32.color( 61 | (int) (pAlpha * 255.0F), 62 | (int) (pBlue * 255.0F), 63 | (int) (pGreen * 255.0F), 64 | (int) (pRed * 255.0F) 65 | ); 66 | 67 | AcceleratedBakedGlyphRenderer renderer = pItalic 68 | ? italicRenderer 69 | : normalRenderer; 70 | 71 | extension.doRender( 72 | renderer, 73 | null, 74 | TRANSFORM, 75 | NORMAL, 76 | pPackedLight, 77 | 0, 78 | color 79 | ); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/github/argon4w/acceleratedrendering/features/touhoulittlemaid/mixins/IGeoRendererMixin.java: -------------------------------------------------------------------------------- 1 | package com.github.argon4w.acceleratedrendering.features.touhoulittlemaid.mixins; 2 | 3 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.builders.IAcceleratedVertexConsumer; 4 | import com.github.argon4w.acceleratedrendering.core.buffers.accelerated.renderers.IAcceleratedRenderer; 5 | import com.github.argon4w.acceleratedrendering.features.entities.AcceleratedEntityRenderingFeature; 6 | import com.github.tartaricacid.touhoulittlemaid.geckolib3.geo.IGeoRenderer; 7 | import com.github.tartaricacid.touhoulittlemaid.geckolib3.geo.animated.AnimatedGeoBone; 8 | import com.mojang.blaze3d.vertex.PoseStack; 9 | import com.mojang.blaze3d.vertex.VertexConsumer; 10 | import net.minecraft.util.FastColor; 11 | import org.spongepowered.asm.mixin.Mixin; 12 | import org.spongepowered.asm.mixin.Pseudo; 13 | import org.spongepowered.asm.mixin.injection.At; 14 | import org.spongepowered.asm.mixin.injection.Inject; 15 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 16 | 17 | @Pseudo 18 | @Mixin(IGeoRenderer.class) 19 | public interface IGeoRendererMixin { 20 | 21 | @SuppressWarnings("unchecked") 22 | @Inject(method = "renderCubesOfBone", at = @At(value = "INVOKE", target = "Lcom/github/tartaricacid/touhoulittlemaid/geckolib3/geo/animated/AnimatedGeoBone;geoBone()Lcom/github/tartaricacid/touhoulittlemaid/geckolib3/geo/render/built/GeoBone;"), cancellable = true) 23 | default void renderBoneFast( 24 | AnimatedGeoBone bone, 25 | PoseStack poseStack, 26 | VertexConsumer buffer, 27 | int packedLight, 28 | int packedOverlay, 29 | float red, 30 | float green, 31 | float blue, 32 | float alpha, 33 | CallbackInfo ci 34 | ) { 35 | IAcceleratedVertexConsumer extension = (IAcceleratedVertexConsumer) buffer; 36 | 37 | if (!AcceleratedEntityRenderingFeature.isEnabled()) { 38 | return; 39 | } 40 | 41 | if (!AcceleratedEntityRenderingFeature.shouldUseAcceleratedPipeline()) { 42 | return; 43 | } 44 | 45 | if (!extension.isAccelerated()) { 46 | return; 47 | } 48 | 49 | ci.cancel(); 50 | 51 | PoseStack.Pose pose = poseStack.last(); 52 | 53 | extension.doRender( 54 | (IAcceleratedRenderer) bone.geoBone(), 55 | null, 56 | pose.pose(), 57 | pose.normal(), 58 | packedLight, 59 | packedOverlay, 60 | FastColor.ARGB32.color( 61 | (int) (alpha * 255.0f), 62 | (int) (red * 255.0f), 63 | (int) (green * 255.0f), 64 | (int) (blue * 255.0f) 65 | ) 66 | ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/accesstransformer.cfg: -------------------------------------------------------------------------------- 1 | # Core 2 | public net.minecraft.client.renderer.OutlineBufferSource$EntityOutlineGenerator 3 | 4 | # Mesh caching 5 | public net.minecraft.client.model.geom.ModelPart$Cube polygons 6 | public net.minecraft.client.model.geom.ModelPart$Polygon 7 | public net.minecraft.client.model.geom.ModelPart$Vertex 8 | 9 | # For Texture based pre-render culling and gpu-based culling 10 | public net.minecraft.client.renderer.RenderType$CompositeRenderType 11 | public net.minecraft.client.renderer.RenderType$CompositeRenderType state 12 | 13 | # Texture based pre-render culling 14 | public net.minecraft.client.renderer.RenderType$CompositeState textureState 15 | public net.minecraft.client.renderer.RenderStateShard$EmptyTextureStateShard cutoutTexture()Ljava/util/Optional; 16 | public net.minecraft.client.renderer.RenderStateShard$TextureStateShard cutoutTexture()Ljava/util/Optional; 17 | public net.minecraft.client.renderer.RenderStateShard$MultiTextureStateShard cutoutTexture()Ljava/util/Optional; 18 | 19 | # GPU based culling 20 | public net.minecraft.client.renderer.RenderType$CompositeState cullState 21 | public net.minecraft.client.renderer.RenderStateShard$BooleanStateShard enabled 22 | 23 | # Text Rendering 24 | public net.minecraft.client.gui.font.glyphs.BakedGlyph u0 25 | public net.minecraft.client.gui.font.glyphs.BakedGlyph u1 26 | public net.minecraft.client.gui.font.glyphs.BakedGlyph v0 27 | public net.minecraft.client.gui.font.glyphs.BakedGlyph v1 28 | public net.minecraft.client.gui.font.glyphs.BakedGlyph left 29 | public net.minecraft.client.gui.font.glyphs.BakedGlyph right 30 | public net.minecraft.client.gui.font.glyphs.BakedGlyph up 31 | public net.minecraft.client.gui.font.glyphs.BakedGlyph down -------------------------------------------------------------------------------- /src/main/resources/acceleratedrendering.compat.iris.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "com.github.argon4w.acceleratedrendering.compat.iris.mixins", 5 | "compatibilityLevel": "JAVA_21", 6 | "plugin": "com.github.argon4w.acceleratedrendering.compat.iris.mixins.plugin.IrisCompatMixinPlugin", 7 | "client": [ 8 | "acceleratedrendering.AcceleratedBufferSourceMixin", 9 | "acceleratedrendering.AcceleratedRenderingModEntryMixin", 10 | "acceleratedrendering.IBufferEnvironmentPresetsMixin", 11 | "acceleratedrendering.RedirectingBufferSourceMixin", 12 | "acceleratedrendering.RenderTypeUtilsMixin", 13 | "iris.IrisVertexFormatsMixin", 14 | "iris.ModelToEntityVertexSerializerMixin", 15 | "iris.ShadowRendererMixin", 16 | "iris.WrappableRenderTypeMixin", 17 | "vanilla.LevelRendererMixin", 18 | "vanilla.RenderTypeMixin" 19 | ], 20 | "injectors": { 21 | "defaultRequire": 1 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/resources/acceleratedrendering.core.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "com.github.argon4w.acceleratedrendering.core.mixins", 5 | "compatibilityLevel": "JAVA_21", 6 | "client": [ 7 | "EntityOutlineGeneratorMixin", 8 | "LevelRendererMixin", 9 | "MinecraftMixin", 10 | "SheetedDecalTextureGeneratorMixin", 11 | "SpriteCoordinateExpanderMixin", 12 | "VertexConsumerMixin", 13 | "VertexDoubleConsumerMixin" 14 | ], 15 | "injectors": { 16 | "defaultRequire": 1 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/resources/acceleratedrendering.feature.blocks.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "com.github.argon4w.acceleratedrendering.features.blocks.mixins", 5 | "compatibilityLevel": "JAVA_21", 6 | "client": [ 7 | "LevelRendererMixin", 8 | "ShadowRendererMixin", 9 | "SodiumWorldRendererMixin" 10 | ], 11 | "injectors": { 12 | "defaultRequire": 1 13 | } 14 | } -------------------------------------------------------------------------------- /src/main/resources/acceleratedrendering.feature.entities.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "com.github.argon4w.acceleratedrendering.features.entities.mixins", 5 | "compatibilityLevel": "JAVA_21", 6 | "client": [ 7 | "LevelRendererMixin", 8 | "ShadowRendererMixin", 9 | "EntityRenderDispatcherMixin" 10 | ], 11 | "injectors": { 12 | "defaultRequire": 1 13 | } 14 | } -------------------------------------------------------------------------------- /src/main/resources/acceleratedrendering.feature.items.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "com.github.argon4w.acceleratedrendering.features.items.mixins", 5 | "compatibilityLevel": "JAVA_21", 6 | "client": [ 7 | "BakedModelMixin", 8 | "BakedQuadMixin", 9 | "ItemColorsAccessor", 10 | "ItemRendererMixin", 11 | "SimpleBakedModelMixin" 12 | ], 13 | "injectors": { 14 | "defaultRequire": 1 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/resources/acceleratedrendering.feature.modelparts.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "com.github.argon4w.acceleratedrendering.features.modelparts.mixins", 5 | "compatibilityLevel": "JAVA_21", 6 | "client": [ 7 | "ModelPartMixin" 8 | ], 9 | "injectors": { 10 | "defaultRequire": 1 11 | } 12 | } -------------------------------------------------------------------------------- /src/main/resources/acceleratedrendering.feature.text.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "com.github.argon4w.acceleratedrendering.features.text.mixins", 5 | "compatibilityLevel": "JAVA_21", 6 | "client": [ 7 | "BakedGlyphMixin" 8 | ], 9 | "injectors": { 10 | "defaultRequire": 1 11 | } 12 | } -------------------------------------------------------------------------------- /src/main/resources/acceleratedrendering.feature.touhoulittlemaid.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "com.github.argon4w.acceleratedrendering.features.touhoulittlemaid.mixins", 5 | "compatibilityLevel": "JAVA_21", 6 | "client": [ 7 | "BedrockPartMixin", 8 | "GeoBoneMixin", 9 | "IGeoRendererMixin" 10 | ], 11 | "injectors": { 12 | "defaultRequire": 1 13 | } 14 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/compat/culling/iris_block_quad_culling_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | uint color; 8 | float u0; 9 | float v0; 10 | uint uv2; 11 | uint normal; 12 | uint iris_entity; 13 | uint iris_data_0; 14 | uint iris_data_1; 15 | uint iris_data_2; 16 | uint iris_data_3; 17 | }; 18 | 19 | struct VaryingData { 20 | int offset; 21 | int sharing; 22 | int mesh; 23 | int flags; 24 | }; 25 | 26 | struct SharingData { 27 | mat4 transform; 28 | mat3 normal; 29 | }; 30 | 31 | struct Polygon { 32 | uint vertex1; 33 | uint vertex2; 34 | uint vertex3; 35 | }; 36 | 37 | layout(local_size_x = 128) in; 38 | 39 | layout(binding=1, std430) readonly buffer Vertices { 40 | Vertex vertices[]; 41 | }; 42 | 43 | layout(binding=2, std430) readonly buffer Sharings { 44 | SharingData sharings[]; 45 | }; 46 | 47 | layout(binding=3, std430) readonly buffer Varyings { 48 | VaryingData varyings[]; 49 | }; 50 | 51 | layout(binding=6, std430) writeonly buffer PolygonsOut { 52 | Polygon polygonsOut[]; 53 | }; 54 | 55 | layout(binding=0, offset=0) uniform atomic_uint indexCounter; 56 | 57 | layout(location=0) uniform mat4 viewMatrix; 58 | layout(location=1) uniform mat4 projectMatrix; 59 | layout(location=2) uniform uint polygonCount; 60 | layout(location=3) uniform uint vertexOffset; 61 | 62 | void main() { 63 | uint index = gl_GlobalInvocationID.x; 64 | uint base = index * 4u; 65 | 66 | if (index >= polygonCount) { 67 | return; 68 | } 69 | 70 | uint index1 = vertexOffset + base + 0u; 71 | uint index2 = vertexOffset + base + 1u; 72 | uint index3 = vertexOffset + base + 2u; 73 | uint index4 = vertexOffset + base + 3u; 74 | 75 | uint flags = varyings[index - varyings[index1].offset].flags; 76 | uint noCull = flags & 0x1u; 77 | 78 | Vertex vertex1 = vertices[index1]; 79 | Vertex vertex2 = vertices[index2]; 80 | Vertex vertex3 = vertices[index3]; 81 | Vertex vertex4 = vertices[index4]; 82 | 83 | vec4 pos1 = projectMatrix * viewMatrix * vec4(vertex1.x, vertex1.y, vertex1.z, 1.0); 84 | vec4 pos2 = projectMatrix * viewMatrix * vec4(vertex2.x, vertex2.y, vertex2.z, 1.0); 85 | vec4 pos3 = projectMatrix * viewMatrix * vec4(vertex3.x, vertex3.y, vertex3.z, 1.0); 86 | vec4 pos4 = projectMatrix * viewMatrix * vec4(vertex4.x, vertex4.y, vertex4.z, 1.0); 87 | 88 | float det1 = determinant(mat3(pos1.xyw, pos2.xyw, pos3.xyw)); 89 | float det2 = determinant(mat3(pos3.xyw, pos4.xyw, pos1.xyw)); 90 | 91 | if (noCull > 0u || det1 > 0.0 || det2 > 0.0) { 92 | uint indexOut = atomicCounterAdd(indexCounter, 6u) / 3u; 93 | 94 | polygonsOut[indexOut + 0].vertex1 = index1; 95 | polygonsOut[indexOut + 0].vertex2 = index2; 96 | polygonsOut[indexOut + 0].vertex3 = index3; 97 | 98 | polygonsOut[indexOut + 1].vertex1 = index3; 99 | polygonsOut[indexOut + 1].vertex2 = index4; 100 | polygonsOut[indexOut + 1].vertex3 = index1; 101 | } 102 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/compat/culling/iris_block_triangle_culling_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | uint color; 8 | float u0; 9 | float v0; 10 | uint uv2; 11 | uint normal; 12 | uint iris_entity; 13 | uint iris_data_0; 14 | uint iris_data_1; 15 | uint iris_data_2; 16 | uint iris_data_3; 17 | }; 18 | 19 | struct VaryingData { 20 | int offset; 21 | int sharing; 22 | int mesh; 23 | int flags; 24 | }; 25 | 26 | struct SharingData { 27 | mat4 transform; 28 | mat3 normal; 29 | }; 30 | 31 | struct Polygon { 32 | uint vertex1; 33 | uint vertex2; 34 | uint vertex3; 35 | }; 36 | 37 | layout(local_size_x = 128) in; 38 | 39 | layout(binding=1, std430) readonly buffer Vertices { 40 | Vertex vertices[]; 41 | }; 42 | 43 | layout(binding=2, std430) readonly buffer Sharings { 44 | SharingData sharings[]; 45 | }; 46 | 47 | layout(binding=3, std430) readonly buffer Varyings { 48 | VaryingData varyings[]; 49 | }; 50 | 51 | layout(binding=6, std430) writeonly buffer PolygonsOut { 52 | Polygon polygonsOut[]; 53 | }; 54 | 55 | layout(binding=0, offset=0) uniform atomic_uint indexCounter; 56 | 57 | layout(location=0) uniform mat4 viewMatrix; 58 | layout(location=1) uniform mat4 projectMatrix; 59 | layout(location=2) uniform uint polygonCount; 60 | layout(location=3) uniform uint vertexOffset; 61 | 62 | void main() { 63 | uint index = gl_GlobalInvocationID.x; 64 | uint base = index * 3u; 65 | 66 | if (index >= polygonCount) { 67 | return; 68 | } 69 | 70 | uint index1 = vertexOffset + base + 0u; 71 | uint index2 = vertexOffset + base + 1u; 72 | uint index3 = vertexOffset + base + 2u; 73 | 74 | uint flags = varyings[index - varyings[index1].offset].flags; 75 | uint noCull = flags & 0x1u; 76 | 77 | Vertex vertex1 = vertices[index1]; 78 | Vertex vertex2 = vertices[index2]; 79 | Vertex vertex3 = vertices[index3]; 80 | 81 | vec4 pos1 = projectMatrix * viewMatrix * vec4(vertex1.x, vertex1.y, vertex1.z, 1.0); 82 | vec4 pos2 = projectMatrix * viewMatrix * vec4(vertex2.x, vertex2.y, vertex2.z, 1.0); 83 | vec4 pos3 = projectMatrix * viewMatrix * vec4(vertex3.x, vertex3.y, vertex3.z, 1.0); 84 | 85 | float det = determinant(mat3(pos1.xyw, pos2.xyw, pos3.xyw)); 86 | 87 | if (noCull > 0u || det > 0.0) { 88 | uint indexOut = atomicCounterAdd(indexCounter, 3u) / 3u; 89 | 90 | polygonsOut[indexOut + 0].vertex1 = index1; 91 | polygonsOut[indexOut + 0].vertex2 = index2; 92 | polygonsOut[indexOut + 0].vertex3 = index3; 93 | } 94 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/compat/culling/iris_entity_triangle_culling_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | uint color; 8 | float u0; 9 | float v0; 10 | int uv1; 11 | int uv2; 12 | uint normal; 13 | uint iris_data_0; 14 | uint iris_data_1; 15 | uint iris_data_2; 16 | uint iris_data_3; 17 | uint iris_data_4; 18 | }; 19 | 20 | struct VaryingData { 21 | int offset; 22 | int sharing; 23 | int mesh; 24 | int flags; 25 | }; 26 | 27 | struct SharingData { 28 | mat4 transform; 29 | mat3 normal; 30 | }; 31 | 32 | struct Polygon { 33 | uint vertex1; 34 | uint vertex2; 35 | uint vertex3; 36 | }; 37 | 38 | layout(local_size_x = 128) in; 39 | 40 | layout(binding=1, std430) readonly buffer Vertices { 41 | Vertex vertices[]; 42 | }; 43 | 44 | layout(binding=2, std430) readonly buffer Sharings { 45 | SharingData sharings[]; 46 | }; 47 | 48 | layout(binding=3, std430) readonly buffer Varyings { 49 | VaryingData varyings[]; 50 | }; 51 | 52 | layout(binding=6, std430) writeonly buffer PolygonsOut { 53 | Polygon polygonsOut[]; 54 | }; 55 | 56 | layout(binding=0, offset=0) uniform atomic_uint indexCounter; 57 | 58 | layout(location=0) uniform mat4 viewMatrix; 59 | layout(location=1) uniform mat4 projectMatrix; 60 | layout(location=2) uniform uint polygonCount; 61 | layout(location=3) uniform uint vertexOffset; 62 | 63 | void main() { 64 | uint index = gl_GlobalInvocationID.x; 65 | uint base = index * 3u; 66 | 67 | if (index >= polygonCount) { 68 | return; 69 | } 70 | 71 | uint index1 = vertexOffset + base + 0u; 72 | uint index2 = vertexOffset + base + 1u; 73 | uint index3 = vertexOffset + base + 2u; 74 | 75 | uint flags = varyings[index - varyings[index1].offset].flags; 76 | uint noCull = flags & 0x1u; 77 | 78 | Vertex vertex1 = vertices[index1]; 79 | Vertex vertex2 = vertices[index2]; 80 | Vertex vertex3 = vertices[index3]; 81 | 82 | vec4 pos1 = projectMatrix * viewMatrix * vec4(vertex1.x, vertex1.y, vertex1.z, 1.0); 83 | vec4 pos2 = projectMatrix * viewMatrix * vec4(vertex2.x, vertex2.y, vertex2.z, 1.0); 84 | vec4 pos3 = projectMatrix * viewMatrix * vec4(vertex3.x, vertex3.y, vertex3.z, 1.0); 85 | 86 | float det = determinant(mat3(pos1.xyw, pos2.xyw, pos3.xyw)); 87 | 88 | if (noCull > 0u || det > 0.0) { 89 | uint indexOut = atomicCounterAdd(indexCounter, 3u) / 3u; 90 | 91 | polygonsOut[indexOut + 0].vertex1 = index1; 92 | polygonsOut[indexOut + 0].vertex2 = index2; 93 | polygonsOut[indexOut + 0].vertex3 = index3; 94 | } 95 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/compat/processing/iris_entity_quad_processing_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | uint color; 8 | float u0; 9 | float v0; 10 | int uv1; 11 | int uv2; 12 | uint normal; 13 | uint iris_entity_0; 14 | uint iris_entity_1; 15 | float iris_midcoord_u; 16 | float iris_midcoord_v; 17 | uint iris_at_tangent; 18 | }; 19 | 20 | layout(local_size_x = 128) in; 21 | 22 | layout(binding=1, std430) buffer Vertices { 23 | Vertex vertices[]; 24 | }; 25 | 26 | layout(location=0) uniform uint polygonCount; 27 | layout(location=1) uniform uint vertexOffset; 28 | 29 | void main() { 30 | uint index = gl_GlobalInvocationID.x; 31 | uint base = index * 4u; 32 | 33 | if (index >= polygonCount) { 34 | return; 35 | } 36 | 37 | uint index1 = vertexOffset + base + 0u; 38 | uint index2 = vertexOffset + base + 1u; 39 | uint index3 = vertexOffset + base + 2u; 40 | uint index4 = vertexOffset + base + 3u; 41 | 42 | Vertex vertex1 = vertices[index1]; 43 | Vertex vertex2 = vertices[index2]; 44 | Vertex vertex3 = vertices[index3]; 45 | Vertex vertex4 = vertices[index4]; 46 | 47 | vec3 pos1 = vec3(vertex1.x, vertex1.y, vertex1.z); 48 | vec3 pos2 = vec3(vertex2.x, vertex2.y, vertex2.z); 49 | vec3 pos3 = vec3(vertex3.x, vertex3.y, vertex3.z); 50 | vec3 pos4 = vec3(vertex4.x, vertex4.y, vertex4.z); 51 | 52 | vec2 uv1 = vec2(vertex1.u0, vertex1.v0); 53 | vec2 uv2 = vec2(vertex2.u0, vertex2.v0); 54 | vec2 uv3 = vec2(vertex3.u0, vertex3.v0); 55 | vec2 uv4 = vec2(vertex4.u0, vertex4.v0); 56 | 57 | vec2 midUV = (uv1 + uv2 + uv3 + uv4) / 4; 58 | vec3 normal = unpackSnorm4x8(vertex1.normal).xyz; 59 | 60 | vec3 edge1 = pos2 - pos1; 61 | vec3 edge2 = pos3 - pos1; 62 | 63 | vec2 dUV1 = uv2 - uv1; 64 | vec2 dUV2 = uv3 - uv1; 65 | 66 | float fdenom = dUV1.x * dUV2.y - dUV2.x * dUV1.y; 67 | float f = fdenom == 0.0 ? 1.0 : 1.0 / fdenom; 68 | 69 | vec3 tangent = normalize(f * (dUV2.y * edge1 - dUV1.y * edge2)); 70 | vec3 aBitangent = normalize(f * (-dUV2.x * edge1 + dUV1.x * edge2)); 71 | vec3 pBitangent = cross(tangent, normal); 72 | vec4 tangent4 = vec4(tangent, dot(aBitangent, pBitangent) < 0.0 ? -1.0 : 1.0); 73 | uint packedTangent = packSnorm4x8(tangent4); 74 | 75 | vertices[index1].iris_at_tangent = packedTangent; 76 | vertices[index2].iris_at_tangent = packedTangent; 77 | vertices[index3].iris_at_tangent = packedTangent; 78 | vertices[index4].iris_at_tangent = packedTangent; 79 | 80 | vertices[index1].iris_midcoord_u = midUV.x; 81 | vertices[index2].iris_midcoord_u = midUV.x; 82 | vertices[index3].iris_midcoord_u = midUV.x; 83 | vertices[index4].iris_midcoord_u = midUV.x; 84 | 85 | vertices[index1].iris_midcoord_v = midUV.y; 86 | vertices[index2].iris_midcoord_v = midUV.y; 87 | vertices[index3].iris_midcoord_v = midUV.y; 88 | vertices[index4].iris_midcoord_v = midUV.y; 89 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/culling/block_quad_culling_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | uint color; 8 | float u0; 9 | float v0; 10 | int uv2; 11 | uint normal; 12 | }; 13 | 14 | struct VaryingData { 15 | int offset; 16 | int sharing; 17 | int mesh; 18 | int flags; 19 | }; 20 | 21 | struct SharingData { 22 | mat4 transform; 23 | mat3 normal; 24 | }; 25 | 26 | struct Polygon { 27 | uint vertex1; 28 | uint vertex2; 29 | uint vertex3; 30 | }; 31 | 32 | layout(local_size_x = 128) in; 33 | 34 | layout(binding=1, std430) readonly buffer Vertices { 35 | Vertex vertices[]; 36 | }; 37 | 38 | layout(binding=2, std430) readonly buffer Sharings { 39 | SharingData sharings[]; 40 | }; 41 | 42 | layout(binding=3, std430) readonly buffer Varyings { 43 | VaryingData varyings[]; 44 | }; 45 | 46 | layout(binding=6, std430) writeonly buffer PolygonsOut { 47 | Polygon polygonsOut[]; 48 | }; 49 | 50 | layout(binding=0, offset=0) uniform atomic_uint indexCounter; 51 | 52 | layout(location=0) uniform mat4 viewMatrix; 53 | layout(location=1) uniform mat4 projectMatrix; 54 | layout(location=2) uniform uint polygonCount; 55 | layout(location=3) uniform uint vertexOffset; 56 | 57 | void main() { 58 | uint index = gl_GlobalInvocationID.x; 59 | uint base = index * 4u; 60 | 61 | if (index >= polygonCount) { 62 | return; 63 | } 64 | 65 | uint index1 = vertexOffset + base + 0u; 66 | uint index2 = vertexOffset + base + 1u; 67 | uint index3 = vertexOffset + base + 2u; 68 | uint index4 = vertexOffset + base + 3u; 69 | 70 | uint flags = varyings[index - varyings[index1].offset].flags; 71 | uint noCull = flags & 0x1u; 72 | 73 | Vertex vertex1 = vertices[index1]; 74 | Vertex vertex2 = vertices[index2]; 75 | Vertex vertex3 = vertices[index3]; 76 | Vertex vertex4 = vertices[index4]; 77 | 78 | vec4 pos1 = projectMatrix * viewMatrix * vec4(vertex1.x, vertex1.y, vertex1.z, 1.0); 79 | vec4 pos2 = projectMatrix * viewMatrix * vec4(vertex2.x, vertex2.y, vertex2.z, 1.0); 80 | vec4 pos3 = projectMatrix * viewMatrix * vec4(vertex3.x, vertex3.y, vertex3.z, 1.0); 81 | vec4 pos4 = projectMatrix * viewMatrix * vec4(vertex4.x, vertex4.y, vertex4.z, 1.0); 82 | 83 | float det1 = determinant(mat3(pos1.xyw, pos2.xyw, pos3.xyw)); 84 | float det2 = determinant(mat3(pos3.xyw, pos4.xyw, pos1.xyw)); 85 | 86 | if (noCull > 0u || det1 > 0.0 || det2 > 0.0) { 87 | uint indexOut = atomicCounterAdd(indexCounter, 6u) / 3u; 88 | 89 | polygonsOut[indexOut + 0].vertex1 = index1; 90 | polygonsOut[indexOut + 0].vertex2 = index2; 91 | polygonsOut[indexOut + 0].vertex3 = index3; 92 | 93 | polygonsOut[indexOut + 1].vertex1 = index3; 94 | polygonsOut[indexOut + 1].vertex2 = index4; 95 | polygonsOut[indexOut + 1].vertex3 = index1; 96 | } 97 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/culling/block_triangle_culling_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | uint color; 8 | float u0; 9 | float v0; 10 | int uv2; 11 | uint normal; 12 | }; 13 | 14 | struct VaryingData { 15 | int offset; 16 | int sharing; 17 | int mesh; 18 | int flags; 19 | }; 20 | 21 | struct SharingData { 22 | mat4 transform; 23 | mat3 normal; 24 | }; 25 | 26 | struct Polygon { 27 | uint vertex1; 28 | uint vertex2; 29 | uint vertex3; 30 | }; 31 | 32 | layout(local_size_x = 128) in; 33 | 34 | layout(binding=1, std430) readonly buffer Vertices { 35 | Vertex vertices[]; 36 | }; 37 | 38 | layout(binding=2, std430) readonly buffer Sharings { 39 | SharingData sharings[]; 40 | }; 41 | 42 | layout(binding=3, std430) readonly buffer Varyings { 43 | VaryingData varyings[]; 44 | }; 45 | 46 | layout(binding=6, std430) writeonly buffer PolygonsOut { 47 | Polygon polygonsOut[]; 48 | }; 49 | 50 | layout(binding=0, offset=0) uniform atomic_uint indexCounter; 51 | 52 | layout(location=0) uniform mat4 viewMatrix; 53 | layout(location=1) uniform mat4 projectMatrix; 54 | layout(location=2) uniform uint polygonCount; 55 | layout(location=3) uniform uint vertexOffset; 56 | 57 | void main() { 58 | uint index = gl_GlobalInvocationID.x; 59 | uint base = index * 3u; 60 | 61 | if (index >= polygonCount) { 62 | return; 63 | } 64 | 65 | uint index1 = vertexOffset + base + 0u; 66 | uint index2 = vertexOffset + base + 1u; 67 | uint index3 = vertexOffset + base + 2u; 68 | 69 | uint flags = varyings[index - varyings[index1].offset].flags; 70 | uint noCull = flags & 0x1u; 71 | 72 | Vertex vertex1 = vertices[index1]; 73 | Vertex vertex2 = vertices[index2]; 74 | Vertex vertex3 = vertices[index3]; 75 | 76 | vec4 pos1 = projectMatrix * viewMatrix * vec4(vertex1.x, vertex1.y, vertex1.z, 1.0); 77 | vec4 pos2 = projectMatrix * viewMatrix * vec4(vertex2.x, vertex2.y, vertex2.z, 1.0); 78 | vec4 pos3 = projectMatrix * viewMatrix * vec4(vertex3.x, vertex3.y, vertex3.z, 1.0); 79 | 80 | float det = determinant(mat3(pos1.xyw, pos2.xyw, pos3.xyw)); 81 | 82 | if (noCull > 0u || det > 0.0) { 83 | uint indexOut = atomicCounterAdd(indexCounter, 3u) / 3u; 84 | 85 | polygonsOut[indexOut + 0].vertex1 = index1; 86 | polygonsOut[indexOut + 0].vertex2 = index2; 87 | polygonsOut[indexOut + 0].vertex3 = index3; 88 | } 89 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/culling/entity_quad_culling_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | uint color; 8 | float u0; 9 | float v0; 10 | int uv1; 11 | int uv2; 12 | uint normal; 13 | }; 14 | 15 | struct VaryingData { 16 | int offset; 17 | int sharing; 18 | int mesh; 19 | int flags; 20 | }; 21 | 22 | struct SharingData { 23 | mat4 transform; 24 | mat3 normal; 25 | }; 26 | 27 | struct Polygon { 28 | uint vertex1; 29 | uint vertex2; 30 | uint vertex3; 31 | }; 32 | 33 | layout(local_size_x = 128) in; 34 | 35 | layout(binding=1, std430) readonly buffer Vertices { 36 | Vertex vertices[]; 37 | }; 38 | 39 | layout(binding=2, std430) readonly buffer Sharings { 40 | SharingData sharings[]; 41 | }; 42 | 43 | layout(binding=3, std430) readonly buffer Varyings { 44 | VaryingData varyings[]; 45 | }; 46 | 47 | layout(binding=6, std430) writeonly buffer PolygonsOut { 48 | Polygon polygonsOut[]; 49 | }; 50 | 51 | layout(binding=0, offset=0) uniform atomic_uint indexCounter; 52 | 53 | layout(location=0) uniform mat4 viewMatrix; 54 | layout(location=1) uniform mat4 projectMatrix; 55 | layout(location=2) uniform uint polygonCount; 56 | layout(location=3) uniform uint vertexOffset; 57 | 58 | void main() { 59 | uint index = gl_GlobalInvocationID.x; 60 | uint base = index * 4u; 61 | 62 | if (index >= polygonCount) { 63 | return; 64 | } 65 | 66 | uint index1 = vertexOffset + base + 0u; 67 | uint index2 = vertexOffset + base + 1u; 68 | uint index3 = vertexOffset + base + 2u; 69 | uint index4 = vertexOffset + base + 3u; 70 | 71 | uint flags = varyings[index - varyings[index1].offset].flags; 72 | uint noCull = flags & 0x1u; 73 | 74 | Vertex vertex1 = vertices[index1]; 75 | Vertex vertex2 = vertices[index2]; 76 | Vertex vertex3 = vertices[index3]; 77 | Vertex vertex4 = vertices[index4]; 78 | 79 | vec4 pos1 = projectMatrix * viewMatrix * vec4(vertex1.x, vertex1.y, vertex1.z, 1.0); 80 | vec4 pos2 = projectMatrix * viewMatrix * vec4(vertex2.x, vertex2.y, vertex2.z, 1.0); 81 | vec4 pos3 = projectMatrix * viewMatrix * vec4(vertex3.x, vertex3.y, vertex3.z, 1.0); 82 | vec4 pos4 = projectMatrix * viewMatrix * vec4(vertex4.x, vertex4.y, vertex4.z, 1.0); 83 | 84 | float det1 = determinant(mat3(pos1.xyw, pos2.xyw, pos3.xyw)); 85 | float det2 = determinant(mat3(pos3.xyw, pos4.xyw, pos1.xyw)); 86 | 87 | if (noCull > 0u || det1 > 0.0 || det2 > 0.0) { 88 | uint indexOut = atomicCounterAdd(indexCounter, 6u) / 3u; 89 | 90 | polygonsOut[indexOut + 0].vertex1 = index1; 91 | polygonsOut[indexOut + 0].vertex2 = index2; 92 | polygonsOut[indexOut + 0].vertex3 = index3; 93 | 94 | polygonsOut[indexOut + 1].vertex1 = index3; 95 | polygonsOut[indexOut + 1].vertex2 = index4; 96 | polygonsOut[indexOut + 1].vertex3 = index1; 97 | } 98 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/culling/entity_triangle_culling_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | uint color; 8 | float u0; 9 | float v0; 10 | int uv1; 11 | int uv2; 12 | uint normal; 13 | }; 14 | 15 | struct VaryingData { 16 | int offset; 17 | int sharing; 18 | int mesh; 19 | int flags; 20 | }; 21 | 22 | struct SharingData { 23 | mat4 transform; 24 | mat3 normal; 25 | }; 26 | 27 | struct Polygon { 28 | uint vertex1; 29 | uint vertex2; 30 | uint vertex3; 31 | }; 32 | 33 | layout(local_size_x = 128) in; 34 | 35 | layout(binding=1, std430) readonly buffer Vertices { 36 | Vertex vertices[]; 37 | }; 38 | 39 | layout(binding=2, std430) readonly buffer Sharings { 40 | SharingData sharings[]; 41 | }; 42 | 43 | layout(binding=3, std430) readonly buffer Varyings { 44 | VaryingData varyings[]; 45 | }; 46 | 47 | layout(binding=6, std430) writeonly buffer PolygonsOut { 48 | Polygon polygonsOut[]; 49 | }; 50 | 51 | layout(binding=0, offset=0) uniform atomic_uint indexCounter; 52 | 53 | layout(location=0) uniform mat4 viewMatrix; 54 | layout(location=1) uniform mat4 projectMatrix; 55 | layout(location=2) uniform uint polygonCount; 56 | layout(location=3) uniform uint vertexOffset; 57 | 58 | void main() { 59 | uint index = gl_GlobalInvocationID.x; 60 | uint base = index * 3u; 61 | 62 | if (index >= polygonCount) { 63 | return; 64 | } 65 | 66 | uint index1 = vertexOffset + base + 0u; 67 | uint index2 = vertexOffset + base + 1u; 68 | uint index3 = vertexOffset + base + 2u; 69 | 70 | uint flags = varyings[index - varyings[index1].offset].flags; 71 | uint noCull = flags & 0x1u; 72 | 73 | Vertex vertex1 = vertices[index1]; 74 | Vertex vertex2 = vertices[index2]; 75 | Vertex vertex3 = vertices[index3]; 76 | 77 | vec4 pos1 = projectMatrix * viewMatrix * vec4(vertex1.x, vertex1.y, vertex1.z, 1.0); 78 | vec4 pos2 = projectMatrix * viewMatrix * vec4(vertex2.x, vertex2.y, vertex2.z, 1.0); 79 | vec4 pos3 = projectMatrix * viewMatrix * vec4(vertex3.x, vertex3.y, vertex3.z, 1.0); 80 | 81 | float det = determinant(mat3(pos1.xyw, pos2.xyw, pos3.xyw)); 82 | 83 | if (noCull > 0u || det > 0.0) { 84 | uint indexOut = atomicCounterAdd(indexCounter, 3u) / 3u; 85 | 86 | polygonsOut[indexOut + 0].vertex1 = index1; 87 | polygonsOut[indexOut + 0].vertex2 = index2; 88 | polygonsOut[indexOut + 0].vertex3 = index3; 89 | } 90 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/culling/pass_through_quad_culling_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Polygon { 4 | uint vertex1; 5 | uint vertex2; 6 | uint vertex3; 7 | }; 8 | 9 | layout(local_size_x = 128) in; 10 | 11 | layout(binding=6, std430) writeonly buffer PolygonsOut { 12 | Polygon polygonsOut[]; 13 | }; 14 | 15 | layout(binding=0, offset=0) uniform atomic_uint indexCounter; 16 | 17 | layout(location=0) uniform mat4 viewMatrix; 18 | layout(location=1) uniform uint polygonCount; 19 | layout(location=2) uniform uint vertexOffset; 20 | 21 | void main() { 22 | uint index = gl_GlobalInvocationID.x; 23 | uint base = index * 4u; 24 | 25 | if (index >= polygonCount) { 26 | return; 27 | } 28 | 29 | uint index1 = vertexOffset + base + 0u; 30 | uint index2 = vertexOffset + base + 1u; 31 | uint index3 = vertexOffset + base + 2u; 32 | uint index4 = vertexOffset + base + 3u; 33 | 34 | uint indexOut = atomicCounterAdd(indexCounter, 6u) / 3u; 35 | 36 | polygonsOut[indexOut + 0].vertex1 = index1; 37 | polygonsOut[indexOut + 0].vertex2 = index2; 38 | polygonsOut[indexOut + 0].vertex3 = index3; 39 | 40 | polygonsOut[indexOut + 1].vertex1 = index3; 41 | polygonsOut[indexOut + 1].vertex2 = index4; 42 | polygonsOut[indexOut + 1].vertex3 = index1; 43 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/culling/pass_through_triangle_culling_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Polygon { 4 | uint vertex1; 5 | uint vertex2; 6 | uint vertex3; 7 | }; 8 | 9 | layout(local_size_x = 128) in; 10 | 11 | layout(binding=6, std430) writeonly buffer PolygonsOut { 12 | Polygon polygonsOut[]; 13 | }; 14 | 15 | layout(binding=0, offset=0) uniform atomic_uint indexCounter; 16 | 17 | layout(location=0) uniform mat4 viewMatrix; 18 | layout(location=1) uniform uint polygonCount; 19 | layout(location=2) uniform uint vertexOffset; 20 | 21 | void main() { 22 | uint index = gl_GlobalInvocationID.x; 23 | uint base = index * 3u; 24 | 25 | if (index >= polygonCount) { 26 | return; 27 | } 28 | 29 | uint index1 = vertexOffset + base + 0u; 30 | uint index2 = vertexOffset + base + 1u; 31 | uint index3 = vertexOffset + base + 2u; 32 | 33 | uint indexOut = atomicCounterAdd(indexCounter, 3u) / 3u; 34 | 35 | polygonsOut[indexOut].vertex1 = index1; 36 | polygonsOut[indexOut].vertex2 = index2; 37 | polygonsOut[indexOut].vertex3 = index3; 38 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/culling/pos_tex_color_quad_culling_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | float u0; 8 | float v0; 9 | uint color; 10 | }; 11 | 12 | struct VaryingData { 13 | int offset; 14 | int sharing; 15 | int mesh; 16 | int flags; 17 | }; 18 | 19 | struct SharingData { 20 | mat4 transform; 21 | mat3 normal; 22 | }; 23 | 24 | struct Polygon { 25 | uint vertex1; 26 | uint vertex2; 27 | uint vertex3; 28 | }; 29 | 30 | layout(local_size_x = 128) in; 31 | 32 | layout(binding=1, std430) readonly buffer Vertices { 33 | Vertex vertices[]; 34 | }; 35 | 36 | layout(binding=2, std430) readonly buffer Sharings { 37 | SharingData sharings[]; 38 | }; 39 | 40 | layout(binding=3, std430) readonly buffer Varyings { 41 | VaryingData varyings[]; 42 | }; 43 | 44 | layout(binding=6, std430) writeonly buffer PolygonsOut { 45 | Polygon polygonsOut[]; 46 | }; 47 | 48 | layout(binding=0, offset=0) uniform atomic_uint indexCounter; 49 | 50 | layout(location=0) uniform mat4 viewMatrix; 51 | layout(location=1) uniform mat4 projectMatrix; 52 | layout(location=2) uniform uint polygonCount; 53 | layout(location=3) uniform uint vertexOffset; 54 | 55 | void main() { 56 | uint index = gl_GlobalInvocationID.x; 57 | uint base = index * 4u; 58 | 59 | if (index >= polygonCount) { 60 | return; 61 | } 62 | 63 | uint index1 = vertexOffset + base + 0u; 64 | uint index2 = vertexOffset + base + 1u; 65 | uint index3 = vertexOffset + base + 2u; 66 | uint index4 = vertexOffset + base + 3u; 67 | 68 | uint flags = varyings[index - varyings[index1].offset].flags; 69 | uint noCull = flags & 0x1u; 70 | 71 | Vertex vertex1 = vertices[index1]; 72 | Vertex vertex2 = vertices[index2]; 73 | Vertex vertex3 = vertices[index3]; 74 | Vertex vertex4 = vertices[index4]; 75 | 76 | vec4 pos1 = projectMatrix * viewMatrix * vec4(vertex1.x, vertex1.y, vertex1.z, 1.0); 77 | vec4 pos2 = projectMatrix * viewMatrix * vec4(vertex2.x, vertex2.y, vertex2.z, 1.0); 78 | vec4 pos3 = projectMatrix * viewMatrix * vec4(vertex3.x, vertex3.y, vertex3.z, 1.0); 79 | vec4 pos4 = projectMatrix * viewMatrix * vec4(vertex4.x, vertex4.y, vertex4.z, 1.0); 80 | 81 | float det1 = determinant(mat3(pos1.xyw, pos2.xyw, pos3.xyw)); 82 | float det2 = determinant(mat3(pos3.xyw, pos4.xyw, pos1.xyw)); 83 | 84 | if (noCull > 0u || det1 > 0.0 || det2 > 0.0) { 85 | uint indexOut = atomicCounterAdd(indexCounter, 6u) / 3u; 86 | 87 | polygonsOut[indexOut + 0].vertex1 = index1; 88 | polygonsOut[indexOut + 0].vertex2 = index2; 89 | polygonsOut[indexOut + 0].vertex3 = index3; 90 | 91 | polygonsOut[indexOut + 1].vertex1 = index3; 92 | polygonsOut[indexOut + 1].vertex2 = index4; 93 | polygonsOut[indexOut + 1].vertex3 = index1; 94 | } 95 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/culling/pos_tex_color_triangle_culling_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | float u0; 8 | float v0; 9 | int color; 10 | }; 11 | 12 | struct VaryingData { 13 | int offset; 14 | int sharing; 15 | int mesh; 16 | int flags; 17 | }; 18 | 19 | struct SharingData { 20 | mat4 transform; 21 | mat3 normal; 22 | }; 23 | 24 | struct Polygon { 25 | uint vertex1; 26 | uint vertex2; 27 | uint vertex3; 28 | }; 29 | 30 | layout(local_size_x = 128) in; 31 | 32 | layout(binding=1, std430) readonly buffer Vertices { 33 | Vertex vertices[]; 34 | }; 35 | 36 | layout(binding=2, std430) readonly buffer Sharings { 37 | SharingData sharings[]; 38 | }; 39 | 40 | layout(binding=3, std430) readonly buffer Varyings { 41 | VaryingData varyings[]; 42 | }; 43 | 44 | layout(binding=6, std430) writeonly buffer PolygonsOut { 45 | Polygon polygonsOut[]; 46 | }; 47 | 48 | layout(binding=0, offset=0) uniform atomic_uint indexCounter; 49 | 50 | layout(location=0) uniform mat4 viewMatrix; 51 | layout(location=1) uniform mat4 projectMatrix; 52 | layout(location=2) uniform uint polygonCount; 53 | layout(location=3) uniform uint vertexOffset; 54 | 55 | void main() { 56 | uint index = gl_GlobalInvocationID.x; 57 | uint base = index * 3u; 58 | 59 | if (index >= polygonCount) { 60 | return; 61 | } 62 | 63 | uint index1 = vertexOffset + base + 0u; 64 | uint index2 = vertexOffset + base + 1u; 65 | uint index3 = vertexOffset + base + 2u; 66 | 67 | uint flags = varyings[index - varyings[index1].offset].flags; 68 | uint noCull = flags & 0x1u; 69 | 70 | Vertex vertex1 = vertices[index1]; 71 | Vertex vertex2 = vertices[index2]; 72 | Vertex vertex3 = vertices[index3]; 73 | 74 | vec4 pos1 = projectMatrix * viewMatrix * vec4(vertex1.x, vertex1.y, vertex1.z, 1.0); 75 | vec4 pos2 = projectMatrix * viewMatrix * vec4(vertex2.x, vertex2.y, vertex2.z, 1.0); 76 | vec4 pos3 = projectMatrix * viewMatrix * vec4(vertex3.x, vertex3.y, vertex3.z, 1.0); 77 | 78 | float det = determinant(mat3(pos1.xyw, pos2.xyw, pos3.xyw)); 79 | 80 | if (noCull > 0u || det > 0.0) { 81 | uint indexOut = atomicCounterAdd(indexCounter, 3u) / 3u; 82 | 83 | polygonsOut[indexOut + 0].vertex1 = index1; 84 | polygonsOut[indexOut + 0].vertex2 = index2; 85 | polygonsOut[indexOut + 0].vertex3 = index3; 86 | } 87 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/culling/pos_tex_quad_culling_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | float u0; 8 | float v0; 9 | }; 10 | 11 | struct VaryingData { 12 | int offset; 13 | int sharing; 14 | int mesh; 15 | int flags; 16 | }; 17 | 18 | struct SharingData { 19 | mat4 transform; 20 | mat3 normal; 21 | }; 22 | 23 | struct Polygon { 24 | uint vertex1; 25 | uint vertex2; 26 | uint vertex3; 27 | }; 28 | 29 | layout(local_size_x = 128) in; 30 | 31 | layout(binding=1, std430) readonly buffer Vertices { 32 | Vertex vertices[]; 33 | }; 34 | 35 | layout(binding=2, std430) readonly buffer Sharings { 36 | SharingData sharings[]; 37 | }; 38 | 39 | layout(binding=3, std430) readonly buffer Varyings { 40 | VaryingData varyings[]; 41 | }; 42 | 43 | layout(binding=6, std430) writeonly buffer PolygonsOut { 44 | Polygon polygonsOut[]; 45 | }; 46 | 47 | layout(binding=0, offset=0) uniform atomic_uint indexCounter; 48 | 49 | layout(location=0) uniform mat4 viewMatrix; 50 | layout(location=1) uniform mat4 projectMatrix; 51 | layout(location=2) uniform uint polygonCount; 52 | layout(location=3) uniform uint vertexOffset; 53 | 54 | void main() { 55 | uint index = gl_GlobalInvocationID.x; 56 | uint base = index * 4u; 57 | 58 | if (index >= polygonCount) { 59 | return; 60 | } 61 | 62 | uint index1 = vertexOffset + base + 0u; 63 | uint index2 = vertexOffset + base + 1u; 64 | uint index3 = vertexOffset + base + 2u; 65 | uint index4 = vertexOffset + base + 3u; 66 | 67 | uint flags = varyings[index - varyings[index1].offset].flags; 68 | uint noCull = flags & 0x1u; 69 | 70 | Vertex vertex1 = vertices[index1]; 71 | Vertex vertex2 = vertices[index2]; 72 | Vertex vertex3 = vertices[index3]; 73 | Vertex vertex4 = vertices[index4]; 74 | 75 | vec4 pos1 = projectMatrix * viewMatrix * vec4(vertex1.x, vertex1.y, vertex1.z, 1.0); 76 | vec4 pos2 = projectMatrix * viewMatrix * vec4(vertex2.x, vertex2.y, vertex2.z, 1.0); 77 | vec4 pos3 = projectMatrix * viewMatrix * vec4(vertex3.x, vertex3.y, vertex3.z, 1.0); 78 | vec4 pos4 = projectMatrix * viewMatrix * vec4(vertex4.x, vertex4.y, vertex4.z, 1.0); 79 | 80 | float det1 = determinant(mat3(pos1.xyw, pos2.xyw, pos3.xyw)); 81 | float det2 = determinant(mat3(pos3.xyw, pos4.xyw, pos1.xyw)); 82 | 83 | if (noCull > 0u || det1 > 0.0 || det2 > 0.0) { 84 | uint indexOut = atomicCounterAdd(indexCounter, 6u) / 3u; 85 | 86 | polygonsOut[indexOut + 0].vertex1 = index1; 87 | polygonsOut[indexOut + 0].vertex2 = index2; 88 | polygonsOut[indexOut + 0].vertex3 = index3; 89 | 90 | polygonsOut[indexOut + 1].vertex1 = index3; 91 | polygonsOut[indexOut + 1].vertex2 = index4; 92 | polygonsOut[indexOut + 1].vertex3 = index1; 93 | } 94 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/culling/pos_tex_triangle_culling_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | float u0; 8 | float v0; 9 | }; 10 | 11 | struct VaryingData { 12 | int offset; 13 | int sharing; 14 | int mesh; 15 | int flags; 16 | }; 17 | 18 | struct SharingData { 19 | mat4 transform; 20 | mat3 normal; 21 | }; 22 | 23 | struct Polygon { 24 | uint vertex1; 25 | uint vertex2; 26 | uint vertex3; 27 | }; 28 | 29 | layout(local_size_x = 128) in; 30 | 31 | layout(binding=1, std430) readonly buffer Vertices { 32 | Vertex vertices[]; 33 | }; 34 | 35 | layout(binding=2, std430) readonly buffer Sharings { 36 | SharingData sharings[]; 37 | }; 38 | 39 | layout(binding=3, std430) readonly buffer Varyings { 40 | VaryingData varyings[]; 41 | }; 42 | 43 | layout(binding=6, std430) writeonly buffer PolygonsOut { 44 | Polygon polygonsOut[]; 45 | }; 46 | 47 | layout(binding=0, offset=0) uniform atomic_uint indexCounter; 48 | 49 | layout(location=0) uniform mat4 viewMatrix; 50 | layout(location=1) uniform mat4 projectMatrix; 51 | layout(location=2) uniform uint polygonCount; 52 | layout(location=3) uniform uint vertexOffset; 53 | 54 | void main() { 55 | uint index = gl_GlobalInvocationID.x; 56 | uint base = index * 3u; 57 | 58 | if (index >= polygonCount) { 59 | return; 60 | } 61 | 62 | uint index1 = vertexOffset + base + 0u; 63 | uint index2 = vertexOffset + base + 1u; 64 | uint index3 = vertexOffset + base + 2u; 65 | 66 | uint flags = varyings[index - varyings[index1].offset].flags; 67 | uint noCull = flags & 0x1u; 68 | 69 | Vertex vertex1 = vertices[index1]; 70 | Vertex vertex2 = vertices[index2]; 71 | Vertex vertex3 = vertices[index3]; 72 | 73 | vec4 pos1 = projectMatrix * viewMatrix * vec4(vertex1.x, vertex1.y, vertex1.z, 1.0); 74 | vec4 pos2 = projectMatrix * viewMatrix * vec4(vertex2.x, vertex2.y, vertex2.z, 1.0); 75 | vec4 pos3 = projectMatrix * viewMatrix * vec4(vertex3.x, vertex3.y, vertex3.z, 1.0); 76 | 77 | float det = determinant(mat3(pos1.xyw, pos2.xyw, pos3.xyw)); 78 | 79 | if (noCull > 0u || det > 0.0) { 80 | uint indexOut = atomicCounterAdd(indexCounter, 3u) / 3u; 81 | 82 | polygonsOut[indexOut + 0].vertex1 = index1; 83 | polygonsOut[indexOut + 0].vertex2 = index2; 84 | polygonsOut[indexOut + 0].vertex3 = index3; 85 | } 86 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/transform/block_vertex_transform_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | uint color; 8 | float u0; 9 | float v0; 10 | uint uv2; 11 | uint normal; 12 | }; 13 | 14 | struct VaryingData { 15 | int offset; 16 | int sharing; 17 | int mesh; 18 | int flags; 19 | }; 20 | 21 | struct SharingData { 22 | mat4 transform; 23 | mat3 normal; 24 | }; 25 | 26 | layout(local_size_x = 128) in; 27 | 28 | layout(binding=0, std430) readonly buffer VerticesIn { 29 | Vertex verticesIn[]; 30 | }; 31 | 32 | layout(binding=1, std430) writeonly buffer VerticesOut { 33 | Vertex verticesOut[]; 34 | }; 35 | 36 | layout(binding=2, std430) readonly buffer Sharings { 37 | SharingData sharings[]; 38 | }; 39 | 40 | layout(binding=3, std430) readonly buffer Varyings { 41 | VaryingData varyings[]; 42 | }; 43 | 44 | layout(binding=4, std430) readonly buffer Meshes { 45 | Vertex meshVertices[]; 46 | }; 47 | 48 | layout(location=0) uniform uint vertexCount; 49 | layout(location=1) uniform uint vertexOffset; 50 | 51 | void main() { 52 | uint indexIn = gl_GlobalInvocationID.x; 53 | uint indexOut = indexIn + vertexOffset; 54 | 55 | if (indexIn >= vertexCount) { 56 | return; 57 | } 58 | 59 | int offset = varyings[indexIn].offset; 60 | uint reference = indexIn - offset; 61 | int sharing = varyings[reference].sharing; 62 | int mesh = varyings[reference].mesh; 63 | 64 | mat4 transformMatrix; 65 | mat3 normalMatrix; 66 | 67 | Vertex vertex; 68 | vec4 refColor; 69 | uvec2 refUv2; 70 | 71 | if (sharing != -1) { 72 | transformMatrix = sharings[sharing].transform; 73 | normalMatrix = sharings[sharing].normal; 74 | } else { 75 | transformMatrix = mat4(1.0); 76 | normalMatrix = mat3(1.0); 77 | } 78 | 79 | if (mesh != -1) { 80 | vertex = meshVertices[mesh + offset]; 81 | refColor = unpackUnorm4x8(verticesIn[reference].color); 82 | refUv2 = floatBitsToUint(unpackSnorm2x16(verticesIn[reference].uv2)); 83 | } else { 84 | vertex = verticesIn[indexIn]; 85 | refColor = vec4(1.0); 86 | refUv2 = uvec2(0u); 87 | } 88 | 89 | vec4 pos = transformMatrix * vec4(vertex.x, vertex.y, vertex.z, 1.0); 90 | vec4 color = refColor * unpackUnorm4x8(vertex.color); 91 | uvec2 uv2 = max(floatBitsToUint(unpackSnorm2x16(vertex.uv2)), refUv2); 92 | vec3 normal = normalize(normalMatrix * unpackSnorm4x8(vertex.normal).xyz); 93 | 94 | verticesOut[indexOut].x = pos.x; 95 | verticesOut[indexOut].y = pos.y; 96 | verticesOut[indexOut].z = pos.z; 97 | 98 | verticesOut[indexOut].u0 = vertex.u0; 99 | verticesOut[indexOut].v0 = vertex.v0; 100 | 101 | verticesOut[indexOut].color = packUnorm4x8(color); 102 | // verticesOut[indexOut].uv1 = verticesIn[reference].uv1; 103 | verticesOut[indexOut].uv2 = packSnorm2x16(uintBitsToFloat(uv2)); 104 | 105 | verticesOut[indexOut].normal = packSnorm4x8(vec4(normal, 0.0)); 106 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/transform/entity_vertex_transform_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | uint color; 8 | float u0; 9 | float v0; 10 | uint uv1; 11 | uint uv2; 12 | uint normal; 13 | }; 14 | 15 | struct VaryingData { 16 | int offset; 17 | int sharing; 18 | int mesh; 19 | int flags; 20 | }; 21 | 22 | struct SharingData { 23 | mat4 transform; 24 | mat3 normal; 25 | }; 26 | 27 | layout(local_size_x = 128) in; 28 | 29 | layout(binding=0, std430) readonly buffer VerticesIn { 30 | Vertex verticesIn[]; 31 | }; 32 | 33 | layout(binding=1, std430) writeonly buffer VerticesOut { 34 | Vertex verticesOut[]; 35 | }; 36 | 37 | layout(binding=2, std430) readonly buffer Sharings { 38 | SharingData sharings[]; 39 | }; 40 | 41 | layout(binding=3, std430) readonly buffer Varyings { 42 | VaryingData varyings[]; 43 | }; 44 | 45 | layout(binding=4, std430) readonly buffer Meshes { 46 | Vertex meshVertices[]; 47 | }; 48 | 49 | layout(location=0) uniform uint vertexCount; 50 | layout(location=1) uniform uint vertexOffset; 51 | 52 | void main() { 53 | uint indexIn = gl_GlobalInvocationID.x; 54 | uint indexOut = indexIn + vertexOffset; 55 | 56 | if (indexIn >= vertexCount) { 57 | return; 58 | } 59 | 60 | int offset = varyings[indexIn].offset; 61 | uint reference = indexIn - offset; 62 | int sharing = varyings[reference].sharing; 63 | int mesh = varyings[reference].mesh; 64 | 65 | mat4 transformMatrix; 66 | mat3 normalMatrix; 67 | 68 | Vertex vertex; 69 | vec4 refColor; 70 | uvec2 refUv2; 71 | 72 | if (sharing != -1) { 73 | transformMatrix = sharings[sharing].transform; 74 | normalMatrix = sharings[sharing].normal; 75 | } else { 76 | transformMatrix = mat4(1.0); 77 | normalMatrix = mat3(1.0); 78 | } 79 | 80 | if (mesh != -1) { 81 | vertex = meshVertices[mesh + offset]; 82 | refColor = unpackUnorm4x8(verticesIn[reference].color); 83 | refUv2 = floatBitsToUint(unpackSnorm2x16(verticesIn[reference].uv2)); 84 | } else { 85 | vertex = verticesIn[indexIn]; 86 | refColor = vec4(1.0); 87 | refUv2 = uvec2(0u); 88 | } 89 | 90 | vec4 pos = transformMatrix * vec4(vertex.x, vertex.y, vertex.z, 1.0); 91 | vec4 color = refColor * unpackUnorm4x8(vertex.color); 92 | uvec2 uv2 = max(floatBitsToUint(unpackSnorm2x16(vertex.uv2)), refUv2); 93 | vec3 normal = normalize(normalMatrix * unpackSnorm4x8(vertex.normal).xyz); 94 | 95 | verticesOut[indexOut].x = pos.x; 96 | verticesOut[indexOut].y = pos.y; 97 | verticesOut[indexOut].z = pos.z; 98 | 99 | verticesOut[indexOut].u0 = vertex.u0; 100 | verticesOut[indexOut].v0 = vertex.v0; 101 | 102 | verticesOut[indexOut].color = packUnorm4x8(color); 103 | verticesOut[indexOut].uv1 = verticesIn[reference].uv1; 104 | verticesOut[indexOut].uv2 = packSnorm2x16(uintBitsToFloat(uv2)); 105 | 106 | verticesOut[indexOut].normal = packSnorm4x8(vec4(normal, 0.0)); 107 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/transform/pos_color_tex_light_vertex_transform_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | uint color; 8 | float u0; 9 | float v0; 10 | uint uv2; 11 | }; 12 | 13 | struct VaryingData { 14 | int offset; 15 | int sharing; 16 | int mesh; 17 | int flags; 18 | }; 19 | 20 | struct SharingData { 21 | mat4 transform; 22 | mat3 normal; 23 | }; 24 | 25 | layout(local_size_x = 128) in; 26 | 27 | layout(binding=0, std430) readonly buffer VerticesIn { 28 | Vertex verticesIn[]; 29 | }; 30 | 31 | layout(binding=1, std430) writeonly buffer VerticesOut { 32 | Vertex verticesOut[]; 33 | }; 34 | 35 | layout(binding=2, std430) readonly buffer Sharings { 36 | SharingData sharings[]; 37 | }; 38 | 39 | layout(binding=3, std430) readonly buffer Varyings { 40 | VaryingData varyings[]; 41 | }; 42 | 43 | layout(binding=4, std430) readonly buffer Meshes { 44 | Vertex meshVertices[]; 45 | }; 46 | 47 | layout(location=0) uniform uint vertexCount; 48 | layout(location=1) uniform uint vertexOffset; 49 | 50 | void main() { 51 | uint indexIn = gl_GlobalInvocationID.x; 52 | uint indexOut = indexIn + vertexOffset; 53 | 54 | if (indexIn >= vertexCount) { 55 | return; 56 | } 57 | 58 | int offset = varyings[indexIn].offset; 59 | uint reference = indexIn - offset; 60 | int sharing = varyings[reference].sharing; 61 | int mesh = varyings[reference].mesh; 62 | 63 | mat4 transformMatrix; 64 | // mat3 normalMatrix; 65 | 66 | Vertex vertex; 67 | vec4 refColor; 68 | uvec2 refUv2; 69 | 70 | if (sharing != -1) { 71 | transformMatrix = sharings[sharing].transform; 72 | // normalMatrix = sharings[sharing].normal; 73 | } else { 74 | transformMatrix = mat4(1.0); 75 | // normalMatrix = mat3(1.0); 76 | } 77 | 78 | if (mesh != -1) { 79 | vertex = meshVertices[mesh + offset]; 80 | refColor = unpackUnorm4x8(verticesIn[reference].color); 81 | refUv2 = floatBitsToUint(unpackSnorm2x16(verticesIn[reference].uv2)); 82 | } else { 83 | vertex = verticesIn[indexIn]; 84 | refColor = vec4(1.0); 85 | refUv2 = uvec2(0u); 86 | } 87 | 88 | vec4 pos = transformMatrix * vec4(vertex.x, vertex.y, vertex.z, 1.0); 89 | vec4 color = refColor * unpackUnorm4x8(vertex.color); 90 | uvec2 uv2 = max(floatBitsToUint(unpackSnorm2x16(vertex.uv2)), refUv2); 91 | // vec3 normal = normalize(normalMatrix * unpackSnorm4x8(vertex.normal).xyz); 92 | 93 | verticesOut[indexOut].x = pos.x; 94 | verticesOut[indexOut].y = pos.y; 95 | verticesOut[indexOut].z = pos.z; 96 | 97 | verticesOut[indexOut].u0 = vertex.u0; 98 | verticesOut[indexOut].v0 = vertex.v0; 99 | 100 | verticesOut[indexOut].color = packUnorm4x8(color); 101 | // verticesOut[indexOut].uv1 = verticesIn[reference].uv1; 102 | verticesOut[indexOut].uv2 = packSnorm2x16(uintBitsToFloat(uv2)); 103 | 104 | // verticesOut[indexOut].normal = packSnorm4x8(vec4(normal, 0.0)); 105 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/transform/pos_tex_color_vertex_transform_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | float u0; 8 | float v0; 9 | uint color; 10 | }; 11 | 12 | struct VaryingData { 13 | int offset; 14 | int sharing; 15 | int mesh; 16 | int flags; 17 | }; 18 | 19 | struct SharingData { 20 | mat4 transform; 21 | mat3 normal; 22 | }; 23 | 24 | layout(local_size_x = 128) in; 25 | 26 | layout(binding=0, std430) readonly buffer VerticesIn { 27 | Vertex verticesIn[]; 28 | }; 29 | 30 | layout(binding=1, std430) writeonly buffer VerticesOut { 31 | Vertex verticesOut[]; 32 | }; 33 | 34 | layout(binding=2, std430) readonly buffer Sharings { 35 | SharingData sharings[]; 36 | }; 37 | 38 | layout(binding=3, std430) readonly buffer Varyings { 39 | VaryingData varyings[]; 40 | }; 41 | 42 | layout(binding=4, std430) readonly buffer Meshes { 43 | Vertex meshVertices[]; 44 | }; 45 | 46 | layout(location=0) uniform uint vertexCount; 47 | layout(location=1) uniform uint vertexOffset; 48 | 49 | void main() { 50 | uint indexIn = gl_GlobalInvocationID.x; 51 | uint indexOut = indexIn + vertexOffset; 52 | 53 | if (indexIn >= vertexCount) { 54 | return; 55 | } 56 | 57 | int offset = varyings[indexIn].offset; 58 | uint reference = indexIn - offset; 59 | int sharing = varyings[reference].sharing; 60 | int mesh = varyings[reference].mesh; 61 | 62 | mat4 transformMatrix; 63 | // mat3 normalMatrix; 64 | 65 | Vertex vertex; 66 | vec4 refColor; 67 | // uvec2 refUv2; 68 | 69 | if (sharing != -1) { 70 | transformMatrix = sharings[sharing].transform; 71 | // normalMatrix = sharings[sharing].normal; 72 | } else { 73 | transformMatrix = mat4(1.0); 74 | // normalMatrix = mat3(1.0); 75 | } 76 | 77 | if (mesh != -1) { 78 | vertex = meshVertices[mesh + offset]; 79 | refColor = unpackUnorm4x8(verticesIn[reference].color); 80 | // refUv2 = floatBitsToUint(unpackSnorm2x16(verticesIn[reference].uv2)); 81 | } else { 82 | vertex = verticesIn[indexIn]; 83 | refColor = vec4(1.0); 84 | // refUv2 = uvec2(0u); 85 | } 86 | 87 | vec4 pos = transformMatrix * vec4(vertex.x, vertex.y, vertex.z, 1.0); 88 | vec4 color = refColor * unpackUnorm4x8(vertex.color); 89 | // uvec2 uv2 = max(floatBitsToUint(unpackSnorm2x16(vertex.uv2)), refUv2); 90 | // vec3 normal = normalize(normalMatrix * unpackSnorm4x8(vertex.normal).xyz); 91 | 92 | verticesOut[indexOut].x = pos.x; 93 | verticesOut[indexOut].y = pos.y; 94 | verticesOut[indexOut].z = pos.z; 95 | 96 | verticesOut[indexOut].u0 = vertex.u0; 97 | verticesOut[indexOut].v0 = vertex.v0; 98 | 99 | verticesOut[indexOut].color = packUnorm4x8(color); 100 | // verticesOut[indexOut].uv1 = verticesIn[reference].uv1; 101 | // verticesOut[indexOut].uv2 = packSnorm2x16(uintBitsToFloat(uv2)); 102 | 103 | // verticesOut[indexOut].normal = packSnorm4x8(vec4(normal, 0.0)); 104 | } -------------------------------------------------------------------------------- /src/main/resources/assets/acceleratedrendering/shaders/core/transform/pos_tex_vertex_transform_shader.compute: -------------------------------------------------------------------------------- 1 | #version 460 core 2 | 3 | struct Vertex { 4 | float x; 5 | float y; 6 | float z; 7 | float u0; 8 | float v0; 9 | }; 10 | 11 | struct VaryingData { 12 | int offset; 13 | int sharing; 14 | int mesh; 15 | int flags; 16 | }; 17 | 18 | struct SharingData { 19 | mat4 transform; 20 | mat3 normal; 21 | }; 22 | 23 | layout(local_size_x = 128) in; 24 | 25 | layout(binding=0, std430) readonly buffer VerticesIn { 26 | Vertex verticesIn[]; 27 | }; 28 | 29 | layout(binding=1, std430) writeonly buffer VerticesOut { 30 | Vertex verticesOut[]; 31 | }; 32 | 33 | layout(binding=2, std430) readonly buffer Sharings { 34 | SharingData sharings[]; 35 | }; 36 | 37 | layout(binding=3, std430) readonly buffer Varyings { 38 | VaryingData varyings[]; 39 | }; 40 | 41 | layout(binding=4, std430) readonly buffer Meshes { 42 | Vertex meshVertices[]; 43 | }; 44 | 45 | layout(location=0) uniform uint vertexCount; 46 | layout(location=1) uniform uint vertexOffset; 47 | 48 | void main() { 49 | uint indexIn = gl_GlobalInvocationID.x; 50 | uint indexOut = indexIn + vertexOffset; 51 | 52 | if (indexIn >= vertexCount) { 53 | return; 54 | } 55 | 56 | int offset = varyings[indexIn].offset; 57 | uint reference = indexIn - offset; 58 | int sharing = varyings[reference].sharing; 59 | int mesh = varyings[reference].mesh; 60 | 61 | mat4 transformMatrix; 62 | // mat3 normalMatrix; 63 | 64 | Vertex vertex; 65 | // vec4 refColor; 66 | // uvec2 refUv2; 67 | 68 | if (sharing != -1) { 69 | transformMatrix = sharings[sharing].transform; 70 | // normalMatrix = sharings[sharing].normal; 71 | } else { 72 | transformMatrix = mat4(1.0); 73 | // normalMatrix = mat3(1.0); 74 | } 75 | 76 | if (mesh != -1) { 77 | vertex = meshVertices[mesh + offset]; 78 | // refColor = unpackUnorm4x8(verticesIn[reference].color); 79 | // refUv2 = floatBitsToUint(unpackSnorm2x16(verticesIn[reference].uv2)); 80 | } else { 81 | vertex = verticesIn[indexIn]; 82 | // refColor = vec4(1.0); 83 | // refUv2 = uvec2(0u); 84 | } 85 | 86 | vec4 pos = transformMatrix * vec4(vertex.x, vertex.y, vertex.z, 1.0); 87 | // vec4 color = refColor * unpackUnorm4x8(vertex.color); 88 | // uvec2 uv2 = max(floatBitsToUint(unpackSnorm2x16(vertex.uv2)), refUv2); 89 | // vec3 normal = normalize(normalMatrix * unpackSnorm4x8(vertex.normal).xyz); 90 | 91 | verticesOut[indexOut].x = pos.x; 92 | verticesOut[indexOut].y = pos.y; 93 | verticesOut[indexOut].z = pos.z; 94 | 95 | verticesOut[indexOut].u0 = vertex.u0; 96 | verticesOut[indexOut].v0 = vertex.v0; 97 | 98 | // verticesOut[indexOut].color = packUnorm4x8(color); 99 | // verticesOut[indexOut].uv1 = verticesIn[reference].uv1; 100 | // verticesOut[indexOut].uv2 = packSnorm2x16(uintBitsToFloat(uv2)); 101 | 102 | // verticesOut[indexOut].normal = packSnorm4x8(vec4(normal, 0.0)); 103 | } --------------------------------------------------------------------------------