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
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,16 @@ foreach(mutation IN ITEMS bc4 width clamp)
add_test(NAME startup_tile64_plan_${mutation}_control COMMAND startup_tile64_plan_check --mutate ${mutation})
set_tests_properties(startup_tile64_plan_${mutation}_control PROPERTIES WILL_FAIL TRUE)
endforeach()
# Console texture layouts for the non-XOR standard and display swizzle modes (src/startup_stubs/gfx10_layout.h)
# and the slot-70 descriptions that use them (src/startup_stubs/address_texture.h), without a device: address
# equations against the pattern rows of AMD addrlib (Mesa 25.1.0, src/amd/addrlib, MIT), agreement with
# bc7_4k_s.h, bc64_chain.h and tile64_plan.h, and round trips. The mutated run reads the display order as the standard one and is a negative control.
add_executable(startup_gfx10_layout_check tests/startup_gfx10_layout_check.cpp)
target_compile_features(startup_gfx10_layout_check PRIVATE cxx_std_17)
target_include_directories(startup_gfx10_layout_check PRIVATE src)
add_test(NAME startup_gfx10_layout COMMAND startup_gfx10_layout_check)
add_test(NAME startup_gfx10_layout_display_control COMMAND startup_gfx10_layout_check --mutate display)
set_tests_properties(startup_gfx10_layout_display_control PROPERTIES WILL_FAIL TRUE)
add_test(NAME xg_swizzle_select COMMAND xg_swizzle_select_check)
set_tests_properties(xg_swizzle_select PROPERTIES TIMEOUT 30 SKIP_RETURN_CODE 77)
# Mutation control: the same comparison must identify all nine mismatches.
Expand Down Expand Up @@ -2842,6 +2852,19 @@ if(EXISTS "${INTAKE_PYTHON}")
"${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_address_bc_view_check.py"
"$<TARGET_FILE:startup_stream_consumer>" "${backend}")
set_tests_properties(startup_address_bc_view_${backend} PROPERTIES TIMEOUT 90 SKIP_RETURN_CODE 77)
add_test(NAME startup_address_console_${backend} COMMAND "${CMAKE_COMMAND}" -E env "X2W_FXC=${STARTUP_FXC}"
"${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_address_console_check.py"
"$<TARGET_FILE:startup_stream_consumer>" "${backend}")
set_tests_properties(startup_address_console_${backend} PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77)
# Uploads of by-address textures recorded while the queue waits on a fence keep their bytes until the
# queue has run them. The ring control fills them from the shared upload ring and must lose the first.
foreach(gate IN ITEMS gate gate-ring)
string(REPLACE "-" "_" gate_name "${gate}")
add_test(NAME startup_address_console_${gate_name}_${backend} COMMAND "${CMAKE_COMMAND}" -E env "X2W_FXC=${STARTUP_FXC}"
"${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_address_console_check.py"
"$<TARGET_FILE:startup_stream_consumer>" "${backend}" "${gate}")
set_tests_properties(startup_address_console_${gate_name}_${backend} PROPERTIES TIMEOUT 300 SKIP_RETURN_CODE 77)
endforeach()
add_test(NAME startup_xg_bc_chain_${backend} COMMAND "${CMAKE_COMMAND}" -E env "X2W_FXC=${STARTUP_FXC}"
"${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_xg_bc_chain_check.py"
"$<TARGET_FILE:startup_stub_xg_xs>" "$<TARGET_FILE:startup_stream_consumer>" "${backend}")
Expand Down
63 changes: 63 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -12312,6 +12312,69 @@ cmake --build --preset release --target startup_stream_consumer startup_stub_con
ctest --preset release --no-tests=error --output-on-failure -R '^(startup_address_(bc_view|srv)_(hardware|warp)|startup_xg_bc7_layout|startup_bc7_4k_s|bc7_tile_swizzle)$'
```

### Sample by-address textures of the non-XOR console layouts

Slot 70 took a few texture shapes without a resource object (the R8 plane of an existing resource,
the single texel, the `0x105` BC3/BC7 view above and the `0x109` BC chains below; those keep their
own paths) and refused every other description, which leaves the destination descriptor as it was.
It now also takes a two-dimensional,
single-sample, sampled-only texture with a known element size whose layout is `0x101`, `0x102`,
`0x105`, `0x106`, `0x109` or `0x10a`, and reads it in that console layout, mip tail and array slices
included. Layout `0` and the linear mode `0x100` are refused as before: `startup_address_srv` still
runs in the default configuration, and its mismatched-width and interior-address calls stay refused.
The accepted descriptions, views, limits and log lines are listed in `docs/startup-runtime.md`
("Textures published by address").

`startup_gfx10_layout` needs no device. It compares `src/startup_stubs/gfx10_layout.h` with the 30
one-pipe equations of AMD addrlib's `GFX10_SW_{256,4K,64K}_{S,D}_PATINFO` rows written out in the test
(five element sizes for each of the six modes), with `bc7_4k_s.h` on five 4 KiB surfaces, with
`bc64_chain.h` on eight 64 KiB chains and with `tile64_plan.h` on ten tile plans; it tiles and
detiles nine textures back to their bytes, and lists 11 refused layouts, 15 slot 70 descriptions and
16 views on each side of the accepted set. `startup_gfx10_layout_display_control` reads the `0x10a`
order as `0x109` and must fail. The addrlib reference is the revision `tools/fetch_addrlib.py` pins
(Mesa 25.1.0, commit `5c142e46f3f6e752ed745fd48912ebb8fad67145`, `src/amd/addrlib`, MIT); the files
and their notice ("Copyright (C) 2007-2024 Advanced Micro Devices, Inc. All rights reserved.",
`SPDX-License-Identifier: MIT`) are named in the header and in both fixtures.
[AMD addrlib revision](https://gitlab.freedesktop.org/mesa/mesa/-/tree/5c142e46f3f6e752ed745fd48912ebb8fad67145/src/amd/addrlib)

`startup_address_console_{warp,hardware}` builds the backing bytes in Python from the same addrlib
rows, independently of the header, publishes them through slot 70 with no resource object, and
compares all 65,536 RGBA pixels of a 512 by 128 target for each of seven textures: RGBA8 96 by 40
and BC1 192 by 96 at `0x105`, BC1 256 by 128 at `0x10a`, mips 1, 2 and 3 of a four-mip RGBA8 256 by
256 chain at `0x10a` (mips 2 and 3 are in the mip tail), and RGBA8 40 by 24 at `0x101`. Each run must
also log `slot70 texture kind 1: published console layout`. Two held descriptions follow: the first
texture again over an address announced as an XG copy of rows (`console_layout_xg_rows`), and
RGBA8 257 by 257 at `0x109`, whose nine 64 KiB blocks run past the 393,216 bytes the XG stand-in
reports (`console_layout_beyond_xg_size`). Both must log their reason, publish nothing and read the
null view at every pixel. Last, the first texture is published and its address is then announced as
an XG copy of rows before the draw; the published view must read the null view at every pixel, as
a partial-tile BC view does after a later row copy.

An upload of a console-layout texture owns its upload buffer. The buffer and the texture stay referenced
by the recording and by each submit of it until the queue has completed that submit; the shared
upload ring, which is reused without waiting for a queue, is not used. `startup_address_console_gate_{warp,hardware}`
makes the queue wait on a fence the fixture holds (queue slot 17), then records and submits eighteen
lists on one list object, resetting the allocator and the list between them. Each republishes one
2048 by 2048 RGBA8 texture at `0x109` (16 MiB) from the same address with a new payload and draws it,
payload 0 over the left half of the target and the others over the right half. No submit may complete
before the fixture signals the fence. After the last one completes, the left half must hold payload 0
and the right half payload 17, and the log must report eighteen retained submits released.
`startup_address_console_gate_ring_{warp,hardware}` is the control: with
`X2W_TEST_ADDRESS_UPLOAD_RING=1` (fixtures only) the same uploads come from the 256 MiB ring, the
later ones pass over the bytes of payload 0 before the queue copies them, and the left half must not
hold payload 0.

The equations are checked against addrlib and against the three existing layout headers, not against
console memory. Which layouts a given console build writes for which textures is not established by
these fixtures. The gate fixture covers one direct queue, one texture and uploads recorded by draws;
it does not cover a release of the desktop texture, which this change never does.

```powershell
cmake --build --preset release --target startup_gfx10_layout_check startup_stream_consumer
ctest --preset release --no-tests=error --output-on-failure -R '^startup_gfx10_layout'
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)$'
```

### 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)
Expand Down
75 changes: 75 additions & 0 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,81 @@ memory-type and state rules are unchanged. The five-second `x2w-d3d12 views note
that call count is its sole failure. Neither is `WILL_FAIL`, so a crash cannot pass them. A
refused allocation or mapping is a capability skip (77) in the controls.

## Textures published by address (device slot 70)

Device slot 70 gets a resource description, a view and the address of the texels. When a live
texture with that description exists at the address, its view is created as before. The shapes slot
70 already read from an address keep their own paths unchanged: the single texel, the `0x105`
BC3/BC7 surface (partial last tiles included) and the `0x109` BC chains. For any other description
with no live texture whose `Layout` is `0x101`, `0x102`, `0x105`, `0x106`, `0x109` or `0x10a` (256 B,
4 KiB and 64 KiB blocks in the standard and display orders, no XOR), the texels are read from the
address in that console layout (`src/startup_stubs/address_texture.h`, device-free). A translated
draw that samples the view copies each mip of each array slice from that layout into desktop
footprint rows (`src/startup_stubs/gfx10_layout.h`: address equations, block sizes and mip-tail rules
after AMD addrlib, Mesa 25.1.0, `src/amd/addrlib`, MIT). A 256 B layout is taken with one mip only.

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 be a 2D or
2D-array view of the same typeless family whose mip and slice ranges stay inside the texture.
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
at most 64 MiB.

A console-layout description is held (not published, descriptor unchanged) in the two cases a
partial-tile BC view is held for. `console_layout_xg_rows`: the latest XG stand-in copy announced
for the address wrote desktop-footprint rows, so the bytes are not in the layout the description
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.

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
buffer and to the texture until the list is reset, and each `ExecuteCommandLists` of the recording
takes its own references and signals a fence behind the submit; a later submit drops the references
of the submits whose fence has completed. A submit whose fence cannot be created or signalled keeps
its references. The earlier by-address shapes keep using the shared ring as before. The desktop
texture of a by-address texture is made on the first draw that samples it and is not released. The
texels are compared with the uploaded copy on each frame that binds them, as for the earlier
by-address shapes, and at once after a repeated slot 70 call for the same texture, which announces
a write: a description and address that were published before are published again rather than
taken as a live resource, so changed texels are uploaded again.

Limits and choices that are not measured against a console:

- The texels are taken in the layout the description names. The XG stand-in's default copy writes
rows whatever the swizzle mode; a description filled through it is held as above. A write by the
title itself is not told apart from one in the named layout.
- One upload buffer is created per upload and there is no bound on the bytes uploaded in a frame.
A policy for releasing textures that are no longer sampled and for spreading large uploads over
frames is left to a follow-up.
- Second sources for the address equations: only the 16-byte standard rows of `0x105` and `0x109`
are compared with another implementation in the tree (`bc7_4k_s.h`, `bc64_chain.h`);
`tile64_plan.h` checks the `0x10a` mip starts and tail, not the bit order. The display (`_D`)
rows in `gfx10_layout.h` that differ from the standard ones (1-, 8- and 16-byte elements; the 2-
and 4-byte display rows equal the standard rows) and the standard rows for 1-, 2-, 4- and 8-byte
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.

Log lines (stderr and `X2W_TRAP_LOG`):

- `x2w-d3d12 slot70 texture kind <n>: <outcome>; first seen res{...} view{...} address=...`, once
for each new combination of format, layout, one or several mips, one or several slices, flags,
dimension, view format, view dimension and outcome (at most 200). The outcome is
`existing resource`, `published BC shape` (the earlier `0x105` and `0x109` BC paths),
`published console layout`, one of the two hold reasons or `texture_unavailable`.
- `x2w-draw by-address uploads: <n> submits completed and released (...)`, for the first twelve
submits that drop retained uploads.

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 -j 1 -R '^startup_address_console_' -V`

## Buffer memory SRVs (device slot 70)

Device slot 70 (`src/startup_stubs/d3d12_memory_srv.inl`, validation in
Expand Down
56 changes: 56 additions & 0 deletions src/startup_stubs/address_texture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#pragma once

// Textures a title publishes by address (device slot 70): a resource description, a view and the
// address of the texels, with no resource object behind them. This header decides, without a
// device, which of those descriptions the startup renderer reads from the address: a sampled-only,
// two-dimensional, single-sample texture whose Layout field holds a console swizzle mode that
// gfx10_layout.h addresses. Its texels are in that console layout.
// Everything else is refused here: the desktop's unknown layout and the console's linear mode (the
// extent of such rows is not established), other dimensions, multisampled textures, textures that
// are also targets, formats without a known element size and swizzle modes without an equation.

#include "startup_stubs/gfx10_layout.h"

namespace x2w_startup {
inline bool console_address_texture(const D3D12_RESOURCE_DESC& r)
{
// Each flag is cast on its own: with MinGW-w64 headers the flag enum's operator| is not constexpr.
constexpr UINT not_sampled_only = static_cast<UINT>(D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET) |
static_cast<UINT>(D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL) |
static_cast<UINT>(D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS) |
static_cast<UINT>(D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE);
// A desktop block-compressed texture needs whole 4x4 blocks in its largest mip.
const UINT texels = gfx10::element_of(r.Format).texels;
return r.SampleDesc.Quality == 0 && !(static_cast<UINT>(r.Flags) & not_sampled_only) && gfx10::supports(r) &&
r.Width % texels == 0 && r.Height % texels == 0;
}

// Formats with one typeless parent hold the same bytes; a view may name any of them.
inline UINT format_family(DXGI_FORMAT format)
{
const UINT f = static_cast<UINT>(format);
constexpr UINT first[] = {1, 5, 9, 15, 19, 23, 27, 33, 39, 44, 48, 53, 60, 70, 73, 76, 79, 82, 94, 97};
constexpr UINT last[] = {4, 8, 14, 18, 22, 25, 32, 38, 43, 47, 52, 59, 64, 72, 75, 78, 81, 84, 96, 99};
for (UINT i = 0; i < sizeof(first) / sizeof(first[0]); ++i)
if (f >= first[i] && f <= last[i]) return first[i];
if (f == 87 || f == 90 || f == 91) return 90; // B8G8R8A8
if (f == 88 || f == 92 || f == 93) return 92; // B8G8R8X8
return f;
}

// A two-dimensional or array view that stays inside the texture and reads its texels as stored.
inline bool address_view_fits(const D3D12_RESOURCE_DESC& r, const D3D12_SHADER_RESOURCE_VIEW_DESC& v)
{
if (format_family(v.Format) != format_family(r.Format)) return false;
const auto inside = [](UINT first, UINT count, UINT total) {
return first < total && (count == ~0u || (count && count <= total - first));
};
if (v.ViewDimension == D3D12_SRV_DIMENSION_TEXTURE2D)
return inside(v.Texture2D.MostDetailedMip, v.Texture2D.MipLevels, r.MipLevels) && !v.Texture2D.PlaneSlice;
if (v.ViewDimension == D3D12_SRV_DIMENSION_TEXTURE2DARRAY)
return inside(v.Texture2DArray.MostDetailedMip, v.Texture2DArray.MipLevels, r.MipLevels) &&
inside(v.Texture2DArray.FirstArraySlice, v.Texture2DArray.ArraySize, r.DepthOrArraySize) &&
!v.Texture2DArray.PlaneSlice;
return false;
}
} // namespace x2w_startup
Loading
Loading