From b4506a359c140336faace432490c04a58afdbe08 Mon Sep 17 00:00:00 2001 From: DotDebian Date: Fri, 2 Oct 2026 19:07:30 +0200 Subject: [PATCH] feat(shader): decode image_sample_d_cl_o MIMG opcode 0x33 samples with explicit derivatives, an LOD clamp and a texel offset. The three address flags already exist; only the opcode was missing from the decoder table. Co-Authored-By: Claude Opus 5.5 --- .../tests/execution/ImageSampleLodClamp.cpp | 25 +++++++++++++------ .../RdnaDecoder/src/RdnaImageOpDecoder.cpp | 1 + tools/progress.py | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/ImageSampleLodClamp.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/ImageSampleLodClamp.cpp index 871273350..dcdd05ce3 100644 --- a/core/libs/prx/libSceAgcDriver/tests/execution/ImageSampleLodClamp.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/execution/ImageSampleLodClamp.cpp @@ -19,7 +19,7 @@ using AgcDriver::Graphics::Require; using ShaderRecompiler::ShaderStage; constexpr std::uint32_t Threads = 32; -constexpr std::uint32_t Words = 16; +constexpr std::uint32_t Words = 32; constexpr std::uint32_t ResultWord = 8; constexpr std::uint32_t Size = 16; constexpr std::uint32_t Levels = 5; @@ -31,12 +31,15 @@ constexpr std::uint32_t MinLodCapability = 42; alignas(256) std::array Buffer{}; alignas(256) std::array Texels{}; -alignas(256) constexpr std::array Code{ - 0x34020086, 0xe0301000, 0x80000501, 0xe0301004, 0x80000601, 0xe0301008, 0x80000701, 0xe030100c, +alignas(256) constexpr std::array Code{ + 0x34020087, 0xe0301000, 0x80000501, 0xe0301004, 0x80000601, 0xe0301008, 0x80000701, 0xe030100c, 0x80000801, 0xe0301010, 0x80000901, 0xe0301014, 0x80000a01, 0xe0301018, 0x80000b01, 0xbf8c3f70, 0xf08c0f08, 0x00610c05, 0xe0701020, 0x80000c01, 0xe0701024, 0x80000d01, 0xe0701028, 0x80000e01, 0xe070102c, 0x80000f01, 0xf0840f08, 0x00610c09, 0xe0701030, 0x80000c01, 0xe0701034, 0x80000d01, - 0xe0701038, 0x80000e01, 0xe070103c, 0x80000f01, 0xbf810000, + 0xe0701038, 0x80000e01, 0xe070103c, 0x80000f01, 0x7e0802ff, 0x00000201, 0xf0cc0f08, 0x00610c04, + 0xe0701040, 0x80000c01, 0xe0701044, 0x80000d01, 0xe0701048, 0x80000e01, 0xe070104c, 0x80000f01, + 0x7e0802ff, 0x00003e3f, 0xf0cc0f08, 0x00610c04, 0xe0701050, 0x80000c01, 0xe0701054, 0x80000d01, + 0xe0701058, 0x80000e01, 0xe070105c, 0x80000f01, 0xbf810000, }; struct Sample { @@ -133,14 +136,22 @@ void Run(AgcDriver::VulkanDevice& device) { device.WaitIdle(); } +std::uint32_t Wrap(std::uint32_t coordinate, std::int32_t offset, std::uint32_t size) { + const auto extent = static_cast(size); + return static_cast(((static_cast(coordinate) + offset) % extent + extent) % extent); +} + void Check() { - constexpr std::array names{"image_sample_d_cl", "image_sample_cl"}; + constexpr std::array names{"image_sample_d_cl", "image_sample_cl", "image_sample_d_cl_o (1, 2)", "image_sample_d_cl_o (-1, -2)"}; + constexpr std::array, 4> offsets{{{0, 0}, {0, 0}, {1, 2}, {-1, -2}}}; for (std::uint32_t tid = 0; tid < Threads; ++tid) { const auto sample = SampleOf(tid); - const std::array levels{std::max(sample.level, sample.clamp), sample.clamp}; + const std::uint32_t clamped = std::max(sample.level, sample.clamp); + const std::array levels{clamped, sample.clamp, clamped, clamped}; for (std::uint32_t index = 0; index < levels.size(); ++index) { const std::uint32_t level = levels[index]; - const std::array expected{level, sample.x >> level, sample.y >> level, 255u}; + const std::uint32_t size = Size >> level; + const std::array expected{level, Wrap(sample.x >> level, offsets[index][0], size), Wrap(sample.y >> level, offsets[index][1], size), 255u}; for (std::uint32_t component = 0; component < 4u; ++component) { const float value = std::bit_cast(Buffer[tid * Words + ResultWord + index * 4u + component]) * 255.0f; Require(std::lround(value) == static_cast(expected[component]), std::string(names[index]) + ": thread " + std::to_string(tid) + " component " + std::to_string(component) + " is " + std::to_string(value) + ", expected " + std::to_string(expected[component])); diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaImageOpDecoder.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaImageOpDecoder.cpp index 5d0aaf657..6a0b32488 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaImageOpDecoder.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaImageOpDecoder.cpp @@ -41,6 +41,7 @@ constexpr ImageOpcodeInfo imageOpcodes[] = { {0x37u, RdnaOpcode::ImageSample, "image_sample_lz_o", RdnaImageSampleFlagLevelZero | RdnaImageSampleFlagOffset, true, false, false}, {0x38u, RdnaOpcode::ImageSample, "image_sample_c_o", RdnaImageSampleFlagCompare | RdnaImageSampleFlagOffset, true, false, false}, {0x68u, RdnaOpcode::ImageSample, "image_sample_cd", RdnaImageSampleFlagDerivative | RdnaImageSampleFlagCd, true, false, false}, + {0x33u, RdnaOpcode::ImageSample, "image_sample_d_cl_o", RdnaImageSampleFlagDerivative | RdnaImageSampleFlagLodClamp | RdnaImageSampleFlagOffset, true, false, false}, {0xa0u, RdnaOpcode::ImageSample, "image_sample_a", RdnaImageSampleFlagAdjust, true, false, false}, {0xa1u, RdnaOpcode::ImageSample, "image_sample_cl_a", RdnaImageSampleFlagLodClamp | RdnaImageSampleFlagAdjust, true, false, false}, {0xa5u, RdnaOpcode::ImageSample, "image_sample_b_a", RdnaImageSampleFlagBias | RdnaImageSampleFlagAdjust, true, false, false}, diff --git a/tools/progress.py b/tools/progress.py index c233224b0..fb450bf60 100644 --- a/tools/progress.py +++ b/tools/progress.py @@ -32,7 +32,7 @@ OPCODE_VARIANTS = { "SWaitcnt": ("S_WAITCNT_VSCNT",), "VAddI32": ("V_ADD_CO_U32",), "VSubrevI32": ("V_SUBREV_CO_U32",), - "ImageSample": ("IMAGE_SAMPLE_L", "IMAGE_SAMPLE_B", "IMAGE_SAMPLE_C_LZ", "IMAGE_SAMPLE_L_O"), + "ImageSample": ("IMAGE_SAMPLE_L", "IMAGE_SAMPLE_B", "IMAGE_SAMPLE_C_LZ", "IMAGE_SAMPLE_L_O", "IMAGE_SAMPLE_D_CL_O"), } REPORT_ROWS = 100 PANEL_WIDTH, GAP, MAP_HEIGHT, HEADER = 495, 10, 280, 30