summaryrefslogtreecommitdiff
path: root/src/shader_recompiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler')
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_image.cpp41
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_instructions.h4
2 files changed, 38 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..64a4e0e55 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,37 @@ 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 case TextureType::ColorArray1D: {
326 result_type = ctx.U32[1];
327 break;
328 }
329 case TextureType::Color2D:
330 case TextureType::Color2DRect:
331 case TextureType::ColorArray2D: {
332 result_type = ctx.U32[2];
333 break;
334 }
335 case TextureType::Color3D: {
336 result_type = ctx.U32[3];
337 break;
338 }
339 case TextureType::ColorCube:
340 case TextureType::ColorArrayCube:
341 return;
342 }
343 coords = ctx.OpIAdd(result_type, coords, offset);
344}
315} // Anonymous namespace 345} // Anonymous namespace
316 346
317Id EmitBindlessImageSampleImplicitLod(EmitContext&) { 347Id EmitBindlessImageSampleImplicitLod(EmitContext&) {
@@ -494,9 +524,10 @@ Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index,
494 operands.Span()); 524 operands.Span());
495} 525}
496 526
497Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, 527Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset,
498 const IR::Value& offset, Id lod, Id ms) { 528 Id lod, Id ms) {
499 const auto info{inst->Flags<IR::TextureInstInfo>()}; 529 const auto info{inst->Flags<IR::TextureInstInfo>()};
530 AddOffsetToCoordinates(ctx, info, coords, offset);
500 if (info.type == TextureType::Buffer) { 531 if (info.type == TextureType::Buffer) {
501 lod = Id{}; 532 lod = Id{};
502 } 533 }
@@ -504,7 +535,7 @@ Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id c
504 // This image is multisampled, lod must be implicit 535 // This image is multisampled, lod must be implicit
505 lod = Id{}; 536 lod = Id{};
506 } 537 }
507 const ImageOperands operands(ctx, offset, lod, ms); 538 const ImageOperands operands(lod, ms);
508 return Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst, ctx.F32[4], 539 return Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst, ctx.F32[4],
509 TextureImage(ctx, info, index), coords, operands.MaskOptional(), operands.Span()); 540 TextureImage(ctx, info, index), coords, operands.MaskOptional(), operands.Span());
510} 541}
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);