summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar FernandoS272021-04-03 02:34:07 +0200
committerGravatar ameerj2021-07-22 21:51:26 -0400
commited6a1b1a3def4b8ed8c8fd1a7774a0a14edefc70 (patch)
treec7ec469906ac5a8d2788316203b3c507286b940c
parentshader: "Implement" NOP (diff)
downloadyuzu-ed6a1b1a3def4b8ed8c8fd1a7774a0a14edefc70.tar.gz
yuzu-ed6a1b1a3def4b8ed8c8fd1a7774a0a14edefc70.tar.xz
yuzu-ed6a1b1a3def4b8ed8c8fd1a7774a0a14edefc70.zip
shader: Address feedback
-rw-r--r--src/shader_recompiler/frontend/ir/modifiers.h8
-rw-r--r--src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp20
-rw-r--r--src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp1
3 files changed, 16 insertions, 13 deletions
diff --git a/src/shader_recompiler/frontend/ir/modifiers.h b/src/shader_recompiler/frontend/ir/modifiers.h
index 2aa4ac79b..461671326 100644
--- a/src/shader_recompiler/frontend/ir/modifiers.h
+++ b/src/shader_recompiler/frontend/ir/modifiers.h
@@ -25,7 +25,13 @@ enum class FpRounding : u8 {
25 RZ, // Round towards zero 25 RZ, // Round towards zero
26}; 26};
27 27
28enum class MemoryScope : u32 { DontCare, Warp, Workgroup, Device, System }; 28enum class MemoryScope : u32 {
29 DontCare,
30 Warp,
31 Workgroup,
32 Device,
33 System,
34};
29 35
30struct FpControl { 36struct FpControl {
31 bool no_contraction{false}; 37 bool no_contraction{false};
diff --git a/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp b/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp
index 8876a5c33..c8bd7b329 100644
--- a/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp
+++ b/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp
@@ -46,7 +46,9 @@ using StorageBufferSet =
46using StorageInstVector = boost::container::small_vector<StorageInst, 24>; 46using StorageInstVector = boost::container::small_vector<StorageInst, 24>;
47using VisitedBlocks = boost::container::flat_set<IR::Block*, std::less<IR::Block*>, 47using VisitedBlocks = boost::container::flat_set<IR::Block*, std::less<IR::Block*>,
48 boost::container::small_vector<IR::Block*, 4>>; 48 boost::container::small_vector<IR::Block*, 4>>;
49using StorageWritesMap = std::map<StorageBufferAddr, bool>; 49using StorageWritesSet =
50 boost::container::flat_set<StorageBufferAddr, std::less<StorageBufferAddr>,
51 boost::container::small_vector<StorageBufferAddr, 16>>;
50 52
51/// Returns true when the instruction is a global memory instruction 53/// Returns true when the instruction is a global memory instruction
52bool IsGlobalMemory(const IR::Inst& inst) { 54bool IsGlobalMemory(const IR::Inst& inst) {
@@ -266,7 +268,7 @@ std::optional<StorageBufferAddr> Track(IR::Block* block, const IR::Value& value,
266 268
267/// Collects the storage buffer used by a global memory instruction and the instruction itself 269/// Collects the storage buffer used by a global memory instruction and the instruction itself
268void CollectStorageBuffers(IR::Block& block, IR::Inst& inst, StorageBufferSet& storage_buffer_set, 270void CollectStorageBuffers(IR::Block& block, IR::Inst& inst, StorageBufferSet& storage_buffer_set,
269 StorageInstVector& to_replace, StorageWritesMap& writes_map) { 271 StorageInstVector& to_replace, StorageWritesSet& writes_set) {
270 // NVN puts storage buffers in a specific range, we have to bias towards these addresses to 272 // NVN puts storage buffers in a specific range, we have to bias towards these addresses to
271 // avoid getting false positives 273 // avoid getting false positives
272 static constexpr Bias nvn_bias{ 274 static constexpr Bias nvn_bias{
@@ -295,12 +297,8 @@ void CollectStorageBuffers(IR::Block& block, IR::Inst& inst, StorageBufferSet& s
295 } 297 }
296 } 298 }
297 // Collect storage buffer and the instruction 299 // Collect storage buffer and the instruction
298 const bool is_a_write{IsGlobalMemoryWrite(inst)}; 300 if (IsGlobalMemoryWrite(inst)) {
299 auto it{writes_map.find(*storage_buffer)}; 301 writes_set.insert(*storage_buffer);
300 if (it == writes_map.end()) {
301 writes_map[*storage_buffer] = is_a_write;
302 } else {
303 it->second = it->second || is_a_write;
304 } 302 }
305 storage_buffer_set.insert(*storage_buffer); 303 storage_buffer_set.insert(*storage_buffer);
306 to_replace.push_back(StorageInst{ 304 to_replace.push_back(StorageInst{
@@ -375,14 +373,14 @@ void Replace(IR::Block& block, IR::Inst& inst, const IR::U32& storage_index,
375void GlobalMemoryToStorageBufferPass(IR::Program& program) { 373void GlobalMemoryToStorageBufferPass(IR::Program& program) {
376 StorageBufferSet storage_buffers; 374 StorageBufferSet storage_buffers;
377 StorageInstVector to_replace; 375 StorageInstVector to_replace;
378 StorageWritesMap writes_map; 376 StorageWritesSet writes_set;
379 377
380 for (IR::Block* const block : program.post_order_blocks) { 378 for (IR::Block* const block : program.post_order_blocks) {
381 for (IR::Inst& inst : block->Instructions()) { 379 for (IR::Inst& inst : block->Instructions()) {
382 if (!IsGlobalMemory(inst)) { 380 if (!IsGlobalMemory(inst)) {
383 continue; 381 continue;
384 } 382 }
385 CollectStorageBuffers(*block, inst, storage_buffers, to_replace, writes_map); 383 CollectStorageBuffers(*block, inst, storage_buffers, to_replace, writes_set);
386 } 384 }
387 } 385 }
388 Info& info{program.info}; 386 Info& info{program.info};
@@ -392,7 +390,7 @@ void GlobalMemoryToStorageBufferPass(IR::Program& program) {
392 .cbuf_index{storage_buffer.index}, 390 .cbuf_index{storage_buffer.index},
393 .cbuf_offset{storage_buffer.offset}, 391 .cbuf_offset{storage_buffer.offset},
394 .count{1}, 392 .count{1},
395 .is_written{writes_map[storage_buffer]}, 393 .is_written{writes_set.contains(storage_buffer)},
396 }); 394 });
397 ++storage_index; 395 ++storage_index;
398 } 396 }
diff --git a/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp b/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
index 72d4abb77..259233746 100644
--- a/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
+++ b/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
@@ -275,7 +275,6 @@ void VisitInst(Pass& pass, IR::Block* block, IR::Inst& inst) {
275 case IR::Opcode::GetOFlag: 275 case IR::Opcode::GetOFlag:
276 inst.ReplaceUsesWith(pass.ReadVariable(OverflowFlagTag{}, block)); 276 inst.ReplaceUsesWith(pass.ReadVariable(OverflowFlagTag{}, block));
277 break; 277 break;
278 break;
279 default: 278 default:
280 break; 279 break;
281 } 280 }