summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_context.cpp5
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp8
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp10
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_convert.cpp4
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp8
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_memory.cpp5
-rw-r--r--src/shader_recompiler/backend/glsl/reg_alloc.cpp2
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
12namespace Shader::Backend::GLSL { 12namespace Shader::Backend::GLSL {
13static constexpr std::string_view SWIZZLE{"xyzw"};
14
13void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, 15void 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
33void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, 35void 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
38void EmitCompositeExtractU32x3([[maybe_unused]] EmitContext& ctx, 40void EmitCompositeExtractU32x3([[maybe_unused]] EmitContext& ctx,
@@ -130,7 +132,7 @@ void EmitCompositeInsertF16x4([[maybe_unused]] EmitContext& ctx,
130 132
131void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, 133void 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
136void EmitCompositeConstructF32x3([[maybe_unused]] EmitContext& ctx, 138void EmitCompositeConstructF32x3([[maybe_unused]] EmitContext& ctx,
@@ -150,7 +152,7 @@ void EmitCompositeConstructF32x4([[maybe_unused]] EmitContext& ctx,
150 152
151void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, 153void 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
156void EmitCompositeExtractF32x3([[maybe_unused]] EmitContext& ctx, 158void 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
12namespace Shader::Backend::GLSL { 12namespace Shader::Backend::GLSL {
13static constexpr std::string_view SWIZZLE{"xyzw"};
14
13void EmitGetCbufU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding, 15void 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
33void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 35void 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
40void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 43void 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
46void EmitGetCbufU32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding, 50void 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
48void EmitConvertS64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 48void 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
53void EmitConvertS64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 53void 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
93void EmitConvertU64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 93void 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
98void EmitConvertU64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 98void 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
157void EmitFPSaturate16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 157void 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
162void EmitFPSaturate32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 162void 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
167void EmitFPSaturate64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 167void 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
198void EmitFPRoundEven32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 198void 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
203void EmitFPRoundEven64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 203void 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
208void EmitFPFloor16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 208void 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
79void EmitWriteStorage32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, 79void 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
84void EmitWriteStorage64(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, 84void 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
90void EmitWriteStorage128([[maybe_unused]] EmitContext& ctx, 89void 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 }