From 0e76c7356912e6c129cec9f1f172d4f08e0c577e Mon Sep 17 00:00:00 2001 From: adrianmjim <11887815+adrianmjim@users.noreply.github.com> Date: Tue, 24 Nov 2026 16:56:04 +0100 Subject: [PATCH 1/3] test: texture tiles NOTE only for AMD's rounded CopyTiles offset (D3D-TILES-AMD-BYTE-OFFSET) d3d12_texture_tiles failed on AMD Windows (RX 7900 XT, driver 32.0.32029.2010 / 26.11.2) with "row-major alias tile 0 at (0,0): got 0x20000cc, expected 0xcc020000". The half that failed was native D3D12, not the Vulkan layer: the layer's 256 x 240 replay at linear offset 1 had already passed, and buffered stdout printed its progress line after the native failure on stderr. AMD's driver behaves as if CopyTiles rounded BufferStartOffsetInBytes down to a multiple of 4, in both directions: the row-major CopyTextureRegion finds each texel 1-3 bytes early, and texels that straddle a tile seam differ in the CopyTiles reads too. Offsets 1, 2, 3, 5, 6 and 7 diverge; 4 and 8 match. CopyTiles documents no alignment for that offset, WARP meets the test's expectations at every offset tried (1-8), and so does the layer, which stages unaligned offsets through transfer scratch so Vulkan only sees texel-aligned bufferOffsets (the validation layer reports nothing). The mechanism is inferred from the texel values: the D3D12 debug layer is not installed here and was not run. At a byte-unaligned offset the native run now reads every texel quietly and is a NOTE (on stdout) only when every checked read equals modelled_readback(), the CPU model of CopyTiles moving whole 64 KiB tiles with the offset rounded down to 4. Any other divergence fails and names the first read off the model, and every byte-offset case first checks that the model with the true offset reproduces the expectations. In local runs with extra cases (not committed), native on this GPU matches the model at every texel for offsets 1-3 and 5-7 on 256x256, 240x240, 130x129 and 129x250, and a deliberately wrong model (a multiple of 2) fails. WARP runs at those offsets to confirm the expectations; without WARP the output says nothing confirms them. The layer is held to the expectations at every offset, as before. 256x240 and 240x240 at offset 4 are new cases, so native stays strict on clipped tiles on every GPU. Under Wine and Proton neither the hardware adapter nor WARP is compared (host_wine.h), as in the other host-comparison tests. stdout is unbuffered so progress lines stay in order with failures. docs/testing.md gets a Known problems row and docs/d3d12_vulkan.md describes the driver behaviour. Not addressed here, and still red now and then on AMD: the native half of the COPY-to-DIRECT case (offset 4) sometimes reads zeros through the aliased tiles on this GPU (5 of 30 runs under a parallel ctest, and once in 3 single-test runs). On 23c45964 that case is never reached on AMD, because the offset-1 case fails first; it also fails with the unchanged test code when only that case is run, and in a native-only probe without the layer. It is a separate finding. Tested on AMD Radeon RX 7900 XT, driver 32.0.32029.2010, Windows 11, Vulkan SDK 1.4.363.0: the test from 23c45964 fails 6/6 runs at offset 1; this one passed 6/6 in a row (3 with LEONIDA_VK_VALIDATION=1, no validation messages), apart from the handoff case above; full ctest: only the 4 failures main already has on this GPU (vk_queue_query_sync, d3d12_execute_indirect_validation, d3d12_clear, d3d12_pipeline_library_host). AI-assisted. Co-Authored-By: Claude Opus 5.5 --- docs/d3d12_vulkan.md | 9 +- docs/testing.md | 1 + runtime/test/d3d12_texture_tiles_test.cpp | 239 +++++++++++++++++----- 3 files changed, 201 insertions(+), 48 deletions(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 8bf2bd38ea..77847f05b5 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -2449,7 +2449,14 @@ The trace will enumerate them. - `CopyTiles` transfers RGBA8 tiles in either direction. Partial edge blocks use the full 512-byte linear row pitch and transfer only in-bounds texels. Byte-unaligned offsets use transfer scratch. `d3d12_texture_tiles_test` compares initially unmapped tiles, column mappings, aliases, and a fence-delayed - remap with native D3D12, including clipped edges and byte-unaligned offsets. + remap with native D3D12, including clipped edges at 4-byte and byte-unaligned offsets. `CopyTiles` documents no + alignment for `BufferStartOffsetInBytes`; at a byte-unaligned offset WARP also runs, to confirm the test's + expectations (it meets them at every offset tried, 1-8), and the layer is held to them. AMD's Windows D3D12 + driver (RX 7900 XT, 26.11.2) does not: judging by the texel values (the D3D12 debug layer was not run), it + moves whole tiles as if the offset were rounded down to a multiple of 4, in both directions, so a row-major + copy finds each texel 1-3 bytes early and texels that straddle a tile seam differ in the `CopyTiles` reads. The + test prints a note when a native run matches that rounded-down model at every texel, and fails on any other + divergence ([testing.md](testing.md#known-problems)). - `D3D12_RESOURCE_DESC::Layout`: the public `ROW_MAJOR` and `64KB_STANDARD_SWIZZLE` values plus the Xbox `0x101` tiled value from slot 76. Row-major textures need `VK_IMAGE_TILING_LINEAR` (not usable for RT/DS) or a staging copy; `64KB_STANDARD_SWIZZLE` and `0x101` have no direct Vulkan equivalent. If the game uploads console-tiled data, diff --git a/docs/testing.md b/docs/testing.md index 04a5af1805..1c05fc1448 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -665,6 +665,7 @@ game's device ignores it`, so leaving them set cannot slow a game down (`run_tin | With `--wave64-emulate` (or `LEONIDA_W64_EMULATE=1`) on an NVIDIA RTX 5080 with Windows driver 32.0.16.1692 (616.92), `crosslane_fuzz.py --seed 91001 --dpp --no-maskdata` reports a hard mismatch for `cs_xl64_9100373886`: after `s_xor_b64 s[16:17], vcc, vcc` (0 in every lane), the second of two nested `v_cndmask_b32_e64 … s[16:17]` returns the old register instead of the lane id | An NVIDIA driver miscompile, not the translator (SHADER-720). The same SPIR-V (spirv-val clean) matches the model on an RTX 3060 with 616.64, an RTX 5060 Ti (Blackwell) with 621.14, an RTX 5070 Ti with 621.24 and an RTX 5080 with the Linux 580.65.06 driver. Hand edits narrow it to a value selected through the `%active` gate of a store; on the Linux 580 driver a similar pattern, a subgroup shuffle selected by an `%active` that is false, still fails in three wave32 `v_permlane16`/`v_permlanex16` programs of the same seed (#3796, #3918) | Update the NVIDIA driver to 621.14 or newer on Windows. If a crosslane mismatch only shows on one driver, check another driver or GPU before changing the translator | | `lds_fuzz.py --wave 64` (native, not `--emulate`) reports a `ds_bpermute_b32` mismatch on an AMD GPU on Windows, e.g. `cs_ldsfuzz_s7031_496_w64` (seed 7031): small values like `0x14` where the model wants another lane's data, while `--oracle hw` and `--emulate` on another GPU agree with the model | The AMD Windows driver (32.0.21042.62, gfx1036) miscompiles a native wave64 compute shader with two subgroup shuffles; a reduced SPIR-V module is in #4613 | Not a translator regression: check the same seed with `--oracle hw` and with `--emulate`. Native wave64 results on that driver need that cross-check | | On AMD's Windows driver a compute pipeline creation takes tens of minutes: `vk_pipeline_check` prints `still compiling after ...s` with one busy thread, or a compute PSO creation through the D3D12 layer seems never to return | The driver's compiler on one module in the dispatch-loop form (`"control_flow": "dispatch loop"` in the translated `index.json`). Measured on a Radeon gfx1036 iGPU, driver 32.0.21042.62 (SHADER-995): `XboxBvhBuilder.dll`'s `LeafRehydration` in that form (a 581-case switch in a loop) was created after 34 minutes of one busy thread (XXTESTING), while its structured module is created in 2.9 s and an RTX 3070 (NVIDIA 610.74) created the dispatch-loop one in 11 s. It is not every such module: ten other programs of that DLL compile in that form on the Radeon in 0.4 to 40 s ([embedded_shaders.md](embedded_shaders.md), section 7). Not tried on another AMD GPU or driver branch | Translate with current `main`. Since SHADER-427 only a tree nested deeper than 64, a graph that cannot be made reducible or `--dispatch-loop` gives that form, and none of that DLL's programs has it; the shaders stage translates again by itself when the translator changed. A wave64 compute shader that still has it comes out in another form with `--wave64-emulate on` (12.4 s for this program on that driver), which that driver can crash on for other programs (#857) | +| `d3d12_texture_tiles` passes but prints `NOTE: native D3D12 broke the expectations at N of M checked reads, every read as CopyTiles would with linear offset 1 rounded down to 0 in both directions` (and the same at offset 3) | AMD's Windows D3D12 driver (RX 7900 XT, 26.11.2, `32.0.32029.2010`) runs `CopyTiles` at a byte-unaligned `BufferStartOffsetInBytes` as if the offset were rounded down to a multiple of 4, in both directions. That is inferred from the texel values; the D3D12 debug layer was not run. `CopyTiles` documents no alignment, WARP meets the test's expectations at every offset tried (1-8), and so does the layer, which stages such offsets through aligned scratch | Nothing: the note is harmless. The test still fails when a native run diverges in any other way, or at a 4-byte offset | ### Signed zero in a float storage image (SHADER-605) diff --git a/runtime/test/d3d12_texture_tiles_test.cpp b/runtime/test/d3d12_texture_tiles_test.cpp index fc08c34220..01a494ffba 100644 --- a/runtime/test/d3d12_texture_tiles_test.cpp +++ b/runtime/test/d3d12_texture_tiles_test.cpp @@ -1,5 +1,7 @@ -// D3D-285: compare synthetic sparse RGBA8 texture tiles on the Vulkan shim and native D3D12. +// D3D-285: compare synthetic sparse RGBA8 texture tiles on the Vulkan shim and native D3D12; at byte-unaligned +// CopyTiles offsets WARP also confirms the expectations. #include "../shims/d3d12_com.h" +#include "host_wine.h" #include #include @@ -75,18 +77,103 @@ void transition(ID3D12GraphicsCommandList& list, ID3D12Resource* resource, list.ResourceBarrier(1, &barrier); } -bool compare_pixel(std::vector& result, std::uint32_t actual, std::uint32_t expected, - const char* read, UINT tile, UINT x, UINT y) { - if (actual != expected) { - std::fprintf(stderr, "%s tile %u at (%u,%u): got %#x, expected %#x\n", read, tile, x, y, actual, expected); - return false; +// The tiles' texels in the upload buffer, from `data` = the buffer at the CopyTiles offset. +void fill_tiles(std::uint8_t* data) { + for (UINT tile = 0; tile < tiles; ++tile) + for (UINT y = 0; y < tile_height; ++y) + for (UINT x = 0; x < tile_width; ++x) { + const auto value = pixel(tile, x, y); + std::memcpy(data + tile * tile_bytes + y * row_pitch + x * sizeof(value), &value, sizeof(value)); + } +} + +std::uint32_t load(const std::uint8_t* bytes, UINT64 offset) { + std::uint32_t value = 0; + std::memcpy(&value, bytes + offset, sizeof(value)); + return value; +} + +// Every readback texel run() checks: `visit(read, tile, x, y, offset, expected)` with its readback offset and the +// value the D3D12 rules put there. Stops at the first false. +template +bool for_each_checked(UINT width, UINT height, UINT64 tile_copy_offset, Visit&& visit) { + for (UINT tile = 0; tile < tiles; ++tile) { + const UINT first_y = (tile / 2) * tile_height, first_x = (tile % 2) * tile_width; + const UINT rows = std::min(tile_height, height - first_y), columns = std::min(tile_width, width - first_x); + for (UINT y = 0; y < rows; ++y) { + for (UINT x = 0; x < columns; ++x) { + const auto tiled = tile_copy_offset + tile * tile_bytes + y * row_pitch + x * sizeof(std::uint32_t); + if (!visit("initially unbound", tile, x, y, tiled, 0u)) return false; + const UINT source_x = ((tile ^ 1) % 2) * tile_width; + // The source never wrote the texels beyond its own clipped edge. + if (source_x + x < width) { + const auto aliased = pixel(tile ^ 1, x, y); + const auto row_major = row_major_offset + + ((first_y + y) * full_width + first_x + x) * sizeof(std::uint32_t); + if (!visit("alias", tile, x, y, image_bytes + tiled, aliased)) return false; + if (!visit("row-major alias", tile, x, y, row_major, aliased)) return false; + } + const auto remapped = tile < 2 ? pixel(0, x, y) : 0u; + if (!visit("remap", tile, x, y, 2 * image_bytes + tiled, remapped)) return false; + } + } } - result.push_back(actual); return true; } -bool run(ID3D12Device& device, UINT width, UINT height, UINT64 tile_copy_offset, - std::vector& result, bool layer, bool separate_copy_queue, bool& sparse) { +// The readback buffer run() leaves if every CopyTiles moves whole 64 KiB tiles (clipped texels too) with its linear +// offset taken as `linear`, in both directions. `linear` == tile_copy_offset gives the D3D12 rules (main() checks +// that against the expectations above); tile_copy_offset & ~3 gives the AMD pattern described in main(). +std::vector modelled_readback(UINT width, UINT height, UINT64 tile_copy_offset, UINT64 linear) { + std::vector upload(tile_copy_offset + image_bytes), heap(image_bytes), + readback(row_major_offset + image_bytes); + fill_tiles(upload.data() + tile_copy_offset); + // The heap tile behind each of a's tiles (UpdateTileMappings: the left column, then the right); b swaps the + // columns (CopyTileMappings). Snapshot 0 reads a unmapped: zeros, as the buffer starts. + constexpr UINT a_heap_tile[tiles] = {0, 2, 1, 3}; + const auto b_tile = [&](UINT tile) { return heap.data() + a_heap_tile[tile ^ 1] * tile_bytes; }; + for (UINT tile = 0; tile < tiles; ++tile) + std::memcpy(heap.data() + a_heap_tile[tile] * tile_bytes, upload.data() + linear + tile * tile_bytes, + tile_bytes); + for (UINT tile = 0; tile < tiles; ++tile) + std::memcpy(readback.data() + linear + image_bytes + tile * tile_bytes, b_tile(tile), tile_bytes); + for (UINT y = 0; y < height; ++y) // CopyTextureRegion, at an aligned footprint + for (UINT x = 0; x < width; ++x) + std::memcpy(readback.data() + row_major_offset + (y * full_width + x) * sizeof(std::uint32_t), + b_tile((y / tile_height) * 2 + x / tile_width) + (y % tile_height) * row_pitch + + (x % tile_width) * sizeof(std::uint32_t), + sizeof(std::uint32_t)); + // The gated remap: b's top row reuses heap tile 0 (a's first tile), its bottom row is unmapped (zeros). + for (UINT tile = 0; tile < tiles; ++tile) + if (tile < 2) + std::memcpy(readback.data() + linear + 2 * image_bytes + tile * tile_bytes, heap.data(), tile_bytes); + else + std::memset(readback.data() + linear + 2 * image_bytes + tile * tile_bytes, 0, tile_bytes); + return readback; +} + +// The model with the true offset must reproduce the expectations, or it cannot judge a native divergence. +bool model_matches_rules(UINT width, UINT height, UINT64 tile_copy_offset) { + const auto model = modelled_readback(width, height, tile_copy_offset, tile_copy_offset); + return for_each_checked(width, height, tile_copy_offset, + [&](const char* read, UINT tile, UINT x, UINT y, UINT64 offset, std::uint32_t expected) { + if (load(model.data(), offset) == expected) return true; + std::fprintf(stderr, "the CopyTiles model breaks the expectations: %s tile %u at (%u,%u)\n", read, tile, x, y); + return false; + }); +} + +// A native run at a byte-unaligned offset reads every texel quietly instead of stopping at the first that breaks the +// D3D12 rules: how many do, and how many differ from `model` (the readback modelled_readback gives). +struct Advisory { + const std::vector* model = nullptr; + std::uint64_t texels = 0, differ = 0, unmodelled = 0; + char first_unmodelled[160] = {}; +}; + +// False when a call fails, or (unless `advisory`) a texel breaks the D3D12 rules. +bool run(ID3D12Device& device, UINT width, UINT height, UINT64 tile_copy_offset, std::vector& result, + bool layer, bool separate_copy_queue, bool& sparse, Advisory* advisory = nullptr) { ComPtr a, b, upload, readback; const auto desc = texture_desc(width, height); EXPECT(SUCCEEDED(device.CreateReservedResource(&desc, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(&a)))); @@ -112,13 +199,7 @@ bool run(ID3D12Device& device, UINT width, UINT height, UINT64 tile_copy_offset, const D3D12_RANGE empty{0, 0}; void* mapped = nullptr; EXPECT(SUCCEEDED(upload->Map(0, &empty, &mapped))); - auto* data = static_cast(mapped) + tile_copy_offset; - for (UINT tile = 0; tile < tiles; ++tile) - for (UINT y = 0; y < tile_height; ++y) - for (UINT x = 0; x < tile_width; ++x) { - const auto value = pixel(tile, x, y); - std::memcpy(data + tile * tile_bytes + y * row_pitch + x * sizeof(value), &value, sizeof(value)); - } + fill_tiles(static_cast(mapped) + tile_copy_offset); upload->Unmap(0, nullptr); ComPtr gate, done; @@ -218,37 +299,32 @@ bool run(ID3D12Device& device, UINT width, UINT height, UINT64 tile_copy_offset, EXPECT(WaitForSingleObject(event.handle, 15000) == WAIT_OBJECT_0); EXPECT(SUCCEEDED(readback->Map(0, nullptr, &mapped))); - const auto read_pixel = [mapped](UINT64 offset) { - std::uint32_t value = 0; - std::memcpy(&value, static_cast(mapped) + offset, sizeof(value)); - return value; - }; - for (UINT tile = 0; tile < tiles; ++tile) { - const UINT first_y = (tile / 2) * tile_height, first_x = (tile % 2) * tile_width; - const UINT rows = std::min(tile_height, height - first_y), columns = std::min(tile_width, width - first_x); - for (UINT y = 0; y < rows; ++y) { - for (UINT x = 0; x < columns; ++x) { - const auto tiled = tile_copy_offset + tile * tile_bytes + y * row_pitch + x * sizeof(std::uint32_t); - EXPECT(compare_pixel(result, read_pixel(tiled), 0, "initially unbound", tile, x, y)); - const UINT source_x = ((tile ^ 1) % 2) * tile_width; - // The source never wrote the texels beyond its own clipped edge. - if (source_x + x < width) { - const auto aliased = pixel(tile ^ 1, x, y); - const auto row_major = row_major_offset + - ((first_y + y) * full_width + first_x + x) * sizeof(std::uint32_t); - EXPECT(compare_pixel(result, read_pixel(image_bytes + tiled), aliased, "alias", tile, x, y)); - EXPECT(compare_pixel(result, read_pixel(row_major), aliased, "row-major alias", tile, x, y)); - } - const auto remapped = tile < 2 ? pixel(0, x, y) : 0; - EXPECT(compare_pixel(result, read_pixel(2 * image_bytes + tiled), remapped, "remap", tile, x, y)); - } + const auto* bytes = static_cast(mapped); + const auto judge = [&](const char* read, UINT tile, UINT x, UINT y, UINT64 offset, std::uint32_t expected) { + const auto actual = load(bytes, offset); + if (advisory) { + const auto modelled = load(advisory->model->data(), offset); + ++advisory->texels; + advisory->differ += actual != expected; + if (actual != modelled && !advisory->unmodelled++) + std::snprintf(advisory->first_unmodelled, sizeof(advisory->first_unmodelled), + "%s tile %u at (%u,%u): got %#x, expected %#x, modelled %#x", read, tile, x, y, actual, + expected, modelled); + } else if (actual != expected) { + std::fprintf(stderr, "%s tile %u at (%u,%u): got %#x, expected %#x\n", read, tile, x, y, actual, expected); + return false; } - } + if (actual == expected) result.push_back(actual); + return true; + }; + EXPECT(for_each_checked(width, height, tile_copy_offset, judge)); readback->Unmap(0, &empty); return true; } +// Under Wine and Proton the host D3D12 is vkd3d, and "WARP" is vkd3d-proton on the GPU: neither is compared. ComPtr native_device() { + if (hostwine::host_is_wine()) return {}; ComPtr factory; if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) return {}; for (UINT i = 0;; ++i) { @@ -266,9 +342,28 @@ ComPtr native_device() { } } +ComPtr warp_device() { + if (hostwine::host_is_wine()) return {}; + ComPtr factory; + ComPtr adapter; + ComPtr device; + D3D12_FEATURE_DATA_D3D12_OPTIONS options{}; + if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))) || + FAILED(factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter))) || + FAILED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device))) || + FAILED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options))) || + options.TiledResourcesTier < D3D12_TILED_RESOURCES_TIER_2) { + std::puts("No WARP with tiled resources tier 2: nothing confirms the expectations at byte-unaligned offsets"); + return {}; + } + std::printf("WARP: tiled resources tier %u\n", unsigned(options.TiledResourcesTier)); + return device; +} + } // namespace int main() { + std::setvbuf(stdout, nullptr, _IONBF, 0); // progress in order with the failures on stderr ComPtr vulkan; if (FAILED(rt::d3d12::create_vulkan_device_standalone(IID_PPV_ARGS(&vulkan)))) { std::puts("Vulkan standalone device unavailable"); @@ -284,20 +379,34 @@ int main() { return 1; } auto native = native_device(); + // Byte-unaligned CopyTiles offsets. CopyTiles documents no alignment for BufferStartOffsetInBytes, and WARP meets + // the expectations at every offset tried (1-8), so at such an offset WARP runs too, to confirm them; the layer is + // held to the expectations. AMD's Windows D3D12 driver (RX 7900 XT, 26.11.2) does not meet them: judging by the + // texel values (the D3D12 debug layer was not run), it moves the tiles as if the offset were rounded down to a + // multiple of 4, in both directions. The row-major copy then finds each texel 1-3 bytes early, and texels that + // straddle a tile seam differ in the CopyTiles reads too. Such a native run is a NOTE only when every texel + // matches that rounded-down model (modelled_readback); any other divergence fails, and so does any texel at a + // 4-byte offset. + const auto warp = warp_device(); const auto* info = rt::d3d12::vulkan_device_info(vulkan.Get()); const bool dedicated_copy = info && !info->copy_queues.empty() && info->copy_family != info->queue_family; struct ReplayCase { UINT width, height, linear_offset; bool separate_copy_queue; }; - constexpr std::array cases{ReplayCase{256, 256, 4, false}, ReplayCase{256, 240, 1, false}, + // Clipped edges at a 4-byte offset keep native strict on partial tiles on every GPU. + constexpr std::array cases{ReplayCase{256, 256, 4, false}, ReplayCase{256, 240, 4, false}, + ReplayCase{240, 240, 4, false}, ReplayCase{256, 240, 1, false}, ReplayCase{240, 240, 3, false}, ReplayCase{256, 256, 4, true}}; if (!dedicated_copy) std::puts("No separate Vulkan copy family for the cross-family case"); for (const auto& [width, height, linear_offset, separate_copy_queue] : cases) { if (separate_copy_queue && !dedicated_copy) continue; bool sparse = false; - std::vector observed, expected; - if (!run(*vulkan.Get(), width, height, linear_offset, observed, true, separate_copy_queue, sparse)) return 1; + std::vector observed, expected, reference; + if (!run(*vulkan.Get(), width, height, linear_offset, observed, true, separate_copy_queue, sparse)) { + std::fprintf(stderr, "Vulkan replay failed: %u x %u, linear offset %u\n", width, height, linear_offset); + return 1; + } if (!sparse) { std::printf("Vulkan device does not support compatible sparse RGBA8 tiling for %u x %u\n", width, height); if (height == 256) return 77; @@ -306,10 +415,46 @@ int main() { std::printf("Vulkan replay: %u x %u, linear offset %u, initially unbound, aliased, row-major, gated remap%s\n", width, height, linear_offset, separate_copy_queue ? ", COPY-to-DIRECT handoff" : ""); + const bool byte_offset = linear_offset % 4 != 0; + if (byte_offset && !model_matches_rules(width, height, linear_offset)) return 1; if (native) { - if (!run(*native.Get(), width, height, linear_offset, expected, false, separate_copy_queue, sparse) || - observed != expected) return 1; - std::printf("Native D3D12 matched all %zu verified pixels\n", observed.size()); + const UINT rounded_offset = linear_offset & ~3u; + std::vector rounded; + Advisory advisory; + if (byte_offset) { + rounded = modelled_readback(width, height, linear_offset, rounded_offset); + advisory.model = &rounded; + } + if (!run(*native.Get(), width, height, linear_offset, expected, false, separate_copy_queue, sparse, + byte_offset ? &advisory : nullptr) || + (!advisory.differ && observed != expected)) { + std::fprintf(stderr, "Native D3D12 failed: %u x %u, linear offset %u\n", width, height, linear_offset); + return 1; + } + if (!advisory.differ) { + std::printf("Native D3D12 matched all %zu verified pixels\n", observed.size()); + } else if (!advisory.unmodelled) { + std::printf("NOTE: native D3D12 broke the expectations at %llu of %llu checked reads, every read as " + "CopyTiles would with linear offset %u rounded down to %u in both directions " + "(docs/testing.md, Known problems); not a failure\n", + static_cast(advisory.differ), + static_cast(advisory.texels), linear_offset, rounded_offset); + } else { + std::fprintf(stderr, "Native D3D12 failed: %u x %u, linear offset %u: %llu of %llu checked reads " + "break the expectations, and %llu differ from the rounded-down model; first: %s\n", + width, height, linear_offset, static_cast(advisory.differ), + static_cast(advisory.texels), + static_cast(advisory.unmodelled), advisory.first_unmodelled); + return 1; + } + } + if (byte_offset && warp) { + if (!run(*warp.Get(), width, height, linear_offset, reference, false, separate_copy_queue, sparse)) { + std::fprintf(stderr, "WARP failed: %u x %u, linear offset %u\n", width, height, linear_offset); + return 1; + } + std::printf("WARP meets the expectations at linear offset %u (%zu pixels)\n", linear_offset, + reference.size()); } } return 0; From e4f0403323309d3b757f2c27e229a07520dd58e9 Mon Sep 17 00:00:00 2001 From: adrianmjim <11887815+adrianmjim@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:46:33 +0100 Subject: [PATCH 2/3] test: texture tiles review follow-ups (D3D-TILES-AMD-BYTE-OFFSET) - for_each_checked skips a tile that starts past the texture's edge, so a case smaller than the tile grid cannot underflow `height - first_y`. - The upload buffer is zeroed before the CopyTiles offset: modelled_readback() reads those bytes when it rounds the offset down, and the model should not rely on the committed resource starting zeroed. - The first-unmodelled capture and the counter are written out explicitly instead of `!advisory->unmodelled++`. - docs/testing.md quotes the NOTE with placeholders (offset X rounded down to Y) instead of offset 1 only. Tested on AMD Radeon RX 7900 XT, driver 32.0.32029.2010: builds without warnings, d3d12_texture_tiles passes 3/3 (one with LEONIDA_VK_VALIDATION=1, no validation messages). AI-assisted. Co-Authored-By: Claude Opus 5.5 --- docs/testing.md | 2 +- runtime/test/d3d12_texture_tiles_test.cpp | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/testing.md b/docs/testing.md index 1c05fc1448..08d4733762 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -665,7 +665,7 @@ game's device ignores it`, so leaving them set cannot slow a game down (`run_tin | With `--wave64-emulate` (or `LEONIDA_W64_EMULATE=1`) on an NVIDIA RTX 5080 with Windows driver 32.0.16.1692 (616.92), `crosslane_fuzz.py --seed 91001 --dpp --no-maskdata` reports a hard mismatch for `cs_xl64_9100373886`: after `s_xor_b64 s[16:17], vcc, vcc` (0 in every lane), the second of two nested `v_cndmask_b32_e64 … s[16:17]` returns the old register instead of the lane id | An NVIDIA driver miscompile, not the translator (SHADER-720). The same SPIR-V (spirv-val clean) matches the model on an RTX 3060 with 616.64, an RTX 5060 Ti (Blackwell) with 621.14, an RTX 5070 Ti with 621.24 and an RTX 5080 with the Linux 580.65.06 driver. Hand edits narrow it to a value selected through the `%active` gate of a store; on the Linux 580 driver a similar pattern, a subgroup shuffle selected by an `%active` that is false, still fails in three wave32 `v_permlane16`/`v_permlanex16` programs of the same seed (#3796, #3918) | Update the NVIDIA driver to 621.14 or newer on Windows. If a crosslane mismatch only shows on one driver, check another driver or GPU before changing the translator | | `lds_fuzz.py --wave 64` (native, not `--emulate`) reports a `ds_bpermute_b32` mismatch on an AMD GPU on Windows, e.g. `cs_ldsfuzz_s7031_496_w64` (seed 7031): small values like `0x14` where the model wants another lane's data, while `--oracle hw` and `--emulate` on another GPU agree with the model | The AMD Windows driver (32.0.21042.62, gfx1036) miscompiles a native wave64 compute shader with two subgroup shuffles; a reduced SPIR-V module is in #4613 | Not a translator regression: check the same seed with `--oracle hw` and with `--emulate`. Native wave64 results on that driver need that cross-check | | On AMD's Windows driver a compute pipeline creation takes tens of minutes: `vk_pipeline_check` prints `still compiling after ...s` with one busy thread, or a compute PSO creation through the D3D12 layer seems never to return | The driver's compiler on one module in the dispatch-loop form (`"control_flow": "dispatch loop"` in the translated `index.json`). Measured on a Radeon gfx1036 iGPU, driver 32.0.21042.62 (SHADER-995): `XboxBvhBuilder.dll`'s `LeafRehydration` in that form (a 581-case switch in a loop) was created after 34 minutes of one busy thread (XXTESTING), while its structured module is created in 2.9 s and an RTX 3070 (NVIDIA 610.74) created the dispatch-loop one in 11 s. It is not every such module: ten other programs of that DLL compile in that form on the Radeon in 0.4 to 40 s ([embedded_shaders.md](embedded_shaders.md), section 7). Not tried on another AMD GPU or driver branch | Translate with current `main`. Since SHADER-427 only a tree nested deeper than 64, a graph that cannot be made reducible or `--dispatch-loop` gives that form, and none of that DLL's programs has it; the shaders stage translates again by itself when the translator changed. A wave64 compute shader that still has it comes out in another form with `--wave64-emulate on` (12.4 s for this program on that driver), which that driver can crash on for other programs (#857) | -| `d3d12_texture_tiles` passes but prints `NOTE: native D3D12 broke the expectations at N of M checked reads, every read as CopyTiles would with linear offset 1 rounded down to 0 in both directions` (and the same at offset 3) | AMD's Windows D3D12 driver (RX 7900 XT, 26.11.2, `32.0.32029.2010`) runs `CopyTiles` at a byte-unaligned `BufferStartOffsetInBytes` as if the offset were rounded down to a multiple of 4, in both directions. That is inferred from the texel values; the D3D12 debug layer was not run. `CopyTiles` documents no alignment, WARP meets the test's expectations at every offset tried (1-8), and so does the layer, which stages such offsets through aligned scratch | Nothing: the note is harmless. The test still fails when a native run diverges in any other way, or at a 4-byte offset | +| `d3d12_texture_tiles` passes but prints `NOTE: native D3D12 broke the expectations at N of M checked reads, every read as CopyTiles would with linear offset X rounded down to Y in both directions` (Y is X rounded down to a multiple of 4; the test runs X = 1 and 3) | AMD's Windows D3D12 driver (RX 7900 XT, 26.11.2, `32.0.32029.2010`) runs `CopyTiles` at a byte-unaligned `BufferStartOffsetInBytes` as if the offset were rounded down to a multiple of 4, in both directions. That is inferred from the texel values; the D3D12 debug layer was not run. `CopyTiles` documents no alignment, WARP meets the test's expectations at every offset tried (1-8), and so does the layer, which stages such offsets through aligned scratch | Nothing: the note is harmless. The test still fails when a native run diverges in any other way, or at a 4-byte offset | ### Signed zero in a float storage image (SHADER-605) diff --git a/runtime/test/d3d12_texture_tiles_test.cpp b/runtime/test/d3d12_texture_tiles_test.cpp index 01a494ffba..c306706628 100644 --- a/runtime/test/d3d12_texture_tiles_test.cpp +++ b/runtime/test/d3d12_texture_tiles_test.cpp @@ -99,6 +99,7 @@ template bool for_each_checked(UINT width, UINT height, UINT64 tile_copy_offset, Visit&& visit) { for (UINT tile = 0; tile < tiles; ++tile) { const UINT first_y = (tile / 2) * tile_height, first_x = (tile % 2) * tile_width; + if (first_y >= height || first_x >= width) continue; // a texture smaller than the tile grid const UINT rows = std::min(tile_height, height - first_y), columns = std::min(tile_width, width - first_x); for (UINT y = 0; y < rows; ++y) { for (UINT x = 0; x < columns; ++x) { @@ -199,6 +200,9 @@ bool run(ID3D12Device& device, UINT width, UINT height, UINT64 tile_copy_offset, const D3D12_RANGE empty{0, 0}; void* mapped = nullptr; EXPECT(SUCCEEDED(upload->Map(0, &empty, &mapped))); + // modelled_readback() reads the bytes before the CopyTiles offset when it rounds the offset down: zero them + // explicitly rather than rely on a committed resource starting zeroed. + std::memset(mapped, 0, static_cast(tile_copy_offset)); fill_tiles(static_cast(mapped) + tile_copy_offset); upload->Unmap(0, nullptr); @@ -306,10 +310,13 @@ bool run(ID3D12Device& device, UINT width, UINT height, UINT64 tile_copy_offset, const auto modelled = load(advisory->model->data(), offset); ++advisory->texels; advisory->differ += actual != expected; - if (actual != modelled && !advisory->unmodelled++) - std::snprintf(advisory->first_unmodelled, sizeof(advisory->first_unmodelled), - "%s tile %u at (%u,%u): got %#x, expected %#x, modelled %#x", read, tile, x, y, actual, - expected, modelled); + if (actual != modelled) { + if (advisory->unmodelled == 0) + std::snprintf(advisory->first_unmodelled, sizeof(advisory->first_unmodelled), + "%s tile %u at (%u,%u): got %#x, expected %#x, modelled %#x", read, tile, x, y, + actual, expected, modelled); + ++advisory->unmodelled; + } } else if (actual != expected) { std::fprintf(stderr, "%s tile %u at (%u,%u): got %#x, expected %#x\n", read, tile, x, y, actual, expected); return false; From 83aea690ae03c00c898ee34271332652cf9606bb Mon Sep 17 00:00:00 2001 From: adrianmjim <11887815+adrianmjim@users.noreply.github.com> Date: Tue, 24 Nov 2026 21:42:12 +0100 Subject: [PATCH 3/3] test: texture tiles also accepts Intel's readback-only CopyTiles rounding (D3D-TILES-AMD-BYTE-OFFSET) An Intel Iris Xe host (Intel 32.0.101.7092, Windows 11 26100) still failed d3d12_texture_tiles at linear offset 1: 94208 of 245760 checked reads broke the expectations, and 155648 differed from the AMD model. Measured there, that driver rounds BufferStartOffsetInBytes down to a multiple of 4 only when CopyTiles writes the buffer (tiles to buffer); the upload (buffer to tiles) honours the offset. modelled_readback() now takes the upload and the readback offsets separately, and a native run at a byte-unaligned offset is a NOTE when every checked read matches one of two measured models: rounded in both directions (AMD) or only in the tiles-to-buffer copies (Intel). The NOTE names the model that matched, and every diverging case on a device must match the same model, or the test fails. Anything else still fails too, and the failure prints how many reads each model leaves unexplained, with the first one. 4-byte offsets stay strict, and the layer is still held to the expectations. docs/testing.md and docs/d3d12_vulkan.md describe the Intel pattern, measured on that host in #964. On the AMD Radeon RX 7900 XT (32.0.32029.2010) the test still passes with the both-directions NOTE (4 runs, one with LEONIDA_VK_VALIDATION=1). A temporary local probe (not committed) checked the models against each other: the readback-only model breaks the expectations at 94208 of 245760 reads at offset 1 and 84480 of 222720 at offset 3, and differs from the both-directions model at 155648 reads at offset 1, the counts measured on the Iris Xe. On the AMD GPU it leaves 155648 and 138240 reads unexplained, so the two models do not overlap, and an upload-only model or one rounding to a multiple of 2 fails there too. A probe that pretended an earlier case had matched the Intel model made the AMD run fail on the model mismatch, as intended. Full ctest (-j 6): d3d12_texture_tiles passes; the other failures are the four main already has on this GPU, plus xmem once (its working-set charge check, under parallel load; it passed 3 of 3 runs alone, and this change does not touch it). Not run on Intel here. --- docs/d3d12_vulkan.md | 14 ++-- docs/testing.md | 2 +- runtime/test/d3d12_texture_tiles_test.cpp | 98 ++++++++++++++++------- 3 files changed, 76 insertions(+), 38 deletions(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 77847f05b5..fedba2a49b 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -2451,12 +2451,14 @@ The trace will enumerate them. `d3d12_texture_tiles_test` compares initially unmapped tiles, column mappings, aliases, and a fence-delayed remap with native D3D12, including clipped edges at 4-byte and byte-unaligned offsets. `CopyTiles` documents no alignment for `BufferStartOffsetInBytes`; at a byte-unaligned offset WARP also runs, to confirm the test's - expectations (it meets them at every offset tried, 1-8), and the layer is held to them. AMD's Windows D3D12 - driver (RX 7900 XT, 26.11.2) does not: judging by the texel values (the D3D12 debug layer was not run), it - moves whole tiles as if the offset were rounded down to a multiple of 4, in both directions, so a row-major - copy finds each texel 1-3 bytes early and texels that straddle a tile seam differ in the `CopyTiles` reads. The - test prints a note when a native run matches that rounded-down model at every texel, and fails on any other - divergence ([testing.md](testing.md#known-problems)). + expectations (it meets them at every offset tried, 1-8), and the layer is held to them. Two Windows D3D12 + drivers measured so far do not. Judging by the texel values (the D3D12 debug layer was not run), they move + whole tiles as if the offset were rounded down to a multiple of 4. AMD's (RX 7900 XT, 26.11.2) does so in both + directions, so a row-major copy finds each texel 1-3 bytes early and texels that straddle a tile seam differ in + the `CopyTiles` reads. Intel's (Iris Xe, 32.0.101.7092, measured on that host in #964) does so only in the + tiles-to-buffer copies, so the row-major copy matches and the `CopyTiles` reads of every nonzero texel differ. + The test prints a note when every checked read of a native run matches one of those two models, the same one + for every case on the device, and fails on any other divergence ([testing.md](testing.md#known-problems)). - `D3D12_RESOURCE_DESC::Layout`: the public `ROW_MAJOR` and `64KB_STANDARD_SWIZZLE` values plus the Xbox `0x101` tiled value from slot 76. Row-major textures need `VK_IMAGE_TILING_LINEAR` (not usable for RT/DS) or a staging copy; `64KB_STANDARD_SWIZZLE` and `0x101` have no direct Vulkan equivalent. If the game uploads console-tiled data, diff --git a/docs/testing.md b/docs/testing.md index 08d4733762..b6930804c5 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -665,7 +665,7 @@ game's device ignores it`, so leaving them set cannot slow a game down (`run_tin | With `--wave64-emulate` (or `LEONIDA_W64_EMULATE=1`) on an NVIDIA RTX 5080 with Windows driver 32.0.16.1692 (616.92), `crosslane_fuzz.py --seed 91001 --dpp --no-maskdata` reports a hard mismatch for `cs_xl64_9100373886`: after `s_xor_b64 s[16:17], vcc, vcc` (0 in every lane), the second of two nested `v_cndmask_b32_e64 … s[16:17]` returns the old register instead of the lane id | An NVIDIA driver miscompile, not the translator (SHADER-720). The same SPIR-V (spirv-val clean) matches the model on an RTX 3060 with 616.64, an RTX 5060 Ti (Blackwell) with 621.14, an RTX 5070 Ti with 621.24 and an RTX 5080 with the Linux 580.65.06 driver. Hand edits narrow it to a value selected through the `%active` gate of a store; on the Linux 580 driver a similar pattern, a subgroup shuffle selected by an `%active` that is false, still fails in three wave32 `v_permlane16`/`v_permlanex16` programs of the same seed (#3796, #3918) | Update the NVIDIA driver to 621.14 or newer on Windows. If a crosslane mismatch only shows on one driver, check another driver or GPU before changing the translator | | `lds_fuzz.py --wave 64` (native, not `--emulate`) reports a `ds_bpermute_b32` mismatch on an AMD GPU on Windows, e.g. `cs_ldsfuzz_s7031_496_w64` (seed 7031): small values like `0x14` where the model wants another lane's data, while `--oracle hw` and `--emulate` on another GPU agree with the model | The AMD Windows driver (32.0.21042.62, gfx1036) miscompiles a native wave64 compute shader with two subgroup shuffles; a reduced SPIR-V module is in #4613 | Not a translator regression: check the same seed with `--oracle hw` and with `--emulate`. Native wave64 results on that driver need that cross-check | | On AMD's Windows driver a compute pipeline creation takes tens of minutes: `vk_pipeline_check` prints `still compiling after ...s` with one busy thread, or a compute PSO creation through the D3D12 layer seems never to return | The driver's compiler on one module in the dispatch-loop form (`"control_flow": "dispatch loop"` in the translated `index.json`). Measured on a Radeon gfx1036 iGPU, driver 32.0.21042.62 (SHADER-995): `XboxBvhBuilder.dll`'s `LeafRehydration` in that form (a 581-case switch in a loop) was created after 34 minutes of one busy thread (XXTESTING), while its structured module is created in 2.9 s and an RTX 3070 (NVIDIA 610.74) created the dispatch-loop one in 11 s. It is not every such module: ten other programs of that DLL compile in that form on the Radeon in 0.4 to 40 s ([embedded_shaders.md](embedded_shaders.md), section 7). Not tried on another AMD GPU or driver branch | Translate with current `main`. Since SHADER-427 only a tree nested deeper than 64, a graph that cannot be made reducible or `--dispatch-loop` gives that form, and none of that DLL's programs has it; the shaders stage translates again by itself when the translator changed. A wave64 compute shader that still has it comes out in another form with `--wave64-emulate on` (12.4 s for this program on that driver), which that driver can crash on for other programs (#857) | -| `d3d12_texture_tiles` passes but prints `NOTE: native D3D12 broke the expectations at N of M checked reads, every read as CopyTiles would with linear offset X rounded down to Y in both directions` (Y is X rounded down to a multiple of 4; the test runs X = 1 and 3) | AMD's Windows D3D12 driver (RX 7900 XT, 26.11.2, `32.0.32029.2010`) runs `CopyTiles` at a byte-unaligned `BufferStartOffsetInBytes` as if the offset were rounded down to a multiple of 4, in both directions. That is inferred from the texel values; the D3D12 debug layer was not run. `CopyTiles` documents no alignment, WARP meets the test's expectations at every offset tried (1-8), and so does the layer, which stages such offsets through aligned scratch | Nothing: the note is harmless. The test still fails when a native run diverges in any other way, or at a 4-byte offset | +| `d3d12_texture_tiles` passes but prints `NOTE: native D3D12 broke the expectations at N of M checked reads, every read as CopyTiles would with linear offset X rounded down to Y in both directions` (or `only in the tiles-to-buffer copies`; Y is X rounded down to a multiple of 4; the test runs X = 1 and 3) | Two Windows D3D12 drivers measured so far run `CopyTiles` at a byte-unaligned `BufferStartOffsetInBytes` as if the offset were rounded down to a multiple of 4: AMD's (RX 7900 XT, 26.11.2, `32.0.32029.2010`) in both directions, Intel's (Iris Xe, `32.0.101.7092`, measured on that host in #964) only in the tiles-to-buffer copies. That is inferred from the texel values; the D3D12 debug layer was not run. A device whose cases match different models fails. `CopyTiles` documents no alignment, WARP meets the test's expectations at every offset tried (1-8), and so does the layer, which stages such offsets through aligned scratch | Nothing: the note is harmless. The test still fails when a native run diverges in any other way, or at a 4-byte offset | ### Signed zero in a float storage image (SHADER-605) diff --git a/runtime/test/d3d12_texture_tiles_test.cpp b/runtime/test/d3d12_texture_tiles_test.cpp index c306706628..cd8a71dc97 100644 --- a/runtime/test/d3d12_texture_tiles_test.cpp +++ b/runtime/test/d3d12_texture_tiles_test.cpp @@ -123,9 +123,11 @@ bool for_each_checked(UINT width, UINT height, UINT64 tile_copy_offset, Visit&& } // The readback buffer run() leaves if every CopyTiles moves whole 64 KiB tiles (clipped texels too) with its linear -// offset taken as `linear`, in both directions. `linear` == tile_copy_offset gives the D3D12 rules (main() checks -// that against the expectations above); tile_copy_offset & ~3 gives the AMD pattern described in main(). -std::vector modelled_readback(UINT width, UINT height, UINT64 tile_copy_offset, UINT64 linear) { +// offset taken as `upload_linear` when it reads the buffer (to_tiled) and as `readback_linear` when it writes it +// (to_linear). Both == tile_copy_offset gives the D3D12 rules (main() checks that against the expectations above); +// the driver patterns described in main() round one or both down to a multiple of 4. +std::vector modelled_readback(UINT width, UINT height, UINT64 tile_copy_offset, UINT64 upload_linear, + UINT64 readback_linear) { std::vector upload(tile_copy_offset + image_bytes), heap(image_bytes), readback(row_major_offset + image_bytes); fill_tiles(upload.data() + tile_copy_offset); @@ -134,10 +136,10 @@ std::vector modelled_readback(UINT width, UINT height, UINT64 tile constexpr UINT a_heap_tile[tiles] = {0, 2, 1, 3}; const auto b_tile = [&](UINT tile) { return heap.data() + a_heap_tile[tile ^ 1] * tile_bytes; }; for (UINT tile = 0; tile < tiles; ++tile) - std::memcpy(heap.data() + a_heap_tile[tile] * tile_bytes, upload.data() + linear + tile * tile_bytes, + std::memcpy(heap.data() + a_heap_tile[tile] * tile_bytes, upload.data() + upload_linear + tile * tile_bytes, tile_bytes); for (UINT tile = 0; tile < tiles; ++tile) - std::memcpy(readback.data() + linear + image_bytes + tile * tile_bytes, b_tile(tile), tile_bytes); + std::memcpy(readback.data() + readback_linear + image_bytes + tile * tile_bytes, b_tile(tile), tile_bytes); for (UINT y = 0; y < height; ++y) // CopyTextureRegion, at an aligned footprint for (UINT x = 0; x < width; ++x) std::memcpy(readback.data() + row_major_offset + (y * full_width + x) * sizeof(std::uint32_t), @@ -147,15 +149,16 @@ std::vector modelled_readback(UINT width, UINT height, UINT64 tile // The gated remap: b's top row reuses heap tile 0 (a's first tile), its bottom row is unmapped (zeros). for (UINT tile = 0; tile < tiles; ++tile) if (tile < 2) - std::memcpy(readback.data() + linear + 2 * image_bytes + tile * tile_bytes, heap.data(), tile_bytes); + std::memcpy(readback.data() + readback_linear + 2 * image_bytes + tile * tile_bytes, heap.data(), + tile_bytes); else - std::memset(readback.data() + linear + 2 * image_bytes + tile * tile_bytes, 0, tile_bytes); + std::memset(readback.data() + readback_linear + 2 * image_bytes + tile * tile_bytes, 0, tile_bytes); return readback; } // The model with the true offset must reproduce the expectations, or it cannot judge a native divergence. bool model_matches_rules(UINT width, UINT height, UINT64 tile_copy_offset) { - const auto model = modelled_readback(width, height, tile_copy_offset, tile_copy_offset); + const auto model = modelled_readback(width, height, tile_copy_offset, tile_copy_offset, tile_copy_offset); return for_each_checked(width, height, tile_copy_offset, [&](const char* read, UINT tile, UINT x, UINT y, UINT64 offset, std::uint32_t expected) { if (load(model.data(), offset) == expected) return true; @@ -164,12 +167,19 @@ bool model_matches_rules(UINT width, UINT height, UINT64 tile_copy_offset) { }); } +// One measured driver pattern: the readback modelled_readback gives for it, and how many checked reads differ from it. +struct DriverModel { + const char* rounding; // which CopyTiles round the offset down, as the NOTE names it + std::vector readback; + std::uint64_t unmodelled = 0; + char first_unmodelled[160] = {}; +}; + // A native run at a byte-unaligned offset reads every texel quietly instead of stopping at the first that breaks the -// D3D12 rules: how many do, and how many differ from `model` (the readback modelled_readback gives). +// D3D12 rules: how many do, and how many differ from each driver model. struct Advisory { - const std::vector* model = nullptr; - std::uint64_t texels = 0, differ = 0, unmodelled = 0; - char first_unmodelled[160] = {}; + std::vector models; + std::uint64_t texels = 0, differ = 0; }; // False when a call fails, or (unless `advisory`) a texel breaks the D3D12 rules. @@ -307,15 +317,16 @@ bool run(ID3D12Device& device, UINT width, UINT height, UINT64 tile_copy_offset, const auto judge = [&](const char* read, UINT tile, UINT x, UINT y, UINT64 offset, std::uint32_t expected) { const auto actual = load(bytes, offset); if (advisory) { - const auto modelled = load(advisory->model->data(), offset); ++advisory->texels; advisory->differ += actual != expected; - if (actual != modelled) { - if (advisory->unmodelled == 0) - std::snprintf(advisory->first_unmodelled, sizeof(advisory->first_unmodelled), + for (auto& model : advisory->models) { + const auto modelled = load(model.readback.data(), offset); + if (actual == modelled) continue; + if (model.unmodelled == 0) + std::snprintf(model.first_unmodelled, sizeof(model.first_unmodelled), "%s tile %u at (%u,%u): got %#x, expected %#x, modelled %#x", read, tile, x, y, actual, expected, modelled); - ++advisory->unmodelled; + ++model.unmodelled; } } else if (actual != expected) { std::fprintf(stderr, "%s tile %u at (%u,%u): got %#x, expected %#x\n", read, tile, x, y, actual, expected); @@ -388,11 +399,15 @@ int main() { auto native = native_device(); // Byte-unaligned CopyTiles offsets. CopyTiles documents no alignment for BufferStartOffsetInBytes, and WARP meets // the expectations at every offset tried (1-8), so at such an offset WARP runs too, to confirm them; the layer is - // held to the expectations. AMD's Windows D3D12 driver (RX 7900 XT, 26.11.2) does not meet them: judging by the - // texel values (the D3D12 debug layer was not run), it moves the tiles as if the offset were rounded down to a - // multiple of 4, in both directions. The row-major copy then finds each texel 1-3 bytes early, and texels that - // straddle a tile seam differ in the CopyTiles reads too. Such a native run is a NOTE only when every texel - // matches that rounded-down model (modelled_readback); any other divergence fails, and so does any texel at a + // held to the expectations. Two Windows drivers measured so far do not meet them. Judging by the texel values + // (the D3D12 debug layer was not run), they move the tiles as if the offset were rounded down to a multiple of 4: + // - AMD (RX 7900 XT, 26.11.2) in both directions. The row-major copy then finds each texel 1-3 bytes early, and + // texels that straddle a tile seam differ in the CopyTiles reads too. + // - Intel (Iris Xe, 32.0.101.7092, measured on that host in pull request #964) only in the tiles-to-buffer + // copies: the upload honours the offset, so the row-major copy matches and the CopyTiles reads of every + // nonzero texel differ. + // Such a native run is a NOTE only when every checked read matches one of those two models (modelled_readback), + // and every case on the device matches the same one; any other divergence fails, and so does any texel at a // 4-byte offset. const auto warp = warp_device(); const auto* info = rt::d3d12::vulkan_device_info(vulkan.Get()); @@ -406,6 +421,7 @@ int main() { ReplayCase{240, 240, 4, false}, ReplayCase{256, 240, 1, false}, ReplayCase{240, 240, 3, false}, ReplayCase{256, 256, 4, true}}; if (!dedicated_copy) std::puts("No separate Vulkan copy family for the cross-family case"); + const char* device_rounding = nullptr; // the model the first diverging native case matched for (const auto& [width, height, linear_offset, separate_copy_queue] : cases) { if (separate_copy_queue && !dedicated_copy) continue; bool sparse = false; @@ -426,11 +442,13 @@ int main() { if (byte_offset && !model_matches_rules(width, height, linear_offset)) return 1; if (native) { const UINT rounded_offset = linear_offset & ~3u; - std::vector rounded; Advisory advisory; if (byte_offset) { - rounded = modelled_readback(width, height, linear_offset, rounded_offset); - advisory.model = &rounded; + advisory.models.push_back({"in both directions", modelled_readback(width, height, linear_offset, + rounded_offset, rounded_offset)}); + advisory.models.push_back({"only in the tiles-to-buffer copies", + modelled_readback(width, height, linear_offset, linear_offset, + rounded_offset)}); } if (!run(*native.Get(), width, height, linear_offset, expected, false, separate_copy_queue, sparse, byte_offset ? &advisory : nullptr) || @@ -438,20 +456,38 @@ int main() { std::fprintf(stderr, "Native D3D12 failed: %u x %u, linear offset %u\n", width, height, linear_offset); return 1; } + const DriverModel* fit = nullptr; + for (const auto& model : advisory.models) + if (!model.unmodelled) { + fit = &model; + break; + } if (!advisory.differ) { std::printf("Native D3D12 matched all %zu verified pixels\n", observed.size()); - } else if (!advisory.unmodelled) { + } else if (fit) { + if (device_rounding && std::strcmp(device_rounding, fit->rounding) != 0) { + std::fprintf(stderr, "Native D3D12 failed: %u x %u, linear offset %u matches the offset rounded " + "down %s, but an earlier case matched it rounded down %s\n", width, height, + linear_offset, fit->rounding, device_rounding); + return 1; + } std::printf("NOTE: native D3D12 broke the expectations at %llu of %llu checked reads, every read as " - "CopyTiles would with linear offset %u rounded down to %u in both directions " + "CopyTiles would with linear offset %u rounded down to %u %s " "(docs/testing.md, Known problems); not a failure\n", static_cast(advisory.differ), - static_cast(advisory.texels), linear_offset, rounded_offset); + static_cast(advisory.texels), linear_offset, rounded_offset, + fit->rounding); + device_rounding = fit->rounding; } else { std::fprintf(stderr, "Native D3D12 failed: %u x %u, linear offset %u: %llu of %llu checked reads " - "break the expectations, and %llu differ from the rounded-down model; first: %s\n", + "break the expectations\n", width, height, linear_offset, static_cast(advisory.differ), - static_cast(advisory.texels), - static_cast(advisory.unmodelled), advisory.first_unmodelled); + static_cast(advisory.texels)); + for (const auto& model : advisory.models) + std::fprintf(stderr, " %llu differ from the model with the offset rounded down to %u %s; " + "first: %s\n", + static_cast(model.unmodelled), rounded_offset, model.rounding, + model.first_unmodelled); return 1; } }