diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl.cpp | 17 | ||||
| -rw-r--r-- | src/shader_recompiler/backend/glsl/var_alloc.cpp | 34 | ||||
| -rw-r--r-- | src/shader_recompiler/backend/glsl/var_alloc.h | 5 |
3 files changed, 35 insertions, 21 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl.cpp b/src/shader_recompiler/backend/glsl/emit_glsl.cpp index 7b57c1e91..b189f6c11 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl.cpp | |||
| @@ -172,19 +172,28 @@ std::string GlslVersionSpecifier(const EmitContext& ctx) { | |||
| 172 | return ""; | 172 | return ""; |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | bool IsPreciseType(GlslVarType type) { | ||
| 176 | switch (type) { | ||
| 177 | case GlslVarType::PrecF32: | ||
| 178 | case GlslVarType::PrecF64: | ||
| 179 | return true; | ||
| 180 | default: | ||
| 181 | return false; | ||
| 182 | } | ||
| 183 | } | ||
| 184 | |||
| 175 | void DefineVariables(const EmitContext& ctx, std::string& header) { | 185 | void DefineVariables(const EmitContext& ctx, std::string& header) { |
| 176 | for (u32 i = 0; i < static_cast<u32>(GlslVarType::Void); ++i) { | 186 | for (u32 i = 0; i < static_cast<u32>(GlslVarType::Void); ++i) { |
| 177 | const auto type{static_cast<GlslVarType>(i)}; | 187 | const auto type{static_cast<GlslVarType>(i)}; |
| 178 | const auto& tracker{ctx.var_alloc.GetUseTracker(type)}; | 188 | const auto& tracker{ctx.var_alloc.GetUseTracker(type)}; |
| 179 | const auto type_name{ctx.var_alloc.GetGlslType(type)}; | 189 | const auto type_name{ctx.var_alloc.GetGlslType(type)}; |
| 180 | const auto precise{ | 190 | const auto precise{IsPreciseType(type) ? "precise " : ""}; |
| 181 | (type == GlslVarType::PrecF32 || type == GlslVarType::PrecF64) ? "precise " : ""}; | ||
| 182 | // Temps/return types that are never used are stored at index 0 | 191 | // Temps/return types that are never used are stored at index 0 |
| 183 | if (tracker.uses_temp) { | 192 | if (tracker.uses_temp) { |
| 184 | header += fmt::format("{}{} {}={}(0);", precise, type_name, | 193 | header += fmt::format("{}{} t{}={}(0);", precise, type_name, |
| 185 | ctx.var_alloc.Representation(0, type), type_name); | 194 | ctx.var_alloc.Representation(0, type), type_name); |
| 186 | } | 195 | } |
| 187 | for (u32 index = 1; index <= tracker.num_used; ++index) { | 196 | for (u32 index = 0; index < tracker.num_used; ++index) { |
| 188 | header += fmt::format("{}{} {}={}(0);", precise, type_name, | 197 | header += fmt::format("{}{} {}={}(0);", precise, type_name, |
| 189 | ctx.var_alloc.Representation(index, type), type_name); | 198 | ctx.var_alloc.Representation(index, type), type_name); |
| 190 | } | 199 | } |
diff --git a/src/shader_recompiler/backend/glsl/var_alloc.cpp b/src/shader_recompiler/backend/glsl/var_alloc.cpp index 0ae56651e..95e8233e2 100644 --- a/src/shader_recompiler/backend/glsl/var_alloc.cpp +++ b/src/shader_recompiler/backend/glsl/var_alloc.cpp | |||
| @@ -116,8 +116,8 @@ std::string VarAlloc::Define(IR::Inst& inst, GlslVarType type) { | |||
| 116 | id.type.Assign(type); | 116 | id.type.Assign(type); |
| 117 | GetUseTracker(type).uses_temp = true; | 117 | GetUseTracker(type).uses_temp = true; |
| 118 | inst.SetDefinition<Id>(id); | 118 | inst.SetDefinition<Id>(id); |
| 119 | return "t" + Representation(inst.Definition<Id>()); | ||
| 119 | } | 120 | } |
| 120 | return Representation(inst.Definition<Id>()); | ||
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | std::string VarAlloc::Define(IR::Inst& inst, IR::Type type) { | 123 | std::string VarAlloc::Define(IR::Inst& inst, IR::Type type) { |
| @@ -156,21 +156,27 @@ std::string VarAlloc::GetGlslType(IR::Type type) const { | |||
| 156 | 156 | ||
| 157 | Id VarAlloc::Alloc(GlslVarType type) { | 157 | Id VarAlloc::Alloc(GlslVarType type) { |
| 158 | auto& use_tracker{GetUseTracker(type)}; | 158 | auto& use_tracker{GetUseTracker(type)}; |
| 159 | if (use_tracker.num_used < NUM_VARS) { | 159 | const auto num_vars{use_tracker.var_use.size()}; |
| 160 | for (size_t var = 1; var < NUM_VARS; ++var) { | 160 | for (size_t var = 0; var < num_vars; ++var) { |
| 161 | if (use_tracker.var_use[var]) { | 161 | if (use_tracker.var_use[var]) { |
| 162 | continue; | 162 | continue; |
| 163 | } | ||
| 164 | use_tracker.num_used = std::max(use_tracker.num_used, var + 1); | ||
| 165 | use_tracker.var_use[var] = true; | ||
| 166 | Id ret{}; | ||
| 167 | ret.is_valid.Assign(1); | ||
| 168 | ret.type.Assign(type); | ||
| 169 | ret.index.Assign(static_cast<u32>(var)); | ||
| 170 | return ret; | ||
| 171 | } | 163 | } |
| 164 | use_tracker.num_used = std::max(use_tracker.num_used, var + 1); | ||
| 165 | use_tracker.var_use[var] = true; | ||
| 166 | Id ret{}; | ||
| 167 | ret.is_valid.Assign(1); | ||
| 168 | ret.type.Assign(type); | ||
| 169 | ret.index.Assign(static_cast<u32>(var)); | ||
| 170 | return ret; | ||
| 172 | } | 171 | } |
| 173 | throw NotImplementedException("Variable spilling"); | 172 | // Allocate a new variable |
| 173 | use_tracker.var_use.push_back(true); | ||
| 174 | Id ret{}; | ||
| 175 | ret.is_valid.Assign(1); | ||
| 176 | ret.type.Assign(type); | ||
| 177 | ret.index.Assign(static_cast<u32>(use_tracker.num_used)); | ||
| 178 | ++use_tracker.num_used; | ||
| 179 | return ret; | ||
| 174 | } | 180 | } |
| 175 | 181 | ||
| 176 | void VarAlloc::Free(Id id) { | 182 | void VarAlloc::Free(Id id) { |
diff --git a/src/shader_recompiler/backend/glsl/var_alloc.h b/src/shader_recompiler/backend/glsl/var_alloc.h index ed936f8dc..ab1d1acbd 100644 --- a/src/shader_recompiler/backend/glsl/var_alloc.h +++ b/src/shader_recompiler/backend/glsl/var_alloc.h | |||
| @@ -57,11 +57,10 @@ static_assert(sizeof(Id) == sizeof(u32)); | |||
| 57 | 57 | ||
| 58 | class VarAlloc { | 58 | class VarAlloc { |
| 59 | public: | 59 | public: |
| 60 | static constexpr size_t NUM_VARS = 1023; | ||
| 61 | struct UseTracker { | 60 | struct UseTracker { |
| 62 | size_t num_used{}; | ||
| 63 | std::bitset<NUM_VARS> var_use{}; | ||
| 64 | bool uses_temp{}; | 61 | bool uses_temp{}; |
| 62 | size_t num_used{}; | ||
| 63 | std::vector<bool> var_use; | ||
| 65 | }; | 64 | }; |
| 66 | 65 | ||
| 67 | /// Used for explicit usages of variables, may revert to temporaries | 66 | /// Used for explicit usages of variables, may revert to temporaries |