From 5bec2aa4ac3a311dd17521c82ce2e297b1f66106 Mon Sep 17 00:00:00 2001 From: supsm Date: Sun, 26 Feb 2023 12:17:33 -0800 Subject: [PATCH 1/3] fix chisels n bits compatibility (#407) --- .../canvas/mixin/MixinModelBlockRenderer.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/main/java/grondag/canvas/mixin/MixinModelBlockRenderer.java b/src/main/java/grondag/canvas/mixin/MixinModelBlockRenderer.java index c00164baa..c4c5144bb 100644 --- a/src/main/java/grondag/canvas/mixin/MixinModelBlockRenderer.java +++ b/src/main/java/grondag/canvas/mixin/MixinModelBlockRenderer.java @@ -21,11 +21,14 @@ package grondag.canvas.mixin; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; +import grondag.canvas.apiimpl.rendercontext.CanvasBlockRenderContext; import net.minecraft.client.renderer.block.ModelBlockRenderer; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; @@ -33,19 +36,13 @@ import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; -import grondag.canvas.apiimpl.rendercontext.CanvasBlockRenderContext; - -// WIP: change this an inject with cancel so that mods that hook in here don't break directly - esp C&B // WIP: move hooks upstream so that multi-consumer is available in more cases @Mixin(ModelBlockRenderer.class) public abstract class MixinModelBlockRenderer { - /** - * @author grondag - * @reason performance; less bad than inject and cancel at head - */ - @Overwrite - public void tesselateBlock(BlockAndTintGetter blockView, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, VertexConsumer buffer, boolean checkSides, RandomSource randomSource, long seed, int overlay) { + @Inject(at = @At("HEAD"), method = "tesselateBlock", cancellable = true) + public void beforeTesselateBlock(BlockAndTintGetter blockView, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, VertexConsumer buffer, boolean checkSides, RandomSource randomSource, long seed, int overlay, CallbackInfo ci) { // PERF: try to avoid threadlocal lookup here CanvasBlockRenderContext.get().render((ModelBlockRenderer) (Object) this, blockView, model, state, pos, poseStack, buffer, checkSides, seed, overlay); + ci.cancel(); } } From e42ace3058f983c97d4397914ddb9cfd4190b51e Mon Sep 17 00:00:00 2001 From: supsm Date: Mon, 1 May 2023 18:25:19 -0700 Subject: [PATCH 2/3] fix import order --- .../java/grondag/canvas/mixin/MixinModelBlockRenderer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/grondag/canvas/mixin/MixinModelBlockRenderer.java b/src/main/java/grondag/canvas/mixin/MixinModelBlockRenderer.java index c4c5144bb..111d10b7b 100644 --- a/src/main/java/grondag/canvas/mixin/MixinModelBlockRenderer.java +++ b/src/main/java/grondag/canvas/mixin/MixinModelBlockRenderer.java @@ -28,7 +28,6 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; -import grondag.canvas.apiimpl.rendercontext.CanvasBlockRenderContext; import net.minecraft.client.renderer.block.ModelBlockRenderer; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; @@ -36,6 +35,8 @@ import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; +import grondag.canvas.apiimpl.rendercontext.CanvasBlockRenderContext; + // WIP: move hooks upstream so that multi-consumer is available in more cases @Mixin(ModelBlockRenderer.class) public abstract class MixinModelBlockRenderer { From ed27032158551b2e04433cdedb3edfe1ce4efe91 Mon Sep 17 00:00:00 2001 From: spiralhalo Date: Sun, 11 Jun 2023 15:56:54 +0700 Subject: [PATCH 3/3] Backport - Verify accessibility options when closing video settings screen as well - Move `onInit` and `onResize` just before `beforeWorldRender` --- .../MixinAccessibilityOptionsScreen.java | 12 ++---------- .../mixin/MixinVideoSettingsScreen.java | 12 ++++++++++++ .../canvas/pipeline/PipelineManager.java | 19 ++++++++++++++++--- .../canvas/shader/data/AccessibilityData.java | 8 ++++++++ 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/main/java/grondag/canvas/mixin/MixinAccessibilityOptionsScreen.java b/src/main/java/grondag/canvas/mixin/MixinAccessibilityOptionsScreen.java index 308d8f9d0..3d302a552 100644 --- a/src/main/java/grondag/canvas/mixin/MixinAccessibilityOptionsScreen.java +++ b/src/main/java/grondag/canvas/mixin/MixinAccessibilityOptionsScreen.java @@ -25,7 +25,6 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import net.minecraft.client.Minecraft; import net.minecraft.client.OptionInstance; import net.minecraft.client.Options; import net.minecraft.client.gui.screens.AccessibilityOptionsScreen; @@ -33,7 +32,6 @@ import net.minecraft.client.gui.screens.SimpleOptionsSubScreen; import net.minecraft.network.chat.Component; -import grondag.canvas.apiimpl.CanvasState; import grondag.canvas.shader.data.AccessibilityData; @Mixin(AccessibilityOptionsScreen.class) @@ -44,18 +42,12 @@ public MixinAccessibilityOptionsScreen(Screen screen, Options options, Component @Inject(at = @At("HEAD"), method = "method_31384") void onClosing(CallbackInfo ci) { - canvas_onClose(); + AccessibilityData.onCloseOptionScreen(); } @Override public void onClose() { - canvas_onClose(); + AccessibilityData.onCloseOptionScreen(); super.onClose(); } - - private static void canvas_onClose() { - if (AccessibilityData.checkChanged() && Minecraft.getInstance().level != null) { - CanvasState.recompileIfNeeded(true); - } - } } diff --git a/src/main/java/grondag/canvas/mixin/MixinVideoSettingsScreen.java b/src/main/java/grondag/canvas/mixin/MixinVideoSettingsScreen.java index 0d1836bdb..35c237a27 100644 --- a/src/main/java/grondag/canvas/mixin/MixinVideoSettingsScreen.java +++ b/src/main/java/grondag/canvas/mixin/MixinVideoSettingsScreen.java @@ -29,6 +29,7 @@ import net.minecraft.client.gui.screens.VideoSettingsScreen; import net.minecraft.network.chat.Component; +import grondag.canvas.shader.data.AccessibilityData; import grondag.canvas.varia.CanvasButtonWidget; @Mixin(VideoSettingsScreen.class) @@ -41,4 +42,15 @@ public MixinVideoSettingsScreen(Component title) { private void onInit(CallbackInfo info) { CanvasButtonWidget.parent = this; } + + @Inject(at = @At("HEAD"), method = "method_19865") + void onClosing(CallbackInfo ci) { + AccessibilityData.onCloseOptionScreen(); + } + + @Override + public void onClose() { + AccessibilityData.onCloseOptionScreen(); + super.onClose(); + } } diff --git a/src/main/java/grondag/canvas/pipeline/PipelineManager.java b/src/main/java/grondag/canvas/pipeline/PipelineManager.java index 47449a62c..7851f5113 100644 --- a/src/main/java/grondag/canvas/pipeline/PipelineManager.java +++ b/src/main/java/grondag/canvas/pipeline/PipelineManager.java @@ -61,6 +61,9 @@ public class PipelineManager { private static int oldTex0; private static int oldTex1; + private static boolean pendingInitPass; + private static boolean pendingResizePass; + public static int width() { return w; } @@ -103,8 +106,8 @@ public static void init(PrimaryFrameBuffer primary, int width, int height) { collector.clear(); // releases storage - renderFullFramePasses(Pipeline.onInit); - renderFullFramePasses(Pipeline.onResize); + pendingInitPass = true; + pendingResizePass = true; } private static void addVertex(float x, float y, float z, float u, float v, int[] target, int index) { @@ -123,10 +126,20 @@ public static void onResize(PrimaryFrameBuffer primary, int newWidth, int newHei Pipeline.onResize(primary, w, h); - renderFullFramePasses(Pipeline.onResize); + pendingResizePass = true; } public static void beforeWorldRender() { + if (pendingInitPass) { + renderFullFramePasses(Pipeline.onInit); + pendingInitPass = false; + } + + if (pendingResizePass) { + renderFullFramePasses(Pipeline.onResize); + pendingResizePass = false; + } + renderFullFramePasses(Pipeline.onWorldRenderStart, Timekeeper.ProfilerGroup.BeforeWorld); Pipeline.defaultFbo.bind(); } diff --git a/src/main/java/grondag/canvas/shader/data/AccessibilityData.java b/src/main/java/grondag/canvas/shader/data/AccessibilityData.java index 0239f6987..87c592916 100644 --- a/src/main/java/grondag/canvas/shader/data/AccessibilityData.java +++ b/src/main/java/grondag/canvas/shader/data/AccessibilityData.java @@ -23,6 +23,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; +import grondag.canvas.apiimpl.CanvasState; + public class AccessibilityData { static final ResourceLocation id = new ResourceLocation("canvas:accessibility"); @@ -37,6 +39,12 @@ public class AccessibilityData { static String cache = null; + public static void onCloseOptionScreen() { + if (AccessibilityData.checkChanged() && Minecraft.getInstance().level != null) { + CanvasState.recompileIfNeeded(true); + } + } + public static boolean checkChanged() { final var mc = Minecraft.getInstance();