diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp | 35 | ||||
| -rw-r--r-- | src/shader_recompiler/backend/glsl/glsl_emit_context.cpp | 7 |
2 files changed, 25 insertions, 17 deletions
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 5ef46d634..0c1fbc7b1 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 | |||
| @@ -102,39 +102,46 @@ void GetCbuf16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, const | |||
| 102 | 102 | ||
| 103 | void EmitGetCbufU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 103 | void EmitGetCbufU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 104 | const IR::Value& offset) { | 104 | const IR::Value& offset) { |
| 105 | GetCbuf8(ctx, inst, binding, offset, "ftou"); | 105 | const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "" : "ftou"}; |
| 106 | GetCbuf8(ctx, inst, binding, offset, cast); | ||
| 106 | } | 107 | } |
| 107 | 108 | ||
| 108 | void EmitGetCbufS8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 109 | void EmitGetCbufS8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 109 | const IR::Value& offset) { | 110 | const IR::Value& offset) { |
| 110 | GetCbuf8(ctx, inst, binding, offset, "ftoi"); | 111 | const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "int" : "ftoi"}; |
| 112 | GetCbuf8(ctx, inst, binding, offset, cast); | ||
| 111 | } | 113 | } |
| 112 | 114 | ||
| 113 | void EmitGetCbufU16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 115 | void EmitGetCbufU16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 114 | const IR::Value& offset) { | 116 | const IR::Value& offset) { |
| 115 | GetCbuf16(ctx, inst, binding, offset, "ftou"); | 117 | const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "" : "ftou"}; |
| 118 | GetCbuf16(ctx, inst, binding, offset, cast); | ||
| 116 | } | 119 | } |
| 117 | 120 | ||
| 118 | void EmitGetCbufS16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 121 | void EmitGetCbufS16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 119 | const IR::Value& offset) { | 122 | const IR::Value& offset) { |
| 120 | GetCbuf16(ctx, inst, binding, offset, "ftoi"); | 123 | const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "int" : "ftoi"}; |
| 124 | GetCbuf16(ctx, inst, binding, offset, cast); | ||
| 121 | } | 125 | } |
| 122 | 126 | ||
| 123 | void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 127 | void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 124 | const IR::Value& offset) { | 128 | const IR::Value& offset) { |
| 125 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; | 129 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; |
| 126 | GetCbuf(ctx, ret, binding, offset, 32, "ftou"); | 130 | const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "" : "ftou"}; |
| 131 | GetCbuf(ctx, ret, binding, offset, 32, cast); | ||
| 127 | } | 132 | } |
| 128 | 133 | ||
| 129 | void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 134 | void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 130 | const IR::Value& offset) { | 135 | const IR::Value& offset) { |
| 131 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32)}; | 136 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32)}; |
| 132 | GetCbuf(ctx, ret, binding, offset, 32); | 137 | const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "utof" : ""}; |
| 138 | GetCbuf(ctx, ret, binding, offset, 32, cast); | ||
| 133 | } | 139 | } |
| 134 | 140 | ||
| 135 | void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 141 | void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 136 | const IR::Value& offset) { | 142 | const IR::Value& offset) { |
| 137 | const auto cbuf{fmt::format("{}_cbuf{}", ctx.stage_name, binding.U32())}; | 143 | const auto cbuf{fmt::format("{}_cbuf{}", ctx.stage_name, binding.U32())}; |
| 144 | const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "" : "ftou"}; | ||
| 138 | if (offset.IsImmediate()) { | 145 | if (offset.IsImmediate()) { |
| 139 | static constexpr u32 cbuf_size{0x10000}; | 146 | static constexpr u32 cbuf_size{0x10000}; |
| 140 | const u32 u32_offset{offset.U32()}; | 147 | const u32 u32_offset{offset.U32()}; |
| @@ -145,26 +152,26 @@ void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding | |||
| 145 | return; | 152 | return; |
| 146 | } | 153 | } |
| 147 | if (u32_offset % 2 == 0) { | 154 | if (u32_offset % 2 == 0) { |
| 148 | ctx.AddU32x2("{}=ftou({}[{}].{}{});", inst, cbuf, u32_offset / 16, | 155 | ctx.AddU32x2("{}={}({}[{}].{}{});", inst, cast, cbuf, u32_offset / 16, |
| 149 | OffsetSwizzle(u32_offset), OffsetSwizzle(u32_offset + 4)); | 156 | OffsetSwizzle(u32_offset), OffsetSwizzle(u32_offset + 4)); |
| 150 | } else { | 157 | } else { |
| 151 | ctx.AddU32x2("{}=uvec2(ftou({}[{}].{}),ftou({}[{}].{}));", inst, cbuf, u32_offset / 16, | 158 | ctx.AddU32x2("{}=uvec2({}({}[{}].{}),{}({}[{}].{}));", inst, cast, cbuf, |
| 152 | OffsetSwizzle(u32_offset), cbuf, (u32_offset + 4) / 16, | 159 | u32_offset / 16, OffsetSwizzle(u32_offset), cast, cbuf, |
| 153 | OffsetSwizzle(u32_offset + 4)); | 160 | (u32_offset + 4) / 16, OffsetSwizzle(u32_offset + 4)); |
| 154 | } | 161 | } |
| 155 | return; | 162 | return; |
| 156 | } | 163 | } |
| 157 | const auto offset_var{ctx.var_alloc.Consume(offset)}; | 164 | const auto offset_var{ctx.var_alloc.Consume(offset)}; |
| 158 | if (!ctx.profile.has_gl_component_indexing_bug) { | 165 | if (!ctx.profile.has_gl_component_indexing_bug) { |
| 159 | ctx.AddU32x2("{}=uvec2(ftou({}[{}>>4][({}>>2)%4]),ftou({}[({}+4)>>4][(({}+4)>>2)%4]));", | 166 | ctx.AddU32x2("{}=uvec2({}({}[{}>>4][({}>>2)%4]),{}({}[({}+4)>>4][(({}+4)>>2)%4]));", inst, |
| 160 | inst, cbuf, offset_var, offset_var, cbuf, offset_var, offset_var); | 167 | cast, cbuf, offset_var, offset_var, cast, cbuf, offset_var, offset_var); |
| 161 | return; | 168 | return; |
| 162 | } | 169 | } |
| 163 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x2)}; | 170 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x2)}; |
| 164 | const auto cbuf_offset{fmt::format("{}>>2", offset_var)}; | 171 | const auto cbuf_offset{fmt::format("{}>>2", offset_var)}; |
| 165 | for (u32 swizzle = 0; swizzle < 4; ++swizzle) { | 172 | for (u32 swizzle = 0; swizzle < 4; ++swizzle) { |
| 166 | ctx.Add("if(({}&3)=={}){}=uvec2(ftou({}[{}>>4].{}),ftou({}[({}+4)>>4].{}));", cbuf_offset, | 173 | ctx.Add("if(({}&3)=={}){}=uvec2({}({}[{}>>4].{}),{}({}[({}+4)>>4].{}));", cbuf_offset, |
| 167 | swizzle, ret, cbuf, offset_var, "xyzw"[swizzle], cbuf, offset_var, | 174 | swizzle, ret, cast, cbuf, offset_var, "xyzw"[swizzle], cast, cbuf, offset_var, |
| 168 | "xyzw"[(swizzle + 1) % 4]); | 175 | "xyzw"[(swizzle + 1) % 4]); |
| 169 | } | 176 | } |
| 170 | } | 177 | } |
diff --git a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp index bc9d2a904..bb7f1a0fd 100644 --- a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp | |||
| @@ -428,9 +428,10 @@ void EmitContext::DefineConstantBuffers(Bindings& bindings) { | |||
| 428 | return; | 428 | return; |
| 429 | } | 429 | } |
| 430 | for (const auto& desc : info.constant_buffer_descriptors) { | 430 | for (const auto& desc : info.constant_buffer_descriptors) { |
| 431 | header += fmt::format( | 431 | const auto cbuf_type{profile.has_gl_cbuf_ftou_bug ? "uvec4" : "vec4"}; |
| 432 | "layout(std140,binding={}) uniform {}_cbuf_{}{{vec4 {}_cbuf{}[{}];}};", | 432 | header += fmt::format("layout(std140,binding={}) uniform {}_cbuf_{}{{{} {}_cbuf{}[{}];}};", |
| 433 | bindings.uniform_buffer, stage_name, desc.index, stage_name, desc.index, 4 * 1024); | 433 | bindings.uniform_buffer, stage_name, desc.index, cbuf_type, |
| 434 | stage_name, desc.index, 4 * 1024); | ||
| 434 | bindings.uniform_buffer += desc.count; | 435 | bindings.uniform_buffer += desc.count; |
| 435 | } | 436 | } |
| 436 | } | 437 | } |