-
Notifications
You must be signed in to change notification settings - Fork 822
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track render targets to avoid unnecessary composites
- Loading branch information
1 parent
278de5d
commit 8a26259
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
common/src/main/java/net/caffeinemc/mods/sodium/client/render/util/RenderTargetTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package net.caffeinemc.mods.sodium.client.render.util; | ||
|
||
import com.mojang.blaze3d.pipeline.RenderTarget; | ||
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; | ||
import it.unimi.dsi.fastutil.objects.ReferenceSet; | ||
|
||
public class RenderTargetTracker { | ||
private static final ReferenceSet<RenderTarget> DIRTY_FRAMEBUFFERS = new ReferenceOpenHashSet<>(); | ||
|
||
private static RenderTarget ACTIVE_WRITE_TARGET; | ||
|
||
public static void setActiveWriteTarget(RenderTarget rt) { | ||
ACTIVE_WRITE_TARGET = rt; | ||
} | ||
|
||
public static void notifyActiveWriteTargetModified() { | ||
RenderTarget rt = ACTIVE_WRITE_TARGET; | ||
|
||
if (rt != null) { | ||
markDirty(rt); | ||
} | ||
} | ||
|
||
public static void markDirty(RenderTarget rt) { | ||
DIRTY_FRAMEBUFFERS.add(rt); | ||
} | ||
|
||
public static boolean isDirty(RenderTarget rt) { | ||
return DIRTY_FRAMEBUFFERS.contains(rt); | ||
} | ||
|
||
public static void markClean(RenderTarget rt) { | ||
DIRTY_FRAMEBUFFERS.remove(rt); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...java/net/caffeinemc/mods/sodium/mixin/features/render/compositing/LevelRendererMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.caffeinemc.mods.sodium.mixin.features.render.compositing; | ||
|
||
import com.mojang.blaze3d.pipeline.RenderTarget; | ||
import net.caffeinemc.mods.sodium.client.render.util.RenderTargetTracker; | ||
import net.minecraft.client.renderer.LevelRenderer; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(LevelRenderer.class) | ||
public class LevelRendererMixin { | ||
@Shadow | ||
@Nullable | ||
private RenderTarget entityTarget; | ||
|
||
@Inject(method = "doEntityOutline", at = @At("HEAD"), cancellable = true) | ||
private void preEntityOutlineComposite(CallbackInfo ci) { | ||
RenderTarget entityTarget = this.entityTarget; | ||
|
||
// If the entity render target hasn't been modified, don't try to composite it into the final image | ||
if (entityTarget != null && !RenderTargetTracker.isDirty(entityTarget)) { | ||
ci.cancel(); | ||
} | ||
|
||
RenderTargetTracker.markClean(entityTarget); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
.../java/net/caffeinemc/mods/sodium/mixin/features/render/compositing/VertexBufferMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package net.caffeinemc.mods.sodium.mixin.features.render.compositing; | ||
|
||
import com.mojang.blaze3d.vertex.VertexBuffer; | ||
import net.caffeinemc.mods.sodium.client.render.util.RenderTargetTracker; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(VertexBuffer.class) | ||
public class VertexBufferMixin { | ||
@Inject(method = "draw", at = @At("RETURN")) | ||
private void postDraw(CallbackInfo ci) { | ||
// When any geometry is drawn, mark the framebuffer that it was rasterized to | ||
RenderTargetTracker.notifyActiveWriteTargetModified(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters