From ef4ee2e843bb932d6f107447f981c76a62712304 Mon Sep 17 00:00:00 2001 From: lewisalex86 Date: Thu, 26 Nov 2026 15:17:17 +0000 Subject: [PATCH 1/2] startup: read single-mip 0x105 volumes in slot 70 A Texture3D description in the 4 KiB standard layout with one mip and an uncompressed format is now detiled from its thick blocks (GFX10_SW_4K_S3_PATINFO rows) instead of refused. The XG-size hold counts a volume as one slice, since its footprints already span every depth layer. --- docs/experiments.md | 31 +++ docs/startup-runtime.md | 20 +- src/startup_stubs/d3d12_draw.inl | 5 +- src/startup_stubs/d3d12_memory_srv.inl | 6 +- src/startup_stubs/gfx10_layout.h | 107 ++++++-- tests/cmake/startup_gfx10_volume.cmake | 18 ++ tests/startup_address_console_check.py | 121 ++++++++- tests/startup_address_srv.cpp | 25 +- tests/startup_gfx10_volume_check.cpp | 362 +++++++++++++++++++++++++ 9 files changed, 659 insertions(+), 36 deletions(-) create mode 100644 tests/cmake/startup_gfx10_volume.cmake create mode 100644 tests/startup_gfx10_volume_check.cpp diff --git a/docs/experiments.md b/docs/experiments.md index 1fe79025ee..2fc009815d 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -16347,6 +16347,37 @@ ctest --preset release --no-tests=error --output-on-failure -R '^startup_gfx10_l ctest --preset release --no-tests=error --output-on-failure -j 1 -R '^startup_address_(console|console_gate|console_gate_ring|bc_view|srv)_(hardware|warp)$' ``` +#### Volumes in the 4 KiB standard layout + +Slot 70 also reads a single-mip, uncompressed 3D texture whose layout is `0x105`. addrlib lays it +out in thick 4 KiB blocks (`GFX10_SW_4K_S3_PATINFO`). `startup_gfx10_volume` needs no device. It +checks the address bit of every x, y and z bit against the restated one-pipe rows for the five element +sizes, the block sizes, and the order of blocks in a 17 by 17 by 17 RGBA8 volume. It also checks that +the elements of ten volumes (odd sides included) have their own bytes, that they tile and detile back +to their rows, 15 layouts on either side of the accepted set, six slot 70 descriptions and seven +views. `startup_gfx10_volume_thin_control` lays each volume out as a thin 2D array of its layers and +must fail. `startup_gfx10_volume_addrlib` compares the size and every element address of 190 volumes +(276,885 addresses) with `Addr2ComputeSurfaceInfo` and `Addr2ComputeSurfaceAddrFromCoord` +(`ADDR_RSRC_TEX_3D`, `ADDR_SW_4KB_S`) on the Navi21 configuration the other addrlib checks use; it +skips (77) when the build has no addrlib (`-DXBOX2WINDOWS_ADDRLIB_DIR`). + +`startup_address_console_{warp,hardware}` now also draws two volumes, RGBA8 17 by 17 by 17 and 33 by +9 by 18, whose backing it builds in Python from the same S3 row. Each target tile of the volume's +width and height loads one depth layer, and every layer must appear. All 65,536 pixels must match. +A third volume, RGBA8 64 by 8 by 40, takes 163,840 bytes in the layout, but its desktop footprint +rounded to 64 KiB is only 131,072. It must be held as `console_layout_beyond_xg_size`. Before this +change the hold counted that footprint once for each of the 40 layers, and the volume would have been +published. + +Two local mutations were run once and are not registered tests: the layer pitch of the upload set +to zero, and the hold counting one footprint per layer. Each fails `startup_address_console_warp`: +the first on the first volume's pixels, the second on the held volume. + +```powershell +ctest --preset release --no-tests=error --output-on-failure -R '^startup_gfx10_volume' +ctest --preset release --no-tests=error --output-on-failure -j 1 -R '^startup_address_console_(hardware|warp)$' +``` + ### Six BC5/BC7 mips on a 64 KiB standard layout `startup_xg_bc_chain_{warp,hardware}` uses a source-built 1024×1024 BC5_UNORM or BC7_UNORM texture with six mip levels, one slice, one sample, explicit layout `0x109` (64 KiB standard, no XOR), default alignment and zero flags. The guest chain occupies `0x160000` bytes. The six offsets starting at mip 0 are `0x60000, 0x20000, 0x10000, 0x8000, 0x4000, 0x2000`. The three smallest mips share tile zero. These offsets and all 87,360 visible block addresses were checked with `Addr2ComputeSurfaceInfo` and `Addr2ComputeSurfaceAddrFromCoord` on the pinned Navi21 configuration. [AMD addrlib revision](https://gitlab.freedesktop.org/mesa/mesa/-/tree/5c142e46f3f6e752ed745fd48912ebb8fad67145/src/amd/addrlib) · [XCL comparison](https://github.com/ivall/xcl/blob/64b3f35599bb7102f55d640e1a791e7d6dd3b175/crates/xcl/src/gpu/tiling.rs) diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index dcad1222ea..79fa84dd1d 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -3285,9 +3285,18 @@ after AMD addrlib, Mesa 25.1.0, `src/amd/addrlib`, MIT). A 256 B layout is taken The description must be two-dimensional, at most 16384 texels a side, with 1 to 15 mips, one sample, no target, depth or unordered-access flag, and a format with a known element size (8- to 128-bit texels and BC1 to BC7, whose largest mip must then be whole 4x4 blocks). The view must use a supported typed format that matches the storage format or belongs to its typeless parent. The 2D or 2D-array view must fit the mip and slice ranges. A mismatched or interior view overlapping a live resource preserves the destination descriptor. + +A three-dimensional description is taken in one layout only: `0x105` (4 KiB standard), one mip, one +sample, at most 2048 texels on each side and an uncompressed format with a known element size, +viewed as a Texture3D. addrlib lays a 3D resource in a standard or display mode out in thick blocks +(`Gfx10Lib::HwlIsThick`): the 12 address bits of a block follow the one-pipe rows of +`GFX10_SW_4K_S3_PATINFO`, the block is 16x16x16, 8x16x16, 8x16x8, 8x8x8 or 4x8x8 elements for 1- to +16-byte elements, and blocks follow along x, then y, then a layer of blocks at a time along z, with +every side padded to whole blocks. Each depth layer is copied to its own footprint rows. Anything else is refused as before and leaves the destination descriptor unchanged: layout `0` and -the linear mode `0x100` without a live texture, three-dimensional and cube views, multisampled -textures, the XOR swizzle modes and every other layout value. The texels must be readable and span +the linear mode `0x100` without a live texture, cube views, three-dimensional descriptions in any +other layout, with a mip chain or with a block-compressed format, multisampled textures, the XOR +swizzle modes and every other layout value. The texels must be readable and span at most 64 MiB. A console-layout description is held (not published, descriptor unchanged) in the two cases a @@ -3296,7 +3305,7 @@ for the address wrote desktop-footprint rows, so the bytes are not in the layout names. As for a partial-tile view, a texture already published there samples the null view while that is so. `console_layout_beyond_xg_size`: the layout runs past the size the XG stand-in reports for the description (the desktop copyable footprints of a slice rounded up to 64 KiB, times the -slices), which the title may not own. +slices; a volume is one slice, whose footprints span every depth layer), which the title may not own. Upload lifetime: each upload of a console-layout texture is written into an upload buffer of its own (`x2w_upload::make_page`), not into the shared upload ring. The recording keeps a reference to the @@ -3326,6 +3335,9 @@ Limits and choices that are not measured against a console: elements are checked only against the addrlib pattern rows restated from the addrlib source text in `startup_gfx10_layout_check.cpp` (all five element sizes) and in the Python oracle of `startup_address_console_check.py` (4- and 8-byte elements), both written from the same source. +- The thick `0x105` volume layout is compared with addrlib itself when the build has it + (`startup_gfx10_volume_addrlib`: every element address of 190 volumes). Mip chains, block-compressed + volumes and volumes in the other modes are not handled; they stay refused. Log lines (stderr and `X2W_TRAP_LOG`): @@ -3340,7 +3352,7 @@ Log lines (stderr and `X2W_TRAP_LOG`): Checks (reproduction in `docs/experiments.md`, "Sample by-address textures of the non-XOR console layouts"): -- `ctest --preset release --no-tests=error -R '^startup_gfx10_layout' -V` +- `ctest --preset release --no-tests=error -R '^startup_gfx10_(layout|volume)' -V` - `ctest --preset release --no-tests=error -j 1 -R '^startup_address_console_' -V` ## Linear buffer backing (device slot 133, opt-in) diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index a67724e605..df4d8e7bbf 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -1372,6 +1372,7 @@ bool upload_texture(Wrapper* self, Wrapper* resource, ID3D12Resource* texture) if (console_layout->mips != mips || console_layout->slices != slices || plan.count != mips) return false; for (UINT i = 0; i < mips; ++i) if (!plan.bytes(i) || plan.rows[i] != console_layout->rows(i) || + plan.placed[i].Footprint.Depth != console_layout->layers(i) || plan.row_bytes[i] != u64{console_layout->columns(i)} * console_layout->bytes_per_element) return false; } // A texture given the 4 KiB allocation answer is read in the compact plan XG describes and writes for it @@ -1443,7 +1444,9 @@ bool upload_texture(Wrapper* self, Wrapper* resource, ID3D12Resource* texture) } std::memset(rows, 0, static_cast(bytes)); } - console_layout->detile(i, slice, memory, rows, plan.placed[i].Footprint.RowPitch); + // The depth layers of a volume follow one another, rows[i] rows apart. + console_layout->detile(i, slice, memory, rows, plan.placed[i].Footprint.RowPitch, + std::size_t{plan.placed[i].Footprint.RowPitch} * plan.rows[i]); plan.upload(list, texture, owned.cpu ? owned.resource.Get() : chunk, mips, slices, slice, i, offset); } } diff --git a/src/startup_stubs/d3d12_memory_srv.inl b/src/startup_stubs/d3d12_memory_srv.inl index 1252190e86..0d057ac6a3 100644 --- a/src/startup_stubs/d3d12_memory_srv.inl +++ b/src/startup_stubs/d3d12_memory_srv.inl @@ -513,13 +513,15 @@ u64 address_texture_bytes(Wrapper* device, const D3D12_RESOURCE_DESC& desc) // copy records a tiled write; the 0x109 BC chains, which XG writes in their layout, keep their own // path and never come through here); // - the layout runs past the size the XG stand-in reports for the description (the desktop copyable -// footprints of a slice rounded up to 64 KiB, times the slices), which the title may not own. +// footprints of a slice rounded up to 64 KiB, times the slices), which the title may not own. A volume +// has one slice: its footprints already span every depth layer. const char* console_address_hold(Wrapper* device, u64 address, const D3D12_RESOURCE_DESC& desc) { if (latest_texture_write_is_rows(address)) return "console_layout_xg_rows"; const x2w_startup::SliceFootprints plan(device_of(device), sanitized(desc), desc.MipLevels); if (plan.size == UINT64_MAX || !plan.size) return "console_layout_without_footprints"; - const u64 reported = ((plan.size + 0xFFFF) & ~u64{0xFFFF}) * desc.DepthOrArraySize; + const u64 slices = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? 1 : desc.DepthOrArraySize; + const u64 reported = ((plan.size + 0xFFFF) & ~u64{0xFFFF}) * slices; return x2w_startup::gfx10::Layout(desc).bytes() > reported ? "console_layout_beyond_xg_size" : nullptr; } diff --git a/src/startup_stubs/gfx10_layout.h b/src/startup_stubs/gfx10_layout.h index 87deac0414..a81d52b7cf 100644 --- a/src/startup_stubs/gfx10_layout.h +++ b/src/startup_stubs/gfx10_layout.h @@ -65,9 +65,21 @@ inline UINT block_log2(UINT mode) } } -// A two-dimensional, single-sample texture whose memory this header can address. +// A three-dimensional texture in the 4 KiB standard mode (0x105), which addrlib lays out in thick blocks +// (Gfx10Lib::HwlIsThick: a 3D resource in a standard or display mode): one mip of uncompressed texels. +inline bool supports_volume(const D3D12_RESOURCE_DESC& d) +{ + const Element element = element_of(d.Format); + return d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D && swizzle_mode(d) == 5 && element.bytes && element.texels == 1 && + d.Width && d.Height && d.DepthOrArraySize && d.Width <= 2048 && d.Height <= 2048 && d.DepthOrArraySize <= 2048 && + d.MipLevels == 1 && d.SampleDesc.Count == 1; +} + +// A two-dimensional, single-sample texture whose memory this header can address, or a volume +// supports_volume takes. inline bool supports(const D3D12_RESOURCE_DESC& d) { + if (d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D) return supports_volume(d); const UINT log2 = block_log2(swizzle_mode(d)); if (!log2 || d.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || !element_of(d.Format).bytes) return false; if (!d.Width || !d.Height || d.Width > 16384 || d.Height > 16384 || !d.DepthOrArraySize) return false; @@ -83,6 +95,11 @@ struct Layout { std::array start{}; // byte offset of a mip in its slice std::array blocks_wide{}, origin_x{}, origin_y{}; std::array x_bits{}, y_bits{}; // in-block byte offset contributed by a coordinate + // A volume (supports_volume): its depth, the depth of a thick block, the in-block offset contributed by z, + // and the bytes of one layer of blocks. Its one slice holds every depth layer; a 2D texture keeps 1, 1, 0. + UINT depth = 1, block_depth = 1, blocks_high = 0; + std::array z_bits{}; + std::uint64_t layer_size = 0; explicit Layout(const D3D12_RESOURCE_DESC& d) : width(static_cast(d.Width)), height(d.Height), mips(d.MipLevels), slices(d.DepthOrArraySize) @@ -90,6 +107,10 @@ struct Layout { const Element element = element_of(d.Format); bytes_per_element = element.bytes; texels = element.texels; + if (d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D) { + thick(d); + return; + } const UINT mode = swizzle_mode(d), log2 = block_log2(mode); UINT element_log2 = 0; while ((1u << element_log2) < bytes_per_element) ++element_log2; @@ -164,37 +185,91 @@ struct Layout { } } + // A volume in the 4 KiB standard mode, one mip (supports_volume). The 12 address bits of a thick block + // follow the one-pipe rows of GFX10_SW_4K_S3_PATINFO (nibble01 rows 29-33, nibble2 rows 131-135), by + // element size; "0" is a bit inside the element. The block is 2^n texels on each axis, n counting that + // axis in the row (addrlib ComputeThickBlockDimension: Block1K_3d scaled to 4 KiB). Blocks follow in x, + // then y, then z, a layer of pitch x height blocks at a time (Gfx10Lib::ComputeSurfaceAddrFromCoord- + // MacroTiled for a thick, single-mip surface: the slice size times the block depth per layer). + void thick(const D3D12_RESOURCE_DESC& d) + { + static constexpr const char* rows4k[5] = { + "X0X1Z0Y0Z1Y1X2Z2Y2X3Z3Y3", "--X0Z0Y0Z1Y1X1Z2Y2X2Z3Y3", "----X0Y0Z0Y1X1Z1Y2X2Z2Y3", + "------X0Z0Y0X1Z1Y1X2Z2Y2", "--------Z0Y0X0Z1Y1X1Z2Y2"}; + UINT element_log2 = 0; + while ((1u << element_log2) < bytes_per_element) ++element_log2; + depth = slices; + slices = 1; + block_bytes = 4096; + UINT xs = 0, ys = 0, zs = 0; + std::array x_at{}, y_at{}, z_at{}; + const char* pattern = rows4k[element_log2]; + for (UINT bit = 0; bit < 12; ++bit) { + const char axis = pattern[2 * bit]; + const UINT index = static_cast(pattern[2 * bit + 1] - '0'); + if (axis == 'X') x_at[index] = bit, xs = (std::max)(xs, index + 1); + if (axis == 'Y') y_at[index] = bit, ys = (std::max)(ys, index + 1); + if (axis == 'Z') z_at[index] = bit, zs = (std::max)(zs, index + 1); + } + block_width = 1u << xs; + block_height = 1u << ys; + block_depth = 1u << zs; + for (UINT v = 0; v < 256; ++v) + for (UINT bit = 0; bit < 8; ++bit) { + if (!((v >> bit) & 1)) continue; + if (bit < xs) x_bits[v] |= 1u << x_at[bit]; + if (bit < ys) y_bits[v] |= 1u << y_at[bit]; + if (bit < zs) z_bits[v] |= 1u << z_at[bit]; + } + first_tail = mips; + blocks_wide[0] = (width + block_width - 1) / block_width; + blocks_high = (height + block_height - 1) / block_height; + layer_size = std::uint64_t{blocks_wide[0]} * blocks_high * block_bytes; + slice_size = layer_size * ((depth + block_depth - 1) / block_depth); + } + // Elements a mip holds, with the desktop's mip sizes (rounded down, at least one texel). UINT columns(UINT mip) const { return ((std::max)(1u, width >> mip) + texels - 1) / texels; } UINT rows(UINT mip) const { return ((std::max)(1u, height >> mip) + texels - 1) / texels; } + UINT layers(UINT mip) const { return (std::max)(1u, depth >> mip); } std::uint64_t bytes() const { return slice_size * slices; } - // Byte offset of element (x, y) of a mip of a slice from the start of the texture. - std::uint64_t address(UINT mip, UINT x, UINT y, UINT slice) const + // Byte offset of element (x, y) of a mip of a slice from the start of the texture; z is the depth + // layer of a volume. + std::uint64_t address(UINT mip, UINT x, UINT y, UINT slice, UINT z = 0) const { + if (block_depth > 1) // a volume (thick) + return std::uint64_t{z / block_depth} * layer_size + + (std::uint64_t{y / block_height} * blocks_wide[0] + x / block_width) * block_bytes + + (x_bits[x % block_width] | y_bits[y % block_height] | z_bits[z % block_depth]); const std::uint64_t base = slice * slice_size; if (mip >= first_tail) return base + (x_bits[(origin_x[mip] + x) & 255] | y_bits[(origin_y[mip] + y) & 255]); const std::uint64_t block = std::uint64_t{y / block_height} * blocks_wide[mip] + x / block_width; return base + start[mip] + block * block_bytes + (x_bits[x % block_width] | y_bits[y % block_height]); } - // Copies one subresource from the console layout at `tiled` to rows `pitch` bytes apart at `linear`. - void detile(UINT mip, UINT slice, const unsigned char* tiled, unsigned char* linear, std::size_t pitch) const + // Copies one subresource from the console layout at `tiled` to rows `pitch` bytes apart at `linear`; + // the depth layers of a volume are `layer_pitch` bytes apart. + void detile(UINT mip, UINT slice, const unsigned char* tiled, unsigned char* linear, std::size_t pitch, + std::size_t layer_pitch = 0) const { - const UINT w = columns(mip), h = rows(mip); - for (UINT y = 0; y < h; ++y) - for (UINT x = 0; x < w; ++x) - std::memcpy(linear + y * pitch + std::size_t{x} * bytes_per_element, tiled + address(mip, x, y, slice), - bytes_per_element); + const UINT w = columns(mip), h = rows(mip), n = layers(mip); + for (UINT z = 0; z < n; ++z) + for (UINT y = 0; y < h; ++y) + for (UINT x = 0; x < w; ++x) + std::memcpy(linear + z * layer_pitch + y * pitch + std::size_t{x} * bytes_per_element, + tiled + address(mip, x, y, slice, z), bytes_per_element); } // The opposite copy, from rows into the console layout. - void tile(UINT mip, UINT slice, unsigned char* tiled, const unsigned char* linear, std::size_t pitch) const + void tile(UINT mip, UINT slice, unsigned char* tiled, const unsigned char* linear, std::size_t pitch, + std::size_t layer_pitch = 0) const { - const UINT w = columns(mip), h = rows(mip); - for (UINT y = 0; y < h; ++y) - for (UINT x = 0; x < w; ++x) - std::memcpy(tiled + address(mip, x, y, slice), linear + y * pitch + std::size_t{x} * bytes_per_element, - bytes_per_element); + const UINT w = columns(mip), h = rows(mip), n = layers(mip); + for (UINT z = 0; z < n; ++z) + for (UINT y = 0; y < h; ++y) + for (UINT x = 0; x < w; ++x) + std::memcpy(tiled + address(mip, x, y, slice, z), + linear + z * layer_pitch + y * pitch + std::size_t{x} * bytes_per_element, bytes_per_element); } }; } // namespace x2w_startup::gfx10 diff --git a/tests/cmake/startup_gfx10_volume.cmake b/tests/cmake/startup_gfx10_volume.cmake new file mode 100644 index 0000000000..2eff66639d --- /dev/null +++ b/tests/cmake/startup_gfx10_volume.cmake @@ -0,0 +1,18 @@ +# Volumes in the 4 KiB standard console layout (0x105, one mip; src/startup_stubs/gfx10_layout.h) and the +# slot-70 descriptions and views that use them (src/startup_stubs/address_texture.h), without a device: +# address equations against addrlib's GFX10_SW_4K_S3 rows (Mesa 25.1.0, src/amd/addrlib, MIT), block +# order, distinct addresses, round trips and refusals. The thin run lays each volume out as a 2D array of +# its layers and is the negative control; the addrlib run compares every element address with addrlib +# and skips (77) without it. +add_executable(startup_gfx10_volume_check tests/startup_gfx10_volume_check.cpp) +target_compile_features(startup_gfx10_volume_check PRIVATE cxx_std_17) +target_include_directories(startup_gfx10_volume_check PRIVATE src) +if(XBOX2WINDOWS_ADDRLIB_DIR) + target_link_libraries(startup_gfx10_volume_check PRIVATE xbw_addrlib) + target_compile_definitions(startup_gfx10_volume_check PRIVATE XBOX2WINDOWS_HAVE_ADDRLIB) +endif() +add_test(NAME startup_gfx10_volume COMMAND startup_gfx10_volume_check) +add_test(NAME startup_gfx10_volume_thin_control COMMAND startup_gfx10_volume_check --mutate thin) +set_tests_properties(startup_gfx10_volume_thin_control PROPERTIES WILL_FAIL TRUE) +add_test(NAME startup_gfx10_volume_addrlib COMMAND startup_gfx10_volume_check --addrlib) +set_tests_properties(startup_gfx10_volume_addrlib PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) diff --git a/tests/startup_address_console_check.py b/tests/startup_address_console_check.py index d36db04448..b3ccc8caee 100644 --- a/tests/startup_address_console_check.py +++ b/tests/startup_address_console_check.py @@ -1,9 +1,9 @@ """Draw textures published by address (device slot 70) whose texels are in a console layout. - seven textures, each drawn once; every pixel of the 512x128 target is - compared with the texel the view names; then two held descriptions - and one texture whose address is announced as XG rows after it - was published + seven textures and two volumes, each drawn once; every pixel of the + 512x128 target is compared with the texel the view names; then three + held descriptions and one texture whose address is announced as XG + rows after it was published gate the upload lifetime control described at check_gate gate-ring the same draws with X2W_TEST_ADDRESS_UPLOAD_RING=1: the 256 MiB ring refuses the uploads past its cap, the refused draws read the null view @@ -94,6 +94,32 @@ def address(self, mip, x, y): return self.start[mip] + (block << self.log2) + self.in_block(x % self.block_w, y % self.block_h) +# A volume in the 4 KiB standard mode (0x105), one mip: addrlib lays a 3D resource in a standard mode out in +# thick blocks (Gfx10Lib::HwlIsThick). The 12 address bits of a 4-byte element follow the one-pipe row of +# GFX10_SW_4K_S3_PATINFO; the block is 8x16x8 elements, and blocks follow in x, then y, then a layer of +# blocks at a time in z. +THICK_4K_S3 = {4: "0 0 X0 Y0 Z0 Y1 X1 Z1 Y2 X2 Z2 Y3"} + + +class ConsoleVolume: + def __init__(self, width, height, depth, element): + self.width, self.height, self.depth = width, height, depth + self.bits = THICK_4K_S3[element].split() + self.block = [1 << sum(b[0] == axis for b in self.bits) for axis in "XYZ"] + self.wide, high, layers = (-(-side // block) for side, block in zip((width, height, depth), self.block)) + self.layer = self.wide * high * 4096 + self.bytes = self.layer * layers + + def address(self, x, y, z): + bw, bh, bd = self.block + value = (z // bd) * self.layer + ((y // bh) * self.wide + x // bw) * 4096 + for bit, name in enumerate(self.bits): + coordinate = {"X": x % bw, "Y": y % bh, "Z": z % bd}.get(name[0]) + if coordinate is not None and (coordinate >> int(name[1:])) & 1: + value |= 1 << bit + return value + + def rgba_texel(mip, x, y): return bytes(((7 * x + 40 * mip + 1) & 255, (5 * y + 3) & 255, (x ^ (3 * y)) & 255, 255)) @@ -118,6 +144,84 @@ def bc1_block(mip, x, y): ] +def volume_texel(x, y, z): + return bytes(((7 * x + 1) & 255, (5 * y + 3) & 255, (29 * z + 11) & 255, 255)) + + +# name, width, height, depth, format, layout: one mip of RGBA8 in the 4 KiB standard mode, viewed as a +# Texture3D. Each target tile of the texture's width and height draws one depth layer. +VOLUMES = [ + ("RGBA8 volume 17x17x17 4 KiB standard", 17, 17, 17, RGBA8, 0x105), + ("RGBA8 volume 33x9x18 4 KiB standard", 33, 9, 18, RGBA8, 0x105), +] + + +def build_volume(width, height, depth): + """Backing bytes of a volume, built from the S3 row above.""" + console = ConsoleVolume(width, height, depth, 4) + backing = bytearray(console.bytes) + seen = set() + for z in range(depth): + for y in range(height): + for x in range(width): + at = console.address(x, y, z) + if at in seen or at + 4 > len(backing): + raise AssertionError(f"oracle address {at:#x} of ({x},{y},{z}) is shared or outside the volume") + seen.add(at) + backing[at:at + 4] = volume_texel(x, y, z) + return backing + + +def check_volume(directory, consumer, backend, case, held=None): + name, width, height, depth, fmt, layout = case + source = directory / "texels.bin" + source.write_bytes(build_volume(width, height, depth)) + across = -(-TARGET_W // width) + hlsl = ("Texture3D t : register(t0);\n" + "float4 main(float4 p : SV_Position) : SV_Target {\n" + " uint x = uint(p.x), y = uint(p.y);\n" + f" uint z = (x / {width} + (y / {height}) * {across}) % {depth};\n" + f" return t.Load(int4(x % {width}, y % {height}, z, 0));\n}}\n") + trap_log = directory / "trap.log" + modes = {"X2W_TEST_CONSOLE_VIEW": str(source), "X2W_TRAP_LOG": str(trap_log), + "X2W_TEST_CONSOLE_DESC": f"{width},{height},1,{fmt},{layout},0,{depth}"} + actual = draw_texture(directory, consumer, backend, hlsl, modes, "tex3d") + if actual is None: + return 77 + if len(actual) != TARGET_W * TARGET_H * 4: + raise AssertionError(f"{name}: readback length {len(actual)}") + log = trap_log.read_text(errors="replace") + if held: + if any(actual): + raise AssertionError(f"{name}: a held description drew texels") + if f"slot70 texture kind 1: {held};" not in log or "published console layout" in log: + raise AssertionError(f"{name}: no '{held}' line in the log, or a publication") + print(f"{backend} {name}: held ({held}), {TARGET_W * TARGET_H} pixels read the null view") + return 0 + layers = set() + for y in range(TARGET_H): + for x in range(TARGET_W): + z = (x // width + (y // height) * across) % depth + layers.add(z) + pixel = actual[4 * (y * TARGET_W + x):4 * (y * TARGET_W + x) + 4] + expect = volume_texel(x % width, y % height, z) + if pixel != expect: + raise AssertionError(f"{name}: pixel ({x},{y}) layer {z} actual {pixel.hex()} expected {expect.hex()}") + if len(layers) != depth: + raise AssertionError(f"{name}: the draw read {len(layers)} of {depth} layers") + if "slot70 texture kind 1: published console layout" not in log: + raise AssertionError(f"{name}: no 'published console layout' line in the log") + print(f"{backend} {name}: {TARGET_W * TARGET_H} RGBA pixels exact over {depth} layers") + return 0 + + +# A volume past the size the XG stand-in reports: 64x8x40 RGBA8 is eight blocks across, one down and five +# layers of blocks (163,840 bytes); the desktop footprint (40 layers of 8 rows of 256 bytes) rounded to +# 64 KiB is 131,072. A volume has one slice, so the footprint is not counted once per layer. +HELD_VOLUME = (("RGBA8 volume 64x8x40 4 KiB standard past the XG size", 64, 8, 40, RGBA8, 0x105), + "console_layout_beyond_xg_size") + + def build(width, height, mips, fmt, layout): """Backing bytes and, per mip, the RGBA texels a correct detile shows.""" texels = 4 if fmt == BC1 else 1 @@ -293,10 +397,19 @@ def check_gate(directory, consumer, backend, ring): result = check(Path(temporary), *sys.argv[1:3], case) if result: sys.exit(result) + for case in VOLUMES: + with tempfile.TemporaryDirectory() as temporary: + result = check_volume(Path(temporary), *sys.argv[1:3], case) + if result: + sys.exit(result) for case, extra, held in HELD: with tempfile.TemporaryDirectory() as temporary: result = check(Path(temporary), *sys.argv[1:3], case, extra, held) if result: sys.exit(result) + with tempfile.TemporaryDirectory() as temporary: + result = check_volume(Path(temporary), *sys.argv[1:3], *HELD_VOLUME) + if result: + sys.exit(result) with tempfile.TemporaryDirectory() as temporary: sys.exit(check(Path(temporary), *sys.argv[1:3], LATE[0], LATE[1], late=True)) diff --git a/tests/startup_address_srv.cpp b/tests/startup_address_srv.cpp index 183f25d0a8..4568540465 100644 --- a/tests/startup_address_srv.cpp +++ b/tests/startup_address_srv.cpp @@ -259,8 +259,8 @@ int draw_bc_address_srvs(void* guest, void* list) } // X2W_TEST_CONSOLE_VIEW names a file of texels and X2W_TEST_CONSOLE_DESC the texture they belong to -// ("width,height,mips,format,layout,viewed mip"). No resource object exists at the address; one mip is -// viewed and drawn over the whole target. With X2W_TEST_CONSOLE_XG_ROWS=1 the address is first announced +// ("width,height,mips,format,layout,viewed mip", and a depth for a volume viewed as a Texture3D). No +// resource object exists at the address; one mip is viewed and drawn over the whole target. With X2W_TEST_CONSOLE_XG_ROWS=1 the address is first announced // the way the XG stand-in announces a copy of desktop-footprint rows; with =after the announcement comes // between the publication and the draw. int draw_console_address_srv(void* guest, void* list) @@ -268,21 +268,28 @@ int draw_console_address_srv(void* guest, void* list) wchar_t path[MAX_PATH]{}; const DWORD length = GetEnvironmentVariableW(L"X2W_TEST_CONSOLE_VIEW", path, MAX_PATH); char text[96]{}; - unsigned width = 0, height = 0, mips = 0, format = 0, layout = 0, viewed = 0; + unsigned width = 0, height = 0, mips = 0, format = 0, layout = 0, viewed = 0, depth = 0; if (!length || length >= MAX_PATH || !GetEnvironmentVariableA("X2W_TEST_CONSOLE_DESC", text, sizeof(text)) || - std::sscanf(text, "%u,%u,%u,%u,%u,%u", &width, &height, &mips, &format, &layout, &viewed) != 6) return 43; + std::sscanf(text, "%u,%u,%u,%u,%u,%u,%u", &width, &height, &mips, &format, &layout, &viewed, &depth) < 6) return 43; alignas(4096) static std::array backing{}; std::ifstream input(path, std::ios::binary); input.read(backing.data(), backing.size()); if (!input.gcount() || !input.eof()) return 43; - const D3D12_RESOURCE_DESC desc{D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, width, height, 1, static_cast(mips), - static_cast(format), {1, 0}, static_cast(layout), D3D12_RESOURCE_FLAG_NONE}; + const D3D12_RESOURCE_DESC desc{depth ? D3D12_RESOURCE_DIMENSION_TEXTURE3D : D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, width, + height, static_cast(depth ? depth : 1), static_cast(mips), static_cast(format), {1, 0}, + static_cast(layout), D3D12_RESOURCE_FLAG_NONE}; ViewAt v{}; v.view.Format = desc.Format; - v.view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; v.view.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; - v.view.Texture2D.MostDetailedMip = viewed; - v.view.Texture2D.MipLevels = 1; + if (depth) { + v.view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D; + v.view.Texture3D.MostDetailedMip = viewed; + v.view.Texture3D.MipLevels = 1; + } else { + v.view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; + v.view.Texture2D.MostDetailedMip = viewed; + v.view.Texture2D.MipLevels = 1; + } v.address = ptr(backing.data()); Word cpu = 0; if (!bind_view_table(guest, list, cpu)) return 42; diff --git a/tests/startup_gfx10_volume_check.cpp b/tests/startup_gfx10_volume_check.cpp new file mode 100644 index 0000000000..40401a99b2 --- /dev/null +++ b/tests/startup_gfx10_volume_check.cpp @@ -0,0 +1,362 @@ +// Checks the volume layout of src/startup_stubs/gfx10_layout.h (a single-mip 3D texture in the 4 KiB +// standard mode, 0x105, which addrlib lays out in thick blocks) without a device: +// - the address bit of every x, y and z bit against the one-pipe rows of addrlib's GFX10_SW_4K_S3_PATINFO, +// restated below, and the block each element size gives; +// - the order of blocks: along x, then y, then a layer of blocks at a time along z, with the sides of +// the texture padded to whole blocks; +// - that every element of a volume gets its own bytes inside the texture, and that a tile followed by a +// detile (with padded row and layer pitches) returns the texels it started from; +// - the descriptions it takes and refuses, and the slot-70 views it allows on them. +// `--addrlib` compares the size and every element address of a set of volumes with +// Addr2ComputeSurfaceInfo and Addr2ComputeSurfaceAddrFromCoord (ADDR_RSRC_TEX_3D, ADDR_SW_4KB_S) and +// skips (77) when the build has no addrlib. `--mutate thin` lays each volume out as a thin 2D array of +// its depth layers and is the negative control: it must fail. +// +// Reference: AMD addrlib as Mesa carries it under src/amd/addrlib, at the revision tools/fetch_addrlib.py +// pins (Mesa 25.1.0, commit 5c142e46f3f6e752ed745fd48912ebb8fad67145): src/gfx10/gfx10SwizzlePattern.h, +// src/gfx10/gfx10addrlib.cpp and src/core/addrlib2.cpp, each with the notice +// Copyright (C) 2007-2024 Advanced Micro Devices, Inc. All rights reserved. +// SPDX-License-Identifier: MIT +// The pattern rows are restated below as data; no addrlib code is included in the default run. +#include "startup_stubs/address_texture.h" +#include "startup_stubs/gfx10_layout.h" + +#include +#include +#include +#include + +namespace { +using x2w_startup::gfx10::Layout; +int failures = 0; +bool thin = false; // --mutate thin + +void fail(const std::string& what) +{ + if (++failures <= 40) std::printf("FAIL %s\n", what.c_str()); +} + +D3D12_RESOURCE_DESC volume(UINT width, UINT height, UINT depth, DXGI_FORMAT format, UINT layout = 0x105, UINT mips = 1) +{ + D3D12_RESOURCE_DESC d{}; + d.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D; + d.Width = width; + d.Height = height; + d.DepthOrArraySize = static_cast(depth); + d.MipLevels = static_cast(mips); + d.Format = format; + d.SampleDesc.Count = 1; + d.Layout = static_cast(layout); + return d; +} + +// The layout under test; the control reads the volume as a thin array of its layers. +Layout layout_of(D3D12_RESOURCE_DESC d) +{ + if (thin) d.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + return Layout(d); +} +std::uint64_t at(const Layout& l, UINT x, UINT y, UINT z) +{ + return thin ? l.address(0, x, y, z) : l.address(0, x, y, 0, z); +} + +// One format per element size: 1, 2, 4, 8 and 16 bytes. +constexpr DXGI_FORMAT by_size[5] = {DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, + DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT}; + +// GFX10_SW_4K_S3_PATINFO one-pipe rows by element size, address bits from bit 0 up; "0" is a bit inside +// the element. +const char* const rows_s3[5] = { + "X0 X1 Z0 Y0 Z1 Y1 X2 Z2 Y2 X3 Z3 Y3", "0 X0 Z0 Y0 Z1 Y1 X1 Z2 Y2 X2 Z3 Y3", "0 0 X0 Y0 Z0 Y1 X1 Z1 Y2 X2 Z2 Y3", + "0 0 0 X0 Z0 Y0 X1 Z1 Y1 X2 Z2 Y2", "0 0 0 0 Z0 Y0 X0 Z1 Y1 X1 Z2 Y2"}; +// addrlib Block1K_3d, scaled to 4 KiB by ComputeThickBlockDimension (height and depth doubled). +constexpr UINT block_sides[5][3] = {{16, 16, 16}, {8, 16, 16}, {8, 16, 8}, {8, 8, 8}, {4, 8, 8}}; + +void check_equations() +{ + for (UINT size = 0; size < 5; ++size) { + const Layout l = layout_of(volume(64, 64, 64, by_size[size])); + const std::string name = "element " + std::to_string(1u << size); + UINT bit = 0; + for (const char* p = rows_s3[size]; *p; ++bit) { + const char axis = *p++; + UINT index = 0; + if (axis != '0') index = static_cast(*p++ - '0'); + if (*p == ' ') ++p; + if (axis == '0') continue; + const UINT v = 1u << index; + const std::uint64_t got = axis == 'X' ? at(l, v, 0, 0) : axis == 'Y' ? at(l, 0, v, 0) : at(l, 0, 0, v); + if (got != (1ull << bit)) + fail(name + " " + axis + std::to_string(index) + ": " + std::to_string(got) + ", expected bit " + std::to_string(bit)); + } + if (l.block_bytes != 4096 || l.block_width != block_sides[size][0] || l.block_height != block_sides[size][1] || + l.block_depth != block_sides[size][2]) + fail(name + ": block " + std::to_string(l.block_width) + "x" + std::to_string(l.block_height) + "x" + + std::to_string(l.block_depth)); + } +} + +// 17x17x17 RGBA8 in 8x16x8 blocks: 3 blocks across, 2 down and 3 layers of blocks. +void check_block_order() +{ + const Layout l = layout_of(volume(17, 17, 17, DXGI_FORMAT_R8G8B8A8_UNORM)); + const auto expect = [](const char* what, std::uint64_t got, std::uint64_t want) { + if (got != want) fail(std::string("block order: ") + what + " " + std::to_string(got) + ", expected " + std::to_string(want)); + }; + expect("bytes", l.bytes(), 3ull * 2 * 3 * 4096); + expect("next block in x", at(l, 8, 0, 0), 4096); + expect("next row of blocks", at(l, 0, 16, 0), 3 * 4096); + expect("next layer of blocks", at(l, 0, 0, 8), 6 * 4096); + expect("last element", at(l, 16, 16, 16), (2ull * 6 + 1 * 3 + 2) * 4096); +} + +struct Shape { + UINT width, height, depth; + DXGI_FORMAT format; +}; +const Shape shapes[] = { + {17, 17, 17, DXGI_FORMAT_R16G16B16A16_FLOAT}, {32, 32, 32, DXGI_FORMAT_R8G8B8A8_UNORM}, {33, 33, 33, DXGI_FORMAT_R16G16B16A16_FLOAT}, + {32, 32, 32, DXGI_FORMAT_A8_UNORM}, {16, 16, 8, DXGI_FORMAT_R16_FLOAT}, {16, 16, 16, DXGI_FORMAT_R8G8_UNORM}, + {32, 32, 32, DXGI_FORMAT_R10G10B10A2_UNORM}, {5, 3, 7, DXGI_FORMAT_R32G32B32A32_FLOAT}, {1, 1, 2, DXGI_FORMAT_R8_UNORM}, + {64, 8, 40, DXGI_FORMAT_R32_FLOAT}, +}; + +void check_distinct_and_round_trip() +{ + for (const Shape& s : shapes) { + const D3D12_RESOURCE_DESC d = volume(s.width, s.height, s.depth, s.format); + const std::string name = std::to_string(s.width) + "x" + std::to_string(s.height) + "x" + std::to_string(s.depth) + + " format " + std::to_string(s.format); + if (!x2w_startup::gfx10::supports(d)) { + fail(name + ": refused"); + continue; + } + const Layout l = layout_of(d); + const UINT e = l.bytes_per_element; + const std::uint64_t size = l.bytes(); + std::vector used(static_cast(size)); + bool clash = false; + for (UINT z = 0; z < s.depth; ++z) + for (UINT y = 0; y < s.height; ++y) + for (UINT x = 0; x < s.width; ++x) { + const std::uint64_t a = at(l, x, y, z); + if (a % e || a + e > size) { + clash = true; + continue; + } + if (used[static_cast(a)]) clash = true; + used[static_cast(a)] = 1; + } + if (clash) fail(name + ": elements share bytes or fall outside the texture"); + if (thin) continue; + const std::size_t pitch = (std::size_t{s.width} * e + 255) & ~std::size_t{255}, layer = pitch * (s.height + 1); + std::vector rows(layer * s.depth), back(rows.size()), tiled(static_cast(size)); + for (std::size_t i = 0; i < rows.size(); ++i) rows[i] = static_cast(i * 131 + 7); + l.tile(0, 0, tiled.data(), rows.data(), pitch, layer); + l.detile(0, 0, tiled.data(), back.data(), pitch, layer); + for (UINT z = 0; z < s.depth; ++z) + for (UINT y = 0; y < s.height; ++y) + if (std::memcmp(&rows[z * layer + y * pitch], &back[z * layer + y * pitch], std::size_t{s.width} * e)) { + fail(name + ": round trip differs at layer " + std::to_string(z) + " row " + std::to_string(y)); + z = s.depth; + break; + } + } +} + +void check_descriptions() +{ + const auto supported = [](const char* name, const D3D12_RESOURCE_DESC& d, bool want) { + if (x2w_startup::gfx10::supports(d) != want) fail(std::string("layout: ") + name); + }; + const D3D12_RESOURCE_DESC good = volume(32, 32, 32, DXGI_FORMAT_R8G8B8A8_UNORM); + supported("4 KiB standard RGBA8", good, true); + D3D12_RESOURCE_DESC d = good; + d.MipLevels = 2; + supported("two mips", d, false); + supported("BC1", volume(32, 32, 32, DXGI_FORMAT_BC1_UNORM), false); + supported("BC7", volume(32, 32, 32, DXGI_FORMAT_BC7_UNORM), false); + supported("4 KiB display", volume(32, 32, 32, DXGI_FORMAT_R8G8B8A8_UNORM, 0x106), false); + supported("256 B standard", volume(32, 32, 32, DXGI_FORMAT_R8G8B8A8_UNORM, 0x101), false); + supported("64 KiB standard", volume(32, 32, 32, DXGI_FORMAT_R8G8B8A8_UNORM, 0x109), false); + supported("64 KiB display", volume(32, 32, 32, DXGI_FORMAT_R8G8B8A8_UNORM, 0x10a), false); + supported("linear", volume(32, 32, 32, DXGI_FORMAT_R8G8B8A8_UNORM, 0x100), false); + supported("desktop layout", volume(32, 32, 32, DXGI_FORMAT_R8G8B8A8_UNORM, 0), false); + supported("12-byte texels", volume(32, 32, 32, DXGI_FORMAT_R32G32B32_FLOAT), false); + supported("too wide", volume(2049, 4, 4, DXGI_FORMAT_R8_UNORM), false); + supported("too deep", volume(4, 4, 2049, DXGI_FORMAT_R8_UNORM), false); + supported("no depth", volume(4, 4, 0, DXGI_FORMAT_R8_UNORM), false); + d = good; + d.SampleDesc.Count = 2; + supported("multisampled", d, false); + + const auto address = [](const char* name, const D3D12_RESOURCE_DESC& d, bool want) { + if (x2w_startup::console_address_texture(d) != want) fail(std::string("address texture: ") + name); + }; + address("RGBA16F 17x17x17", volume(17, 17, 17, DXGI_FORMAT_R16G16B16A16_FLOAT), true); + address("R8 32x32x32", volume(32, 32, 32, DXGI_FORMAT_R8_UNORM), true); + address("typed depth", volume(32, 32, 32, DXGI_FORMAT_D32_FLOAT), false); + d = good; + d.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + address("unordered access", d, false); + address("BC7", volume(32, 32, 32, DXGI_FORMAT_BC7_UNORM), false); + d = good; + d.MipLevels = 6; + address("mip chain", d, false); + + D3D12_SHADER_RESOURCE_VIEW_DESC v{}; + v.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + v.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + v.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D; + v.Texture3D.MipLevels = ~0u; + if (!x2w_startup::address_view_fits(good, v)) fail("view: whole volume"); + v.Texture3D.MipLevels = 1; + if (!x2w_startup::address_view_fits(good, v)) fail("view: one mip"); + v.Texture3D.MostDetailedMip = 1; + if (x2w_startup::address_view_fits(good, v)) fail("view: mip past the volume"); + v.Texture3D.MostDetailedMip = 0; + D3D12_RESOURCE_DESC typeless = good; + typeless.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS; + v.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; + if (!x2w_startup::address_view_fits(typeless, v)) fail("view: sRGB of typeless storage"); + if (x2w_startup::address_view_fits(good, v)) fail("view: sRGB of UNORM storage"); + v.Format = DXGI_FORMAT_R32_FLOAT; + if (x2w_startup::address_view_fits(good, v)) fail("view: other family"); + v.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + v.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DARRAY; + v.Texture2DArray = {0, ~0u, 0, 32, 0, 0.0f}; + if (x2w_startup::address_view_fits(good, v)) fail("view: 2D array on a volume"); +} +} // namespace + +#ifndef XBOX2WINDOWS_HAVE_ADDRLIB +int addrlib_check() +{ + std::puts("startup_gfx10_volume --addrlib: SKIP (built without addrlib; run tools/fetch_addrlib.py and configure with " + "-DXBOX2WINDOWS_ADDRLIB_DIR=/src/amd/addrlib)"); + return 77; +} +#else +#include + +#include "addrinterface.h" + +namespace { +VOID* ADDR_API alloc_sys_mem(const ADDR_ALLOCSYSMEM_INPUT* in) { return std::malloc(in->sizeInBytes); } +ADDR_E_RETURNCODE ADDR_API free_sys_mem(const ADDR_FREESYSMEM_INPUT* in) +{ + std::free(in->pVirtAddr); + return ADDR_OK; +} +} // namespace + +// The shapes above and a sweep of small odd sides, for each element size, against Mesa's "navi21" +// (gfx10.3) configuration that startup_small_texture_4k_check and xg_swizzle_select_check use: family +// 0x8F, revision 0x28, GB_ADDR_CONFIG 0x444. +int addrlib_check() +{ + ADDR_CREATE_INPUT create{}; + ADDR_CREATE_OUTPUT created{}; + create.size = sizeof create; + created.size = sizeof created; + create.chipEngine = 0x0000000D; // CIASICIDGFXENGINE_ARCTICISLAND + create.chipFamily = 0x8F; + create.chipRevision = 0x28; + create.callbacks.allocSysMem = alloc_sys_mem; + create.callbacks.freeSysMem = free_sys_mem; + create.regValue.gbAddrConfig = 0x40 | 4u | (4u << 8); + if (AddrCreate(&create, &created) != ADDR_OK) return 1; + const AddrFormat addr_formats[5] = {ADDR_FMT_8, ADDR_FMT_16, ADDR_FMT_8_8_8_8, ADDR_FMT_16_16_16_16, ADDR_FMT_32_32_32_32}; + std::vector cases; + for (const Shape& s : shapes) cases.push_back(volume(s.width, s.height, s.depth, s.format)); + for (UINT size = 0; size < 5; ++size) + for (UINT w : {1u, 3u, 9u, 24u}) + for (UINT h : {1u, 7u, 17u}) + for (UINT dep : {1u, 5u, 18u}) cases.push_back(volume(w, h, dep, by_size[size])); + unsigned compared = 0, elements = 0, mismatches = 0; + for (const D3D12_RESOURCE_DESC& d : cases) { + const Layout l(d); + UINT size = 0; + while ((1u << size) < l.bytes_per_element) ++size; + ADDR2_COMPUTE_SURFACE_INFO_INPUT in{}; + ADDR2_COMPUTE_SURFACE_INFO_OUTPUT out{}; + in.size = sizeof in; + out.size = sizeof out; + in.flags.texture = 1; + in.swizzleMode = ADDR_SW_4KB_S; + in.resourceType = ADDR_RSRC_TEX_3D; + in.format = addr_formats[size]; + in.bpp = l.bytes_per_element * 8; + in.width = l.width; + in.height = l.height; + in.numSlices = l.depth; + in.numMipLevels = 1; + in.numSamples = 1; + in.numFrags = 1; + ++compared; + char name[64]; + std::snprintf(name, sizeof name, "%ux%ux%u %u-byte", l.width, l.height, l.depth, l.bytes_per_element); + if (Addr2ComputeSurfaceInfo(created.hLib, &in, &out) != ADDR_OK || out.surfSize != l.bytes()) { + if (++mismatches <= 12) + std::printf("FAIL %s: size 0x%llx, addrlib 0x%llx\n", name, static_cast(l.bytes()), + static_cast(out.surfSize)); + continue; + } + for (UINT z = 0; z < l.depth; ++z) + for (UINT y = 0; y < l.height; ++y) + for (UINT x = 0; x < l.width; ++x) { + ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT ain{}; + ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT aout{}; + ain.size = sizeof ain; + aout.size = sizeof aout; + ain.x = x; + ain.y = y; + ain.slice = z; + ain.swizzleMode = ADDR_SW_4KB_S; + ain.flags.texture = 1; + ain.resourceType = ADDR_RSRC_TEX_3D; + ain.bpp = in.bpp; + ain.unalignedWidth = l.width; + ain.unalignedHeight = l.height; + ain.numSlices = l.depth; + ain.numMipLevels = 1; + ain.numSamples = 1; + ain.numFrags = 1; + ain.pitchInElement = out.pitch; + ++elements; + const std::uint64_t mine = l.address(0, x, y, 0, z); + if (Addr2ComputeSurfaceAddrFromCoord(created.hLib, &ain, &aout) != ADDR_OK || aout.addr != mine) { + if (++mismatches <= 12) + std::printf("FAIL %s (%u,%u,%u): 0x%llx, addrlib 0x%llx\n", name, x, y, z, + static_cast(mine), static_cast(aout.addr)); + } + } + } + AddrDestroy(created.hLib); + std::printf("startup_gfx10_volume --addrlib: %u volumes, %u element addresses compared, %u mismatches (Mesa 25.1.0 addrlib, " + "SW_4KB_S, 3D)\n", compared, elements, mismatches); + return compared && elements && !mismatches ? 0 : 1; +} +#endif + +int main(int argc, char** argv) +{ + if (argc == 2 && std::strcmp(argv[1], "--addrlib") == 0) return addrlib_check(); + thin = argc == 3 && std::strcmp(argv[1], "--mutate") == 0 && std::strcmp(argv[2], "thin") == 0; + if (argc != 1 && !thin) { + std::printf("usage: startup_gfx10_volume_check [--addrlib | --mutate thin]\n"); + return 2; + } + check_equations(); + check_block_order(); + check_distinct_and_round_trip(); + check_descriptions(); + if (failures) { + std::printf("startup_gfx10_volume: %d failures\n", failures); + return 1; + } + std::printf("startup_gfx10_volume: PASS (5 element sizes, block order, %zu round trips, 15 layouts, 6 address descriptions, " + "7 views)\n", sizeof(shapes) / sizeof(shapes[0])); + return 0; +} From eb36ad01e6576f016df0859d36defdc515611fa0 Mon Sep 17 00:00:00 2001 From: lewisalex86 Date: Thu, 26 Nov 2026 15:54:49 +0000 Subject: [PATCH 2/2] startup: read 0x105 volume mip chains in slot 70 A Texture3D description in the 4 KiB standard layout with a mip chain is now detiled instead of refused. Each layer of thick blocks holds that layer of every mip: the shared tail block, then the mips from the smallest to the largest, with the tail mips at the origins addrlib gives them. The mip-count check counts a volume's depth. --- docs/experiments.md | 22 ++- docs/startup-runtime.md | 28 ++- src/startup_stubs/address_texture.h | 4 +- src/startup_stubs/gfx10_layout.h | 73 ++++++-- tests/cmake/startup_gfx10_volume.cmake | 14 +- tests/startup_address_console_check.py | 102 ++++++---- tests/startup_address_srv.cpp | 2 +- tests/startup_address_volume_srv_check.py | 5 +- tests/startup_gfx10_volume_check.cpp | 217 +++++++++++++++------- 9 files changed, 324 insertions(+), 143 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index 2fc009815d..2cbab56d19 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -16349,7 +16349,7 @@ ctest --preset release --no-tests=error --output-on-failure -j 1 -R '^startup_ad #### Volumes in the 4 KiB standard layout -Slot 70 also reads a single-mip, uncompressed 3D texture whose layout is `0x105`. addrlib lays it +Slot 70 also reads an uncompressed 3D texture whose layout is `0x105`, at first a single mip. addrlib lays it out in thick 4 KiB blocks (`GFX10_SW_4K_S3_PATINFO`). `startup_gfx10_volume` needs no device. It checks the address bit of every x, y and z bit against the restated one-pipe rows for the five element sizes, the block sizes, and the order of blocks in a 17 by 17 by 17 RGBA8 volume. It also checks that @@ -16373,6 +16373,26 @@ Two local mutations were run once and are not registered tests: the layer pitch to zero, and the hold counting one footprint per layer. Each fails `startup_address_console_warp`: the first on the first volume's pixels, the second on the held volume. +Volumes with a mip chain are read too. Each layer of blocks holds that layer of every mip: the tail +block first, then the mips from the smallest to the largest. A mip at most a block wide and half a +block high goes in the tail while at most five mips remain, at an origin read from its byte offset +in the tail block. `startup_gfx10_volume` checks the addresses of a 32 by 32 by 32 RGBA8 volume with +six mips: 11 blocks to a layer, mip 1 after the tail block, mip 0 after mip 1, and mips 2 to 5 at +(0,8), (4,4), (4,0) and (0,4) in the tail block. It also checks the distinct bytes and tile/detile +round trips of every mip of ten chains (a tail from mip 0, a chain with no tail, odd sides, a deep +volume whose depth allows the mip count), and the mip chains slot 70 takes and the views of them it +allows. `startup_gfx10_volume_tail_control` puts every tail mip at the start of the tail block and +must fail. `startup_gfx10_volume_addrlib` now also compares every mip count of four chains for each +element size: 305 volumes and 12,704,487 element addresses with 0 mismatches. + +`startup_address_console_{warp,hardware}` draws four mips of two chains, RGBA8 32 by 32 by 32 with +six mips (mip 1, and mip 3 in the tail) and 20 by 24 by 16 with five mips (mip 1, and mip 3 in the +tail), from a backing that holds every mip with its own texels. All 65,536 pixels of each must match. +A local mutation that drops the tail origins of a volume, run once, fails it on the first tail mip, +which then reads another mip's texels. A chain whose layout runs past the size the XG stand-in +reports is held as before: RGBA8 33 by 9 by 18 with six mips takes 135,168 bytes in the layout against +65,536 reported. + ```powershell ctest --preset release --no-tests=error --output-on-failure -R '^startup_gfx10_volume' ctest --preset release --no-tests=error --output-on-failure -j 1 -R '^startup_address_console_(hardware|warp)$' diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 79fa84dd1d..4896edd583 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -3286,17 +3286,23 @@ The description must be two-dimensional, at most 16384 texels a side, with 1 to no target, depth or unordered-access flag, and a format with a known element size (8- to 128-bit texels and BC1 to BC7, whose largest mip must then be whole 4x4 blocks). The view must use a supported typed format that matches the storage format or belongs to its typeless parent. The 2D or 2D-array view must fit the mip and slice ranges. A mismatched or interior view overlapping a live resource preserves the destination descriptor. -A three-dimensional description is taken in one layout only: `0x105` (4 KiB standard), one mip, one -sample, at most 2048 texels on each side and an uncompressed format with a known element size, -viewed as a Texture3D. addrlib lays a 3D resource in a standard or display mode out in thick blocks +A three-dimensional description is taken in one layout only: `0x105` (4 KiB standard), one sample, +at most 2048 texels on each side and an uncompressed format with a known element size, with one mip +or a mip chain its largest side (depth included) allows, viewed as a Texture3D whose mips fit the +chain. addrlib lays a 3D resource in a standard or display mode out in thick blocks (`Gfx10Lib::HwlIsThick`): the 12 address bits of a block follow the one-pipe rows of `GFX10_SW_4K_S3_PATINFO`, the block is 16x16x16, 8x16x16, 8x16x8, 8x8x8 or 4x8x8 elements for 1- to -16-byte elements, and blocks follow along x, then y, then a layer of blocks at a time along z, with -every side padded to whole blocks. Each depth layer is copied to its own footprint rows. +16-byte elements, and the volume is stored a layer of blocks (one block deep) at a time. Each layer +holds that layer of every mip: first the shared tail block when the chain has one, then the mips from +the smallest to the largest, each in blocks along x, then y, with every side rounded up at each level +and padded to whole blocks. A mip is in the tail when it is at most a block wide and half a block high +and at most five mips remain; tail mip k from the end starts at byte k x 256 of the tail block, which, +read as 256-byte micro blocks, gives its origin in x and y (`ComputeSurfaceInfoMacroTiled`). Each +depth layer is copied to its own footprint rows. Anything else is refused as before and leaves the destination descriptor unchanged: layout `0` and the linear mode `0x100` without a live texture, cube views, three-dimensional descriptions in any -other layout, with a mip chain or with a block-compressed format, multisampled textures, the XOR -swizzle modes and every other layout value. The texels must be readable and span +other layout or with a block-compressed format, multisampled textures, the XOR swizzle modes and +every other layout value. The texels must be readable and span at most 64 MiB. A console-layout description is held (not published, descriptor unchanged) in the two cases a @@ -3336,8 +3342,9 @@ Limits and choices that are not measured against a console: in `startup_gfx10_layout_check.cpp` (all five element sizes) and in the Python oracle of `startup_address_console_check.py` (4- and 8-byte elements), both written from the same source. - The thick `0x105` volume layout is compared with addrlib itself when the build has it - (`startup_gfx10_volume_addrlib`: every element address of 190 volumes). Mip chains, block-compressed - volumes and volumes in the other modes are not handled; they stay refused. + (`startup_gfx10_volume_addrlib`: every element address of every mip of 305 volumes, 115 of them + with a mip chain). Block-compressed volumes and volumes in the other modes are not handled; they + stay refused. Log lines (stderr and `X2W_TRAP_LOG`): @@ -3475,7 +3482,8 @@ footprint layout (256-byte row pitch alignment and 512-byte subresource placemen `startup_address_volume_srv_*` exercises volume SRVs on a device (WARP and hardware) with multiple depth slices and mip levels, where footprint row pitch (256 bytes) exceeds packed row bytes (16 bytes), and verifies refusal lines for mismatched view dimensions, short backings, out-of-bounds mips, explicit clamps, -and console layouts. On Windows 11 Build 26100 with an AMD Radeon RX 6600M (driver 32.0.21045.11001), +and a console-layout description over the live volume (`overlapping_resource`; before mip chains of `0x105` +volumes were read, `unsupported_description`). On Windows 11 Build 26100 with an AMD Radeon RX 6600M (driver 32.0.21045.11001), `startup_address_volume_srv_hardware` passed with all 32 RGBA pixels exact. - `ctest --preset release --no-tests=error -R '^startup_memory_srv_(report|buffer|volume)$' -V` diff --git a/src/startup_stubs/address_texture.h b/src/startup_stubs/address_texture.h index 11d8337391..a999974072 100644 --- a/src/startup_stubs/address_texture.h +++ b/src/startup_stubs/address_texture.h @@ -29,7 +29,9 @@ inline bool console_address_texture(const D3D12_RESOURCE_DESC& r) static_cast(D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER); if (!gfx10::supports(r) || r.SampleDesc.Quality || (static_cast(r.Flags) & incompatible_flags) || r.DepthOrArraySize > D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION || - !((std::max)(r.Width, UINT64{r.Height}) >> (r.MipLevels - 1)) || + // The largest side, depth included for a volume, must allow the mip count. + !((std::max)({r.Width, UINT64{r.Height}, + UINT64{r.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? r.DepthOrArraySize : 1u}}) >> (r.MipLevels - 1)) || (r.Alignment && r.Alignment != D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT && r.Alignment != D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT) || address_depth_format(r.Format)) diff --git a/src/startup_stubs/gfx10_layout.h b/src/startup_stubs/gfx10_layout.h index a81d52b7cf..cf618b0193 100644 --- a/src/startup_stubs/gfx10_layout.h +++ b/src/startup_stubs/gfx10_layout.h @@ -66,13 +66,14 @@ inline UINT block_log2(UINT mode) } // A three-dimensional texture in the 4 KiB standard mode (0x105), which addrlib lays out in thick blocks -// (Gfx10Lib::HwlIsThick: a 3D resource in a standard or display mode): one mip of uncompressed texels. +// (Gfx10Lib::HwlIsThick: a 3D resource in a standard or display mode): uncompressed texels, with a mip +// chain or without. inline bool supports_volume(const D3D12_RESOURCE_DESC& d) { const Element element = element_of(d.Format); return d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D && swizzle_mode(d) == 5 && element.bytes && element.texels == 1 && d.Width && d.Height && d.DepthOrArraySize && d.Width <= 2048 && d.Height <= 2048 && d.DepthOrArraySize <= 2048 && - d.MipLevels == 1 && d.SampleDesc.Count == 1; + d.MipLevels && d.MipLevels <= max_mips && d.SampleDesc.Count == 1; } // A two-dimensional, single-sample texture whose memory this header can address, or a volume @@ -96,8 +97,9 @@ struct Layout { std::array blocks_wide{}, origin_x{}, origin_y{}; std::array x_bits{}, y_bits{}; // in-block byte offset contributed by a coordinate // A volume (supports_volume): its depth, the depth of a thick block, the in-block offset contributed by z, - // and the bytes of one layer of blocks. Its one slice holds every depth layer; a 2D texture keeps 1, 1, 0. - UINT depth = 1, block_depth = 1, blocks_high = 0; + // and the bytes of one layer of blocks, which holds that layer of every mip. Its one slice holds every + // depth layer; a 2D texture keeps 1, 1, 0. + UINT depth = 1, block_depth = 1; std::array z_bits{}; std::uint64_t layer_size = 0; @@ -185,14 +187,22 @@ struct Layout { } } - // A volume in the 4 KiB standard mode, one mip (supports_volume). The 12 address bits of a thick block - // follow the one-pipe rows of GFX10_SW_4K_S3_PATINFO (nibble01 rows 29-33, nibble2 rows 131-135), by - // element size; "0" is a bit inside the element. The block is 2^n texels on each axis, n counting that - // axis in the row (addrlib ComputeThickBlockDimension: Block1K_3d scaled to 4 KiB). Blocks follow in x, - // then y, then z, a layer of pitch x height blocks at a time (Gfx10Lib::ComputeSurfaceAddrFromCoord- - // MacroTiled for a thick, single-mip surface: the slice size times the block depth per layer). + // A volume in the 4 KiB standard mode (supports_volume). The 12 address bits of a thick block follow the + // one-pipe rows of GFX10_SW_4K_S3_PATINFO (nibble01 rows 29-33, nibble2 rows 131-135), by element size; + // "0" is a bit inside the element. The block is 2^n texels on each axis, n counting that axis in the row + // (addrlib ComputeThickBlockDimension: Block1K_3d scaled to 4 KiB). + // + // The volume is stored a layer of blocks (block_depth texels deep) at a time, and each layer holds that + // layer of every mip (Gfx10Lib::ComputeSurfaceInfoMacroTiled and ComputeSurfaceAddrFromCoordMacroTiled + // for a thick surface): first the shared tail block when the chain has one, then the mips from the + // smallest to the largest, each pitch x height blocks in x, then y. Mip sizes round up at every level + // (GetMipSize). A mip is in the tail when it is at most a block wide and half a block high + // (GetMipTailDim: a 4 KiB block halves its height) and at most five mips remain (GetMaxNumMipsInTail for + // a thick 4 KiB block). Tail mip k from the end sits at byte (k << 8) of the tail block; that offset, + // read back as 256-byte micro blocks of Block256_3d, is its origin in x and y. Its z is not moved. void thick(const D3D12_RESOURCE_DESC& d) { + static constexpr UINT micro[5][2] = {{8, 4}, {4, 4}, {4, 4}, {4, 2}, {2, 2}}; // Block256_3d width, height static constexpr const char* rows4k[5] = { "X0X1Z0Y0Z1Y1X2Z2Y2X3Z3Y3", "--X0Z0Y0Z1Y1X1Z2Y2X2Z3Y3", "----X0Y0Z0Y1X1Z1Y2X2Z2Y3", "------X0Z0Y0X1Z1Y1X2Z2Y2", "--------Z0Y0X0Z1Y1X1Z2Y2"}; @@ -221,11 +231,36 @@ struct Layout { if (bit < ys) y_bits[v] |= 1u << y_at[bit]; if (bit < zs) z_bits[v] |= 1u << z_at[bit]; } + const auto shifted = [](UINT v, UINT mip) { return (std::max)(1u, (v + (1u << mip) - 1) >> mip); }; + constexpr UINT tail_mips = 5; first_tail = mips; - blocks_wide[0] = (width + block_width - 1) / block_width; - blocks_high = (height + block_height - 1) / block_height; - layer_size = std::uint64_t{blocks_wide[0]} * blocks_high * block_bytes; + for (UINT mip = 0; mips > 1 && mip < mips; ++mip) + if (shifted(width, mip) <= block_width && shifted(height, mip) <= block_height / 2 && mips - mip <= tail_mips) { + first_tail = mip; + break; + } + std::array size{}; + for (UINT mip = 0; mip < first_tail; ++mip) { + blocks_wide[mip] = (shifted(width, mip) + block_width - 1) / block_width; + size[mip] = std::uint64_t{blocks_wide[mip]} * ((shifted(height, mip) + block_height - 1) / block_height) * block_bytes; + } + std::uint64_t offset = first_tail < mips ? block_bytes : 0; + for (UINT mip = first_tail; mip-- > 0;) { + start[mip] = offset; + offset += size[mip]; + } + layer_size = offset; slice_size = layer_size * ((depth + block_depth - 1) / block_depth); + for (UINT mip = first_tail; mip < mips; ++mip) { + const UINT tail_offset = (tail_mips - 1 - (mip - first_tail)) << 8; + UINT x = 0, y = 0; + for (UINT bit = 0; bit < 2; ++bit) { + y |= ((tail_offset >> (8 + 2 * bit)) & 1) << bit; + x |= ((tail_offset >> (9 + 2 * bit)) & 1) << bit; + } + origin_x[mip] = x * micro[element_log2][0]; + origin_y[mip] = y * micro[element_log2][1]; + } } // Elements a mip holds, with the desktop's mip sizes (rounded down, at least one texel). @@ -238,10 +273,14 @@ struct Layout { // layer of a volume. std::uint64_t address(UINT mip, UINT x, UINT y, UINT slice, UINT z = 0) const { - if (block_depth > 1) // a volume (thick) - return std::uint64_t{z / block_depth} * layer_size + - (std::uint64_t{y / block_height} * blocks_wide[0] + x / block_width) * block_bytes + - (x_bits[x % block_width] | y_bits[y % block_height] | z_bits[z % block_depth]); + if (block_depth > 1) { // a volume (thick) + const std::uint64_t layer = std::uint64_t{z / block_depth} * layer_size + start[mip]; + const UINT in_z = z_bits[z % block_depth]; + if (mip >= first_tail) + return layer + (x_bits[(origin_x[mip] + x) % block_width] | y_bits[(origin_y[mip] + y) % block_height] | in_z); + return layer + (std::uint64_t{y / block_height} * blocks_wide[mip] + x / block_width) * block_bytes + + (x_bits[x % block_width] | y_bits[y % block_height] | in_z); + } const std::uint64_t base = slice * slice_size; if (mip >= first_tail) return base + (x_bits[(origin_x[mip] + x) & 255] | y_bits[(origin_y[mip] + y) & 255]); const std::uint64_t block = std::uint64_t{y / block_height} * blocks_wide[mip] + x / block_width; diff --git a/tests/cmake/startup_gfx10_volume.cmake b/tests/cmake/startup_gfx10_volume.cmake index 2eff66639d..d81d067e33 100644 --- a/tests/cmake/startup_gfx10_volume.cmake +++ b/tests/cmake/startup_gfx10_volume.cmake @@ -1,8 +1,10 @@ -# Volumes in the 4 KiB standard console layout (0x105, one mip; src/startup_stubs/gfx10_layout.h) and the -# slot-70 descriptions and views that use them (src/startup_stubs/address_texture.h), without a device: -# address equations against addrlib's GFX10_SW_4K_S3 rows (Mesa 25.1.0, src/amd/addrlib, MIT), block -# order, distinct addresses, round trips and refusals. The thin run lays each volume out as a 2D array of -# its layers and is the negative control; the addrlib run compares every element address with addrlib +# Volumes in the 4 KiB standard console layout (0x105, with or without a mip chain; +# src/startup_stubs/gfx10_layout.h) and the slot-70 descriptions and views that use them +# (src/startup_stubs/address_texture.h), without a device: address equations against addrlib's +# GFX10_SW_4K_S3 rows (Mesa 25.1.0, src/amd/addrlib, MIT), block order, the mip chain and its tail, +# distinct addresses, round trips and refusals. The thin run lays each volume out as a 2D array of its +# layers and the tail run puts every tail mip at the start of the tail block; both are negative +# controls. The addrlib run compares every element address with addrlib # and skips (77) without it. add_executable(startup_gfx10_volume_check tests/startup_gfx10_volume_check.cpp) target_compile_features(startup_gfx10_volume_check PRIVATE cxx_std_17) @@ -14,5 +16,7 @@ endif() add_test(NAME startup_gfx10_volume COMMAND startup_gfx10_volume_check) add_test(NAME startup_gfx10_volume_thin_control COMMAND startup_gfx10_volume_check --mutate thin) set_tests_properties(startup_gfx10_volume_thin_control PROPERTIES WILL_FAIL TRUE) +add_test(NAME startup_gfx10_volume_tail_control COMMAND startup_gfx10_volume_check --mutate tail) +set_tests_properties(startup_gfx10_volume_tail_control PROPERTIES WILL_FAIL TRUE) add_test(NAME startup_gfx10_volume_addrlib COMMAND startup_gfx10_volume_check --addrlib) set_tests_properties(startup_gfx10_volume_addrlib PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) diff --git a/tests/startup_address_console_check.py b/tests/startup_address_console_check.py index b3ccc8caee..d105cfaa67 100644 --- a/tests/startup_address_console_check.py +++ b/tests/startup_address_console_check.py @@ -1,6 +1,6 @@ """Draw textures published by address (device slot 70) whose texels are in a console layout. - seven textures and two volumes, each drawn once; every pixel of the + seven textures and six volume mips, each drawn once; every pixel of the 512x128 target is compared with the texel the view names; then three held descriptions and one texture whose address is announced as XG rows after it was published @@ -94,25 +94,46 @@ def address(self, mip, x, y): return self.start[mip] + (block << self.log2) + self.in_block(x % self.block_w, y % self.block_h) -# A volume in the 4 KiB standard mode (0x105), one mip: addrlib lays a 3D resource in a standard mode out in -# thick blocks (Gfx10Lib::HwlIsThick). The 12 address bits of a 4-byte element follow the one-pipe row of -# GFX10_SW_4K_S3_PATINFO; the block is 8x16x8 elements, and blocks follow in x, then y, then a layer of -# blocks at a time in z. +# A volume in the 4 KiB standard mode (0x105): addrlib lays a 3D resource in a standard mode out in thick +# blocks (Gfx10Lib::HwlIsThick). The 12 address bits of a 4-byte element follow the one-pipe row of +# GFX10_SW_4K_S3_PATINFO; the block is 8x16x8 elements. The volume is stored a layer of blocks (8 deep) at +# a time, and each layer holds that layer of every mip: the shared tail block first when the chain has +# one, then the mips from the smallest to the largest, blocks in x, then y. Mip sizes round up. A mip is in +# the tail when it is at most 8 wide and 8 high and at most five mips remain; tail mip k from the end sits +# at byte (k << 8) of the tail block, which, read as 4x4x4 micro blocks, is its origin in x and y. THICK_4K_S3 = {4: "0 0 X0 Y0 Z0 Y1 X1 Z1 Y2 X2 Z2 Y3"} class ConsoleVolume: - def __init__(self, width, height, depth, element): + def __init__(self, width, height, depth, element, mips=1): self.width, self.height, self.depth = width, height, depth self.bits = THICK_4K_S3[element].split() self.block = [1 << sum(b[0] == axis for b in self.bits) for axis in "XYZ"] - self.wide, high, layers = (-(-side // block) for side, block in zip((width, height, depth), self.block)) - self.layer = self.wide * high * 4096 - self.bytes = self.layer * layers - - def address(self, x, y, z): bw, bh, bd = self.block - value = (z // bd) * self.layer + ((y // bh) * self.wide + x // bw) * 4096 + size = [(max(1, -(-width // (1 << m))), max(1, -(-height // (1 << m)))) for m in range(mips)] + tail = next((m for m, (w, h) in enumerate(size) if mips > 1 and w <= bw and h <= bh // 2 and mips - m <= 5), + mips) + self.wide, self.start, self.origin = {}, {}, {} + offset = 4096 if tail < mips else 0 + for m in reversed(range(tail)): + self.wide[m] = -(-size[m][0] // bw) + self.start[m] = offset + offset += self.wide[m] * -(-size[m][1] // bh) * 4096 + for m in range(tail, mips): + at = (4 - (m - tail)) << 8 + self.start[m] = 0 + self.origin[m] = (4 * ((at >> 9 & 1) | (at >> 10 & 2)), 4 * ((at >> 8 & 1) | (at >> 9 & 2))) + self.layer = offset + self.bytes = self.layer * -(-depth // bd) + + def address(self, x, y, z, mip=0): + bw, bh, bd = self.block + value = (z // bd) * self.layer + self.start[mip] + if mip in self.origin: + x, y = x + self.origin[mip][0], y + self.origin[mip][1] + else: + value += ((y // bh) * self.wide[mip] + x // bw) * 4096 + x, y = x % bw, y % bh for bit, name in enumerate(self.bits): coordinate = {"X": x % bw, "Y": y % bh, "Z": z % bd}.get(name[0]) if coordinate is not None and (coordinate >> int(name[1:])) & 1: @@ -144,38 +165,51 @@ def bc1_block(mip, x, y): ] -def volume_texel(x, y, z): - return bytes(((7 * x + 1) & 255, (5 * y + 3) & 255, (29 * z + 11) & 255, 255)) +def volume_texel(x, y, z, mip=0): + return bytes(((7 * x + 1) & 255, (5 * y + 3) & 255, (29 * z + 11) & 255, 255 - 16 * mip)) -# name, width, height, depth, format, layout: one mip of RGBA8 in the 4 KiB standard mode, viewed as a -# Texture3D. Each target tile of the texture's width and height draws one depth layer. +# name, width, height, depth, format, layout, mips, viewed mip: RGBA8 in the 4 KiB standard mode, one mip +# viewed as a Texture3D. Each target tile of the viewed mip's width and height draws one depth layer. The +# chains view a mip outside the tail and one inside it. VOLUMES = [ - ("RGBA8 volume 17x17x17 4 KiB standard", 17, 17, 17, RGBA8, 0x105), - ("RGBA8 volume 33x9x18 4 KiB standard", 33, 9, 18, RGBA8, 0x105), + ("RGBA8 volume 17x17x17 4 KiB standard", 17, 17, 17, RGBA8, 0x105, 1, 0), + ("RGBA8 volume 33x9x18 4 KiB standard", 33, 9, 18, RGBA8, 0x105, 1, 0), + ("RGBA8 volume 32x32x32 6 mips, mip 1", 32, 32, 32, RGBA8, 0x105, 6, 1), + ("RGBA8 volume 32x32x32 6 mips, mip 3 in the tail", 32, 32, 32, RGBA8, 0x105, 6, 3), + ("RGBA8 volume 20x24x16 5 mips, mip 1", 20, 24, 16, RGBA8, 0x105, 5, 1), + ("RGBA8 volume 20x24x16 5 mips, mip 3 in the tail", 20, 24, 16, RGBA8, 0x105, 5, 3), ] -def build_volume(width, height, depth): - """Backing bytes of a volume, built from the S3 row above.""" - console = ConsoleVolume(width, height, depth, 4) +def mip_sides(width, height, depth, mip): + return max(1, width >> mip), max(1, height >> mip), max(1, depth >> mip) + + +def build_volume(width, height, depth, mips=1): + """Backing bytes of a volume and its mips, built from the S3 row above.""" + console = ConsoleVolume(width, height, depth, 4, mips) backing = bytearray(console.bytes) seen = set() - for z in range(depth): - for y in range(height): - for x in range(width): - at = console.address(x, y, z) - if at in seen or at + 4 > len(backing): - raise AssertionError(f"oracle address {at:#x} of ({x},{y},{z}) is shared or outside the volume") - seen.add(at) - backing[at:at + 4] = volume_texel(x, y, z) + for mip in range(mips): + w, h, d = mip_sides(width, height, depth, mip) + for z in range(d): + for y in range(h): + for x in range(w): + at = console.address(x, y, z, mip) + if at in seen or at + 4 > len(backing): + raise AssertionError(f"oracle address {at:#x} of mip {mip} ({x},{y},{z}) is shared or outside " + "the volume") + seen.add(at) + backing[at:at + 4] = volume_texel(x, y, z, mip) return backing def check_volume(directory, consumer, backend, case, held=None): - name, width, height, depth, fmt, layout = case + name, width, height, depth, fmt, layout, mips, viewed = case source = directory / "texels.bin" - source.write_bytes(build_volume(width, height, depth)) + source.write_bytes(build_volume(width, height, depth, mips)) + width, height, depth = mip_sides(width, height, depth, viewed) across = -(-TARGET_W // width) hlsl = ("Texture3D t : register(t0);\n" "float4 main(float4 p : SV_Position) : SV_Target {\n" @@ -184,7 +218,7 @@ def check_volume(directory, consumer, backend, case, held=None): f" return t.Load(int4(x % {width}, y % {height}, z, 0));\n}}\n") trap_log = directory / "trap.log" modes = {"X2W_TEST_CONSOLE_VIEW": str(source), "X2W_TRAP_LOG": str(trap_log), - "X2W_TEST_CONSOLE_DESC": f"{width},{height},1,{fmt},{layout},0,{depth}"} + "X2W_TEST_CONSOLE_DESC": f"{case[1]},{case[2]},{mips},{fmt},{layout},{viewed},{case[3]}"} actual = draw_texture(directory, consumer, backend, hlsl, modes, "tex3d") if actual is None: return 77 @@ -204,7 +238,7 @@ def check_volume(directory, consumer, backend, case, held=None): z = (x // width + (y // height) * across) % depth layers.add(z) pixel = actual[4 * (y * TARGET_W + x):4 * (y * TARGET_W + x) + 4] - expect = volume_texel(x % width, y % height, z) + expect = volume_texel(x % width, y % height, z, viewed) if pixel != expect: raise AssertionError(f"{name}: pixel ({x},{y}) layer {z} actual {pixel.hex()} expected {expect.hex()}") if len(layers) != depth: @@ -218,7 +252,7 @@ def check_volume(directory, consumer, backend, case, held=None): # A volume past the size the XG stand-in reports: 64x8x40 RGBA8 is eight blocks across, one down and five # layers of blocks (163,840 bytes); the desktop footprint (40 layers of 8 rows of 256 bytes) rounded to # 64 KiB is 131,072. A volume has one slice, so the footprint is not counted once per layer. -HELD_VOLUME = (("RGBA8 volume 64x8x40 4 KiB standard past the XG size", 64, 8, 40, RGBA8, 0x105), +HELD_VOLUME = (("RGBA8 volume 64x8x40 4 KiB standard past the XG size", 64, 8, 40, RGBA8, 0x105, 1, 0), "console_layout_beyond_xg_size") diff --git a/tests/startup_address_srv.cpp b/tests/startup_address_srv.cpp index 4568540465..0103adabe2 100644 --- a/tests/startup_address_srv.cpp +++ b/tests/startup_address_srv.cpp @@ -1020,7 +1020,7 @@ int draw_volume_address_srvs(ID3D12Device* desktop, void* guest, void* list) bad_clamp.view.Texture3D.ResourceMinLODClamp = 1.0f; invoke(guest, 70, ptr(&desc), ptr(&bad_clamp), cpu); - // 5. Wrong layout (console layout 0x105) + // 5. A console layout (0x105) over the live desktop-layout volume: refused as overlapping_resource D3D12_RESOURCE_DESC bad_layout = desc; bad_layout.Layout = static_cast(0x105); invoke(guest, 70, ptr(&bad_layout), ptr(&v), cpu); diff --git a/tests/startup_address_volume_srv_check.py b/tests/startup_address_volume_srv_check.py index c83b6d5ba8..94e74fb03d 100644 --- a/tests/startup_address_volume_srv_check.py +++ b/tests/startup_address_volume_srv_check.py @@ -38,9 +38,10 @@ def check_refusal_lines(log): + res_base + r" view\{dim=8 fmt=28 map=0x1688 mostmip=1 mips=1 clamp=1\} " + rf"dest={HEX} dest_in_view_heap=1 address={HEX} address_readable=1", - # 5. Wrong layout (0x105) + # 5. A console layout (0x105) over the live desktop-layout volume: the description is one slot 70 + # reads by address, but the address is inside a live resource. prefix - + r"unsupported memory SRV arguments: reason=unsupported_description " + + r"unavailable texture at the supplied base and layout: reason=overlapping_resource " + res_swizzle + r" view\{dim=8 fmt=28 map=0x1688 mostmip=1 mips=1 clamp=0\} " + rf"dest={HEX} dest_in_view_heap=1 address={HEX} address_readable=1", diff --git a/tests/startup_gfx10_volume_check.cpp b/tests/startup_gfx10_volume_check.cpp index 40401a99b2..a7f617195c 100644 --- a/tests/startup_gfx10_volume_check.cpp +++ b/tests/startup_gfx10_volume_check.cpp @@ -1,16 +1,19 @@ -// Checks the volume layout of src/startup_stubs/gfx10_layout.h (a single-mip 3D texture in the 4 KiB -// standard mode, 0x105, which addrlib lays out in thick blocks) without a device: +// Checks the volume layout of src/startup_stubs/gfx10_layout.h (a 3D texture in the 4 KiB standard mode, +// 0x105, which addrlib lays out in thick blocks) without a device: // - the address bit of every x, y and z bit against the one-pipe rows of addrlib's GFX10_SW_4K_S3_PATINFO, // restated below, and the block each element size gives; // - the order of blocks: along x, then y, then a layer of blocks at a time along z, with the sides of // the texture padded to whole blocks; +// - a mip chain: each layer of blocks holds the tail block, then the mips from the smallest to the largest, +// and the tail mips sit at their origins inside the tail block; // - that every element of a volume gets its own bytes inside the texture, and that a tile followed by a -// detile (with padded row and layer pitches) returns the texels it started from; +// detile (with padded row and layer pitches) returns the texels it started from, for every mip; // - the descriptions it takes and refuses, and the slot-70 views it allows on them. // `--addrlib` compares the size and every element address of a set of volumes with // Addr2ComputeSurfaceInfo and Addr2ComputeSurfaceAddrFromCoord (ADDR_RSRC_TEX_3D, ADDR_SW_4KB_S) and // skips (77) when the build has no addrlib. `--mutate thin` lays each volume out as a thin 2D array of -// its depth layers and is the negative control: it must fail. +// its depth layers, and `--mutate tail` puts every mip of the tail at the start of the tail block; both +// are negative controls and must fail. // // Reference: AMD addrlib as Mesa carries it under src/amd/addrlib, at the revision tools/fetch_addrlib.py // pins (Mesa 25.1.0, commit 5c142e46f3f6e752ed745fd48912ebb8fad67145): src/gfx10/gfx10SwizzlePattern.h, @@ -21,6 +24,7 @@ #include "startup_stubs/address_texture.h" #include "startup_stubs/gfx10_layout.h" +#include #include #include #include @@ -29,7 +33,8 @@ namespace { using x2w_startup::gfx10::Layout; int failures = 0; -bool thin = false; // --mutate thin +bool thin = false; // --mutate thin +bool flat_tail = false; // --mutate tail void fail(const std::string& what) { @@ -50,15 +55,18 @@ D3D12_RESOURCE_DESC volume(UINT width, UINT height, UINT depth, DXGI_FORMAT form return d; } -// The layout under test; the control reads the volume as a thin array of its layers. +// The layout under test; the controls read the volume as a thin array of its layers, or move every tail +// mip to the start of the tail block. Layout layout_of(D3D12_RESOURCE_DESC d) { if (thin) d.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; - return Layout(d); + Layout l(d); + for (UINT mip = l.first_tail; flat_tail && mip < l.mips; ++mip) l.origin_x[mip] = l.origin_y[mip] = 0; + return l; } -std::uint64_t at(const Layout& l, UINT x, UINT y, UINT z) +std::uint64_t at(const Layout& l, UINT x, UINT y, UINT z, UINT mip = 0) { - return thin ? l.address(0, x, y, z) : l.address(0, x, y, 0, z); + return thin ? l.address(mip, x, y, z) : l.address(mip, x, y, 0, z); } // One format per element size: 1, 2, 4, 8 and 16 bytes. @@ -111,23 +119,54 @@ void check_block_order() expect("last element", at(l, 16, 16, 16), (2ull * 6 + 1 * 3 + 2) * 4096); } +// 32x32x32 RGBA8 with six mips, in 8x16x8 blocks. Mips 2 to 5 (8x8 and smaller, at most five from the +// end) share the tail block. A layer of blocks holds the tail block, mip 1 (2x1 blocks) and mip 0 (4x2 +// blocks): 11 blocks. The tail mips sit at byte (k << 8) of the tail block for k = 4, 3, 2, 1, read as +// 4x4x4 micro blocks: (0,8), (4,4), (4,0) and (0,4). +void check_mip_chain() +{ + const Layout l = layout_of(volume(32, 32, 32, DXGI_FORMAT_R8G8B8A8_UNORM, 0x105, 6)); + const auto expect = [](const char* what, std::uint64_t got, std::uint64_t want) { + if (got != want) fail(std::string("mip chain: ") + what + " " + std::to_string(got) + ", expected " + std::to_string(want)); + }; + expect("bytes", l.bytes(), 4ull * 11 * 4096); + expect("mip 0", at(l, 0, 0, 0, 0), 3 * 4096); + expect("mip 0 next row of blocks", at(l, 0, 16, 0, 0), 7 * 4096); + expect("mip 0 next layer of blocks", at(l, 0, 0, 8, 0), 14 * 4096); + expect("mip 1", at(l, 0, 0, 0, 1), 4096); + expect("mip 1 next block in x", at(l, 8, 0, 0, 1), 2 * 4096); + expect("mip 1 next layer of blocks", at(l, 0, 0, 8, 1), 12 * 4096); + expect("mip 2 at (0,8)", at(l, 0, 0, 0, 2), 0x800); // y 8: Y3, bit 11 + expect("mip 3 at (4,4)", at(l, 0, 0, 0, 3), 0x300); // x 4: X2, bit 9; y 4: Y2, bit 8 + expect("mip 4 at (4,0)", at(l, 0, 0, 0, 4), 0x200); + expect("mip 5 at (0,4)", at(l, 0, 0, 0, 5), 0x100); + expect("mip 2 next layer of blocks", at(l, 0, 0, 8, 2), 11 * 4096 + 0x800); +} + struct Shape { UINT width, height, depth; DXGI_FORMAT format; + UINT mips = 1; }; const Shape shapes[] = { {17, 17, 17, DXGI_FORMAT_R16G16B16A16_FLOAT}, {32, 32, 32, DXGI_FORMAT_R8G8B8A8_UNORM}, {33, 33, 33, DXGI_FORMAT_R16G16B16A16_FLOAT}, {32, 32, 32, DXGI_FORMAT_A8_UNORM}, {16, 16, 8, DXGI_FORMAT_R16_FLOAT}, {16, 16, 16, DXGI_FORMAT_R8G8_UNORM}, {32, 32, 32, DXGI_FORMAT_R10G10B10A2_UNORM}, {5, 3, 7, DXGI_FORMAT_R32G32B32A32_FLOAT}, {1, 1, 2, DXGI_FORMAT_R8_UNORM}, {64, 8, 40, DXGI_FORMAT_R32_FLOAT}, + // Mip chains: whole and partial, a tail that starts at mip 0, a chain with no tail, odd sides. + {32, 32, 32, DXGI_FORMAT_R8_UNORM, 6}, {32, 32, 32, DXGI_FORMAT_R8G8B8A8_UNORM, 6}, + {64, 64, 32, DXGI_FORMAT_R16G16_FLOAT, 7}, {128, 128, 128, DXGI_FORMAT_R16G16B16A16_FLOAT, 8}, + {16, 16, 16, DXGI_FORMAT_R32G32B32A32_FLOAT, 5}, {8, 4, 8, DXGI_FORMAT_R8G8B8A8_UNORM, 4}, + {64, 64, 64, DXGI_FORMAT_R16_FLOAT, 2}, {33, 17, 9, DXGI_FORMAT_R16G16B16A16_FLOAT, 6}, + {4, 4, 64, DXGI_FORMAT_R8_UNORM, 7}, {256, 32, 8, DXGI_FORMAT_R16_FLOAT, 9}, }; void check_distinct_and_round_trip() { for (const Shape& s : shapes) { - const D3D12_RESOURCE_DESC d = volume(s.width, s.height, s.depth, s.format); + const D3D12_RESOURCE_DESC d = volume(s.width, s.height, s.depth, s.format, 0x105, s.mips); const std::string name = std::to_string(s.width) + "x" + std::to_string(s.height) + "x" + std::to_string(s.depth) + - " format " + std::to_string(s.format); + " format " + std::to_string(s.format) + " mips " + std::to_string(s.mips); if (!x2w_startup::gfx10::supports(d)) { fail(name + ": refused"); continue; @@ -136,32 +175,39 @@ void check_distinct_and_round_trip() const UINT e = l.bytes_per_element; const std::uint64_t size = l.bytes(); std::vector used(static_cast(size)); + // Every element of every mip has its own bytes. bool clash = false; - for (UINT z = 0; z < s.depth; ++z) - for (UINT y = 0; y < s.height; ++y) - for (UINT x = 0; x < s.width; ++x) { - const std::uint64_t a = at(l, x, y, z); - if (a % e || a + e > size) { - clash = true; - continue; + for (UINT mip = 0; mip < s.mips; ++mip) + for (UINT z = 0; z < l.layers(mip); ++z) + for (UINT y = 0; y < l.rows(mip); ++y) + for (UINT x = 0; x < l.columns(mip); ++x) { + const std::uint64_t a = at(l, x, y, z, mip); + if (a % e || a + e > size) { + clash = true; + continue; + } + if (used[static_cast(a)]) clash = true; + used[static_cast(a)] = 1; } - if (used[static_cast(a)]) clash = true; - used[static_cast(a)] = 1; - } if (clash) fail(name + ": elements share bytes or fall outside the texture"); if (thin) continue; - const std::size_t pitch = (std::size_t{s.width} * e + 255) & ~std::size_t{255}, layer = pitch * (s.height + 1); - std::vector rows(layer * s.depth), back(rows.size()), tiled(static_cast(size)); - for (std::size_t i = 0; i < rows.size(); ++i) rows[i] = static_cast(i * 131 + 7); - l.tile(0, 0, tiled.data(), rows.data(), pitch, layer); - l.detile(0, 0, tiled.data(), back.data(), pitch, layer); - for (UINT z = 0; z < s.depth; ++z) - for (UINT y = 0; y < s.height; ++y) - if (std::memcmp(&rows[z * layer + y * pitch], &back[z * layer + y * pitch], std::size_t{s.width} * e)) { - fail(name + ": round trip differs at layer " + std::to_string(z) + " row " + std::to_string(y)); - z = s.depth; - break; - } + std::vector tiled(static_cast(size)); + for (UINT mip = 0; mip < s.mips; ++mip) { + const UINT w = l.columns(mip), h = l.rows(mip), n = l.layers(mip); + const std::size_t pitch = (std::size_t{w} * e + 255) & ~std::size_t{255}, layer = pitch * (h + 1); + std::vector rows(layer * n), back(rows.size()); + for (std::size_t i = 0; i < rows.size(); ++i) rows[i] = static_cast(i * 131 + 7 + mip); + l.tile(mip, 0, tiled.data(), rows.data(), pitch, layer); + l.detile(mip, 0, tiled.data(), back.data(), pitch, layer); + for (UINT z = 0; z < n; ++z) + for (UINT y = 0; y < h; ++y) + if (std::memcmp(&rows[z * layer + y * pitch], &back[z * layer + y * pitch], std::size_t{w} * e)) { + fail(name + ": round trip differs in mip " + std::to_string(mip) + " at layer " + std::to_string(z) + + " row " + std::to_string(y)); + z = n; + break; + } + } } } @@ -173,8 +219,12 @@ void check_descriptions() const D3D12_RESOURCE_DESC good = volume(32, 32, 32, DXGI_FORMAT_R8G8B8A8_UNORM); supported("4 KiB standard RGBA8", good, true); D3D12_RESOURCE_DESC d = good; - d.MipLevels = 2; - supported("two mips", d, false); + d.MipLevels = 6; + supported("a whole mip chain", d, true); + d.MipLevels = 16; + supported("more mips than a layout holds", d, false); + d.MipLevels = 0; + supported("no mips", d, false); supported("BC1", volume(32, 32, 32, DXGI_FORMAT_BC1_UNORM), false); supported("BC7", volume(32, 32, 32, DXGI_FORMAT_BC7_UNORM), false); supported("4 KiB display", volume(32, 32, 32, DXGI_FORMAT_R8G8B8A8_UNORM, 0x106), false); @@ -203,7 +253,10 @@ void check_descriptions() address("BC7", volume(32, 32, 32, DXGI_FORMAT_BC7_UNORM), false); d = good; d.MipLevels = 6; - address("mip chain", d, false); + address("mip chain", d, true); + d.MipLevels = 7; + address("more mips than the sides allow", d, false); + address("mips the depth allows", volume(4, 4, 64, DXGI_FORMAT_R8_UNORM, 0x105, 7), true); D3D12_SHADER_RESOURCE_VIEW_DESC v{}; v.Format = DXGI_FORMAT_R8G8B8A8_UNORM; @@ -215,6 +268,14 @@ void check_descriptions() if (!x2w_startup::address_view_fits(good, v)) fail("view: one mip"); v.Texture3D.MostDetailedMip = 1; if (x2w_startup::address_view_fits(good, v)) fail("view: mip past the volume"); + D3D12_RESOURCE_DESC chain = good; + chain.MipLevels = 6; + v.Texture3D.MostDetailedMip = 2; + v.Texture3D.MipLevels = 4; + if (!x2w_startup::address_view_fits(chain, v)) fail("view: the last four mips of a chain"); + v.Texture3D.MipLevels = 5; + if (x2w_startup::address_view_fits(chain, v)) fail("view: mips past the chain"); + v.Texture3D.MipLevels = 1; v.Texture3D.MostDetailedMip = 0; D3D12_RESOURCE_DESC typeless = good; typeless.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS; @@ -269,11 +330,18 @@ int addrlib_check() if (AddrCreate(&create, &created) != ADDR_OK) return 1; const AddrFormat addr_formats[5] = {ADDR_FMT_8, ADDR_FMT_16, ADDR_FMT_8_8_8_8, ADDR_FMT_16_16_16_16, ADDR_FMT_32_32_32_32}; std::vector cases; - for (const Shape& s : shapes) cases.push_back(volume(s.width, s.height, s.depth, s.format)); + for (const Shape& s : shapes) cases.push_back(volume(s.width, s.height, s.depth, s.format, 0x105, s.mips)); for (UINT size = 0; size < 5; ++size) for (UINT w : {1u, 3u, 9u, 24u}) for (UINT h : {1u, 7u, 17u}) for (UINT dep : {1u, 5u, 18u}) cases.push_back(volume(w, h, dep, by_size[size])); + // Every mip count of a set of chains, so that each mip in turn is the first in the tail or the last + // outside it. + constexpr UINT chains[4][3] = {{64, 64, 64}, {40, 24, 12}, {17, 33, 5}, {8, 8, 32}}; + for (UINT size = 0; size < 5; ++size) + for (const auto& side : chains) + for (UINT mips = 2; ((std::max)({side[0], side[1], side[2]}) >> (mips - 1)) != 0; ++mips) + cases.push_back(volume(side[0], side[1], side[2], by_size[size], 0x105, mips)); unsigned compared = 0, elements = 0, mismatches = 0; for (const D3D12_RESOURCE_DESC& d : cases) { const Layout l(d); @@ -291,47 +359,49 @@ int addrlib_check() in.width = l.width; in.height = l.height; in.numSlices = l.depth; - in.numMipLevels = 1; + in.numMipLevels = l.mips; in.numSamples = 1; in.numFrags = 1; ++compared; char name[64]; - std::snprintf(name, sizeof name, "%ux%ux%u %u-byte", l.width, l.height, l.depth, l.bytes_per_element); + std::snprintf(name, sizeof name, "%ux%ux%u %u-byte %u mips", l.width, l.height, l.depth, l.bytes_per_element, l.mips); if (Addr2ComputeSurfaceInfo(created.hLib, &in, &out) != ADDR_OK || out.surfSize != l.bytes()) { if (++mismatches <= 12) std::printf("FAIL %s: size 0x%llx, addrlib 0x%llx\n", name, static_cast(l.bytes()), static_cast(out.surfSize)); continue; } - for (UINT z = 0; z < l.depth; ++z) - for (UINT y = 0; y < l.height; ++y) - for (UINT x = 0; x < l.width; ++x) { - ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT ain{}; - ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT aout{}; - ain.size = sizeof ain; - aout.size = sizeof aout; - ain.x = x; - ain.y = y; - ain.slice = z; - ain.swizzleMode = ADDR_SW_4KB_S; - ain.flags.texture = 1; - ain.resourceType = ADDR_RSRC_TEX_3D; - ain.bpp = in.bpp; - ain.unalignedWidth = l.width; - ain.unalignedHeight = l.height; - ain.numSlices = l.depth; - ain.numMipLevels = 1; - ain.numSamples = 1; - ain.numFrags = 1; - ain.pitchInElement = out.pitch; - ++elements; - const std::uint64_t mine = l.address(0, x, y, 0, z); - if (Addr2ComputeSurfaceAddrFromCoord(created.hLib, &ain, &aout) != ADDR_OK || aout.addr != mine) { - if (++mismatches <= 12) - std::printf("FAIL %s (%u,%u,%u): 0x%llx, addrlib 0x%llx\n", name, x, y, z, - static_cast(mine), static_cast(aout.addr)); + for (UINT mip = 0; mip < l.mips; ++mip) + for (UINT z = 0; z < l.layers(mip); ++z) + for (UINT y = 0; y < l.rows(mip); ++y) + for (UINT x = 0; x < l.columns(mip); ++x) { + ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT ain{}; + ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT aout{}; + ain.size = sizeof ain; + aout.size = sizeof aout; + ain.x = x; + ain.y = y; + ain.slice = z; + ain.mipId = mip; + ain.swizzleMode = ADDR_SW_4KB_S; + ain.flags.texture = 1; + ain.resourceType = ADDR_RSRC_TEX_3D; + ain.bpp = in.bpp; + ain.unalignedWidth = l.width; + ain.unalignedHeight = l.height; + ain.numSlices = l.depth; + ain.numMipLevels = l.mips; + ain.numSamples = 1; + ain.numFrags = 1; + ain.pitchInElement = out.pitch; + ++elements; + const std::uint64_t mine = l.address(mip, x, y, 0, z); + if (Addr2ComputeSurfaceAddrFromCoord(created.hLib, &ain, &aout) != ADDR_OK || aout.addr != mine) { + if (++mismatches <= 12) + std::printf("FAIL %s mip %u (%u,%u,%u): 0x%llx, addrlib 0x%llx\n", name, mip, x, y, z, + static_cast(mine), static_cast(aout.addr)); + } } - } } AddrDestroy(created.hLib); std::printf("startup_gfx10_volume --addrlib: %u volumes, %u element addresses compared, %u mismatches (Mesa 25.1.0 addrlib, " @@ -343,20 +413,23 @@ int addrlib_check() int main(int argc, char** argv) { if (argc == 2 && std::strcmp(argv[1], "--addrlib") == 0) return addrlib_check(); - thin = argc == 3 && std::strcmp(argv[1], "--mutate") == 0 && std::strcmp(argv[2], "thin") == 0; - if (argc != 1 && !thin) { - std::printf("usage: startup_gfx10_volume_check [--addrlib | --mutate thin]\n"); + const bool mutate = argc == 3 && std::strcmp(argv[1], "--mutate") == 0; + thin = mutate && std::strcmp(argv[2], "thin") == 0; + flat_tail = mutate && std::strcmp(argv[2], "tail") == 0; + if (argc != 1 && !thin && !flat_tail) { + std::printf("usage: startup_gfx10_volume_check [--addrlib | --mutate thin | --mutate tail]\n"); return 2; } check_equations(); check_block_order(); + check_mip_chain(); check_distinct_and_round_trip(); check_descriptions(); if (failures) { std::printf("startup_gfx10_volume: %d failures\n", failures); return 1; } - std::printf("startup_gfx10_volume: PASS (5 element sizes, block order, %zu round trips, 15 layouts, 6 address descriptions, " - "7 views)\n", sizeof(shapes) / sizeof(shapes[0])); + std::printf("startup_gfx10_volume: PASS (5 element sizes, block order, a mip chain, %zu volumes round-tripped mip by mip, " + "17 layouts, 8 address descriptions, 9 views)\n", sizeof(shapes) / sizeof(shapes[0])); return 0; }