From 702ae8e22262aa77174cc1ce1ace9d14be493f34 Mon Sep 17 00:00:00 2001 From: fayer3 Date: Wed, 18 Dec 2024 23:57:37 +0100 Subject: [PATCH] fix crash when the vr fabulous shader fails to compile --- .../client_vr/provider/VRRenderer.java | 8 +++++ .../vivecraft/client_vr/render/VRShaders.java | 4 +++ .../client/renderer/ShaderManagerMixin.java | 29 +++++++++++++++++++ .../assets/vivecraft/lang/de_de.json | 1 + .../assets/vivecraft/lang/en_us.json | 1 + .../main/resources/vivecraft.accesswidener | 4 +++ .../src/main/resources/vivecraft.mixins.json | 1 + gradle.properties | 2 +- 8 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/org/vivecraft/mixin/client/renderer/ShaderManagerMixin.java diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java b/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java index 8e6ab0d5a..30bb11437 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java @@ -484,6 +484,14 @@ public void setupRenderConfiguration() throws Exception { this.reinitFrameBuffers("gfx setting change"); } + if (minecraft.options.graphicsMode().get() == GraphicsStatus.FABULOUS && + minecraft.getShaderManager().getProgram(VRShaders.vrTransparency) == null) { + minecraft.gui.getChat().addMessage(Component.translatable("vivecraft.messages.fabulousFailed")); + minecraft.options.graphicsMode().set(GraphicsStatus.FAST); + minecraft.levelRenderer.allChanged(); + this.reinitFrameBuffers("fabulous missing"); + } + if ((this.resizeFrameBuffers || this.reinitFramebuffers) && ((WindowExtension) (Object) Minecraft.getInstance().getWindow()).vivecraft$getActualScreenWidth() != 0 && ((WindowExtension) (Object) Minecraft.getInstance().getWindow()).vivecraft$getActualScreenHeight() != 0) { diff --git a/common/src/main/java/org/vivecraft/client_vr/render/VRShaders.java b/common/src/main/java/org/vivecraft/client_vr/render/VRShaders.java index 93c6a6af9..99121e06b 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/VRShaders.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/VRShaders.java @@ -57,6 +57,10 @@ public class VRShaders { ResourceLocation.fromNamespaceAndPath("vivecraft", "core/rendertype_end_gateway_vr"), DefaultVertexFormat.POSITION, ShaderDefines.EMPTY); + public static final ShaderProgram vrTransparency = new ShaderProgram( + ResourceLocation.fromNamespaceAndPath("vivecraft", "post/vrtransparency"), + DefaultVertexFormat.POSITION, ShaderDefines.EMPTY); + private VRShaders() { } diff --git a/common/src/main/java/org/vivecraft/mixin/client/renderer/ShaderManagerMixin.java b/common/src/main/java/org/vivecraft/mixin/client/renderer/ShaderManagerMixin.java new file mode 100644 index 000000000..12d42579b --- /dev/null +++ b/common/src/main/java/org/vivecraft/mixin/client/renderer/ShaderManagerMixin.java @@ -0,0 +1,29 @@ +package org.vivecraft.mixin.client.renderer; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.client.renderer.ShaderManager; +import net.minecraft.client.renderer.ShaderProgram; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.vivecraft.client_vr.render.VRShaders; +import org.vivecraft.client_vr.settings.VRSettings; + +import java.util.Map; +import java.util.Optional; + +@Mixin(ShaderManager.class) +public class ShaderManagerMixin { + + @WrapOperation(method = "apply(Lnet/minecraft/client/renderer/ShaderManager$Configs;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)V", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", ordinal = 1)) + private Object vivecraft$letTransparencyFail(Map instance, Object k, Object v, Operation original, @Local ShaderManager.CompilationCache compilationCache) { + if (((ShaderProgram) k).configId().equals(VRShaders.vrTransparency.configId())) { + // let vrtransparency fail, some gpus don't support the 18 samplers we need + VRSettings.logger.error("Vivecraft: Failed to compile 'post/vrtransparency' fabulous graphics will not be available in VR.", (ShaderManager.CompilationException) v); + compilationCache.programs.put((ShaderProgram) k, Optional.empty()); + return null; + } + return original.call(instance, k, v); + } +} diff --git a/common/src/main/resources/assets/vivecraft/lang/de_de.json b/common/src/main/resources/assets/vivecraft/lang/de_de.json index 55e001f2f..0d44c66f4 100644 --- a/common/src/main/resources/assets/vivecraft/lang/de_de.json +++ b/common/src/main/resources/assets/vivecraft/lang/de_de.json @@ -503,6 +503,7 @@ "vivecraft.messages.stencil": "[Vivecraft] Ein anderer Mod verwendet den Schablonen Puffer, wenn Sie Grafikfehler bemerken, versuchen Sie die Augenschablone in folgendem Menü zu deaktivieren: %s\nSie können diese Nachricht in folgendem Menü deaktivieren: %s", "vivecraft.messages.3options": "%s > %s > %s", "vivecraft.messages.openSettings": "Klicken um die Einstellungen zu öffnen.", + "vivecraft.messages.fabulousFailed": "§cFabelhaft VR Shader konnte nicht kompiliert werden, prüfe den Log für den kompletten Fehler.", "vivecraft.message.kofi": "Unterstütze uns auf Ko-Fi", "vivecraft.message.overriddenbyserver": "§6Einstellung überschrieben vom Server.§r\n", "vivecraft.message.limitedbyserver": "§6Einstellungsbereich vom Server limitiert (%s - %s)§r\n", diff --git a/common/src/main/resources/assets/vivecraft/lang/en_us.json b/common/src/main/resources/assets/vivecraft/lang/en_us.json index e64e4c3aa..e96495d51 100644 --- a/common/src/main/resources/assets/vivecraft/lang/en_us.json +++ b/common/src/main/resources/assets/vivecraft/lang/en_us.json @@ -505,6 +505,7 @@ "vivecraft.messages.stencil": "[Vivecraft] A different mod uses the stencil buffer, if you run into weird rendering issues, try disabling the Eye Stencil in: %s\nYou can disable this message in: %s", "vivecraft.messages.3options": "%s > %s > %s", "vivecraft.messages.openSettings": "Click to open settings", + "vivecraft.messages.fabulousFailed": "§cFabulous VR shader failed to compile, check the log for the full error.", "vivecraft.message.kofi": "Support us on Ko-Fi", "vivecraft.message.overriddenbyserver": "§6Setting overridden by server.§r\n", "vivecraft.message.limitedbyserver": "§6Setting range limited by server (%s - %s)§r\n", diff --git a/common/src/main/resources/vivecraft.accesswidener b/common/src/main/resources/vivecraft.accesswidener index 0c18a385e..d6c412f9a 100644 --- a/common/src/main/resources/vivecraft.accesswidener +++ b/common/src/main/resources/vivecraft.accesswidener @@ -100,3 +100,7 @@ accessible field net/minecraft/server/network/ServerGamePacketListenerImpl above # to render the camera widget with dispaly accessible field net/minecraft/client/renderer/item/ItemStackRenderState layers [Lnet/minecraft/client/renderer/item/ItemStackRenderState$LayerRenderState; accessible field net/minecraft/client/renderer/item/ItemStackRenderState$LayerRenderState model Lnet/minecraft/client/resources/model/BakedModel; + +# to let the vr transparancy shader fail to compile +accessible class net/minecraft/client/renderer/ShaderManager$CompilationCache +accessible field net/minecraft/client/renderer/ShaderManager$CompilationCache programs Ljava/util/Map; diff --git a/common/src/main/resources/vivecraft.mixins.json b/common/src/main/resources/vivecraft.mixins.json index 1207c3813..953c5ff3a 100644 --- a/common/src/main/resources/vivecraft.mixins.json +++ b/common/src/main/resources/vivecraft.mixins.json @@ -16,6 +16,7 @@ "client.player.AbstractClientPlayerMixin", "client.renderer.ItemBlockRenderTypesMixin", "client.renderer.RenderStateShardAccessor", + "client.renderer.ShaderManagerMixin", "client.renderer.block.LiquidBlockRendererMixin", "client.renderer.entity.ArmedEntityRenderStateMixin", "client.renderer.entity.EntityRenderDispatcherMixin", diff --git a/gradle.properties b/gradle.properties index f203fc272..906b24a91 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ minecraft_version=1.21.4 enabled_platforms=fabric,forge,neoforge archives_base_name=vivecraft -mod_version=1.1.14-b3 +mod_version=1.1.14-b4 maven_group=org.vivecraft architectury_version=15.0.1