diff options
12 files changed, 133 insertions, 72 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp index de19e0fba..2bf0def82 100644 --- a/src/shader_recompiler/backend/glsl/emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/emit_context.cpp | |||
| @@ -88,6 +88,7 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile | |||
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | void EmitContext::SetupExtensions(std::string& header) { | 90 | void EmitContext::SetupExtensions(std::string& header) { |
| 91 | header += "#extension GL_ARB_separate_shader_objects : enable\n"; | ||
| 91 | if (info.uses_int64) { | 92 | if (info.uses_int64) { |
| 92 | header += "#extension GL_ARB_gpu_shader_int64 : enable\n"; | 93 | header += "#extension GL_ARB_gpu_shader_int64 : enable\n"; |
| 93 | } | 94 | } |
diff --git a/src/shader_recompiler/backend/glsl/emit_context.h b/src/shader_recompiler/backend/glsl/emit_context.h index 1cd051b24..66f70d355 100644 --- a/src/shader_recompiler/backend/glsl/emit_context.h +++ b/src/shader_recompiler/backend/glsl/emit_context.h | |||
| @@ -91,6 +91,21 @@ public: | |||
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | template <typename... Args> | 93 | template <typename... Args> |
| 94 | void AddU32x3(const char* format_str, IR::Inst& inst, Args&&... args) { | ||
| 95 | Add<Type::U32x3>(format_str, inst, args...); | ||
| 96 | } | ||
| 97 | |||
| 98 | template <typename... Args> | ||
| 99 | void AddF32x3(const char* format_str, IR::Inst& inst, Args&&... args) { | ||
| 100 | Add<Type::F32x3>(format_str, inst, args...); | ||
| 101 | } | ||
| 102 | |||
| 103 | template <typename... Args> | ||
| 104 | void AddU32x4(const char* format_str, IR::Inst& inst, Args&&... args) { | ||
| 105 | Add<Type::U32x4>(format_str, inst, args...); | ||
| 106 | } | ||
| 107 | |||
| 108 | template <typename... Args> | ||
| 94 | void AddF32x4(const char* format_str, IR::Inst& inst, Args&&... args) { | 109 | void AddF32x4(const char* format_str, IR::Inst& inst, Args&&... args) { |
| 95 | Add<Type::F32x4>(format_str, inst, args...); | 110 | Add<Type::F32x4>(format_str, inst, args...); |
| 96 | } | 111 | } |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl.cpp b/src/shader_recompiler/backend/glsl/emit_glsl.cpp index 35dbe19ec..644da43f4 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl.cpp | |||
| @@ -160,8 +160,13 @@ void EmitCode(EmitContext& ctx, const IR::Program& program) { | |||
| 160 | ctx.Add("return;"); | 160 | ctx.Add("return;"); |
| 161 | break; | 161 | break; |
| 162 | case IR::AbstractSyntaxNode::Type::Loop: | 162 | case IR::AbstractSyntaxNode::Type::Loop: |
| 163 | ctx.Add("do{{"); | ||
| 164 | break; | ||
| 163 | case IR::AbstractSyntaxNode::Type::Repeat: | 165 | case IR::AbstractSyntaxNode::Type::Repeat: |
| 166 | ctx.Add("}}while({});", ctx.reg_alloc.Consume(node.data.repeat.cond)); | ||
| 167 | break; | ||
| 164 | default: | 168 | default: |
| 169 | fmt::print("{}", node.type); | ||
| 165 | throw NotImplementedException("{}", node.type); | 170 | throw NotImplementedException("{}", node.type); |
| 166 | break; | 171 | break; |
| 167 | } | 172 | } |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp index 048b12f38..aa966a304 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp | |||
| @@ -17,19 +17,14 @@ void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_v | |||
| 17 | ctx.AddU32x2("{}=uvec2({},{});", inst, e1, e2); | 17 | ctx.AddU32x2("{}=uvec2({},{});", inst, e1, e2); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | void EmitCompositeConstructU32x3([[maybe_unused]] EmitContext& ctx, | 20 | void EmitCompositeConstructU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1, |
| 21 | [[maybe_unused]] std::string_view e1, | 21 | std::string_view e2, std::string_view e3) { |
| 22 | [[maybe_unused]] std::string_view e2, | 22 | ctx.AddU32x3("{}=uvec3({},{},{});", inst, e1, e2, e3); |
| 23 | [[maybe_unused]] std::string_view e3) { | ||
| 24 | throw NotImplementedException("GLSL Instruction"); | ||
| 25 | } | 23 | } |
| 26 | 24 | ||
| 27 | void EmitCompositeConstructU32x4([[maybe_unused]] EmitContext& ctx, | 25 | void EmitCompositeConstructU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1, |
| 28 | [[maybe_unused]] std::string_view e1, | 26 | std::string_view e2, std::string_view e3, std::string_view e4) { |
| 29 | [[maybe_unused]] std::string_view e2, | 27 | ctx.AddU32x4("{}=uvec4({},{},{},{});", inst, e1, e2, e3, e4); |
| 30 | [[maybe_unused]] std::string_view e3, | ||
| 31 | [[maybe_unused]] std::string_view e4) { | ||
| 32 | throw NotImplementedException("GLSL Instruction"); | ||
| 33 | } | 28 | } |
| 34 | 29 | ||
| 35 | void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, | 30 | void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| @@ -37,16 +32,14 @@ void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_vie | |||
| 37 | ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]); | 32 | ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]); |
| 38 | } | 33 | } |
| 39 | 34 | ||
| 40 | void EmitCompositeExtractU32x3([[maybe_unused]] EmitContext& ctx, | 35 | void EmitCompositeExtractU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 41 | [[maybe_unused]] std::string_view composite, | 36 | u32 index) { |
| 42 | [[maybe_unused]] u32 index) { | 37 | ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]); |
| 43 | throw NotImplementedException("GLSL Instruction"); | ||
| 44 | } | 38 | } |
| 45 | 39 | ||
| 46 | void EmitCompositeExtractU32x4([[maybe_unused]] EmitContext& ctx, | 40 | void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 47 | [[maybe_unused]] std::string_view composite, | 41 | u32 index) { |
| 48 | [[maybe_unused]] u32 index) { | 42 | ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]); |
| 49 | throw NotImplementedException("GLSL Instruction"); | ||
| 50 | } | 43 | } |
| 51 | 44 | ||
| 52 | void EmitCompositeInsertU32x2([[maybe_unused]] EmitContext& ctx, | 45 | void EmitCompositeInsertU32x2([[maybe_unused]] EmitContext& ctx, |
| @@ -135,19 +128,14 @@ void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_v | |||
| 135 | ctx.AddF32x2("{}=vec2({},{});", inst, e1, e2); | 128 | ctx.AddF32x2("{}=vec2({},{});", inst, e1, e2); |
| 136 | } | 129 | } |
| 137 | 130 | ||
| 138 | void EmitCompositeConstructF32x3([[maybe_unused]] EmitContext& ctx, | 131 | void EmitCompositeConstructF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1, |
| 139 | [[maybe_unused]] std::string_view e1, | 132 | std::string_view e2, std::string_view e3) { |
| 140 | [[maybe_unused]] std::string_view e2, | 133 | ctx.AddF32x3("{}=vec3({},{},{});", inst, e1, e2, e3); |
| 141 | [[maybe_unused]] std::string_view e3) { | ||
| 142 | throw NotImplementedException("GLSL Instruction"); | ||
| 143 | } | 134 | } |
| 144 | 135 | ||
| 145 | void EmitCompositeConstructF32x4([[maybe_unused]] EmitContext& ctx, | 136 | void EmitCompositeConstructF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1, |
| 146 | [[maybe_unused]] std::string_view e1, | 137 | std::string_view e2, std::string_view e3, std::string_view e4) { |
| 147 | [[maybe_unused]] std::string_view e2, | 138 | ctx.AddF32x4("{}=vec4({},{},{},{});", inst, e1, e2, e3, e4); |
| 148 | [[maybe_unused]] std::string_view e3, | ||
| 149 | [[maybe_unused]] std::string_view e4) { | ||
| 150 | throw NotImplementedException("GLSL Instruction"); | ||
| 151 | } | 139 | } |
| 152 | 140 | ||
| 153 | void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, | 141 | void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
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 441818c0b..796f01883 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 | |||
| @@ -10,8 +10,18 @@ | |||
| 10 | #include "shader_recompiler/profile.h" | 10 | #include "shader_recompiler/profile.h" |
| 11 | 11 | ||
| 12 | namespace Shader::Backend::GLSL { | 12 | namespace Shader::Backend::GLSL { |
| 13 | namespace { | ||
| 13 | static constexpr std::string_view SWIZZLE{"xyzw"}; | 14 | static constexpr std::string_view SWIZZLE{"xyzw"}; |
| 14 | 15 | ||
| 16 | u32 CbufIndex(u32 offset) { | ||
| 17 | return (offset / 4) % 4; | ||
| 18 | } | ||
| 19 | |||
| 20 | char OffsetSwizzle(u32 offset) { | ||
| 21 | return SWIZZLE[CbufIndex(offset)]; | ||
| 22 | } | ||
| 23 | } // namespace | ||
| 24 | |||
| 15 | void EmitGetCbufU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding, | 25 | void EmitGetCbufU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding, |
| 16 | [[maybe_unused]] const IR::Value& offset) { | 26 | [[maybe_unused]] const IR::Value& offset) { |
| 17 | throw NotImplementedException("GLSL"); | 27 | throw NotImplementedException("GLSL"); |
| @@ -34,22 +44,42 @@ void EmitGetCbufS16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR | |||
| 34 | 44 | ||
| 35 | void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 45 | void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 36 | const IR::Value& offset) { | 46 | const IR::Value& offset) { |
| 37 | const auto u32_offset{offset.U32()}; | 47 | if (offset.IsImmediate()) { |
| 38 | const auto index{(u32_offset / 4) % 4}; | 48 | ctx.AddU32("{}=floatBitsToUint(cbuf{}[{}].{});", inst, binding.U32(), offset.U32() / 16, |
| 39 | ctx.AddU32("{}=floatBitsToUint(cbuf{}[{}].{});", inst, binding.U32(), u32_offset / 16, | 49 | OffsetSwizzle(offset.U32())); |
| 40 | SWIZZLE[index]); | 50 | } else { |
| 51 | const auto offset_var{ctx.reg_alloc.Consume(offset)}; | ||
| 52 | ctx.AddU32("{}=floatBitsToUint(cbuf{}[{}/16][({}/4)%4]);", inst, binding.U32(), offset_var, | ||
| 53 | offset_var); | ||
| 54 | } | ||
| 41 | } | 55 | } |
| 42 | 56 | ||
| 43 | void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 57 | void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 44 | const IR::Value& offset) { | 58 | const IR::Value& offset) { |
| 45 | const auto u32_offset{offset.U32()}; | 59 | if (offset.IsImmediate()) { |
| 46 | const auto index{(u32_offset / 4) % 4}; | 60 | ctx.AddF32("{}=cbuf{}[{}].{};", inst, binding.U32(), offset.U32() / 16, |
| 47 | ctx.AddF32("{}=cbuf{}[{}].{};", inst, binding.U32(), u32_offset / 16, SWIZZLE[index]); | 61 | OffsetSwizzle(offset.U32())); |
| 62 | } else { | ||
| 63 | const auto offset_var{ctx.reg_alloc.Consume(offset)}; | ||
| 64 | ctx.AddF32("{}=cbuf{}[{}/16][({}/4)%4];", inst, binding.U32(), offset_var, offset_var); | ||
| 65 | } | ||
| 48 | } | 66 | } |
| 49 | 67 | ||
| 50 | void EmitGetCbufU32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding, | 68 | void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 51 | [[maybe_unused]] const IR::Value& offset) { | 69 | const IR::Value& offset) { |
| 52 | throw NotImplementedException("GLSL"); | 70 | if (offset.IsImmediate()) { |
| 71 | const auto u32_offset{offset.U32()}; | ||
| 72 | const auto index{(u32_offset / 4) % 4}; | ||
| 73 | ctx.AddU32x2("{}=uvec2(floatBitsToUint(cbuf{}[{}].{}),floatBitsToUint(cbuf{}[{}].{}));", | ||
| 74 | inst, binding.U32(), offset.U32() / 16, OffsetSwizzle(offset.U32()), | ||
| 75 | binding.U32(), (offset.U32() + 1) / 16, OffsetSwizzle(offset.U32() + 1)); | ||
| 76 | } else { | ||
| 77 | const auto offset_var{ctx.reg_alloc.Consume(offset)}; | ||
| 78 | ctx.AddU32x2("{}=uvec2(floatBitsToUint(cbuf{}[{}/16][({}/" | ||
| 79 | "4)%4]),floatBitsToUint(cbuf{}[({}+1)/16][(({}+1/4))%4]));", | ||
| 80 | inst, binding.U32(), offset_var, offset_var, binding.U32(), offset_var, | ||
| 81 | offset_var); | ||
| 82 | } | ||
| 53 | } | 83 | } |
| 54 | 84 | ||
| 55 | void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, | 85 | void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, |
| @@ -66,7 +96,23 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, | |||
| 66 | case IR::Attribute::PositionY: | 96 | case IR::Attribute::PositionY: |
| 67 | case IR::Attribute::PositionZ: | 97 | case IR::Attribute::PositionZ: |
| 68 | case IR::Attribute::PositionW: | 98 | case IR::Attribute::PositionW: |
| 69 | ctx.AddF32("{}=gl_Position.{};", inst, swizzle); | 99 | switch (ctx.stage) { |
| 100 | case Stage::VertexA: | ||
| 101 | case Stage::VertexB: | ||
| 102 | ctx.AddF32("{}=gl_Position.{};", inst, swizzle); | ||
| 103 | break; | ||
| 104 | case Stage::Fragment: | ||
| 105 | ctx.AddF32("{}=gl_FragCoord.{};", inst, swizzle); | ||
| 106 | break; | ||
| 107 | default: | ||
| 108 | throw NotImplementedException("Get Position for stage {}", ctx.stage); | ||
| 109 | } | ||
| 110 | break; | ||
| 111 | case IR::Attribute::InstanceId: | ||
| 112 | ctx.AddS32("{}=gl_InstanceID;", inst, ctx.attrib_name); | ||
| 113 | break; | ||
| 114 | case IR::Attribute::VertexId: | ||
| 115 | ctx.AddS32("{}=gl_VertexID;", inst, ctx.attrib_name); | ||
| 70 | break; | 116 | break; |
| 71 | default: | 117 | default: |
| 72 | fmt::print("Get attribute {}", attr); | 118 | fmt::print("Get attribute {}", attr); |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_convert.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_convert.cpp index 0f95d4465..866bcfc4d 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_convert.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_convert.cpp | |||
| @@ -197,7 +197,7 @@ void EmitConvertF32U8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::In | |||
| 197 | 197 | ||
| 198 | void EmitConvertF32U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 198 | void EmitConvertF32U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 199 | [[maybe_unused]] std::string_view value) { | 199 | [[maybe_unused]] std::string_view value) { |
| 200 | throw NotImplementedException("GLSL Instruction"); | 200 | ctx.AddF32("{}=float({});", inst, value); |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | void EmitConvertF32U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 203 | void EmitConvertF32U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp index f3d1d1af0..33aba9fef 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp | |||
| @@ -133,7 +133,7 @@ void EmitFPRecip64(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | |||
| 133 | 133 | ||
| 134 | void EmitFPRecipSqrt32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 134 | void EmitFPRecipSqrt32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 135 | [[maybe_unused]] std::string_view value) { | 135 | [[maybe_unused]] std::string_view value) { |
| 136 | throw NotImplementedException("GLSL Instruction"); | 136 | ctx.AddF32("{}=1/sqrt({});", inst, value); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | void EmitFPRecipSqrt64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 139 | void EmitFPRecipSqrt64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h index c9b53bae2..295b7a8c4 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h +++ b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h | |||
| @@ -60,7 +60,8 @@ void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | |||
| 60 | const IR::Value& offset); | 60 | const IR::Value& offset); |
| 61 | void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 61 | void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 62 | const IR::Value& offset); | 62 | const IR::Value& offset); |
| 63 | void EmitGetCbufU32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset); | 63 | void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 64 | const IR::Value& offset); | ||
| 64 | void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, | 65 | void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, |
| 65 | std::string_view vertex); | 66 | std::string_view vertex); |
| 66 | void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view value, | 67 | void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view value, |
| @@ -116,7 +117,8 @@ void EmitLoadStorage32(EmitContext& ctx, IR::Inst& inst, const IR::Value& bindin | |||
| 116 | const IR::Value& offset); | 117 | const IR::Value& offset); |
| 117 | void EmitLoadStorage64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 118 | void EmitLoadStorage64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 118 | const IR::Value& offset); | 119 | const IR::Value& offset); |
| 119 | void EmitLoadStorage128(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset); | 120 | void EmitLoadStorage128(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 121 | const IR::Value& offset); | ||
| 120 | void EmitWriteStorageU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | 122 | void EmitWriteStorageU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, |
| 121 | std::string_view value); | 123 | std::string_view value); |
| 122 | void EmitWriteStorageS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | 124 | void EmitWriteStorageS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, |
| @@ -145,14 +147,16 @@ void EmitWriteSharedU64(EmitContext& ctx, std::string_view offset, std::string_v | |||
| 145 | void EmitWriteSharedU128(EmitContext& ctx, std::string_view offset, std::string_view value); | 147 | void EmitWriteSharedU128(EmitContext& ctx, std::string_view offset, std::string_view value); |
| 146 | void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, | 148 | void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, |
| 147 | std::string_view e2); | 149 | std::string_view e2); |
| 148 | void EmitCompositeConstructU32x3(EmitContext& ctx, std::string_view e1, std::string_view e2, | 150 | void EmitCompositeConstructU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1, |
| 149 | std::string_view e3); | 151 | std::string_view e2, std::string_view e3); |
| 150 | void EmitCompositeConstructU32x4(EmitContext& ctx, std::string_view e1, std::string_view e2, | 152 | void EmitCompositeConstructU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1, |
| 151 | std::string_view e3, std::string_view e4); | 153 | std::string_view e2, std::string_view e3, std::string_view e4); |
| 152 | void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, | 154 | void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 153 | u32 index); | 155 | u32 index); |
| 154 | void EmitCompositeExtractU32x3(EmitContext& ctx, std::string_view composite, u32 index); | 156 | void EmitCompositeExtractU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 155 | void EmitCompositeExtractU32x4(EmitContext& ctx, std::string_view composite, u32 index); | 157 | u32 index); |
| 158 | void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite, | ||
| 159 | u32 index); | ||
| 156 | void EmitCompositeInsertU32x2(EmitContext& ctx, std::string_view composite, std::string_view object, | 160 | void EmitCompositeInsertU32x2(EmitContext& ctx, std::string_view composite, std::string_view object, |
| 157 | u32 index); | 161 | u32 index); |
| 158 | void EmitCompositeInsertU32x3(EmitContext& ctx, std::string_view composite, std::string_view object, | 162 | void EmitCompositeInsertU32x3(EmitContext& ctx, std::string_view composite, std::string_view object, |
| @@ -175,10 +179,10 @@ void EmitCompositeInsertF16x4(EmitContext& ctx, std::string_view composite, std: | |||
| 175 | u32 index); | 179 | u32 index); |
| 176 | void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, | 180 | void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, |
| 177 | std::string_view e2); | 181 | std::string_view e2); |
| 178 | void EmitCompositeConstructF32x3(EmitContext& ctx, std::string_view e1, std::string_view e2, | 182 | void EmitCompositeConstructF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1, |
| 179 | std::string_view e3); | 183 | std::string_view e2, std::string_view e3); |
| 180 | void EmitCompositeConstructF32x4(EmitContext& ctx, std::string_view e1, std::string_view e2, | 184 | void EmitCompositeConstructF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1, |
| 181 | std::string_view e3, std::string_view e4); | 185 | std::string_view e2, std::string_view e3, std::string_view e4); |
| 182 | void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, | 186 | void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 183 | u32 index); | 187 | u32 index); |
| 184 | void EmitCompositeExtractF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite, | 188 | void EmitCompositeExtractF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_memory.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_memory.cpp index 8994c02a2..32cee7d3e 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_memory.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_memory.cpp | |||
| @@ -34,19 +34,23 @@ void EmitLoadStorageS16([[maybe_unused]] EmitContext& ctx, | |||
| 34 | 34 | ||
| 35 | void EmitLoadStorage32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 35 | void EmitLoadStorage32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 36 | const IR::Value& offset) { | 36 | const IR::Value& offset) { |
| 37 | ctx.AddU32("{}=ssbo{}[{}];", inst, binding.U32(), offset.U32()); | 37 | const auto offset_var{ctx.reg_alloc.Consume(offset)}; |
| 38 | ctx.AddU32("{}=ssbo{}[{}];", inst, binding.U32(), offset_var); | ||
| 38 | } | 39 | } |
| 39 | 40 | ||
| 40 | void EmitLoadStorage64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 41 | void EmitLoadStorage64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 41 | const IR::Value& offset) { | 42 | const IR::Value& offset) { |
| 42 | ctx.AddU32x2("{}=uvec2(ssbo{}[{}],ssbo{}[{}]);", inst, binding.U32(), offset.U32(), | 43 | const auto offset_var{ctx.reg_alloc.Consume(offset)}; |
| 43 | binding.U32(), offset.U32() + 1); | 44 | ctx.AddU32x2("{}=uvec2(ssbo{}[{}],ssbo{}[{}+1]);", inst, binding.U32(), offset_var, |
| 45 | binding.U32(), offset_var); | ||
| 44 | } | 46 | } |
| 45 | 47 | ||
| 46 | void EmitLoadStorage128([[maybe_unused]] EmitContext& ctx, | 48 | void EmitLoadStorage128(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 47 | [[maybe_unused]] const IR::Value& binding, | 49 | const IR::Value& offset) { |
| 48 | [[maybe_unused]] const IR::Value& offset) { | 50 | const auto offset_var{ctx.reg_alloc.Consume(offset)}; |
| 49 | throw NotImplementedException("GLSL Instrucion"); | 51 | ctx.AddU32x4("{}=uvec4(ssbo{}[{}],ssbo{}[{}+1],ssbo{}[{}+2],ssbo{}[{}+3]);", inst, |
| 52 | binding.U32(), offset_var, binding.U32(), offset_var, binding.U32(), offset_var, | ||
| 53 | binding.U32(), offset_var); | ||
| 50 | } | 54 | } |
| 51 | 55 | ||
| 52 | void EmitWriteStorageU8([[maybe_unused]] EmitContext& ctx, | 56 | void EmitWriteStorageU8([[maybe_unused]] 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 42b1e8764..761145a5d 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp | |||
| @@ -50,15 +50,7 @@ void EmitPhiMove(EmitContext& ctx, const IR::Value& phi_value, const IR::Value& | |||
| 50 | if (phi_reg == val_reg) { | 50 | if (phi_reg == val_reg) { |
| 51 | return; | 51 | return; |
| 52 | } | 52 | } |
| 53 | if (phi_type == value.Type()) { | 53 | ctx.Add("{}={};", phi_reg, val_reg); |
| 54 | ctx.Add("{}={}; // PHI MOVE", phi_reg, val_reg); | ||
| 55 | } else if (phi_type == IR::Type::U32 && value.Type() == IR::Type::F32) { | ||
| 56 | ctx.Add("{}=floatBitsToUint({}); // CAST PHI MOVE", phi_reg, val_reg); | ||
| 57 | } else { | ||
| 58 | throw NotImplementedException("{} to {} move", phi_type, value.Type()); | ||
| 59 | const auto cast{ctx.reg_alloc.GetGlslType(phi_type)}; | ||
| 60 | ctx.Add("{}={}({}); // CAST PHI MOVE", phi_reg, cast, val_reg); | ||
| 61 | } | ||
| 62 | } | 54 | } |
| 63 | 55 | ||
| 64 | void EmitBranch(EmitContext& ctx, std::string_view label) { | 56 | void EmitBranch(EmitContext& ctx, std::string_view label) { |
| @@ -245,7 +237,7 @@ void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_ | |||
| 245 | } | 237 | } |
| 246 | 238 | ||
| 247 | void EmitUndefU1(EmitContext& ctx, IR::Inst& inst) { | 239 | void EmitUndefU1(EmitContext& ctx, IR::Inst& inst) { |
| 248 | NotImplemented(); | 240 | ctx.AddU1("{}=false;", inst); |
| 249 | } | 241 | } |
| 250 | 242 | ||
| 251 | void EmitUndefU8(EmitContext& ctx, IR::Inst& inst) { | 243 | void EmitUndefU8(EmitContext& ctx, IR::Inst& inst) { |
diff --git a/src/shader_recompiler/backend/glsl/reg_alloc.cpp b/src/shader_recompiler/backend/glsl/reg_alloc.cpp index 06f1965b5..a987ce543 100644 --- a/src/shader_recompiler/backend/glsl/reg_alloc.cpp +++ b/src/shader_recompiler/backend/glsl/reg_alloc.cpp | |||
| @@ -137,6 +137,10 @@ std::string RegAlloc::GetGlslType(Type type) { | |||
| 137 | return "uvec2 "; | 137 | return "uvec2 "; |
| 138 | case Type::F32x2: | 138 | case Type::F32x2: |
| 139 | return "vec2 "; | 139 | return "vec2 "; |
| 140 | case Type::U32x3: | ||
| 141 | return "uvec3 "; | ||
| 142 | case Type::F32x3: | ||
| 143 | return "vec3 "; | ||
| 140 | case Type::U32x4: | 144 | case Type::U32x4: |
| 141 | return "uvec4 "; | 145 | return "uvec4 "; |
| 142 | case Type::F32x4: | 146 | case Type::F32x4: |
diff --git a/src/shader_recompiler/backend/glsl/reg_alloc.h b/src/shader_recompiler/backend/glsl/reg_alloc.h index 419d0bde0..2dc506c58 100644 --- a/src/shader_recompiler/backend/glsl/reg_alloc.h +++ b/src/shader_recompiler/backend/glsl/reg_alloc.h | |||
| @@ -27,6 +27,8 @@ enum class Type : u32 { | |||
| 27 | F64, | 27 | F64, |
| 28 | U32x2, | 28 | U32x2, |
| 29 | F32x2, | 29 | F32x2, |
| 30 | U32x3, | ||
| 31 | F32x3, | ||
| 30 | U32x4, | 32 | U32x4, |
| 31 | F32x4, | 33 | F32x4, |
| 32 | Void, | 34 | Void, |