diff --git a/docs/experiments.md b/docs/experiments.md index 6c30d84af6..1501bd208a 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -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)$' diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index b5e2e009fd..4602a691fd 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -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 @@ -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. @@ -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`): diff --git a/src/startup_stubs/gfx10_layout.h b/src/startup_stubs/gfx10_layout.h index f07d39f743..38cf1a2f40 100644 --- a/src/startup_stubs/gfx10_layout.h +++ b/src/startup_stubs/gfx10_layout.h @@ -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; } @@ -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. @@ -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 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;) { diff --git a/tests/cmake/startup_gfx10_volume.cmake b/tests/cmake/startup_gfx10_volume.cmake index d81d067e33..988e462925 100644 --- a/tests/cmake/startup_gfx10_volume.cmake +++ b/tests/cmake/startup_gfx10_volume.cmake @@ -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) @@ -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) diff --git a/tests/startup_address_console_check.py b/tests/startup_address_console_check.py index 10e07f388d..53bde47822 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. - fourteen textures, three cubes and six volume mips, each drawn once; every + 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 @@ -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) @@ -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) @@ -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), @@ -215,6 +226,9 @@ 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), ] @@ -222,29 +236,38 @@ 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 t : register(t0);\n" @@ -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: diff --git a/tests/startup_gfx10_layout_check.cpp b/tests/startup_gfx10_layout_check.cpp index f0d54e13c1..4ea0f8d657 100644 --- a/tests/startup_gfx10_layout_check.cpp +++ b/tests/startup_gfx10_layout_check.cpp @@ -227,7 +227,8 @@ void check_refusals() refused("linear volume", d); d = good; d.Layout = static_cast(0x115); refused("XOR mode", d); d = good; d.Layout = static_cast(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(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); @@ -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); diff --git a/tests/startup_gfx10_volume_check.cpp b/tests/startup_gfx10_volume_check.cpp index a7f617195c..17c9ba4156 100644 --- a/tests/startup_gfx10_volume_check.cpp +++ b/tests/startup_gfx10_volume_check.cpp @@ -6,14 +6,16 @@ // 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; +// - a block-compressed volume: laid out as the uncompressed volume of its 4x4 blocks, one depth layer each; // - 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, 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 `--mutate tail` puts every mip of the tail at the start of the tail block; both -// are negative controls and must fail. +// its depth layers, `--mutate tail` puts every mip of the tail at the start of the tail block, and +// `--mutate bc` sizes a block-compressed volume's blocks and mips by its texel sides instead of its 4x4 +// blocks; all three 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, @@ -35,6 +37,7 @@ using x2w_startup::gfx10::Layout; int failures = 0; bool thin = false; // --mutate thin bool flat_tail = false; // --mutate tail +bool bc_texels = false; // --mutate bc void fail(const std::string& what) { @@ -60,6 +63,15 @@ D3D12_RESOURCE_DESC volume(UINT width, UINT height, UINT depth, DXGI_FORMAT form Layout layout_of(D3D12_RESOURCE_DESC d) { if (thin) d.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + const x2w_startup::gfx10::Element element = x2w_startup::gfx10::element_of(d.Format); + if (bc_texels && element.texels > 1) { + // The same volume with an uncompressed element of the block's size: blocks and mips are sized + // by the texel sides, while the elements visited stay the 4x4 blocks. + d.Format = element.bytes == 8 ? DXGI_FORMAT_R16G16B16A16_UNORM : DXGI_FORMAT_R32G32B32A32_UINT; + Layout l(d); + l.texels = element.texels; + return l; + } 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; @@ -143,6 +155,34 @@ void check_mip_chain() expect("mip 2 next layer of blocks", at(l, 0, 0, 8, 2), 11 * 4096 + 0x800); } +// A block-compressed volume is the volume of its 4x4 blocks: BC1 64x64x16 with five mips takes the +// addresses of an 8-byte 16x16x16 volume with five mips, and BC7 48x20x9 with three mips those of a +// 16-byte 12x5x9 volume with three mips, element for element. +void check_block_compressed() +{ + struct Pair { + D3D12_RESOURCE_DESC bc, blocks; + }; + const Pair pairs[] = { + {volume(64, 64, 16, DXGI_FORMAT_BC1_UNORM, 0x105, 5), volume(16, 16, 16, DXGI_FORMAT_R16G16B16A16_UNORM, 0x105, 5)}, + {volume(48, 20, 9, DXGI_FORMAT_BC7_UNORM, 0x105, 3), volume(12, 5, 9, DXGI_FORMAT_R32G32B32A32_UINT, 0x105, 3)}, + }; + for (const Pair& pair : pairs) { + const Layout bc = layout_of(pair.bc), blocks = layout_of(pair.blocks); + const std::string name = "block-compressed " + std::to_string(pair.bc.Width) + "x" + std::to_string(pair.bc.Height); + if (bc.bytes() != blocks.bytes()) fail(name + ": size " + std::to_string(bc.bytes())); + bool same = true; + for (UINT mip = 0; mip < bc.mips; ++mip) { + if (bc.columns(mip) < blocks.columns(mip) || bc.rows(mip) < blocks.rows(mip) || bc.layers(mip) != blocks.layers(mip)) + same = false; + for (UINT z = 0; z < blocks.layers(mip); ++z) + for (UINT y = 0; y < blocks.rows(mip); ++y) + for (UINT x = 0; x < blocks.columns(mip); ++x) same = same && at(bc, x, y, z, mip) == at(blocks, x, y, z, mip); + } + if (!same) fail(name + ": an element differs from the uncompressed volume of its blocks"); + } +} + struct Shape { UINT width, height, depth; DXGI_FORMAT format; @@ -159,6 +199,12 @@ const Shape shapes[] = { {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}, + // Block-compressed volumes: 8- and 16-byte blocks, with and without a chain, sides that are not + // powers of two, and mips smaller than a block. + {64, 64, 16, DXGI_FORMAT_BC1_UNORM, 5}, {32, 32, 32, DXGI_FORMAT_BC7_UNORM, 6}, + {12, 20, 9, DXGI_FORMAT_BC5_UNORM, 5}, {256, 256, 8, DXGI_FORMAT_BC3_UNORM, 9}, + {4, 4, 4, DXGI_FORMAT_BC4_UNORM, 3}, {128, 128, 128, DXGI_FORMAT_BC5_SNORM, 8}, + {40, 8, 3, DXGI_FORMAT_BC6H_UF16, 1}, }; void check_distinct_and_round_trip() @@ -225,8 +271,8 @@ void check_descriptions() 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("BC1", volume(32, 32, 32, DXGI_FORMAT_BC1_UNORM), true); + supported("BC7 with a mip chain", volume(32, 32, 32, DXGI_FORMAT_BC7_UNORM, 0x105, 6), true); 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); @@ -250,7 +296,9 @@ void check_descriptions() 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); + address("BC7", volume(32, 32, 32, DXGI_FORMAT_BC7_UNORM), true); + address("BC1 not whole blocks wide", volume(30, 32, 32, DXGI_FORMAT_BC1_UNORM), false); + address("BC1 any depth", volume(32, 32, 3, DXGI_FORMAT_BC1_UNORM), true); d = good; d.MipLevels = 6; address("mip chain", d, true); @@ -329,6 +377,19 @@ int addrlib_check() 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}; + // A block-compressed format is passed as itself, so that addrlib turns its texel sides into blocks. + const auto addr_format = [&](DXGI_FORMAT f, UINT size) { + switch (f) { + case DXGI_FORMAT_BC1_UNORM: return ADDR_FMT_BC1; + case DXGI_FORMAT_BC2_UNORM: return ADDR_FMT_BC2; + case DXGI_FORMAT_BC3_UNORM: return ADDR_FMT_BC3; + case DXGI_FORMAT_BC4_UNORM: return ADDR_FMT_BC4; + case DXGI_FORMAT_BC5_UNORM: case DXGI_FORMAT_BC5_SNORM: return ADDR_FMT_BC5; + case DXGI_FORMAT_BC6H_UF16: return ADDR_FMT_BC6; + case DXGI_FORMAT_BC7_UNORM: return ADDR_FMT_BC7; + default: return addr_formats[size]; + } + }; std::vector cases; 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) @@ -342,6 +403,14 @@ int addrlib_check() 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)); + // Every mip count of a set of block-compressed chains, for each BC format. + constexpr DXGI_FORMAT bc[] = {DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC4_UNORM, + DXGI_FORMAT_BC5_UNORM, DXGI_FORMAT_BC6H_UF16, DXGI_FORMAT_BC7_UNORM}; + constexpr UINT bc_chains[4][3] = {{64, 64, 16}, {12, 20, 9}, {4, 4, 32}, {256, 8, 8}}; + for (DXGI_FORMAT f : bc) + for (const auto& side : bc_chains) + for (UINT mips = 1; ((std::max)({side[0], side[1], side[2]}) >> (mips - 1)) != 0; ++mips) + cases.push_back(volume(side[0], side[1], side[2], f, 0x105, mips)); unsigned compared = 0, elements = 0, mismatches = 0; for (const D3D12_RESOURCE_DESC& d : cases) { const Layout l(d); @@ -354,7 +423,7 @@ int addrlib_check() in.flags.texture = 1; in.swizzleMode = ADDR_SW_4KB_S; in.resourceType = ADDR_RSRC_TEX_3D; - in.format = addr_formats[size]; + in.format = addr_format(d.Format, size); in.bpp = l.bytes_per_element * 8; in.width = l.width; in.height = l.height; @@ -387,8 +456,8 @@ int addrlib_check() ain.flags.texture = 1; ain.resourceType = ADDR_RSRC_TEX_3D; ain.bpp = in.bpp; - ain.unalignedWidth = l.width; - ain.unalignedHeight = l.height; + ain.unalignedWidth = l.columns(0); // in elements: 4x4 blocks for BC + ain.unalignedHeight = (l.height + l.texels - 1) / l.texels; ain.numSlices = l.depth; ain.numMipLevels = l.mips; ain.numSamples = 1; @@ -416,13 +485,15 @@ int main(int argc, char** argv) 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"); + bc_texels = mutate && std::strcmp(argv[2], "bc") == 0; + if (argc != 1 && !thin && !flat_tail && !bc_texels) { + std::printf("usage: startup_gfx10_volume_check [--addrlib | --mutate thin | --mutate tail | --mutate bc]\n"); return 2; } check_equations(); check_block_order(); check_mip_chain(); + check_block_compressed(); check_distinct_and_round_trip(); check_descriptions(); if (failures) { @@ -430,6 +501,6 @@ int main(int argc, char** argv) return 1; } 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])); + "17 layouts, 10 address descriptions, 9 views, 2 block-compressed volumes against their blocks)\n", sizeof(shapes) / sizeof(shapes[0])); return 0; }