diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
8 files changed, 54 insertions, 126 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl.cpp b/src/shader_recompiler/backend/glsl/emit_glsl.cpp index 78b2eeaa2..b6b17a330 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl.cpp | |||
| @@ -176,7 +176,7 @@ void EmitCode(EmitContext& ctx, const IR::Program& program) { | |||
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | std::string GlslVersionSpecifier(const EmitContext& ctx) { | 178 | std::string GlslVersionSpecifier(const EmitContext& ctx) { |
| 179 | if (ctx.uses_y_direction || ctx.info.stores.Legacy() || ctx.info.loads.Legacy()) { | 179 | if (ctx.uses_y_direction) { |
| 180 | return " compatibility"; | 180 | return " compatibility"; |
| 181 | } | 181 | } |
| 182 | return ""; | 182 | return ""; |
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 0f2668d9e..e0ead7a53 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" | 7 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" |
| 8 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" | 8 | #include "shader_recompiler/backend/glsl/glsl_emit_context.h" |
| 9 | #include "shader_recompiler/frontend/ir/value.h" | 9 | #include "shader_recompiler/frontend/ir/value.h" |
| 10 | #include "shader_recompiler/profile.h" | ||
| 10 | 11 | ||
| 11 | namespace Shader::Backend::GLSL { | 12 | namespace Shader::Backend::GLSL { |
| 12 | namespace { | 13 | namespace { |
| @@ -30,8 +31,9 @@ void EmitConditionRef(EmitContext& ctx, IR::Inst& inst, const IR::Value& value) | |||
| 30 | inst.DestructiveAddUsage(1); | 31 | inst.DestructiveAddUsage(1); |
| 31 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U1)}; | 32 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U1)}; |
| 32 | const auto input{ctx.var_alloc.Consume(value)}; | 33 | const auto input{ctx.var_alloc.Consume(value)}; |
| 34 | const auto suffix{ctx.profile.has_gl_bool_ref_bug ? "?true:false" : ""}; | ||
| 33 | if (ret != input) { | 35 | if (ret != input) { |
| 34 | ctx.Add("{}={};", ret, input); | 36 | ctx.Add("{}={}{};", ret, input, suffix); |
| 35 | } | 37 | } |
| 36 | } | 38 | } |
| 37 | 39 | ||
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 1920047f4..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 | |||
| @@ -98,47 +98,50 @@ void GetCbuf16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, const | |||
| 98 | GetCbuf(ctx, ret, binding, offset, 16, cast, bit_offset); | 98 | GetCbuf(ctx, ret, binding, offset, 16, cast, bit_offset); |
| 99 | } | 99 | } |
| 100 | } | 100 | } |
| 101 | |||
| 102 | u32 TexCoordIndex(IR::Attribute attr) { | ||
| 103 | return (static_cast<u32>(attr) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4; | ||
| 104 | } | ||
| 105 | } // Anonymous namespace | 101 | } // Anonymous namespace |
| 106 | 102 | ||
| 107 | void EmitGetCbufU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 103 | void EmitGetCbufU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 108 | const IR::Value& offset) { | 104 | const IR::Value& offset) { |
| 109 | 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); | ||
| 110 | } | 107 | } |
| 111 | 108 | ||
| 112 | void EmitGetCbufS8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 109 | void EmitGetCbufS8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 113 | const IR::Value& offset) { | 110 | const IR::Value& offset) { |
| 114 | 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); | ||
| 115 | } | 113 | } |
| 116 | 114 | ||
| 117 | void EmitGetCbufU16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 115 | void EmitGetCbufU16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 118 | const IR::Value& offset) { | 116 | const IR::Value& offset) { |
| 119 | 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); | ||
| 120 | } | 119 | } |
| 121 | 120 | ||
| 122 | void EmitGetCbufS16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 121 | void EmitGetCbufS16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 123 | const IR::Value& offset) { | 122 | const IR::Value& offset) { |
| 124 | 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); | ||
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 127 | void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 128 | const IR::Value& offset) { | 128 | const IR::Value& offset) { |
| 129 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; | 129 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; |
| 130 | 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); | ||
| 131 | } | 132 | } |
| 132 | 133 | ||
| 133 | void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 134 | void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 134 | const IR::Value& offset) { | 135 | const IR::Value& offset) { |
| 135 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32)}; | 136 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32)}; |
| 136 | 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); | ||
| 137 | } | 139 | } |
| 138 | 140 | ||
| 139 | void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 141 | void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 140 | const IR::Value& offset) { | 142 | const IR::Value& offset) { |
| 141 | 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"}; | ||
| 142 | if (offset.IsImmediate()) { | 145 | if (offset.IsImmediate()) { |
| 143 | static constexpr u32 cbuf_size{0x10000}; | 146 | static constexpr u32 cbuf_size{0x10000}; |
| 144 | const u32 u32_offset{offset.U32()}; | 147 | const u32 u32_offset{offset.U32()}; |
| @@ -149,26 +152,26 @@ void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding | |||
| 149 | return; | 152 | return; |
| 150 | } | 153 | } |
| 151 | if (u32_offset % 2 == 0) { | 154 | if (u32_offset % 2 == 0) { |
| 152 | ctx.AddU32x2("{}=ftou({}[{}].{}{});", inst, cbuf, u32_offset / 16, | 155 | ctx.AddU32x2("{}={}({}[{}].{}{});", inst, cast, cbuf, u32_offset / 16, |
| 153 | OffsetSwizzle(u32_offset), OffsetSwizzle(u32_offset + 4)); | 156 | OffsetSwizzle(u32_offset), OffsetSwizzle(u32_offset + 4)); |
| 154 | } else { | 157 | } else { |
| 155 | ctx.AddU32x2("{}=uvec2(ftou({}[{}].{}),ftou({}[{}].{}));", inst, cbuf, u32_offset / 16, | 158 | ctx.AddU32x2("{}=uvec2({}({}[{}].{}),{}({}[{}].{}));", inst, cast, cbuf, |
| 156 | OffsetSwizzle(u32_offset), cbuf, (u32_offset + 4) / 16, | 159 | u32_offset / 16, OffsetSwizzle(u32_offset), cast, cbuf, |
| 157 | OffsetSwizzle(u32_offset + 4)); | 160 | (u32_offset + 4) / 16, OffsetSwizzle(u32_offset + 4)); |
| 158 | } | 161 | } |
| 159 | return; | 162 | return; |
| 160 | } | 163 | } |
| 161 | const auto offset_var{ctx.var_alloc.Consume(offset)}; | 164 | const auto offset_var{ctx.var_alloc.Consume(offset)}; |
| 162 | if (!ctx.profile.has_gl_component_indexing_bug) { | 165 | if (!ctx.profile.has_gl_component_indexing_bug) { |
| 163 | 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, |
| 164 | inst, cbuf, offset_var, offset_var, cbuf, offset_var, offset_var); | 167 | cast, cbuf, offset_var, offset_var, cast, cbuf, offset_var, offset_var); |
| 165 | return; | 168 | return; |
| 166 | } | 169 | } |
| 167 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x2)}; | 170 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x2)}; |
| 168 | const auto cbuf_offset{fmt::format("{}>>2", offset_var)}; | 171 | const auto cbuf_offset{fmt::format("{}>>2", offset_var)}; |
| 169 | for (u32 swizzle = 0; swizzle < 4; ++swizzle) { | 172 | for (u32 swizzle = 0; swizzle < 4; ++swizzle) { |
| 170 | ctx.Add("if(({}&3)=={}){}=uvec2(ftou({}[{}>>4].{}),ftou({}[({}+4)>>4].{}));", cbuf_offset, | 173 | ctx.Add("if(({}&3)=={}){}=uvec2({}({}[{}>>4].{}),{}({}[({}+4)>>4].{}));", cbuf_offset, |
| 171 | swizzle, ret, cbuf, offset_var, "xyzw"[swizzle], cbuf, offset_var, | 174 | swizzle, ret, cast, cbuf, offset_var, "xyzw"[swizzle], cast, cbuf, offset_var, |
| 172 | "xyzw"[(swizzle + 1) % 4]); | 175 | "xyzw"[(swizzle + 1) % 4]); |
| 173 | } | 176 | } |
| 174 | } | 177 | } |
| @@ -190,18 +193,6 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, | |||
| 190 | ctx.AddF32("{}=in_attr{}{}.{};", inst, index, InputVertexIndex(ctx, vertex), swizzle); | 193 | ctx.AddF32("{}=in_attr{}{}.{};", inst, index, InputVertexIndex(ctx, vertex), swizzle); |
| 191 | return; | 194 | return; |
| 192 | } | 195 | } |
| 193 | // GLSL only exposes 8 legacy texcoords | ||
| 194 | if (attr >= IR::Attribute::FixedFncTexture8S && attr <= IR::Attribute::FixedFncTexture9Q) { | ||
| 195 | LOG_WARNING(Shader_GLSL, "GLSL does not allow access to gl_TexCoord[{}]", | ||
| 196 | TexCoordIndex(attr)); | ||
| 197 | ctx.AddF32("{}=0.f;", inst); | ||
| 198 | return; | ||
| 199 | } | ||
| 200 | if (attr >= IR::Attribute::FixedFncTexture0S && attr <= IR::Attribute::FixedFncTexture7Q) { | ||
| 201 | const u32 index{TexCoordIndex(attr)}; | ||
| 202 | ctx.AddF32("{}=gl_TexCoord[{}].{};", inst, index, swizzle); | ||
| 203 | return; | ||
| 204 | } | ||
| 205 | switch (attr) { | 196 | switch (attr) { |
| 206 | case IR::Attribute::PrimitiveId: | 197 | case IR::Attribute::PrimitiveId: |
| 207 | ctx.AddF32("{}=itof(gl_PrimitiveID);", inst); | 198 | ctx.AddF32("{}=itof(gl_PrimitiveID);", inst); |
| @@ -215,16 +206,6 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, | |||
| 215 | ctx.AddF32("{}={}{}.{};", inst, input_decorator, ctx.position_name, swizzle); | 206 | ctx.AddF32("{}={}{}.{};", inst, input_decorator, ctx.position_name, swizzle); |
| 216 | break; | 207 | break; |
| 217 | } | 208 | } |
| 218 | case IR::Attribute::ColorFrontDiffuseR: | ||
| 219 | case IR::Attribute::ColorFrontDiffuseG: | ||
| 220 | case IR::Attribute::ColorFrontDiffuseB: | ||
| 221 | case IR::Attribute::ColorFrontDiffuseA: | ||
| 222 | if (ctx.stage == Stage::Fragment) { | ||
| 223 | ctx.AddF32("{}=gl_Color.{};", inst, swizzle); | ||
| 224 | } else { | ||
| 225 | ctx.AddF32("{}=gl_FrontColor.{};", inst, swizzle); | ||
| 226 | } | ||
| 227 | break; | ||
| 228 | case IR::Attribute::PointSpriteS: | 209 | case IR::Attribute::PointSpriteS: |
| 229 | case IR::Attribute::PointSpriteT: | 210 | case IR::Attribute::PointSpriteT: |
| 230 | ctx.AddF32("{}=gl_PointCoord.{};", inst, swizzle); | 211 | ctx.AddF32("{}=gl_PointCoord.{};", inst, swizzle); |
| @@ -247,6 +228,22 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, | |||
| 247 | } | 228 | } |
| 248 | } | 229 | } |
| 249 | 230 | ||
| 231 | void EmitGetAttributeU32(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, std::string_view) { | ||
| 232 | switch (attr) { | ||
| 233 | case IR::Attribute::PrimitiveId: | ||
| 234 | ctx.AddU32("{}=uint(gl_PrimitiveID);", inst); | ||
| 235 | break; | ||
| 236 | case IR::Attribute::InstanceId: | ||
| 237 | ctx.AddU32("{}=uint(gl_InstanceID);", inst); | ||
| 238 | break; | ||
| 239 | case IR::Attribute::VertexId: | ||
| 240 | ctx.AddU32("{}=uint(gl_VertexID);", inst); | ||
| 241 | break; | ||
| 242 | default: | ||
| 243 | throw NotImplementedException("Get U32 attribute {}", attr); | ||
| 244 | } | ||
| 245 | } | ||
| 246 | |||
| 250 | void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view value, | 247 | void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view value, |
| 251 | [[maybe_unused]] std::string_view vertex) { | 248 | [[maybe_unused]] std::string_view vertex) { |
| 252 | if (IR::IsGeneric(attr)) { | 249 | if (IR::IsGeneric(attr)) { |
| @@ -264,17 +261,6 @@ void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view val | |||
| 264 | } | 261 | } |
| 265 | const u32 element{static_cast<u32>(attr) % 4}; | 262 | const u32 element{static_cast<u32>(attr) % 4}; |
| 266 | const char swizzle{"xyzw"[element]}; | 263 | const char swizzle{"xyzw"[element]}; |
| 267 | // GLSL only exposes 8 legacy texcoords | ||
| 268 | if (attr >= IR::Attribute::FixedFncTexture8S && attr <= IR::Attribute::FixedFncTexture9Q) { | ||
| 269 | LOG_WARNING(Shader_GLSL, "GLSL does not allow access to gl_TexCoord[{}]", | ||
| 270 | TexCoordIndex(attr)); | ||
| 271 | return; | ||
| 272 | } | ||
| 273 | if (attr >= IR::Attribute::FixedFncTexture0S && attr <= IR::Attribute::FixedFncTexture7Q) { | ||
| 274 | const u32 index{TexCoordIndex(attr)}; | ||
| 275 | ctx.Add("gl_TexCoord[{}].{}={};", index, swizzle, value); | ||
| 276 | return; | ||
| 277 | } | ||
| 278 | switch (attr) { | 264 | switch (attr) { |
| 279 | case IR::Attribute::Layer: | 265 | case IR::Attribute::Layer: |
| 280 | if (ctx.stage != Stage::Geometry && | 266 | if (ctx.stage != Stage::Geometry && |
| @@ -312,33 +298,6 @@ void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view val | |||
| 312 | case IR::Attribute::PositionW: | 298 | case IR::Attribute::PositionW: |
| 313 | ctx.Add("gl_Position.{}={};", swizzle, value); | 299 | ctx.Add("gl_Position.{}={};", swizzle, value); |
| 314 | break; | 300 | break; |
| 315 | case IR::Attribute::ColorFrontDiffuseR: | ||
| 316 | case IR::Attribute::ColorFrontDiffuseG: | ||
| 317 | case IR::Attribute::ColorFrontDiffuseB: | ||
| 318 | case IR::Attribute::ColorFrontDiffuseA: | ||
| 319 | ctx.Add("gl_FrontColor.{}={};", swizzle, value); | ||
| 320 | break; | ||
| 321 | case IR::Attribute::ColorFrontSpecularR: | ||
| 322 | case IR::Attribute::ColorFrontSpecularG: | ||
| 323 | case IR::Attribute::ColorFrontSpecularB: | ||
| 324 | case IR::Attribute::ColorFrontSpecularA: | ||
| 325 | ctx.Add("gl_FrontSecondaryColor.{}={};", swizzle, value); | ||
| 326 | break; | ||
| 327 | case IR::Attribute::ColorBackDiffuseR: | ||
| 328 | case IR::Attribute::ColorBackDiffuseG: | ||
| 329 | case IR::Attribute::ColorBackDiffuseB: | ||
| 330 | case IR::Attribute::ColorBackDiffuseA: | ||
| 331 | ctx.Add("gl_BackColor.{}={};", swizzle, value); | ||
| 332 | break; | ||
| 333 | case IR::Attribute::ColorBackSpecularR: | ||
| 334 | case IR::Attribute::ColorBackSpecularG: | ||
| 335 | case IR::Attribute::ColorBackSpecularB: | ||
| 336 | case IR::Attribute::ColorBackSpecularA: | ||
| 337 | ctx.Add("gl_BackSecondaryColor.{}={};", swizzle, value); | ||
| 338 | break; | ||
| 339 | case IR::Attribute::FogCoordinate: | ||
| 340 | ctx.Add("gl_FogFragCoord={};", value); | ||
| 341 | break; | ||
| 342 | case IR::Attribute::ClipDistance0: | 301 | case IR::Attribute::ClipDistance0: |
| 343 | case IR::Attribute::ClipDistance1: | 302 | case IR::Attribute::ClipDistance1: |
| 344 | case IR::Attribute::ClipDistance2: | 303 | case IR::Attribute::ClipDistance2: |
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 b765a251b..474189d87 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp | |||
| @@ -125,11 +125,11 @@ void EmitFPNeg16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& i | |||
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | void EmitFPNeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | 127 | void EmitFPNeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { |
| 128 | ctx.AddF32("{}=-({});", inst, value); | 128 | ctx.AddF32("{}=0.f-({});", inst, value); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | void EmitFPNeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | 131 | void EmitFPNeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value) { |
| 132 | ctx.AddF64("{}=-({});", inst, value); | 132 | ctx.AddF64("{}=double(0.)-({});", inst, value); |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | void EmitFPSin(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | 135 | void EmitFPSin(EmitContext& ctx, IR::Inst& inst, std::string_view value) { |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h index f86502e4c..6cabbc717 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h +++ b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h | |||
| @@ -60,6 +60,8 @@ void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding | |||
| 60 | const IR::Value& offset); | 60 | const IR::Value& offset); |
| 61 | void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, | 61 | void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, |
| 62 | std::string_view vertex); | 62 | std::string_view vertex); |
| 63 | void EmitGetAttributeU32(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, | ||
| 64 | std::string_view vertex); | ||
| 63 | void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view value, | 65 | void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view value, |
| 64 | std::string_view vertex); | 66 | std::string_view vertex); |
| 65 | void EmitGetAttributeIndexed(EmitContext& ctx, IR::Inst& inst, std::string_view offset, | 67 | void EmitGetAttributeIndexed(EmitContext& ctx, IR::Inst& inst, std::string_view offset, |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp index 44060df33..b0d85be99 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp | |||
| @@ -87,11 +87,11 @@ void EmitUDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::strin | |||
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | void EmitINeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | 89 | void EmitINeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { |
| 90 | ctx.AddU32("{}=uint(-({}));", inst, value); | 90 | ctx.AddU32("{}=uint(int(0)-int({}));", inst, value); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | void EmitINeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | 93 | void EmitINeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value) { |
| 94 | ctx.AddU64("{}=-({});", inst, value); | 94 | ctx.AddU64("{}=uint64_t(int64_t(0)-int64_t({}));", inst, value); |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | 97 | void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp index b8ddafe48..fcf620b79 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp | |||
| @@ -90,7 +90,9 @@ void EmitPhiMove(EmitContext& ctx, const IR::Value& phi_value, const IR::Value& | |||
| 90 | if (phi_reg == val_reg) { | 90 | if (phi_reg == val_reg) { |
| 91 | return; | 91 | return; |
| 92 | } | 92 | } |
| 93 | ctx.Add("{}={};", phi_reg, val_reg); | 93 | const bool needs_workaround{ctx.profile.has_gl_bool_ref_bug && phi_type == IR::Type::U1}; |
| 94 | const auto suffix{needs_workaround ? "?true:false" : ""}; | ||
| 95 | ctx.Add("{}={}{};", phi_reg, val_reg, suffix); | ||
| 94 | } | 96 | } |
| 95 | 97 | ||
| 96 | void EmitPrologue(EmitContext& ctx) { | 98 | void EmitPrologue(EmitContext& ctx) { |
diff --git a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp index 1de017e76..bb7f1a0fd 100644 --- a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp | |||
| @@ -211,27 +211,6 @@ std::string_view OutputPrimitive(OutputTopology topology) { | |||
| 211 | throw InvalidArgument("Invalid output topology {}", topology); | 211 | throw InvalidArgument("Invalid output topology {}", topology); |
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | void SetupLegacyOutPerVertex(EmitContext& ctx, std::string& header) { | ||
| 215 | if (!ctx.info.stores.Legacy()) { | ||
| 216 | return; | ||
| 217 | } | ||
| 218 | if (ctx.info.stores.FixedFunctionTexture()) { | ||
| 219 | header += "vec4 gl_TexCoord[8];"; | ||
| 220 | } | ||
| 221 | if (ctx.info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { | ||
| 222 | header += "vec4 gl_FrontColor;"; | ||
| 223 | } | ||
| 224 | if (ctx.info.stores.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { | ||
| 225 | header += "vec4 gl_FrontSecondaryColor;"; | ||
| 226 | } | ||
| 227 | if (ctx.info.stores.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { | ||
| 228 | header += "vec4 gl_BackColor;"; | ||
| 229 | } | ||
| 230 | if (ctx.info.stores.AnyComponent(IR::Attribute::ColorBackSpecularR)) { | ||
| 231 | header += "vec4 gl_BackSecondaryColor;"; | ||
| 232 | } | ||
| 233 | } | ||
| 234 | |||
| 235 | void SetupOutPerVertex(EmitContext& ctx, std::string& header) { | 214 | void SetupOutPerVertex(EmitContext& ctx, std::string& header) { |
| 236 | if (!StoresPerVertexAttributes(ctx.stage)) { | 215 | if (!StoresPerVertexAttributes(ctx.stage)) { |
| 237 | return; | 216 | return; |
| @@ -250,7 +229,6 @@ void SetupOutPerVertex(EmitContext& ctx, std::string& header) { | |||
| 250 | ctx.profile.support_viewport_index_layer_non_geometry && ctx.stage != Stage::Geometry) { | 229 | ctx.profile.support_viewport_index_layer_non_geometry && ctx.stage != Stage::Geometry) { |
| 251 | header += "int gl_ViewportIndex;"; | 230 | header += "int gl_ViewportIndex;"; |
| 252 | } | 231 | } |
| 253 | SetupLegacyOutPerVertex(ctx, header); | ||
| 254 | header += "};"; | 232 | header += "};"; |
| 255 | if (ctx.info.stores[IR::Attribute::ViewportIndex] && ctx.stage == Stage::Geometry) { | 233 | if (ctx.info.stores[IR::Attribute::ViewportIndex] && ctx.stage == Stage::Geometry) { |
| 256 | header += "out int gl_ViewportIndex;"; | 234 | header += "out int gl_ViewportIndex;"; |
| @@ -282,21 +260,6 @@ void SetupInPerVertex(EmitContext& ctx, std::string& header) { | |||
| 282 | } | 260 | } |
| 283 | header += "}gl_in[gl_MaxPatchVertices];"; | 261 | header += "}gl_in[gl_MaxPatchVertices];"; |
| 284 | } | 262 | } |
| 285 | |||
| 286 | void SetupLegacyInPerFragment(EmitContext& ctx, std::string& header) { | ||
| 287 | if (!ctx.info.loads.Legacy()) { | ||
| 288 | return; | ||
| 289 | } | ||
| 290 | header += "in gl_PerFragment{"; | ||
| 291 | if (ctx.info.loads.FixedFunctionTexture()) { | ||
| 292 | header += "vec4 gl_TexCoord[8];"; | ||
| 293 | } | ||
| 294 | if (ctx.info.loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { | ||
| 295 | header += "vec4 gl_Color;"; | ||
| 296 | } | ||
| 297 | header += "};"; | ||
| 298 | } | ||
| 299 | |||
| 300 | } // Anonymous namespace | 263 | } // Anonymous namespace |
| 301 | 264 | ||
| 302 | EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_, | 265 | EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_, |
| @@ -361,7 +324,6 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile | |||
| 361 | } | 324 | } |
| 362 | SetupOutPerVertex(*this, header); | 325 | SetupOutPerVertex(*this, header); |
| 363 | SetupInPerVertex(*this, header); | 326 | SetupInPerVertex(*this, header); |
| 364 | SetupLegacyInPerFragment(*this, header); | ||
| 365 | 327 | ||
| 366 | for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { | 328 | for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { |
| 367 | if (!info.loads.Generic(index) || !runtime_info.previous_stage_stores.Generic(index)) { | 329 | if (!info.loads.Generic(index) || !runtime_info.previous_stage_stores.Generic(index)) { |
| @@ -466,9 +428,10 @@ void EmitContext::DefineConstantBuffers(Bindings& bindings) { | |||
| 466 | return; | 428 | return; |
| 467 | } | 429 | } |
| 468 | for (const auto& desc : info.constant_buffer_descriptors) { | 430 | for (const auto& desc : info.constant_buffer_descriptors) { |
| 469 | header += fmt::format( | 431 | const auto cbuf_type{profile.has_gl_cbuf_ftou_bug ? "uvec4" : "vec4"}; |
| 470 | "layout(std140,binding={}) uniform {}_cbuf_{}{{vec4 {}_cbuf{}[{}];}};", | 432 | header += fmt::format("layout(std140,binding={}) uniform {}_cbuf_{}{{{} {}_cbuf{}[{}];}};", |
| 471 | 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); | ||
| 472 | bindings.uniform_buffer += desc.count; | 435 | bindings.uniform_buffer += desc.count; |
| 473 | } | 436 | } |
| 474 | } | 437 | } |