summaryrefslogtreecommitdiff
path: root/src/shader_recompiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler')
-rw-r--r--src/shader_recompiler/CMakeLists.txt1
-rw-r--r--src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp3
-rw-r--r--src/shader_recompiler/ir_opt/passes.h1
-rw-r--r--src/shader_recompiler/ir_opt/rescaling_pass.cpp60
-rw-r--r--src/shader_recompiler/shader_info.h2
5 files changed, 32 insertions, 35 deletions
diff --git a/src/shader_recompiler/CMakeLists.txt b/src/shader_recompiler/CMakeLists.txt
index b5b7e5e83..bc3df80c8 100644
--- a/src/shader_recompiler/CMakeLists.txt
+++ b/src/shader_recompiler/CMakeLists.txt
@@ -221,6 +221,7 @@ add_library(shader_recompiler STATIC
221 ir_opt/lower_fp16_to_fp32.cpp 221 ir_opt/lower_fp16_to_fp32.cpp
222 ir_opt/lower_int64_to_int32.cpp 222 ir_opt/lower_int64_to_int32.cpp
223 ir_opt/passes.h 223 ir_opt/passes.h
224 ir_opt/rescaling_pass.cpp
224 ir_opt/ssa_rewrite_pass.cpp 225 ir_opt/ssa_rewrite_pass.cpp
225 ir_opt/texture_pass.cpp 226 ir_opt/texture_pass.cpp
226 ir_opt/verification_pass.cpp 227 ir_opt/verification_pass.cpp
diff --git a/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp b/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp
index f69e1c9cc..ef918f4d4 100644
--- a/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp
+++ b/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp
@@ -430,6 +430,9 @@ void VisitUsages(Info& info, IR::Inst& inst) {
430 case IR::Opcode::IsHelperInvocation: 430 case IR::Opcode::IsHelperInvocation:
431 info.uses_is_helper_invocation = true; 431 info.uses_is_helper_invocation = true;
432 break; 432 break;
433 case IR::Opcode::ResolutionDownFactor:
434 info.uses_rescaling_uniform = true;
435 break;
433 case IR::Opcode::LaneId: 436 case IR::Opcode::LaneId:
434 info.uses_subgroup_invocation_id = true; 437 info.uses_subgroup_invocation_id = true;
435 break; 438 break;
diff --git a/src/shader_recompiler/ir_opt/passes.h b/src/shader_recompiler/ir_opt/passes.h
index 2f89b1ea0..f877c7ba0 100644
--- a/src/shader_recompiler/ir_opt/passes.h
+++ b/src/shader_recompiler/ir_opt/passes.h
@@ -19,6 +19,7 @@ void GlobalMemoryToStorageBufferPass(IR::Program& program);
19void IdentityRemovalPass(IR::Program& program); 19void IdentityRemovalPass(IR::Program& program);
20void LowerFp16ToFp32(IR::Program& program); 20void LowerFp16ToFp32(IR::Program& program);
21void LowerInt64ToInt32(IR::Program& program); 21void LowerInt64ToInt32(IR::Program& program);
22void RescalingPass(IR::Program& program);
22void SsaRewritePass(IR::Program& program); 23void SsaRewritePass(IR::Program& program);
23void TexturePass(Environment& env, IR::Program& program); 24void TexturePass(Environment& env, IR::Program& program);
24void VerificationPass(const IR::Program& program); 25void VerificationPass(const IR::Program& program);
diff --git a/src/shader_recompiler/ir_opt/rescaling_pass.cpp b/src/shader_recompiler/ir_opt/rescaling_pass.cpp
index d3ae3f159..293593c78 100644
--- a/src/shader_recompiler/ir_opt/rescaling_pass.cpp
+++ b/src/shader_recompiler/ir_opt/rescaling_pass.cpp
@@ -3,7 +3,9 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "common/alignment.h" 5#include "common/alignment.h"
6#include "common/settings.h"
6#include "shader_recompiler/environment.h" 7#include "shader_recompiler/environment.h"
8#include "shader_recompiler/frontend/ir/ir_emitter.h"
7#include "shader_recompiler/frontend/ir/modifiers.h" 9#include "shader_recompiler/frontend/ir/modifiers.h"
8#include "shader_recompiler/frontend/ir/program.h" 10#include "shader_recompiler/frontend/ir/program.h"
9#include "shader_recompiler/frontend/ir/value.h" 11#include "shader_recompiler/frontend/ir/value.h"
@@ -12,59 +14,49 @@
12 14
13namespace Shader::Optimization { 15namespace Shader::Optimization {
14namespace { 16namespace {
15 17void PatchFragCoord(IR::Block& block, IR::Inst& inst) {
16void PatchFragCoord(IR::Inst& inst) {
17 IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; 18 IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)};
18 const IR::F32 inv_resolution_factor = IR::F32{Settings::values.resolution_info.down_factor}; 19 const IR::F32 down_factor{ir.ResolutionDownFactor()};
19 const IR::F32 new_get_attribute = ir.GetAttribute(inst.Arg(0).Attribute()); 20 const IR::F32 frag_coord{&inst};
20 const IR::F32 mul = ir.FMul(new_get_attribute, inv_resolution_factor); 21 const IR::F32 downscaled_frag_coord{ir.FPMul(frag_coord, down_factor)};
21 const IR::U1 should_rescale = IR::U1{true}; 22 inst.ReplaceUsesWith(downscaled_frag_coord);
22 const IR::F32 selection = ir.Select(should_rescale, mul, new_get_attribute);
23 inst.ReplaceUsesWith(selection);
24} 23}
25 24
26void Visit(Info& info, IR::Inst& inst) { 25void Visit(const IR::Program& program, IR::Block& block, IR::Inst& inst) {
27 info.requires_rescaling_uniform = false; 26 const bool is_fragment_shader{program.stage == Stage::Fragment};
28 switch (inst.GetOpcode()) { 27 switch (inst.GetOpcode()) {
29 case IR::Opcode::GetAttribute: { 28 case IR::Opcode::GetAttribute: {
30 conast auto attrib = inst.Arg(0).Attribute(); 29 const IR::Attribute attr{inst.Arg(0).Attribute()};
31 const bool is_frag = 30 switch (attr) {
32 attrib == IR::Attribute::PositionX || attrib == IR::Attribute::PositionY; 31 case IR::Attribute::PositionX:
33 const bool must_path = is_frag && program.stage == Stage::Fragment; 32 case IR::Attribute::PositionY:
34 if (must_path) { 33 if (is_fragment_shader) {
35 PatchFragCoord(inst); 34 PatchFragCoord(block, inst);
36 info.requires_rescaling_uniform = true; 35 }
36 break;
37 default:
38 break;
37 } 39 }
38 break; 40 break;
39 } 41 }
40 case IR::Opcode::ImageQueryDimensions: { 42 case IR::Opcode::ImageQueryDimensions:
41 info.requires_rescaling_uniform |= true;
42 break; 43 break;
43 } 44 case IR::Opcode::ImageFetch:
44 case IR::Opcode::ImageFetch: {
45 info.requires_rescaling_uniform |= true;
46 break; 45 break;
47 } 46 case IR::Opcode::ImageRead:
48 case IR::Opcode::ImageRead: {
49 info.requires_rescaling_uniform |= true;
50 break; 47 break;
51 } 48 case IR::Opcode::ImageWrite:
52 case IR::Opcode::ImageWrite: {
53 info.requires_rescaling_uniform |= true;
54 break; 49 break;
55 }
56 default: 50 default:
57 break; 51 break;
58 } 52 }
59} 53}
54} // Anonymous namespace
60 55
61} // namespace 56void RescalingPass(IR::Program& program) {
62
63void RescalingPass(Environment& env, IR::Program& program) {
64 Info& info{program.info};
65 for (IR::Block* const block : program.post_order_blocks) { 57 for (IR::Block* const block : program.post_order_blocks) {
66 for (IR::Inst& inst : block->Instructions()) { 58 for (IR::Inst& inst : block->Instructions()) {
67 Visit(info, inst); 59 Visit(program, *block, inst);
68 } 60 }
69 } 61 }
70} 62}
diff --git a/src/shader_recompiler/shader_info.h b/src/shader_recompiler/shader_info.h
index e7981a08c..7bac9e2cd 100644
--- a/src/shader_recompiler/shader_info.h
+++ b/src/shader_recompiler/shader_info.h
@@ -172,7 +172,7 @@ struct Info {
172 bool uses_global_memory{}; 172 bool uses_global_memory{};
173 bool uses_atomic_image_u32{}; 173 bool uses_atomic_image_u32{};
174 bool uses_shadow_lod{}; 174 bool uses_shadow_lod{};
175 bool requires_rescaling_uniform{}; 175 bool uses_rescaling_uniform{};
176 176
177 IR::Type used_constant_buffer_types{}; 177 IR::Type used_constant_buffer_types{};
178 IR::Type used_storage_buffer_types{}; 178 IR::Type used_storage_buffer_types{};