|
1 | 1 | package net.vulkanmod.mixin.compatibility; |
2 | 2 |
|
3 | | -import com.mojang.blaze3d.ProjectionType; |
4 | | -import com.mojang.blaze3d.buffers.GpuBuffer; |
5 | 3 | import com.mojang.blaze3d.buffers.GpuBufferSlice; |
6 | | -import com.mojang.blaze3d.buffers.Std140Builder; |
7 | | -import com.mojang.blaze3d.framegraph.FrameGraphBuilder; |
8 | | -import com.mojang.blaze3d.framegraph.FramePass; |
9 | | -import com.mojang.blaze3d.pipeline.RenderPipeline; |
10 | | -import com.mojang.blaze3d.pipeline.RenderTarget; |
11 | 4 | import com.mojang.blaze3d.resource.ResourceHandle; |
12 | | -import com.mojang.blaze3d.systems.CommandEncoder; |
13 | | -import com.mojang.blaze3d.systems.RenderPass; |
14 | | -import com.mojang.blaze3d.systems.RenderSystem; |
15 | | -import com.mojang.blaze3d.textures.GpuTextureView; |
16 | 5 | import com.mojang.blaze3d.vertex.*; |
17 | | -import com.mojang.datafixers.util.Pair; |
18 | | -import net.minecraft.client.renderer.MappableRingBuffer; |
19 | 6 | import net.minecraft.client.renderer.PostPass; |
20 | | -import net.minecraft.resources.ResourceLocation; |
21 | 7 | import net.vulkanmod.render.engine.*; |
22 | 8 | import net.vulkanmod.vulkan.Renderer; |
23 | 9 | import org.spongepowered.asm.mixin.Final; |
24 | 10 | import org.spongepowered.asm.mixin.Mixin; |
25 | | -import org.spongepowered.asm.mixin.Overwrite; |
26 | 11 | import org.spongepowered.asm.mixin.Shadow; |
| 12 | +import org.spongepowered.asm.mixin.injection.At; |
| 13 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 14 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
27 | 15 |
|
28 | 16 | import java.util.List; |
29 | 17 | import java.util.Map; |
30 | | -import java.util.OptionalDouble; |
31 | | -import java.util.OptionalInt; |
32 | 18 |
|
33 | 19 | @Mixin(PostPass.class) |
34 | 20 | public abstract class PostPassM { |
35 | | - @Shadow @Final private String name; |
36 | 21 | @Shadow @Final private List<PostPass.Input> inputs; |
37 | | - @Shadow @Final private ResourceLocation outputTargetId; |
38 | | - @Shadow @Final private RenderPipeline pipeline; |
39 | | - @Shadow @Final private MappableRingBuffer infoUbo; |
40 | | - @Shadow @Final private Map<String, GpuBuffer> customUniforms; |
41 | 22 |
|
42 | | - /** |
43 | | - * @author |
44 | | - * @reason |
45 | | - */ |
46 | | - @Overwrite |
47 | | - public void addToFrame(FrameGraphBuilder frameGraphBuilder, Map<ResourceLocation, ResourceHandle<RenderTarget>> map, GpuBufferSlice gpuBufferSlice) { |
48 | | - FramePass framePass = frameGraphBuilder.addPass(this.name); |
| 23 | + @Inject(method = "method_67884", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/GpuDevice;createCommandEncoder()Lcom/mojang/blaze3d/systems/CommandEncoder;")) |
| 24 | + private void transitionLayouts(ResourceHandle resourceHandle, GpuBufferSlice gpuBufferSlice, Map map, |
| 25 | + CallbackInfo ci) { |
| 26 | + Renderer.getInstance().endRenderPass(); |
49 | 27 |
|
50 | | - for (PostPass.Input input : this.inputs) { |
51 | | - input.addToPass(framePass, map); |
52 | | - } |
53 | | - |
54 | | - ResourceHandle<RenderTarget> resourceHandle = (ResourceHandle<RenderTarget>)map.computeIfPresent( |
55 | | - this.outputTargetId, (resourceLocation, resourceHandlex) -> framePass.readsAndWrites(resourceHandlex) |
56 | | - ); |
57 | | - if (resourceHandle == null) { |
58 | | - throw new IllegalStateException("Missing handle for target " + this.outputTargetId); |
59 | | - } else { |
60 | | - framePass.executes( |
61 | | - () -> { |
62 | | - RenderTarget renderTarget = resourceHandle.get(); |
63 | | - RenderSystem.backupProjectionMatrix(); |
64 | | - RenderSystem.setProjectionMatrix(gpuBufferSlice, ProjectionType.ORTHOGRAPHIC); |
65 | | - CommandEncoder commandEncoder = RenderSystem.getDevice().createCommandEncoder(); |
66 | | - List<Pair<String, GpuTextureView>> list = this.inputs.stream().map(inputxx -> Pair.of(inputxx.samplerName(), inputxx.texture(map))).toList(); |
67 | | - |
68 | | - try (GpuBuffer.MappedView mappedView = commandEncoder.mapBuffer(this.infoUbo.currentBuffer(), false, true)) { |
69 | | - Std140Builder std140Builder = Std140Builder.intoBuffer(mappedView.data()); |
70 | | - std140Builder.putVec2(renderTarget.width, renderTarget.height); |
71 | | - |
72 | | - for (Pair<String, GpuTextureView> pair : list) { |
73 | | - std140Builder.putVec2(pair.getSecond().getWidth(0), pair.getSecond().getHeight(0)); |
74 | | - } |
75 | | - } |
76 | | - |
77 | | - Renderer.getInstance().endRenderPass(); |
78 | | - |
79 | | - for (var input : this.inputs) { |
80 | | - VkGpuTexture gpuTexture = (VkGpuTexture) input.texture(map).texture(); |
81 | | - gpuTexture.getVulkanImage().readOnlyLayout(); |
82 | | - } |
83 | | - |
84 | | - try (RenderPass renderPass = commandEncoder.createRenderPass( |
85 | | - () -> "Post pass " + this.name, |
86 | | - renderTarget.getColorTextureView(), |
87 | | - OptionalInt.empty(), |
88 | | - renderTarget.useDepth ? renderTarget.getDepthTextureView() : null, |
89 | | - OptionalDouble.empty() |
90 | | - )) { |
91 | | - renderPass.setPipeline(this.pipeline); |
92 | | - RenderSystem.bindDefaultUniforms(renderPass); |
93 | | - renderPass.setUniform("SamplerInfo", this.infoUbo.currentBuffer()); |
94 | | - |
95 | | - for (Map.Entry<String, GpuBuffer> entry : this.customUniforms.entrySet()) { |
96 | | - renderPass.setUniform((String)entry.getKey(), (GpuBuffer)entry.getValue()); |
97 | | - } |
98 | | - |
99 | | - for (Pair<String, GpuTextureView> pair2 : list) { |
100 | | - renderPass.bindSampler(pair2.getFirst() + "Sampler", pair2.getSecond()); |
101 | | - } |
102 | | - |
103 | | - renderPass.draw(0, 3); |
104 | | - } |
| 28 | + for (var input : this.inputs) { |
| 29 | + VkGpuTexture gpuTexture = (VkGpuTexture) input.texture(map).texture(); |
105 | 30 |
|
106 | | - this.infoUbo.rotate(); |
107 | | - RenderSystem.restoreProjectionMatrix(); |
| 31 | + if (gpuTexture.needsClear()) { |
| 32 | + gpuTexture.getFbo(null).bind(); |
| 33 | + } |
108 | 34 |
|
109 | | - for (PostPass.Input inputx : this.inputs) { |
110 | | - inputx.cleanup(map); |
111 | | - } |
112 | | - } |
113 | | - ); |
| 35 | + gpuTexture.getVulkanImage().readOnlyLayout(); |
114 | 36 | } |
115 | 37 | } |
116 | 38 |
|
|
0 commit comments