From 54a17054fe44463890d34db3b4db12293a53ec4c Mon Sep 17 00:00:00 2001 From: slopgobblercobbler <336610228+slopgobblercobbler@users.noreply.github.com> Date: Thu, 26 Nov 2026 23:27:04 +0100 Subject: [PATCH 1/2] fix(kyty): ignore exemplar skip_degamma for image heap specializations --- .../ir/passes/ResourceMaterialization.cpp | 6 +- .../KytyShim/tests/CMakeLists.txt | 10 ++ .../KytyShim/tests/ImageHeapVariantKey.cpp | 155 ++++++++++++++++++ 3 files changed, 166 insertions(+), 5 deletions(-) create mode 100644 core/libs/prx/libSceAgcDriver/KytyShim/tests/ImageHeapVariantKey.cpp diff --git a/core/kyty/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp b/core/kyty/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp index 44ad99bfc4..eedc50cf3a 100644 --- a/core/kyty/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp +++ b/core/kyty/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp @@ -1598,11 +1598,7 @@ static bool BuildResourceSpecialization(const ResourcePlan& program, ResourceSna static_cast((descriptor.dwords[3] >> 20u) & 0x1fu) == Prospero::TileMode::kDepth; image.conversion_format = depth_bits ? format : ImageConversionFormat(format); - const auto* base_source = Source(program, base.source); - const bool table_heap = image.heap && base_source != nullptr && - base_source->indirect_descriptor.has_value() && - base_source->indirect_descriptor->table_array; - image.skip_degamma = !table_heap && Prospero::IsSrgbFormat(format) && + image.skip_degamma = !image.heap && Prospero::IsSrgbFormat(format) && SamplerSkipsDegamma(program, snapshot, base_index); if (!storage && !base.depth_compare && !image.skip_degamma && image.indirect_root == ImageResource::NoIndirectImage && diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt index 4d5bdc20d1..a60b61c5dd 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt @@ -70,6 +70,16 @@ target_include_directories(kyty_shim_half_profile_tests SYSTEM PRIVATE ${CMAKE_S add_test(NAME kyty_shim_half_profile COMMAND kyty_shim_half_profile_tests) set_tests_properties(kyty_shim_half_profile PROPERTIES TIMEOUT 20) +add_test_executable(kyty_shim_image_heap_variant_key_tests ${CMAKE_CURRENT_SOURCE_DIR}/ImageHeapVariantKey.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../src/Log.cpp) +target_include_directories(kyty_shim_image_heap_variant_key_tests PRIVATE ${LIBS_INCLUDE_DIR}) +configure_host_test_executable(kyty_shim_image_heap_variant_key_tests) +if(MINGW) + target_link_libraries(kyty_shim_image_heap_variant_key_tests PRIVATE stdc++ gcc_eh) +endif() +target_link_libraries(kyty_shim_image_heap_variant_key_tests PRIVATE Kyty::gpu libkernel libc) +add_test(NAME kyty_shim_image_heap_variant_key COMMAND kyty_shim_image_heap_variant_key_tests) +set_tests_properties(kyty_shim_image_heap_variant_key PROPERTIES TIMEOUT 20 PASS_REGULAR_EXPRESSION "kyty_shim_image_heap_variant_key: ok") + add_test_executable(kyty_shim_replay_sampling_tests ${CMAKE_CURRENT_SOURCE_DIR}/ReplaySampling.cpp) configure_host_test_executable(kyty_shim_replay_sampling_tests) target_include_directories(kyty_shim_replay_sampling_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tools) diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/ImageHeapVariantKey.cpp b/core/libs/prx/libSceAgcDriver/KytyShim/tests/ImageHeapVariantKey.cpp new file mode 100644 index 0000000000..8b6df2a1d1 --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/ImageHeapVariantKey.cpp @@ -0,0 +1,155 @@ +#include "graphics/shader/recompiler/ir/passes/ResourceMaterialization.h" + +#include +#include +#include + +namespace { + +using namespace Libs::Graphics; +using namespace Libs::Graphics::ShaderRecompiler; + +void Require(bool condition, const char* message) { + if (condition) return; + std::fprintf(stderr, "kyty_shim_image_heap_variant_key: %s\n", message); + std::exit(1); +} + +IR::DescriptorValue MakeTextureDescriptor(Prospero::BufferFormat format) { + IR::DescriptorValue value {.dword_count = 8u}; + value.dwords[0] = 0x1000u; + value.dwords[1] = (static_cast(format) << 20u) | (3u << 30u); + value.dwords[2] = 15u; + value.dwords[3] = 0xfacu | (9u << 28u); + return value; +} + +class MockImageHeapSource final : public IR::ImageHeapSource { +public: + explicit MockImageHeapSource(IR::DescriptorValue exemplar) : m_exemplar(exemplar) {} + + bool Acquire(const IR::ImageHeapRequest& , IR::ImageHeapView& view) override { + view.slots = 0x200000000ull; + view.slot_count = 4u; + view.kinds = std::span(&m_exemplar, 1u); + return true; + } + +private: + IR::DescriptorValue m_exemplar; +}; + +IR::DescriptorSource MakeImmediateSource(std::span words) { + IR::DescriptorSource source; + source.dword_count = static_cast(words.size()); + for (size_t i = 0; i < words.size(); ++i) { + source.dwords[i] = IR::Value(words[i]); + } + return source; +} + +IR::ResourcePlan MakeHeapPlan() { + IR::ResourcePlan plan; + plan.stage = Libs::Graphics::ShaderType::Compute; + plan.resource_tracking_complete = true; + plan.srt_plan_complete = true; + + const std::array table_pointer {0x00000000u, 0x00000002u}; + const std::array sampler_words {0x80000012u, 0u, 0u, 0u}; + + IR::DescriptorSource indirect; + indirect.dword_count = 8u; + indirect.indirect_descriptor = IR::DescriptorSource::IndirectDescriptor { + .table_maximum = 3u, + .table_source = 0u, + .table_offset = 0u, + .table_stride = 32u, + .table_scalar = true, + }; + + plan.descriptor_sources.push_back(MakeImmediateSource(table_pointer)); + plan.descriptor_sources.push_back(std::move(indirect)); + plan.descriptor_sources.push_back(MakeImmediateSource(sampler_words)); + + IR::ImageResource image; + image.resource_class = IR::ImageResourceClass::Sampled; + image.read = true; + image.dimension = Decoder::ImageDimension::Dim2D; + image.source = 1u; + plan.info.images.push_back(image); + + IR::SamplerResource sampler; + sampler.source = 2u; + plan.info.samplers.push_back(sampler); + plan.info.sampled_pairs.push_back({.image = 0u, .sampler = 0u}); + IR::CompileSrtWalker(plan); + return plan; +} + +IR::ResourcePlan MakeDirectPlan(Prospero::BufferFormat format) { + IR::ResourcePlan plan; + plan.stage = Libs::Graphics::ShaderType::Compute; + plan.resource_tracking_complete = true; + plan.srt_plan_complete = true; + + const auto descriptor = MakeTextureDescriptor(format); + const std::array sampler_words {0x80000012u, 0u, 0u, 0u}; + plan.descriptor_sources.push_back(MakeImmediateSource(descriptor.dwords)); + plan.descriptor_sources.push_back(MakeImmediateSource(sampler_words)); + + IR::ImageResource image; + image.resource_class = IR::ImageResourceClass::Sampled; + image.read = true; + image.dimension = Decoder::ImageDimension::Dim2D; + image.source = 0u; + plan.info.images.push_back(image); + + IR::SamplerResource sampler; + sampler.source = 1u; + plan.info.samplers.push_back(sampler); + plan.info.sampled_pairs.push_back({.image = 0u, .sampler = 0u}); + IR::CompileSrtWalker(plan); + return plan; +} + +} + +int main() { + const auto heap_plan = MakeHeapPlan(); + const auto srgb_t = MakeTextureDescriptor(Prospero::BufferFormat::k8Srgb); + const auto unorm_t = MakeTextureDescriptor(Prospero::BufferFormat::k8UNorm); + + MockImageHeapSource heap_srgb(srgb_t); + MockImageHeapSource heap_unorm(unorm_t); + IR::SrtRuntime runtime_srgb {.image_heap = &heap_srgb}; + IR::SrtRuntime runtime_unorm {.image_heap = &heap_unorm}; + IR::ResourceSnapshot snap_srgb, snap_unorm; + IR::ResourceSpecialization spec_srgb, spec_unorm; + + Require(IR::MaterializeResources(heap_plan, runtime_srgb, snap_srgb, spec_srgb), + "sRGB heap exemplar failed materialization"); + Require(IR::MaterializeResources(heap_plan, runtime_unorm, snap_unorm, spec_unorm), + "UNorm heap exemplar failed materialization"); + Require(spec_srgb.images.size() == 2u && spec_unorm.images.size() == 2u, + "unexpected heap specialization image count"); + Require(spec_srgb == spec_unorm, + "image heap specialization differed between sRGB and UNorm exemplars of the same kind"); + Require(!spec_srgb.images[1].skip_degamma, + "image heap child must not record exemplar skip_degamma"); + + const auto direct_srgb_plan = MakeDirectPlan(Prospero::BufferFormat::k8Srgb); + const auto direct_unorm_plan = MakeDirectPlan(Prospero::BufferFormat::k8UNorm); + IR::SrtRuntime direct_runtime {}; + IR::ResourceSnapshot direct_snap_srgb, direct_snap_unorm; + IR::ResourceSpecialization direct_spec_srgb, direct_spec_unorm; + + Require(IR::MaterializeResources(direct_srgb_plan, direct_runtime, direct_snap_srgb, direct_spec_srgb), + "direct sRGB image failed materialization"); + Require(IR::MaterializeResources(direct_unorm_plan, direct_runtime, direct_snap_unorm, direct_spec_unorm), + "direct UNorm image failed materialization"); + Require(direct_spec_srgb.images[0].skip_degamma && !direct_spec_unorm.images[0].skip_degamma, + "direct sampled image must preserve skip_degamma"); + + std::puts("kyty_shim_image_heap_variant_key: ok"); + return 0; +} From 1ce046ce499b7048d32fcbfe91ee509a6f765b31 Mon Sep 17 00:00:00 2001 From: slopgobblercobbler <336610228+slopgobblercobbler@users.noreply.github.com> Date: Thu, 26 Nov 2026 23:39:39 +0100 Subject: [PATCH 2/2] test(kyty): rely on exit code for image heap variant key test --- core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt index a60b61c5dd..f8670f18fd 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt @@ -78,7 +78,7 @@ if(MINGW) endif() target_link_libraries(kyty_shim_image_heap_variant_key_tests PRIVATE Kyty::gpu libkernel libc) add_test(NAME kyty_shim_image_heap_variant_key COMMAND kyty_shim_image_heap_variant_key_tests) -set_tests_properties(kyty_shim_image_heap_variant_key PROPERTIES TIMEOUT 20 PASS_REGULAR_EXPRESSION "kyty_shim_image_heap_variant_key: ok") +set_tests_properties(kyty_shim_image_heap_variant_key PROPERTIES TIMEOUT 20) add_test_executable(kyty_shim_replay_sampling_tests ${CMAKE_CURRENT_SOURCE_DIR}/ReplaySampling.cpp) configure_host_test_executable(kyty_shim_replay_sampling_tests)