summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2019-06-25 20:40:38 -0400
committerGravatar FernandoS272019-07-09 08:14:40 -0400
commitd45fed303055fa699377bedcc3a7973bd03b7870 (patch)
tree1a21fe83b7ad852021f886cb2494ad5467ad5c66 /src
parentshader_ir: Corrections, documenting and asserting control_flow (diff)
downloadyuzu-d45fed303055fa699377bedcc3a7973bd03b7870.tar.gz
yuzu-d45fed303055fa699377bedcc3a7973bd03b7870.tar.xz
yuzu-d45fed303055fa699377bedcc3a7973bd03b7870.zip
shader_ir: Remove unnecessary constructors and use optional for ScanFlow result
Diffstat (limited to 'src')
-rw-r--r--src/video_core/shader/control_flow.cpp21
-rw-r--r--src/video_core/shader/control_flow.h14
-rw-r--r--src/video_core/shader/decode.cpp10
3 files changed, 17 insertions, 28 deletions
diff --git a/src/video_core/shader/control_flow.cpp b/src/video_core/shader/control_flow.cpp
index deef0cd3a..6259ad594 100644
--- a/src/video_core/shader/control_flow.cpp
+++ b/src/video_core/shader/control_flow.cpp
@@ -29,10 +29,6 @@ struct ControlStack {
29 std::array<u32, stack_fixed_size> stack{}; 29 std::array<u32, stack_fixed_size> stack{};
30 u32 index{}; 30 u32 index{};
31 31
32 ControlStack() {}
33
34 ControlStack(const ControlStack& cp) = default;
35
36 bool Compare(const ControlStack& cs) const { 32 bool Compare(const ControlStack& cs) const {
37 if (index != cs.index) { 33 if (index != cs.index) {
38 return false; 34 return false;
@@ -75,8 +71,6 @@ struct ControlStack {
75}; 71};
76 72
77struct Query { 73struct Query {
78 Query() {}
79 Query(const Query& q) = default;
80 u32 address{}; 74 u32 address{};
81 ControlStack ssy_stack{}; 75 ControlStack ssy_stack{};
82 ControlStack pbk_stack{}; 76 ControlStack pbk_stack{};
@@ -91,8 +85,6 @@ struct BlockStack {
91}; 85};
92 86
93struct BlockBranchInfo { 87struct BlockBranchInfo {
94 BlockBranchInfo() = default;
95 BlockBranchInfo(const BlockBranchInfo& b) = default;
96 Condition condition{}; 88 Condition condition{};
97 s32 address{exit_branch}; 89 s32 address{exit_branch};
98 bool kill{}; 90 bool kill{};
@@ -102,7 +94,6 @@ struct BlockBranchInfo {
102}; 94};
103 95
104struct BlockInfo { 96struct BlockInfo {
105 BlockInfo() = default;
106 u32 start{}; 97 u32 start{};
107 u32 end{}; 98 u32 end{};
108 bool visited{}; 99 bool visited{};
@@ -454,8 +445,8 @@ bool TryQuery(CFGRebuildState& state) {
454 return true; 445 return true;
455} 446}
456 447
457bool ScanFlow(const ProgramCode& program_code, u32 program_size, u32 start_address, 448std::optional<ShaderCharacteristics> ScanFlow(const ProgramCode& program_code, u32 program_size,
458 ShaderCharacteristics& result_out) { 449 u32 start_address) {
459 CFGRebuildState state{program_code, program_size}; 450 CFGRebuildState state{program_code, program_size};
460 // Inspect Code and generate blocks 451 // Inspect Code and generate blocks
461 state.labels.clear(); 452 state.labels.clear();
@@ -463,7 +454,7 @@ bool ScanFlow(const ProgramCode& program_code, u32 program_size, u32 start_addre
463 state.inspect_queries.push_back(start_address); 454 state.inspect_queries.push_back(start_address);
464 while (!state.inspect_queries.empty()) { 455 while (!state.inspect_queries.empty()) {
465 if (!TryInspectAddress(state)) { 456 if (!TryInspectAddress(state)) {
466 return false; 457 return {};
467 } 458 }
468 } 459 }
469 // Decompile Stacks 460 // Decompile Stacks
@@ -480,7 +471,7 @@ bool ScanFlow(const ProgramCode& program_code, u32 program_size, u32 start_addre
480 // Sort and organize results 471 // Sort and organize results
481 std::sort(state.block_info.begin(), state.block_info.end(), 472 std::sort(state.block_info.begin(), state.block_info.end(),
482 [](const BlockInfo& a, const BlockInfo& b) -> bool { return a.start < b.start; }); 473 [](const BlockInfo& a, const BlockInfo& b) -> bool { return a.start < b.start; });
483 result_out.blocks.clear(); 474 ShaderCharacteristics result_out{};
484 result_out.decompilable = decompiled; 475 result_out.decompilable = decompiled;
485 result_out.start = start_address; 476 result_out.start = start_address;
486 result_out.end = start_address; 477 result_out.end = start_address;
@@ -499,7 +490,7 @@ bool ScanFlow(const ProgramCode& program_code, u32 program_size, u32 start_addre
499 } 490 }
500 if (result_out.decompilable) { 491 if (result_out.decompilable) {
501 result_out.labels = std::move(state.labels); 492 result_out.labels = std::move(state.labels);
502 return true; 493 return {result_out};
503 } 494 }
504 // If it's not decompilable, merge the unlabelled blocks together 495 // If it's not decompilable, merge the unlabelled blocks together
505 auto back = result_out.blocks.begin(); 496 auto back = result_out.blocks.begin();
@@ -513,6 +504,6 @@ bool ScanFlow(const ProgramCode& program_code, u32 program_size, u32 start_addre
513 back = next; 504 back = next;
514 next++; 505 next++;
515 } 506 }
516 return true; 507 return {result_out};
517} 508}
518} // namespace VideoCommon::Shader 509} // namespace VideoCommon::Shader
diff --git a/src/video_core/shader/control_flow.h b/src/video_core/shader/control_flow.h
index 4689b0c10..5e8ea3271 100644
--- a/src/video_core/shader/control_flow.h
+++ b/src/video_core/shader/control_flow.h
@@ -32,8 +32,6 @@ struct Condition {
32}; 32};
33 33
34struct ShaderBlock { 34struct ShaderBlock {
35 ShaderBlock() = default;
36 ShaderBlock(const ShaderBlock& sb) = default;
37 u32 start{}; 35 u32 start{};
38 u32 end{}; 36 u32 end{};
39 bool ignore_branch{}; 37 bool ignore_branch{};
@@ -44,7 +42,7 @@ struct ShaderBlock {
44 bool operator==(const Branch& b) const { 42 bool operator==(const Branch& b) const {
45 return std::tie(cond, kills, address) == std::tie(b.cond, b.kills, b.address); 43 return std::tie(cond, kills, address) == std::tie(b.cond, b.kills, b.address);
46 } 44 }
47 } branch; 45 } branch{};
48 bool operator==(const ShaderBlock& sb) const { 46 bool operator==(const ShaderBlock& sb) const {
49 return std::tie(start, end, ignore_branch, branch) == 47 return std::tie(start, end, ignore_branch, branch) ==
50 std::tie(sb.start, sb.end, sb.ignore_branch, sb.branch); 48 std::tie(sb.start, sb.end, sb.ignore_branch, sb.branch);
@@ -52,14 +50,14 @@ struct ShaderBlock {
52}; 50};
53 51
54struct ShaderCharacteristics { 52struct ShaderCharacteristics {
55 std::list<ShaderBlock> blocks; 53 std::list<ShaderBlock> blocks{};
56 bool decompilable{}; 54 bool decompilable{};
57 u32 start; 55 u32 start{};
58 u32 end; 56 u32 end{};
59 std::unordered_set<u32> labels{}; 57 std::unordered_set<u32> labels{};
60}; 58};
61 59
62bool ScanFlow(const ProgramCode& program_code, u32 program_size, u32 start_address, 60std::optional<ShaderCharacteristics> ScanFlow(const ProgramCode& program_code, u32 program_size,
63 ShaderCharacteristics& result_out); 61 u32 start_address);
64 62
65} // namespace VideoCommon::Shader 63} // namespace VideoCommon::Shader
diff --git a/src/video_core/shader/decode.cpp b/src/video_core/shader/decode.cpp
index b4a282cbd..15cb33bbf 100644
--- a/src/video_core/shader/decode.cpp
+++ b/src/video_core/shader/decode.cpp
@@ -39,9 +39,9 @@ void ShaderIR::Decode() {
39 std::memcpy(&header, program_code.data(), sizeof(Tegra::Shader::Header)); 39 std::memcpy(&header, program_code.data(), sizeof(Tegra::Shader::Header));
40 40
41 disable_flow_stack = false; 41 disable_flow_stack = false;
42 ShaderCharacteristics shader_info{}; 42 const auto info = ScanFlow(program_code, program_code.size(), main_offset);
43 bool can_proceed = ScanFlow(program_code, program_code.size(), main_offset, shader_info); 43 if (info) {
44 if (can_proceed) { 44 const auto& shader_info = *info;
45 coverage_begin = shader_info.start; 45 coverage_begin = shader_info.start;
46 coverage_end = shader_info.end; 46 coverage_end = shader_info.end;
47 if (shader_info.decompilable) { 47 if (shader_info.decompilable) {
@@ -52,7 +52,7 @@ void ShaderIR::Decode() {
52 } 52 }
53 basic_blocks.insert({label, nodes}); 53 basic_blocks.insert({label, nodes});
54 }); 54 });
55 std::list<ShaderBlock>& blocks = shader_info.blocks; 55 const auto& blocks = shader_info.blocks;
56 NodeBlock current_block; 56 NodeBlock current_block;
57 u32 current_label = exit_branch; 57 u32 current_label = exit_branch;
58 for (auto& block : blocks) { 58 for (auto& block : blocks) {
@@ -82,7 +82,7 @@ void ShaderIR::Decode() {
82 82
83 // Now we need to deal with an undecompilable shader. We need to brute force 83 // Now we need to deal with an undecompilable shader. We need to brute force
84 // a shader that captures every position. 84 // a shader that captures every position.
85 coverage_begin = shader_info.start; 85 coverage_begin = main_offset;
86 const u32 shader_end = static_cast<u32>(program_size / sizeof(u64)); 86 const u32 shader_end = static_cast<u32>(program_size / sizeof(u64));
87 coverage_end = shader_end; 87 coverage_end = shader_end;
88 for (u32 label = main_offset; label < shader_end; label++) { 88 for (u32 label = main_offset; label < shader_end; label++) {