diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_context.cpp | 4 | ||||
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp | 68 |
2 files changed, 60 insertions, 12 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp index 6c2828644..e0d678554 100644 --- a/src/shader_recompiler/backend/glsl/emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/emit_context.cpp | |||
| @@ -239,6 +239,7 @@ bool UsesTyplessImage(const Info& info) { | |||
| 239 | EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_, | 239 | EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_, |
| 240 | const RuntimeInfo& runtime_info_) | 240 | const RuntimeInfo& runtime_info_) |
| 241 | : info{program.info}, profile{profile_}, runtime_info{runtime_info_} { | 241 | : info{program.info}, profile{profile_}, runtime_info{runtime_info_} { |
| 242 | header += "#pragma optionNV(fastmath off)\n"; | ||
| 242 | SetupExtensions(header); | 243 | SetupExtensions(header); |
| 243 | stage = program.stage; | 244 | stage = program.stage; |
| 244 | switch (program.stage) { | 245 | switch (program.stage) { |
| @@ -351,6 +352,9 @@ void EmitContext::SetupExtensions(std::string&) { | |||
| 351 | if (info.uses_sparse_residency) { | 352 | if (info.uses_sparse_residency) { |
| 352 | header += "#extension GL_ARB_sparse_texture2 : enable\n"; | 353 | header += "#extension GL_ARB_sparse_texture2 : enable\n"; |
| 353 | } | 354 | } |
| 355 | if (info.stores_viewport_mask && profile.support_viewport_mask) { | ||
| 356 | header += "#extension GL_NV_viewport_array2 : enable\n"; | ||
| 357 | } | ||
| 354 | if (UsesTyplessImage(info)) { | 358 | if (UsesTyplessImage(info)) { |
| 355 | header += "#extension GL_EXT_shader_image_load_formatted : enable\n"; | 359 | header += "#extension GL_EXT_shader_image_load_formatted : enable\n"; |
| 356 | } | 360 | } |
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 d09187ea7..c9a2ceb3d 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 | |||
| @@ -203,6 +203,9 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, | |||
| 203 | return; | 203 | return; |
| 204 | } | 204 | } |
| 205 | switch (attr) { | 205 | switch (attr) { |
| 206 | case IR::Attribute::PrimitiveId: | ||
| 207 | ctx.AddF32("{}=itof(gl_PrimitiveID);", inst); | ||
| 208 | break; | ||
| 206 | case IR::Attribute::PositionX: | 209 | case IR::Attribute::PositionX: |
| 207 | case IR::Attribute::PositionY: | 210 | case IR::Attribute::PositionY: |
| 208 | case IR::Attribute::PositionZ: | 211 | case IR::Attribute::PositionZ: |
| @@ -212,10 +215,20 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, | |||
| 212 | ctx.AddF32("{}={}{}.{};", inst, input_decorator, ctx.position_name, swizzle); | 215 | ctx.AddF32("{}={}{}.{};", inst, input_decorator, ctx.position_name, swizzle); |
| 213 | break; | 216 | break; |
| 214 | } | 217 | } |
| 218 | case IR::Attribute::ColorFrontDiffuseR: | ||
| 219 | case IR::Attribute::ColorFrontDiffuseG: | ||
| 220 | case IR::Attribute::ColorFrontDiffuseB: | ||
| 221 | case IR::Attribute::ColorFrontDiffuseA: | ||
| 222 | ctx.AddF32("{}=gl_FrontMaterial.diffuse.{};", inst, swizzle); | ||
| 223 | break; | ||
| 215 | case IR::Attribute::PointSpriteS: | 224 | case IR::Attribute::PointSpriteS: |
| 216 | case IR::Attribute::PointSpriteT: | 225 | case IR::Attribute::PointSpriteT: |
| 217 | ctx.AddF32("{}=gl_PointCoord.{};", inst, swizzle); | 226 | ctx.AddF32("{}=gl_PointCoord.{};", inst, swizzle); |
| 218 | break; | 227 | break; |
| 228 | case IR::Attribute::TessellationEvaluationPointU: | ||
| 229 | case IR::Attribute::TessellationEvaluationPointV: | ||
| 230 | ctx.AddF32("{}=gl_TessCoord.{};", inst, swizzle); | ||
| 231 | break; | ||
| 219 | case IR::Attribute::InstanceId: | 232 | case IR::Attribute::InstanceId: |
| 220 | ctx.AddF32("{}=itof(gl_InstanceID);", inst); | 233 | ctx.AddF32("{}=itof(gl_InstanceID);", inst); |
| 221 | break; | 234 | break; |
| @@ -225,10 +238,6 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, | |||
| 225 | case IR::Attribute::FrontFace: | 238 | case IR::Attribute::FrontFace: |
| 226 | ctx.AddF32("{}=itof(gl_FrontFacing?-1:0);", inst); | 239 | ctx.AddF32("{}=itof(gl_FrontFacing?-1:0);", inst); |
| 227 | break; | 240 | break; |
| 228 | case IR::Attribute::TessellationEvaluationPointU: | ||
| 229 | case IR::Attribute::TessellationEvaluationPointV: | ||
| 230 | ctx.AddF32("{}=gl_TessCoord.{};", inst, swizzle); | ||
| 231 | break; | ||
| 232 | default: | 241 | default: |
| 233 | fmt::print("Get attribute {}", attr); | 242 | fmt::print("Get attribute {}", attr); |
| 234 | throw NotImplementedException("Get attribute {}", attr); | 243 | throw NotImplementedException("Get attribute {}", attr); |
| @@ -262,6 +271,23 @@ void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view val | |||
| 262 | } | 271 | } |
| 263 | ctx.Add("gl_Layer=ftoi({});", value); | 272 | ctx.Add("gl_Layer=ftoi({});", value); |
| 264 | break; | 273 | break; |
| 274 | case IR::Attribute::ViewportIndex: | ||
| 275 | if (ctx.stage != Stage::Geometry && | ||
| 276 | !ctx.profile.support_viewport_index_layer_non_geometry) { | ||
| 277 | // LOG_WARNING(..., "Shader stores viewport index but device does not support viewport | ||
| 278 | // layer extension"); | ||
| 279 | break; | ||
| 280 | } | ||
| 281 | ctx.Add("gl_ViewportIndex=ftoi({});", value); | ||
| 282 | break; | ||
| 283 | case IR::Attribute::ViewportMask: | ||
| 284 | if (ctx.stage != Stage::Geometry && !ctx.profile.support_viewport_mask) { | ||
| 285 | // LOG_WARNING(..., "Shader stores viewport mask but device does not support viewport | ||
| 286 | // mask extension"); | ||
| 287 | break; | ||
| 288 | } | ||
| 289 | ctx.Add("gl_ViewportMask[0]=ftoi({});", value); | ||
| 290 | break; | ||
| 265 | case IR::Attribute::PointSize: | 291 | case IR::Attribute::PointSize: |
| 266 | ctx.Add("gl_PointSize={};", value); | 292 | ctx.Add("gl_PointSize={};", value); |
| 267 | break; | 293 | break; |
| @@ -271,14 +297,32 @@ void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view val | |||
| 271 | case IR::Attribute::PositionW: | 297 | case IR::Attribute::PositionW: |
| 272 | ctx.Add("gl_Position.{}={};", swizzle, value); | 298 | ctx.Add("gl_Position.{}={};", swizzle, value); |
| 273 | break; | 299 | break; |
| 274 | case IR::Attribute::ViewportIndex: | 300 | case IR::Attribute::ColorFrontDiffuseR: |
| 275 | if (ctx.stage != Stage::Geometry && | 301 | case IR::Attribute::ColorFrontDiffuseG: |
| 276 | !ctx.profile.support_viewport_index_layer_non_geometry) { | 302 | case IR::Attribute::ColorFrontDiffuseB: |
| 277 | // LOG_WARNING(..., "Shader stores viewport index but device does not support viewport | 303 | case IR::Attribute::ColorFrontDiffuseA: |
| 278 | // layer extension"); | 304 | ctx.Add("gl_FrontMaterial.diffuse.{}={};", swizzle, value); |
| 279 | break; | 305 | break; |
| 280 | } | 306 | case IR::Attribute::ColorFrontSpecularR: |
| 281 | ctx.Add("gl_ViewportIndex=ftoi({});", value); | 307 | case IR::Attribute::ColorFrontSpecularG: |
| 308 | case IR::Attribute::ColorFrontSpecularB: | ||
| 309 | case IR::Attribute::ColorFrontSpecularA: | ||
| 310 | ctx.Add("gl_FrontMaterial.specular.{}={};", swizzle, value); | ||
| 311 | break; | ||
| 312 | case IR::Attribute::ColorBackDiffuseR: | ||
| 313 | case IR::Attribute::ColorBackDiffuseG: | ||
| 314 | case IR::Attribute::ColorBackDiffuseB: | ||
| 315 | case IR::Attribute::ColorBackDiffuseA: | ||
| 316 | ctx.Add("gl_BackMaterial.diffuse.{}={};", swizzle, value); | ||
| 317 | break; | ||
| 318 | case IR::Attribute::ColorBackSpecularR: | ||
| 319 | case IR::Attribute::ColorBackSpecularG: | ||
| 320 | case IR::Attribute::ColorBackSpecularB: | ||
| 321 | case IR::Attribute::ColorBackSpecularA: | ||
| 322 | ctx.Add("gl_BackMaterial.specular.{}={};", swizzle, value); | ||
| 323 | break; | ||
| 324 | case IR::Attribute::FogCoordinate: | ||
| 325 | ctx.Add("gl_FragCoord.x={};", value); | ||
| 282 | break; | 326 | break; |
| 283 | case IR::Attribute::ClipDistance0: | 327 | case IR::Attribute::ClipDistance0: |
| 284 | case IR::Attribute::ClipDistance1: | 328 | case IR::Attribute::ClipDistance1: |