From f9cd6c7116b54b8e4be944ae0cd10544e09dbfae Mon Sep 17 00:00:00 2001 From: yuzubot Date: Mon, 5 Feb 2024 01:47:39 +0000 Subject: [PATCH] Merge yuzu-emu#12903 --- .../backend/spirv/emit_spirv_image.cpp | 41 +++---------------- .../backend/spirv/emit_spirv_instructions.h | 4 +- 2 files changed, 7 insertions(+), 38 deletions(-) diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp index 64a4e0e55..f62ae1ca9 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp @@ -60,7 +60,8 @@ public: Add(spv::ImageOperandsMask::ConstOffsets, offsets); } - explicit ImageOperands(Id lod, Id ms) { + explicit ImageOperands(EmitContext& ctx, const IR::Value& offset, Id lod, Id ms) { + AddOffset(ctx, offset, ImageFetchOffsetAllowed); if (Sirit::ValidId(lod)) { Add(spv::ImageOperandsMask::Lod, lod); } @@ -311,37 +312,6 @@ Id ImageGatherSubpixelOffset(EmitContext& ctx, const IR::TextureInstInfo& info, return coords; } } - -void AddOffsetToCoordinates(EmitContext& ctx, const IR::TextureInstInfo& info, Id& coords, - Id offset) { - if (!Sirit::ValidId(offset)) { - return; - } - - Id result_type{}; - switch (info.type) { - case TextureType::Buffer: - case TextureType::Color1D: - case TextureType::ColorArray1D: { - result_type = ctx.U32[1]; - break; - } - case TextureType::Color2D: - case TextureType::Color2DRect: - case TextureType::ColorArray2D: { - result_type = ctx.U32[2]; - break; - } - case TextureType::Color3D: { - result_type = ctx.U32[3]; - break; - } - case TextureType::ColorCube: - case TextureType::ColorArrayCube: - return; - } - coords = ctx.OpIAdd(result_type, coords, offset); -} } // Anonymous namespace Id EmitBindlessImageSampleImplicitLod(EmitContext&) { @@ -524,10 +494,9 @@ Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, operands.Span()); } -Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset, - Id lod, Id ms) { +Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, + const IR::Value& offset, Id lod, Id ms) { const auto info{inst->Flags()}; - AddOffsetToCoordinates(ctx, info, coords, offset); if (info.type == TextureType::Buffer) { lod = Id{}; } @@ -535,7 +504,7 @@ Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id c // This image is multisampled, lod must be implicit lod = Id{}; } - const ImageOperands operands(lod, ms); + const ImageOperands operands(ctx, offset, lod, ms); return Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst, ctx.F32[4], TextureImage(ctx, info, index), coords, operands.MaskOptional(), operands.Span()); } diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h index 5c01b1012..08fcabd58 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 const IR::Value& offset, const IR::Value& offset2); Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, const IR::Value& offset, const IR::Value& offset2, Id dref); -Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset, - Id lod, Id ms); +Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, + const IR::Value& offset, Id lod, Id ms); Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id lod, const IR::Value& skip_mips); Id EmitImageQueryLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords);