diff options
| author | 2021-03-26 16:46:07 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:24 -0400 | |
| commit | d9c5bd9509e82fcde72c18663989931f97ed6518 (patch) | |
| tree | d6575e66d66a8abc8ee8776c1c2536c052424787 /src/shader_recompiler/backend/spirv/emit_spirv_image.cpp | |
| parent | shader: Add IR opcode for ImageFetch (diff) | |
| download | yuzu-d9c5bd9509e82fcde72c18663989931f97ed6518.tar.gz yuzu-d9c5bd9509e82fcde72c18663989931f97ed6518.tar.xz yuzu-d9c5bd9509e82fcde72c18663989931f97ed6518.zip | |
shader: Refactor PTP and other minor changes
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_spirv_image.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/emit_spirv_image.cpp | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp index 13bc8831f..b6e9d3c0c 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp | |||
| @@ -30,16 +30,34 @@ public: | |||
| 30 | } | 30 | } |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | explicit ImageOperands([[maybe_unused]] EmitContext& ctx, Id offset, Id offset2) { | 33 | explicit ImageOperands(EmitContext& ctx, const IR::Value& offset, const IR::Value& offset2) { |
| 34 | if (Sirit::ValidId(offset)) { | 34 | if (offset2.IsEmpty()) { |
| 35 | Add(spv::ImageOperandsMask::Offset, offset); | 35 | if (offset.IsEmpty()) { |
| 36 | return; | ||
| 37 | } | ||
| 38 | Add(spv::ImageOperandsMask::Offset, ctx.Def(offset)); | ||
| 39 | return; | ||
| 40 | } | ||
| 41 | const std::array values{offset.InstRecursive(), offset2.InstRecursive()}; | ||
| 42 | if (!values[0]->AreAllArgsImmediates() || !values[1]->AreAllArgsImmediates()) { | ||
| 43 | throw NotImplementedException("Not all arguments in PTP are immediate"); | ||
| 36 | } | 44 | } |
| 37 | if (Sirit::ValidId(offset2)) { | 45 | const IR::Opcode opcode{values[0]->Opcode()}; |
| 38 | Add(spv::ImageOperandsMask::ConstOffsets, offset2); | 46 | if (opcode != values[1]->Opcode() || opcode != IR::Opcode::CompositeConstructU32x4) { |
| 47 | throw LogicError("Invalid PTP arguments"); | ||
| 39 | } | 48 | } |
| 49 | auto read{[&](int a, int b) { return ctx.Constant(ctx.U32[1], values[a]->Arg(b).U32()); }}; | ||
| 50 | |||
| 51 | const Id offsets{ | ||
| 52 | ctx.ConstantComposite(ctx.TypeArray(ctx.U32[2], ctx.Constant(ctx.U32[1], 4)), | ||
| 53 | ctx.ConstantComposite(ctx.U32[2], read(0, 0), read(0, 1)), | ||
| 54 | ctx.ConstantComposite(ctx.U32[2], read(0, 2), read(0, 3)), | ||
| 55 | ctx.ConstantComposite(ctx.U32[2], read(1, 0), read(1, 1)), | ||
| 56 | ctx.ConstantComposite(ctx.U32[2], read(1, 2), read(1, 3)))}; | ||
| 57 | Add(spv::ImageOperandsMask::ConstOffsets, offsets); | ||
| 40 | } | 58 | } |
| 41 | 59 | ||
| 42 | explicit ImageOperands([[maybe_unused]] EmitContext& ctx, Id offset, Id lod, Id ms) { | 60 | explicit ImageOperands(Id offset, Id lod, Id ms) { |
| 43 | if (Sirit::ValidId(lod)) { | 61 | if (Sirit::ValidId(lod)) { |
| 44 | Add(spv::ImageOperandsMask::Lod, lod); | 62 | Add(spv::ImageOperandsMask::Lod, lod); |
| 45 | } | 63 | } |
| @@ -197,8 +215,8 @@ Id EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Va | |||
| 197 | Texture(ctx, index), coords, dref, operands.Mask(), operands.Span()); | 215 | Texture(ctx, index), coords, dref, operands.Mask(), operands.Span()); |
| 198 | } | 216 | } |
| 199 | 217 | ||
| 200 | Id EmitImageGather(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset, | 218 | Id EmitImageGather(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, |
| 201 | Id offset2) { | 219 | const IR::Value& offset, const IR::Value& offset2) { |
| 202 | const auto info{inst->Flags<IR::TextureInstInfo>()}; | 220 | const auto info{inst->Flags<IR::TextureInstInfo>()}; |
| 203 | const ImageOperands operands(ctx, offset, offset2); | 221 | const ImageOperands operands(ctx, offset, offset2); |
| 204 | return Emit(&EmitContext::OpImageSparseGather, &EmitContext::OpImageGather, ctx, inst, | 222 | return Emit(&EmitContext::OpImageSparseGather, &EmitContext::OpImageGather, ctx, inst, |
| @@ -208,7 +226,7 @@ Id EmitImageGather(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id | |||
| 208 | } | 226 | } |
| 209 | 227 | ||
| 210 | Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, | 228 | Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, |
| 211 | Id offset, Id offset2, Id dref) { | 229 | const IR::Value& offset, const IR::Value& offset2, Id dref) { |
| 212 | const auto info{inst->Flags<IR::TextureInstInfo>()}; | 230 | const auto info{inst->Flags<IR::TextureInstInfo>()}; |
| 213 | const ImageOperands operands(ctx, offset, offset2); | 231 | const ImageOperands operands(ctx, offset, offset2); |
| 214 | return Emit(&EmitContext::OpImageSparseDrefGather, &EmitContext::OpImageDrefGather, ctx, inst, | 232 | return Emit(&EmitContext::OpImageSparseDrefGather, &EmitContext::OpImageDrefGather, ctx, inst, |
| @@ -218,7 +236,7 @@ Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, | |||
| 218 | Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset, | 236 | Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset, |
| 219 | Id lod, Id ms) { | 237 | Id lod, Id ms) { |
| 220 | const auto info{inst->Flags<IR::TextureInstInfo>()}; | 238 | const auto info{inst->Flags<IR::TextureInstInfo>()}; |
| 221 | const ImageOperands operands(ctx, offset, lod, ms); | 239 | const ImageOperands operands(offset, lod, ms); |
| 222 | return Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst, ctx.F32[4], | 240 | return Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst, ctx.F32[4], |
| 223 | Texture(ctx, index), coords, operands.Mask(), operands.Span()); | 241 | Texture(ctx, index), coords, operands.Mask(), operands.Span()); |
| 224 | } | 242 | } |