Compare commits

...
Author SHA1 Message Date
Jason Mitchell 34b6efde7b Maybe fix TAA (#1047) 2025-10-12 17:40:41 -07:00
6 changed files with 49 additions and 20 deletions

No files matched your search

@@ -1252,7 +1252,7 @@ public class GLStateManager {
i = mipmap ? GL11.GL_LINEAR_MIPMAP_LINEAR : GL11.GL_LINEAR;
j = GL11.GL_LINEAR;
} else {
i = mipmap ? GL11.GL_NEAREST_MIPMAP_LINEAR : GL11.GL_NEAREST;
i = mipmap ? GL11.GL_LINEAR_MIPMAP_LINEAR : GL11.GL_NEAREST;
j = GL11.GL_NEAREST;
}
glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, i);
@@ -12,7 +12,7 @@ public class TextureInfo {
protected int width = -1;
protected int height = -1;
@Getter @Setter protected int minFilter = GL11.GL_NEAREST_MIPMAP_LINEAR;
@Getter @Setter protected int minFilter = GL11.GL_LINEAR_MIPMAP_LINEAR;
@Getter @Setter protected int magFilter = GL11.GL_LINEAR;
@Getter @Setter protected int wrapS = GL11.GL_REPEAT;
@Getter @Setter protected int wrapT = GL11.GL_REPEAT;
@@ -74,7 +74,7 @@ public class MipmapHelper {
int mipmaps = useMipmapsForTexture(textureName) ? getMipmapLevels(width, height, 1) : 0;
logger.finer("setupTexture(%s) %dx%d %d mipmaps", textureName, width, height, mipmaps);
int magFilter = blur ? GL11.GL_LINEAR : GL11.GL_NEAREST;
int minFilter = mipmaps > 0 ? GL11.GL_NEAREST_MIPMAP_LINEAR : magFilter;
int minFilter = mipmaps > 0 ? GL11.GL_LINEAR_MIPMAP_LINEAR : magFilter;
int wrap = clamp ? GL11.GL_CLAMP : GL11.GL_REPEAT;
if (mipmaps > 0) {
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, mipmaps);
@@ -222,6 +222,10 @@ public class ShaderTransformer {
for (var entry : types.entrySet()) {
String formattedShader = getFormattedShader(entry.getValue(), prepatched.get(entry.getKey()));
// Restore identifiers that were temporarily renamed to dodge GLSL reserved keywords.
formattedShader = formattedShader.replace("iris_renamed_texture", "texture");
formattedShader = formattedShader.replace("iris_renamed_sample", "sample");
// Please don't mind the entire rest of this loop basically, we're doing awful fragile regex on the transformed
// shader output to do things that I can't figure out with AST because I'm bad at it
@@ -13,6 +13,13 @@ public class BufferFlipper {
}
public void flip(int target) {
// colortex6 carries material/mask data that the gbuffer populates every frame.
// If we allow it to flip, the alternate texture remains empty and later copy-back
// wipes the fresh mask, breaking TAA mask lookups (notably on foliage/transparents).
if (target == 6) {
return;
}
if (!flippedBuffers.remove(target)) {
// If the target wasn't in the set, add it to the set.
flippedBuffers.add(target);
@@ -49,6 +49,7 @@ public class FinalPassRenderer {
@Nullable
private final Pass finalPass;
private final ImmutableList<SwapPass> swapPasses;
private final ImmutableSet<Integer> flippedBuffers;
private final GlFramebuffer baseline;
private final GlFramebuffer colorHolder;
private int lastColorTextureId;
@@ -72,6 +73,7 @@ public class FinalPassRenderer {
this.noiseTexture = noiseTexture;
this.renderTargets = renderTargets;
this.flippedBuffers = flippedBuffers;
this.customUniforms = customUniforms;
this.finalPass = pack.getCompositeFinal().map(source -> {
Pass pass = new Pass();
@@ -101,23 +103,37 @@ public class FinalPassRenderer {
// TODO: We don't actually fully swap the content, we merely copy it from alt to main
// This works for the most part, but it's not perfect. A better approach would be creating secondary
// framebuffers for every other frame, but that would be a lot more complex...
ImmutableList.Builder<SwapPass> swapPasses = ImmutableList.builder();
final ImmutableList.Builder<SwapPass> swapPasses = ImmutableList.builder();
flippedBuffers.forEach(i -> {
int target = i;
// BUG FIX: Swap passes are only needed for NON-flipped buffers that might flip in the future.
// Flipped buffers use ping-pong mechanism - no swap needed.
// Original code created swaps for ALL flippedAtLeastOnce buffers and copied ALT→MAIN,
// which destroyed fresh data in MAIN for currently-flipped buffers (breaking TAA).
// Fixed: Only create swaps for buffers that are in flippedAtLeastOnce but NOT currently flipped.
flippedAtLeastOnce.forEach(i -> {
final int target = i;
// Skip buffer 6 (material mask) - gbuffers always write to MAIN, never flipped
if (target == 6) {
return;
}
// Skip buffers that are currently flipped - they use ping-pong, no swap needed
if (flippedBuffers.contains(target)) {
return;
}
if (buffersToBeCleared.contains(target)) {
return;
}
SwapPass swap = new SwapPass();
RenderTarget target1 = renderTargets.get(target);
final SwapPass swap = new SwapPass();
final RenderTarget target1 = renderTargets.get(target);
swap.target = target;
swap.width = target1.getWidth();
swap.height = target1.getHeight();
// Non-flipped buffers write to ALT, copy ALT→MAIN to preserve data
swap.from = renderTargets.createColorFramebuffer(ImmutableSet.of(), new int[] {target});
// NB: This is handled in RenderTargets now.
//swap.from.readBuffer(target);
swap.targetTexture = renderTargets.get(target).getMainTexture();
swapPasses.add(swap);
@@ -264,8 +280,10 @@ public class FinalPassRenderer {
public void recalculateSwapPassSize() {
for (SwapPass swapPass : swapPasses) {
RenderTarget target = renderTargets.get(swapPass.target);
final RenderTarget target = renderTargets.get(swapPass.target);
renderTargets.destroyFramebuffer(swapPass.from);
// Match constructor logic - swap passes are only for non-flipped buffers
// Copy ALT→MAIN to preserve data written to ALT
swapPass.from = renderTargets.createColorFramebuffer(ImmutableSet.of(), new int[] {swapPass.target});
swapPass.width = target.getWidth();
swapPass.height = target.getHeight();
@@ -274,7 +292,7 @@ public class FinalPassRenderer {
}
private static void setupMipmapping(RenderTarget target, boolean readFromAlt) {
int texture = readFromAlt ? target.getAltTexture() : target.getMainTexture();
final int texture = readFromAlt ? target.getAltTexture() : target.getMainTexture();
// TODO: Only generate the mipmap if a valid mipmap hasn't been generated or if we've written to the buffer
// (since the last mipmap was generated)
@@ -319,13 +337,13 @@ public class FinalPassRenderer {
source.getVertexSource().orElseThrow(NullPointerException::new),
source.getGeometrySource().orElse(null),
source.getFragmentSource().orElseThrow(NullPointerException::new));
String vertex = transformed.get(PatchShaderType.VERTEX);
String geometry = transformed.get(PatchShaderType.GEOMETRY);
String fragment = transformed.get(PatchShaderType.FRAGMENT);
final String vertex = transformed.get(PatchShaderType.VERTEX);
final String geometry = transformed.get(PatchShaderType.GEOMETRY);
final String fragment = transformed.get(PatchShaderType.FRAGMENT);
PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, fragment);
Objects.requireNonNull(flipped);
ProgramBuilder builder;
final ProgramBuilder builder;
try {
builder = ProgramBuilder.begin(source.getName(), vertex, geometry, fragment,
@@ -337,7 +355,7 @@ public class FinalPassRenderer {
this.customUniforms.assignTo(builder);
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureIds, flippedAtLeastOnceSnapshot);
final ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureIds, flippedAtLeastOnceSnapshot);
CommonUniforms.addDynamicUniforms(builder);
IrisSamplers.addRenderTargetSamplers(customTextureSamplerInterceptor, () -> flipped, renderTargets, true);
@@ -361,15 +379,15 @@ public class FinalPassRenderer {
}
private ComputeProgram[] createComputes(ComputeSource[] compute, ImmutableSet<Integer> flipped, ImmutableSet<Integer> flippedAtLeastOnceSnapshot, Supplier<ShadowRenderTargets> shadowTargetsSupplier) {
ComputeProgram[] programs = new ComputeProgram[compute.length];
final ComputeProgram[] programs = new ComputeProgram[compute.length];
for (int i = 0; i < programs.length; i++) {
ComputeSource source = compute[i];
final ComputeSource source = compute[i];
if (source == null || !source.getSource().isPresent()) {
continue;
} else {
// TODO: Properly handle empty shaders
Objects.requireNonNull(flipped);
ProgramBuilder builder;
final ProgramBuilder builder;
try {
builder = ProgramBuilder.beginCompute(source.getName(), source.getSource().orElse(null), IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS);