diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl/reg_alloc.h')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/reg_alloc.h | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/src/shader_recompiler/backend/glsl/reg_alloc.h b/src/shader_recompiler/backend/glsl/reg_alloc.h index a777cbbd2..9b98aab39 100644 --- a/src/shader_recompiler/backend/glsl/reg_alloc.h +++ b/src/shader_recompiler/backend/glsl/reg_alloc.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <bitset> | 7 | #include <bitset> |
| 8 | 8 | ||
| 9 | #include "common/bit_field.h" | ||
| 9 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 10 | 11 | ||
| 11 | namespace Shader::IR { | 12 | namespace Shader::IR { |
| @@ -14,18 +15,36 @@ class Value; | |||
| 14 | } // namespace Shader::IR | 15 | } // namespace Shader::IR |
| 15 | 16 | ||
| 16 | namespace Shader::Backend::GLSL { | 17 | namespace Shader::Backend::GLSL { |
| 18 | enum class Type : u32 { | ||
| 19 | U32, | ||
| 20 | S32, | ||
| 21 | F32, | ||
| 22 | U64, | ||
| 23 | F64, | ||
| 24 | Void, | ||
| 25 | }; | ||
| 17 | 26 | ||
| 18 | struct Id { | 27 | struct Id { |
| 19 | u32 base_element : 2; | 28 | union { |
| 20 | u32 num_elements_minus_one : 2; | 29 | u32 raw; |
| 21 | u32 index : 26; | 30 | BitField<0, 29, u32> index; |
| 22 | u32 is_spill : 1; | 31 | BitField<29, 1, u32> is_long; |
| 23 | u32 is_condition_code : 1; | 32 | BitField<30, 1, u32> is_spill; |
| 33 | BitField<31, 1, u32> is_condition_code; | ||
| 34 | }; | ||
| 35 | |||
| 36 | bool operator==(Id rhs) const noexcept { | ||
| 37 | return raw == rhs.raw; | ||
| 38 | } | ||
| 39 | bool operator!=(Id rhs) const noexcept { | ||
| 40 | return !operator==(rhs); | ||
| 41 | } | ||
| 24 | }; | 42 | }; |
| 43 | static_assert(sizeof(Id) == sizeof(u32)); | ||
| 25 | 44 | ||
| 26 | class RegAlloc { | 45 | class RegAlloc { |
| 27 | public: | 46 | public: |
| 28 | std::string Define(IR::Inst& inst, u32 num_elements = 1, u32 alignment = 1); | 47 | std::string Define(IR::Inst& inst, Type type = Type::Void); |
| 29 | 48 | ||
| 30 | std::string Consume(const IR::Value& value); | 49 | std::string Consume(const IR::Value& value); |
| 31 | 50 | ||
| @@ -40,13 +59,14 @@ private: | |||
| 40 | static constexpr size_t NUM_ELEMENTS = 4; | 59 | static constexpr size_t NUM_ELEMENTS = 4; |
| 41 | 60 | ||
| 42 | std::string Consume(IR::Inst& inst); | 61 | std::string Consume(IR::Inst& inst); |
| 62 | std::string GetType(Type type, u32 index); | ||
| 43 | 63 | ||
| 44 | Id Alloc(u32 num_elements, u32 alignment); | 64 | Id Alloc(); |
| 45 | |||
| 46 | void Free(Id id); | 65 | void Free(Id id); |
| 47 | 66 | ||
| 48 | size_t num_used_registers{}; | 67 | size_t num_used_registers{}; |
| 49 | std::bitset<NUM_REGS> register_use{}; | 68 | std::bitset<NUM_REGS> register_use{}; |
| 69 | std::bitset<NUM_REGS> register_defined{}; | ||
| 50 | }; | 70 | }; |
| 51 | 71 | ||
| 52 | } // namespace Shader::Backend::GLSL | 72 | } // namespace Shader::Backend::GLSL |