diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
9 files changed, 91 insertions, 49 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp index b9594de40..da29290a2 100644 --- a/src/shader_recompiler/backend/glsl/emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/emit_context.cpp | |||
| @@ -122,11 +122,9 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile | |||
| 122 | 122 | ||
| 123 | void EmitContext::SetupExtensions(std::string&) { | 123 | void EmitContext::SetupExtensions(std::string&) { |
| 124 | header += "#extension GL_ARB_separate_shader_objects : enable\n"; | 124 | header += "#extension GL_ARB_separate_shader_objects : enable\n"; |
| 125 | if (stage != Stage::Compute) { | 125 | // TODO: track this usage |
| 126 | // TODO: track this usage | 126 | header += "#extension GL_ARB_sparse_texture2 : enable\n"; |
| 127 | header += "#extension GL_ARB_sparse_texture2 : enable\n"; | 127 | header += "#extension GL_EXT_texture_shadow_lod : enable\n"; |
| 128 | header += "#extension GL_EXT_texture_shadow_lod : enable\n"; | ||
| 129 | } | ||
| 130 | if (info.uses_int64) { | 128 | if (info.uses_int64) { |
| 131 | header += "#extension GL_ARB_gpu_shader_int64 : enable\n"; | 129 | header += "#extension GL_ARB_gpu_shader_int64 : enable\n"; |
| 132 | } | 130 | } |
diff --git a/src/shader_recompiler/backend/glsl/emit_context.h b/src/shader_recompiler/backend/glsl/emit_context.h index 2f1062954..423fc6104 100644 --- a/src/shader_recompiler/backend/glsl/emit_context.h +++ b/src/shader_recompiler/backend/glsl/emit_context.h | |||
| @@ -37,7 +37,13 @@ public: | |||
| 37 | 37 | ||
| 38 | template <GlslVarType type, typename... Args> | 38 | template <GlslVarType type, typename... Args> |
| 39 | void Add(const char* format_str, IR::Inst& inst, Args&&... args) { | 39 | void Add(const char* format_str, IR::Inst& inst, Args&&... args) { |
| 40 | code += fmt::format(format_str, var_alloc.Define(inst, type), std::forward<Args>(args)...); | 40 | const auto var_def{var_alloc.AddDefine(inst, type)}; |
| 41 | if (var_def.empty()) { | ||
| 42 | // skip assigment. | ||
| 43 | code += fmt::format(&format_str[3], std::forward<Args>(args)...); | ||
| 44 | } else { | ||
| 45 | code += fmt::format(format_str, var_def, std::forward<Args>(args)...); | ||
| 46 | } | ||
| 41 | // TODO: Remove this | 47 | // TODO: Remove this |
| 42 | code += '\n'; | 48 | code += '\n'; |
| 43 | } | 49 | } |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp index 918f90058..db4c60002 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp | |||
| @@ -11,8 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | namespace Shader::Backend::GLSL { | 12 | namespace Shader::Backend::GLSL { |
| 13 | namespace { | 13 | namespace { |
| 14 | static constexpr std::string_view cas_loop{R"({}; | 14 | static constexpr std::string_view cas_loop{R"(for (;;){{ |
| 15 | for (;;){{ | ||
| 16 | uint old_value={}; | 15 | uint old_value={}; |
| 17 | {}=atomicCompSwap({},old_value,{}({},{})); | 16 | {}=atomicCompSwap({},old_value,{}({},{})); |
| 18 | if ({}==old_value){{break;}} | 17 | if ({}==old_value){{break;}} |
| @@ -22,14 +21,14 @@ void SharedCasFunction(EmitContext& ctx, IR::Inst& inst, std::string_view offset | |||
| 22 | std::string_view value, std::string_view function) { | 21 | std::string_view value, std::string_view function) { |
| 23 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; | 22 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; |
| 24 | const std::string smem{fmt::format("smem[{}/4]", offset)}; | 23 | const std::string smem{fmt::format("smem[{}/4]", offset)}; |
| 25 | ctx.Add(cas_loop.data(), ret, smem, ret, smem, function, smem, value, ret); | 24 | ctx.Add(cas_loop.data(), smem, ret, smem, function, smem, value, ret); |
| 26 | } | 25 | } |
| 27 | 26 | ||
| 28 | void SsboCasFunction(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 27 | void SsboCasFunction(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 29 | const IR::Value& offset, std::string_view value, std::string_view function) { | 28 | const IR::Value& offset, std::string_view value, std::string_view function) { |
| 30 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; | 29 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; |
| 31 | const std::string ssbo{fmt::format("ssbo{}[{}]", binding.U32(), offset.U32())}; | 30 | const std::string ssbo{fmt::format("ssbo{}[{}]", binding.U32(), offset.U32())}; |
| 32 | ctx.Add(cas_loop.data(), ret, ssbo, ret, ssbo, function, ssbo, value, ret); | 31 | ctx.Add(cas_loop.data(), ssbo, ret, ssbo, function, ssbo, value, ret); |
| 33 | } | 32 | } |
| 34 | 33 | ||
| 35 | void SsboCasFunctionF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 34 | void SsboCasFunctionF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| @@ -37,7 +36,7 @@ void SsboCasFunctionF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& bindi | |||
| 37 | std::string_view function) { | 36 | std::string_view function) { |
| 38 | const std::string ssbo{fmt::format("ssbo{}[{}]", binding.U32(), offset.U32())}; | 37 | const std::string ssbo{fmt::format("ssbo{}[{}]", binding.U32(), offset.U32())}; |
| 39 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; | 38 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; |
| 40 | ctx.Add(cas_loop.data(), ret, ssbo, ret, ssbo, function, ssbo, value, ret); | 39 | ctx.Add(cas_loop.data(), ssbo, ret, ssbo, function, ssbo, value, ret); |
| 41 | ctx.AddF32("{}=uintBitsToFloat({});", inst, ret); | 40 | ctx.AddF32("{}=uintBitsToFloat({});", inst, ret); |
| 42 | } | 41 | } |
| 43 | } // namespace | 42 | } // namespace |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp index 2b08aa593..9d844b831 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp | |||
| @@ -26,7 +26,13 @@ void EmitIdentity(EmitContext&, IR::Inst& inst, const IR::Value& value) { | |||
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | void EmitConditionRef(EmitContext& ctx, IR::Inst& inst, const IR::Value& value) { | 28 | void EmitConditionRef(EmitContext& ctx, IR::Inst& inst, const IR::Value& value) { |
| 29 | ctx.AddU1("{}={};", inst, ctx.var_alloc.Consume(value)); | 29 | // Fake one usage to get a real variable out of the condition |
| 30 | inst.DestructiveAddUsage(1); | ||
| 31 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U1)}; | ||
| 32 | const auto input{ctx.var_alloc.Consume(value)}; | ||
| 33 | if (ret != input) { | ||
| 34 | ctx.Add("{}={};", ret, input); | ||
| 35 | } | ||
| 30 | } | 36 | } |
| 31 | 37 | ||
| 32 | void EmitBitCastU16F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst) { | 38 | void EmitBitCastU16F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst) { |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp index 0fd667c8f..44a719fc3 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp | |||
| @@ -9,8 +9,14 @@ | |||
| 9 | #include "shader_recompiler/frontend/ir/value.h" | 9 | #include "shader_recompiler/frontend/ir/value.h" |
| 10 | 10 | ||
| 11 | namespace Shader::Backend::GLSL { | 11 | namespace Shader::Backend::GLSL { |
| 12 | namespace { | ||
| 12 | static constexpr std::string_view SWIZZLE{"xyzw"}; | 13 | static constexpr std::string_view SWIZZLE{"xyzw"}; |
| 13 | 14 | void CompositeInsert(EmitContext& ctx, std::string_view result, std::string_view composite, | |
| 15 | std::string_view object, u32 index) { | ||
| 16 | ctx.Add("{}={};", result, composite); | ||
| 17 | ctx.Add("{}.{}={};", result, SWIZZLE[index], object); | ||
| 18 | } | ||
| 19 | } // namespace | ||
| 14 | void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, | 20 | void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, |
| 15 | std::string_view e2) { | 21 | std::string_view e2) { |
| 16 | ctx.AddU32x2("{}=uvec2({},{});", inst, e1, e2); | 22 | ctx.AddU32x2("{}=uvec2({},{});", inst, e1, e2); |
| @@ -41,19 +47,22 @@ void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_vie | |||
| 41 | ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]); | 47 | ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]); |
| 42 | } | 48 | } |
| 43 | 49 | ||
| 44 | void EmitCompositeInsertU32x2(EmitContext& ctx, std::string_view composite, std::string_view object, | 50 | void EmitCompositeInsertU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 45 | u32 index) { | 51 | std::string_view object, u32 index) { |
| 46 | ctx.Add("{}.{}={};", composite, SWIZZLE[index], object); | 52 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x2)}; |
| 53 | CompositeInsert(ctx, ret, composite, object, index); | ||
| 47 | } | 54 | } |
| 48 | 55 | ||
| 49 | void EmitCompositeInsertU32x3(EmitContext& ctx, std::string_view composite, std::string_view object, | 56 | void EmitCompositeInsertU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 50 | u32 index) { | 57 | std::string_view object, u32 index) { |
| 51 | ctx.Add("{}.{}={};", composite, SWIZZLE[index], object); | 58 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x3)}; |
| 59 | CompositeInsert(ctx, ret, composite, object, index); | ||
| 52 | } | 60 | } |
| 53 | 61 | ||
| 54 | void EmitCompositeInsertU32x4(EmitContext& ctx, std::string_view composite, std::string_view object, | 62 | void EmitCompositeInsertU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 55 | u32 index) { | 63 | std::string_view object, u32 index) { |
| 56 | ctx.Add("{}.{}={};", composite, SWIZZLE[index], object); | 64 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x4)}; |
| 65 | CompositeInsert(ctx, ret, composite, object, index); | ||
| 57 | } | 66 | } |
| 58 | 67 | ||
| 59 | void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx, | 68 | void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx, |
| @@ -146,19 +155,22 @@ void EmitCompositeExtractF32x4(EmitContext& ctx, IR::Inst& inst, std::string_vie | |||
| 146 | ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]); | 155 | ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]); |
| 147 | } | 156 | } |
| 148 | 157 | ||
| 149 | void EmitCompositeInsertF32x2(EmitContext& ctx, std::string_view composite, std::string_view object, | 158 | void EmitCompositeInsertF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 150 | u32 index) { | 159 | std::string_view object, u32 index) { |
| 151 | ctx.Add("{}.{}={};", composite, SWIZZLE[index], object); | 160 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x2)}; |
| 161 | CompositeInsert(ctx, ret, composite, object, index); | ||
| 152 | } | 162 | } |
| 153 | 163 | ||
| 154 | void EmitCompositeInsertF32x3(EmitContext& ctx, std::string_view composite, std::string_view object, | 164 | void EmitCompositeInsertF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 155 | u32 index) { | 165 | std::string_view object, u32 index) { |
| 156 | ctx.Add("{}.{}={};", composite, SWIZZLE[index], object); | 166 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x3)}; |
| 167 | CompositeInsert(ctx, ret, composite, object, index); | ||
| 157 | } | 168 | } |
| 158 | 169 | ||
| 159 | void EmitCompositeInsertF32x4(EmitContext& ctx, std::string_view composite, std::string_view object, | 170 | void EmitCompositeInsertF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 160 | u32 index) { | 171 | std::string_view object, u32 index) { |
| 161 | ctx.Add("{}.{}={};", composite, SWIZZLE[index], object); | 172 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x4)}; |
| 173 | CompositeInsert(ctx, ret, composite, object, index); | ||
| 162 | } | 174 | } |
| 163 | 175 | ||
| 164 | void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) { | 176 | void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) { |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h index 703db80ee..c2e5aff16 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h +++ b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h | |||
| @@ -26,7 +26,7 @@ void EmitPhi(EmitContext& ctx, IR::Inst& inst); | |||
| 26 | void EmitVoid(EmitContext& ctx); | 26 | void EmitVoid(EmitContext& ctx); |
| 27 | void EmitIdentity(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 27 | void EmitIdentity(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 28 | void EmitConditionRef(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 28 | void EmitConditionRef(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 29 | void EmitReference(EmitContext&); | 29 | void EmitReference(EmitContext& ctx, const IR::Value& value); |
| 30 | void EmitPhiMove(EmitContext& ctx, const IR::Value& phi, const IR::Value& value); | 30 | void EmitPhiMove(EmitContext& ctx, const IR::Value& phi, const IR::Value& value); |
| 31 | void EmitBranch(EmitContext& ctx, std::string_view label); | 31 | void EmitBranch(EmitContext& ctx, std::string_view label); |
| 32 | void EmitBranchConditional(EmitContext& ctx, std::string_view condition, | 32 | void EmitBranchConditional(EmitContext& ctx, std::string_view condition, |
| @@ -165,12 +165,12 @@ void EmitCompositeExtractU32x3(EmitContext& ctx, IR::Inst& inst, std::string_vie | |||
| 165 | u32 index); | 165 | u32 index); |
| 166 | void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite, | 166 | void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 167 | u32 index); | 167 | u32 index); |
| 168 | void EmitCompositeInsertU32x2(EmitContext& ctx, std::string_view composite, std::string_view object, | 168 | void EmitCompositeInsertU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 169 | u32 index); | 169 | std::string_view object, u32 index); |
| 170 | void EmitCompositeInsertU32x3(EmitContext& ctx, std::string_view composite, std::string_view object, | 170 | void EmitCompositeInsertU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 171 | u32 index); | 171 | std::string_view object, u32 index); |
| 172 | void EmitCompositeInsertU32x4(EmitContext& ctx, std::string_view composite, std::string_view object, | 172 | void EmitCompositeInsertU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 173 | u32 index); | 173 | std::string_view object, u32 index); |
| 174 | void EmitCompositeConstructF16x2(EmitContext& ctx, std::string_view e1, std::string_view e2); | 174 | void EmitCompositeConstructF16x2(EmitContext& ctx, std::string_view e1, std::string_view e2); |
| 175 | void EmitCompositeConstructF16x3(EmitContext& ctx, std::string_view e1, std::string_view e2, | 175 | void EmitCompositeConstructF16x3(EmitContext& ctx, std::string_view e1, std::string_view e2, |
| 176 | std::string_view e3); | 176 | std::string_view e3); |
| @@ -197,12 +197,12 @@ void EmitCompositeExtractF32x3(EmitContext& ctx, IR::Inst& inst, std::string_vie | |||
| 197 | u32 index); | 197 | u32 index); |
| 198 | void EmitCompositeExtractF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite, | 198 | void EmitCompositeExtractF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 199 | u32 index); | 199 | u32 index); |
| 200 | void EmitCompositeInsertF32x2(EmitContext& ctx, std::string_view composite, std::string_view object, | 200 | void EmitCompositeInsertF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 201 | u32 index); | 201 | std::string_view object, u32 index); |
| 202 | void EmitCompositeInsertF32x3(EmitContext& ctx, std::string_view composite, std::string_view object, | 202 | void EmitCompositeInsertF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 203 | u32 index); | 203 | std::string_view object, u32 index); |
| 204 | void EmitCompositeInsertF32x4(EmitContext& ctx, std::string_view composite, std::string_view object, | 204 | void EmitCompositeInsertF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 205 | u32 index); | 205 | std::string_view object, u32 index); |
| 206 | void EmitCompositeConstructF64x2(EmitContext& ctx); | 206 | void EmitCompositeConstructF64x2(EmitContext& ctx); |
| 207 | void EmitCompositeConstructF64x3(EmitContext& ctx); | 207 | void EmitCompositeConstructF64x3(EmitContext& ctx); |
| 208 | void EmitCompositeConstructF64x4(EmitContext& ctx); | 208 | void EmitCompositeConstructF64x4(EmitContext& ctx); |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp index 806c4777b..599ff90e0 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp | |||
| @@ -25,7 +25,7 @@ void EmitPhi(EmitContext& ctx, IR::Inst& phi) { | |||
| 25 | } | 25 | } |
| 26 | if (!phi.Definition<Id>().is_valid) { | 26 | if (!phi.Definition<Id>().is_valid) { |
| 27 | // The phi node wasn't forward defined | 27 | // The phi node wasn't forward defined |
| 28 | ctx.Add("{};", ctx.var_alloc.Define(phi, phi.Arg(0).Type())); | 28 | ctx.var_alloc.PhiDefine(phi, phi.Arg(0).Type()); |
| 29 | } | 29 | } |
| 30 | } | 30 | } |
| 31 | 31 | ||
| @@ -33,8 +33,8 @@ void EmitVoid(EmitContext& ctx) { | |||
| 33 | // NotImplemented(); | 33 | // NotImplemented(); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | void EmitReference(EmitContext&) { | 36 | void EmitReference(EmitContext& ctx, const IR::Value& value) { |
| 37 | // NotImplemented(); | 37 | ctx.var_alloc.Consume(value); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | void EmitPhiMove(EmitContext& ctx, const IR::Value& phi_value, const IR::Value& value) { | 40 | void EmitPhiMove(EmitContext& ctx, const IR::Value& phi_value, const IR::Value& value) { |
| @@ -42,7 +42,7 @@ void EmitPhiMove(EmitContext& ctx, const IR::Value& phi_value, const IR::Value& | |||
| 42 | const auto phi_type{phi.Arg(0).Type()}; | 42 | const auto phi_type{phi.Arg(0).Type()}; |
| 43 | if (!phi.Definition<Id>().is_valid) { | 43 | if (!phi.Definition<Id>().is_valid) { |
| 44 | // The phi node wasn't forward defined | 44 | // The phi node wasn't forward defined |
| 45 | ctx.Add("{};", ctx.var_alloc.Define(phi, phi_type)); | 45 | ctx.var_alloc.PhiDefine(phi, phi_type); |
| 46 | } | 46 | } |
| 47 | const auto phi_reg{ctx.var_alloc.Consume(IR::Value{&phi})}; | 47 | const auto phi_reg{ctx.var_alloc.Consume(IR::Value{&phi})}; |
| 48 | const auto val_reg{ctx.var_alloc.Consume(value)}; | 48 | const auto val_reg{ctx.var_alloc.Consume(value)}; |
diff --git a/src/shader_recompiler/backend/glsl/var_alloc.cpp b/src/shader_recompiler/backend/glsl/var_alloc.cpp index 8c6944f07..896457248 100644 --- a/src/shader_recompiler/backend/glsl/var_alloc.cpp +++ b/src/shader_recompiler/backend/glsl/var_alloc.cpp | |||
| @@ -110,7 +110,6 @@ std::string VarAlloc::Define(IR::Inst& inst, GlslVarType type) { | |||
| 110 | } else { | 110 | } else { |
| 111 | Id id{}; | 111 | Id id{}; |
| 112 | id.type.Assign(type); | 112 | id.type.Assign(type); |
| 113 | // id.is_null.Assign(1); | ||
| 114 | GetUseTracker(type).uses_temp = true; | 113 | GetUseTracker(type).uses_temp = true; |
| 115 | inst.SetDefinition<Id>(id); | 114 | inst.SetDefinition<Id>(id); |
| 116 | } | 115 | } |
| @@ -121,6 +120,20 @@ std::string VarAlloc::Define(IR::Inst& inst, IR::Type type) { | |||
| 121 | return Define(inst, RegType(type)); | 120 | return Define(inst, RegType(type)); |
| 122 | } | 121 | } |
| 123 | 122 | ||
| 123 | std::string VarAlloc::PhiDefine(IR::Inst& inst, IR::Type type) { | ||
| 124 | return AddDefine(inst, RegType(type)); | ||
| 125 | } | ||
| 126 | |||
| 127 | std::string VarAlloc::AddDefine(IR::Inst& inst, GlslVarType type) { | ||
| 128 | if (inst.HasUses()) { | ||
| 129 | inst.SetDefinition<Id>(Alloc(type)); | ||
| 130 | return Representation(inst.Definition<Id>()); | ||
| 131 | } else { | ||
| 132 | return ""; | ||
| 133 | } | ||
| 134 | return Representation(inst.Definition<Id>()); | ||
| 135 | } | ||
| 136 | |||
| 124 | std::string VarAlloc::Consume(const IR::Value& value) { | 137 | std::string VarAlloc::Consume(const IR::Value& value) { |
| 125 | return value.IsImmediate() ? MakeImm(value) : ConsumeInst(*value.InstRecursive()); | 138 | return value.IsImmediate() ? MakeImm(value) : ConsumeInst(*value.InstRecursive()); |
| 126 | } | 139 | } |
| @@ -223,6 +236,8 @@ VarAlloc::UseTracker& VarAlloc::GetUseTracker(GlslVarType type) { | |||
| 223 | switch (type) { | 236 | switch (type) { |
| 224 | case GlslVarType::U1: | 237 | case GlslVarType::U1: |
| 225 | return var_bool; | 238 | return var_bool; |
| 239 | case GlslVarType::F16x2: | ||
| 240 | return var_f16x2; | ||
| 226 | case GlslVarType::U32: | 241 | case GlslVarType::U32: |
| 227 | return var_u32; | 242 | return var_u32; |
| 228 | case GlslVarType::S32: | 243 | case GlslVarType::S32: |
diff --git a/src/shader_recompiler/backend/glsl/var_alloc.h b/src/shader_recompiler/backend/glsl/var_alloc.h index 29d78a571..574960b1a 100644 --- a/src/shader_recompiler/backend/glsl/var_alloc.h +++ b/src/shader_recompiler/backend/glsl/var_alloc.h | |||
| @@ -62,9 +62,15 @@ public: | |||
| 62 | bool uses_temp{}; | 62 | bool uses_temp{}; |
| 63 | }; | 63 | }; |
| 64 | 64 | ||
| 65 | /// Used for explicit usages of variables, may revert to temporaries | ||
| 65 | std::string Define(IR::Inst& inst, GlslVarType type); | 66 | std::string Define(IR::Inst& inst, GlslVarType type); |
| 66 | std::string Define(IR::Inst& inst, IR::Type type); | 67 | std::string Define(IR::Inst& inst, IR::Type type); |
| 67 | 68 | ||
| 69 | /// Used to assign variables used by the IR. May return a blank string if | ||
| 70 | /// the instruction's result is unused in the IR. | ||
| 71 | std::string AddDefine(IR::Inst& inst, GlslVarType type); | ||
| 72 | std::string PhiDefine(IR::Inst& inst, IR::Type type); | ||
| 73 | |||
| 68 | std::string Consume(const IR::Value& value); | 74 | std::string Consume(const IR::Value& value); |
| 69 | std::string ConsumeInst(IR::Inst& inst); | 75 | std::string ConsumeInst(IR::Inst& inst); |
| 70 | 76 | ||