From 41b5ec9b1a826401604ec5ae0ee413247aff6734 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Sat, 21 Jun 2025 16:25:02 -0700 Subject: [PATCH] shader_recompiler: Consolidate unbound image handling. --- src/shader_recompiler/info.h | 2 ++ .../ir/passes/resource_tracking_pass.cpp | 32 +++++++------------ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/shader_recompiler/info.h b/src/shader_recompiler/info.h index 8a7fb5d41..6777c4769 100644 --- a/src/shader_recompiler/info.h +++ b/src/shader_recompiler/info.h @@ -313,10 +313,12 @@ constexpr AmdGpu::Image ImageResource::GetSharp(const Info& info) const noexcept } if (!image.Valid()) { // Fall back to null image if unbound. + LOG_DEBUG(Render_Vulkan, "Encountered unbound image!"); image = is_depth ? AmdGpu::Image::NullDepth() : AmdGpu::Image::Null(); } else if (is_depth) { const auto data_fmt = image.GetDataFmt(); if (data_fmt != AmdGpu::DataFormat::Format16 && data_fmt != AmdGpu::DataFormat::Format32) { + LOG_DEBUG(Render_Vulkan, "Encountered non-depth image used with depth instruction!"); image = AmdGpu::Image::NullDepth(); } } diff --git a/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp b/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp index ec46ce5ff..2e9b78f0e 100644 --- a/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp +++ b/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp @@ -366,20 +366,17 @@ void PatchImageSharp(IR::Block& block, IR::Inst& inst, Info& info, Descriptors& // Read image sharp. const auto tsharp = TrackSharp(tsharp_handle, info); const auto inst_info = inst.Flags(); - auto image = info.ReadUdSharp(tsharp); - if (!image.Valid()) { - LOG_ERROR(Render_Vulkan, "Shader compiled with unbound image!"); - image = inst_info.is_depth ? AmdGpu::Image::NullDepth() : AmdGpu::Image::Null(); - } else if (inst_info.is_depth) { - const auto data_fmt = image.GetDataFmt(); - if (data_fmt != AmdGpu::DataFormat::Format16 && data_fmt != AmdGpu::DataFormat::Format32) { - LOG_ERROR(Render_Vulkan, - "Shader compiled using non-depth image with depth instruction!"); - image = AmdGpu::Image::NullDepth(); - } - } - ASSERT(image.GetType() != AmdGpu::ImageType::Invalid); const bool is_written = inst.GetOpcode() == IR::Opcode::ImageWrite; + const ImageResource image_res = { + .sharp_idx = tsharp, + .is_depth = bool(inst_info.is_depth), + .is_atomic = IsImageAtomicInstruction(inst), + .is_array = bool(inst_info.is_array), + .is_written = is_written, + .is_r128 = bool(inst_info.is_r128), + }; + auto image = image_res.GetSharp(info); + ASSERT(image.GetType() != AmdGpu::ImageType::Invalid); // Patch image instruction if image is FMask. if (image.IsFmask()) { @@ -414,14 +411,7 @@ void PatchImageSharp(IR::Block& block, IR::Inst& inst, Info& info, Descriptors& } } - u32 image_binding = descriptors.Add(ImageResource{ - .sharp_idx = tsharp, - .is_depth = bool(inst_info.is_depth), - .is_atomic = IsImageAtomicInstruction(inst), - .is_array = bool(inst_info.is_array), - .is_written = is_written, - .is_r128 = bool(inst_info.is_r128), - }); + u32 image_binding = descriptors.Add(image_res); IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)};