diff options
| author | 2021-05-07 06:31:30 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:30 -0400 | |
| commit | c1ba685d9c9b9ca9e8c479c52097adf943e804eb (patch) | |
| tree | 015e58378db727b8df4089570ad224e7439b281a /src/shader_recompiler/backend/glasm/reg_alloc.cpp | |
| parent | vk_scheduler: Use locks instead of SPSC a queue (diff) | |
| download | yuzu-c1ba685d9c9b9ca9e8c479c52097adf943e804eb.tar.gz yuzu-c1ba685d9c9b9ca9e8c479c52097adf943e804eb.tar.xz yuzu-c1ba685d9c9b9ca9e8c479c52097adf943e804eb.zip | |
glasm: Changes to GLASM register allocator and emit context
Diffstat (limited to 'src/shader_recompiler/backend/glasm/reg_alloc.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glasm/reg_alloc.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/shader_recompiler/backend/glasm/reg_alloc.cpp b/src/shader_recompiler/backend/glasm/reg_alloc.cpp index 0460a394b..55e8107e9 100644 --- a/src/shader_recompiler/backend/glasm/reg_alloc.cpp +++ b/src/shader_recompiler/backend/glasm/reg_alloc.cpp | |||
| @@ -3,18 +3,16 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string> | 5 | #include <string> |
| 6 | #include <string_view> | ||
| 7 | 6 | ||
| 8 | #include <fmt/format.h> | 7 | #include <fmt/format.h> |
| 9 | 8 | ||
| 9 | #include "shader_recompiler/backend/glasm/emit_context.h" | ||
| 10 | #include "shader_recompiler/backend/glasm/reg_alloc.h" | 10 | #include "shader_recompiler/backend/glasm/reg_alloc.h" |
| 11 | #include "shader_recompiler/exception.h" | 11 | #include "shader_recompiler/exception.h" |
| 12 | #include "shader_recompiler/frontend/ir/value.h" | 12 | #include "shader_recompiler/frontend/ir/value.h" |
| 13 | 13 | ||
| 14 | namespace Shader::Backend::GLASM { | 14 | namespace Shader::Backend::GLASM { |
| 15 | namespace { | 15 | namespace { |
| 16 | constexpr std::string_view SWIZZLE = "xyzw"; | ||
| 17 | |||
| 18 | std::string Representation(Id id) { | 16 | std::string Representation(Id id) { |
| 19 | if (id.is_condition_code != 0) { | 17 | if (id.is_condition_code != 0) { |
| 20 | throw NotImplementedException("Condition code"); | 18 | throw NotImplementedException("Condition code"); |
| @@ -22,27 +20,36 @@ std::string Representation(Id id) { | |||
| 22 | if (id.is_spill != 0) { | 20 | if (id.is_spill != 0) { |
| 23 | throw NotImplementedException("Spilling"); | 21 | throw NotImplementedException("Spilling"); |
| 24 | } | 22 | } |
| 25 | const u32 num_elements{id.num_elements_minus_one + 1}; | ||
| 26 | const u32 index{static_cast<u32>(id.index)}; | 23 | const u32 index{static_cast<u32>(id.index)}; |
| 27 | if (num_elements == 4) { | 24 | return fmt::format("R{}.x", index); |
| 28 | return fmt::format("R{}", index); | 25 | } |
| 29 | } else { | 26 | |
| 30 | return fmt::format("R{}.{}", index, SWIZZLE.substr(id.base_element, num_elements)); | 27 | std::string ImmValue(const IR::Value& value) { |
| 28 | switch (value.Type()) { | ||
| 29 | case IR::Type::U1: | ||
| 30 | return value.U1() ? "-1" : "0"; | ||
| 31 | case IR::Type::U32: | ||
| 32 | return fmt::format("{}", value.U32()); | ||
| 33 | case IR::Type::F32: | ||
| 34 | return fmt::format("{}", value.F32()); | ||
| 35 | default: | ||
| 36 | throw NotImplementedException("Immediate type", value.Type()); | ||
| 31 | } | 37 | } |
| 32 | } | 38 | } |
| 33 | } // Anonymous namespace | 39 | } // Anonymous namespace |
| 34 | 40 | ||
| 35 | std::string RegAlloc::Define(IR::Inst& inst, u32 num_elements, u32 alignment) { | 41 | std::string RegAlloc::Define(IR::Inst& inst) { |
| 36 | const Id id{Alloc(num_elements, alignment)}; | 42 | const Id id{Alloc()}; |
| 37 | inst.SetDefinition<Id>(id); | 43 | inst.SetDefinition<Id>(id); |
| 38 | return Representation(id); | 44 | return Representation(id); |
| 39 | } | 45 | } |
| 40 | 46 | ||
| 41 | std::string RegAlloc::Consume(const IR::Value& value) { | 47 | std::string RegAlloc::Consume(const IR::Value& value) { |
| 42 | if (!value.IsImmediate()) { | 48 | if (value.IsImmediate()) { |
| 43 | return Consume(*value.Inst()); | 49 | return ImmValue(value); |
| 50 | } else { | ||
| 51 | return Consume(*value.InstRecursive()); | ||
| 44 | } | 52 | } |
| 45 | throw NotImplementedException("Immediate loading"); | ||
| 46 | } | 53 | } |
| 47 | 54 | ||
| 48 | std::string RegAlloc::Consume(IR::Inst& inst) { | 55 | std::string RegAlloc::Consume(IR::Inst& inst) { |
| @@ -54,7 +61,7 @@ std::string RegAlloc::Consume(IR::Inst& inst) { | |||
| 54 | return Representation(inst.Definition<Id>()); | 61 | return Representation(inst.Definition<Id>()); |
| 55 | } | 62 | } |
| 56 | 63 | ||
| 57 | Id RegAlloc::Alloc(u32 num_elements, [[maybe_unused]] u32 alignment) { | 64 | Id RegAlloc::Alloc() { |
| 58 | for (size_t reg = 0; reg < NUM_REGS; ++reg) { | 65 | for (size_t reg = 0; reg < NUM_REGS; ++reg) { |
| 59 | if (register_use[reg]) { | 66 | if (register_use[reg]) { |
| 60 | continue; | 67 | continue; |
| @@ -62,8 +69,6 @@ Id RegAlloc::Alloc(u32 num_elements, [[maybe_unused]] u32 alignment) { | |||
| 62 | num_used_registers = std::max(num_used_registers, reg + 1); | 69 | num_used_registers = std::max(num_used_registers, reg + 1); |
| 63 | register_use[reg] = true; | 70 | register_use[reg] = true; |
| 64 | return Id{ | 71 | return Id{ |
| 65 | .base_element = 0, | ||
| 66 | .num_elements_minus_one = num_elements - 1, | ||
| 67 | .index = static_cast<u32>(reg), | 72 | .index = static_cast<u32>(reg), |
| 68 | .is_spill = 0, | 73 | .is_spill = 0, |
| 69 | .is_condition_code = 0, | 74 | .is_condition_code = 0, |