From 22bdafecbb2447bf5f085c9683c63c22135478e8 Mon Sep 17 00:00:00 2001 From: nmzik Date: Thu, 20 Aug 2026 08:12:16 +0200 Subject: [PATCH] graphics: preserve raw D16 uint texture reads --- .../host_gpu/renderer/cache/textureCache.cpp | 16 ++++++++- tests/ShaderRecompilerComputeTests.cpp | 36 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/graphics/host_gpu/renderer/cache/textureCache.cpp b/src/graphics/host_gpu/renderer/cache/textureCache.cpp index cccc6098e..bc1b317b4 100644 --- a/src/graphics/host_gpu/renderer/cache/textureCache.cpp +++ b/src/graphics/host_gpu/renderer/cache/textureCache.cpp @@ -683,9 +683,23 @@ ImageId TextureCache::ResolveDepthOverlap(const ImageInfo& requested, BindingTyp } const bool stencil_match = requested.HasStencil() == cached.info.HasStencil(); const bool bpp_match = requested.bytes_per_block == cached.info.bytes_per_block; + // PPSA04264 + const bool raw_d16_texture = + binding == BindingType::Texture && cached.info.IsDepth() && + cached.info.guest_format == Prospero::BufferFormat::k16UNorm && + requested.guest_format == Prospero::BufferFormat::k16UInt && + requested.pixel_format == vk::Format::eR16Uint && cached.backing.samples == 1 && + requested.samples == 1 && requested.data == cached.info.data && + requested.extent == cached.info.extent && requested.resources == cached.info.resources && + requested.type == cached.info.type && requested.pitch == cached.info.pitch && + requested.tile_mode == cached.info.tile_mode && !requested.HasStencil() && + !cached.info.HasStencil() && !requested.HasMetadata() && !cached.info.HasMetadata(); bool recreate = cached.info.resources < requested.resources; switch (binding) { - case BindingType::Texture: recreate |= requested.IsDepth() && !cached.info.IsDepth(); break; + case BindingType::Texture: + recreate |= requested.IsDepth() && !cached.info.IsDepth(); + recreate |= raw_d16_texture; + break; case BindingType::Storage: recreate |= cached.info.IsDepth(); break; case BindingType::RenderTarget: recreate |= cached.info.IsDepth(); break; case BindingType::DepthTarget: diff --git a/tests/ShaderRecompilerComputeTests.cpp b/tests/ShaderRecompilerComputeTests.cpp index f08979a4c..7a8b6f418 100644 --- a/tests/ShaderRecompilerComputeTests.cpp +++ b/tests/ShaderRecompilerComputeTests.cpp @@ -3846,6 +3846,42 @@ public: "partial depth synchronization was accepted or " "transferred ownership"); + constexpr uint64_t raw_d16_offset = 0x27d0000; + constexpr std::array raw_d16_values{0x2000u, 0xc000u}; + std::memcpy(memory + raw_d16_offset, raw_d16_values.data(), + sizeof(raw_d16_values)); + auto raw_d16 = MakeLinearDesc( + base + raw_d16_offset, sizeof(raw_d16_values), + vk::Format::eD16Unorm, Prospero::BufferFormat::k16UNorm, + Prospero::ImageType::kColor2D, {2, 1, 1}, 1, sizeof(uint16_t), 1); + raw_d16.type = BindingType::DepthTarget; + raw_d16.view_info.format = vk::Format::eD16Unorm; + raw_d16.view_info.aspect = vk::ImageAspectFlagBits::eDepth; + raw_d16.view_info.usage = + vk::ImageUsageFlagBits::eDepthStencilAttachment; + const auto raw_d16_image = texture_cache.FindImage(raw_d16); + (void)texture_cache.FindDepthTarget(raw_d16_image, raw_d16); + + auto raw_d16_uint = raw_d16; + raw_d16_uint.type = BindingType::Texture; + raw_d16_uint.info.pixel_format = vk::Format::eR16Uint; + raw_d16_uint.info.guest_format = Prospero::BufferFormat::k16UInt; + raw_d16_uint.view_info.format = vk::Format::eR16Uint; + raw_d16_uint.view_info.aspect = vk::ImageAspectFlagBits::eColor; + raw_d16_uint.view_info.usage = vk::ImageUsageFlagBits::eSampled; + const auto raw_d16_uint_image = texture_cache.FindImage(raw_d16_uint); + Require(name, "raw D16 uint texture backing", + raw_d16_uint_image && raw_d16_uint_image != raw_d16_image && + !TextureCacheTestAccess::Contains(texture_cache, + raw_d16_image) && + texture_cache.GetImage(raw_d16_uint_image) + .backing.format == vk::Format::eR16Uint, + "D16 uint sampling did not recreate a true integer color backing"); + Require(name, "raw D16 uint texture view", + texture_cache.FindTexture(raw_d16_uint_image, raw_d16_uint) != + nullptr, + "D16 uint sampling did not create an integer sampled view"); + auto native_array_info = array_desc.info; native_array_info.data = {}; auto native_volume_info = volume_desc.info;