summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/maxwell/program.cpp
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-04-19 16:33:23 -0300
committerGravatar ameerj2021-07-22 21:51:28 -0400
commit7018e524f5e6217b3259333acc4ea09ad036d331 (patch)
tree58e750b08d48e018accc4de9a05cb483d825904c /src/shader_recompiler/frontend/maxwell/program.cpp
parentspirv: Fix ViewportMask (diff)
downloadyuzu-7018e524f5e6217b3259333acc4ea09ad036d331.tar.gz
yuzu-7018e524f5e6217b3259333acc4ea09ad036d331.tar.xz
yuzu-7018e524f5e6217b3259333acc4ea09ad036d331.zip
shader: Add NVN storage buffer fallbacks
When we can't track the SSBO origin of a global memory instruction, leave it as a global memory operation and assume these pointers are in the NVN storage buffer slots, then apply a linear search in the shader's runtime.
Diffstat (limited to 'src/shader_recompiler/frontend/maxwell/program.cpp')
-rw-r--r--src/shader_recompiler/frontend/maxwell/program.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/program.cpp b/src/shader_recompiler/frontend/maxwell/program.cpp
index 20a1d61cc..14180dcd9 100644
--- a/src/shader_recompiler/frontend/maxwell/program.cpp
+++ b/src/shader_recompiler/frontend/maxwell/program.cpp
@@ -60,6 +60,48 @@ void CollectInterpolationInfo(Environment& env, IR::Program& program) {
60 }(); 60 }();
61 } 61 }
62} 62}
63
64void AddNVNStorageBuffers(IR::Program& program) {
65 if (!program.info.uses_global_memory) {
66 return;
67 }
68 const u32 driver_cbuf{0};
69 const u32 descriptor_size{0x10};
70 const u32 num_buffers{16};
71 const u32 base{[&] {
72 switch (program.stage) {
73 case Stage::VertexA:
74 case Stage::VertexB:
75 return 0x110u;
76 case Stage::TessellationControl:
77 return 0x210u;
78 case Stage::TessellationEval:
79 return 0x310u;
80 case Stage::Geometry:
81 return 0x410u;
82 case Stage::Fragment:
83 return 0x510u;
84 case Stage::Compute:
85 return 0x310u;
86 }
87 throw InvalidArgument("Invalid stage {}", program.stage);
88 }()};
89 auto& descs{program.info.storage_buffers_descriptors};
90 for (u32 index = 0; index < num_buffers; ++index) {
91 const u32 offset{base + index * descriptor_size};
92 const auto it{std::ranges::find(descs, offset, &StorageBufferDescriptor::cbuf_offset)};
93 if (it != descs.end()) {
94 continue;
95 }
96 // Assume these are written for now
97 descs.push_back({
98 .cbuf_index = driver_cbuf,
99 .cbuf_offset = offset,
100 .count = 1,
101 .is_written = true,
102 });
103 }
104}
63} // Anonymous namespace 105} // Anonymous namespace
64 106
65IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool, 107IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool,
@@ -105,6 +147,7 @@ IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Blo
105 Optimization::VerificationPass(program); 147 Optimization::VerificationPass(program);
106 Optimization::CollectShaderInfoPass(env, program); 148 Optimization::CollectShaderInfoPass(env, program);
107 CollectInterpolationInfo(env, program); 149 CollectInterpolationInfo(env, program);
150 AddNVNStorageBuffers(program);
108 return program; 151 return program;
109} 152}
110 153