Entity Shadow Replay (#2294)

This commit is contained in:
Eclipse-Sol authored and GitHub committed 2026-10-24 16:21:33 -07:00
1 parent 102c6cad86
commit 713509a87b
39 files changed
+3750 -157

No files matched your search

@@ -205,17 +205,13 @@ public class AngelicaBufferSource implements Groupable {
private void restoreIrisState() {
if (!irisStateSaved) return;
CapturedRenderingState.INSTANCE.popCurrentEntityColor();
CapturedRenderingState.INSTANCE.popCurrentBlockEntity();
CapturedRenderingState.INSTANCE.popCurrentEntityAndItem();
CapturedRenderingState.INSTANCE.popEntityState();
irisStateSaved = false;
}
private void saveIrisState() {
if (irisStateSaved) return;
CapturedRenderingState.INSTANCE.pushCurrentEntityAndItem();
CapturedRenderingState.INSTANCE.pushCurrentBlockEntity();
CapturedRenderingState.INSTANCE.pushCurrentEntityColor();
CapturedRenderingState.INSTANCE.pushEntityState();
irisStateSaved = true;
}
@@ -42,12 +42,17 @@ public final class Program extends GlResource {
}
public void use() {
RenderSystem.memoryBarrier(GL42.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL42.GL_TEXTURE_FETCH_BARRIER_BIT | GL43.GL_SHADER_STORAGE_BARRIER_BIT);
bindManaged(getGlId());
final boolean suspended = GLStateManager.suspendExitCapture();
try {
RenderSystem.memoryBarrier(GL42.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL42.GL_TEXTURE_FETCH_BARRIER_BIT | GL43.GL_SHADER_STORAGE_BARRIER_BIT);
bindManaged(getGlId());
uniforms.update();
samplers.update();
images.update();
uniforms.update();
samplers.update();
images.update();
} finally {
GLStateManager.resumeExitCapture(suspended);
}
}
static void bindManaged(int program) {
@@ -61,9 +66,14 @@ public final class Program extends GlResource {
}
public static void unbind() {
ProgramUniforms.clearActiveUniforms();
ProgramSamplers.clearActiveSamplers();
GLStateManager.glUseProgram(0);
final boolean suspended = GLStateManager.suspendExitCapture();
try {
ProgramUniforms.clearActiveUniforms();
ProgramSamplers.clearActiveSamplers();
GLStateManager.glUseProgram(0);
} finally {
GLStateManager.resumeExitCapture(suspended);
}
}
@Override
@@ -1,5 +1,6 @@
package net.coderbot.iris.layer;
import net.coderbot.iris.gbuffer_overrides.matching.RenderCondition;
import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition;
import net.coderbot.iris.pipeline.WorldRenderingPhase;
@@ -60,6 +61,11 @@ public final class PassOverride {
return phase == WorldRenderingPhase.ENTITIES;
}
public RenderCondition entityCondition(boolean defaultTranslucent) {
if (special != null || phase != null && phase != WorldRenderingPhase.ENTITIES) return null;
return (translucent != null ? translucent : defaultTranslucent) ? RenderCondition.ENTITIES_TRANSLUCENT : RenderCondition.ENTITIES;
}
public String nameSuffix() {
if (special == null && translucent == null && phase == null) {
return "";
@@ -1437,10 +1437,24 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
void rebindProgram() {
if (program != null) program.use();
DeferredWorldRenderingPipeline.this.customUniforms.push(this);
final boolean suspended = GLStateManager.suspendExitCapture();
try {
DeferredWorldRenderingPipeline.this.customUniforms.push(this);
} finally {
GLStateManager.resumeExitCapture(suspended);
}
}
private void useNow() {
final boolean suspended = GLStateManager.suspendExitCapture();
try {
applyState();
} finally {
GLStateManager.resumeExitCapture(suspended);
}
}
private void applyState() {
DepthColorStorage.unlockDepthColor();
if (isBeforeTranslucent) {
@@ -1485,14 +1499,19 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
}
public void stopUsing() {
DepthColorStorage.unlockDepthColor();
final boolean suspended = GLStateManager.suspendExitCapture();
try {
DepthColorStorage.unlockDepthColor();
if (alphaTestOverride != null) {
AlphaTestOverride.restore();
}
if (alphaTestOverride != null) {
AlphaTestOverride.restore();
}
if (blendModeOverride != null || (bufferBlendOverrides != null && !bufferBlendOverrides.isEmpty())) {
BlendModeOverride.restore();
if (blendModeOverride != null || (bufferBlendOverrides != null && !bufferBlendOverrides.isEmpty())) {
BlendModeOverride.restore();
}
} finally {
GLStateManager.resumeExitCapture(suspended);
}
}
@@ -1604,6 +1623,11 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
return current != null && current.instancedVariant(kind) != null;
}
public boolean hasInstancedVariant(RenderCondition condition, InputAvailability availability, Instancing kind) {
final Pass pass = table.match(condition, availability);
return pass != null && pass.instancedVariant(kind) != null;
}
@Override
public void bindInstancedVariant(Instancing kind) {
activeInstancing = kind;
@@ -2496,25 +2520,34 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
@Override
public void onBindTexture(int id) {
if (shouldBindPBR && isRenderingWorld) {
final PBRTextureHolder pbrHolder = PBRTextureManager.INSTANCE.getOrLoadHolder(id);
currentNormalTexture = pbrHolder.getNormalTexture().getGlTextureId();
currentSpecularTexture = pbrHolder.getSpecularTexture().getGlTextureId();
BatchStateGuard.suspend();
final boolean suspended = GLStateManager.suspendExitCapture();
try {
final TextureFormat textureFormat = TextureFormatLoader.getFormat();
if (textureFormat != null) {
textureFormat.setupTextureParameters(PBRType.NORMAL, pbrHolder.getNormalTexture());
textureFormat.setupTextureParameters(PBRType.SPECULAR, pbrHolder.getSpecularTexture());
}
PBRTextureManager.notifyPBRTexturesChanged();
updatePbrTextures(id);
} finally {
BatchStateGuard.resume();
GLStateManager.resumeExitCapture(suspended);
}
}
}
private void updatePbrTextures(int id) {
final PBRTextureHolder pbrHolder = PBRTextureManager.INSTANCE.getOrLoadHolder(id);
currentNormalTexture = pbrHolder.getNormalTexture().getGlTextureId();
currentSpecularTexture = pbrHolder.getSpecularTexture().getGlTextureId();
BatchStateGuard.suspend();
try {
final TextureFormat textureFormat = TextureFormatLoader.getFormat();
if (textureFormat != null) {
textureFormat.setupTextureParameters(PBRType.NORMAL, pbrHolder.getNormalTexture());
textureFormat.setupTextureParameters(PBRType.SPECULAR, pbrHolder.getSpecularTexture());
}
PBRTextureManager.notifyPBRTexturesChanged();
} finally {
BatchStateGuard.resume();
}
}
private static CompletableFuture<Map<PatchShaderType, String>> submitCompositeTransform(ProgramSource source, TextureStage stage,
Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
return Iris.ShaderTransformExecutor.submitTracked(() -> TransformPatcher.patchComposite(
@@ -9,6 +9,7 @@ import com.gtnewhorizons.angelica.glsm.GLDebug;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import com.gtnewhorizons.angelica.glsm.profiling.Tracy;
import com.gtnewhorizons.angelica.profiling.RenderClassTimings;
import com.gtnewhorizons.angelica.rendering.tesr.EntityShadowReplay;
import com.gtnewhorizons.angelica.rendering.tesr.ModelPartBatcher;
import com.gtnewhorizons.angelica.rendering.tesr.PendingTesrDraws;
import com.gtnewhorizons.angelica.rendering.tesr.SectionBuiltBlockEntity;
@@ -590,9 +591,12 @@ public class ShadowRenderer {
}
for (Entity entity : renderedEntitiesList) {
final long start = Tracy.ENABLED ? System.nanoTime() : 0L;
final boolean recording = AngelicaConfig.entityShadowReplayEnabled() && EntityShadowReplay.beginEntity(entity, tickDelta);
boolean completed = false;
try {
RenderManager.instance.renderEntitySimple(entity, tickDelta);
completed = RenderManager.instance.renderEntitySimple(entity, tickDelta);
} finally {
if (recording) EntityShadowReplay.endEntity(completed);
if (Tracy.ENABLED) RenderClassTimings.SHADOW_ENTITY.add(entity.getClass(), System.nanoTime() - start);
}
}
@@ -161,6 +161,18 @@ public class CapturedRenderingState {
applyCurrentEntityColor(r, g, b, a);
}
public void pushEntityState() {
pushCurrentEntityAndItem();
pushCurrentBlockEntity();
pushCurrentEntityColor();
}
public void popEntityState() {
popCurrentEntityColor();
popCurrentBlockEntity();
popCurrentEntityAndItem();
}
private void applyCurrentEntityColor(float r, float g, float b, float a) {
if (currentEntityColor.equals(r, g, b, a)) return;
this.currentEntityColor.set(r, g, b, a);