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
16 changes: 16 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -16633,6 +16633,22 @@ which then reads another mip's texels. A chain whose layout runs past the size t
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.

Block-compressed volumes are read too. addrlib turns the texel sides of a BC volume into 4x4 blocks
before it lays the volume out, and does not divide the depth: the volume is the volume of its blocks,
each one depth layer deep, with every mip size counted in blocks from there. `startup_gfx10_volume`
checks that BC1 64 by 64 by 16 with five mips and BC7 48 by 20 by 9 with three mips take, element for
element, the addresses of the 8-byte and 16-byte volumes of their blocks, and adds the distinct bytes
and round trips of seven BC volumes (BC1 to BC7, with and without a chain, sides that are not powers
of two). `startup_gfx10_volume_bc_control` sizes a BC volume by its texel sides instead and must fail;
it fails four checks. `startup_gfx10_volume_addrlib`, passing each BC format to addrlib as itself, now
compares every mip count of four chains for each of BC1 to BC7 too: 501 volumes and 13,205,290
element addresses with 0 mismatches.

`startup_address_console_{warp,hardware}` draws three BC1 volume mips: 48 by 40 by 12 with one mip,
and mips 1 and 3 (the second in the tail) of 64 by 64 by 8 with five mips. Each block is one solid
colour, and all 65,536 pixels of each must match. A local mutation that sizes the thick layout by
texels instead of blocks, run once, fails it on the first BC 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)$'
Expand Down
19 changes: 12 additions & 7 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -3566,9 +3566,13 @@ texels and BC1 to BC7, whose largest mip must then be whole 4x4 blocks). The vie


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
at most 2048 texels on each side 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 across and down; the depth is any), with
one mip or a mip chain its largest side (depth included) allows, viewed as a Texture3D whose mips fit
the chain. A block-compressed volume is laid out as the volume of its 4x4 blocks, each one depth layer
deep: the sides are rounded up to whole blocks first, and every mip size after that is counted in
blocks (`ElemLib::AdjustSurfaceInfo`), so a mip whose texel side is not a multiple of 4 can be a block
wider in the layout than in the view. 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 the volume is stored a layer of blocks (one block deep) at a time. Each layer
Expand All @@ -3580,7 +3584,7 @@ read as 256-byte micro blocks, gives its origin in x and y (`ComputeSurfaceInfoM
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 or with a block-compressed format, multisampled textures, the XOR swizzle modes and
other layout, multisampled textures, the XOR swizzle modes and
every other layout value. The texels must be readable and span
at most 64 MiB.

Expand Down Expand Up @@ -3621,9 +3625,10 @@ 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 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.
(`startup_gfx10_volume_addrlib`: every element address of every mip of 501 volumes, 115 of the uncompressed ones
with a mip chain, and 196 block-compressed ones, every mip count of four chains for each of BC1
to BC7). Only BC1 volumes are drawn. Volumes in the other modes are not handled; they stay
refused.

Log lines (stderr and `X2W_TRAP_LOG`):

Expand Down
16 changes: 9 additions & 7 deletions src/startup_stubs/gfx10_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ 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): uncompressed texels, with a mip
// chain or without.
// (Gfx10Lib::HwlIsThick: a 3D resource in a standard or display mode), with a mip chain or without. A
// block-compressed element is a 4x4 block of one depth layer.
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 &&
return d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D && swizzle_mode(d) == 5 && element.bytes &&
d.Width && d.Height && d.DepthOrArraySize && d.Width <= 2048 && d.Height <= 2048 && d.DepthOrArraySize <= 2048 &&
d.MipLevels && d.MipLevels <= max_mips && d.SampleDesc.Count == 1;
}
Expand Down Expand Up @@ -228,7 +228,8 @@ struct Layout {
// 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
// (GetMipSize), in elements: a block-compressed volume is first rounded up to whole 4x4 blocks
// (ElemLib::AdjustSurfaceInfo), and its depth is not divided. 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.
Expand Down Expand Up @@ -264,17 +265,18 @@ struct Layout {
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); };
const UINT columns0 = (width + texels - 1) / texels, rows0 = (height + texels - 1) / texels;
constexpr UINT tail_mips = 5;
first_tail = mips;
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) {
if (shifted(columns0, mip) <= block_width && shifted(rows0, 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;
blocks_wide[mip] = (shifted(columns0, mip) + block_width - 1) / block_width;
size[mip] = std::uint64_t{blocks_wide[mip]} * ((shifted(rows0, 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;) {
Expand Down
12 changes: 8 additions & 4 deletions tests/cmake/startup_gfx10_volume.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Volumes in the 4 KiB standard console layout (0x105, with or without a mip chain;
# Volumes in the 4 KiB standard console layout (0x105, with or without a mip chain, uncompressed or
# block-compressed;
# 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
# block-compressed volumes against the volume of their blocks, distinct addresses, round trips and
# refusals. The thin run lays each volume out as a 2D array of its layers, the tail run puts every tail
# mip at the start of the tail block, and the bc run sizes a block-compressed volume by its texel sides;
# all three 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 @@ -18,5 +20,7 @@ add_test(NAME startup_gfx10_volume_thin_control COMMAND startup_gfx10_volume_che
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_bc_control COMMAND startup_gfx10_volume_check --mutate bc)
set_tests_properties(startup_gfx10_volume_bc_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)
65 changes: 44 additions & 21 deletions tests/startup_address_console_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Draw textures published by address (device slot 70) whose texels are in a console layout.
<consumer> <backend> fourteen textures, three cubes and six volume mips, each drawn once; every
<consumer> <backend> fourteen textures, three cubes and nine 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
Expand Down Expand Up @@ -121,21 +121,27 @@ def address(self, mip, x, y):


# 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"}
# blocks (Gfx10Lib::HwlIsThick). The 12 address bits of an element follow the one-pipe row of
# GFX10_SW_4K_S3_PATINFO for its size; the block is 8x16x8 elements of 4 bytes, or 8x8x8 of 8. 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 a block wide and half a block 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 256-byte
# micro blocks (4x4x4 elements of 4 bytes, 4x2x4 of 8), is its origin in x and y. A BC1 volume is the volume
# of its 4x4 blocks, 8-byte elements one depth layer each: the sides are first rounded up to whole blocks,
# and every mip size after that is in blocks.
THICK_4K_S3 = {4: "0 0 X0 Y0 Z0 Y1 X1 Z1 Y2 X2 Z2 Y3", 8: "0 0 0 X0 Z0 Y0 X1 Z1 Y1 X2 Z2 Y2"}
MICRO_3D = {4: (4, 4), 8: (4, 2)}


class ConsoleVolume:
def __init__(self, width, height, depth, element, mips=1):
def __init__(self, width, height, depth, element, mips=1, texels=1):
width, height = -(-width // texels), -(-height // texels)
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"]
bw, bh, bd = self.block
mw, mh = MICRO_3D[element]
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)
Expand All @@ -148,7 +154,7 @@ def __init__(self, width, height, depth, element, mips=1):
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.origin[m] = (mw * ((at >> 9 & 1) | (at >> 10 & 2)), mh * ((at >> 8 & 1) | (at >> 9 & 2)))
self.layer = offset
self.bytes = self.layer * -(-depth // bd)

Expand Down Expand Up @@ -205,8 +211,13 @@ 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, 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
def volume_bc1_block(x, y, z, mip=0):
"""The block of BC1 volume block (x, y) of layer z: one colour, which differs between neighbours."""
return bc1_block(mip, x, y + 3 * z)


# name, width, height, depth, format, layout, mips, viewed mip: RGBA8 or BC1 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, 1, 0),
Expand All @@ -215,36 +226,48 @@ def volume_texel(x, y, z, mip=0):
("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),
("BC1 volume 48x40x12 4 KiB standard", 48, 40, 12, BC1, 0x105, 1, 0),
("BC1 volume 64x64x8 5 mips, mip 1", 64, 64, 8, BC1, 0x105, 5, 1),
("BC1 volume 64x64x8 5 mips, mip 3 in the tail", 64, 64, 8, BC1, 0x105, 5, 3),
]


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)
def volume_colour(fmt, x, y, z, mip):
"""The RGBA8 colour a correct detile shows at texel (x, y, z) of a mip."""
return volume_bc1_block(x // 4, y // 4, z, mip)[1] if fmt == BC1 else volume_texel(x, y, z, mip)


def build_volume(width, height, depth, mips=1, fmt=RGBA8):
"""Backing bytes of a volume and its mips, built from the S3 rows above."""
texels, element = (4, 8) if fmt == BC1 else (1, 4)
console = ConsoleVolume(width, height, depth, element, mips, texels)
backing = bytearray(console.bytes)
seen = set()
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):
for y in range(-(-h // texels)):
for x in range(-(-w // texels)):
at = console.address(x, y, z, mip)
if at in seen or at + 4 > len(backing):
if at in seen or at + element > 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)
if fmt == BC1:
backing[at:at + 8] = volume_bc1_block(x, y, z, mip)[0]
else:
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, mips, viewed = case
source = directory / "texels.bin"
source.write_bytes(build_volume(width, height, depth, mips))
source.write_bytes(build_volume(width, height, depth, mips, fmt))
width, height, depth = mip_sides(width, height, depth, viewed)
across = -(-TARGET_W // width)
hlsl = ("Texture3D<float4> t : register(t0);\n"
Expand Down Expand Up @@ -274,7 +297,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, viewed)
expect = volume_colour(fmt, 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:
Expand Down
7 changes: 4 additions & 3 deletions tests/startup_gfx10_layout_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ void check_refusals()
refused("linear volume", d);
d = good; d.Layout = static_cast<D3D12_TEXTURE_LAYOUT>(0x115); refused("XOR mode", d);
d = good; d.Layout = static_cast<D3D12_TEXTURE_LAYOUT>(0x209); refused("layout outside 0x1xx", d);
d = good; d.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D; refused("volume", d);
d = good; d.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D;
d.Layout = static_cast<D3D12_TEXTURE_LAYOUT>(0x109); refused("volume outside 0x105", d);
d = good; d.SampleDesc.Count = 4; refused("multisampled", d);
d = good; d.Format = DXGI_FORMAT_R32G32B32_FLOAT; refused("12-byte texels", d);
d = good; d.MipLevels = 16; refused("16 mips", d);
Expand Down Expand Up @@ -285,9 +286,9 @@ void check_address_textures()
d = texture(256, 256, 1, 1, DXGI_FORMAT_BC7_UNORM, 0x105);
d.SampleDesc.Count = 2;
expect("multisampled", d, false);
d = texture(256, 256, 1, 1, DXGI_FORMAT_BC7_UNORM, 0x105);
d = texture(256, 256, 1, 1, DXGI_FORMAT_BC7_UNORM, 0x109);
d.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D;
expect("volume", d, false);
expect("volume outside 0x105", d, false);
expect("BC1 width not whole blocks", texture(126, 128, 1, 1, DXGI_FORMAT_BC1_UNORM, 0x105), false);
expect("BC1 height not whole blocks", texture(128, 126, 1, 1, DXGI_FORMAT_BC1_UNORM, 0x10a), false);
expect("RGBA8 odd sides", texture(257, 129, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0x106), true);
Expand Down
Loading
Loading