Support for custom uniforms (#902)

* wip backport of custom uniforms

* Functioning custom uniforms maybe?

* Workon separating dynamic/non-dynamic uniforms and making variables available to custom uniforms (currently the JVM dies horribly)

* wip

* It no longer crashes horrifically

* star imports
This commit is contained in:
Darren Eberly authored and GitHub committed 2025-03-18 10:04:31 -07:00
1 parent 6fa973dbc8
commit bed724ba59
89 files changed
+4622 -266

No files matched your search

@@ -28,6 +28,7 @@ import net.coderbot.iris.shaderpack.ProgramSource;
import net.coderbot.iris.shadows.ShadowRenderTargets;
import net.coderbot.iris.uniforms.CommonUniforms;
import net.coderbot.iris.uniforms.FrameUpdateNotifier;
import net.coderbot.iris.uniforms.custom.CustomUniforms;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.shader.Framebuffer;
@@ -48,6 +49,7 @@ public class CompositeRenderer {
private final IntSupplier noiseTexture;
private final FrameUpdateNotifier updateNotifier;
private final CenterDepthSampler centerDepthSampler;
private final CustomUniforms customUniforms;
private final Object2ObjectMap<String, IntSupplier> customTextureIds;
@Getter
private final ImmutableSet<Integer> flippedAtLeastOnceFinal;
@@ -56,12 +58,13 @@ public class CompositeRenderer {
IntSupplier noiseTexture, FrameUpdateNotifier updateNotifier,
CenterDepthSampler centerDepthSampler, BufferFlipper bufferFlipper,
Supplier<ShadowRenderTargets> shadowTargetsSupplier,
Object2ObjectMap<String, IntSupplier> customTextureIds, ImmutableMap<Integer, Boolean> explicitPreFlips) {
Object2ObjectMap<String, IntSupplier> customTextureIds, ImmutableMap<Integer, Boolean> explicitPreFlips, CustomUniforms customUniforms) {
this.noiseTexture = noiseTexture;
this.updateNotifier = updateNotifier;
this.centerDepthSampler = centerDepthSampler;
this.renderTargets = renderTargets;
this.customTextureIds = customTextureIds;
this.customUniforms = customUniforms;
final ImmutableList.Builder<Pass> passes = ImmutableList.builder();
final ImmutableSet.Builder<Integer> flippedAtLeastOnce = new ImmutableSet.Builder<>();
@@ -207,6 +210,8 @@ public class CompositeRenderer {
if (computeProgram != null) {
ranCompute = true;
final Framebuffer main = Minecraft.getMinecraft().getFramebuffer();
computeProgram.use();
this.customUniforms.push(computeProgram);
computeProgram.dispatch(main.framebufferWidth, main.framebufferHeight);
}
}
@@ -236,6 +241,8 @@ public class CompositeRenderer {
renderPass.framebuffer.bind();
renderPass.program.use();
this.customUniforms.push(renderPass.program);
FullScreenQuadRenderer.INSTANCE.renderQuad();
}
@@ -307,9 +314,11 @@ public class CompositeRenderer {
throw new RuntimeException("Shader compilation failed!", e);
}
CommonUniforms.addDynamicUniforms(builder);
this.customUniforms.assignTo(builder);
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureIds, flippedAtLeastOnceSnapshot);
CommonUniforms.addCommonUniforms(builder, source.getParent().getPack().getIdMap(), source.getParent().getPackDirectives(), updateNotifier);
IrisSamplers.addRenderTargetSamplers(customTextureSamplerInterceptor, () -> flipped, renderTargets, true);
IrisImages.addRenderTargetImages(builder, () -> flipped, renderTargets);
@@ -324,8 +333,12 @@ public class CompositeRenderer {
// TODO: Don't duplicate this with FinalPassRenderer
centerDepthSampler.setUsage(builder.addDynamicSampler(centerDepthSampler::getCenterDepthTexture, "iris_centerDepthSmooth"));
return builder.build();
}
Program build = builder.build();
this.customUniforms.mapholderToPass(builder, build);
return build;
}
private ComputeProgram[] createComputes(ComputeSource[] compute, ImmutableSet<Integer> flipped, ImmutableSet<Integer> flippedAtLeastOnceSnapshot, Supplier<ShadowRenderTargets> shadowTargetsSupplier) {
ComputeProgram[] programs = new ComputeProgram[compute.length];
@@ -347,7 +360,10 @@ public class CompositeRenderer {
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureIds, flippedAtLeastOnceSnapshot);
CommonUniforms.addCommonUniforms(builder, source.getParent().getPack().getIdMap(), source.getParent().getPackDirectives(), updateNotifier);
CommonUniforms.addDynamicUniforms(builder);
this.customUniforms.assignTo(builder);
IrisSamplers.addRenderTargetSamplers(customTextureSamplerInterceptor, () -> flipped, renderTargets, true);
IrisImages.addRenderTargetImages(builder, () -> flipped, renderTargets);
@@ -364,6 +380,8 @@ public class CompositeRenderer {
programs[i] = builder.buildCompute();
customUniforms.mapholderToPass(builder, programs[i]);
programs[i].setWorkGroupInfo(source.getWorkGroupRelative(), source.getWorkGroups());
}
}