diff options
Diffstat (limited to 'src/shader_recompiler')
84 files changed, 969 insertions, 247 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_convert.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_convert.cpp index 4cff70fe4..8603c6be2 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_convert.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_convert.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string_view> | ||
| 6 | |||
| 7 | #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h" | 5 | #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h" |
| 8 | #include "shader_recompiler/backend/glasm/glasm_emit_context.h" | 6 | #include "shader_recompiler/backend/glasm/glasm_emit_context.h" |
| 9 | #include "shader_recompiler/frontend/ir/modifiers.h" | 7 | #include "shader_recompiler/frontend/ir/modifiers.h" |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_floating_point.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_floating_point.cpp index 356640471..e4b6b6f31 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_floating_point.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_floating_point.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string_view> | ||
| 6 | |||
| 7 | #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h" | 5 | #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h" |
| 8 | #include "shader_recompiler/backend/glasm/glasm_emit_context.h" | 6 | #include "shader_recompiler/backend/glasm/glasm_emit_context.h" |
| 9 | #include "shader_recompiler/frontend/ir/modifiers.h" | 7 | #include "shader_recompiler/frontend/ir/modifiers.h" |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_memory.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_memory.cpp index f0fd94a28..44b363b50 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_memory.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_memory.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string_view> | ||
| 6 | |||
| 7 | #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h" | 5 | #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h" |
| 8 | #include "shader_recompiler/backend/glasm/glasm_emit_context.h" | 6 | #include "shader_recompiler/backend/glasm/glasm_emit_context.h" |
| 9 | #include "shader_recompiler/frontend/ir/program.h" | 7 | #include "shader_recompiler/frontend/ir/program.h" |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_not_implemented.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_not_implemented.cpp index 86287ee3f..affe35be7 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_not_implemented.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_not_implemented.cpp | |||
| @@ -2,11 +2,8 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string_view> | ||
| 6 | |||
| 7 | #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h" | 5 | #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h" |
| 8 | #include "shader_recompiler/backend/glasm/glasm_emit_context.h" | 6 | #include "shader_recompiler/backend/glasm/glasm_emit_context.h" |
| 9 | #include "shader_recompiler/frontend/ir/program.h" | ||
| 10 | #include "shader_recompiler/frontend/ir/value.h" | 7 | #include "shader_recompiler/frontend/ir/value.h" |
| 11 | 8 | ||
| 12 | #ifdef _MSC_VER | 9 | #ifdef _MSC_VER |
diff --git a/src/shader_recompiler/backend/glasm/glasm_emit_context.cpp b/src/shader_recompiler/backend/glasm/glasm_emit_context.cpp index 0401953f7..af88b7dfa 100644 --- a/src/shader_recompiler/backend/glasm/glasm_emit_context.cpp +++ b/src/shader_recompiler/backend/glasm/glasm_emit_context.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string_view> | ||
| 6 | |||
| 7 | #include "shader_recompiler/backend/bindings.h" | 5 | #include "shader_recompiler/backend/bindings.h" |
| 8 | #include "shader_recompiler/backend/glasm/emit_glasm.h" | 6 | #include "shader_recompiler/backend/glasm/emit_glasm.h" |
| 9 | #include "shader_recompiler/backend/glasm/glasm_emit_context.h" | 7 | #include "shader_recompiler/backend/glasm/glasm_emit_context.h" |
diff --git a/src/shader_recompiler/backend/glasm/reg_alloc.cpp b/src/shader_recompiler/backend/glasm/reg_alloc.cpp index 201e428c1..4e98d3ea0 100644 --- a/src/shader_recompiler/backend/glasm/reg_alloc.cpp +++ b/src/shader_recompiler/backend/glasm/reg_alloc.cpp | |||
| @@ -2,11 +2,8 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string> | ||
| 6 | |||
| 7 | #include <fmt/format.h> | 5 | #include <fmt/format.h> |
| 8 | 6 | ||
| 9 | #include "shader_recompiler/backend/glasm/glasm_emit_context.h" | ||
| 10 | #include "shader_recompiler/backend/glasm/reg_alloc.h" | 7 | #include "shader_recompiler/backend/glasm/reg_alloc.h" |
| 11 | #include "shader_recompiler/exception.h" | 8 | #include "shader_recompiler/exception.h" |
| 12 | #include "shader_recompiler/frontend/ir/value.h" | 9 | #include "shader_recompiler/frontend/ir/value.h" |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_barriers.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_barriers.cpp index 8a9faa394..0f204495c 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_barriers.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_barriers.cpp | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" | 5 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" |
| 6 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" | 6 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" |
| 7 | #include "shader_recompiler/frontend/ir/value.h" | ||
| 8 | 7 | ||
| 9 | namespace Shader::Backend::GLSL { | 8 | namespace Shader::Backend::GLSL { |
| 10 | void EmitBarrier(EmitContext& ctx) { | 9 | void EmitBarrier(EmitContext& ctx) { |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp index 0c1fbc7b1..282668b36 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp | |||
| @@ -35,6 +35,15 @@ std::string_view OutputVertexIndex(EmitContext& ctx) { | |||
| 35 | return ctx.stage == Stage::TessellationControl ? "[gl_InvocationID]" : ""; | 35 | return ctx.stage == Stage::TessellationControl ? "[gl_InvocationID]" : ""; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | std::string ChooseCbuf(EmitContext& ctx, const IR::Value& binding, std::string_view index) { | ||
| 39 | if (binding.IsImmediate()) { | ||
| 40 | return fmt::format("{}_cbuf{}[{}]", ctx.stage_name, binding.U32(), index); | ||
| 41 | } else { | ||
| 42 | const auto binding_var{ctx.var_alloc.Consume(binding)}; | ||
| 43 | return fmt::format("GetCbufIndirect({},{})", binding_var, index); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 38 | void GetCbuf(EmitContext& ctx, std::string_view ret, const IR::Value& binding, | 47 | void GetCbuf(EmitContext& ctx, std::string_view ret, const IR::Value& binding, |
| 39 | const IR::Value& offset, u32 num_bits, std::string_view cast = {}, | 48 | const IR::Value& offset, u32 num_bits, std::string_view cast = {}, |
| 40 | std::string_view bit_offset = {}) { | 49 | std::string_view bit_offset = {}) { |
| @@ -55,8 +64,8 @@ void GetCbuf(EmitContext& ctx, std::string_view ret, const IR::Value& binding, | |||
| 55 | const auto swizzle{is_immediate ? fmt::format(".{}", OffsetSwizzle(offset.U32())) | 64 | const auto swizzle{is_immediate ? fmt::format(".{}", OffsetSwizzle(offset.U32())) |
| 56 | : fmt::format("[({}>>2)%4]", offset_var)}; | 65 | : fmt::format("[({}>>2)%4]", offset_var)}; |
| 57 | 66 | ||
| 58 | const auto cbuf{fmt::format("{}_cbuf{}", ctx.stage_name, binding.U32())}; | 67 | const auto cbuf{ChooseCbuf(ctx, binding, index)}; |
| 59 | const auto cbuf_cast{fmt::format("{}({}[{}]{{}})", cast, cbuf, index)}; | 68 | const auto cbuf_cast{fmt::format("{}({}{{}})", cast, cbuf)}; |
| 60 | const auto extraction{num_bits == 32 ? cbuf_cast | 69 | const auto extraction{num_bits == 32 ? cbuf_cast |
| 61 | : fmt::format("bitfieldExtract({},int({}),{})", cbuf_cast, | 70 | : fmt::format("bitfieldExtract({},int({}),{})", cbuf_cast, |
| 62 | bit_offset, num_bits)}; | 71 | bit_offset, num_bits)}; |
| @@ -140,9 +149,9 @@ void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | |||
| 140 | 149 | ||
| 141 | void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 150 | void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 142 | const IR::Value& offset) { | 151 | const IR::Value& offset) { |
| 143 | const auto cbuf{fmt::format("{}_cbuf{}", ctx.stage_name, binding.U32())}; | ||
| 144 | const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "" : "ftou"}; | 152 | const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "" : "ftou"}; |
| 145 | if (offset.IsImmediate()) { | 153 | if (offset.IsImmediate()) { |
| 154 | const auto cbuf{fmt::format("{}_cbuf{}", ctx.stage_name, binding.U32())}; | ||
| 146 | static constexpr u32 cbuf_size{0x10000}; | 155 | static constexpr u32 cbuf_size{0x10000}; |
| 147 | const u32 u32_offset{offset.U32()}; | 156 | const u32 u32_offset{offset.U32()}; |
| 148 | const s32 signed_offset{static_cast<s32>(offset.U32())}; | 157 | const s32 signed_offset{static_cast<s32>(offset.U32())}; |
| @@ -162,17 +171,17 @@ void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding | |||
| 162 | return; | 171 | return; |
| 163 | } | 172 | } |
| 164 | const auto offset_var{ctx.var_alloc.Consume(offset)}; | 173 | const auto offset_var{ctx.var_alloc.Consume(offset)}; |
| 174 | const auto cbuf{ChooseCbuf(ctx, binding, fmt::format("{}>>4", offset_var))}; | ||
| 165 | if (!ctx.profile.has_gl_component_indexing_bug) { | 175 | if (!ctx.profile.has_gl_component_indexing_bug) { |
| 166 | ctx.AddU32x2("{}=uvec2({}({}[{}>>4][({}>>2)%4]),{}({}[({}+4)>>4][(({}+4)>>2)%4]));", inst, | 176 | ctx.AddU32x2("{}=uvec2({}({}[({}>>2)%4]),{}({}[(({}+4)>>2)%4]));", inst, cast, cbuf, |
| 167 | cast, cbuf, offset_var, offset_var, cast, cbuf, offset_var, offset_var); | 177 | offset_var, cast, cbuf, offset_var); |
| 168 | return; | 178 | return; |
| 169 | } | 179 | } |
| 170 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x2)}; | 180 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x2)}; |
| 171 | const auto cbuf_offset{fmt::format("{}>>2", offset_var)}; | 181 | const auto cbuf_offset{fmt::format("{}>>2", offset_var)}; |
| 172 | for (u32 swizzle = 0; swizzle < 4; ++swizzle) { | 182 | for (u32 swizzle = 0; swizzle < 4; ++swizzle) { |
| 173 | ctx.Add("if(({}&3)=={}){}=uvec2({}({}[{}>>4].{}),{}({}[({}+4)>>4].{}));", cbuf_offset, | 183 | ctx.Add("if(({}&3)=={}){}=uvec2({}({}.{}),{}({}.{}));", cbuf_offset, swizzle, ret, cast, |
| 174 | swizzle, ret, cast, cbuf, offset_var, "xyzw"[swizzle], cast, cbuf, offset_var, | 184 | cbuf, "xyzw"[swizzle], cast, cbuf, "xyzw"[(swizzle + 1) % 4]); |
| 175 | "xyzw"[(swizzle + 1) % 4]); | ||
| 176 | } | 185 | } |
| 177 | } | 186 | } |
| 178 | 187 | ||
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_control_flow.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_control_flow.cpp index c86465e8b..6f61560f1 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_control_flow.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_control_flow.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string_view> | ||
| 6 | |||
| 7 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" | 5 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" |
| 8 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" | 6 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" |
| 9 | #include "shader_recompiler/exception.h" | 7 | #include "shader_recompiler/exception.h" |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp index b0d85be99..64322cdbf 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string_view> | ||
| 6 | |||
| 7 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" | 5 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" |
| 8 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" | 6 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" |
| 9 | #include "shader_recompiler/frontend/ir/value.h" | 7 | #include "shader_recompiler/frontend/ir/value.h" |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_logical.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_logical.cpp index 742fec9cf..162a8c461 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_logical.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_logical.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string_view> | ||
| 6 | |||
| 7 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" | 5 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" |
| 8 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" | 6 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" |
| 9 | #include "shader_recompiler/frontend/ir/value.h" | 7 | #include "shader_recompiler/frontend/ir/value.h" |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_shared_memory.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_shared_memory.cpp index 74ae345e5..f8aa4ecd6 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_shared_memory.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_shared_memory.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string_view> | ||
| 6 | |||
| 7 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" | 5 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" |
| 8 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" | 6 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" |
| 9 | #include "shader_recompiler/frontend/ir/value.h" | 7 | #include "shader_recompiler/frontend/ir/value.h" |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp index fcf620b79..8b94ea90a 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string_view> | ||
| 6 | |||
| 7 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" | 5 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" |
| 8 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" | 6 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" |
| 9 | #include "shader_recompiler/frontend/ir/program.h" | 7 | #include "shader_recompiler/frontend/ir/program.h" |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_undefined.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_undefined.cpp index cace1db85..9367524e8 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_undefined.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_undefined.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string_view> | ||
| 6 | |||
| 7 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" | 5 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" |
| 8 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" | 6 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" |
| 9 | 7 | ||
diff --git a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp index e816a93ec..17266f40d 100644 --- a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp | |||
| @@ -359,6 +359,7 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile | |||
| 359 | header += "layout(location=0) uniform vec4 scaling;"; | 359 | header += "layout(location=0) uniform vec4 scaling;"; |
| 360 | } | 360 | } |
| 361 | DefineConstantBuffers(bindings); | 361 | DefineConstantBuffers(bindings); |
| 362 | DefineConstantBufferIndirect(); | ||
| 362 | DefineStorageBuffers(bindings); | 363 | DefineStorageBuffers(bindings); |
| 363 | SetupImages(bindings); | 364 | SetupImages(bindings); |
| 364 | SetupTextures(bindings); | 365 | SetupTextures(bindings); |
| @@ -436,6 +437,24 @@ void EmitContext::DefineConstantBuffers(Bindings& bindings) { | |||
| 436 | } | 437 | } |
| 437 | } | 438 | } |
| 438 | 439 | ||
| 440 | void EmitContext::DefineConstantBufferIndirect() { | ||
| 441 | if (!info.uses_cbuf_indirect) { | ||
| 442 | return; | ||
| 443 | } | ||
| 444 | |||
| 445 | header += profile.has_gl_cbuf_ftou_bug ? "uvec4 " : "vec4 "; | ||
| 446 | header += "GetCbufIndirect(uint binding, uint offset){" | ||
| 447 | "switch(binding){" | ||
| 448 | "default:"; | ||
| 449 | |||
| 450 | for (const auto& desc : info.constant_buffer_descriptors) { | ||
| 451 | header += | ||
| 452 | fmt::format("case {}:return {}_cbuf{}[offset];", desc.index, stage_name, desc.index); | ||
| 453 | } | ||
| 454 | |||
| 455 | header += "}}"; | ||
| 456 | } | ||
| 457 | |||
| 439 | void EmitContext::DefineStorageBuffers(Bindings& bindings) { | 458 | void EmitContext::DefineStorageBuffers(Bindings& bindings) { |
| 440 | if (info.storage_buffers_descriptors.empty()) { | 459 | if (info.storage_buffers_descriptors.empty()) { |
| 441 | return; | 460 | return; |
diff --git a/src/shader_recompiler/backend/glsl/glsl_emit_context.h b/src/shader_recompiler/backend/glsl/glsl_emit_context.h index d9b639d29..2b13db6e6 100644 --- a/src/shader_recompiler/backend/glsl/glsl_emit_context.h +++ b/src/shader_recompiler/backend/glsl/glsl_emit_context.h | |||
| @@ -162,6 +162,7 @@ public: | |||
| 162 | private: | 162 | private: |
| 163 | void SetupExtensions(); | 163 | void SetupExtensions(); |
| 164 | void DefineConstantBuffers(Bindings& bindings); | 164 | void DefineConstantBuffers(Bindings& bindings); |
| 165 | void DefineConstantBufferIndirect(); | ||
| 165 | void DefineStorageBuffers(Bindings& bindings); | 166 | void DefineStorageBuffers(Bindings& bindings); |
| 166 | void DefineGenericOutput(size_t index, u32 invocations); | 167 | void DefineGenericOutput(size_t index, u32 invocations); |
| 167 | void DefineHelperFunctions(); | 168 | void DefineHelperFunctions(); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv.h b/src/shader_recompiler/backend/spirv/emit_spirv.h index b412957c7..2b360e073 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv.h | |||
| @@ -22,7 +22,7 @@ constexpr u32 NUM_TEXTURE_AND_IMAGE_SCALING_WORDS = | |||
| 22 | struct RescalingLayout { | 22 | struct RescalingLayout { |
| 23 | alignas(16) std::array<u32, NUM_TEXTURE_SCALING_WORDS> rescaling_textures; | 23 | alignas(16) std::array<u32, NUM_TEXTURE_SCALING_WORDS> rescaling_textures; |
| 24 | alignas(16) std::array<u32, NUM_IMAGE_SCALING_WORDS> rescaling_images; | 24 | alignas(16) std::array<u32, NUM_IMAGE_SCALING_WORDS> rescaling_images; |
| 25 | alignas(16) u32 down_factor; | 25 | u32 down_factor; |
| 26 | }; | 26 | }; |
| 27 | constexpr u32 RESCALING_LAYOUT_WORDS_OFFSET = offsetof(RescalingLayout, rescaling_textures); | 27 | constexpr u32 RESCALING_LAYOUT_WORDS_OFFSET = offsetof(RescalingLayout, rescaling_textures); |
| 28 | constexpr u32 RESCALING_LAYOUT_DOWN_FACTOR_OFFSET = offsetof(RescalingLayout, down_factor); | 28 | constexpr u32 RESCALING_LAYOUT_DOWN_FACTOR_OFFSET = offsetof(RescalingLayout, down_factor); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_atomic.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_atomic.cpp index d3cbb14a9..cb47d253c 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_atomic.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_atomic.cpp | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <bit> | ||
| 6 | |||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | 7 | #include "shader_recompiler/backend/spirv/emit_spirv.h" |
| 6 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 8 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 7 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 9 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_barriers.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_barriers.cpp index 9ce95a41b..6ecaa3937 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_barriers.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_barriers.cpp | |||
| @@ -2,10 +2,8 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 6 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 5 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 7 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 6 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
| 8 | #include "shader_recompiler/frontend/ir/modifiers.h" | ||
| 9 | 7 | ||
| 10 | namespace Shader::Backend::SPIRV { | 8 | namespace Shader::Backend::SPIRV { |
| 11 | namespace { | 9 | namespace { |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp index 02d1e63f7..831c6f158 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 6 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 5 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 7 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 6 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
| 8 | 7 | ||
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_composite.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_composite.cpp index 5c3e1ee2b..812c3668d 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_composite.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_composite.cpp | |||
| @@ -2,10 +2,8 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 6 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 5 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 7 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 6 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
| 8 | #include "shader_recompiler/frontend/ir/modifiers.h" | ||
| 9 | 7 | ||
| 10 | namespace Shader::Backend::SPIRV { | 8 | namespace Shader::Backend::SPIRV { |
| 11 | 9 | ||
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp index 8ea730c80..aa7082978 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp | |||
| @@ -2,10 +2,10 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <bit> | ||
| 5 | #include <tuple> | 6 | #include <tuple> |
| 6 | #include <utility> | 7 | #include <utility> |
| 7 | 8 | ||
| 8 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 9 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 9 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 10 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 10 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
| 11 | 11 | ||
| @@ -123,34 +123,36 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) { | |||
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | Id GetCbuf(EmitContext& ctx, Id result_type, Id UniformDefinitions::*member_ptr, u32 element_size, | 125 | Id GetCbuf(EmitContext& ctx, Id result_type, Id UniformDefinitions::*member_ptr, u32 element_size, |
| 126 | const IR::Value& binding, const IR::Value& offset) { | 126 | const IR::Value& binding, const IR::Value& offset, const Id indirect_func) { |
| 127 | Id buffer_offset; | ||
| 128 | const Id uniform_type{ctx.uniform_types.*member_ptr}; | ||
| 129 | if (offset.IsImmediate()) { | ||
| 130 | // Hardware been proved to read the aligned offset (e.g. LDC.U32 at 6 will read offset 4) | ||
| 131 | const Id imm_offset{ctx.Const(offset.U32() / element_size)}; | ||
| 132 | buffer_offset = imm_offset; | ||
| 133 | } else if (element_size > 1) { | ||
| 134 | const u32 log2_element_size{static_cast<u32>(std::countr_zero(element_size))}; | ||
| 135 | const Id shift{ctx.Const(log2_element_size)}; | ||
| 136 | buffer_offset = ctx.OpShiftRightArithmetic(ctx.U32[1], ctx.Def(offset), shift); | ||
| 137 | } else { | ||
| 138 | buffer_offset = ctx.Def(offset); | ||
| 139 | } | ||
| 127 | if (!binding.IsImmediate()) { | 140 | if (!binding.IsImmediate()) { |
| 128 | throw NotImplementedException("Constant buffer indexing"); | 141 | return ctx.OpFunctionCall(result_type, indirect_func, ctx.Def(binding), buffer_offset); |
| 129 | } | 142 | } |
| 130 | const Id cbuf{ctx.cbufs[binding.U32()].*member_ptr}; | 143 | const Id cbuf{ctx.cbufs[binding.U32()].*member_ptr}; |
| 131 | const Id uniform_type{ctx.uniform_types.*member_ptr}; | 144 | const Id access_chain{ctx.OpAccessChain(uniform_type, cbuf, ctx.u32_zero_value, buffer_offset)}; |
| 132 | if (!offset.IsImmediate()) { | ||
| 133 | Id index{ctx.Def(offset)}; | ||
| 134 | if (element_size > 1) { | ||
| 135 | const u32 log2_element_size{static_cast<u32>(std::countr_zero(element_size))}; | ||
| 136 | const Id shift{ctx.Const(log2_element_size)}; | ||
| 137 | index = ctx.OpShiftRightArithmetic(ctx.U32[1], ctx.Def(offset), shift); | ||
| 138 | } | ||
| 139 | const Id access_chain{ctx.OpAccessChain(uniform_type, cbuf, ctx.u32_zero_value, index)}; | ||
| 140 | return ctx.OpLoad(result_type, access_chain); | ||
| 141 | } | ||
| 142 | // Hardware been proved to read the aligned offset (e.g. LDC.U32 at 6 will read offset 4) | ||
| 143 | const Id imm_offset{ctx.Const(offset.U32() / element_size)}; | ||
| 144 | const Id access_chain{ctx.OpAccessChain(uniform_type, cbuf, ctx.u32_zero_value, imm_offset)}; | ||
| 145 | return ctx.OpLoad(result_type, access_chain); | 145 | return ctx.OpLoad(result_type, access_chain); |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | Id GetCbufU32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 148 | Id GetCbufU32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 149 | return GetCbuf(ctx, ctx.U32[1], &UniformDefinitions::U32, sizeof(u32), binding, offset); | 149 | return GetCbuf(ctx, ctx.U32[1], &UniformDefinitions::U32, sizeof(u32), binding, offset, |
| 150 | ctx.load_const_func_u32); | ||
| 150 | } | 151 | } |
| 151 | 152 | ||
| 152 | Id GetCbufU32x4(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 153 | Id GetCbufU32x4(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 153 | return GetCbuf(ctx, ctx.U32[4], &UniformDefinitions::U32x4, sizeof(u32[4]), binding, offset); | 154 | return GetCbuf(ctx, ctx.U32[4], &UniformDefinitions::U32x4, sizeof(u32[4]), binding, offset, |
| 155 | ctx.load_const_func_u32x4); | ||
| 154 | } | 156 | } |
| 155 | 157 | ||
| 156 | Id GetCbufElement(EmitContext& ctx, Id vector, const IR::Value& offset, u32 index_offset) { | 158 | Id GetCbufElement(EmitContext& ctx, Id vector, const IR::Value& offset, u32 index_offset) { |
| @@ -201,7 +203,8 @@ void EmitGetIndirectBranchVariable(EmitContext&) { | |||
| 201 | 203 | ||
| 202 | Id EmitGetCbufU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 204 | Id EmitGetCbufU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 203 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int8) { | 205 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int8) { |
| 204 | const Id load{GetCbuf(ctx, ctx.U8, &UniformDefinitions::U8, sizeof(u8), binding, offset)}; | 206 | const Id load{GetCbuf(ctx, ctx.U8, &UniformDefinitions::U8, sizeof(u8), binding, offset, |
| 207 | ctx.load_const_func_u8)}; | ||
| 205 | return ctx.OpUConvert(ctx.U32[1], load); | 208 | return ctx.OpUConvert(ctx.U32[1], load); |
| 206 | } | 209 | } |
| 207 | Id element{}; | 210 | Id element{}; |
| @@ -217,7 +220,8 @@ Id EmitGetCbufU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& of | |||
| 217 | 220 | ||
| 218 | Id EmitGetCbufS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 221 | Id EmitGetCbufS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 219 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int8) { | 222 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int8) { |
| 220 | const Id load{GetCbuf(ctx, ctx.S8, &UniformDefinitions::S8, sizeof(s8), binding, offset)}; | 223 | const Id load{GetCbuf(ctx, ctx.S8, &UniformDefinitions::S8, sizeof(s8), binding, offset, |
| 224 | ctx.load_const_func_u8)}; | ||
| 221 | return ctx.OpSConvert(ctx.U32[1], load); | 225 | return ctx.OpSConvert(ctx.U32[1], load); |
| 222 | } | 226 | } |
| 223 | Id element{}; | 227 | Id element{}; |
| @@ -233,8 +237,8 @@ Id EmitGetCbufS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& of | |||
| 233 | 237 | ||
| 234 | Id EmitGetCbufU16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 238 | Id EmitGetCbufU16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 235 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int16) { | 239 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int16) { |
| 236 | const Id load{ | 240 | const Id load{GetCbuf(ctx, ctx.U16, &UniformDefinitions::U16, sizeof(u16), binding, offset, |
| 237 | GetCbuf(ctx, ctx.U16, &UniformDefinitions::U16, sizeof(u16), binding, offset)}; | 241 | ctx.load_const_func_u16)}; |
| 238 | return ctx.OpUConvert(ctx.U32[1], load); | 242 | return ctx.OpUConvert(ctx.U32[1], load); |
| 239 | } | 243 | } |
| 240 | Id element{}; | 244 | Id element{}; |
| @@ -250,8 +254,8 @@ Id EmitGetCbufU16(EmitContext& ctx, const IR::Value& binding, const IR::Value& o | |||
| 250 | 254 | ||
| 251 | Id EmitGetCbufS16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 255 | Id EmitGetCbufS16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 252 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int16) { | 256 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int16) { |
| 253 | const Id load{ | 257 | const Id load{GetCbuf(ctx, ctx.S16, &UniformDefinitions::S16, sizeof(s16), binding, offset, |
| 254 | GetCbuf(ctx, ctx.S16, &UniformDefinitions::S16, sizeof(s16), binding, offset)}; | 258 | ctx.load_const_func_u16)}; |
| 255 | return ctx.OpSConvert(ctx.U32[1], load); | 259 | return ctx.OpSConvert(ctx.U32[1], load); |
| 256 | } | 260 | } |
| 257 | Id element{}; | 261 | Id element{}; |
| @@ -276,7 +280,8 @@ Id EmitGetCbufU32(EmitContext& ctx, const IR::Value& binding, const IR::Value& o | |||
| 276 | 280 | ||
| 277 | Id EmitGetCbufF32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 281 | Id EmitGetCbufF32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 278 | if (ctx.profile.support_descriptor_aliasing) { | 282 | if (ctx.profile.support_descriptor_aliasing) { |
| 279 | return GetCbuf(ctx, ctx.F32[1], &UniformDefinitions::F32, sizeof(f32), binding, offset); | 283 | return GetCbuf(ctx, ctx.F32[1], &UniformDefinitions::F32, sizeof(f32), binding, offset, |
| 284 | ctx.load_const_func_f32); | ||
| 280 | } else { | 285 | } else { |
| 281 | const Id vector{GetCbufU32x4(ctx, binding, offset)}; | 286 | const Id vector{GetCbufU32x4(ctx, binding, offset)}; |
| 282 | return ctx.OpBitcast(ctx.F32[1], GetCbufElement(ctx, vector, offset, 0u)); | 287 | return ctx.OpBitcast(ctx.F32[1], GetCbufElement(ctx, vector, offset, 0u)); |
| @@ -285,8 +290,8 @@ Id EmitGetCbufF32(EmitContext& ctx, const IR::Value& binding, const IR::Value& o | |||
| 285 | 290 | ||
| 286 | Id EmitGetCbufU32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 291 | Id EmitGetCbufU32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 287 | if (ctx.profile.support_descriptor_aliasing) { | 292 | if (ctx.profile.support_descriptor_aliasing) { |
| 288 | return GetCbuf(ctx, ctx.U32[2], &UniformDefinitions::U32x2, sizeof(u32[2]), binding, | 293 | return GetCbuf(ctx, ctx.U32[2], &UniformDefinitions::U32x2, sizeof(u32[2]), binding, offset, |
| 289 | offset); | 294 | ctx.load_const_func_u32x2); |
| 290 | } else { | 295 | } else { |
| 291 | const Id vector{GetCbufU32x4(ctx, binding, offset)}; | 296 | const Id vector{GetCbufU32x4(ctx, binding, offset)}; |
| 292 | return ctx.OpCompositeConstruct(ctx.U32[2], GetCbufElement(ctx, vector, offset, 0u), | 297 | return ctx.OpCompositeConstruct(ctx.U32[2], GetCbufElement(ctx, vector, offset, 0u), |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_control_flow.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_control_flow.cpp index 1eca3aa85..d1afd47b8 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_control_flow.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_control_flow.cpp | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 6 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 5 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 7 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 6 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
| 8 | 7 | ||
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_convert.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_convert.cpp index 832de2452..137a0e257 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_convert.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_convert.cpp | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 6 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 5 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 7 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 6 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
| 8 | 7 | ||
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_floating_point.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_floating_point.cpp index 0cdc46495..9f65fa269 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_floating_point.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_floating_point.cpp | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 6 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 5 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 7 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 6 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
| 8 | #include "shader_recompiler/frontend/ir/modifiers.h" | 7 | #include "shader_recompiler/frontend/ir/modifiers.h" |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_image_atomic.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_image_atomic.cpp index a96190bc6..727ac2027 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_image_atomic.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_image_atomic.cpp | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 6 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 5 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 7 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 6 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
| 8 | #include "shader_recompiler/frontend/ir/modifiers.h" | 7 | #include "shader_recompiler/frontend/ir/modifiers.h" |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp index 44521f539..45a384e46 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 6 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 5 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 7 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 6 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
| 8 | 7 | ||
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_logical.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_logical.cpp index 47745f7ee..74b6efe01 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_logical.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_logical.cpp | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 6 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 5 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 7 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 6 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
| 8 | 7 | ||
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_select.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_select.cpp index 48caf1ffc..ce55cd31c 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_select.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_select.cpp | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 6 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 5 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 7 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 6 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
| 8 | 7 | ||
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_shared_memory.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_shared_memory.cpp index 330c9052c..b57c66828 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_shared_memory.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_shared_memory.cpp | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 6 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 5 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 7 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 6 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
| 8 | 7 | ||
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_undefined.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_undefined.cpp index b5766fc52..00c6e86e2 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_undefined.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_undefined.cpp | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 6 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 5 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 7 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 6 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
| 8 | 7 | ||
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_warp.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_warp.cpp index 7034228bf..905c735ad 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_warp.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_warp.cpp | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 6 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" | 5 | #include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" |
| 7 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" | 6 | #include "shader_recompiler/backend/spirv/spirv_emit_context.h" |
| 8 | 7 | ||
diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp index cd90c084a..9c83cd2e4 100644 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp | |||
| @@ -4,8 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <bit> | ||
| 7 | #include <climits> | 8 | #include <climits> |
| 8 | #include <string_view> | ||
| 9 | 9 | ||
| 10 | #include <boost/container/static_vector.hpp> | 10 | #include <boost/container/static_vector.hpp> |
| 11 | 11 | ||
| @@ -464,6 +464,7 @@ EmitContext::EmitContext(const Profile& profile_, const RuntimeInfo& runtime_inf | |||
| 464 | DefineSharedMemory(program); | 464 | DefineSharedMemory(program); |
| 465 | DefineSharedMemoryFunctions(program); | 465 | DefineSharedMemoryFunctions(program); |
| 466 | DefineConstantBuffers(program.info, uniform_binding); | 466 | DefineConstantBuffers(program.info, uniform_binding); |
| 467 | DefineConstantBufferIndirectFunctions(program.info); | ||
| 467 | DefineStorageBuffers(program.info, storage_binding); | 468 | DefineStorageBuffers(program.info, storage_binding); |
| 468 | DefineTextureBuffers(program.info, texture_binding); | 469 | DefineTextureBuffers(program.info, texture_binding); |
| 469 | DefineImageBuffers(program.info, image_binding); | 470 | DefineImageBuffers(program.info, image_binding); |
| @@ -993,7 +994,7 @@ void EmitContext::DefineConstantBuffers(const Info& info, u32& binding) { | |||
| 993 | } | 994 | } |
| 994 | return; | 995 | return; |
| 995 | } | 996 | } |
| 996 | IR::Type types{info.used_constant_buffer_types}; | 997 | IR::Type types{info.used_constant_buffer_types | info.used_indirect_cbuf_types}; |
| 997 | if (True(types & IR::Type::U8)) { | 998 | if (True(types & IR::Type::U8)) { |
| 998 | if (profile.support_int8) { | 999 | if (profile.support_int8) { |
| 999 | DefineConstBuffers(*this, info, &UniformDefinitions::U8, binding, U8, 'u', sizeof(u8)); | 1000 | DefineConstBuffers(*this, info, &UniformDefinitions::U8, binding, U8, 'u', sizeof(u8)); |
| @@ -1027,6 +1028,63 @@ void EmitContext::DefineConstantBuffers(const Info& info, u32& binding) { | |||
| 1027 | binding += static_cast<u32>(info.constant_buffer_descriptors.size()); | 1028 | binding += static_cast<u32>(info.constant_buffer_descriptors.size()); |
| 1028 | } | 1029 | } |
| 1029 | 1030 | ||
| 1031 | void EmitContext::DefineConstantBufferIndirectFunctions(const Info& info) { | ||
| 1032 | if (!info.uses_cbuf_indirect) { | ||
| 1033 | return; | ||
| 1034 | } | ||
| 1035 | const auto make_accessor{[&](Id buffer_type, Id UniformDefinitions::*member_ptr) { | ||
| 1036 | const Id func_type{TypeFunction(buffer_type, U32[1], U32[1])}; | ||
| 1037 | const Id func{OpFunction(buffer_type, spv::FunctionControlMask::MaskNone, func_type)}; | ||
| 1038 | const Id binding{OpFunctionParameter(U32[1])}; | ||
| 1039 | const Id offset{OpFunctionParameter(U32[1])}; | ||
| 1040 | |||
| 1041 | AddLabel(); | ||
| 1042 | |||
| 1043 | const Id merge_label{OpLabel()}; | ||
| 1044 | const Id uniform_type{uniform_types.*member_ptr}; | ||
| 1045 | |||
| 1046 | std::array<Id, Info::MAX_INDIRECT_CBUFS> buf_labels; | ||
| 1047 | std::array<Sirit::Literal, Info::MAX_INDIRECT_CBUFS> buf_literals; | ||
| 1048 | for (u32 i = 0; i < Info::MAX_INDIRECT_CBUFS; i++) { | ||
| 1049 | buf_labels[i] = OpLabel(); | ||
| 1050 | buf_literals[i] = Sirit::Literal{i}; | ||
| 1051 | } | ||
| 1052 | OpSelectionMerge(merge_label, spv::SelectionControlMask::MaskNone); | ||
| 1053 | OpSwitch(binding, buf_labels[0], buf_literals, buf_labels); | ||
| 1054 | for (u32 i = 0; i < Info::MAX_INDIRECT_CBUFS; i++) { | ||
| 1055 | AddLabel(buf_labels[i]); | ||
| 1056 | const Id cbuf{cbufs[i].*member_ptr}; | ||
| 1057 | const Id access_chain{OpAccessChain(uniform_type, cbuf, u32_zero_value, offset)}; | ||
| 1058 | const Id result{OpLoad(buffer_type, access_chain)}; | ||
| 1059 | OpReturnValue(result); | ||
| 1060 | } | ||
| 1061 | AddLabel(merge_label); | ||
| 1062 | OpUnreachable(); | ||
| 1063 | OpFunctionEnd(); | ||
| 1064 | return func; | ||
| 1065 | }}; | ||
| 1066 | IR::Type types{info.used_indirect_cbuf_types}; | ||
| 1067 | bool supports_aliasing = profile.support_descriptor_aliasing; | ||
| 1068 | if (supports_aliasing && True(types & IR::Type::U8)) { | ||
| 1069 | load_const_func_u8 = make_accessor(U8, &UniformDefinitions::U8); | ||
| 1070 | } | ||
| 1071 | if (supports_aliasing && True(types & IR::Type::U16)) { | ||
| 1072 | load_const_func_u16 = make_accessor(U16, &UniformDefinitions::U16); | ||
| 1073 | } | ||
| 1074 | if (supports_aliasing && True(types & IR::Type::F32)) { | ||
| 1075 | load_const_func_f32 = make_accessor(F32[1], &UniformDefinitions::F32); | ||
| 1076 | } | ||
| 1077 | if (supports_aliasing && True(types & IR::Type::U32)) { | ||
| 1078 | load_const_func_u32 = make_accessor(U32[1], &UniformDefinitions::U32); | ||
| 1079 | } | ||
| 1080 | if (supports_aliasing && True(types & IR::Type::U32x2)) { | ||
| 1081 | load_const_func_u32x2 = make_accessor(U32[2], &UniformDefinitions::U32x2); | ||
| 1082 | } | ||
| 1083 | if (!supports_aliasing || True(types & IR::Type::U32x4)) { | ||
| 1084 | load_const_func_u32x4 = make_accessor(U32[4], &UniformDefinitions::U32x4); | ||
| 1085 | } | ||
| 1086 | } | ||
| 1087 | |||
| 1030 | void EmitContext::DefineStorageBuffers(const Info& info, u32& binding) { | 1088 | void EmitContext::DefineStorageBuffers(const Info& info, u32& binding) { |
| 1031 | if (info.storage_buffers_descriptors.empty()) { | 1089 | if (info.storage_buffers_descriptors.empty()) { |
| 1032 | return; | 1090 | return; |
diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.h b/src/shader_recompiler/backend/spirv/spirv_emit_context.h index f87138f7e..b9115a405 100644 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.h +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.h | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <string_view> | ||
| 9 | 8 | ||
| 10 | #include <sirit/sirit.h> | 9 | #include <sirit/sirit.h> |
| 11 | 10 | ||
| @@ -294,6 +293,13 @@ public: | |||
| 294 | 293 | ||
| 295 | std::vector<Id> interfaces; | 294 | std::vector<Id> interfaces; |
| 296 | 295 | ||
| 296 | Id load_const_func_u8{}; | ||
| 297 | Id load_const_func_u16{}; | ||
| 298 | Id load_const_func_u32{}; | ||
| 299 | Id load_const_func_f32{}; | ||
| 300 | Id load_const_func_u32x2{}; | ||
| 301 | Id load_const_func_u32x4{}; | ||
| 302 | |||
| 297 | private: | 303 | private: |
| 298 | void DefineCommonTypes(const Info& info); | 304 | void DefineCommonTypes(const Info& info); |
| 299 | void DefineCommonConstants(); | 305 | void DefineCommonConstants(); |
| @@ -302,6 +308,7 @@ private: | |||
| 302 | void DefineSharedMemory(const IR::Program& program); | 308 | void DefineSharedMemory(const IR::Program& program); |
| 303 | void DefineSharedMemoryFunctions(const IR::Program& program); | 309 | void DefineSharedMemoryFunctions(const IR::Program& program); |
| 304 | void DefineConstantBuffers(const Info& info, u32& binding); | 310 | void DefineConstantBuffers(const Info& info, u32& binding); |
| 311 | void DefineConstantBufferIndirectFunctions(const Info& info); | ||
| 305 | void DefineStorageBuffers(const Info& info, u32& binding); | 312 | void DefineStorageBuffers(const Info& info, u32& binding); |
| 306 | void DefineTextureBuffers(const Info& info, u32& binding); | 313 | void DefineTextureBuffers(const Info& info, u32& binding); |
| 307 | void DefineImageBuffers(const Info& info, u32& binding); | 314 | void DefineImageBuffers(const Info& info, u32& binding); |
diff --git a/src/shader_recompiler/exception.h b/src/shader_recompiler/exception.h index d98b6029b..a6aecde3e 100644 --- a/src/shader_recompiler/exception.h +++ b/src/shader_recompiler/exception.h | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | #include <exception> | 7 | #include <exception> |
| 8 | #include <string> | 8 | #include <string> |
| 9 | #include <string_view> | ||
| 10 | #include <utility> | 9 | #include <utility> |
| 11 | 10 | ||
| 12 | #include "common/logging/formatter.h" | 11 | #include "common/logging/formatter.h" |
diff --git a/src/shader_recompiler/frontend/ir/basic_block.cpp b/src/shader_recompiler/frontend/ir/basic_block.cpp index 974efa4a0..a1472cb76 100644 --- a/src/shader_recompiler/frontend/ir/basic_block.cpp +++ b/src/shader_recompiler/frontend/ir/basic_block.cpp | |||
| @@ -5,9 +5,7 @@ | |||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <initializer_list> | 6 | #include <initializer_list> |
| 7 | #include <map> | 7 | #include <map> |
| 8 | #include <memory> | ||
| 9 | 8 | ||
| 10 | #include "common/bit_cast.h" | ||
| 11 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 12 | #include "shader_recompiler/frontend/ir/basic_block.h" | 10 | #include "shader_recompiler/frontend/ir/basic_block.h" |
| 13 | #include "shader_recompiler/frontend/ir/value.h" | 11 | #include "shader_recompiler/frontend/ir/value.h" |
diff --git a/src/shader_recompiler/frontend/ir/condition.h b/src/shader_recompiler/frontend/ir/condition.h index aa8597c60..2f8c10e71 100644 --- a/src/shader_recompiler/frontend/ir/condition.h +++ b/src/shader_recompiler/frontend/ir/condition.h | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <compare> | ||
| 8 | #include <string> | 7 | #include <string> |
| 9 | 8 | ||
| 10 | #include <fmt/format.h> | 9 | #include <fmt/format.h> |
diff --git a/src/shader_recompiler/frontend/ir/microinstruction.cpp b/src/shader_recompiler/frontend/ir/microinstruction.cpp index 631446cf7..4a2564f47 100644 --- a/src/shader_recompiler/frontend/ir/microinstruction.cpp +++ b/src/shader_recompiler/frontend/ir/microinstruction.cpp | |||
| @@ -326,6 +326,11 @@ void Inst::AddPhiOperand(Block* predecessor, const Value& value) { | |||
| 326 | phi_args.emplace_back(predecessor, value); | 326 | phi_args.emplace_back(predecessor, value); |
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | void Inst::ErasePhiOperand(size_t index) { | ||
| 330 | const auto operand_it{phi_args.begin() + static_cast<ptrdiff_t>(index)}; | ||
| 331 | phi_args.erase(operand_it); | ||
| 332 | } | ||
| 333 | |||
| 329 | void Inst::OrderPhiArgs() { | 334 | void Inst::OrderPhiArgs() { |
| 330 | if (op != Opcode::Phi) { | 335 | if (op != Opcode::Phi) { |
| 331 | throw LogicError("{} is not a Phi instruction", op); | 336 | throw LogicError("{} is not a Phi instruction", op); |
diff --git a/src/shader_recompiler/frontend/ir/opcodes.cpp b/src/shader_recompiler/frontend/ir/opcodes.cpp index 24d024ad7..5baa6792f 100644 --- a/src/shader_recompiler/frontend/ir/opcodes.cpp +++ b/src/shader_recompiler/frontend/ir/opcodes.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string_view> | ||
| 6 | |||
| 7 | #include "shader_recompiler/frontend/ir/opcodes.h" | 5 | #include "shader_recompiler/frontend/ir/opcodes.h" |
| 8 | 6 | ||
| 9 | namespace Shader::IR { | 7 | namespace Shader::IR { |
diff --git a/src/shader_recompiler/frontend/ir/opcodes.h b/src/shader_recompiler/frontend/ir/opcodes.h index 9ab108292..85f7aac02 100644 --- a/src/shader_recompiler/frontend/ir/opcodes.h +++ b/src/shader_recompiler/frontend/ir/opcodes.h | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | #include <algorithm> | 7 | #include <algorithm> |
| 8 | #include <array> | 8 | #include <array> |
| 9 | #include <string_view> | ||
| 10 | 9 | ||
| 11 | #include <fmt/format.h> | 10 | #include <fmt/format.h> |
| 12 | 11 | ||
diff --git a/src/shader_recompiler/frontend/ir/value.cpp b/src/shader_recompiler/frontend/ir/value.cpp index d365ea1bc..0248d9c6e 100644 --- a/src/shader_recompiler/frontend/ir/value.cpp +++ b/src/shader_recompiler/frontend/ir/value.cpp | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/frontend/ir/opcodes.h" | ||
| 6 | #include "shader_recompiler/frontend/ir/value.h" | 5 | #include "shader_recompiler/frontend/ir/value.h" |
| 7 | 6 | ||
| 8 | namespace Shader::IR { | 7 | namespace Shader::IR { |
diff --git a/src/shader_recompiler/frontend/ir/value.h b/src/shader_recompiler/frontend/ir/value.h index 947579852..14f6e55bc 100644 --- a/src/shader_recompiler/frontend/ir/value.h +++ b/src/shader_recompiler/frontend/ir/value.h | |||
| @@ -179,9 +179,13 @@ public: | |||
| 179 | 179 | ||
| 180 | /// Get a pointer to the block of a phi argument. | 180 | /// Get a pointer to the block of a phi argument. |
| 181 | [[nodiscard]] Block* PhiBlock(size_t index) const; | 181 | [[nodiscard]] Block* PhiBlock(size_t index) const; |
| 182 | |||
| 182 | /// Add phi operand to a phi instruction. | 183 | /// Add phi operand to a phi instruction. |
| 183 | void AddPhiOperand(Block* predecessor, const Value& value); | 184 | void AddPhiOperand(Block* predecessor, const Value& value); |
| 184 | 185 | ||
| 186 | // Erase the phi operand at the given index. | ||
| 187 | void ErasePhiOperand(size_t index); | ||
| 188 | |||
| 185 | /// Orders the Phi arguments from farthest away to nearest. | 189 | /// Orders the Phi arguments from farthest away to nearest. |
| 186 | void OrderPhiArgs(); | 190 | void OrderPhiArgs(); |
| 187 | 191 | ||
diff --git a/src/shader_recompiler/frontend/maxwell/control_flow.h b/src/shader_recompiler/frontend/maxwell/control_flow.h index a6bd3e196..7e91fac46 100644 --- a/src/shader_recompiler/frontend/maxwell/control_flow.h +++ b/src/shader_recompiler/frontend/maxwell/control_flow.h | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <compare> | ||
| 8 | #include <optional> | 7 | #include <optional> |
| 9 | #include <span> | 8 | #include <span> |
| 10 | #include <string> | 9 | #include <string> |
| @@ -15,6 +14,7 @@ | |||
| 15 | 14 | ||
| 16 | #include "shader_recompiler/environment.h" | 15 | #include "shader_recompiler/environment.h" |
| 17 | #include "shader_recompiler/frontend/ir/condition.h" | 16 | #include "shader_recompiler/frontend/ir/condition.h" |
| 17 | #include "shader_recompiler/frontend/ir/reg.h" | ||
| 18 | #include "shader_recompiler/frontend/maxwell/instruction.h" | 18 | #include "shader_recompiler/frontend/maxwell/instruction.h" |
| 19 | #include "shader_recompiler/frontend/maxwell/location.h" | 19 | #include "shader_recompiler/frontend/maxwell/location.h" |
| 20 | #include "shader_recompiler/frontend/maxwell/opcodes.h" | 20 | #include "shader_recompiler/frontend/maxwell/opcodes.h" |
diff --git a/src/shader_recompiler/frontend/maxwell/decode.cpp b/src/shader_recompiler/frontend/maxwell/decode.cpp index 972f677dc..e688e648b 100644 --- a/src/shader_recompiler/frontend/maxwell/decode.cpp +++ b/src/shader_recompiler/frontend/maxwell/decode.cpp | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <bit> | 7 | #include <bit> |
| 8 | #include <memory> | 8 | #include <memory> |
| 9 | #include <string_view> | ||
| 10 | 9 | ||
| 11 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 12 | #include "shader_recompiler/exception.h" | 11 | #include "shader_recompiler/exception.h" |
diff --git a/src/shader_recompiler/frontend/maxwell/indirect_branch_table_track.h b/src/shader_recompiler/frontend/maxwell/indirect_branch_table_track.h index eee5102fa..2a23f7abf 100644 --- a/src/shader_recompiler/frontend/maxwell/indirect_branch_table_track.h +++ b/src/shader_recompiler/frontend/maxwell/indirect_branch_table_track.h | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | #include <optional> | 7 | #include <optional> |
| 8 | 8 | ||
| 9 | #include "common/bit_field.h" | ||
| 10 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 11 | #include "shader_recompiler/environment.h" | 10 | #include "shader_recompiler/environment.h" |
| 12 | #include "shader_recompiler/frontend/ir/reg.h" | 11 | #include "shader_recompiler/frontend/ir/reg.h" |
diff --git a/src/shader_recompiler/frontend/maxwell/instruction.h b/src/shader_recompiler/frontend/maxwell/instruction.h index 743d68d61..57fd531f2 100644 --- a/src/shader_recompiler/frontend/maxwell/instruction.h +++ b/src/shader_recompiler/frontend/maxwell/instruction.h | |||
| @@ -7,7 +7,6 @@ | |||
| 7 | #include "common/bit_field.h" | 7 | #include "common/bit_field.h" |
| 8 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 9 | #include "shader_recompiler/frontend/ir/flow_test.h" | 9 | #include "shader_recompiler/frontend/ir/flow_test.h" |
| 10 | #include "shader_recompiler/frontend/ir/reg.h" | ||
| 11 | 10 | ||
| 12 | namespace Shader::Maxwell { | 11 | namespace Shader::Maxwell { |
| 13 | 12 | ||
diff --git a/src/shader_recompiler/frontend/maxwell/location.h b/src/shader_recompiler/frontend/maxwell/location.h index 26d29eae2..17107f082 100644 --- a/src/shader_recompiler/frontend/maxwell/location.h +++ b/src/shader_recompiler/frontend/maxwell/location.h | |||
| @@ -4,9 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <compare> | ||
| 8 | #include <iterator> | ||
| 9 | |||
| 10 | #include <fmt/format.h> | 7 | #include <fmt/format.h> |
| 11 | 8 | ||
| 12 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
diff --git a/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp b/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp index 69eeaa3e6..7bad628aa 100644 --- a/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp +++ b/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp | |||
| @@ -8,7 +8,6 @@ | |||
| 8 | #include <unordered_map> | 8 | #include <unordered_map> |
| 9 | #include <utility> | 9 | #include <utility> |
| 10 | #include <vector> | 10 | #include <vector> |
| 11 | #include <version> | ||
| 12 | 11 | ||
| 13 | #include <fmt/format.h> | 12 | #include <fmt/format.h> |
| 14 | 13 | ||
| @@ -17,7 +16,6 @@ | |||
| 17 | #include "shader_recompiler/environment.h" | 16 | #include "shader_recompiler/environment.h" |
| 18 | #include "shader_recompiler/frontend/ir/basic_block.h" | 17 | #include "shader_recompiler/frontend/ir/basic_block.h" |
| 19 | #include "shader_recompiler/frontend/ir/ir_emitter.h" | 18 | #include "shader_recompiler/frontend/ir/ir_emitter.h" |
| 20 | #include "shader_recompiler/frontend/maxwell/decode.h" | ||
| 21 | #include "shader_recompiler/frontend/maxwell/structured_control_flow.h" | 19 | #include "shader_recompiler/frontend/maxwell/structured_control_flow.h" |
| 22 | #include "shader_recompiler/frontend/maxwell/translate/translate.h" | 20 | #include "shader_recompiler/frontend/maxwell/translate/translate.h" |
| 23 | #include "shader_recompiler/host_translate_info.h" | 21 | #include "shader_recompiler/host_translate_info.h" |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/attribute_memory_to_physical.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/attribute_memory_to_physical.cpp index fb3f00d3f..d26d0982b 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/attribute_memory_to_physical.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/attribute_memory_to_physical.cpp | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "shader_recompiler/frontend/maxwell/opcodes.h" | ||
| 8 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 7 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 9 | 8 | ||
| 10 | namespace Shader::Maxwell { | 9 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/barrier_operations.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/barrier_operations.cpp index 86e433e41..d92d4e929 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/barrier_operations.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/barrier_operations.cpp | |||
| @@ -4,8 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "shader_recompiler/frontend/ir/modifiers.h" | ||
| 8 | #include "shader_recompiler/frontend/maxwell/opcodes.h" | ||
| 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 7 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 10 | 8 | ||
| 11 | namespace Shader::Maxwell { | 9 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/common_funcs.h b/src/shader_recompiler/frontend/maxwell/translate/impl/common_funcs.h index 214d0af3c..24f041a4f 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/common_funcs.h +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/common_funcs.h | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/common_types.h" | ||
| 8 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 7 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 9 | 8 | ||
| 10 | namespace Shader::Maxwell { | 9 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/exit_program.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/exit_program.cpp index c2443c886..62d20ebe4 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/exit_program.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/exit_program.cpp | |||
| @@ -3,7 +3,6 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/common_types.h" | 5 | #include "common/common_types.h" |
| 6 | #include "shader_recompiler/exception.h" | ||
| 7 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 6 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 8 | 7 | ||
| 9 | namespace Shader::Maxwell { | 8 | namespace Shader::Maxwell { |
| @@ -12,9 +11,13 @@ void ExitFragment(TranslatorVisitor& v) { | |||
| 12 | const ProgramHeader sph{v.env.SPH()}; | 11 | const ProgramHeader sph{v.env.SPH()}; |
| 13 | IR::Reg src_reg{IR::Reg::R0}; | 12 | IR::Reg src_reg{IR::Reg::R0}; |
| 14 | for (u32 render_target = 0; render_target < 8; ++render_target) { | 13 | for (u32 render_target = 0; render_target < 8; ++render_target) { |
| 14 | if (!sph.ps.HasOutputComponents(render_target)) { | ||
| 15 | continue; | ||
| 16 | } | ||
| 15 | const std::array<bool, 4> mask{sph.ps.EnabledOutputComponents(render_target)}; | 17 | const std::array<bool, 4> mask{sph.ps.EnabledOutputComponents(render_target)}; |
| 16 | for (u32 component = 0; component < 4; ++component) { | 18 | for (u32 component = 0; component < 4; ++component) { |
| 17 | if (!mask[component]) { | 19 | if (!mask[component]) { |
| 20 | ++src_reg; | ||
| 18 | continue; | 21 | continue; |
| 19 | } | 22 | } |
| 20 | v.ir.SetFragColor(render_target, component, v.F(src_reg)); | 23 | v.ir.SetFragColor(render_target, component, v.F(src_reg)); |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_multi_function.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_multi_function.cpp index 2f8605619..bb8512400 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_multi_function.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_multi_function.cpp | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "shader_recompiler/exception.h" | 7 | #include "shader_recompiler/exception.h" |
| 8 | #include "shader_recompiler/frontend/maxwell/opcodes.h" | ||
| 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 8 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 10 | 9 | ||
| 11 | namespace Shader::Maxwell { | 10 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.h b/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.h index 59da56a7e..c5e80a559 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.h +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.h | |||
| @@ -6,8 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "shader_recompiler/exception.h" | 8 | #include "shader_recompiler/exception.h" |
| 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/common_encoding.h" | ||
| 10 | #include "shader_recompiler/frontend/maxwell/translate/impl/common_funcs.h" | ||
| 11 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 12 | 10 | ||
| 13 | namespace Shader::Maxwell { | 11 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_set.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_set.cpp index cca5b831f..01bc9c49f 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_set.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_set.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/frontend/maxwell/translate/impl/common_funcs.h" | ||
| 5 | #include "shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.h" | 6 | #include "shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.h" |
| 6 | 7 | ||
| 7 | namespace Shader::Maxwell { | 8 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_set_predicate.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_set_predicate.cpp index b3931dae3..2b9c4fc0f 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_set_predicate.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_set_predicate.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "shader_recompiler/frontend/maxwell/translate/impl/common_funcs.h" | ||
| 5 | #include "shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.h" | 6 | #include "shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.h" |
| 6 | 7 | ||
| 7 | namespace Shader::Maxwell { | 8 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/load_constant.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/load_constant.cpp index 2300088e3..8007a4d46 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/load_constant.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/load_constant.cpp | |||
| @@ -11,10 +11,20 @@ namespace Shader::Maxwell { | |||
| 11 | using namespace LDC; | 11 | using namespace LDC; |
| 12 | namespace { | 12 | namespace { |
| 13 | std::pair<IR::U32, IR::U32> Slot(IR::IREmitter& ir, Mode mode, const IR::U32& imm_index, | 13 | std::pair<IR::U32, IR::U32> Slot(IR::IREmitter& ir, Mode mode, const IR::U32& imm_index, |
| 14 | const IR::U32& reg, const IR::U32& imm) { | 14 | const IR::U32& reg, const IR::U32& imm_offset) { |
| 15 | switch (mode) { | 15 | switch (mode) { |
| 16 | case Mode::Default: | 16 | case Mode::Default: |
| 17 | return {imm_index, ir.IAdd(reg, imm)}; | 17 | return {imm_index, ir.IAdd(reg, imm_offset)}; |
| 18 | case Mode::IS: { | ||
| 19 | // Segmented addressing mode | ||
| 20 | // Ra+imm_offset points into a flat mapping of const buffer | ||
| 21 | // address space | ||
| 22 | const IR::U32 address{ir.IAdd(reg, imm_offset)}; | ||
| 23 | const IR::U32 index{ir.BitFieldExtract(address, ir.Imm32(16), ir.Imm32(16))}; | ||
| 24 | const IR::U32 offset{ir.BitFieldExtract(address, ir.Imm32(0), ir.Imm32(16))}; | ||
| 25 | |||
| 26 | return {ir.IAdd(index, imm_index), offset}; | ||
| 27 | } | ||
| 18 | default: | 28 | default: |
| 19 | break; | 29 | break; |
| 20 | } | 30 | } |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_attribute.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_attribute.cpp index 924fb7a40..00d1d8438 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_attribute.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_attribute.cpp | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "shader_recompiler/exception.h" | 7 | #include "shader_recompiler/exception.h" |
| 8 | #include "shader_recompiler/frontend/ir/ir_emitter.h" | 8 | #include "shader_recompiler/frontend/ir/ir_emitter.h" |
| 9 | #include "shader_recompiler/frontend/maxwell/opcodes.h" | ||
| 10 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 11 | 10 | ||
| 12 | namespace Shader::Maxwell { | 11 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_memory.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_memory.cpp index 36c5cff2f..4792cd4a5 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_memory.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_memory.cpp | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "shader_recompiler/exception.h" | 7 | #include "shader_recompiler/exception.h" |
| 8 | #include "shader_recompiler/frontend/maxwell/opcodes.h" | ||
| 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 8 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 10 | 9 | ||
| 11 | namespace Shader::Maxwell { | 10 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/logic_operation_three_input.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/logic_operation_three_input.cpp index e0fe47912..f3c7ceb57 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/logic_operation_three_input.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/logic_operation_three_input.cpp | |||
| @@ -13,59 +13,535 @@ namespace { | |||
| 13 | // Emulate GPU's LOP3.LUT (three-input logic op with 8-bit truth table) | 13 | // Emulate GPU's LOP3.LUT (three-input logic op with 8-bit truth table) |
| 14 | IR::U32 ApplyLUT(IR::IREmitter& ir, const IR::U32& a, const IR::U32& b, const IR::U32& c, | 14 | IR::U32 ApplyLUT(IR::IREmitter& ir, const IR::U32& a, const IR::U32& b, const IR::U32& c, |
| 15 | u64 ttbl) { | 15 | u64 ttbl) { |
| 16 | IR::U32 r{ir.Imm32(0)}; | 16 | switch (ttbl) { |
| 17 | const IR::U32 not_a{ir.BitwiseNot(a)}; | 17 | // generated code, do not edit manually |
| 18 | const IR::U32 not_b{ir.BitwiseNot(b)}; | 18 | case 0: |
| 19 | const IR::U32 not_c{ir.BitwiseNot(c)}; | 19 | return ir.Imm32(0); |
| 20 | if (ttbl & 0x01) { | 20 | case 1: |
| 21 | // r |= ~a & ~b & ~c; | 21 | return ir.BitwiseNot(ir.BitwiseOr(a, ir.BitwiseOr(b, c))); |
| 22 | const auto lhs{ir.BitwiseAnd(not_a, not_b)}; | 22 | case 2: |
| 23 | const auto rhs{ir.BitwiseAnd(lhs, not_c)}; | 23 | return ir.BitwiseAnd(c, ir.BitwiseNot(ir.BitwiseOr(a, b))); |
| 24 | r = ir.BitwiseOr(r, rhs); | 24 | case 3: |
| 25 | return ir.BitwiseNot(ir.BitwiseOr(a, b)); | ||
| 26 | case 4: | ||
| 27 | return ir.BitwiseAnd(b, ir.BitwiseNot(ir.BitwiseOr(a, c))); | ||
| 28 | case 5: | ||
| 29 | return ir.BitwiseNot(ir.BitwiseOr(a, c)); | ||
| 30 | case 6: | ||
| 31 | return ir.BitwiseAnd(ir.BitwiseNot(a), ir.BitwiseXor(b, c)); | ||
| 32 | case 7: | ||
| 33 | return ir.BitwiseNot(ir.BitwiseOr(a, ir.BitwiseAnd(b, c))); | ||
| 34 | case 8: | ||
| 35 | return ir.BitwiseAnd(ir.BitwiseAnd(b, c), ir.BitwiseNot(a)); | ||
| 36 | case 9: | ||
| 37 | return ir.BitwiseNot(ir.BitwiseOr(a, ir.BitwiseXor(b, c))); | ||
| 38 | case 10: | ||
| 39 | return ir.BitwiseAnd(c, ir.BitwiseNot(a)); | ||
| 40 | case 11: | ||
| 41 | return ir.BitwiseAnd(ir.BitwiseNot(a), ir.BitwiseOr(c, ir.BitwiseNot(b))); | ||
| 42 | case 12: | ||
| 43 | return ir.BitwiseAnd(b, ir.BitwiseNot(a)); | ||
| 44 | case 13: | ||
| 45 | return ir.BitwiseAnd(ir.BitwiseNot(a), ir.BitwiseOr(b, ir.BitwiseNot(c))); | ||
| 46 | case 14: | ||
| 47 | return ir.BitwiseAnd(ir.BitwiseNot(a), ir.BitwiseOr(b, c)); | ||
| 48 | case 15: | ||
| 49 | return ir.BitwiseNot(a); | ||
| 50 | case 16: | ||
| 51 | return ir.BitwiseAnd(a, ir.BitwiseNot(ir.BitwiseOr(b, c))); | ||
| 52 | case 17: | ||
| 53 | return ir.BitwiseNot(ir.BitwiseOr(b, c)); | ||
| 54 | case 18: | ||
| 55 | return ir.BitwiseAnd(ir.BitwiseNot(b), ir.BitwiseXor(a, c)); | ||
| 56 | case 19: | ||
| 57 | return ir.BitwiseNot(ir.BitwiseOr(b, ir.BitwiseAnd(a, c))); | ||
| 58 | case 20: | ||
| 59 | return ir.BitwiseAnd(ir.BitwiseNot(c), ir.BitwiseXor(a, b)); | ||
| 60 | case 21: | ||
| 61 | return ir.BitwiseNot(ir.BitwiseOr(c, ir.BitwiseAnd(a, b))); | ||
| 62 | case 22: | ||
| 63 | return ir.BitwiseXor(ir.BitwiseOr(a, b), ir.BitwiseOr(c, ir.BitwiseAnd(a, b))); | ||
| 64 | case 23: | ||
| 65 | return ir.BitwiseXor(ir.BitwiseAnd(ir.BitwiseXor(a, b), ir.BitwiseXor(a, c)), | ||
| 66 | ir.BitwiseNot(a)); | ||
| 67 | case 24: | ||
| 68 | return ir.BitwiseAnd(ir.BitwiseXor(a, b), ir.BitwiseXor(a, c)); | ||
| 69 | case 25: | ||
| 70 | return ir.BitwiseNot(ir.BitwiseOr(ir.BitwiseAnd(a, b), ir.BitwiseXor(b, c))); | ||
| 71 | case 26: | ||
| 72 | return ir.BitwiseAnd(ir.BitwiseOr(c, ir.BitwiseNot(b)), ir.BitwiseXor(a, c)); | ||
| 73 | case 27: | ||
| 74 | return ir.BitwiseXor(ir.BitwiseOr(a, ir.BitwiseNot(c)), ir.BitwiseOr(b, c)); | ||
| 75 | case 28: | ||
| 76 | return ir.BitwiseAnd(ir.BitwiseOr(b, ir.BitwiseNot(c)), ir.BitwiseXor(a, b)); | ||
| 77 | case 29: | ||
| 78 | return ir.BitwiseXor(ir.BitwiseOr(a, ir.BitwiseNot(b)), ir.BitwiseOr(b, c)); | ||
| 79 | case 30: | ||
| 80 | return ir.BitwiseXor(a, ir.BitwiseOr(b, c)); | ||
| 81 | case 31: | ||
| 82 | return ir.BitwiseNot(ir.BitwiseAnd(a, ir.BitwiseOr(b, c))); | ||
| 83 | case 32: | ||
| 84 | return ir.BitwiseAnd(ir.BitwiseAnd(a, c), ir.BitwiseNot(b)); | ||
| 85 | case 33: | ||
| 86 | return ir.BitwiseNot(ir.BitwiseOr(b, ir.BitwiseXor(a, c))); | ||
| 87 | case 34: | ||
| 88 | return ir.BitwiseAnd(c, ir.BitwiseNot(b)); | ||
| 89 | case 35: | ||
| 90 | return ir.BitwiseAnd(ir.BitwiseNot(b), ir.BitwiseOr(c, ir.BitwiseNot(a))); | ||
| 91 | case 36: | ||
| 92 | return ir.BitwiseAnd(ir.BitwiseXor(a, b), ir.BitwiseXor(b, c)); | ||
| 93 | case 37: | ||
| 94 | return ir.BitwiseNot(ir.BitwiseOr(ir.BitwiseAnd(a, b), ir.BitwiseXor(a, c))); | ||
| 95 | case 38: | ||
| 96 | return ir.BitwiseAnd(ir.BitwiseOr(c, ir.BitwiseNot(a)), ir.BitwiseXor(b, c)); | ||
| 97 | case 39: | ||
| 98 | return ir.BitwiseXor(ir.BitwiseOr(a, c), ir.BitwiseOr(b, ir.BitwiseNot(c))); | ||
| 99 | case 40: | ||
| 100 | return ir.BitwiseAnd(c, ir.BitwiseXor(a, b)); | ||
| 101 | case 41: | ||
| 102 | return ir.BitwiseXor(ir.BitwiseOr(a, b), | ||
| 103 | ir.BitwiseOr(ir.BitwiseAnd(a, b), ir.BitwiseNot(c))); | ||
| 104 | case 42: | ||
| 105 | return ir.BitwiseAnd(c, ir.BitwiseNot(ir.BitwiseAnd(a, b))); | ||
| 106 | case 43: | ||
| 107 | return ir.BitwiseXor(ir.BitwiseOr(a, ir.BitwiseNot(c)), | ||
| 108 | ir.BitwiseOr(b, ir.BitwiseXor(a, c))); | ||
| 109 | case 44: | ||
| 110 | return ir.BitwiseAnd(ir.BitwiseOr(b, c), ir.BitwiseXor(a, b)); | ||
| 111 | case 45: | ||
| 112 | return ir.BitwiseXor(a, ir.BitwiseOr(b, ir.BitwiseNot(c))); | ||
| 113 | case 46: | ||
| 114 | return ir.BitwiseXor(ir.BitwiseAnd(a, b), ir.BitwiseOr(b, c)); | ||
| 115 | case 47: | ||
| 116 | return ir.BitwiseOr(ir.BitwiseAnd(c, ir.BitwiseNot(b)), ir.BitwiseNot(a)); | ||
| 117 | case 48: | ||
| 118 | return ir.BitwiseAnd(a, ir.BitwiseNot(b)); | ||
| 119 | case 49: | ||
| 120 | return ir.BitwiseAnd(ir.BitwiseNot(b), ir.BitwiseOr(a, ir.BitwiseNot(c))); | ||
| 121 | case 50: | ||
| 122 | return ir.BitwiseAnd(ir.BitwiseNot(b), ir.BitwiseOr(a, c)); | ||
| 123 | case 51: | ||
| 124 | return ir.BitwiseNot(b); | ||
| 125 | case 52: | ||
| 126 | return ir.BitwiseAnd(ir.BitwiseOr(a, ir.BitwiseNot(c)), ir.BitwiseXor(a, b)); | ||
| 127 | case 53: | ||
| 128 | return ir.BitwiseXor(ir.BitwiseOr(a, c), ir.BitwiseOr(b, ir.BitwiseNot(a))); | ||
| 129 | case 54: | ||
| 130 | return ir.BitwiseXor(b, ir.BitwiseOr(a, c)); | ||
| 131 | case 55: | ||
| 132 | return ir.BitwiseNot(ir.BitwiseAnd(b, ir.BitwiseOr(a, c))); | ||
| 133 | case 56: | ||
| 134 | return ir.BitwiseAnd(ir.BitwiseOr(a, c), ir.BitwiseXor(a, b)); | ||
| 135 | case 57: | ||
| 136 | return ir.BitwiseXor(b, ir.BitwiseOr(a, ir.BitwiseNot(c))); | ||
| 137 | case 58: | ||
| 138 | return ir.BitwiseXor(ir.BitwiseAnd(a, b), ir.BitwiseOr(a, c)); | ||
| 139 | case 59: | ||
| 140 | return ir.BitwiseOr(ir.BitwiseAnd(c, ir.BitwiseNot(a)), ir.BitwiseNot(b)); | ||
| 141 | case 60: | ||
| 142 | return ir.BitwiseXor(a, b); | ||
| 143 | case 61: | ||
| 144 | return ir.BitwiseOr(ir.BitwiseNot(ir.BitwiseOr(a, c)), ir.BitwiseXor(a, b)); | ||
| 145 | case 62: | ||
| 146 | return ir.BitwiseOr(ir.BitwiseAnd(c, ir.BitwiseNot(a)), ir.BitwiseXor(a, b)); | ||
| 147 | case 63: | ||
| 148 | return ir.BitwiseNot(ir.BitwiseAnd(a, b)); | ||
| 149 | case 64: | ||
| 150 | return ir.BitwiseAnd(ir.BitwiseAnd(a, b), ir.BitwiseNot(c)); | ||
| 151 | case 65: | ||
| 152 | return ir.BitwiseNot(ir.BitwiseOr(c, ir.BitwiseXor(a, b))); | ||
| 153 | case 66: | ||
| 154 | return ir.BitwiseAnd(ir.BitwiseXor(a, c), ir.BitwiseXor(b, c)); | ||
| 155 | case 67: | ||
| 156 | return ir.BitwiseNot(ir.BitwiseOr(ir.BitwiseAnd(a, c), ir.BitwiseXor(a, b))); | ||
| 157 | case 68: | ||
| 158 | return ir.BitwiseAnd(b, ir.BitwiseNot(c)); | ||
| 159 | case 69: | ||
| 160 | return ir.BitwiseAnd(ir.BitwiseNot(c), ir.BitwiseOr(b, ir.BitwiseNot(a))); | ||
| 161 | case 70: | ||
| 162 | return ir.BitwiseAnd(ir.BitwiseOr(b, ir.BitwiseNot(a)), ir.BitwiseXor(b, c)); | ||
| 163 | case 71: | ||
| 164 | return ir.BitwiseXor(ir.BitwiseOr(a, b), ir.BitwiseOr(c, ir.BitwiseNot(b))); | ||
| 165 | case 72: | ||
| 166 | return ir.BitwiseAnd(b, ir.BitwiseXor(a, c)); | ||
| 167 | case 73: | ||
| 168 | return ir.BitwiseXor(ir.BitwiseOr(a, c), | ||
| 169 | ir.BitwiseOr(ir.BitwiseAnd(a, c), ir.BitwiseNot(b))); | ||
| 170 | case 74: | ||
| 171 | return ir.BitwiseAnd(ir.BitwiseOr(b, c), ir.BitwiseXor(a, c)); | ||
| 172 | case 75: | ||
| 173 | return ir.BitwiseXor(a, ir.BitwiseOr(c, ir.BitwiseNot(b))); | ||
| 174 | case 76: | ||
| 175 | return ir.BitwiseAnd(b, ir.BitwiseNot(ir.BitwiseAnd(a, c))); | ||
| 176 | case 77: | ||
| 177 | return ir.BitwiseXor(ir.BitwiseOr(a, ir.BitwiseNot(b)), | ||
| 178 | ir.BitwiseOr(c, ir.BitwiseXor(a, b))); | ||
| 179 | case 78: | ||
| 180 | return ir.BitwiseXor(ir.BitwiseAnd(a, c), ir.BitwiseOr(b, c)); | ||
| 181 | case 79: | ||
| 182 | return ir.BitwiseOr(ir.BitwiseAnd(b, ir.BitwiseNot(c)), ir.BitwiseNot(a)); | ||
| 183 | case 80: | ||
| 184 | return ir.BitwiseAnd(a, ir.BitwiseNot(c)); | ||
| 185 | case 81: | ||
| 186 | return ir.BitwiseAnd(ir.BitwiseNot(c), ir.BitwiseOr(a, ir.BitwiseNot(b))); | ||
| 187 | case 82: | ||
| 188 | return ir.BitwiseAnd(ir.BitwiseOr(a, ir.BitwiseNot(b)), ir.BitwiseXor(a, c)); | ||
| 189 | case 83: | ||
| 190 | return ir.BitwiseXor(ir.BitwiseOr(a, b), ir.BitwiseOr(c, ir.BitwiseNot(a))); | ||
| 191 | case 84: | ||
| 192 | return ir.BitwiseAnd(ir.BitwiseNot(c), ir.BitwiseOr(a, b)); | ||
| 193 | case 85: | ||
| 194 | return ir.BitwiseNot(c); | ||
| 195 | case 86: | ||
| 196 | return ir.BitwiseXor(c, ir.BitwiseOr(a, b)); | ||
| 197 | case 87: | ||
| 198 | return ir.BitwiseNot(ir.BitwiseAnd(c, ir.BitwiseOr(a, b))); | ||
| 199 | case 88: | ||
| 200 | return ir.BitwiseAnd(ir.BitwiseOr(a, b), ir.BitwiseXor(a, c)); | ||
| 201 | case 89: | ||
| 202 | return ir.BitwiseXor(c, ir.BitwiseOr(a, ir.BitwiseNot(b))); | ||
| 203 | case 90: | ||
| 204 | return ir.BitwiseXor(a, c); | ||
| 205 | case 91: | ||
| 206 | return ir.BitwiseOr(ir.BitwiseNot(ir.BitwiseOr(a, b)), ir.BitwiseXor(a, c)); | ||
| 207 | case 92: | ||
| 208 | return ir.BitwiseXor(ir.BitwiseAnd(a, c), ir.BitwiseOr(a, b)); | ||
| 209 | case 93: | ||
| 210 | return ir.BitwiseOr(ir.BitwiseAnd(b, ir.BitwiseNot(a)), ir.BitwiseNot(c)); | ||
| 211 | case 94: | ||
| 212 | return ir.BitwiseOr(ir.BitwiseAnd(b, ir.BitwiseNot(a)), ir.BitwiseXor(a, c)); | ||
| 213 | case 95: | ||
| 214 | return ir.BitwiseNot(ir.BitwiseAnd(a, c)); | ||
| 215 | case 96: | ||
| 216 | return ir.BitwiseAnd(a, ir.BitwiseXor(b, c)); | ||
| 217 | case 97: | ||
| 218 | return ir.BitwiseXor(ir.BitwiseOr(b, c), | ||
| 219 | ir.BitwiseOr(ir.BitwiseAnd(b, c), ir.BitwiseNot(a))); | ||
| 220 | case 98: | ||
| 221 | return ir.BitwiseAnd(ir.BitwiseOr(a, c), ir.BitwiseXor(b, c)); | ||
| 222 | case 99: | ||
| 223 | return ir.BitwiseXor(b, ir.BitwiseOr(c, ir.BitwiseNot(a))); | ||
| 224 | case 100: | ||
| 225 | return ir.BitwiseAnd(ir.BitwiseOr(a, b), ir.BitwiseXor(b, c)); | ||
| 226 | case 101: | ||
| 227 | return ir.BitwiseXor(c, ir.BitwiseOr(b, ir.BitwiseNot(a))); | ||
| 228 | case 102: | ||
| 229 | return ir.BitwiseXor(b, c); | ||
| 230 | case 103: | ||
| 231 | return ir.BitwiseOr(ir.BitwiseNot(ir.BitwiseOr(a, b)), ir.BitwiseXor(b, c)); | ||
| 232 | case 104: | ||
| 233 | return ir.BitwiseAnd(ir.BitwiseOr(a, b), ir.BitwiseXor(c, ir.BitwiseAnd(a, b))); | ||
| 234 | case 105: | ||
| 235 | return ir.BitwiseXor(ir.BitwiseNot(a), ir.BitwiseXor(b, c)); | ||
| 236 | case 106: | ||
| 237 | return ir.BitwiseXor(c, ir.BitwiseAnd(a, b)); | ||
| 238 | case 107: | ||
| 239 | return ir.BitwiseXor(ir.BitwiseAnd(c, ir.BitwiseOr(a, b)), | ||
| 240 | ir.BitwiseXor(a, ir.BitwiseNot(b))); | ||
| 241 | case 108: | ||
| 242 | return ir.BitwiseXor(b, ir.BitwiseAnd(a, c)); | ||
| 243 | case 109: | ||
| 244 | return ir.BitwiseXor(ir.BitwiseAnd(b, ir.BitwiseOr(a, c)), | ||
| 245 | ir.BitwiseXor(a, ir.BitwiseNot(c))); | ||
| 246 | case 110: | ||
| 247 | return ir.BitwiseOr(ir.BitwiseAnd(b, ir.BitwiseNot(a)), ir.BitwiseXor(b, c)); | ||
| 248 | case 111: | ||
| 249 | return ir.BitwiseOr(ir.BitwiseNot(a), ir.BitwiseXor(b, c)); | ||
| 250 | case 112: | ||
| 251 | return ir.BitwiseAnd(a, ir.BitwiseNot(ir.BitwiseAnd(b, c))); | ||
| 252 | case 113: | ||
| 253 | return ir.BitwiseXor(ir.BitwiseOr(b, ir.BitwiseNot(a)), | ||
| 254 | ir.BitwiseOr(c, ir.BitwiseXor(a, b))); | ||
| 255 | case 114: | ||
| 256 | return ir.BitwiseXor(ir.BitwiseAnd(b, c), ir.BitwiseOr(a, c)); | ||
| 257 | case 115: | ||
| 258 | return ir.BitwiseOr(ir.BitwiseAnd(a, ir.BitwiseNot(c)), ir.BitwiseNot(b)); | ||
| 259 | case 116: | ||
| 260 | return ir.BitwiseXor(ir.BitwiseAnd(b, c), ir.BitwiseOr(a, b)); | ||
| 261 | case 117: | ||
| 262 | return ir.BitwiseOr(ir.BitwiseAnd(a, ir.BitwiseNot(b)), ir.BitwiseNot(c)); | ||
| 263 | case 118: | ||
| 264 | return ir.BitwiseOr(ir.BitwiseAnd(a, ir.BitwiseNot(b)), ir.BitwiseXor(b, c)); | ||
| 265 | case 119: | ||
| 266 | return ir.BitwiseNot(ir.BitwiseAnd(b, c)); | ||
| 267 | case 120: | ||
| 268 | return ir.BitwiseXor(a, ir.BitwiseAnd(b, c)); | ||
| 269 | case 121: | ||
| 270 | return ir.BitwiseXor(ir.BitwiseAnd(a, ir.BitwiseOr(b, c)), | ||
| 271 | ir.BitwiseXor(b, ir.BitwiseNot(c))); | ||
| 272 | case 122: | ||
| 273 | return ir.BitwiseOr(ir.BitwiseAnd(a, ir.BitwiseNot(b)), ir.BitwiseXor(a, c)); | ||
| 274 | case 123: | ||
| 275 | return ir.BitwiseOr(ir.BitwiseNot(b), ir.BitwiseXor(a, c)); | ||
| 276 | case 124: | ||
| 277 | return ir.BitwiseOr(ir.BitwiseAnd(a, ir.BitwiseNot(c)), ir.BitwiseXor(a, b)); | ||
| 278 | case 125: | ||
| 279 | return ir.BitwiseOr(ir.BitwiseNot(c), ir.BitwiseXor(a, b)); | ||
| 280 | case 126: | ||
| 281 | return ir.BitwiseOr(ir.BitwiseXor(a, b), ir.BitwiseXor(a, c)); | ||
| 282 | case 127: | ||
| 283 | return ir.BitwiseNot(ir.BitwiseAnd(a, ir.BitwiseAnd(b, c))); | ||
| 284 | case 128: | ||
| 285 | return ir.BitwiseAnd(a, ir.BitwiseAnd(b, c)); | ||
| 286 | case 129: | ||
| 287 | return ir.BitwiseNot(ir.BitwiseOr(ir.BitwiseXor(a, b), ir.BitwiseXor(a, c))); | ||
| 288 | case 130: | ||
| 289 | return ir.BitwiseAnd(c, ir.BitwiseXor(a, ir.BitwiseNot(b))); | ||
| 290 | case 131: | ||
| 291 | return ir.BitwiseAnd(ir.BitwiseOr(c, ir.BitwiseNot(a)), ir.BitwiseXor(a, ir.BitwiseNot(b))); | ||
| 292 | case 132: | ||
| 293 | return ir.BitwiseAnd(b, ir.BitwiseXor(a, ir.BitwiseNot(c))); | ||
| 294 | case 133: | ||
| 295 | return ir.BitwiseAnd(ir.BitwiseOr(b, ir.BitwiseNot(a)), ir.BitwiseXor(a, ir.BitwiseNot(c))); | ||
| 296 | case 134: | ||
| 297 | return ir.BitwiseAnd(ir.BitwiseOr(b, c), ir.BitwiseXor(a, ir.BitwiseXor(b, c))); | ||
| 298 | case 135: | ||
| 299 | return ir.BitwiseXor(ir.BitwiseAnd(b, c), ir.BitwiseNot(a)); | ||
| 300 | case 136: | ||
| 301 | return ir.BitwiseAnd(b, c); | ||
| 302 | case 137: | ||
| 303 | return ir.BitwiseAnd(ir.BitwiseOr(b, ir.BitwiseNot(a)), ir.BitwiseXor(b, ir.BitwiseNot(c))); | ||
| 304 | case 138: | ||
| 305 | return ir.BitwiseAnd(c, ir.BitwiseOr(b, ir.BitwiseNot(a))); | ||
| 306 | case 139: | ||
| 307 | return ir.BitwiseOr(ir.BitwiseAnd(b, c), ir.BitwiseNot(ir.BitwiseOr(a, b))); | ||
| 308 | case 140: | ||
| 309 | return ir.BitwiseAnd(b, ir.BitwiseOr(c, ir.BitwiseNot(a))); | ||
| 310 | case 141: | ||
| 311 | return ir.BitwiseOr(ir.BitwiseAnd(b, c), ir.BitwiseNot(ir.BitwiseOr(a, c))); | ||
| 312 | case 142: | ||
| 313 | return ir.BitwiseXor(a, ir.BitwiseOr(ir.BitwiseXor(a, b), ir.BitwiseXor(a, c))); | ||
| 314 | case 143: | ||
| 315 | return ir.BitwiseOr(ir.BitwiseAnd(b, c), ir.BitwiseNot(a)); | ||
| 316 | case 144: | ||
| 317 | return ir.BitwiseAnd(a, ir.BitwiseXor(b, ir.BitwiseNot(c))); | ||
| 318 | case 145: | ||
| 319 | return ir.BitwiseAnd(ir.BitwiseOr(a, ir.BitwiseNot(b)), ir.BitwiseXor(b, ir.BitwiseNot(c))); | ||
| 320 | case 146: | ||
| 321 | return ir.BitwiseAnd(ir.BitwiseOr(a, c), ir.BitwiseXor(a, ir.BitwiseXor(b, c))); | ||
| 322 | case 147: | ||
| 323 | return ir.BitwiseXor(ir.BitwiseAnd(a, c), ir.BitwiseNot(b)); | ||
| 324 | case 148: | ||
| 325 | return ir.BitwiseAnd(ir.BitwiseOr(a, b), ir.BitwiseXor(a, ir.BitwiseXor(b, c))); | ||
| 326 | case 149: | ||
| 327 | return ir.BitwiseXor(ir.BitwiseAnd(a, b), ir.BitwiseNot(c)); | ||
| 328 | case 150: | ||
| 329 | return ir.BitwiseXor(a, ir.BitwiseXor(b, c)); | ||
| 330 | case 151: | ||
| 331 | return ir.BitwiseOr(ir.BitwiseNot(ir.BitwiseOr(a, b)), | ||
| 332 | ir.BitwiseXor(a, ir.BitwiseXor(b, c))); | ||
| 333 | case 152: | ||
| 334 | return ir.BitwiseAnd(ir.BitwiseOr(a, b), ir.BitwiseXor(b, ir.BitwiseNot(c))); | ||
| 335 | case 153: | ||
| 336 | return ir.BitwiseXor(b, ir.BitwiseNot(c)); | ||
| 337 | case 154: | ||
| 338 | return ir.BitwiseXor(c, ir.BitwiseAnd(a, ir.BitwiseNot(b))); | ||
| 339 | case 155: | ||
| 340 | return ir.BitwiseNot(ir.BitwiseAnd(ir.BitwiseOr(a, b), ir.BitwiseXor(b, c))); | ||
| 341 | case 156: | ||
| 342 | return ir.BitwiseXor(b, ir.BitwiseAnd(a, ir.BitwiseNot(c))); | ||
| 343 | case 157: | ||
| 344 | return ir.BitwiseNot(ir.BitwiseAnd(ir.BitwiseOr(a, c), ir.BitwiseXor(b, c))); | ||
| 345 | case 158: | ||
| 346 | return ir.BitwiseOr(ir.BitwiseAnd(b, c), ir.BitwiseXor(a, ir.BitwiseOr(b, c))); | ||
| 347 | case 159: | ||
| 348 | return ir.BitwiseNot(ir.BitwiseAnd(a, ir.BitwiseXor(b, c))); | ||
| 349 | case 160: | ||
| 350 | return ir.BitwiseAnd(a, c); | ||
| 351 | case 161: | ||
| 352 | return ir.BitwiseAnd(ir.BitwiseOr(a, ir.BitwiseNot(b)), ir.BitwiseXor(a, ir.BitwiseNot(c))); | ||
| 353 | case 162: | ||
| 354 | return ir.BitwiseAnd(c, ir.BitwiseOr(a, ir.BitwiseNot(b))); | ||
| 355 | case 163: | ||
| 356 | return ir.BitwiseOr(ir.BitwiseAnd(a, c), ir.BitwiseNot(ir.BitwiseOr(a, b))); | ||
| 357 | case 164: | ||
| 358 | return ir.BitwiseAnd(ir.BitwiseOr(a, b), ir.BitwiseXor(a, ir.BitwiseNot(c))); | ||
| 359 | case 165: | ||
| 360 | return ir.BitwiseXor(a, ir.BitwiseNot(c)); | ||
| 361 | case 166: | ||
| 362 | return ir.BitwiseXor(c, ir.BitwiseAnd(b, ir.BitwiseNot(a))); | ||
| 363 | case 167: | ||
| 364 | return ir.BitwiseNot(ir.BitwiseAnd(ir.BitwiseOr(a, b), ir.BitwiseXor(a, c))); | ||
| 365 | case 168: | ||
| 366 | return ir.BitwiseAnd(c, ir.BitwiseOr(a, b)); | ||
| 367 | case 169: | ||
| 368 | return ir.BitwiseXor(ir.BitwiseNot(c), ir.BitwiseOr(a, b)); | ||
| 369 | case 170: | ||
| 370 | return c; | ||
| 371 | case 171: | ||
| 372 | return ir.BitwiseOr(c, ir.BitwiseNot(ir.BitwiseOr(a, b))); | ||
| 373 | case 172: | ||
| 374 | return ir.BitwiseAnd(ir.BitwiseOr(a, b), ir.BitwiseOr(c, ir.BitwiseNot(a))); | ||
| 375 | case 173: | ||
| 376 | return ir.BitwiseOr(ir.BitwiseAnd(b, c), ir.BitwiseXor(a, ir.BitwiseNot(c))); | ||
| 377 | case 174: | ||
| 378 | return ir.BitwiseOr(c, ir.BitwiseAnd(b, ir.BitwiseNot(a))); | ||
| 379 | case 175: | ||
| 380 | return ir.BitwiseOr(c, ir.BitwiseNot(a)); | ||
| 381 | case 176: | ||
| 382 | return ir.BitwiseAnd(a, ir.BitwiseOr(c, ir.BitwiseNot(b))); | ||
| 383 | case 177: | ||
| 384 | return ir.BitwiseOr(ir.BitwiseAnd(a, c), ir.BitwiseNot(ir.BitwiseOr(b, c))); | ||
| 385 | case 178: | ||
| 386 | return ir.BitwiseXor(b, ir.BitwiseOr(ir.BitwiseXor(a, b), ir.BitwiseXor(a, c))); | ||
| 387 | case 179: | ||
| 388 | return ir.BitwiseOr(ir.BitwiseAnd(a, c), ir.BitwiseNot(b)); | ||
| 389 | case 180: | ||
| 390 | return ir.BitwiseXor(a, ir.BitwiseAnd(b, ir.BitwiseNot(c))); | ||
| 391 | case 181: | ||
| 392 | return ir.BitwiseNot(ir.BitwiseAnd(ir.BitwiseOr(b, c), ir.BitwiseXor(a, c))); | ||
| 393 | case 182: | ||
| 394 | return ir.BitwiseOr(ir.BitwiseAnd(a, c), ir.BitwiseXor(b, ir.BitwiseOr(a, c))); | ||
| 395 | case 183: | ||
| 396 | return ir.BitwiseNot(ir.BitwiseAnd(b, ir.BitwiseXor(a, c))); | ||
| 397 | case 184: | ||
| 398 | return ir.BitwiseAnd(ir.BitwiseOr(a, b), ir.BitwiseOr(c, ir.BitwiseNot(b))); | ||
| 399 | case 185: | ||
| 400 | return ir.BitwiseOr(ir.BitwiseAnd(a, c), ir.BitwiseXor(b, ir.BitwiseNot(c))); | ||
| 401 | case 186: | ||
| 402 | return ir.BitwiseOr(c, ir.BitwiseAnd(a, ir.BitwiseNot(b))); | ||
| 403 | case 187: | ||
| 404 | return ir.BitwiseOr(c, ir.BitwiseNot(b)); | ||
| 405 | case 188: | ||
| 406 | return ir.BitwiseOr(ir.BitwiseAnd(a, c), ir.BitwiseXor(a, b)); | ||
| 407 | case 189: | ||
| 408 | return ir.BitwiseOr(ir.BitwiseXor(a, b), ir.BitwiseXor(a, ir.BitwiseNot(c))); | ||
| 409 | case 190: | ||
| 410 | return ir.BitwiseOr(c, ir.BitwiseXor(a, b)); | ||
| 411 | case 191: | ||
| 412 | return ir.BitwiseOr(c, ir.BitwiseNot(ir.BitwiseAnd(a, b))); | ||
| 413 | case 192: | ||
| 414 | return ir.BitwiseAnd(a, b); | ||
| 415 | case 193: | ||
| 416 | return ir.BitwiseAnd(ir.BitwiseOr(a, ir.BitwiseNot(c)), ir.BitwiseXor(a, ir.BitwiseNot(b))); | ||
| 417 | case 194: | ||
| 418 | return ir.BitwiseAnd(ir.BitwiseOr(a, c), ir.BitwiseXor(a, ir.BitwiseNot(b))); | ||
| 419 | case 195: | ||
| 420 | return ir.BitwiseXor(a, ir.BitwiseNot(b)); | ||
| 421 | case 196: | ||
| 422 | return ir.BitwiseAnd(b, ir.BitwiseOr(a, ir.BitwiseNot(c))); | ||
| 423 | case 197: | ||
| 424 | return ir.BitwiseOr(ir.BitwiseAnd(a, b), ir.BitwiseNot(ir.BitwiseOr(a, c))); | ||
| 425 | case 198: | ||
| 426 | return ir.BitwiseXor(b, ir.BitwiseAnd(c, ir.BitwiseNot(a))); | ||
| 427 | case 199: | ||
| 428 | return ir.BitwiseNot(ir.BitwiseAnd(ir.BitwiseOr(a, c), ir.BitwiseXor(a, b))); | ||
| 429 | case 200: | ||
| 430 | return ir.BitwiseAnd(b, ir.BitwiseOr(a, c)); | ||
| 431 | case 201: | ||
| 432 | return ir.BitwiseXor(ir.BitwiseNot(b), ir.BitwiseOr(a, c)); | ||
| 433 | case 202: | ||
| 434 | return ir.BitwiseAnd(ir.BitwiseOr(a, c), ir.BitwiseOr(b, ir.BitwiseNot(a))); | ||
| 435 | case 203: | ||
| 436 | return ir.BitwiseOr(ir.BitwiseAnd(b, c), ir.BitwiseXor(a, ir.BitwiseNot(b))); | ||
| 437 | case 204: | ||
| 438 | return b; | ||
| 439 | case 205: | ||
| 440 | return ir.BitwiseOr(b, ir.BitwiseNot(ir.BitwiseOr(a, c))); | ||
| 441 | case 206: | ||
| 442 | return ir.BitwiseOr(b, ir.BitwiseAnd(c, ir.BitwiseNot(a))); | ||
| 443 | case 207: | ||
| 444 | return ir.BitwiseOr(b, ir.BitwiseNot(a)); | ||
| 445 | case 208: | ||
| 446 | return ir.BitwiseAnd(a, ir.BitwiseOr(b, ir.BitwiseNot(c))); | ||
| 447 | case 209: | ||
| 448 | return ir.BitwiseOr(ir.BitwiseAnd(a, b), ir.BitwiseNot(ir.BitwiseOr(b, c))); | ||
| 449 | case 210: | ||
| 450 | return ir.BitwiseXor(a, ir.BitwiseAnd(c, ir.BitwiseNot(b))); | ||
| 451 | case 211: | ||
| 452 | return ir.BitwiseNot(ir.BitwiseAnd(ir.BitwiseOr(b, c), ir.BitwiseXor(a, b))); | ||
| 453 | case 212: | ||
| 454 | return ir.BitwiseXor(c, ir.BitwiseOr(ir.BitwiseXor(a, b), ir.BitwiseXor(a, c))); | ||
| 455 | case 213: | ||
| 456 | return ir.BitwiseOr(ir.BitwiseAnd(a, b), ir.BitwiseNot(c)); | ||
| 457 | case 214: | ||
| 458 | return ir.BitwiseOr(ir.BitwiseAnd(a, b), ir.BitwiseXor(c, ir.BitwiseOr(a, b))); | ||
| 459 | case 215: | ||
| 460 | return ir.BitwiseNot(ir.BitwiseAnd(c, ir.BitwiseXor(a, b))); | ||
| 461 | case 216: | ||
| 462 | return ir.BitwiseAnd(ir.BitwiseOr(a, c), ir.BitwiseOr(b, ir.BitwiseNot(c))); | ||
| 463 | case 217: | ||
| 464 | return ir.BitwiseOr(ir.BitwiseAnd(a, b), ir.BitwiseXor(b, ir.BitwiseNot(c))); | ||
| 465 | case 218: | ||
| 466 | return ir.BitwiseOr(ir.BitwiseAnd(a, b), ir.BitwiseXor(a, c)); | ||
| 467 | case 219: | ||
| 468 | return ir.BitwiseOr(ir.BitwiseXor(a, c), ir.BitwiseXor(a, ir.BitwiseNot(b))); | ||
| 469 | case 220: | ||
| 470 | return ir.BitwiseOr(b, ir.BitwiseAnd(a, ir.BitwiseNot(c))); | ||
| 471 | case 221: | ||
| 472 | return ir.BitwiseOr(b, ir.BitwiseNot(c)); | ||
| 473 | case 222: | ||
| 474 | return ir.BitwiseOr(b, ir.BitwiseXor(a, c)); | ||
| 475 | case 223: | ||
| 476 | return ir.BitwiseOr(b, ir.BitwiseNot(ir.BitwiseAnd(a, c))); | ||
| 477 | case 224: | ||
| 478 | return ir.BitwiseAnd(a, ir.BitwiseOr(b, c)); | ||
| 479 | case 225: | ||
| 480 | return ir.BitwiseXor(ir.BitwiseNot(a), ir.BitwiseOr(b, c)); | ||
| 481 | case 226: | ||
| 482 | return ir.BitwiseAnd(ir.BitwiseOr(a, ir.BitwiseNot(b)), ir.BitwiseOr(b, c)); | ||
| 483 | case 227: | ||
| 484 | return ir.BitwiseOr(ir.BitwiseAnd(a, c), ir.BitwiseXor(a, ir.BitwiseNot(b))); | ||
| 485 | case 228: | ||
| 486 | return ir.BitwiseAnd(ir.BitwiseOr(a, ir.BitwiseNot(c)), ir.BitwiseOr(b, c)); | ||
| 487 | case 229: | ||
| 488 | return ir.BitwiseOr(ir.BitwiseAnd(a, b), ir.BitwiseXor(a, ir.BitwiseNot(c))); | ||
| 489 | case 230: | ||
| 490 | return ir.BitwiseOr(ir.BitwiseAnd(a, b), ir.BitwiseXor(b, c)); | ||
| 491 | case 231: | ||
| 492 | return ir.BitwiseOr(ir.BitwiseXor(a, ir.BitwiseNot(b)), ir.BitwiseXor(b, c)); | ||
| 493 | case 232: | ||
| 494 | return ir.BitwiseAnd(ir.BitwiseOr(a, b), ir.BitwiseOr(c, ir.BitwiseAnd(a, b))); | ||
| 495 | case 233: | ||
| 496 | return ir.BitwiseOr(ir.BitwiseAnd(a, b), | ||
| 497 | ir.BitwiseXor(ir.BitwiseNot(c), ir.BitwiseOr(a, b))); | ||
| 498 | case 234: | ||
| 499 | return ir.BitwiseOr(c, ir.BitwiseAnd(a, b)); | ||
| 500 | case 235: | ||
| 501 | return ir.BitwiseOr(c, ir.BitwiseXor(a, ir.BitwiseNot(b))); | ||
| 502 | case 236: | ||
| 503 | return ir.BitwiseOr(b, ir.BitwiseAnd(a, c)); | ||
| 504 | case 237: | ||
| 505 | return ir.BitwiseOr(b, ir.BitwiseXor(a, ir.BitwiseNot(c))); | ||
| 506 | case 238: | ||
| 507 | return ir.BitwiseOr(b, c); | ||
| 508 | case 239: | ||
| 509 | return ir.BitwiseOr(ir.BitwiseNot(a), ir.BitwiseOr(b, c)); | ||
| 510 | case 240: | ||
| 511 | return a; | ||
| 512 | case 241: | ||
| 513 | return ir.BitwiseOr(a, ir.BitwiseNot(ir.BitwiseOr(b, c))); | ||
| 514 | case 242: | ||
| 515 | return ir.BitwiseOr(a, ir.BitwiseAnd(c, ir.BitwiseNot(b))); | ||
| 516 | case 243: | ||
| 517 | return ir.BitwiseOr(a, ir.BitwiseNot(b)); | ||
| 518 | case 244: | ||
| 519 | return ir.BitwiseOr(a, ir.BitwiseAnd(b, ir.BitwiseNot(c))); | ||
| 520 | case 245: | ||
| 521 | return ir.BitwiseOr(a, ir.BitwiseNot(c)); | ||
| 522 | case 246: | ||
| 523 | return ir.BitwiseOr(a, ir.BitwiseXor(b, c)); | ||
| 524 | case 247: | ||
| 525 | return ir.BitwiseOr(a, ir.BitwiseNot(ir.BitwiseAnd(b, c))); | ||
| 526 | case 248: | ||
| 527 | return ir.BitwiseOr(a, ir.BitwiseAnd(b, c)); | ||
| 528 | case 249: | ||
| 529 | return ir.BitwiseOr(a, ir.BitwiseXor(b, ir.BitwiseNot(c))); | ||
| 530 | case 250: | ||
| 531 | return ir.BitwiseOr(a, c); | ||
| 532 | case 251: | ||
| 533 | return ir.BitwiseOr(ir.BitwiseNot(b), ir.BitwiseOr(a, c)); | ||
| 534 | case 252: | ||
| 535 | return ir.BitwiseOr(a, b); | ||
| 536 | case 253: | ||
| 537 | return ir.BitwiseOr(ir.BitwiseNot(c), ir.BitwiseOr(a, b)); | ||
| 538 | case 254: | ||
| 539 | return ir.BitwiseOr(a, ir.BitwiseOr(b, c)); | ||
| 540 | case 255: | ||
| 541 | return ir.Imm32(0xFFFFFFFF); | ||
| 542 | // end of generated code | ||
| 25 | } | 543 | } |
| 26 | if (ttbl & 0x02) { | 544 | throw NotImplementedException("LOP3 with out of range ttbl"); |
| 27 | // r |= ~a & ~b & c; | ||
| 28 | const auto lhs{ir.BitwiseAnd(not_a, not_b)}; | ||
| 29 | const auto rhs{ir.BitwiseAnd(lhs, c)}; | ||
| 30 | r = ir.BitwiseOr(r, rhs); | ||
| 31 | } | ||
| 32 | if (ttbl & 0x04) { | ||
| 33 | // r |= ~a & b & ~c; | ||
| 34 | const auto lhs{ir.BitwiseAnd(not_a, b)}; | ||
| 35 | const auto rhs{ir.BitwiseAnd(lhs, not_c)}; | ||
| 36 | r = ir.BitwiseOr(r, rhs); | ||
| 37 | } | ||
| 38 | if (ttbl & 0x08) { | ||
| 39 | // r |= ~a & b & c; | ||
| 40 | const auto lhs{ir.BitwiseAnd(not_a, b)}; | ||
| 41 | const auto rhs{ir.BitwiseAnd(lhs, c)}; | ||
| 42 | r = ir.BitwiseOr(r, rhs); | ||
| 43 | } | ||
| 44 | if (ttbl & 0x10) { | ||
| 45 | // r |= a & ~b & ~c; | ||
| 46 | const auto lhs{ir.BitwiseAnd(a, not_b)}; | ||
| 47 | const auto rhs{ir.BitwiseAnd(lhs, not_c)}; | ||
| 48 | r = ir.BitwiseOr(r, rhs); | ||
| 49 | } | ||
| 50 | if (ttbl & 0x20) { | ||
| 51 | // r |= a & ~b & c; | ||
| 52 | const auto lhs{ir.BitwiseAnd(a, not_b)}; | ||
| 53 | const auto rhs{ir.BitwiseAnd(lhs, c)}; | ||
| 54 | r = ir.BitwiseOr(r, rhs); | ||
| 55 | } | ||
| 56 | if (ttbl & 0x40) { | ||
| 57 | // r |= a & b & ~c; | ||
| 58 | const auto lhs{ir.BitwiseAnd(a, b)}; | ||
| 59 | const auto rhs{ir.BitwiseAnd(lhs, not_c)}; | ||
| 60 | r = ir.BitwiseOr(r, rhs); | ||
| 61 | } | ||
| 62 | if (ttbl & 0x80) { | ||
| 63 | // r |= a & b & c; | ||
| 64 | const auto lhs{ir.BitwiseAnd(a, b)}; | ||
| 65 | const auto rhs{ir.BitwiseAnd(lhs, c)}; | ||
| 66 | r = ir.BitwiseOr(r, rhs); | ||
| 67 | } | ||
| 68 | return r; | ||
| 69 | } | 545 | } |
| 70 | 546 | ||
| 71 | IR::U32 LOP3(TranslatorVisitor& v, u64 insn, const IR::U32& op_b, const IR::U32& op_c, u64 lut) { | 547 | IR::U32 LOP3(TranslatorVisitor& v, u64 insn, const IR::U32& op_b, const IR::U32& op_c, u64 lut) { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/logic_operation_three_input_lut3.py b/src/shader_recompiler/frontend/maxwell/translate/impl/logic_operation_three_input_lut3.py new file mode 100644 index 000000000..8f547c266 --- /dev/null +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/logic_operation_three_input_lut3.py | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | # Copyright © 2022 degasus <markus@selfnet.de> | ||
| 2 | # This work is free. You can redistribute it and/or modify it under the | ||
| 3 | # terms of the Do What The Fuck You Want To Public License, Version 2, | ||
| 4 | # as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. | ||
| 5 | |||
| 6 | from itertools import product | ||
| 7 | |||
| 8 | # The primitive instructions | ||
| 9 | OPS = { | ||
| 10 | 'ir.BitwiseAnd({}, {})' : (2, 1, lambda a,b: a&b), | ||
| 11 | 'ir.BitwiseOr({}, {})' : (2, 1, lambda a,b: a|b), | ||
| 12 | 'ir.BitwiseXor({}, {})' : (2, 1, lambda a,b: a^b), | ||
| 13 | 'ir.BitwiseNot({})' : (1, 0.1, lambda a: (~a) & 255), # Only tiny cost, as this can often inlined in other instructions | ||
| 14 | } | ||
| 15 | |||
| 16 | # Our database of combination of instructions | ||
| 17 | optimized_calls = {} | ||
| 18 | def cmp(lhs, rhs): | ||
| 19 | if lhs is None: # new entry | ||
| 20 | return True | ||
| 21 | if lhs[3] > rhs[3]: # costs | ||
| 22 | return True | ||
| 23 | if lhs[3] < rhs[3]: # costs | ||
| 24 | return False | ||
| 25 | if len(lhs[0]) > len(rhs[0]): # string len | ||
| 26 | return True | ||
| 27 | if len(lhs[0]) < len(rhs[0]): # string len | ||
| 28 | return False | ||
| 29 | if lhs[0] > rhs[0]: # string sorting | ||
| 30 | return True | ||
| 31 | if lhs[0] < rhs[0]: # string sorting | ||
| 32 | return False | ||
| 33 | assert lhs == rhs, "redundant instruction, bug in brute force" | ||
| 34 | return False | ||
| 35 | def register(imm, instruction, count, latency): | ||
| 36 | # Use the sum of instruction count and latency as costs to evaluate which combination is best | ||
| 37 | costs = count + latency | ||
| 38 | |||
| 39 | old = optimized_calls.get(imm, None) | ||
| 40 | new = (instruction, count, latency, costs) | ||
| 41 | |||
| 42 | # Update if new or better | ||
| 43 | if cmp(old, new): | ||
| 44 | optimized_calls[imm] = new | ||
| 45 | return True | ||
| 46 | |||
| 47 | return False | ||
| 48 | |||
| 49 | # Constants: 0, 1 (for free) | ||
| 50 | register(0, 'ir.Imm32(0)', 0, 0) | ||
| 51 | register(255, 'ir.Imm32(0xFFFFFFFF)', 0, 0) | ||
| 52 | |||
| 53 | # Inputs: a, b, c (for free) | ||
| 54 | ta = 0xF0 | ||
| 55 | tb = 0xCC | ||
| 56 | tc = 0xAA | ||
| 57 | inputs = { | ||
| 58 | ta : 'a', | ||
| 59 | tb : 'b', | ||
| 60 | tc : 'c', | ||
| 61 | } | ||
| 62 | for imm, instruction in inputs.items(): | ||
| 63 | register(imm, instruction, 0, 0) | ||
| 64 | register((~imm) & 255, 'ir.BitwiseNot({})'.format(instruction), 0.099, 0.099) # slightly cheaper NEG on inputs | ||
| 65 | |||
| 66 | # Try to combine two values from the db with an instruction. | ||
| 67 | # If it is better than the old method, update it. | ||
| 68 | while True: | ||
| 69 | registered = 0 | ||
| 70 | calls_copy = optimized_calls.copy() | ||
| 71 | for OP, (argc, cost, f) in OPS.items(): | ||
| 72 | for args in product(calls_copy.items(), repeat=argc): | ||
| 73 | # unpack(transponse) the arrays | ||
| 74 | imm = [arg[0] for arg in args] | ||
| 75 | value = [arg[1][0] for arg in args] | ||
| 76 | count = [arg[1][1] for arg in args] | ||
| 77 | latency = [arg[1][2] for arg in args] | ||
| 78 | |||
| 79 | registered += register( | ||
| 80 | f(*imm), | ||
| 81 | OP.format(*value), | ||
| 82 | sum(count) + cost, | ||
| 83 | max(latency) + cost) | ||
| 84 | if registered == 0: | ||
| 85 | # No update at all? So terminate | ||
| 86 | break | ||
| 87 | |||
| 88 | # Hacky output. Please improve me to output valid C++ instead. | ||
| 89 | s = """ case {imm}: | ||
| 90 | return {op};""" | ||
| 91 | for imm in range(256): | ||
| 92 | print(s.format(imm=imm, op=optimized_calls[imm][0])) | ||
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/move_register.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/move_register.cpp index 6bb08db8a..c317e14c9 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/move_register.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/move_register.cpp | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "shader_recompiler/exception.h" | 7 | #include "shader_recompiler/exception.h" |
| 8 | #include "shader_recompiler/frontend/maxwell/opcodes.h" | ||
| 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 8 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 10 | 9 | ||
| 11 | namespace Shader::Maxwell { | 10 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/surface_atomic_operations.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/surface_atomic_operations.cpp index 63b588ad4..100c94c19 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/surface_atomic_operations.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/surface_atomic_operations.cpp | |||
| @@ -2,9 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <array> | ||
| 6 | #include <bit> | ||
| 7 | |||
| 8 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 9 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 10 | #include "shader_recompiler/frontend/ir/modifiers.h" | 7 | #include "shader_recompiler/frontend/ir/modifiers.h" |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_fetch_swizzled.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_fetch_swizzled.cpp index 154e7f1a1..00dbcd86f 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_fetch_swizzled.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_fetch_swizzled.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <utility> | ||
| 6 | |||
| 7 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 8 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 9 | #include "shader_recompiler/frontend/ir/modifiers.h" | 7 | #include "shader_recompiler/frontend/ir/modifiers.h" |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather.cpp index 218cbc1a8..959c63ba9 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <optional> | ||
| 6 | |||
| 7 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 8 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 9 | #include "shader_recompiler/frontend/ir/modifiers.h" | 7 | #include "shader_recompiler/frontend/ir/modifiers.h" |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather_swizzled.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather_swizzled.cpp index 34efa2d50..86e68a830 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather_swizzled.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather_swizzled.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <utility> | ||
| 6 | |||
| 7 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 8 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 9 | #include "shader_recompiler/frontend/ir/modifiers.h" | 7 | #include "shader_recompiler/frontend/ir/modifiers.h" |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gradient.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gradient.cpp index c3fe3ffda..6f4feff11 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gradient.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gradient.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <optional> | ||
| 6 | |||
| 7 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 8 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 9 | #include "shader_recompiler/frontend/ir/modifiers.h" | 7 | #include "shader_recompiler/frontend/ir/modifiers.h" |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_load.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_load.cpp index 983058303..60732215b 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_load.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_load.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <optional> | ||
| 6 | |||
| 7 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 8 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 9 | #include "shader_recompiler/frontend/ir/modifiers.h" | 7 | #include "shader_recompiler/frontend/ir/modifiers.h" |
| @@ -134,7 +132,7 @@ void Impl(TranslatorVisitor& v, u64 insn, bool is_bindless) { | |||
| 134 | multisample = v.X(meta_reg++); | 132 | multisample = v.X(meta_reg++); |
| 135 | } | 133 | } |
| 136 | if (tld.clamp != 0) { | 134 | if (tld.clamp != 0) { |
| 137 | throw NotImplementedException("TLD.CL - CLAMP is not implmented"); | 135 | throw NotImplementedException("TLD.CL - CLAMP is not implemented"); |
| 138 | } | 136 | } |
| 139 | IR::TextureInstInfo info{}; | 137 | IR::TextureInstInfo info{}; |
| 140 | info.type.Assign(GetType(tld.type)); | 138 | info.type.Assign(GetType(tld.type)); |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_mipmap_level.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_mipmap_level.cpp index aea3c0e62..f89ce1b68 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_mipmap_level.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_mipmap_level.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <optional> | ||
| 6 | |||
| 7 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 8 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 9 | #include "shader_recompiler/frontend/ir/modifiers.h" | 7 | #include "shader_recompiler/frontend/ir/modifiers.h" |
| @@ -83,7 +81,7 @@ void Impl(TranslatorVisitor& v, u64 insn, bool is_bindless) { | |||
| 83 | } const tmml{insn}; | 81 | } const tmml{insn}; |
| 84 | 82 | ||
| 85 | if ((tmml.mask & 0b1100) != 0) { | 83 | if ((tmml.mask & 0b1100) != 0) { |
| 86 | throw NotImplementedException("TMML BA results are not implmented"); | 84 | throw NotImplementedException("TMML BA results are not implemented"); |
| 87 | } | 85 | } |
| 88 | const IR::Value coords{MakeCoords(v, tmml.coord_reg, tmml.type)}; | 86 | const IR::Value coords{MakeCoords(v, tmml.coord_reg, tmml.type)}; |
| 89 | 87 | ||
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_query.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_query.cpp index 0459e5473..72131301c 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_query.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_query.cpp | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | #include "common/bit_field.h" | 7 | #include "common/bit_field.h" |
| 8 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 9 | #include "shader_recompiler/frontend/ir/modifiers.h" | ||
| 10 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 11 | 10 | ||
| 12 | namespace Shader::Maxwell { | 11 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/warp_shuffle.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/warp_shuffle.cpp index 550fed55c..f98f66940 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/warp_shuffle.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/warp_shuffle.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <optional> | ||
| 6 | |||
| 7 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 8 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 7 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.cpp b/src/shader_recompiler/frontend/maxwell/translate_program.cpp index 248ad3ced..b22725584 100644 --- a/src/shader_recompiler/frontend/maxwell/translate_program.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate_program.cpp | |||
| @@ -212,11 +212,11 @@ IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Blo | |||
| 212 | } | 212 | } |
| 213 | Optimization::SsaRewritePass(program); | 213 | Optimization::SsaRewritePass(program); |
| 214 | 214 | ||
| 215 | Optimization::ConstantPropagationPass(program); | ||
| 216 | |||
| 215 | Optimization::GlobalMemoryToStorageBufferPass(program); | 217 | Optimization::GlobalMemoryToStorageBufferPass(program); |
| 216 | Optimization::TexturePass(env, program); | 218 | Optimization::TexturePass(env, program); |
| 217 | 219 | ||
| 218 | Optimization::ConstantPropagationPass(program); | ||
| 219 | |||
| 220 | if (Settings::values.resolution_info.active) { | 220 | if (Settings::values.resolution_info.active) { |
| 221 | Optimization::RescalingPass(program); | 221 | Optimization::RescalingPass(program); |
| 222 | } | 222 | } |
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.h b/src/shader_recompiler/frontend/maxwell/translate_program.h index eac83da9d..7b024c627 100644 --- a/src/shader_recompiler/frontend/maxwell/translate_program.h +++ b/src/shader_recompiler/frontend/maxwell/translate_program.h | |||
| @@ -8,10 +8,13 @@ | |||
| 8 | #include "shader_recompiler/frontend/ir/basic_block.h" | 8 | #include "shader_recompiler/frontend/ir/basic_block.h" |
| 9 | #include "shader_recompiler/frontend/ir/program.h" | 9 | #include "shader_recompiler/frontend/ir/program.h" |
| 10 | #include "shader_recompiler/frontend/maxwell/control_flow.h" | 10 | #include "shader_recompiler/frontend/maxwell/control_flow.h" |
| 11 | #include "shader_recompiler/host_translate_info.h" | ||
| 12 | #include "shader_recompiler/object_pool.h" | 11 | #include "shader_recompiler/object_pool.h" |
| 13 | #include "shader_recompiler/runtime_info.h" | 12 | #include "shader_recompiler/runtime_info.h" |
| 14 | 13 | ||
| 14 | namespace Shader { | ||
| 15 | struct HostTranslateInfo; | ||
| 16 | } | ||
| 17 | |||
| 15 | namespace Shader::Maxwell { | 18 | namespace Shader::Maxwell { |
| 16 | 19 | ||
| 17 | [[nodiscard]] IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, | 20 | [[nodiscard]] IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, |
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 bfd2ae650..16278faab 100644 --- a/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp +++ b/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp | |||
| @@ -29,6 +29,41 @@ void AddConstantBufferDescriptor(Info& info, u32 index, u32 count) { | |||
| 29 | }); | 29 | }); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | void AddRegisterIndexedLdc(Info& info) { | ||
| 33 | info.uses_cbuf_indirect = true; | ||
| 34 | |||
| 35 | for (u32 i = 0; i < Info::MAX_INDIRECT_CBUFS; i++) { | ||
| 36 | AddConstantBufferDescriptor(info, i, 1); | ||
| 37 | |||
| 38 | // The shader can use any possible access size | ||
| 39 | info.constant_buffer_used_sizes[i] = 0x10'000; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | u32 GetElementSize(IR::Type& used_type, Shader::IR::Opcode opcode) { | ||
| 44 | switch (opcode) { | ||
| 45 | case IR::Opcode::GetCbufU8: | ||
| 46 | case IR::Opcode::GetCbufS8: | ||
| 47 | used_type |= IR::Type::U8; | ||
| 48 | return 1; | ||
| 49 | case IR::Opcode::GetCbufU16: | ||
| 50 | case IR::Opcode::GetCbufS16: | ||
| 51 | used_type |= IR::Type::U16; | ||
| 52 | return 2; | ||
| 53 | case IR::Opcode::GetCbufU32: | ||
| 54 | used_type |= IR::Type::U32; | ||
| 55 | return 4; | ||
| 56 | case IR::Opcode::GetCbufF32: | ||
| 57 | used_type |= IR::Type::F32; | ||
| 58 | return 4; | ||
| 59 | case IR::Opcode::GetCbufU32x2: | ||
| 60 | used_type |= IR::Type::U32x2; | ||
| 61 | return 8; | ||
| 62 | default: | ||
| 63 | throw InvalidArgument("Invalid opcode {}", opcode); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 32 | void GetPatch(Info& info, IR::Patch patch) { | 67 | void GetPatch(Info& info, IR::Patch patch) { |
| 33 | if (!IR::IsGeneric(patch)) { | 68 | if (!IR::IsGeneric(patch)) { |
| 34 | throw NotImplementedException("Reading non-generic patch {}", patch); | 69 | throw NotImplementedException("Reading non-generic patch {}", patch); |
| @@ -463,42 +498,18 @@ void VisitUsages(Info& info, IR::Inst& inst) { | |||
| 463 | case IR::Opcode::GetCbufU32x2: { | 498 | case IR::Opcode::GetCbufU32x2: { |
| 464 | const IR::Value index{inst.Arg(0)}; | 499 | const IR::Value index{inst.Arg(0)}; |
| 465 | const IR::Value offset{inst.Arg(1)}; | 500 | const IR::Value offset{inst.Arg(1)}; |
| 466 | if (!index.IsImmediate()) { | 501 | if (index.IsImmediate()) { |
| 467 | throw NotImplementedException("Constant buffer with non-immediate index"); | 502 | AddConstantBufferDescriptor(info, index.U32(), 1); |
| 468 | } | 503 | u32 element_size = GetElementSize(info.used_constant_buffer_types, inst.GetOpcode()); |
| 469 | AddConstantBufferDescriptor(info, index.U32(), 1); | 504 | u32& size{info.constant_buffer_used_sizes[index.U32()]}; |
| 470 | u32 element_size{}; | 505 | if (offset.IsImmediate()) { |
| 471 | switch (inst.GetOpcode()) { | 506 | size = Common::AlignUp(std::max(size, offset.U32() + element_size), 16u); |
| 472 | case IR::Opcode::GetCbufU8: | 507 | } else { |
| 473 | case IR::Opcode::GetCbufS8: | 508 | size = 0x10'000; |
| 474 | info.used_constant_buffer_types |= IR::Type::U8; | 509 | } |
| 475 | element_size = 1; | ||
| 476 | break; | ||
| 477 | case IR::Opcode::GetCbufU16: | ||
| 478 | case IR::Opcode::GetCbufS16: | ||
| 479 | info.used_constant_buffer_types |= IR::Type::U16; | ||
| 480 | element_size = 2; | ||
| 481 | break; | ||
| 482 | case IR::Opcode::GetCbufU32: | ||
| 483 | info.used_constant_buffer_types |= IR::Type::U32; | ||
| 484 | element_size = 4; | ||
| 485 | break; | ||
| 486 | case IR::Opcode::GetCbufF32: | ||
| 487 | info.used_constant_buffer_types |= IR::Type::F32; | ||
| 488 | element_size = 4; | ||
| 489 | break; | ||
| 490 | case IR::Opcode::GetCbufU32x2: | ||
| 491 | info.used_constant_buffer_types |= IR::Type::U32x2; | ||
| 492 | element_size = 8; | ||
| 493 | break; | ||
| 494 | default: | ||
| 495 | break; | ||
| 496 | } | ||
| 497 | u32& size{info.constant_buffer_used_sizes[index.U32()]}; | ||
| 498 | if (offset.IsImmediate()) { | ||
| 499 | size = Common::AlignUp(std::max(size, offset.U32() + element_size), 16u); | ||
| 500 | } else { | 510 | } else { |
| 501 | size = 0x10'000; | 511 | AddRegisterIndexedLdc(info); |
| 512 | GetElementSize(info.used_indirect_cbuf_types, inst.GetOpcode()); | ||
| 502 | } | 513 | } |
| 503 | break; | 514 | break; |
| 504 | } | 515 | } |
diff --git a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp index c134a12bc..2a14e7f12 100644 --- a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp +++ b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp | |||
| @@ -8,7 +8,6 @@ | |||
| 8 | #include <type_traits> | 8 | #include <type_traits> |
| 9 | 9 | ||
| 10 | #include "common/bit_cast.h" | 10 | #include "common/bit_cast.h" |
| 11 | #include "common/bit_util.h" | ||
| 12 | #include "shader_recompiler/exception.h" | 11 | #include "shader_recompiler/exception.h" |
| 13 | #include "shader_recompiler/frontend/ir/ir_emitter.h" | 12 | #include "shader_recompiler/frontend/ir/ir_emitter.h" |
| 14 | #include "shader_recompiler/frontend/ir/value.h" | 13 | #include "shader_recompiler/frontend/ir/value.h" |
diff --git a/src/shader_recompiler/ir_opt/dead_code_elimination_pass.cpp b/src/shader_recompiler/ir_opt/dead_code_elimination_pass.cpp index 400836301..6697fde85 100644 --- a/src/shader_recompiler/ir_opt/dead_code_elimination_pass.cpp +++ b/src/shader_recompiler/ir_opt/dead_code_elimination_pass.cpp | |||
| @@ -2,24 +2,104 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 6 | |||
| 7 | #include <boost/container/small_vector.hpp> | ||
| 8 | |||
| 5 | #include "shader_recompiler/frontend/ir/basic_block.h" | 9 | #include "shader_recompiler/frontend/ir/basic_block.h" |
| 6 | #include "shader_recompiler/frontend/ir/value.h" | 10 | #include "shader_recompiler/frontend/ir/value.h" |
| 7 | #include "shader_recompiler/ir_opt/passes.h" | 11 | #include "shader_recompiler/ir_opt/passes.h" |
| 8 | 12 | ||
| 9 | namespace Shader::Optimization { | 13 | namespace Shader::Optimization { |
| 10 | 14 | namespace { | |
| 11 | void DeadCodeEliminationPass(IR::Program& program) { | 15 | template <bool TEST_USES> |
| 16 | void DeadInstElimination(IR::Block* const block) { | ||
| 12 | // We iterate over the instructions in reverse order. | 17 | // We iterate over the instructions in reverse order. |
| 13 | // This is because removing an instruction reduces the number of uses for earlier instructions. | 18 | // This is because removing an instruction reduces the number of uses for earlier instructions. |
| 14 | for (IR::Block* const block : program.post_order_blocks) { | 19 | auto it{block->end()}; |
| 15 | auto it{block->end()}; | 20 | while (it != block->begin()) { |
| 16 | while (it != block->begin()) { | 21 | --it; |
| 17 | --it; | 22 | if constexpr (TEST_USES) { |
| 18 | if (!it->HasUses() && !it->MayHaveSideEffects()) { | 23 | if (it->HasUses() || it->MayHaveSideEffects()) { |
| 19 | it->Invalidate(); | 24 | continue; |
| 20 | it = block->Instructions().erase(it); | 25 | } |
| 26 | } | ||
| 27 | it->Invalidate(); | ||
| 28 | it = block->Instructions().erase(it); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | void DeletedPhiArgElimination(IR::Program& program, std::span<const IR::Block*> dead_blocks) { | ||
| 33 | for (IR::Block* const block : program.blocks) { | ||
| 34 | for (IR::Inst& phi : *block) { | ||
| 35 | if (!IR::IsPhi(phi)) { | ||
| 36 | continue; | ||
| 37 | } | ||
| 38 | for (size_t i = 0; i < phi.NumArgs(); ++i) { | ||
| 39 | if (std::ranges::find(dead_blocks, phi.PhiBlock(i)) == dead_blocks.end()) { | ||
| 40 | continue; | ||
| 41 | } | ||
| 42 | // Phi operand at this index is an unreachable block | ||
| 43 | phi.ErasePhiOperand(i); | ||
| 44 | --i; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | void DeadBranchElimination(IR::Program& program) { | ||
| 51 | boost::container::small_vector<const IR::Block*, 3> dead_blocks; | ||
| 52 | const auto begin_it{program.syntax_list.begin()}; | ||
| 53 | for (auto node_it = begin_it; node_it != program.syntax_list.end(); ++node_it) { | ||
| 54 | if (node_it->type != IR::AbstractSyntaxNode::Type::If) { | ||
| 55 | continue; | ||
| 56 | } | ||
| 57 | IR::Inst* const cond_ref{node_it->data.if_node.cond.Inst()}; | ||
| 58 | const IR::U1 cond{cond_ref->Arg(0)}; | ||
| 59 | if (!cond.IsImmediate()) { | ||
| 60 | continue; | ||
| 61 | } | ||
| 62 | if (cond.U1()) { | ||
| 63 | continue; | ||
| 64 | } | ||
| 65 | // False immediate condition. Remove condition ref, erase the entire branch. | ||
| 66 | cond_ref->Invalidate(); | ||
| 67 | // Account for nested if-statements within the if(false) branch | ||
| 68 | u32 nested_ifs{1u}; | ||
| 69 | while (node_it->type != IR::AbstractSyntaxNode::Type::EndIf || nested_ifs > 0) { | ||
| 70 | node_it = program.syntax_list.erase(node_it); | ||
| 71 | switch (node_it->type) { | ||
| 72 | case IR::AbstractSyntaxNode::Type::If: | ||
| 73 | ++nested_ifs; | ||
| 74 | break; | ||
| 75 | case IR::AbstractSyntaxNode::Type::EndIf: | ||
| 76 | --nested_ifs; | ||
| 77 | break; | ||
| 78 | case IR::AbstractSyntaxNode::Type::Block: { | ||
| 79 | IR::Block* const block{node_it->data.block}; | ||
| 80 | DeadInstElimination<false>(block); | ||
| 81 | dead_blocks.push_back(block); | ||
| 82 | break; | ||
| 83 | } | ||
| 84 | default: | ||
| 85 | break; | ||
| 21 | } | 86 | } |
| 22 | } | 87 | } |
| 88 | // Erase EndIf node of the if(false) branch | ||
| 89 | node_it = program.syntax_list.erase(node_it); | ||
| 90 | // Account for loop increment | ||
| 91 | --node_it; | ||
| 92 | } | ||
| 93 | if (!dead_blocks.empty()) { | ||
| 94 | DeletedPhiArgElimination(program, std::span(dead_blocks.data(), dead_blocks.size())); | ||
| 95 | } | ||
| 96 | } | ||
| 97 | } // namespace | ||
| 98 | |||
| 99 | void DeadCodeEliminationPass(IR::Program& program) { | ||
| 100 | DeadBranchElimination(program); | ||
| 101 | for (IR::Block* const block : program.post_order_blocks) { | ||
| 102 | DeadInstElimination<true>(block); | ||
| 23 | } | 103 | } |
| 24 | } | 104 | } |
| 25 | 105 | ||
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 38592afd0..3cc1cc07a 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 | |||
| @@ -2,10 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 6 | #include <compare> | ||
| 7 | #include <optional> | 5 | #include <optional> |
| 8 | #include <queue> | ||
| 9 | 6 | ||
| 10 | #include <boost/container/flat_set.hpp> | 7 | #include <boost/container/flat_set.hpp> |
| 11 | #include <boost/container/small_vector.hpp> | 8 | #include <boost/container/small_vector.hpp> |
| @@ -334,7 +331,8 @@ std::optional<LowAddrInfo> TrackLowAddress(IR::Inst* inst) { | |||
| 334 | /// Tries to track the storage buffer address used by a global memory instruction | 331 | /// Tries to track the storage buffer address used by a global memory instruction |
| 335 | std::optional<StorageBufferAddr> Track(const IR::Value& value, const Bias* bias) { | 332 | std::optional<StorageBufferAddr> Track(const IR::Value& value, const Bias* bias) { |
| 336 | const auto pred{[bias](const IR::Inst* inst) -> std::optional<StorageBufferAddr> { | 333 | const auto pred{[bias](const IR::Inst* inst) -> std::optional<StorageBufferAddr> { |
| 337 | if (inst->GetOpcode() != IR::Opcode::GetCbufU32) { | 334 | if (inst->GetOpcode() != IR::Opcode::GetCbufU32 && |
| 335 | inst->GetOpcode() != IR::Opcode::GetCbufU32x2) { | ||
| 338 | return std::nullopt; | 336 | return std::nullopt; |
| 339 | } | 337 | } |
| 340 | const IR::Value index{inst->Arg(0)}; | 338 | const IR::Value index{inst->Arg(0)}; |
diff --git a/src/shader_recompiler/ir_opt/lower_fp16_to_fp32.cpp b/src/shader_recompiler/ir_opt/lower_fp16_to_fp32.cpp index 773e1f961..622f94fc7 100644 --- a/src/shader_recompiler/ir_opt/lower_fp16_to_fp32.cpp +++ b/src/shader_recompiler/ir_opt/lower_fp16_to_fp32.cpp | |||
| @@ -2,9 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 6 | |||
| 7 | #include "shader_recompiler/frontend/ir/ir_emitter.h" | ||
| 8 | #include "shader_recompiler/frontend/ir/value.h" | 5 | #include "shader_recompiler/frontend/ir/value.h" |
| 9 | #include "shader_recompiler/ir_opt/passes.h" | 6 | #include "shader_recompiler/ir_opt/passes.h" |
| 10 | 7 | ||
diff --git a/src/shader_recompiler/ir_opt/passes.h b/src/shader_recompiler/ir_opt/passes.h index f877c7ba0..16ea3d80a 100644 --- a/src/shader_recompiler/ir_opt/passes.h +++ b/src/shader_recompiler/ir_opt/passes.h | |||
| @@ -4,10 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <span> | ||
| 8 | |||
| 9 | #include "shader_recompiler/environment.h" | 7 | #include "shader_recompiler/environment.h" |
| 10 | #include "shader_recompiler/frontend/ir/basic_block.h" | ||
| 11 | #include "shader_recompiler/frontend/ir/program.h" | 8 | #include "shader_recompiler/frontend/ir/program.h" |
| 12 | 9 | ||
| 13 | namespace Shader::Optimization { | 10 | namespace Shader::Optimization { |
diff --git a/src/shader_recompiler/ir_opt/rescaling_pass.cpp b/src/shader_recompiler/ir_opt/rescaling_pass.cpp index c28500dd1..75679c793 100644 --- a/src/shader_recompiler/ir_opt/rescaling_pass.cpp +++ b/src/shader_recompiler/ir_opt/rescaling_pass.cpp | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/alignment.h" | ||
| 6 | #include "common/settings.h" | 5 | #include "common/settings.h" |
| 7 | #include "shader_recompiler/environment.h" | 6 | #include "shader_recompiler/environment.h" |
| 8 | #include "shader_recompiler/frontend/ir/ir_emitter.h" | 7 | #include "shader_recompiler/frontend/ir/ir_emitter.h" |
| @@ -183,6 +182,31 @@ void ScaleIntegerComposite(IR::IREmitter& ir, IR::Inst& inst, const IR::U1& is_s | |||
| 183 | } | 182 | } |
| 184 | } | 183 | } |
| 185 | 184 | ||
| 185 | void ScaleIntegerOffsetComposite(IR::IREmitter& ir, IR::Inst& inst, const IR::U1& is_scaled, | ||
| 186 | size_t index) { | ||
| 187 | const IR::Value composite{inst.Arg(index)}; | ||
| 188 | if (composite.IsEmpty()) { | ||
| 189 | return; | ||
| 190 | } | ||
| 191 | const auto info{inst.Flags<IR::TextureInstInfo>()}; | ||
| 192 | const IR::U32 x{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(composite, 0)})}; | ||
| 193 | const IR::U32 y{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(composite, 1)})}; | ||
| 194 | switch (info.type) { | ||
| 195 | case TextureType::ColorArray2D: | ||
| 196 | case TextureType::Color2D: | ||
| 197 | inst.SetArg(index, ir.CompositeConstruct(x, y)); | ||
| 198 | break; | ||
| 199 | case TextureType::Color1D: | ||
| 200 | case TextureType::ColorArray1D: | ||
| 201 | case TextureType::Color3D: | ||
| 202 | case TextureType::ColorCube: | ||
| 203 | case TextureType::ColorArrayCube: | ||
| 204 | case TextureType::Buffer: | ||
| 205 | // Nothing to patch here | ||
| 206 | break; | ||
| 207 | } | ||
| 208 | } | ||
| 209 | |||
| 186 | void SubScaleCoord(IR::IREmitter& ir, IR::Inst& inst, const IR::U1& is_scaled) { | 210 | void SubScaleCoord(IR::IREmitter& ir, IR::Inst& inst, const IR::U1& is_scaled) { |
| 187 | const auto info{inst.Flags<IR::TextureInstInfo>()}; | 211 | const auto info{inst.Flags<IR::TextureInstInfo>()}; |
| 188 | const IR::Value coord{inst.Arg(1)}; | 212 | const IR::Value coord{inst.Arg(1)}; |
| @@ -220,7 +244,7 @@ void SubScaleImageFetch(IR::Block& block, IR::Inst& inst) { | |||
| 220 | const IR::U1 is_scaled{ir.IsTextureScaled(ir.Imm32(info.descriptor_index))}; | 244 | const IR::U1 is_scaled{ir.IsTextureScaled(ir.Imm32(info.descriptor_index))}; |
| 221 | SubScaleCoord(ir, inst, is_scaled); | 245 | SubScaleCoord(ir, inst, is_scaled); |
| 222 | // Scale ImageFetch offset | 246 | // Scale ImageFetch offset |
| 223 | ScaleIntegerComposite(ir, inst, is_scaled, 2); | 247 | ScaleIntegerOffsetComposite(ir, inst, is_scaled, 2); |
| 224 | } | 248 | } |
| 225 | 249 | ||
| 226 | void SubScaleImageRead(IR::Block& block, IR::Inst& inst) { | 250 | void SubScaleImageRead(IR::Block& block, IR::Inst& inst) { |
| @@ -242,7 +266,7 @@ void PatchImageFetch(IR::Block& block, IR::Inst& inst) { | |||
| 242 | const IR::U1 is_scaled{ir.IsTextureScaled(ir.Imm32(info.descriptor_index))}; | 266 | const IR::U1 is_scaled{ir.IsTextureScaled(ir.Imm32(info.descriptor_index))}; |
| 243 | ScaleIntegerComposite(ir, inst, is_scaled, 1); | 267 | ScaleIntegerComposite(ir, inst, is_scaled, 1); |
| 244 | // Scale ImageFetch offset | 268 | // Scale ImageFetch offset |
| 245 | ScaleIntegerComposite(ir, inst, is_scaled, 2); | 269 | ScaleIntegerOffsetComposite(ir, inst, is_scaled, 2); |
| 246 | } | 270 | } |
| 247 | 271 | ||
| 248 | void PatchImageRead(IR::Block& block, IR::Inst& inst) { | 272 | void PatchImageRead(IR::Block& block, IR::Inst& inst) { |
diff --git a/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp b/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp index 87aa09358..928557acb 100644 --- a/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp +++ b/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp | |||
| @@ -20,7 +20,6 @@ | |||
| 20 | #include <vector> | 20 | #include <vector> |
| 21 | 21 | ||
| 22 | #include <boost/container/flat_map.hpp> | 22 | #include <boost/container/flat_map.hpp> |
| 23 | #include <boost/container/flat_set.hpp> | ||
| 24 | 23 | ||
| 25 | #include "shader_recompiler/frontend/ir/basic_block.h" | 24 | #include "shader_recompiler/frontend/ir/basic_block.h" |
| 26 | #include "shader_recompiler/frontend/ir/opcodes.h" | 25 | #include "shader_recompiler/frontend/ir/opcodes.h" |
diff --git a/src/shader_recompiler/program_header.h b/src/shader_recompiler/program_header.h index bd6c2bfb5..0cd6597ef 100644 --- a/src/shader_recompiler/program_header.h +++ b/src/shader_recompiler/program_header.h | |||
| @@ -196,6 +196,11 @@ struct ProgramHeader { | |||
| 196 | return {(bits & 1) != 0, (bits & 2) != 0, (bits & 4) != 0, (bits & 8) != 0}; | 196 | return {(bits & 1) != 0, (bits & 2) != 0, (bits & 4) != 0, (bits & 8) != 0}; |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | [[nodiscard]] bool HasOutputComponents(u32 rt) const noexcept { | ||
| 200 | const u32 bits{omap.target >> (rt * 4)}; | ||
| 201 | return (bits & 0xf) != 0; | ||
| 202 | } | ||
| 203 | |||
| 199 | [[nodiscard]] std::array<PixelImap, 4> GenericInputMap(u32 attribute) const { | 204 | [[nodiscard]] std::array<PixelImap, 4> GenericInputMap(u32 attribute) const { |
| 200 | const auto& vector{imap_generic_vector[attribute]}; | 205 | const auto& vector{imap_generic_vector[attribute]}; |
| 201 | return {vector.x, vector.y, vector.z, vector.w}; | 206 | return {vector.x, vector.y, vector.z, vector.w}; |
diff --git a/src/shader_recompiler/runtime_info.h b/src/shader_recompiler/runtime_info.h index f3f83a258..722e9d729 100644 --- a/src/shader_recompiler/runtime_info.h +++ b/src/shader_recompiler/runtime_info.h | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <bitset> | ||
| 9 | #include <optional> | 8 | #include <optional> |
| 10 | #include <vector> | 9 | #include <vector> |
| 11 | 10 | ||
diff --git a/src/shader_recompiler/shader_info.h b/src/shader_recompiler/shader_info.h index 9f375c30e..a3a09c71c 100644 --- a/src/shader_recompiler/shader_info.h +++ b/src/shader_recompiler/shader_info.h | |||
| @@ -105,6 +105,7 @@ struct ImageDescriptor { | |||
| 105 | using ImageDescriptors = boost::container::small_vector<ImageDescriptor, 4>; | 105 | using ImageDescriptors = boost::container::small_vector<ImageDescriptor, 4>; |
| 106 | 106 | ||
| 107 | struct Info { | 107 | struct Info { |
| 108 | static constexpr size_t MAX_INDIRECT_CBUFS{14}; | ||
| 108 | static constexpr size_t MAX_CBUFS{18}; | 109 | static constexpr size_t MAX_CBUFS{18}; |
| 109 | static constexpr size_t MAX_SSBOS{32}; | 110 | static constexpr size_t MAX_SSBOS{32}; |
| 110 | 111 | ||
| @@ -173,9 +174,11 @@ struct Info { | |||
| 173 | bool uses_atomic_image_u32{}; | 174 | bool uses_atomic_image_u32{}; |
| 174 | bool uses_shadow_lod{}; | 175 | bool uses_shadow_lod{}; |
| 175 | bool uses_rescaling_uniform{}; | 176 | bool uses_rescaling_uniform{}; |
| 177 | bool uses_cbuf_indirect{}; | ||
| 176 | 178 | ||
| 177 | IR::Type used_constant_buffer_types{}; | 179 | IR::Type used_constant_buffer_types{}; |
| 178 | IR::Type used_storage_buffer_types{}; | 180 | IR::Type used_storage_buffer_types{}; |
| 181 | IR::Type used_indirect_cbuf_types{}; | ||
| 179 | 182 | ||
| 180 | u32 constant_buffer_mask{}; | 183 | u32 constant_buffer_mask{}; |
| 181 | std::array<u32, MAX_CBUFS> constant_buffer_used_sizes{}; | 184 | std::array<u32, MAX_CBUFS> constant_buffer_used_sizes{}; |