Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -16589,7 +16589,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
Expand All @@ -16613,6 +16613,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)$'
Expand Down
28 changes: 18 additions & 10 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -3565,17 +3565,23 @@ no target, depth or unordered-access flag, and a format with a known element siz
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 1D, 2D or 2D-array view must match the texture's dimension and fit the mip and slice ranges. A cube view is taken on a 2D array of exactly six slices (the faces, +X to -Z) and is bound where a translation's manifest declares `texcube`; `tools/startup/gfx2hlsl.py` does not emit that kind yet, because it refuses `dim:SQ_RSRC_IMG_CUBE`. 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`
without a live texture, cube views of other arrays, 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
Expand Down Expand Up @@ -3615,8 +3621,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`):

Expand Down Expand Up @@ -3777,7 +3784,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`
Expand Down
4 changes: 3 additions & 1 deletion src/startup_stubs/address_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ inline bool console_address_texture(const D3D12_RESOURCE_DESC& r)
r.DepthOrArraySize > D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION ||
// The draw uploads a one-dimensional texture only when it is not an array (d3d12_draw.inl).
(r.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE1D && r.DepthOrArraySize != 1) ||
!((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))
Expand Down
73 changes: 56 additions & 17 deletions src/startup_stubs/gfx10_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,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, a one-dimensional
Expand Down Expand Up @@ -111,8 +112,9 @@ struct Layout {
std::array<UINT, max_mips> row_pitch{}; // elements per row of a linear mip
std::array<UINT, 256> 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<UINT, 256> z_bits{};
std::uint64_t layer_size = 0;

Expand Down Expand Up @@ -217,14 +219,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"};
Expand Down Expand Up @@ -253,11 +263,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<std::uint64_t, max_mips> 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).
Expand All @@ -270,10 +305,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 (is_linear) return base + start[mip] + (std::uint64_t{y} * row_pitch[mip] + x) * bytes_per_element;
if (mip >= first_tail) return base + (x_bits[(origin_x[mip] + x) & 255] | y_bits[(origin_y[mip] + y) & 255]);
Expand Down
14 changes: 9 additions & 5 deletions tests/cmake/startup_gfx10_volume.cmake
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Loading
Loading