From 5d6abfe3f49a15045e7ffff316fdc7ad5a435992 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Sat, 21 Jun 2025 16:11:01 -0700 Subject: [PATCH] shader_recompiler: Fix handling unbound depth image. --- src/shader_recompiler/info.h | 14 +++++++------- .../ir/passes/resource_tracking_pass.cpp | 15 ++++++++------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/shader_recompiler/info.h b/src/shader_recompiler/info.h index 6c931da31..8a7fb5d41 100644 --- a/src/shader_recompiler/info.h +++ b/src/shader_recompiler/info.h @@ -308,17 +308,17 @@ constexpr AmdGpu::Image ImageResource::GetSharp(const Info& info) const noexcept if (!is_r128) { image = info.ReadUdSharp(sharp_idx); } else { - AmdGpu::Buffer buf = info.ReadUdSharp(sharp_idx); + const auto buf = info.ReadUdSharp(sharp_idx); memcpy(&image, &buf, sizeof(buf)); } if (!image.Valid()) { // Fall back to null image if unbound. - return AmdGpu::Image::Null(); - } - const auto data_fmt = image.GetDataFmt(); - if (is_depth && data_fmt != AmdGpu::DataFormat::Format16 && - data_fmt != AmdGpu::DataFormat::Format32) { - return AmdGpu::Image::NullDepth(); + 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) { + image = AmdGpu::Image::NullDepth(); + } } return image; } diff --git a/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp b/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp index e278d10f8..ec46ce5ff 100644 --- a/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp +++ b/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp @@ -369,13 +369,14 @@ void PatchImageSharp(IR::Block& block, IR::Inst& inst, Info& info, Descriptors& auto image = info.ReadUdSharp(tsharp); if (!image.Valid()) { LOG_ERROR(Render_Vulkan, "Shader compiled with unbound image!"); - image = AmdGpu::Image::Null(); - } - const auto data_fmt = image.GetDataFmt(); - if (inst_info.is_depth && 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(); + 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;