summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_image.cpp47
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_instructions.h4
2 files changed, 44 insertions, 7 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
index 44281e407..945cdb42b 100644
--- a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
+++ b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
@@ -60,11 +60,10 @@ public:
60 Add(spv::ImageOperandsMask::ConstOffsets, offsets); 60 Add(spv::ImageOperandsMask::ConstOffsets, offsets);
61 } 61 }
62 62
63 explicit ImageOperands(EmitContext& ctx, const IR::Value& offset, Id lod, Id ms) { 63 explicit ImageOperands(Id lod, Id ms) {
64 if (Sirit::ValidId(lod)) { 64 if (Sirit::ValidId(lod)) {
65 Add(spv::ImageOperandsMask::Lod, lod); 65 Add(spv::ImageOperandsMask::Lod, lod);
66 } 66 }
67 AddOffset(ctx, offset, ImageFetchOffsetAllowed);
68 if (Sirit::ValidId(ms)) { 67 if (Sirit::ValidId(ms)) {
69 Add(spv::ImageOperandsMask::Sample, ms); 68 Add(spv::ImageOperandsMask::Sample, ms);
70 } 69 }
@@ -312,6 +311,43 @@ Id ImageGatherSubpixelOffset(EmitContext& ctx, const IR::TextureInstInfo& info,
312 return coords; 311 return coords;
313 } 312 }
314} 313}
314
315void AddOffsetToCoordinates(EmitContext& ctx, const IR::TextureInstInfo& info, Id& coords,
316 Id offset) {
317 if (!Sirit::ValidId(offset)) {
318 return;
319 }
320
321 Id result_type{};
322 switch (info.type) {
323 case TextureType::Buffer:
324 case TextureType::Color1D: {
325 result_type = ctx.U32[1];
326 break;
327 }
328 case TextureType::ColorArray1D:
329 offset = ctx.OpCompositeConstruct(ctx.U32[2], offset, ctx.u32_zero_value);
330 [[fallthrough]];
331 case TextureType::Color2D:
332 case TextureType::Color2DRect: {
333 result_type = ctx.U32[2];
334 break;
335 }
336 case TextureType::ColorArray2D:
337 offset = ctx.OpCompositeConstruct(ctx.U32[3], ctx.OpCompositeExtract(ctx.U32[1], coords, 0),
338 ctx.OpCompositeExtract(ctx.U32[1], coords, 1),
339 ctx.u32_zero_value);
340 [[fallthrough]];
341 case TextureType::Color3D: {
342 result_type = ctx.U32[3];
343 break;
344 }
345 case TextureType::ColorCube:
346 case TextureType::ColorArrayCube:
347 return;
348 }
349 coords = ctx.OpIAdd(result_type, coords, offset);
350}
315} // Anonymous namespace 351} // Anonymous namespace
316 352
317Id EmitBindlessImageSampleImplicitLod(EmitContext&) { 353Id EmitBindlessImageSampleImplicitLod(EmitContext&) {
@@ -494,9 +530,10 @@ Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index,
494 operands.Span()); 530 operands.Span());
495} 531}
496 532
497Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, 533Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset,
498 const IR::Value& offset, Id lod, Id ms) { 534 Id lod, Id ms) {
499 const auto info{inst->Flags<IR::TextureInstInfo>()}; 535 const auto info{inst->Flags<IR::TextureInstInfo>()};
536 AddOffsetToCoordinates(ctx, info, coords, offset);
500 if (info.type == TextureType::Buffer) { 537 if (info.type == TextureType::Buffer) {
501 lod = Id{}; 538 lod = Id{};
502 } 539 }
@@ -504,7 +541,7 @@ Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id c
504 // This image is multisampled, lod must be implicit 541 // This image is multisampled, lod must be implicit
505 lod = Id{}; 542 lod = Id{};
506 } 543 }
507 const ImageOperands operands(ctx, offset, lod, ms); 544 const ImageOperands operands(lod, ms);
508 return Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst, ctx.F32[4], 545 return Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst, ctx.F32[4],
509 TextureImage(ctx, info, index), coords, operands.MaskOptional(), operands.Span()); 546 TextureImage(ctx, info, index), coords, operands.MaskOptional(), operands.Span());
510} 547}
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h
index 08fcabd58..5c01b1012 100644
--- a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h
+++ b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h
@@ -537,8 +537,8 @@ Id EmitImageGather(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id
537 const IR::Value& offset, const IR::Value& offset2); 537 const IR::Value& offset, const IR::Value& offset2);
538Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, 538Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
539 const IR::Value& offset, const IR::Value& offset2, Id dref); 539 const IR::Value& offset, const IR::Value& offset2, Id dref);
540Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, 540Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset,
541 const IR::Value& offset, Id lod, Id ms); 541 Id lod, Id ms);
542Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id lod, 542Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id lod,
543 const IR::Value& skip_mips); 543 const IR::Value& skip_mips);
544Id EmitImageQueryLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords); 544Id EmitImageQueryLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords);