package defpackage; import com.mojang.blaze3d.GpuFormat; import com.mojang.blaze3d.buffers.GpuBuffer; import com.mojang.blaze3d.buffers.GpuBufferSlice.MappedView; import com.mojang.blaze3d.pipeline.BindGroupLayout; import com.mojang.blaze3d.pipeline.ColorTargetState; import com.mojang.blaze3d.pipeline.RenderPipeline; import com.mojang.blaze3d.pipeline.RenderTarget; import com.mojang.blaze3d.pipeline.RenderPipeline.Snippet; import com.mojang.blaze3d.shaders.UniformType; import com.mojang.blaze3d.systems.CommandEncoder; import com.mojang.blaze3d.systems.GpuDevice; import com.mojang.blaze3d.systems.RenderPass; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.textures.FilterMode; import com.mojang.blaze3d.textures.GpuSampler; import com.mojang.blaze3d.textures.GpuTexture; import com.mojang.blaze3d.textures.GpuTextureView; import java.nio.ByteBuffer; import java.util.ArrayDeque; import java.util.Optional; import java.util.function.Supplier; import net.minecraft.client.renderer.RenderPipelines; import net.minecraft.resources.Identifier; import org.lwjgl.system.MemoryStack; public final class aqv { private static final String NAMESPACE = "evolution"; private static final String UNIFORM_BLOCK = "ReplayParams"; private static final String SAMPLER_SOURCE = "SourceTex"; private static final Identifier VERTEX_SHADER = id("core/replay/fullscreen"); private static final Identifier FRAGMENT_SHADER = id( "core/replay/downscale" ); private static final String PIPELINE_FAILURE = "gpu frame capture pipeline setup failed for {}"; private static final String FRAME_FAILURE = "gpu frame capture frame failed for {}"; private static final String READBACK_FAILURE = "gpu frame capture readback failed for {}"; private static final GpuFormat TARGET_FORMAT = GpuFormat.RGBA8_UNORM; private static final int TARGET_USAGE = 14; private static final int UNIFORM_USAGE = 136; private static final int READBACK_USAGE = 9; private static final int UNIFORM_SIZE = 16; private static final int FLOAT_SIZE = 4; private static final int TEXTURE_DEPTH = 1; private static final int TEXTURE_MIP_LEVELS = 1; private static final int COPY_MIP_LEVEL = 0; private static final long COPY_OFFSET = 0L; private static final int BYTES_PER_PIXEL = 4; private static final int FULLSCREEN_VERTEX_COUNT = 3; private static final int INSTANCE_COUNT = 1; private static final int FIRST_VERTEX = 0; private static final int FIRST_INSTANCE = 0; private static final int MIN_DIMENSION = 16; private static final int EVEN_MASK = -2; private final String name; private final Identifier pipelineId; private final int maxInFlight; private final Supplier uniformLabel; private final Supplier targetLabel; private final Supplier readbackLabel; private final Supplier passLabel; private final ArrayDeque readbackPool = new ArrayDeque<>(); private RenderPipeline pipeline; private GpuBuffer uniformBuffer; private GpuTexture target; private GpuTextureView targetView; private int targetWidth = -1; private int targetHeight = -1; private int inFlight; private int createdBuffers; private long droppedFrames; private boolean disabledAfterError; public aqv(String var1, int var2) { this.name = var1; this.pipelineId = id("pipeline/capture/" + var1); this.maxInFlight = var2; this.uniformLabel = () -> "evolution_" + var1 + "_uniforms"; this.targetLabel = () -> "evolution_" + var1 + "_target"; this.readbackLabel = () -> "evolution_" + var1 + "_readback"; this.passLabel = () -> "evolution_" + var1 + "_downscale"; } public boolean capture(int var1, aqu var2) { RenderTarget var3 = null; int var4 = 0; int var5 = 0; int var6 = -515696636; while (true) { switch (var6) { case -1012398125: return (boolean)(((0)) != 0); case -515696636: default: if (this.disabledAfterError) { var6 = -1012398125; } else { var6 = 139358093; } break; case 139358093: var3 = aqg.mc.gameRenderer.mainRenderTarget(); if (var3 != null) { var6 = 594708333; } else { var6 = 1784395732; } break; case 594708333: if (var3.width > 0) { var6 = 948406879; } else { var6 = 1784395732; } break; case 948406879: if (var3.height > 0) { var6 = 1356677735; } else { var6 = 1784395732; } break; case 1356677735: if (var3.getColorTextureView() == null) { var6 = 1784395732; } else { var6 = 1511473041; } break; case 1511473041: var4 = Math.max(16, Math.min(var1, var3.height)) & -2; var5 = Math.max(16, Math.round(var4 * ((float)var3.width / var3.height))) & -2; return this.captureExact(var5, var4, var2); case 1784395732: return (boolean)(((0)) != 0); } } } public boolean captureExact(int var1, int var2, aqu var3) { if (this.disabledAfterError) { return (boolean)(((0)) != 0); } RenderTarget var4 = aqg.mc.gameRenderer.mainRenderTarget(); if (var4 != null && var4.width > 0 && var4.height > 0 && var4.getColorTextureView() != null) { int var5 = Math.max(16, var1) & -2; int var6 = Math.max(16, var2) & -2; if (!this.ensurePipeline() || !this.ensureTarget(var5, var6)) { return (boolean)(((0)) != 0); } if (this.inFlight >= this.maxInFlight) { this.droppedFrames += (2161285247113744878L ^ -2161285247113744877L) + ((2161285247113744878L & -2161285247113744877L) << 1); return (boolean)(((0)) != 0); } try { CommandEncoder var7 = RenderSystem.getDevice().createCommandEncoder(); this.writeUniforms(var7, var5, var6); this.downscale(var7, var4); this.readback(var7, var5, var6, var3); return (boolean)(((1)) != 0); } catch (Throwable var8) { this.fail( "gpu frame capture frame failed for {}", var8 ); return (boolean)(((0)) != 0); } } else { return (boolean)(((0)) != 0); } } public long droppedFrames() { return this.droppedFrames; } public void release() { int var1 = 167025644; while (true) { switch (var1) { case -487694581: return; case 167025644: default: if (!RenderSystem.isOnRenderThread()) { var1 = -487694581; } else { var1 = 670939751; } break; case 670939751: this.closeTarget(); this.closeUniformBuffer(); this.closePool(); return; } } } private void downscale(CommandEncoder var1, RenderTarget var2) { RenderPass var3 = var1.createRenderPass(this.passLabel, this.targetView, Optional.empty()); try { var3.setPipeline(this.pipeline); RenderSystem.bindDefaultUniforms(var3); var3.setUniform("ReplayParams", this.uniformBuffer); var3.bindTexture("SourceTex", var2.getColorTextureView(), linearSampler()); var3.draw( 3, 1, 0, (-853632027 ^ 853632027) + ((-853632027 & 853632027) << 1) ); } catch (Throwable var7) { if (var3 != null) { try { var3.close(); } catch (Throwable var6) { var7.addSuppressed(var6); } } throw var7; } if (var3 != null) { var3.close(); } } private void readback(CommandEncoder var1, int var2, int var3, aqu var4) { int var5 = 0; GpuBuffer var6 = null; long var7 = (5605029022798628228L | -5605029022798628228L) + (5605029022798628228L & -5605029022798628228L); int var9 = -1144791233; while (true) { switch (var9) { case -1144791233: default: var5 = var2 * var3 * (4); var6 = this.borrowBuffer(var5); if (var6 == null) { var9 = 1067031598; } else { var9 = 1246513384; } break; case 1067031598: this.droppedFrames += (-923868757337586887L ^ 923868757337586888L) + ((-923868757337586887L & 923868757337586888L) << 1); return; case 1246513384: var7 = System.currentTimeMillis(); final GpuBuffer var6f = var6; final long var7f = var7; this.inFlight += 1; var1.copyTextureToBuffer( this.target, var6, (1290606854966732354L ^ -1290606854966732354L) + ((1290606854966732354L & -1290606854966732354L) << 1), () -> this.complete(var6f, var2, var3, var7f, var4), (341102333 | -341102333) + (341102333 & -341102333) ); return; } } } private void complete(GpuBuffer var1, int var2, int var3, long var4, aqu var6) { this.inFlight -= 1; byte[] var7 = null; try { MappedView var8 = var1.map( (boolean)((((1)) != 0)), (boolean)((((-156236915 ^ 156236915) + ((-156236915 & 156236915) << 1)) ) != 0)); try { ByteBuffer var9 = var8.data(); int var10 = var2 * (4); var7 = var6.borrow(var10 * var3); for (int var11 = 0; var11 < var3; var11++) { var9.get((var3 - ((233646291 ^ -233646290) + ((233646291 & -233646290) << 1)) - var11) * var10, var7, var11 * var10, var10); } } catch (Throwable var18) { if (var8 != null) { try { var8.close(); } catch (Throwable var17) { var18.addSuppressed(var17); } } throw var18; } if (var8 != null) { var8.close(); } } catch (Throwable var19) { id.error( Cif.SHADER, "gpu frame capture readback failed for {}", this.name, var19 ); } finally { this.recycleBuffer(var1); } if (var7 != null && !var6.accept(var7, var2, var3, var4)) { var6.discard(var7); } } private GpuBuffer borrowBuffer(int var1) { while (!this.readbackPool.isEmpty()) { GpuBuffer var2 = this.readbackPool.pollLast(); if (!var2.isClosed() && var2.size() == var1) { return var2; } this.closeBuffer(var2); } if (this.createdBuffers >= this.maxInFlight) { return null; } GpuDevice var3 = RenderSystem.tryGetDevice(); if (var3 == null) { return null; } this.createdBuffers += 1; return var3.createBuffer(this.readbackLabel, 9, var1); } private void recycleBuffer(GpuBuffer var1) { int var2 = 0; int var3 = 1137620298; while (true) { switch (var3) { case -1995301694: this.closeBuffer(var1); return; case 201756846: if (var1.size() == var2) { var3 = 1221275881; } else { var3 = -1995301694; } break; case 296115163: this.readbackPool.addLast(var1); return; case 1137620298: default: var2 = this.targetWidth * this.targetHeight * (4); if (!var1.isClosed()) { var3 = 201756846; } else { var3 = -1995301694; } break; case 1221275881: if (this.readbackPool.size() >= this.maxInFlight) { var3 = -1995301694; } else { var3 = 296115163; } } } } private void closeBuffer(GpuBuffer var1) { int var2 = 138270930; while (true) { switch (var2) { case -2113729213: var1.close(); var2 = 523987786; break; case 138270930: default: if (!var1.isClosed()) { var2 = -2113729213; } else { var2 = 523987786; } break; case 523987786: this.createdBuffers = Math.max( 0, this.createdBuffers - ((1417898842 | -1417898841) + (1417898842 & -1417898841)) ); return; } } } private void writeUniforms(CommandEncoder var1, int var2, int var3) { MemoryStack var4 = MemoryStack.stackPush(); try { ByteBuffer var5 = var4.calloc((-1711559781 | 1711559797) + (-1711559781 & 1711559797)); var5.putFloat(0, 1.0F / var2); var5.putFloat(4, 1.0F / var3); var5.position((-2029631338 | 2029631338) + (-2029631338 & 2029631338)); var1.writeToBuffer( this.uniformBuffer .slice( (-4074848553053219808L | 4074848553053219808L) + (-4074848553053219808L & 4074848553053219808L), (5391606672053444432L | -5391606672053444416L) + (5391606672053444432L & -5391606672053444416L) ), var5 ); } catch (Throwable var8) { if (var4 != null) { try { var4.close(); } catch (Throwable var7) { var8.addSuppressed(var7); } } throw var8; } if (var4 != null) { var4.close(); } } private boolean ensurePipeline() { try { if (this.pipeline == null) { Snippet[] var10001 = new Snippet[1]; var10001[0] = RenderPipelines.POST_PROCESSING_SNIPPET; this.pipeline = RenderPipeline.builder(var10001) .withLocation(this.pipelineId) .withVertexShader(VERTEX_SHADER) .withFragmentShader(FRAGMENT_SHADER) .withBindGroupLayout( BindGroupLayout.builder() .withUniform("ReplayParams", UniformType.UNIFORM_BUFFER) .withSampler("SourceTex") .build() ) .withColorTargetState(new ColorTargetState(Optional.empty(), TARGET_FORMAT, (991859025 | -991859010) + (991859025 & -991859010))) .withDepthStencilState(Optional.empty()) .withCull((boolean)((((-1307306347 ^ 1307306347) + ((-1307306347 & 1307306347) << 1))) != 0)) .build(); } GpuDevice var1 = RenderSystem.getDevice(); if (this.uniformBuffer == null || this.uniformBuffer.isClosed()) { this.uniformBuffer = var1.createBuffer( this.uniformLabel, 136, (2248223070295359339L | -2248223070295359323L) + (2248223070295359339L & -2248223070295359323L) ); } return (boolean)(((1)) != 0); } catch (Throwable var2) { this.fail( "gpu frame capture pipeline setup failed for {}", var2 ); return (boolean)(((0)) != 0); } } private boolean ensureTarget(int var1, int var2) { GpuDevice var3 = null; int var4 = -474795863; while (true) { switch (var4) { case -1463889329: if (this.inFlight > 0) { var4 = 797078443; } else { var4 = 1974102740; } break; case -931899969: return (boolean)(((0)) != 0); case -474795863: default: if (this.target != null) { var4 = 251510572; } else { var4 = -1463889329; } break; case -374807303: return (boolean)(((1)) != 0); case 251510572: if (this.targetWidth == var1) { var4 = 269624016; } else { var4 = -1463889329; } break; case 269624016: if (this.targetHeight == var2) { var4 = -374807303; } else { var4 = -1463889329; } break; case 797078443: return (boolean)(((0)) != 0); case 1550908306: this.closeTarget(); this.closePool(); this.target = var3.createTexture( this.targetLabel, 14, TARGET_FORMAT, var1, var2, 1, (-1300786169 ^ 1300786170) + ((-1300786169 & 1300786170) << 1) ); this.targetView = var3.createTextureView(this.target); this.targetWidth = var1; this.targetHeight = var2; return (boolean)(((1)) != 0); case 1974102740: var3 = RenderSystem.tryGetDevice(); if (var3 == null) { var4 = -931899969; } else { var4 = 1550908306; } } } } private void closeTarget() { int var1 = 901914968; while (true) { switch (var1) { case -1596688916: if (this.target != null) { var1 = 1420571763; } else { var1 = 511968408; } break; case -154444244: this.targetView.close(); this.targetView = null; var1 = -1596688916; break; case 511968408: this.targetWidth = -1; this.targetHeight = -1; return; case 901914968: default: if (this.targetView != null) { var1 = -154444244; } else { var1 = -1596688916; } break; case 1420571763: this.target.close(); this.target = null; var1 = 511968408; } } } private void closeUniformBuffer() { int var1 = 1902538830; while (true) { switch (var1) { case 637918980: return; case 712555609: this.uniformBuffer.close(); this.uniformBuffer = null; var1 = 637918980; break; case 1902538830: default: if (this.uniformBuffer != null) { var1 = 712555609; } else { var1 = 637918980; } } } } private void closePool() { int var1 = 1186761462; while (true) { switch (var1) { case -1722672181: return; case -727796916: this.closeBuffer(this.readbackPool.pollLast()); var1 = 1186761462; break; case 1186761462: default: if (!this.readbackPool.isEmpty()) { var1 = -727796916; } else { var1 = -1722672181; } } } } private void fail(String var1, Throwable var2) { this.disabledAfterError = (boolean)(((1)) != 0); id.error(Cif.SHADER, var1, this.name, var2); this.closeTarget(); this.closeUniformBuffer(); this.closePool(); this.pipeline = null; } private static GpuSampler linearSampler() { return RenderSystem.getSamplerCache().getClampToEdge(FilterMode.LINEAR); } private static Identifier id(String var0) { return Identifier.fromNamespaceAndPath("evolution", var0); } }