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
54 changes: 54 additions & 0 deletions docs/experiments/startup-gfx10-linear-1d.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Slot-70 one-dimensional textures in the console linear layout (0x100)

[startup-gfx10-linear.md](startup-gfx10-linear.md) reads two-dimensional `0x100` textures through
device slot 70. A one-dimensional `0x100` description was still refused with
`reason=unsupported_description`, because `gfx10::supports` took only 2D textures and
`address_view_fits` had no 1D view.

## Layout

`Gfx10Lib::HwlComputeSurfaceInfoLinear` (Mesa 25.1.0, `src/amd/addrlib`, MIT) lays out a 1D surface
with the same rule as a 2D one, one row per mip: each mip is padded to 256 bytes and the mips are
stored from the smallest up. It returns `ADDR_INVALIDPARAMS` for a 1D surface taller than one row.
A 300-texel RGBA8 texture with 4 mips (300, 150, 75 and 38 texels, rounded up at each level) has
mip 3 at 0, mip 2 at 256, mip 1 at 768 and mip 0 at 1536.

The change:

- `gfx10_layout.h`: `supports` takes a 1D texture in the linear mode with a height of one and an
element of one texel. Block-compressed formats, 1D arrays and the tiled modes stay refused for 1D.
- `address_texture.h`: a 1D array is refused, since the draw uploads a 1D texture only when it is not
an array (`d3d12_draw.inl`). `address_view_fits` takes a `TEXTURE1D` view of a 1D texture that fits
the mip range with no LOD clamp.
- `d3d12_memory_srv.inl`: the desktop format check asks for `D3D12_FORMAT_SUPPORT1_TEXTURE1D` for a
1D texture.

## Results

Build: `slot70/linear-1d`, stacked on `slot70/linear-layout` (ce2d6f50), dev preset (debug layer on).
Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 5090 (driver 32.0.16.1088) and Microsoft WARP.

| Test | Result |
| --- | --- |
| `startup_gfx10_layout` | PASS: 15 round trips (2 new 1D linear shapes: RGBA8 sRGB 300 with 9 mips, R8 4096 with 13 mips), 15 refusals (new: 1D in `0x105`, 1D two rows high, 1D BC1, a 1D array), 22 address descriptions (new: a 1D texture is accepted, a 1D array and a desktop-layout 1D texture are refused), 33 views (new: the whole 1D chain, its last mip, past the chain, an LOD clamp, a 1D view of a 2D texture and a 2D view of a 1D texture) |
| `startup_gfx10_layout_linear_addrlib` | PASS: 349,547 sizes and element addresses match addrlib, now with three 1D textures (`ADDR_RSRC_TEX_1D`: RGBA8 sRGB 300 with 9 mips, R8 4096 with 13 mips, RGBA16F 1000 with 10 mips) |
| `startup_address_console_{warp,hardware}` | PASS: 3 new 1D draws through a `Texture1D` view are exact on all 65,536 pixels: RGBA8 300 with one mip, and its 4-mip chain viewed at mip 0 and at mip 2 |
| `startup_address_console_linear_unpadded_{warp,hardware}` | PASS (control): the 4-mip 1D chain with its mips packed without padding (mip 2 at 152 instead of 256) is published and all 65,536 pixels of the mip-2 draw differ; the 2D case is unchanged (63,488 differ) |

Without the source change (ce2d6f50), the first 1D draw reads the null view: pixel (0,0) is
`00000000`, but `010300ff` was expected.

Commands (PowerShell, at the repository root, after `. .\tools\dev.ps1`):

```powershell
cmake --preset dev -DXBOX2WINDOWS_ADDRLIB_DIR=<mesa>/src/amd/addrlib
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^startup_gfx10_layout'
ctest --preset dev --no-tests=error -R '^startup_address_console_(warp|hardware|linear_unpadded_(warp|hardware))$' -V
```

## Open

- As for 2D, the rule is addrlib's desktop GFX10 rule; that console memory uses it for `0x100` is
inferred from the layout word, not measured on console hardware.
- 1D arrays and 1D textures in the tiled modes stay refused.
3 changes: 1 addition & 2 deletions docs/experiments/startup-gfx10-linear.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ ctest --preset dev --no-tests=error -R '^startup_address_console_(warp|hardware|
- The rule is addrlib's desktop GFX10 rule. That the console stores `0x100` textures with the same
256-byte pitch is inferred from the layout word naming `ADDR_SW_LINEAR`; no console hardware
measurement backs it.
- One-dimensional linear textures need a 1D view in `address_view_fits` and a 1D desktop texture
for the upload. They are not covered here.
- One-dimensional linear textures are covered in [startup-gfx10-linear-1d.md](startup-gfx10-linear-1d.md).
5 changes: 3 additions & 2 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -3560,9 +3560,10 @@ draw that samples the view copies each mip of each array slice from that layout
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,
The description must be two-dimensional, or in the linear mode `0x100` one-dimensional and not an array (one row per mip, no block-compressed format), 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.
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 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,
Expand Down
11 changes: 9 additions & 2 deletions src/startup_stubs/address_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
// 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.
// The console's linear mode (0x100) is one of those layouts: rows with addrlib's 256-byte pitch.
// The console's linear mode (0x100) is one of those layouts: rows with addrlib's 256-byte pitch. In
// that mode a one-dimensional texture that is not an array is taken too.
// Everything else is refused here: the desktop's unknown layout, other dimensions, multisampled
// textures, textures that are also targets, formats without a known element size and swizzle modes
// without an equation.
Expand All @@ -30,6 +31,8 @@ inline bool console_address_texture(const D3D12_RESOURCE_DESC& r)
static_cast<UINT>(D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER);
if (!gfx10::supports(r) || r.SampleDesc.Quality || (static_cast<UINT>(r.Flags) & incompatible_flags) ||
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)) ||
(r.Alignment && r.Alignment != D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT &&
r.Alignment != D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT) ||
Expand Down Expand Up @@ -71,7 +74,8 @@ inline bool address_component_mapping(UINT mapping)
return true;
}

// A two-dimensional or array view that stays inside the texture and reads its texels as stored.
// A one-dimensional, 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 (!address_view_format(r.Format, v.Format) || !address_component_mapping(v.Shader4ComponentMapping))
Expand All @@ -82,6 +86,9 @@ inline bool address_view_fits(const D3D12_RESOURCE_DESC& r, const D3D12_SHADER_R
const auto mips_fit = [&](UINT first, UINT count) {
return count == ~0u ? first < r.MipLevels : inside(first, count, r.MipLevels);
};
if (v.ViewDimension == D3D12_SRV_DIMENSION_TEXTURE1D)
return r.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE1D && r.DepthOrArraySize == 1 &&
mips_fit(v.Texture1D.MostDetailedMip, v.Texture1D.MipLevels) && v.Texture1D.ResourceMinLODClamp == 0.0f;
if (v.ViewDimension == D3D12_SRV_DIMENSION_TEXTURE2D)
return r.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D && r.DepthOrArraySize == 1 &&
mips_fit(v.Texture2D.MostDetailedMip, v.Texture2D.MipLevels) &&
Expand Down
5 changes: 3 additions & 2 deletions src/startup_stubs/d3d12_memory_srv.inl
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ bool desktop_address_view_supported(Wrapper* device, const D3D12_RESOURCE_DESC&
D3D12_FEATURE_DATA_FORMAT_SUPPORT storage{r.Format};
if (r.Format == v.Format) storage = view;
else if (FAILED(desktop->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &storage, sizeof(storage)))) return false;
const UINT req = r.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? D3D12_FORMAT_SUPPORT1_TEXTURE3D
: D3D12_FORMAT_SUPPORT1_TEXTURE2D;
const UINT req = r.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? D3D12_FORMAT_SUPPORT1_TEXTURE3D
: r.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE1D ? D3D12_FORMAT_SUPPORT1_TEXTURE1D
: D3D12_FORMAT_SUPPORT1_TEXTURE2D;
return (storage.Support1 & req) &&
(r.MipLevels == 1 || (storage.Support1 & D3D12_FORMAT_SUPPORT1_MIP));
}
Expand Down
16 changes: 12 additions & 4 deletions src/startup_stubs/gfx10_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
//
// A console resource description carries its swizzle mode in the Layout field as 0x100 + mode. The
// modes handled here are 256 B, 4 KiB and 64 KiB blocks in the standard (S) and display (D) orders:
// 0x101, 0x102, 0x105, 0x106, 0x109 and 0x10a, and the linear mode 0x100. The address equations,
// 0x101, 0x102, 0x105, 0x106, 0x109 and 0x10a, and the linear mode 0x100, which also takes
// one-dimensional textures (one row per mip, no block-compressed formats). The address equations,
// block dimensions and mip-tail rules follow AMD addrlib as Mesa carries it under src/amd/addrlib, at the revision
// tools/fetch_addrlib.py pins: Mesa 25.1.0, commit 5c142e46f3f6e752ed745fd48912ebb8fad67145. The three
// files used carry this notice:
Expand Down Expand Up @@ -80,13 +81,20 @@ inline bool supports_volume(const D3D12_RESOURCE_DESC& d)
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.
// A two-dimensional, single-sample texture whose memory this header can address, a one-dimensional
// one in the linear mode, or a volume supports_volume takes. addrlib refuses a 1D surface taller than one row (HwlComputeSurfaceInfoLinear). A 1D
// array is refused here as well as in address_view_fits: the draw uploads a 1D texture only when it is not an array.
inline bool supports(const D3D12_RESOURCE_DESC& d)
{
if (d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D) return supports_volume(d);
const UINT mode = swizzle_mode(d), log2 = block_log2(mode);
if ((!log2 && mode != linear_mode) || d.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || !element_of(d.Format).bytes) return false;
const Element element = element_of(d.Format);
if ((!log2 && mode != linear_mode) || !element.bytes) return false;
if (d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE1D) {
if (mode != linear_mode || d.Height != 1 || d.DepthOrArraySize != 1 || element.texels != 1) return false;
} else if (d.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D) {
return false;
}
if (!d.Width || !d.Height || d.Width > 16384 || d.Height > 16384 || !d.DepthOrArraySize) return false;
if (!d.MipLevels || d.MipLevels > max_mips || d.SampleDesc.Count != 1) return false;
return mode == linear_mode || log2 >= 12 || d.MipLevels == 1; // a 256 B block has no mip tail here
Expand Down
4 changes: 2 additions & 2 deletions tests/cmake/startup_gfx10_linear.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ if(XBOX2WINDOWS_ADDRLIB_DIR)
endif()
add_test(NAME startup_gfx10_layout_linear_addrlib COMMAND startup_gfx10_layout_check --addrlib)
set_tests_properties(startup_gfx10_layout_linear_addrlib PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77)
# The negative control for the linear cases of startup_address_console: rows written without the 256-byte
# pitch must not draw exactly.
# The negative control for the linear cases of startup_address_console: a 2D texture and a 1D chain written
# without the 256-byte padding must not draw exactly.
if(STARTUP_FXC AND EXISTS "${INTAKE_PYTHON}" AND TARGET startup_stream_consumer)
foreach(backend IN ITEMS warp hardware)
add_test(NAME startup_address_console_linear_unpadded_${backend} COMMAND "${CMAKE_COMMAND}" -E env "X2W_FXC=${STARTUP_FXC}"
Expand Down
49 changes: 33 additions & 16 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> eleven textures and two volumes, each drawn once; every pixel of the
<consumer> <backend> fourteen 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
Expand Down Expand Up @@ -171,6 +171,11 @@ def bc1_block(mip, x, y):
("RGBA8 100x40 linear chain, mip 0", 100, 40, 4, RGBA8, 0x100, 0),
("RGBA8 100x40 linear chain, mip 2", 100, 40, 4, RGBA8, 0x100, 2),
("BC1 200x96 linear", 200, 96, 1, BC1, 0x100, 0),
# Linear one-dimensional textures (a trailing "1d"): one row per mip, each mip padded to 256 bytes and
# stored from the smallest up, so mip 0 of the 300-texel chain starts at 1536, not at 0.
("RGBA8 300 1D linear", 300, 1, 1, RGBA8, 0x100, 0, "1d"),
("RGBA8 300 1D linear chain, mip 0", 300, 1, 4, RGBA8, 0x100, 0, "1d"),
("RGBA8 300 1D linear chain, mip 2", 300, 1, 4, RGBA8, 0x100, 2, "1d"),
]


Expand Down Expand Up @@ -299,18 +304,25 @@ def build(width, height, mips, fmt, layout, unpadded=False):


def check(directory, consumer, backend, case, extra=None, held=None, late=False, unpadded=False):
name, width, height, mips, fmt, layout, viewed = case
name, width, height, mips, fmt, layout, viewed, *dimension = case
one_d = dimension == ["1d"]
backing, images = build(width, height, mips, fmt, layout, unpadded)
source = directory / "texels.bin"
source.write_bytes(backing)
w, h = max(1, width >> viewed), max(1, height >> viewed)
hlsl = ("Texture2D<float4> t : register(t0);\n"
"float4 main(float4 p : SV_Position) : SV_Target {\n"
f" return t.Load(int3(uint(p.x) % {w}, uint(p.y) % {h}, 0));\n}}\n")
if one_d:
hlsl = ("Texture1D<float4> t : register(t0);\n"
"float4 main(float4 p : SV_Position) : SV_Target {\n"
f" return t.Load(int2(uint(p.x) % {w}, 0));\n}}\n")
else:
hlsl = ("Texture2D<float4> t : register(t0);\n"
"float4 main(float4 p : SV_Position) : SV_Target {\n"
f" return t.Load(int3(uint(p.x) % {w}, uint(p.y) % {h}, 0));\n}}\n")
trap_log = directory / "trap.log"
desc = f"{width},{height},{mips},{fmt},{layout},{viewed}" + (",1d" if one_d else "")
modes = {"X2W_TEST_CONSOLE_VIEW": str(source), "X2W_TRAP_LOG": str(trap_log),
"X2W_TEST_CONSOLE_DESC": f"{width},{height},{mips},{fmt},{layout},{viewed}", **(extra or {})}
actual = draw_texture(directory, consumer, backend, hlsl, modes)
"X2W_TEST_CONSOLE_DESC": desc, **(extra or {})}
actual = draw_texture(directory, consumer, backend, hlsl, modes, "tex1d" if one_d else "tex2d")
if actual is None:
return 77
if len(actual) != TARGET_W * TARGET_H * 4:
Expand Down Expand Up @@ -343,19 +355,25 @@ def check(directory, consumer, backend, case, extra=None, held=None, late=False,
raise AssertionError(f"{name}: no 'published console layout' line in the log")
if unpadded:
if not wrong:
raise AssertionError(f"{name}: rows written without the 256-byte pitch drew exactly; the pitch is not checked")
print(f"{backend} {name}, rows without the 256-byte pitch: published, {wrong} of {TARGET_W * TARGET_H} pixels differ")
raise AssertionError(f"{name}: texels written without the 256-byte padding drew exactly; the padding is not checked")
print(f"{backend} {name}, without the 256-byte padding: published, {wrong} of {TARGET_W * TARGET_H} pixels differ")
return 0
print(f"{backend} {name}: {TARGET_W * TARGET_H} RGBA pixels exact")
return 0


def check_linear_unpadded(directory, consumer, backend):
"""The linear cases' negative control: the first linear texture with its rows written one mip wide
(400 bytes) instead of at the 256-byte pitch (512). The runtime reads the padded pitch, so the draw must
differ from the texels; an exact draw means the linear cases do not test the pitch."""
case = next(c for c in CASES if c[5] == 0x100)
return check(directory, consumer, backend, case, unpadded=True)
"""The linear cases' negative control. The first 2D linear texture has its rows written one mip wide
(400 bytes) instead of at the 256-byte pitch (512), and the 1D chain viewed at mip 2 has its mips packed
without padding, so mip 2 starts at 152 instead of 256. The runtime reads the padded layout, so each draw
must differ from the texels; an exact draw means the linear cases do not test the padding."""
for name in ("RGBA8 100x40 linear", "RGBA8 300 1D linear chain, mip 2"):
case = next(c for c in CASES if c[0] == name)
with tempfile.TemporaryDirectory() as temporary:
result = check(Path(temporary), consumer, backend, case, unpadded=True)
if result:
return result
return 0


GATE_PAYLOADS = 18
Expand Down Expand Up @@ -475,8 +493,7 @@ def check_gate(directory, consumer, backend, mode):
usage = "usage: startup_address_console_check.py <consumer> <backend> [" + " | ".join(modes) + "]\n"
sys.exit(usage + "\n\n".join(__doc__.split("\n\n")[:2]))
if len(sys.argv) == 4 and sys.argv[3] == "linear-unpadded":
with tempfile.TemporaryDirectory() as temporary:
sys.exit(check_linear_unpadded(Path(temporary), sys.argv[1], sys.argv[2]))
sys.exit(check_linear_unpadded(None, sys.argv[1], sys.argv[2]))
if len(sys.argv) == 4:
with tempfile.TemporaryDirectory() as temporary:
sys.exit(check_gate(Path(temporary), sys.argv[1], sys.argv[2], sys.argv[3]))
Expand Down
Loading
Loading