diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp | 142 | ||||
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl_instructions.h | 31 |
2 files changed, 173 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp index dc377b053..a409a7ab3 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp | |||
| @@ -105,6 +105,13 @@ void EmitSharedAtomicExchange64(EmitContext& ctx, IR::Inst& inst, std::string_vi | |||
| 105 | pointer_offset, value, pointer_offset, value); | 105 | pointer_offset, value, pointer_offset, value); |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | void EmitSharedAtomicExchange32x2(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset, | ||
| 109 | std::string_view value) { | ||
| 110 | LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic"); | ||
| 111 | ctx.AddU32x2("{}=uvec2(smem[{}>>2],smem[({}+4)>>2]);", inst, pointer_offset, pointer_offset); | ||
| 112 | ctx.Add("smem[{}>>2]={}.x;smem[({}+4)>>2]={}.y;", pointer_offset, value, pointer_offset, value); | ||
| 113 | } | ||
| 114 | |||
| 108 | void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 115 | void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 109 | const IR::Value& offset, std::string_view value) { | 116 | const IR::Value& offset, std::string_view value) { |
| 110 | ctx.AddU32("{}=atomicAdd({}_ssbo{}[{}>>2],{});", inst, ctx.stage_name, binding.U32(), | 117 | ctx.AddU32("{}=atomicAdd({}_ssbo{}[{}>>2],{});", inst, ctx.stage_name, binding.U32(), |
| @@ -265,6 +272,97 @@ void EmitStorageAtomicExchange64(EmitContext& ctx, IR::Inst& inst, const IR::Val | |||
| 265 | ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value); | 272 | ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value); |
| 266 | } | 273 | } |
| 267 | 274 | ||
| 275 | void EmitStorageAtomicIAdd32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 276 | const IR::Value& offset, std::string_view value) { | ||
| 277 | LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic"); | ||
| 278 | ctx.AddU32x2("{}=uvec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]);", inst, ctx.stage_name, | ||
| 279 | binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name, binding.U32(), | ||
| 280 | ctx.var_alloc.Consume(offset)); | ||
| 281 | ctx.Add("{}_ssbo{}[{}>>2]+={}.x;{}_ssbo{}[({}>>2)+1]+={}.y;", ctx.stage_name, binding.U32(), | ||
| 282 | ctx.var_alloc.Consume(offset), value, ctx.stage_name, binding.U32(), | ||
| 283 | ctx.var_alloc.Consume(offset), value); | ||
| 284 | } | ||
| 285 | |||
| 286 | void EmitStorageAtomicSMin32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 287 | const IR::Value& offset, std::string_view value) { | ||
| 288 | LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic"); | ||
| 289 | ctx.AddU32x2("{}=ivec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]);", inst, ctx.stage_name, | ||
| 290 | binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name, binding.U32(), | ||
| 291 | ctx.var_alloc.Consume(offset)); | ||
| 292 | ctx.Add("for(int " | ||
| 293 | "i=0;i<2;++i){{{}_ssbo{}[({}>>2)+i]=uint(min(int({}_ssbo{}[({}>>2)+i]),int({}[i])));}}", | ||
| 294 | ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name, | ||
| 295 | binding.U32(), ctx.var_alloc.Consume(offset), value); | ||
| 296 | } | ||
| 297 | |||
| 298 | void EmitStorageAtomicUMin32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 299 | const IR::Value& offset, std::string_view value) { | ||
| 300 | LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic"); | ||
| 301 | ctx.AddU32x2("{}=uvec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]);", inst, ctx.stage_name, | ||
| 302 | binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name, binding.U32(), | ||
| 303 | ctx.var_alloc.Consume(offset)); | ||
| 304 | ctx.Add("for(int i=0;i<2;++i){{ " | ||
| 305 | "{}_ssbo{}[({}>>2)+i]=min({}_ssbo{}[({}>>2)+i],{}[i]);}}", | ||
| 306 | ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name, | ||
| 307 | binding.U32(), ctx.var_alloc.Consume(offset), value); | ||
| 308 | } | ||
| 309 | |||
| 310 | void EmitStorageAtomicSMax32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 311 | const IR::Value& offset, std::string_view value) { | ||
| 312 | LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic"); | ||
| 313 | ctx.AddU32x2("{}=ivec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]);", inst, ctx.stage_name, | ||
| 314 | binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name, binding.U32(), | ||
| 315 | ctx.var_alloc.Consume(offset)); | ||
| 316 | ctx.Add("for(int " | ||
| 317 | "i=0;i<2;++i){{{}_ssbo{}[({}>>2)+i]=uint(max(int({}_ssbo{}[({}>>2)+i]),int({}[i])));}}", | ||
| 318 | ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name, | ||
| 319 | binding.U32(), ctx.var_alloc.Consume(offset), value); | ||
| 320 | } | ||
| 321 | |||
| 322 | void EmitStorageAtomicUMax32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 323 | const IR::Value& offset, std::string_view value) { | ||
| 324 | LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic"); | ||
| 325 | ctx.AddU32x2("{}=uvec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]);", inst, ctx.stage_name, | ||
| 326 | binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name, binding.U32(), | ||
| 327 | ctx.var_alloc.Consume(offset)); | ||
| 328 | ctx.Add("for(int i=0;i<2;++i){{{}_ssbo{}[({}>>2)+i]=max({}_ssbo{}[({}>>2)+i],{}[i]);}}", | ||
| 329 | ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name, | ||
| 330 | binding.U32(), ctx.var_alloc.Consume(offset), value); | ||
| 331 | } | ||
| 332 | |||
| 333 | void EmitStorageAtomicAnd32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 334 | const IR::Value& offset, std::string_view value) { | ||
| 335 | LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to 32x2"); | ||
| 336 | ctx.AddU32x2("{}=uvec2(atomicAnd({}_ssbo{}[{}>>2],{}.x),atomicAnd({}_ssbo{}[({}>>2)+1],{}.y));", | ||
| 337 | inst, ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value, | ||
| 338 | ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value); | ||
| 339 | } | ||
| 340 | |||
| 341 | void EmitStorageAtomicOr32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 342 | const IR::Value& offset, std::string_view value) { | ||
| 343 | LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to 32x2"); | ||
| 344 | ctx.AddU32x2("{}=uvec2(atomicOr({}_ssbo{}[{}>>2],{}.x),atomicOr({}_ssbo{}[({}>>2)+1],{}.y));", | ||
| 345 | inst, ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value, | ||
| 346 | ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value); | ||
| 347 | } | ||
| 348 | |||
| 349 | void EmitStorageAtomicXor32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 350 | const IR::Value& offset, std::string_view value) { | ||
| 351 | LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to 32x2"); | ||
| 352 | ctx.AddU32x2("{}=uvec2(atomicXor({}_ssbo{}[{}>>2],{}.x),atomicXor({}_ssbo{}[({}>>2)+1],{}.y));", | ||
| 353 | inst, ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value, | ||
| 354 | ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value); | ||
| 355 | } | ||
| 356 | |||
| 357 | void EmitStorageAtomicExchange32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 358 | const IR::Value& offset, std::string_view value) { | ||
| 359 | LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to 32x2"); | ||
| 360 | ctx.AddU32x2("{}=uvec2(atomicExchange({}_ssbo{}[{}>>2],{}.x),atomicExchange({}_ssbo{}[({}>>2)+" | ||
| 361 | "1],{}.y));", | ||
| 362 | inst, ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value, | ||
| 363 | ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value); | ||
| 364 | } | ||
| 365 | |||
| 268 | void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 366 | void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 269 | const IR::Value& offset, std::string_view value) { | 367 | const IR::Value& offset, std::string_view value) { |
| 270 | SsboCasFunctionF32(ctx, inst, binding, offset, value, "CasFloatAdd"); | 368 | SsboCasFunctionF32(ctx, inst, binding, offset, value, "CasFloatAdd"); |
| @@ -388,6 +486,50 @@ void EmitGlobalAtomicExchange64(EmitContext&) { | |||
| 388 | throw NotImplementedException("GLSL Instrucion"); | 486 | throw NotImplementedException("GLSL Instrucion"); |
| 389 | } | 487 | } |
| 390 | 488 | ||
| 489 | void EmitGlobalAtomicIAdd32x2(EmitContext&) { | ||
| 490 | throw NotImplementedException("GLSL Instrucion"); | ||
| 491 | } | ||
| 492 | |||
| 493 | void EmitGlobalAtomicSMin32x2(EmitContext&) { | ||
| 494 | throw NotImplementedException("GLSL Instrucion"); | ||
| 495 | } | ||
| 496 | |||
| 497 | void EmitGlobalAtomicUMin32x2(EmitContext&) { | ||
| 498 | throw NotImplementedException("GLSL Instrucion"); | ||
| 499 | } | ||
| 500 | |||
| 501 | void EmitGlobalAtomicSMax32x2(EmitContext&) { | ||
| 502 | throw NotImplementedException("GLSL Instrucion"); | ||
| 503 | } | ||
| 504 | |||
| 505 | void EmitGlobalAtomicUMax32x2(EmitContext&) { | ||
| 506 | throw NotImplementedException("GLSL Instrucion"); | ||
| 507 | } | ||
| 508 | |||
| 509 | void EmitGlobalAtomicInc32x2(EmitContext&) { | ||
| 510 | throw NotImplementedException("GLSL Instrucion"); | ||
| 511 | } | ||
| 512 | |||
| 513 | void EmitGlobalAtomicDec32x2(EmitContext&) { | ||
| 514 | throw NotImplementedException("GLSL Instrucion"); | ||
| 515 | } | ||
| 516 | |||
| 517 | void EmitGlobalAtomicAnd32x2(EmitContext&) { | ||
| 518 | throw NotImplementedException("GLSL Instrucion"); | ||
| 519 | } | ||
| 520 | |||
| 521 | void EmitGlobalAtomicOr32x2(EmitContext&) { | ||
| 522 | throw NotImplementedException("GLSL Instrucion"); | ||
| 523 | } | ||
| 524 | |||
| 525 | void EmitGlobalAtomicXor32x2(EmitContext&) { | ||
| 526 | throw NotImplementedException("GLSL Instrucion"); | ||
| 527 | } | ||
| 528 | |||
| 529 | void EmitGlobalAtomicExchange32x2(EmitContext&) { | ||
| 530 | throw NotImplementedException("GLSL Instrucion"); | ||
| 531 | } | ||
| 532 | |||
| 391 | void EmitGlobalAtomicAddF32(EmitContext&) { | 533 | void EmitGlobalAtomicAddF32(EmitContext&) { |
| 392 | throw NotImplementedException("GLSL Instrucion"); | 534 | throw NotImplementedException("GLSL Instrucion"); |
| 393 | } | 535 | } |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h index 6cabbc717..704baddc9 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h +++ b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h | |||
| @@ -442,6 +442,8 @@ void EmitSharedAtomicExchange32(EmitContext& ctx, IR::Inst& inst, std::string_vi | |||
| 442 | std::string_view value); | 442 | std::string_view value); |
| 443 | void EmitSharedAtomicExchange64(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset, | 443 | void EmitSharedAtomicExchange64(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset, |
| 444 | std::string_view value); | 444 | std::string_view value); |
| 445 | void EmitSharedAtomicExchange32x2(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset, | ||
| 446 | std::string_view value); | ||
| 445 | void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 447 | void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 446 | const IR::Value& offset, std::string_view value); | 448 | const IR::Value& offset, std::string_view value); |
| 447 | void EmitStorageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 449 | void EmitStorageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| @@ -482,6 +484,24 @@ void EmitStorageAtomicXor64(EmitContext& ctx, IR::Inst& inst, const IR::Value& b | |||
| 482 | const IR::Value& offset, std::string_view value); | 484 | const IR::Value& offset, std::string_view value); |
| 483 | void EmitStorageAtomicExchange64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 485 | void EmitStorageAtomicExchange64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 484 | const IR::Value& offset, std::string_view value); | 486 | const IR::Value& offset, std::string_view value); |
| 487 | void EmitStorageAtomicIAdd32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 488 | const IR::Value& offset, std::string_view value); | ||
| 489 | void EmitStorageAtomicSMin32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 490 | const IR::Value& offset, std::string_view value); | ||
| 491 | void EmitStorageAtomicUMin32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 492 | const IR::Value& offset, std::string_view value); | ||
| 493 | void EmitStorageAtomicSMax32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 494 | const IR::Value& offset, std::string_view value); | ||
| 495 | void EmitStorageAtomicUMax32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 496 | const IR::Value& offset, std::string_view value); | ||
| 497 | void EmitStorageAtomicAnd32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 498 | const IR::Value& offset, std::string_view value); | ||
| 499 | void EmitStorageAtomicOr32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 500 | const IR::Value& offset, std::string_view value); | ||
| 501 | void EmitStorageAtomicXor32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 502 | const IR::Value& offset, std::string_view value); | ||
| 503 | void EmitStorageAtomicExchange32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 504 | const IR::Value& offset, std::string_view value); | ||
| 485 | void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 505 | void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 486 | const IR::Value& offset, std::string_view value); | 506 | const IR::Value& offset, std::string_view value); |
| 487 | void EmitStorageAtomicAddF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 507 | void EmitStorageAtomicAddF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| @@ -518,6 +538,17 @@ void EmitGlobalAtomicAnd64(EmitContext& ctx); | |||
| 518 | void EmitGlobalAtomicOr64(EmitContext& ctx); | 538 | void EmitGlobalAtomicOr64(EmitContext& ctx); |
| 519 | void EmitGlobalAtomicXor64(EmitContext& ctx); | 539 | void EmitGlobalAtomicXor64(EmitContext& ctx); |
| 520 | void EmitGlobalAtomicExchange64(EmitContext& ctx); | 540 | void EmitGlobalAtomicExchange64(EmitContext& ctx); |
| 541 | void EmitGlobalAtomicIAdd32x2(EmitContext& ctx); | ||
| 542 | void EmitGlobalAtomicSMin32x2(EmitContext& ctx); | ||
| 543 | void EmitGlobalAtomicUMin32x2(EmitContext& ctx); | ||
| 544 | void EmitGlobalAtomicSMax32x2(EmitContext& ctx); | ||
| 545 | void EmitGlobalAtomicUMax32x2(EmitContext& ctx); | ||
| 546 | void EmitGlobalAtomicInc32x2(EmitContext& ctx); | ||
| 547 | void EmitGlobalAtomicDec32x2(EmitContext& ctx); | ||
| 548 | void EmitGlobalAtomicAnd32x2(EmitContext& ctx); | ||
| 549 | void EmitGlobalAtomicOr32x2(EmitContext& ctx); | ||
| 550 | void EmitGlobalAtomicXor32x2(EmitContext& ctx); | ||
| 551 | void EmitGlobalAtomicExchange32x2(EmitContext& ctx); | ||
| 521 | void EmitGlobalAtomicAddF32(EmitContext& ctx); | 552 | void EmitGlobalAtomicAddF32(EmitContext& ctx); |
| 522 | void EmitGlobalAtomicAddF16x2(EmitContext& ctx); | 553 | void EmitGlobalAtomicAddF16x2(EmitContext& ctx); |
| 523 | void EmitGlobalAtomicAddF32x2(EmitContext& ctx); | 554 | void EmitGlobalAtomicAddF32x2(EmitContext& ctx); |