emit_spirv_image_atomic.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Copyright 2021 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "shader_recompiler/backend/spirv/emit_spirv.h"
  5. #include "shader_recompiler/frontend/ir/modifiers.h"
  6. namespace Shader::Backend::SPIRV {
  7. namespace {
  8. Id Image(EmitContext& ctx, const IR::Value& index, IR::TextureInstInfo info) {
  9. if (!index.IsImmediate()) {
  10. throw NotImplementedException("Indirect image indexing");
  11. }
  12. if (info.type == TextureType::Buffer) {
  13. const ImageBufferDefinition def{ctx.image_buffers.at(index.U32())};
  14. return def.id;
  15. } else {
  16. const ImageDefinition def{ctx.images.at(index.U32())};
  17. return def.id;
  18. }
  19. }
  20. std::pair<Id, Id> AtomicArgs(EmitContext& ctx) {
  21. const Id scope{ctx.Const(static_cast<u32>(spv::Scope::Device))};
  22. const Id semantics{ctx.u32_zero_value};
  23. return {scope, semantics};
  24. }
  25. Id ImageAtomicU32(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id value,
  26. Id (Sirit::Module::*atomic_func)(Id, Id, Id, Id, Id)) {
  27. const auto info{inst->Flags<IR::TextureInstInfo>()};
  28. const Id image{Image(ctx, index, info)};
  29. const Id pointer{ctx.OpImageTexelPointer(ctx.image_u32, image, coords, ctx.Const(0U))};
  30. const auto [scope, semantics]{AtomicArgs(ctx)};
  31. return (ctx.*atomic_func)(ctx.U32[1], pointer, scope, semantics, value);
  32. }
  33. } // Anonymous namespace
  34. Id EmitImageAtomicIAdd32(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
  35. Id value) {
  36. return ImageAtomicU32(ctx, inst, index, coords, value, &Sirit::Module::OpAtomicIAdd);
  37. }
  38. Id EmitImageAtomicSMin32(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
  39. Id value) {
  40. return ImageAtomicU32(ctx, inst, index, coords, value, &Sirit::Module::OpAtomicSMin);
  41. }
  42. Id EmitImageAtomicUMin32(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
  43. Id value) {
  44. return ImageAtomicU32(ctx, inst, index, coords, value, &Sirit::Module::OpAtomicUMin);
  45. }
  46. Id EmitImageAtomicSMax32(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
  47. Id value) {
  48. return ImageAtomicU32(ctx, inst, index, coords, value, &Sirit::Module::OpAtomicSMax);
  49. }
  50. Id EmitImageAtomicUMax32(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
  51. Id value) {
  52. return ImageAtomicU32(ctx, inst, index, coords, value, &Sirit::Module::OpAtomicUMax);
  53. }
  54. Id EmitImageAtomicInc32(EmitContext&, IR::Inst*, const IR::Value&, Id, Id) {
  55. // TODO: This is not yet implemented
  56. throw NotImplementedException("SPIR-V Instruction");
  57. }
  58. Id EmitImageAtomicDec32(EmitContext&, IR::Inst*, const IR::Value&, Id, Id) {
  59. // TODO: This is not yet implemented
  60. throw NotImplementedException("SPIR-V Instruction");
  61. }
  62. Id EmitImageAtomicAnd32(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
  63. Id value) {
  64. return ImageAtomicU32(ctx, inst, index, coords, value, &Sirit::Module::OpAtomicAnd);
  65. }
  66. Id EmitImageAtomicOr32(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
  67. Id value) {
  68. return ImageAtomicU32(ctx, inst, index, coords, value, &Sirit::Module::OpAtomicOr);
  69. }
  70. Id EmitImageAtomicXor32(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
  71. Id value) {
  72. return ImageAtomicU32(ctx, inst, index, coords, value, &Sirit::Module::OpAtomicXor);
  73. }
  74. Id EmitImageAtomicExchange32(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
  75. Id value) {
  76. return ImageAtomicU32(ctx, inst, index, coords, value, &Sirit::Module::OpAtomicExchange);
  77. }
  78. Id EmitBindlessImageAtomicIAdd32(EmitContext&) {
  79. throw NotImplementedException("SPIR-V Instruction");
  80. }
  81. Id EmitBindlessImageAtomicSMin32(EmitContext&) {
  82. throw NotImplementedException("SPIR-V Instruction");
  83. }
  84. Id EmitBindlessImageAtomicUMin32(EmitContext&) {
  85. throw NotImplementedException("SPIR-V Instruction");
  86. }
  87. Id EmitBindlessImageAtomicSMax32(EmitContext&) {
  88. throw NotImplementedException("SPIR-V Instruction");
  89. }
  90. Id EmitBindlessImageAtomicUMax32(EmitContext&) {
  91. throw NotImplementedException("SPIR-V Instruction");
  92. }
  93. Id EmitBindlessImageAtomicInc32(EmitContext&) {
  94. throw NotImplementedException("SPIR-V Instruction");
  95. }
  96. Id EmitBindlessImageAtomicDec32(EmitContext&) {
  97. throw NotImplementedException("SPIR-V Instruction");
  98. }
  99. Id EmitBindlessImageAtomicAnd32(EmitContext&) {
  100. throw NotImplementedException("SPIR-V Instruction");
  101. }
  102. Id EmitBindlessImageAtomicOr32(EmitContext&) {
  103. throw NotImplementedException("SPIR-V Instruction");
  104. }
  105. Id EmitBindlessImageAtomicXor32(EmitContext&) {
  106. throw NotImplementedException("SPIR-V Instruction");
  107. }
  108. Id EmitBindlessImageAtomicExchange32(EmitContext&) {
  109. throw NotImplementedException("SPIR-V Instruction");
  110. }
  111. Id EmitBoundImageAtomicIAdd32(EmitContext&) {
  112. throw NotImplementedException("SPIR-V Instruction");
  113. }
  114. Id EmitBoundImageAtomicSMin32(EmitContext&) {
  115. throw NotImplementedException("SPIR-V Instruction");
  116. }
  117. Id EmitBoundImageAtomicUMin32(EmitContext&) {
  118. throw NotImplementedException("SPIR-V Instruction");
  119. }
  120. Id EmitBoundImageAtomicSMax32(EmitContext&) {
  121. throw NotImplementedException("SPIR-V Instruction");
  122. }
  123. Id EmitBoundImageAtomicUMax32(EmitContext&) {
  124. throw NotImplementedException("SPIR-V Instruction");
  125. }
  126. Id EmitBoundImageAtomicInc32(EmitContext&) {
  127. throw NotImplementedException("SPIR-V Instruction");
  128. }
  129. Id EmitBoundImageAtomicDec32(EmitContext&) {
  130. throw NotImplementedException("SPIR-V Instruction");
  131. }
  132. Id EmitBoundImageAtomicAnd32(EmitContext&) {
  133. throw NotImplementedException("SPIR-V Instruction");
  134. }
  135. Id EmitBoundImageAtomicOr32(EmitContext&) {
  136. throw NotImplementedException("SPIR-V Instruction");
  137. }
  138. Id EmitBoundImageAtomicXor32(EmitContext&) {
  139. throw NotImplementedException("SPIR-V Instruction");
  140. }
  141. Id EmitBoundImageAtomicExchange32(EmitContext&) {
  142. throw NotImplementedException("SPIR-V Instruction");
  143. }
  144. } // namespace Shader::Backend::SPIRV