diff options
Diffstat (limited to 'src/shader_recompiler/backend')
10 files changed, 558 insertions, 30 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h index b48007856..5efbe4e6f 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h +++ b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h | |||
| @@ -372,6 +372,8 @@ void EmitSharedAtomicExchange32(EmitContext& ctx, IR::Inst& inst, ScalarU32 poin | |||
| 372 | ScalarU32 value); | 372 | ScalarU32 value); |
| 373 | void EmitSharedAtomicExchange64(EmitContext& ctx, IR::Inst& inst, ScalarU32 pointer_offset, | 373 | void EmitSharedAtomicExchange64(EmitContext& ctx, IR::Inst& inst, ScalarU32 pointer_offset, |
| 374 | Register value); | 374 | Register value); |
| 375 | void EmitSharedAtomicExchange32x2(EmitContext& ctx, IR::Inst& inst, ScalarU32 pointer_offset, | ||
| 376 | Register value); | ||
| 375 | void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 377 | void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 376 | ScalarU32 offset, ScalarU32 value); | 378 | ScalarU32 offset, ScalarU32 value); |
| 377 | void EmitStorageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 379 | void EmitStorageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| @@ -412,6 +414,24 @@ void EmitStorageAtomicXor64(EmitContext& ctx, IR::Inst& inst, const IR::Value& b | |||
| 412 | ScalarU32 offset, Register value); | 414 | ScalarU32 offset, Register value); |
| 413 | void EmitStorageAtomicExchange64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 415 | void EmitStorageAtomicExchange64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 414 | ScalarU32 offset, Register value); | 416 | ScalarU32 offset, Register value); |
| 417 | void EmitStorageAtomicIAdd32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 418 | ScalarU32 offset, Register value); | ||
| 419 | void EmitStorageAtomicSMin32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 420 | ScalarU32 offset, Register value); | ||
| 421 | void EmitStorageAtomicUMin32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 422 | ScalarU32 offset, Register value); | ||
| 423 | void EmitStorageAtomicSMax32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 424 | ScalarU32 offset, Register value); | ||
| 425 | void EmitStorageAtomicUMax32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 426 | ScalarU32 offset, Register value); | ||
| 427 | void EmitStorageAtomicAnd32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 428 | ScalarU32 offset, Register value); | ||
| 429 | void EmitStorageAtomicOr32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 430 | ScalarU32 offset, Register value); | ||
| 431 | void EmitStorageAtomicXor32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 432 | ScalarU32 offset, Register value); | ||
| 433 | void EmitStorageAtomicExchange32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | ||
| 434 | ScalarU32 offset, Register value); | ||
| 415 | void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 435 | void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 416 | ScalarU32 offset, ScalarF32 value); | 436 | ScalarU32 offset, ScalarF32 value); |
| 417 | void EmitStorageAtomicAddF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 437 | void EmitStorageAtomicAddF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| @@ -448,6 +468,17 @@ void EmitGlobalAtomicAnd64(EmitContext& ctx); | |||
| 448 | void EmitGlobalAtomicOr64(EmitContext& ctx); | 468 | void EmitGlobalAtomicOr64(EmitContext& ctx); |
| 449 | void EmitGlobalAtomicXor64(EmitContext& ctx); | 469 | void EmitGlobalAtomicXor64(EmitContext& ctx); |
| 450 | void EmitGlobalAtomicExchange64(EmitContext& ctx); | 470 | void EmitGlobalAtomicExchange64(EmitContext& ctx); |
| 471 | void EmitGlobalAtomicIAdd32x2(EmitContext& ctx); | ||
| 472 | void EmitGlobalAtomicSMin32x2(EmitContext& ctx); | ||
| 473 | void EmitGlobalAtomicUMin32x2(EmitContext& ctx); | ||
| 474 | void EmitGlobalAtomicSMax32x2(EmitContext& ctx); | ||
| 475 | void EmitGlobalAtomicUMax32x2(EmitContext& ctx); | ||
| 476 | void EmitGlobalAtomicInc32x2(EmitContext& ctx); | ||
| 477 | void EmitGlobalAtomicDec32x2(EmitContext& ctx); | ||
| 478 | void EmitGlobalAtomicAnd32x2(EmitContext& ctx); | ||
| 479 | void EmitGlobalAtomicOr32x2(EmitContext& ctx); | ||
| 480 | void EmitGlobalAtomicXor32x2(EmitContext& ctx); | ||
| 481 | void EmitGlobalAtomicExchange32x2(EmitContext& ctx); | ||
| 451 | void EmitGlobalAtomicAddF32(EmitContext& ctx); | 482 | void EmitGlobalAtomicAddF32(EmitContext& ctx); |
| 452 | void EmitGlobalAtomicAddF16x2(EmitContext& ctx); | 483 | void EmitGlobalAtomicAddF16x2(EmitContext& ctx); |
| 453 | void EmitGlobalAtomicAddF32x2(EmitContext& ctx); | 484 | void EmitGlobalAtomicAddF32x2(EmitContext& ctx); |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_memory.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_memory.cpp index f135b67f5..f0fd94a28 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_memory.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_memory.cpp | |||
| @@ -311,6 +311,13 @@ void EmitSharedAtomicExchange64(EmitContext& ctx, IR::Inst& inst, ScalarU32 poin | |||
| 311 | ctx.LongAdd("ATOMS.EXCH.U64 {}.x,{},shared_mem[{}];", inst, value, pointer_offset); | 311 | ctx.LongAdd("ATOMS.EXCH.U64 {}.x,{},shared_mem[{}];", inst, value, pointer_offset); |
| 312 | } | 312 | } |
| 313 | 313 | ||
| 314 | void EmitSharedAtomicExchange32x2([[maybe_unused]] EmitContext& ctx, | ||
| 315 | [[maybe_unused]] IR::Inst& inst, | ||
| 316 | [[maybe_unused]] ScalarU32 pointer_offset, | ||
| 317 | [[maybe_unused]] Register value) { | ||
| 318 | throw NotImplementedException("GLASM instruction"); | ||
| 319 | } | ||
| 320 | |||
| 314 | void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 321 | void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 315 | ScalarU32 offset, ScalarU32 value) { | 322 | ScalarU32 offset, ScalarU32 value) { |
| 316 | Atom(ctx, inst, binding, offset, value, "ADD", "U32"); | 323 | Atom(ctx, inst, binding, offset, value, "ADD", "U32"); |
| @@ -411,6 +418,62 @@ void EmitStorageAtomicExchange64(EmitContext& ctx, IR::Inst& inst, const IR::Val | |||
| 411 | Atom(ctx, inst, binding, offset, value, "EXCH", "U64"); | 418 | Atom(ctx, inst, binding, offset, value, "EXCH", "U64"); |
| 412 | } | 419 | } |
| 413 | 420 | ||
| 421 | void EmitStorageAtomicIAdd32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | ||
| 422 | [[maybe_unused]] const IR::Value& binding, | ||
| 423 | [[maybe_unused]] ScalarU32 offset, [[maybe_unused]] Register value) { | ||
| 424 | throw NotImplementedException("GLASM instruction"); | ||
| 425 | } | ||
| 426 | |||
| 427 | void EmitStorageAtomicSMin32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | ||
| 428 | [[maybe_unused]] const IR::Value& binding, | ||
| 429 | [[maybe_unused]] ScalarU32 offset, [[maybe_unused]] Register value) { | ||
| 430 | throw NotImplementedException("GLASM instruction"); | ||
| 431 | } | ||
| 432 | |||
| 433 | void EmitStorageAtomicUMin32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | ||
| 434 | [[maybe_unused]] const IR::Value& binding, | ||
| 435 | [[maybe_unused]] ScalarU32 offset, [[maybe_unused]] Register value) { | ||
| 436 | throw NotImplementedException("GLASM instruction"); | ||
| 437 | } | ||
| 438 | |||
| 439 | void EmitStorageAtomicSMax32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | ||
| 440 | [[maybe_unused]] const IR::Value& binding, | ||
| 441 | [[maybe_unused]] ScalarU32 offset, [[maybe_unused]] Register value) { | ||
| 442 | throw NotImplementedException("GLASM instruction"); | ||
| 443 | } | ||
| 444 | |||
| 445 | void EmitStorageAtomicUMax32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | ||
| 446 | [[maybe_unused]] const IR::Value& binding, | ||
| 447 | [[maybe_unused]] ScalarU32 offset, [[maybe_unused]] Register value) { | ||
| 448 | throw NotImplementedException("GLASM instruction"); | ||
| 449 | } | ||
| 450 | |||
| 451 | void EmitStorageAtomicAnd32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | ||
| 452 | [[maybe_unused]] const IR::Value& binding, | ||
| 453 | [[maybe_unused]] ScalarU32 offset, [[maybe_unused]] Register value) { | ||
| 454 | throw NotImplementedException("GLASM instruction"); | ||
| 455 | } | ||
| 456 | |||
| 457 | void EmitStorageAtomicOr32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | ||
| 458 | [[maybe_unused]] const IR::Value& binding, | ||
| 459 | [[maybe_unused]] ScalarU32 offset, [[maybe_unused]] Register value) { | ||
| 460 | throw NotImplementedException("GLASM instruction"); | ||
| 461 | } | ||
| 462 | |||
| 463 | void EmitStorageAtomicXor32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | ||
| 464 | [[maybe_unused]] const IR::Value& binding, | ||
| 465 | [[maybe_unused]] ScalarU32 offset, [[maybe_unused]] Register value) { | ||
| 466 | throw NotImplementedException("GLASM instruction"); | ||
| 467 | } | ||
| 468 | |||
| 469 | void EmitStorageAtomicExchange32x2([[maybe_unused]] EmitContext& ctx, | ||
| 470 | [[maybe_unused]] IR::Inst& inst, | ||
| 471 | [[maybe_unused]] const IR::Value& binding, | ||
| 472 | [[maybe_unused]] ScalarU32 offset, | ||
| 473 | [[maybe_unused]] Register value) { | ||
| 474 | throw NotImplementedException("GLASM instruction"); | ||
| 475 | } | ||
| 476 | |||
| 414 | void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 477 | void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 415 | ScalarU32 offset, ScalarF32 value) { | 478 | ScalarU32 offset, ScalarF32 value) { |
| 416 | Atom(ctx, inst, binding, offset, value, "ADD", "F32"); | 479 | Atom(ctx, inst, binding, offset, value, "ADD", "F32"); |
| @@ -537,6 +600,50 @@ void EmitGlobalAtomicExchange64(EmitContext&) { | |||
| 537 | throw NotImplementedException("GLASM instruction"); | 600 | throw NotImplementedException("GLASM instruction"); |
| 538 | } | 601 | } |
| 539 | 602 | ||
| 603 | void EmitGlobalAtomicIAdd32x2(EmitContext&) { | ||
| 604 | throw NotImplementedException("GLASM instruction"); | ||
| 605 | } | ||
| 606 | |||
| 607 | void EmitGlobalAtomicSMin32x2(EmitContext&) { | ||
| 608 | throw NotImplementedException("GLASM instruction"); | ||
| 609 | } | ||
| 610 | |||
| 611 | void EmitGlobalAtomicUMin32x2(EmitContext&) { | ||
| 612 | throw NotImplementedException("GLASM instruction"); | ||
| 613 | } | ||
| 614 | |||
| 615 | void EmitGlobalAtomicSMax32x2(EmitContext&) { | ||
| 616 | throw NotImplementedException("GLASM instruction"); | ||
| 617 | } | ||
| 618 | |||
| 619 | void EmitGlobalAtomicUMax32x2(EmitContext&) { | ||
| 620 | throw NotImplementedException("GLASM instruction"); | ||
| 621 | } | ||
| 622 | |||
| 623 | void EmitGlobalAtomicInc32x2(EmitContext&) { | ||
| 624 | throw NotImplementedException("GLASM instruction"); | ||
| 625 | } | ||
| 626 | |||
| 627 | void EmitGlobalAtomicDec32x2(EmitContext&) { | ||
| 628 | throw NotImplementedException("GLASM instruction"); | ||
| 629 | } | ||
| 630 | |||
| 631 | void EmitGlobalAtomicAnd32x2(EmitContext&) { | ||
| 632 | throw NotImplementedException("GLASM instruction"); | ||
| 633 | } | ||
| 634 | |||
| 635 | void EmitGlobalAtomicOr32x2(EmitContext&) { | ||
| 636 | throw NotImplementedException("GLASM instruction"); | ||
| 637 | } | ||
| 638 | |||
| 639 | void EmitGlobalAtomicXor32x2(EmitContext&) { | ||
| 640 | throw NotImplementedException("GLASM instruction"); | ||
| 641 | } | ||
| 642 | |||
| 643 | void EmitGlobalAtomicExchange32x2(EmitContext&) { | ||
| 644 | throw NotImplementedException("GLASM instruction"); | ||
| 645 | } | ||
| 646 | |||
| 540 | void EmitGlobalAtomicAddF32(EmitContext&) { | 647 | void EmitGlobalAtomicAddF32(EmitContext&) { |
| 541 | throw NotImplementedException("GLASM instruction"); | 648 | throw NotImplementedException("GLASM instruction"); |
| 542 | } | 649 | } |
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); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv.h b/src/shader_recompiler/backend/spirv/emit_spirv.h index b412957c7..2b360e073 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv.h | |||
| @@ -22,7 +22,7 @@ constexpr u32 NUM_TEXTURE_AND_IMAGE_SCALING_WORDS = | |||
| 22 | struct RescalingLayout { | 22 | struct RescalingLayout { |
| 23 | alignas(16) std::array<u32, NUM_TEXTURE_SCALING_WORDS> rescaling_textures; | 23 | alignas(16) std::array<u32, NUM_TEXTURE_SCALING_WORDS> rescaling_textures; |
| 24 | alignas(16) std::array<u32, NUM_IMAGE_SCALING_WORDS> rescaling_images; | 24 | alignas(16) std::array<u32, NUM_IMAGE_SCALING_WORDS> rescaling_images; |
| 25 | alignas(16) u32 down_factor; | 25 | u32 down_factor; |
| 26 | }; | 26 | }; |
| 27 | constexpr u32 RESCALING_LAYOUT_WORDS_OFFSET = offsetof(RescalingLayout, rescaling_textures); | 27 | constexpr u32 RESCALING_LAYOUT_WORDS_OFFSET = offsetof(RescalingLayout, rescaling_textures); |
| 28 | constexpr u32 RESCALING_LAYOUT_DOWN_FACTOR_OFFSET = offsetof(RescalingLayout, down_factor); | 28 | constexpr u32 RESCALING_LAYOUT_DOWN_FACTOR_OFFSET = offsetof(RescalingLayout, down_factor); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_atomic.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_atomic.cpp index 46ba52a25..d3cbb14a9 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_atomic.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_atomic.cpp | |||
| @@ -82,6 +82,17 @@ Id StorageAtomicU64(EmitContext& ctx, const IR::Value& binding, const IR::Value& | |||
| 82 | ctx.OpStore(pointer, ctx.OpBitcast(ctx.U32[2], result)); | 82 | ctx.OpStore(pointer, ctx.OpBitcast(ctx.U32[2], result)); |
| 83 | return original_value; | 83 | return original_value; |
| 84 | } | 84 | } |
| 85 | |||
| 86 | Id StorageAtomicU32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, Id value, | ||
| 87 | Id (Sirit::Module::*non_atomic_func)(Id, Id, Id)) { | ||
| 88 | LOG_WARNING(Shader_SPIRV, "Int64 atomics not supported, fallback to non-atomic"); | ||
| 89 | const Id pointer{StoragePointer(ctx, ctx.storage_types.U32x2, &StorageDefinitions::U32x2, | ||
| 90 | binding, offset, sizeof(u32[2]))}; | ||
| 91 | const Id original_value{ctx.OpLoad(ctx.U32[2], pointer)}; | ||
| 92 | const Id result{(ctx.*non_atomic_func)(ctx.U32[2], value, original_value)}; | ||
| 93 | ctx.OpStore(pointer, result); | ||
| 94 | return original_value; | ||
| 95 | } | ||
| 85 | } // Anonymous namespace | 96 | } // Anonymous namespace |
| 86 | 97 | ||
| 87 | Id EmitSharedAtomicIAdd32(EmitContext& ctx, Id offset, Id value) { | 98 | Id EmitSharedAtomicIAdd32(EmitContext& ctx, Id offset, Id value) { |
| @@ -141,7 +152,7 @@ Id EmitSharedAtomicExchange64(EmitContext& ctx, Id offset, Id value) { | |||
| 141 | const auto [scope, semantics]{AtomicArgs(ctx)}; | 152 | const auto [scope, semantics]{AtomicArgs(ctx)}; |
| 142 | return ctx.OpAtomicExchange(ctx.U64, pointer, scope, semantics, value); | 153 | return ctx.OpAtomicExchange(ctx.U64, pointer, scope, semantics, value); |
| 143 | } | 154 | } |
| 144 | LOG_ERROR(Shader_SPIRV, "Int64 atomics not supported, fallback to non-atomic"); | 155 | LOG_WARNING(Shader_SPIRV, "Int64 atomics not supported, fallback to non-atomic"); |
| 145 | const Id pointer_1{SharedPointer(ctx, offset, 0)}; | 156 | const Id pointer_1{SharedPointer(ctx, offset, 0)}; |
| 146 | const Id pointer_2{SharedPointer(ctx, offset, 1)}; | 157 | const Id pointer_2{SharedPointer(ctx, offset, 1)}; |
| 147 | const Id value_1{ctx.OpLoad(ctx.U32[1], pointer_1)}; | 158 | const Id value_1{ctx.OpLoad(ctx.U32[1], pointer_1)}; |
| @@ -152,6 +163,18 @@ Id EmitSharedAtomicExchange64(EmitContext& ctx, Id offset, Id value) { | |||
| 152 | return ctx.OpBitcast(ctx.U64, ctx.OpCompositeConstruct(ctx.U32[2], value_1, value_2)); | 163 | return ctx.OpBitcast(ctx.U64, ctx.OpCompositeConstruct(ctx.U32[2], value_1, value_2)); |
| 153 | } | 164 | } |
| 154 | 165 | ||
| 166 | Id EmitSharedAtomicExchange32x2(EmitContext& ctx, Id offset, Id value) { | ||
| 167 | LOG_WARNING(Shader_SPIRV, "Int64 atomics not supported, fallback to non-atomic"); | ||
| 168 | const Id pointer_1{SharedPointer(ctx, offset, 0)}; | ||
| 169 | const Id pointer_2{SharedPointer(ctx, offset, 1)}; | ||
| 170 | const Id value_1{ctx.OpLoad(ctx.U32[1], pointer_1)}; | ||
| 171 | const Id value_2{ctx.OpLoad(ctx.U32[1], pointer_2)}; | ||
| 172 | const Id new_vector{ctx.OpBitcast(ctx.U32[2], value)}; | ||
| 173 | ctx.OpStore(pointer_1, ctx.OpCompositeExtract(ctx.U32[1], new_vector, 0U)); | ||
| 174 | ctx.OpStore(pointer_2, ctx.OpCompositeExtract(ctx.U32[1], new_vector, 1U)); | ||
| 175 | return ctx.OpCompositeConstruct(ctx.U32[2], value_1, value_2); | ||
| 176 | } | ||
| 177 | |||
| 155 | Id EmitStorageAtomicIAdd32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | 178 | Id EmitStorageAtomicIAdd32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, |
| 156 | Id value) { | 179 | Id value) { |
| 157 | return StorageAtomicU32(ctx, binding, offset, value, &Sirit::Module::OpAtomicIAdd); | 180 | return StorageAtomicU32(ctx, binding, offset, value, &Sirit::Module::OpAtomicIAdd); |
| @@ -275,6 +298,56 @@ Id EmitStorageAtomicExchange64(EmitContext& ctx, const IR::Value& binding, const | |||
| 275 | return original; | 298 | return original; |
| 276 | } | 299 | } |
| 277 | 300 | ||
| 301 | Id EmitStorageAtomicIAdd32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 302 | Id value) { | ||
| 303 | return StorageAtomicU32x2(ctx, binding, offset, value, &Sirit::Module::OpIAdd); | ||
| 304 | } | ||
| 305 | |||
| 306 | Id EmitStorageAtomicSMin32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 307 | Id value) { | ||
| 308 | return StorageAtomicU32x2(ctx, binding, offset, value, &Sirit::Module::OpSMin); | ||
| 309 | } | ||
| 310 | |||
| 311 | Id EmitStorageAtomicUMin32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 312 | Id value) { | ||
| 313 | return StorageAtomicU32x2(ctx, binding, offset, value, &Sirit::Module::OpUMin); | ||
| 314 | } | ||
| 315 | |||
| 316 | Id EmitStorageAtomicSMax32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 317 | Id value) { | ||
| 318 | return StorageAtomicU32x2(ctx, binding, offset, value, &Sirit::Module::OpSMax); | ||
| 319 | } | ||
| 320 | |||
| 321 | Id EmitStorageAtomicUMax32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 322 | Id value) { | ||
| 323 | return StorageAtomicU32x2(ctx, binding, offset, value, &Sirit::Module::OpUMax); | ||
| 324 | } | ||
| 325 | |||
| 326 | Id EmitStorageAtomicAnd32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 327 | Id value) { | ||
| 328 | return StorageAtomicU32x2(ctx, binding, offset, value, &Sirit::Module::OpBitwiseAnd); | ||
| 329 | } | ||
| 330 | |||
| 331 | Id EmitStorageAtomicOr32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 332 | Id value) { | ||
| 333 | return StorageAtomicU32x2(ctx, binding, offset, value, &Sirit::Module::OpBitwiseOr); | ||
| 334 | } | ||
| 335 | |||
| 336 | Id EmitStorageAtomicXor32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 337 | Id value) { | ||
| 338 | return StorageAtomicU32x2(ctx, binding, offset, value, &Sirit::Module::OpBitwiseXor); | ||
| 339 | } | ||
| 340 | |||
| 341 | Id EmitStorageAtomicExchange32x2(EmitContext& ctx, const IR::Value& binding, | ||
| 342 | const IR::Value& offset, Id value) { | ||
| 343 | LOG_WARNING(Shader_SPIRV, "Int64 atomics not supported, fallback to non-atomic"); | ||
| 344 | const Id pointer{StoragePointer(ctx, ctx.storage_types.U32x2, &StorageDefinitions::U32x2, | ||
| 345 | binding, offset, sizeof(u32[2]))}; | ||
| 346 | const Id original{ctx.OpLoad(ctx.U32[2], pointer)}; | ||
| 347 | ctx.OpStore(pointer, value); | ||
| 348 | return original; | ||
| 349 | } | ||
| 350 | |||
| 278 | Id EmitStorageAtomicAddF32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | 351 | Id EmitStorageAtomicAddF32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, |
| 279 | Id value) { | 352 | Id value) { |
| 280 | const Id ssbo{ctx.ssbos[binding.U32()].U32}; | 353 | const Id ssbo{ctx.ssbos[binding.U32()].U32}; |
| @@ -418,6 +491,50 @@ Id EmitGlobalAtomicExchange64(EmitContext&) { | |||
| 418 | throw NotImplementedException("SPIR-V Instruction"); | 491 | throw NotImplementedException("SPIR-V Instruction"); |
| 419 | } | 492 | } |
| 420 | 493 | ||
| 494 | Id EmitGlobalAtomicIAdd32x2(EmitContext&) { | ||
| 495 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 496 | } | ||
| 497 | |||
| 498 | Id EmitGlobalAtomicSMin32x2(EmitContext&) { | ||
| 499 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 500 | } | ||
| 501 | |||
| 502 | Id EmitGlobalAtomicUMin32x2(EmitContext&) { | ||
| 503 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 504 | } | ||
| 505 | |||
| 506 | Id EmitGlobalAtomicSMax32x2(EmitContext&) { | ||
| 507 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 508 | } | ||
| 509 | |||
| 510 | Id EmitGlobalAtomicUMax32x2(EmitContext&) { | ||
| 511 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 512 | } | ||
| 513 | |||
| 514 | Id EmitGlobalAtomicInc32x2(EmitContext&) { | ||
| 515 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 516 | } | ||
| 517 | |||
| 518 | Id EmitGlobalAtomicDec32x2(EmitContext&) { | ||
| 519 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 520 | } | ||
| 521 | |||
| 522 | Id EmitGlobalAtomicAnd32x2(EmitContext&) { | ||
| 523 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 524 | } | ||
| 525 | |||
| 526 | Id EmitGlobalAtomicOr32x2(EmitContext&) { | ||
| 527 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 528 | } | ||
| 529 | |||
| 530 | Id EmitGlobalAtomicXor32x2(EmitContext&) { | ||
| 531 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 532 | } | ||
| 533 | |||
| 534 | Id EmitGlobalAtomicExchange32x2(EmitContext&) { | ||
| 535 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 536 | } | ||
| 537 | |||
| 421 | Id EmitGlobalAtomicAddF32(EmitContext&) { | 538 | Id EmitGlobalAtomicAddF32(EmitContext&) { |
| 422 | throw NotImplementedException("SPIR-V Instruction"); | 539 | throw NotImplementedException("SPIR-V Instruction"); |
| 423 | } | 540 | } |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp index 8ea730c80..80b4bbd27 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp | |||
| @@ -123,34 +123,36 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) { | |||
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | Id GetCbuf(EmitContext& ctx, Id result_type, Id UniformDefinitions::*member_ptr, u32 element_size, | 125 | Id GetCbuf(EmitContext& ctx, Id result_type, Id UniformDefinitions::*member_ptr, u32 element_size, |
| 126 | const IR::Value& binding, const IR::Value& offset) { | 126 | const IR::Value& binding, const IR::Value& offset, const Id indirect_func) { |
| 127 | Id buffer_offset; | ||
| 128 | const Id uniform_type{ctx.uniform_types.*member_ptr}; | ||
| 129 | if (offset.IsImmediate()) { | ||
| 130 | // Hardware been proved to read the aligned offset (e.g. LDC.U32 at 6 will read offset 4) | ||
| 131 | const Id imm_offset{ctx.Const(offset.U32() / element_size)}; | ||
| 132 | buffer_offset = imm_offset; | ||
| 133 | } else if (element_size > 1) { | ||
| 134 | const u32 log2_element_size{static_cast<u32>(std::countr_zero(element_size))}; | ||
| 135 | const Id shift{ctx.Const(log2_element_size)}; | ||
| 136 | buffer_offset = ctx.OpShiftRightArithmetic(ctx.U32[1], ctx.Def(offset), shift); | ||
| 137 | } else { | ||
| 138 | buffer_offset = ctx.Def(offset); | ||
| 139 | } | ||
| 127 | if (!binding.IsImmediate()) { | 140 | if (!binding.IsImmediate()) { |
| 128 | throw NotImplementedException("Constant buffer indexing"); | 141 | return ctx.OpFunctionCall(result_type, indirect_func, ctx.Def(binding), buffer_offset); |
| 129 | } | 142 | } |
| 130 | const Id cbuf{ctx.cbufs[binding.U32()].*member_ptr}; | 143 | const Id cbuf{ctx.cbufs[binding.U32()].*member_ptr}; |
| 131 | const Id uniform_type{ctx.uniform_types.*member_ptr}; | 144 | const Id access_chain{ctx.OpAccessChain(uniform_type, cbuf, ctx.u32_zero_value, buffer_offset)}; |
| 132 | if (!offset.IsImmediate()) { | ||
| 133 | Id index{ctx.Def(offset)}; | ||
| 134 | if (element_size > 1) { | ||
| 135 | const u32 log2_element_size{static_cast<u32>(std::countr_zero(element_size))}; | ||
| 136 | const Id shift{ctx.Const(log2_element_size)}; | ||
| 137 | index = ctx.OpShiftRightArithmetic(ctx.U32[1], ctx.Def(offset), shift); | ||
| 138 | } | ||
| 139 | const Id access_chain{ctx.OpAccessChain(uniform_type, cbuf, ctx.u32_zero_value, index)}; | ||
| 140 | return ctx.OpLoad(result_type, access_chain); | ||
| 141 | } | ||
| 142 | // Hardware been proved to read the aligned offset (e.g. LDC.U32 at 6 will read offset 4) | ||
| 143 | const Id imm_offset{ctx.Const(offset.U32() / element_size)}; | ||
| 144 | const Id access_chain{ctx.OpAccessChain(uniform_type, cbuf, ctx.u32_zero_value, imm_offset)}; | ||
| 145 | return ctx.OpLoad(result_type, access_chain); | 145 | return ctx.OpLoad(result_type, access_chain); |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | Id GetCbufU32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 148 | Id GetCbufU32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 149 | return GetCbuf(ctx, ctx.U32[1], &UniformDefinitions::U32, sizeof(u32), binding, offset); | 149 | return GetCbuf(ctx, ctx.U32[1], &UniformDefinitions::U32, sizeof(u32), binding, offset, |
| 150 | ctx.load_const_func_u32); | ||
| 150 | } | 151 | } |
| 151 | 152 | ||
| 152 | Id GetCbufU32x4(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 153 | Id GetCbufU32x4(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 153 | return GetCbuf(ctx, ctx.U32[4], &UniformDefinitions::U32x4, sizeof(u32[4]), binding, offset); | 154 | return GetCbuf(ctx, ctx.U32[4], &UniformDefinitions::U32x4, sizeof(u32[4]), binding, offset, |
| 155 | ctx.load_const_func_u32x4); | ||
| 154 | } | 156 | } |
| 155 | 157 | ||
| 156 | Id GetCbufElement(EmitContext& ctx, Id vector, const IR::Value& offset, u32 index_offset) { | 158 | Id GetCbufElement(EmitContext& ctx, Id vector, const IR::Value& offset, u32 index_offset) { |
| @@ -201,7 +203,8 @@ void EmitGetIndirectBranchVariable(EmitContext&) { | |||
| 201 | 203 | ||
| 202 | Id EmitGetCbufU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 204 | Id EmitGetCbufU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 203 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int8) { | 205 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int8) { |
| 204 | const Id load{GetCbuf(ctx, ctx.U8, &UniformDefinitions::U8, sizeof(u8), binding, offset)}; | 206 | const Id load{GetCbuf(ctx, ctx.U8, &UniformDefinitions::U8, sizeof(u8), binding, offset, |
| 207 | ctx.load_const_func_u8)}; | ||
| 205 | return ctx.OpUConvert(ctx.U32[1], load); | 208 | return ctx.OpUConvert(ctx.U32[1], load); |
| 206 | } | 209 | } |
| 207 | Id element{}; | 210 | Id element{}; |
| @@ -217,7 +220,8 @@ Id EmitGetCbufU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& of | |||
| 217 | 220 | ||
| 218 | Id EmitGetCbufS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 221 | Id EmitGetCbufS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 219 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int8) { | 222 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int8) { |
| 220 | const Id load{GetCbuf(ctx, ctx.S8, &UniformDefinitions::S8, sizeof(s8), binding, offset)}; | 223 | const Id load{GetCbuf(ctx, ctx.S8, &UniformDefinitions::S8, sizeof(s8), binding, offset, |
| 224 | ctx.load_const_func_u8)}; | ||
| 221 | return ctx.OpSConvert(ctx.U32[1], load); | 225 | return ctx.OpSConvert(ctx.U32[1], load); |
| 222 | } | 226 | } |
| 223 | Id element{}; | 227 | Id element{}; |
| @@ -233,8 +237,8 @@ Id EmitGetCbufS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& of | |||
| 233 | 237 | ||
| 234 | Id EmitGetCbufU16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 238 | Id EmitGetCbufU16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 235 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int16) { | 239 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int16) { |
| 236 | const Id load{ | 240 | const Id load{GetCbuf(ctx, ctx.U16, &UniformDefinitions::U16, sizeof(u16), binding, offset, |
| 237 | GetCbuf(ctx, ctx.U16, &UniformDefinitions::U16, sizeof(u16), binding, offset)}; | 241 | ctx.load_const_func_u16)}; |
| 238 | return ctx.OpUConvert(ctx.U32[1], load); | 242 | return ctx.OpUConvert(ctx.U32[1], load); |
| 239 | } | 243 | } |
| 240 | Id element{}; | 244 | Id element{}; |
| @@ -250,8 +254,8 @@ Id EmitGetCbufU16(EmitContext& ctx, const IR::Value& binding, const IR::Value& o | |||
| 250 | 254 | ||
| 251 | Id EmitGetCbufS16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 255 | Id EmitGetCbufS16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 252 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int16) { | 256 | if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int16) { |
| 253 | const Id load{ | 257 | const Id load{GetCbuf(ctx, ctx.S16, &UniformDefinitions::S16, sizeof(s16), binding, offset, |
| 254 | GetCbuf(ctx, ctx.S16, &UniformDefinitions::S16, sizeof(s16), binding, offset)}; | 258 | ctx.load_const_func_u16)}; |
| 255 | return ctx.OpSConvert(ctx.U32[1], load); | 259 | return ctx.OpSConvert(ctx.U32[1], load); |
| 256 | } | 260 | } |
| 257 | Id element{}; | 261 | Id element{}; |
| @@ -276,7 +280,8 @@ Id EmitGetCbufU32(EmitContext& ctx, const IR::Value& binding, const IR::Value& o | |||
| 276 | 280 | ||
| 277 | Id EmitGetCbufF32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 281 | Id EmitGetCbufF32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 278 | if (ctx.profile.support_descriptor_aliasing) { | 282 | if (ctx.profile.support_descriptor_aliasing) { |
| 279 | return GetCbuf(ctx, ctx.F32[1], &UniformDefinitions::F32, sizeof(f32), binding, offset); | 283 | return GetCbuf(ctx, ctx.F32[1], &UniformDefinitions::F32, sizeof(f32), binding, offset, |
| 284 | ctx.load_const_func_f32); | ||
| 280 | } else { | 285 | } else { |
| 281 | const Id vector{GetCbufU32x4(ctx, binding, offset)}; | 286 | const Id vector{GetCbufU32x4(ctx, binding, offset)}; |
| 282 | return ctx.OpBitcast(ctx.F32[1], GetCbufElement(ctx, vector, offset, 0u)); | 287 | return ctx.OpBitcast(ctx.F32[1], GetCbufElement(ctx, vector, offset, 0u)); |
| @@ -285,8 +290,8 @@ Id EmitGetCbufF32(EmitContext& ctx, const IR::Value& binding, const IR::Value& o | |||
| 285 | 290 | ||
| 286 | Id EmitGetCbufU32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 291 | Id EmitGetCbufU32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 287 | if (ctx.profile.support_descriptor_aliasing) { | 292 | if (ctx.profile.support_descriptor_aliasing) { |
| 288 | return GetCbuf(ctx, ctx.U32[2], &UniformDefinitions::U32x2, sizeof(u32[2]), binding, | 293 | return GetCbuf(ctx, ctx.U32[2], &UniformDefinitions::U32x2, sizeof(u32[2]), binding, offset, |
| 289 | offset); | 294 | ctx.load_const_func_u32x2); |
| 290 | } else { | 295 | } else { |
| 291 | const Id vector{GetCbufU32x4(ctx, binding, offset)}; | 296 | const Id vector{GetCbufU32x4(ctx, binding, offset)}; |
| 292 | return ctx.OpCompositeConstruct(ctx.U32[2], GetCbufElement(ctx, vector, offset, 0u), | 297 | return ctx.OpCompositeConstruct(ctx.U32[2], GetCbufElement(ctx, vector, offset, 0u), |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h index 887112deb..f263b41b0 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h | |||
| @@ -335,6 +335,7 @@ Id EmitSharedAtomicOr32(EmitContext& ctx, Id pointer_offset, Id value); | |||
| 335 | Id EmitSharedAtomicXor32(EmitContext& ctx, Id pointer_offset, Id value); | 335 | Id EmitSharedAtomicXor32(EmitContext& ctx, Id pointer_offset, Id value); |
| 336 | Id EmitSharedAtomicExchange32(EmitContext& ctx, Id pointer_offset, Id value); | 336 | Id EmitSharedAtomicExchange32(EmitContext& ctx, Id pointer_offset, Id value); |
| 337 | Id EmitSharedAtomicExchange64(EmitContext& ctx, Id pointer_offset, Id value); | 337 | Id EmitSharedAtomicExchange64(EmitContext& ctx, Id pointer_offset, Id value); |
| 338 | Id EmitSharedAtomicExchange32x2(EmitContext& ctx, Id pointer_offset, Id value); | ||
| 338 | Id EmitStorageAtomicIAdd32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | 339 | Id EmitStorageAtomicIAdd32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, |
| 339 | Id value); | 340 | Id value); |
| 340 | Id EmitStorageAtomicSMin32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | 341 | Id EmitStorageAtomicSMin32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, |
| @@ -375,6 +376,24 @@ Id EmitStorageAtomicXor64(EmitContext& ctx, const IR::Value& binding, const IR:: | |||
| 375 | Id value); | 376 | Id value); |
| 376 | Id EmitStorageAtomicExchange64(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | 377 | Id EmitStorageAtomicExchange64(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, |
| 377 | Id value); | 378 | Id value); |
| 379 | Id EmitStorageAtomicIAdd32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 380 | Id value); | ||
| 381 | Id EmitStorageAtomicSMin32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 382 | Id value); | ||
| 383 | Id EmitStorageAtomicUMin32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 384 | Id value); | ||
| 385 | Id EmitStorageAtomicSMax32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 386 | Id value); | ||
| 387 | Id EmitStorageAtomicUMax32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 388 | Id value); | ||
| 389 | Id EmitStorageAtomicAnd32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 390 | Id value); | ||
| 391 | Id EmitStorageAtomicOr32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 392 | Id value); | ||
| 393 | Id EmitStorageAtomicXor32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | ||
| 394 | Id value); | ||
| 395 | Id EmitStorageAtomicExchange32x2(EmitContext& ctx, const IR::Value& binding, | ||
| 396 | const IR::Value& offset, Id value); | ||
| 378 | Id EmitStorageAtomicAddF32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | 397 | Id EmitStorageAtomicAddF32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, |
| 379 | Id value); | 398 | Id value); |
| 380 | Id EmitStorageAtomicAddF16x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, | 399 | Id EmitStorageAtomicAddF16x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, |
| @@ -411,6 +430,17 @@ Id EmitGlobalAtomicAnd64(EmitContext& ctx); | |||
| 411 | Id EmitGlobalAtomicOr64(EmitContext& ctx); | 430 | Id EmitGlobalAtomicOr64(EmitContext& ctx); |
| 412 | Id EmitGlobalAtomicXor64(EmitContext& ctx); | 431 | Id EmitGlobalAtomicXor64(EmitContext& ctx); |
| 413 | Id EmitGlobalAtomicExchange64(EmitContext& ctx); | 432 | Id EmitGlobalAtomicExchange64(EmitContext& ctx); |
| 433 | Id EmitGlobalAtomicIAdd32x2(EmitContext& ctx); | ||
| 434 | Id EmitGlobalAtomicSMin32x2(EmitContext& ctx); | ||
| 435 | Id EmitGlobalAtomicUMin32x2(EmitContext& ctx); | ||
| 436 | Id EmitGlobalAtomicSMax32x2(EmitContext& ctx); | ||
| 437 | Id EmitGlobalAtomicUMax32x2(EmitContext& ctx); | ||
| 438 | Id EmitGlobalAtomicInc32x2(EmitContext& ctx); | ||
| 439 | Id EmitGlobalAtomicDec32x2(EmitContext& ctx); | ||
| 440 | Id EmitGlobalAtomicAnd32x2(EmitContext& ctx); | ||
| 441 | Id EmitGlobalAtomicOr32x2(EmitContext& ctx); | ||
| 442 | Id EmitGlobalAtomicXor32x2(EmitContext& ctx); | ||
| 443 | Id EmitGlobalAtomicExchange32x2(EmitContext& ctx); | ||
| 414 | Id EmitGlobalAtomicAddF32(EmitContext& ctx); | 444 | Id EmitGlobalAtomicAddF32(EmitContext& ctx); |
| 415 | Id EmitGlobalAtomicAddF16x2(EmitContext& ctx); | 445 | Id EmitGlobalAtomicAddF16x2(EmitContext& ctx); |
| 416 | Id EmitGlobalAtomicAddF32x2(EmitContext& ctx); | 446 | Id EmitGlobalAtomicAddF32x2(EmitContext& ctx); |
diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp index cd90c084a..aa5b6c9b7 100644 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp | |||
| @@ -464,6 +464,7 @@ EmitContext::EmitContext(const Profile& profile_, const RuntimeInfo& runtime_inf | |||
| 464 | DefineSharedMemory(program); | 464 | DefineSharedMemory(program); |
| 465 | DefineSharedMemoryFunctions(program); | 465 | DefineSharedMemoryFunctions(program); |
| 466 | DefineConstantBuffers(program.info, uniform_binding); | 466 | DefineConstantBuffers(program.info, uniform_binding); |
| 467 | DefineConstantBufferIndirectFunctions(program.info); | ||
| 467 | DefineStorageBuffers(program.info, storage_binding); | 468 | DefineStorageBuffers(program.info, storage_binding); |
| 468 | DefineTextureBuffers(program.info, texture_binding); | 469 | DefineTextureBuffers(program.info, texture_binding); |
| 469 | DefineImageBuffers(program.info, image_binding); | 470 | DefineImageBuffers(program.info, image_binding); |
| @@ -993,7 +994,7 @@ void EmitContext::DefineConstantBuffers(const Info& info, u32& binding) { | |||
| 993 | } | 994 | } |
| 994 | return; | 995 | return; |
| 995 | } | 996 | } |
| 996 | IR::Type types{info.used_constant_buffer_types}; | 997 | IR::Type types{info.used_constant_buffer_types | info.used_indirect_cbuf_types}; |
| 997 | if (True(types & IR::Type::U8)) { | 998 | if (True(types & IR::Type::U8)) { |
| 998 | if (profile.support_int8) { | 999 | if (profile.support_int8) { |
| 999 | DefineConstBuffers(*this, info, &UniformDefinitions::U8, binding, U8, 'u', sizeof(u8)); | 1000 | DefineConstBuffers(*this, info, &UniformDefinitions::U8, binding, U8, 'u', sizeof(u8)); |
| @@ -1027,6 +1028,62 @@ void EmitContext::DefineConstantBuffers(const Info& info, u32& binding) { | |||
| 1027 | binding += static_cast<u32>(info.constant_buffer_descriptors.size()); | 1028 | binding += static_cast<u32>(info.constant_buffer_descriptors.size()); |
| 1028 | } | 1029 | } |
| 1029 | 1030 | ||
| 1031 | void EmitContext::DefineConstantBufferIndirectFunctions(const Info& info) { | ||
| 1032 | if (!info.uses_cbuf_indirect) { | ||
| 1033 | return; | ||
| 1034 | } | ||
| 1035 | const auto make_accessor{[&](Id buffer_type, Id UniformDefinitions::*member_ptr) { | ||
| 1036 | const Id func_type{TypeFunction(buffer_type, U32[1], U32[1])}; | ||
| 1037 | const Id func{OpFunction(buffer_type, spv::FunctionControlMask::MaskNone, func_type)}; | ||
| 1038 | const Id binding{OpFunctionParameter(U32[1])}; | ||
| 1039 | const Id offset{OpFunctionParameter(U32[1])}; | ||
| 1040 | |||
| 1041 | AddLabel(); | ||
| 1042 | |||
| 1043 | const Id merge_label{OpLabel()}; | ||
| 1044 | const Id uniform_type{uniform_types.*member_ptr}; | ||
| 1045 | |||
| 1046 | std::array<Id, Info::MAX_CBUFS> buf_labels; | ||
| 1047 | std::array<Sirit::Literal, Info::MAX_CBUFS> buf_literals; | ||
| 1048 | for (u32 i = 0; i < Info::MAX_CBUFS; i++) { | ||
| 1049 | buf_labels[i] = OpLabel(); | ||
| 1050 | buf_literals[i] = Sirit::Literal{i}; | ||
| 1051 | } | ||
| 1052 | OpSelectionMerge(merge_label, spv::SelectionControlMask::MaskNone); | ||
| 1053 | OpSwitch(binding, buf_labels[0], buf_literals, buf_labels); | ||
| 1054 | for (u32 i = 0; i < Info::MAX_CBUFS; i++) { | ||
| 1055 | AddLabel(buf_labels[i]); | ||
| 1056 | const Id cbuf{cbufs[i].*member_ptr}; | ||
| 1057 | const Id access_chain{OpAccessChain(uniform_type, cbuf, u32_zero_value, offset)}; | ||
| 1058 | const Id result{OpLoad(buffer_type, access_chain)}; | ||
| 1059 | OpReturnValue(result); | ||
| 1060 | } | ||
| 1061 | AddLabel(merge_label); | ||
| 1062 | OpUnreachable(); | ||
| 1063 | OpFunctionEnd(); | ||
| 1064 | return func; | ||
| 1065 | }}; | ||
| 1066 | IR::Type types{info.used_indirect_cbuf_types}; | ||
| 1067 | if (True(types & IR::Type::U8)) { | ||
| 1068 | load_const_func_u8 = make_accessor(U8, &UniformDefinitions::U8); | ||
| 1069 | } | ||
| 1070 | if (True(types & IR::Type::U16)) { | ||
| 1071 | load_const_func_u16 = make_accessor(U16, &UniformDefinitions::U16); | ||
| 1072 | } | ||
| 1073 | if (True(types & IR::Type::F32)) { | ||
| 1074 | load_const_func_f32 = make_accessor(F32[1], &UniformDefinitions::F32); | ||
| 1075 | } | ||
| 1076 | if (True(types & IR::Type::U32)) { | ||
| 1077 | load_const_func_u32 = make_accessor(U32[1], &UniformDefinitions::U32); | ||
| 1078 | } | ||
| 1079 | if (True(types & IR::Type::U32x2)) { | ||
| 1080 | load_const_func_u32x2 = make_accessor(U32[2], &UniformDefinitions::U32x2); | ||
| 1081 | } | ||
| 1082 | if (True(types & IR::Type::U32x4)) { | ||
| 1083 | load_const_func_u32x4 = make_accessor(U32[4], &UniformDefinitions::U32x4); | ||
| 1084 | } | ||
| 1085 | } | ||
| 1086 | |||
| 1030 | void EmitContext::DefineStorageBuffers(const Info& info, u32& binding) { | 1087 | void EmitContext::DefineStorageBuffers(const Info& info, u32& binding) { |
| 1031 | if (info.storage_buffers_descriptors.empty()) { | 1088 | if (info.storage_buffers_descriptors.empty()) { |
| 1032 | return; | 1089 | return; |
diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.h b/src/shader_recompiler/backend/spirv/spirv_emit_context.h index f87138f7e..906a1dc2c 100644 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.h +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.h | |||
| @@ -294,6 +294,13 @@ public: | |||
| 294 | 294 | ||
| 295 | std::vector<Id> interfaces; | 295 | std::vector<Id> interfaces; |
| 296 | 296 | ||
| 297 | Id load_const_func_u8{}; | ||
| 298 | Id load_const_func_u16{}; | ||
| 299 | Id load_const_func_u32{}; | ||
| 300 | Id load_const_func_f32{}; | ||
| 301 | Id load_const_func_u32x2{}; | ||
| 302 | Id load_const_func_u32x4{}; | ||
| 303 | |||
| 297 | private: | 304 | private: |
| 298 | void DefineCommonTypes(const Info& info); | 305 | void DefineCommonTypes(const Info& info); |
| 299 | void DefineCommonConstants(); | 306 | void DefineCommonConstants(); |
| @@ -302,6 +309,7 @@ private: | |||
| 302 | void DefineSharedMemory(const IR::Program& program); | 309 | void DefineSharedMemory(const IR::Program& program); |
| 303 | void DefineSharedMemoryFunctions(const IR::Program& program); | 310 | void DefineSharedMemoryFunctions(const IR::Program& program); |
| 304 | void DefineConstantBuffers(const Info& info, u32& binding); | 311 | void DefineConstantBuffers(const Info& info, u32& binding); |
| 312 | void DefineConstantBufferIndirectFunctions(const Info& info); | ||
| 305 | void DefineStorageBuffers(const Info& info, u32& binding); | 313 | void DefineStorageBuffers(const Info& info, u32& binding); |
| 306 | void DefineTextureBuffers(const Info& info, u32& binding); | 314 | void DefineTextureBuffers(const Info& info, u32& binding); |
| 307 | void DefineImageBuffers(const Info& info, u32& binding); | 315 | void DefineImageBuffers(const Info& info, u32& binding); |