diff options
| author | 2021-05-22 15:06:14 -0400 | |
|---|---|---|
| committer | 2021-07-22 21:51:36 -0400 | |
| commit | 3064bde4155b865d61258e8fa87df9e6377578b6 (patch) | |
| tree | a615735520ff688e6ba64775856c76d84e2d2416 /src/shader_recompiler/backend/glsl | |
| parent | glsl: More FP instructions/fixes (diff) | |
| download | yuzu-3064bde4155b865d61258e8fa87df9e6377578b6.tar.gz yuzu-3064bde4155b865d61258e8fa87df9e6377578b6.tar.xz yuzu-3064bde4155b865d61258e8fa87df9e6377578b6.zip | |
glsl: FP function fixes
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
7 files changed, 25 insertions, 17 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp index b3a3e5647..da379360a 100644 --- a/src/shader_recompiler/backend/glsl/emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/emit_context.cpp | |||
| @@ -48,8 +48,11 @@ void EmitContext::DefineStorageBuffers() { | |||
| 48 | } | 48 | } |
| 49 | u32 binding{}; | 49 | u32 binding{}; |
| 50 | for (const auto& desc : info.storage_buffers_descriptors) { | 50 | for (const auto& desc : info.storage_buffers_descriptors) { |
| 51 | Add("layout(std430,binding={}) buffer buff_{}{{uint buff{}[];}};", binding, binding, | 51 | Add("layout(std430,binding={}) buffer ssbo_{}_u32{{uint ssbo{}_u32[];}};", binding, binding, |
| 52 | desc.cbuf_index, desc.count); | 52 | desc.cbuf_index, desc.count); |
| 53 | // TODO: Track ssbo data type usage | ||
| 54 | Add("layout(std430,binding={}) buffer ssbo_{}_u64{{uvec2 ssbo{}_u64[];}};", binding, | ||
| 55 | binding, desc.cbuf_index, desc.count); | ||
| 53 | ++binding; | 56 | ++binding; |
| 54 | } | 57 | } |
| 55 | } | 58 | } |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp index 40b9ca08e..8e7ad68bd 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp | |||
| @@ -10,6 +10,8 @@ | |||
| 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 | static constexpr std::string_view SWIZZLE{"xyzw"}; | ||
| 14 | |||
| 13 | void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, | 15 | void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, |
| 14 | std::string_view e2) { | 16 | std::string_view e2) { |
| 15 | ctx.AddU32x2("{}=uvec2({},{});", inst, e1, e2); | 17 | ctx.AddU32x2("{}=uvec2({},{});", inst, e1, e2); |
| @@ -32,7 +34,7 @@ void EmitCompositeConstructU32x4([[maybe_unused]] EmitContext& ctx, | |||
| 32 | 34 | ||
| 33 | void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, | 35 | void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 34 | u32 index) { | 36 | u32 index) { |
| 35 | ctx.AddU32("{}={}[{}];", inst, composite, index); | 37 | ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]); |
| 36 | } | 38 | } |
| 37 | 39 | ||
| 38 | void EmitCompositeExtractU32x3([[maybe_unused]] EmitContext& ctx, | 40 | void EmitCompositeExtractU32x3([[maybe_unused]] EmitContext& ctx, |
| @@ -130,7 +132,7 @@ void EmitCompositeInsertF16x4([[maybe_unused]] EmitContext& ctx, | |||
| 130 | 132 | ||
| 131 | void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, | 133 | void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, |
| 132 | std::string_view e2) { | 134 | std::string_view e2) { |
| 133 | ctx.AddF32x2("{}=uvec2({},{});", inst, e1, e2); | 135 | ctx.AddF32x2("{}=vec2({},{});", inst, e1, e2); |
| 134 | } | 136 | } |
| 135 | 137 | ||
| 136 | void EmitCompositeConstructF32x3([[maybe_unused]] EmitContext& ctx, | 138 | void EmitCompositeConstructF32x3([[maybe_unused]] EmitContext& ctx, |
| @@ -150,7 +152,7 @@ void EmitCompositeConstructF32x4([[maybe_unused]] EmitContext& ctx, | |||
| 150 | 152 | ||
| 151 | void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, | 153 | void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, |
| 152 | u32 index) { | 154 | u32 index) { |
| 153 | ctx.AddF32("{}={}[{}];", inst, composite, index); | 155 | ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]); |
| 154 | } | 156 | } |
| 155 | 157 | ||
| 156 | void EmitCompositeExtractF32x3([[maybe_unused]] EmitContext& ctx, | 158 | void EmitCompositeExtractF32x3([[maybe_unused]] EmitContext& ctx, |
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 d3d55562c..7c9cadd7e 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,6 +10,8 @@ | |||
| 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 | static constexpr std::string_view SWIZZLE{"xyzw"}; | ||
| 14 | |||
| 13 | void EmitGetCbufU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding, | 15 | void EmitGetCbufU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding, |
| 14 | [[maybe_unused]] const IR::Value& offset) { | 16 | [[maybe_unused]] const IR::Value& offset) { |
| 15 | throw NotImplementedException("GLSL"); | 17 | throw NotImplementedException("GLSL"); |
| @@ -33,14 +35,16 @@ void EmitGetCbufS16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR | |||
| 33 | void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 35 | void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 34 | const IR::Value& offset) { | 36 | const IR::Value& offset) { |
| 35 | const auto u32_offset{offset.U32()}; | 37 | const auto u32_offset{offset.U32()}; |
| 36 | ctx.AddU32("{}=floatBitsToUint(cbuf{}[{}][{}]);", inst, binding.U32(), u32_offset / 16, | 38 | const auto index{(u32_offset / 4) % 4}; |
| 37 | (u32_offset / 4) % 4); | 39 | ctx.AddU32("{}=floatBitsToUint(cbuf{}[{}].{});", inst, binding.U32(), u32_offset / 16, |
| 40 | SWIZZLE[index]); | ||
| 38 | } | 41 | } |
| 39 | 42 | ||
| 40 | void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 43 | void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 41 | const IR::Value& offset) { | 44 | const IR::Value& offset) { |
| 42 | const auto u32_offset{offset.U32()}; | 45 | const auto u32_offset{offset.U32()}; |
| 43 | ctx.AddF32("{}=cbuf{}[{}][{}];", inst, binding.U32(), u32_offset / 16, (u32_offset / 4) % 4); | 46 | const auto index{(u32_offset / 4) % 4}; |
| 47 | ctx.AddF32("{}=cbuf{}[{}].{};", inst, binding.U32(), u32_offset / 16, SWIZZLE[index]); | ||
| 44 | } | 48 | } |
| 45 | 49 | ||
| 46 | void EmitGetCbufU32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding, | 50 | void EmitGetCbufU32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding, |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_convert.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_convert.cpp index 7ddc24c71..0f95d4465 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_convert.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_convert.cpp | |||
| @@ -47,7 +47,7 @@ void EmitConvertS64F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I | |||
| 47 | 47 | ||
| 48 | void EmitConvertS64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 48 | void EmitConvertS64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 49 | [[maybe_unused]] std::string_view value) { | 49 | [[maybe_unused]] std::string_view value) { |
| 50 | ctx.AddS64("{}=int64_t({});", inst, value); | 50 | ctx.AddS64("{}=int64_t(double({}));", inst, value); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | void EmitConvertS64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 53 | void EmitConvertS64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| @@ -92,7 +92,7 @@ void EmitConvertU64F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I | |||
| 92 | 92 | ||
| 93 | void EmitConvertU64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 93 | void EmitConvertU64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 94 | [[maybe_unused]] std::string_view value) { | 94 | [[maybe_unused]] std::string_view value) { |
| 95 | ctx.AddU64("{}=uint64_t({});", inst, value); | 95 | ctx.AddU64("{}=uint64_t(double({}));", inst, value); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | void EmitConvertU64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 98 | void EmitConvertU64F64([[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 3f3a83b20..2aa9f2cd3 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp | |||
| @@ -156,12 +156,12 @@ void EmitFPSqrt([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& in | |||
| 156 | 156 | ||
| 157 | void EmitFPSaturate16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 157 | void EmitFPSaturate16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 158 | [[maybe_unused]] std::string_view value) { | 158 | [[maybe_unused]] std::string_view value) { |
| 159 | ctx.AddF64("{}=sqrt({});", inst, value); | 159 | throw NotImplementedException("GLSL"); |
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | void EmitFPSaturate32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 162 | void EmitFPSaturate32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 163 | [[maybe_unused]] std::string_view value) { | 163 | [[maybe_unused]] std::string_view value) { |
| 164 | ctx.AddF32("{}=clamp({},0.0f,1.0f);", inst, value); | 164 | ctx.AddF32("{}=clamp({},0.0,1.0);", inst, value); |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | void EmitFPSaturate64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 167 | void EmitFPSaturate64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| @@ -197,12 +197,12 @@ void EmitFPRoundEven16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I | |||
| 197 | 197 | ||
| 198 | void EmitFPRoundEven32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 198 | void EmitFPRoundEven32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 199 | [[maybe_unused]] std::string_view value) { | 199 | [[maybe_unused]] std::string_view value) { |
| 200 | ctx.AddF32("{}=round({});", inst, value); | 200 | ctx.AddF32("{}=roundEven({});", inst, value); |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | void EmitFPRoundEven64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 203 | void EmitFPRoundEven64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 204 | [[maybe_unused]] std::string_view value) { | 204 | [[maybe_unused]] std::string_view value) { |
| 205 | ctx.AddF64("{}=round({});", inst, value); | 205 | ctx.AddF64("{}=roundEven({});", inst, value); |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | void EmitFPFloor16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 208 | void EmitFPFloor16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_memory.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_memory.cpp index 7c8c23050..b042ae853 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_memory.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_memory.cpp | |||
| @@ -78,13 +78,12 @@ void EmitWriteStorageS16([[maybe_unused]] EmitContext& ctx, | |||
| 78 | 78 | ||
| 79 | void EmitWriteStorage32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | 79 | void EmitWriteStorage32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, |
| 80 | std::string_view value) { | 80 | std::string_view value) { |
| 81 | ctx.Add("buff{}[{}]={};", binding.U32(), offset.U32(), value); | 81 | ctx.Add("ssbo{}_u32[{}]={};", binding.U32(), offset.U32(), value); |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | void EmitWriteStorage64(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | 84 | void EmitWriteStorage64(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, |
| 85 | std::string_view value) { | 85 | std::string_view value) { |
| 86 | ctx.Add("buff{}[{}]={}.x;", binding.U32(), offset.U32(), value); | 86 | ctx.Add("ssbo{}_u64[{}]={};", binding.U32(), offset.U32(), value); |
| 87 | ctx.Add("buff{}[{}]={}.y;", binding.U32(), offset.U32() + 1, value); | ||
| 88 | } | 87 | } |
| 89 | 88 | ||
| 90 | void EmitWriteStorage128([[maybe_unused]] EmitContext& ctx, | 89 | void EmitWriteStorage128([[maybe_unused]] EmitContext& ctx, |
diff --git a/src/shader_recompiler/backend/glsl/reg_alloc.cpp b/src/shader_recompiler/backend/glsl/reg_alloc.cpp index c370aabb5..73295a1e5 100644 --- a/src/shader_recompiler/backend/glsl/reg_alloc.cpp +++ b/src/shader_recompiler/backend/glsl/reg_alloc.cpp | |||
| @@ -36,7 +36,7 @@ std::string MakeImm(const IR::Value& value) { | |||
| 36 | case IR::Type::U64: | 36 | case IR::Type::U64: |
| 37 | return fmt::format("{}ul", value.U64()); | 37 | return fmt::format("{}ul", value.U64()); |
| 38 | case IR::Type::F64: | 38 | case IR::Type::F64: |
| 39 | return fmt::format("{}", value.F64()); | 39 | return fmt::format("{}lf", value.F64()); |
| 40 | default: | 40 | default: |
| 41 | throw NotImplementedException("Immediate type {}", value.Type()); | 41 | throw NotImplementedException("Immediate type {}", value.Type()); |
| 42 | } | 42 | } |