From a51c9d2e8d067c06ce3f44ebef9df6a57f902671 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sun, 26 Nov 2023 16:37:27 -0800 Subject: [PATCH 1/5] With this one weird trick, you too can lose 100 uniforms --- .../coderbot/iris/shaderpack/ShaderPack.java | 28 +++++++++++++------ .../iris/shaderpack/ShaderProperties.java | 6 +--- .../preprocessor/PropertiesPreprocessor.java | 14 +--------- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java b/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java index 7f829c3cf1..790d557de4 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java @@ -47,7 +47,17 @@ import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Properties; +import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -75,7 +85,7 @@ public class ShaderPack { private List dimensionIds; private Map dimensionMap; - public ShaderPack(Path root, Iterable environmentDefines) throws IOException, IllegalStateException { + public ShaderPack(Path root, ImmutableList environmentDefines) throws IOException, IllegalStateException { this(root, Collections.emptyMap(), environmentDefines); } @@ -89,11 +99,13 @@ public ShaderPack(Path root, Iterable environmentDefines) throws IOE * have completed, and there is no need to hold on to the path for that reason. * @throws IOException if there are any IO errors during shader pack loading. */ - public ShaderPack(Path root, Map changedConfigs, Iterable environmentDefines) throws IOException, IllegalStateException { + public ShaderPack(Path root, Map changedConfigs, ImmutableList environmentDefines) throws IOException, IllegalStateException { // A null path is not allowed. Objects.requireNonNull(root); - + ArrayList envDefines1 = new ArrayList<>(environmentDefines); + envDefines1.addAll(IrisDefines.createIrisReplacements()); + environmentDefines = ImmutableList.copyOf(envDefines1); ImmutableList.Builder starts = ImmutableList.builder(); ImmutableList potentialFileNames = ShaderPackSourceNames.POTENTIAL_STARTS; @@ -153,10 +165,9 @@ public ShaderPack(Path root, Map changedConfigs, Iterable replacements = IrisDefines.createIrisReplacements(); Iterable finalEnvironmentDefines = environmentDefines; this.shaderProperties = loadProperties(root, "shaders.properties") - .map(source -> new ShaderProperties(source, shaderPackOptions, finalEnvironmentDefines, replacements)) + .map(source -> new ShaderProperties(source, shaderPackOptions, finalEnvironmentDefines)) .orElseGet(ShaderProperties::empty); activeFeatures = new HashSet<>(); @@ -201,7 +212,7 @@ public ShaderPack(Path root, Map changedConfigs, Iterable optionalFeatureFlags = shaderProperties.getOptionalFeatureFlags().stream().filter(flag -> !FeatureFlags.isInvalid(flag)).collect(Collectors.toList()); if (!optionalFeatureFlags.isEmpty()) { - + optionalFeatureFlags.forEach(flag -> Iris.logger.warn("Found flag " + flag)); optionalFeatureFlags.forEach(flag -> newEnvDefines.add(new StringPair("IRIS_FEATURE_" + flag, ""))); } @@ -241,8 +252,7 @@ public ShaderPack(Path root, Map changedConfigs, Iterable finalEnvironmentDefines1 = new ArrayList<>((Collection) finalEnvironmentDefines); - finalEnvironmentDefines1.addAll(IrisDefines.createIrisReplacements()); + Iterable finalEnvironmentDefines1 = environmentDefines; this.sourceProvider = (path) -> { String pathString = path.getPathString(); // Removes the first "/" in the path if present, and the file diff --git a/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java b/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java index 2d7f220599..31e12f2657 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java @@ -111,11 +111,7 @@ private ShaderProperties() { } // TODO: Is there a better solution than having ShaderPack pass a root path to ShaderProperties to be able to read textures? - public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, Iterable environmentDefines, Iterable replacements) { - for (StringPair pair : replacements) { - contents = contents.replaceAll("\\b" + pair.getKey() + "\\b", pair.getValue()); - } - + public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, Iterable environmentDefines) { String preprocessedContents = PropertiesPreprocessor.preprocessSource(contents, shaderPackOptions, environmentDefines); Properties preprocessed = new OrderBackedProperties(); diff --git a/src/main/java/net/coderbot/iris/shaderpack/preprocessor/PropertiesPreprocessor.java b/src/main/java/net/coderbot/iris/shaderpack/preprocessor/PropertiesPreprocessor.java index 7bb2bd9846..74da7f19ab 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/preprocessor/PropertiesPreprocessor.java +++ b/src/main/java/net/coderbot/iris/shaderpack/preprocessor/PropertiesPreprocessor.java @@ -78,19 +78,7 @@ private static String process(Preprocessor preprocessor, String source) { // Not super efficient, but this removes trailing whitespace on lines, fixing an issue with whitespace after // line continuations (see PreprocessorTest#testWeirdPropertiesLineContinuation) // Required for Voyager Shader - source = Arrays.stream(source.split("\\R")).map(String::trim) - .map(line -> { - if (line.startsWith("#")) { - // In PropertyCollectingListener we suppress "unknown preprocessor directive errors" and - // assume the line to be a comment, since in .properties files `#` also functions as a comment - // marker. - return line; - } else { - // This is a hack to ensure that non-macro lines don't have any preprocessing applied... - // In properties files, we don't substitute #define values except on macro lines. - return "#warning IRIS_PASSTHROUGH " + line; - } - }).collect(Collectors.joining("\n")) + "\n"; + source = Arrays.stream(source.split("\\R")).map(String::trim).collect(Collectors.joining("\n")) + "\n"; // TODO: This is a horrible fix to trick the preprocessor into not seeing the backslashes during processing. We need a better way to do this. source = source.replace("\\", "IRIS_PASSTHROUGHBACKSLASH"); From f2998a1001656bfa0dd9c9a36e654fa25a90e060 Mon Sep 17 00:00:00 2001 From: IMS Date: Mon, 27 Nov 2023 14:51:24 -0800 Subject: [PATCH 2/5] I swear I did this --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6558bedcfe..70e63fdd26 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ## Links -* **Visit [our website](https://irisshaders.net) for downloads and pretty screenshots!** +* **Visit [our website](https://irisshaders.dev) for downloads and pretty screenshots!** * * **Visit [Modrinth](https://modrinth.com/shaders) to find shader packs!** * Visit [our Discord server](https://discord.gg/jQJnav2jPu) to chat about the mod and get support! It's also a great place to get development updates right as they're happening. * Visit [the developer documentation](https://github.com/IrisShaders/Iris/tree/trunk/docs/development) for information on developing, building, and contributing to Iris! From 8b55c8b7ec708662245342a048c30cd84f13c022 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 2 Dec 2023 08:47:05 -0800 Subject: [PATCH 3/5] Fix some issues with color space conversion --- .../net/coderbot/iris/mixin/MixinGameRenderer.java | 5 +++++ .../pipeline/DeferredWorldRenderingPipeline.java | 5 +++++ .../FixedFunctionWorldRenderingPipeline.java | 5 +++++ .../iris/pipeline/WorldRenderingPipeline.java | 1 + .../newshader/NewWorldRenderingPipeline.java | 4 ++++ .../coderbot/iris/shaderpack/ShaderProperties.java | 11 +++++++++++ src/main/resources/colorSpace.csh | 14 +++++++------- 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java index aabf4052ed..cea7e40e54 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java @@ -57,6 +57,11 @@ public class MixinGameRenderer { itemInHandRenderer.renderHandsWithItems(tickDelta, poseStack, bufferSource, localPlayer, light); } + @Inject(method = "renderLevel", at = @At("TAIL")) + private void iris$runColorSpace(float pGameRenderer0, long pLong1, PoseStack pPoseStack2, CallbackInfo ci) { + Iris.getPipelineManager().getPipeline().ifPresent(WorldRenderingPipeline::finalizeGameRendering); + } + @Redirect(method = "reloadShaders", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/Lists;newArrayList()Ljava/util/ArrayList;")) private ArrayList iris$reloadGeometryShaders() { ArrayList programs = Lists.newArrayList(); diff --git a/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java b/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java index e177d6b902..858528c985 100644 --- a/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java @@ -1290,6 +1290,11 @@ public void finalizeLevelRendering() { isRenderingFullScreenPass = false; } + @Override + public void finalizeGameRendering() { + + } + @Override public SodiumTerrainPipeline getSodiumTerrainPipeline() { return sodiumTerrainPipeline; diff --git a/src/main/java/net/coderbot/iris/pipeline/FixedFunctionWorldRenderingPipeline.java b/src/main/java/net/coderbot/iris/pipeline/FixedFunctionWorldRenderingPipeline.java index 95a038543f..e4346a5ce4 100644 --- a/src/main/java/net/coderbot/iris/pipeline/FixedFunctionWorldRenderingPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/FixedFunctionWorldRenderingPipeline.java @@ -140,6 +140,11 @@ public void finalizeLevelRendering() { // stub: nothing to do here } + @Override + public void finalizeGameRendering() { + // stub: nothing to do here + } + @Override public void destroy() { // stub: nothing to do here diff --git a/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPipeline.java b/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPipeline.java index 5e4ba7b0fc..3bec5584b0 100644 --- a/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPipeline.java @@ -45,6 +45,7 @@ public interface WorldRenderingPipeline { void beginTranslucents(); void finalizeLevelRendering(); + void finalizeGameRendering(); void destroy(); SodiumTerrainPipeline getSodiumTerrainPipeline(); diff --git a/src/main/java/net/coderbot/iris/pipeline/newshader/NewWorldRenderingPipeline.java b/src/main/java/net/coderbot/iris/pipeline/newshader/NewWorldRenderingPipeline.java index 664faa2bff..670cf06f20 100644 --- a/src/main/java/net/coderbot/iris/pipeline/newshader/NewWorldRenderingPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/newshader/NewWorldRenderingPipeline.java @@ -1094,6 +1094,10 @@ public void finalizeLevelRendering() { isRenderingWorld = false; compositeRenderer.renderAll(); finalPassRenderer.renderFinalPass(); + } + + @Override + public void finalizeGameRendering() { colorSpaceConverter.process(Minecraft.getInstance().getMainRenderTarget().getColorTextureId()); } diff --git a/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java b/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java index 31e12f2657..5adba0c55a 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java @@ -29,9 +29,11 @@ import net.coderbot.iris.shaderpack.preprocessor.PropertiesPreprocessor; import net.coderbot.iris.shaderpack.texture.TextureStage; import net.coderbot.iris.uniforms.custom.CustomUniforms; +import net.fabricmc.loader.api.FabricLoader; import java.io.IOException; import java.io.StringReader; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.EnumMap; @@ -114,6 +116,15 @@ private ShaderProperties() { public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, Iterable environmentDefines) { String preprocessedContents = PropertiesPreprocessor.preprocessSource(contents, shaderPackOptions, environmentDefines); + if (Iris.getIrisConfig().areDebugOptionsEnabled()) { + try { + Files.writeString(FabricLoader.getInstance().getGameDir().resolve("preprocessed.properties"), preprocessedContents); + Files.writeString(FabricLoader.getInstance().getGameDir().resolve("original.properties"), contents); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + Properties preprocessed = new OrderBackedProperties(); Properties original = new OrderBackedProperties(); try { diff --git a/src/main/resources/colorSpace.csh b/src/main/resources/colorSpace.csh index baee69b49b..016417bb04 100644 --- a/src/main/resources/colorSpace.csh +++ b/src/main/resources/colorSpace.csh @@ -10,7 +10,7 @@ layout(rgba8) uniform image2D readImage; #else uniform sampler2D readImage; in vec2 uv; -out vec3 outColor; +out vec4 outColor; #endif // https://en.wikipedia.org/wiki/Rec._709#Transfer_characteristics @@ -107,13 +107,13 @@ void main() { #if CURRENT_COLOR_SPACE != SRGB #ifdef COMPUTE ivec2 PixelIndex = ivec2(gl_GlobalInvocationID.xy); - vec3 SourceColor = imageLoad(readImage, PixelIndex).rgb; + vec4 SourceColor = imageLoad(readImage, PixelIndex); #else - vec3 SourceColor = texture(readImage, uv).rgb; + vec4 SourceColor = texture(readImage, uv); #endif - SourceColor = InverseEOTF_IEC61966(SourceColor); + SourceColor.rgb = InverseEOTF_IEC61966(SourceColor.rgb); - vec3 TargetColor = SourceColor; + vec3 TargetColor = SourceColor.rgb; #if CURRENT_COLOR_SPACE == DCI_P3 // https://en.wikipedia.org/wiki/DCI-P3 @@ -137,9 +137,9 @@ void main() { #endif #ifdef COMPUTE - imageStore(readImage, PixelIndex, vec4(TargetColor, 1.0)); + imageStore(readImage, PixelIndex, vec4(TargetColor, SourceColor.a)); #else - outColor = TargetColor; + outColor = vec4(TargetColor, SourceColor.a); #endif #endif } From e8a625222920f9b9e8249b7adb285a83abf9bbda Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sun, 3 Dec 2023 09:24:02 -0800 Subject: [PATCH 4/5] Extremely dumb code --- .../preprocessor/PropertiesPreprocessor.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/coderbot/iris/shaderpack/preprocessor/PropertiesPreprocessor.java b/src/main/java/net/coderbot/iris/shaderpack/preprocessor/PropertiesPreprocessor.java index 74da7f19ab..414e877203 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/preprocessor/PropertiesPreprocessor.java +++ b/src/main/java/net/coderbot/iris/shaderpack/preprocessor/PropertiesPreprocessor.java @@ -6,6 +6,7 @@ import org.anarres.cpp.Feature; import org.anarres.cpp.LexerException; import org.anarres.cpp.Preprocessor; +import org.anarres.cpp.PreprocessorCommand; import org.anarres.cpp.StringLexerSource; import org.anarres.cpp.Token; @@ -14,6 +15,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; @@ -78,7 +80,21 @@ private static String process(Preprocessor preprocessor, String source) { // Not super efficient, but this removes trailing whitespace on lines, fixing an issue with whitespace after // line continuations (see PreprocessorTest#testWeirdPropertiesLineContinuation) // Required for Voyager Shader - source = Arrays.stream(source.split("\\R")).map(String::trim).collect(Collectors.joining("\n")) + "\n"; + source = Arrays.stream(source.split("\\R")).map(String::trim) + .map(line -> { + if (line.startsWith("#")) { + for (PreprocessorCommand command : PreprocessorCommand.values()) { + if (line.startsWith("#" + (command.name().replace("PP_", "").toLowerCase(Locale.ROOT)))) { + return line; + } + } + return ""; + } + // In PropertyCollectingListener we suppress "unknown preprocessor directive errors" and + // assume the line to be a comment, since in .properties files `#` also functions as a comment + // marker. + return line.replace("#", ""); + }).collect(Collectors.joining("\n")) + "\n"; // TODO: This is a horrible fix to trick the preprocessor into not seeing the backslashes during processing. We need a better way to do this. source = source.replace("\\", "IRIS_PASSTHROUGHBACKSLASH"); From 8a6cdbbd7d3cc8ad46aea7307a170aaae78c36bc Mon Sep 17 00:00:00 2001 From: IMS212 Date: Tue, 5 Dec 2023 15:23:11 -0800 Subject: [PATCH 5/5] Fix SSBO's... again --- .../net/coderbot/iris/shaderpack/ShaderProperties.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java b/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java index 5adba0c55a..6276c953e3 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java @@ -531,10 +531,6 @@ public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, It customUniforms.addVariable(parts[0], parts[1], value, true); }); - - handleWhitespacedListDirective(key, value, "iris.features.required", options -> requiredFeatureFlags = options); - handleWhitespacedListDirective(key, value, "iris.features.optional", options -> optionalFeatureFlags = options); - // TODO: Buffer size directives // TODO: Conditional program enabling directives }); @@ -544,6 +540,9 @@ public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, It String key = (String) keyObject; String value = (String) valueObject; + handleWhitespacedListDirective(key, value, "iris.features.required", options -> requiredFeatureFlags = options); + handleWhitespacedListDirective(key, value, "iris.features.optional", options -> optionalFeatureFlags = options); + // Defining "sliders" multiple times in the properties file will only result in // the last definition being used, should be tested if behavior matches OptiFine handleWhitespacedListDirective(key, value, "sliders", sliders -> sliderOptions = sliders);