From 9b56d16f55f16be0e342ac151c71c428acf5e61d Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Fri, 2 Sep 2022 22:49:18 -0700 Subject: [PATCH] AAAAAAAAAAAAMD - Fixes issue rendering models in block format while using instancing on AMD - A very hacky fix, everything will be cleaner in 1.0 - Diagonalport flw.loadRenderDoc jvm arg from 1.18/culling --- build.gradle | 1 + .../backend/model/FallbackAllocator.java | 3 +- .../flywheel/backend/model/IndexedModel.java | 11 ++++++-- .../jozufozu/flywheel/core/model/Model.java | 1 - .../flywheel/mixin/ClientMainMixin.java | 28 +++++++++++++++++++ src/main/resources/flywheel.mixins.json | 13 +++++---- 6 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/jozufozu/flywheel/mixin/ClientMainMixin.java diff --git a/build.gradle b/build.gradle index b7a987060..3bcd74b6e 100644 --- a/build.gradle +++ b/build.gradle @@ -44,6 +44,7 @@ minecraft { property 'mixin.debug.export', 'true' property 'mixin.env.remapRefMap', 'true' property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" + property 'flw.loadRenderDoc', 'true' arg '-mixin.config=flywheel.mixins.json' diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/FallbackAllocator.java b/src/main/java/com/jozufozu/flywheel/backend/model/FallbackAllocator.java index 7520afff2..42d1a67df 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/model/FallbackAllocator.java +++ b/src/main/java/com/jozufozu/flywheel/backend/model/FallbackAllocator.java @@ -1,5 +1,6 @@ package com.jozufozu.flywheel.backend.model; +import com.jozufozu.flywheel.core.Formats; import com.jozufozu.flywheel.core.model.Model; public enum FallbackAllocator implements ModelAllocator { @@ -7,7 +8,7 @@ public enum FallbackAllocator implements ModelAllocator { @Override public BufferedModel alloc(Model model, Callback allocationCallback) { - IndexedModel out = new IndexedModel(model); + IndexedModel out = new IndexedModel(model, Formats.POS_TEX_NORMAL); allocationCallback.onAlloc(out); return out; } diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/IndexedModel.java b/src/main/java/com/jozufozu/flywheel/backend/model/IndexedModel.java index 4052e569e..26d3672d1 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/model/IndexedModel.java +++ b/src/main/java/com/jozufozu/flywheel/backend/model/IndexedModel.java @@ -20,6 +20,7 @@ import com.jozufozu.flywheel.core.model.Model; */ public class IndexedModel implements BufferedModel { + protected final VertexType type; protected final Model model; protected final GlPrimitive primitiveMode; protected ElementBuffer ebo; @@ -27,6 +28,11 @@ public class IndexedModel implements BufferedModel { protected boolean deleted; public IndexedModel(Model model) { + this(model, model.getType()); + } + + public IndexedModel(Model model, VertexType type) { + this.type = type; this.model = model; this.primitiveMode = GlPrimitive.TRIANGLES; @@ -38,7 +44,8 @@ public class IndexedModel implements BufferedModel { // mirror it in system memory, so we can write to it, and upload our model. try (MappedBuffer buffer = vbo.getBuffer()) { - model.writeInto(buffer.unwrap()); + type.createWriter(buffer.unwrap()) + .writeVertexList(model.getReader()); } catch (Exception e) { Flywheel.LOGGER.error(String.format("Error uploading model '%s':", model.name()), e); } @@ -81,7 +88,7 @@ public class IndexedModel implements BufferedModel { @Override public VertexType getType() { - return model.getType(); + return type; } public int getVertexCount() { diff --git a/src/main/java/com/jozufozu/flywheel/core/model/Model.java b/src/main/java/com/jozufozu/flywheel/core/model/Model.java index c93e1df84..72692a614 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/Model.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/Model.java @@ -6,7 +6,6 @@ import com.jozufozu.flywheel.api.vertex.VertexList; import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.backend.model.ElementBuffer; import com.jozufozu.flywheel.core.Formats; -import com.jozufozu.flywheel.core.QuadConverter; /** * A model that can be rendered by flywheel. diff --git a/src/main/java/com/jozufozu/flywheel/mixin/ClientMainMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/ClientMainMixin.java new file mode 100644 index 000000000..e753a1a83 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/mixin/ClientMainMixin.java @@ -0,0 +1,28 @@ +package com.jozufozu.flywheel.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.main.Main; + +@Mixin(Main.class) +public class ClientMainMixin { + + @Inject(method = "main", at = @At("HEAD")) + private static void injectRenderDoc(CallbackInfo ci) { + // Only try to load RenderDoc if a system property is set. + if (System.getProperty("flw.loadRenderDoc") == null) { + return; + } + + try { + System.loadLibrary("renderdoc"); + } catch (Throwable ignored) { + // Oh well, we tried. + // On Windows, RenderDoc installs to "C:\Program Files\RenderDoc\" + System.err.println("Is RenderDoc in your PATH?"); + } + } +} diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.mixins.json index 265b160c7..71d3f7495 100644 --- a/src/main/resources/flywheel.mixins.json +++ b/src/main/resources/flywheel.mixins.json @@ -9,24 +9,25 @@ "BlockEntityTypeMixin", "BufferBuilderMixin", "CameraMixin", - "instancemanage.ChunkRebuildHooksMixin", - "instancemanage.ChunkRenderDispatcherAccessor", "ClientLevelMixin", + "ClientMainMixin", "EntityTypeMixin", "FixFabulousDepthMixin", "FrustumMixin", "GlStateManagerMixin", - "instancemanage.InstanceAddMixin", - "instancemanage.InstanceRemoveMixin", "LevelRendererAccessor", "LevelRendererMixin", "PausedPartialTickAccessor", - "instancemanage.RenderChunkAccessor", - "instancemanage.RenderChunkMixin", "RenderTexturesMixin", "RenderTypeMixin", "atlas.AtlasDataMixin", "atlas.SheetDataAccessor", + "instancemanage.ChunkRebuildHooksMixin", + "instancemanage.ChunkRenderDispatcherAccessor", + "instancemanage.InstanceAddMixin", + "instancemanage.InstanceRemoveMixin", + "instancemanage.RenderChunkAccessor", + "instancemanage.RenderChunkMixin", "light.LightUpdateMixin", "light.NetworkLightUpdateMixin", "matrix.Matrix3fMixin",