From a8cf51a7bd799cc9ece96644e13b91b1b5dcfa41 Mon Sep 17 00:00:00 2001 From: lewisalex86 Date: Thu, 26 Nov 2026 21:37:00 +0000 Subject: [PATCH 1/4] startup: read one-dimensional linear (0x100) textures in slot 70 Take a 1D, non-array texture in the console linear layout through the console-layout path: one row per mip, each padded to 256 bytes, smallest mip first (addrlib HwlComputeSurfaceInfoLinear). Add a TEXTURE1D view check, the 1D format-support bit, 1D unit and addrlib cases, three 1D draws and a 1D unpadded control. --- docs/experiments/startup-gfx10-linear-1d.md | 54 +++++++++++++++++++ docs/experiments/startup-gfx10-linear.md | 3 +- docs/startup-runtime.md | 4 +- src/startup_stubs/address_texture.h | 11 +++- src/startup_stubs/d3d12_memory_srv.inl | 5 +- src/startup_stubs/gfx10_layout.h | 14 +++-- tests/cmake/startup_gfx10_linear.cmake | 4 +- tests/startup_address_console_check.py | 49 +++++++++++------ tests/startup_address_srv.cpp | 28 ++++++---- tests/startup_gfx10_layout_check.cpp | 60 ++++++++++++++++++--- 10 files changed, 186 insertions(+), 46 deletions(-) create mode 100644 docs/experiments/startup-gfx10-linear-1d.md diff --git a/docs/experiments/startup-gfx10-linear-1d.md b/docs/experiments/startup-gfx10-linear-1d.md new file mode 100644 index 0000000000..0d0bfc43d9 --- /dev/null +++ b/docs/experiments/startup-gfx10-linear-1d.md @@ -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 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), 14 refusals (new: 1D in `0x105`, 1D two rows high, 1D BC1), 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=/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. diff --git a/docs/experiments/startup-gfx10-linear.md b/docs/experiments/startup-gfx10-linear.md index 330d225c6d..43bc91a5c5 100644 --- a/docs/experiments/startup-gfx10-linear.md +++ b/docs/experiments/startup-gfx10-linear.md @@ -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). diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 40b44cf97b..caefcbd881 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -3342,9 +3342,9 @@ 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. Anything else is refused as before and leaves the destination descriptor unchanged: layout `0` 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 diff --git a/src/startup_stubs/address_texture.h b/src/startup_stubs/address_texture.h index b5cdcc5150..0cc8e8477c 100644 --- a/src/startup_stubs/address_texture.h +++ b/src/startup_stubs/address_texture.h @@ -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. @@ -30,6 +31,8 @@ inline bool console_address_texture(const D3D12_RESOURCE_DESC& r) static_cast(D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER); if (!gfx10::supports(r) || r.SampleDesc.Quality || (static_cast(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) || @@ -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)) @@ -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) && diff --git a/src/startup_stubs/d3d12_memory_srv.inl b/src/startup_stubs/d3d12_memory_srv.inl index 1252190e86..a14b834b28 100644 --- a/src/startup_stubs/d3d12_memory_srv.inl +++ b/src/startup_stubs/d3d12_memory_srv.inl @@ -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)); } diff --git a/src/startup_stubs/gfx10_layout.h b/src/startup_stubs/gfx10_layout.h index f088ca4bc3..0f18b7a023 100644 --- a/src/startup_stubs/gfx10_layout.h +++ b/src/startup_stubs/gfx10_layout.h @@ -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: @@ -70,11 +71,18 @@ inline UINT block_log2(UINT mode) } } -// A two-dimensional, single-sample texture whose memory this header can address. +// A two-dimensional, single-sample texture whose memory this header can address, or a one-dimensional +// one in the linear mode. addrlib refuses a 1D surface taller than one row (HwlComputeSurfaceInfoLinear). inline bool supports(const D3D12_RESOURCE_DESC& 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 || 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 diff --git a/tests/cmake/startup_gfx10_linear.cmake b/tests/cmake/startup_gfx10_linear.cmake index 9f68899b9e..e3ead6af1d 100644 --- a/tests/cmake/startup_gfx10_linear.cmake +++ b/tests/cmake/startup_gfx10_linear.cmake @@ -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}" diff --git a/tests/startup_address_console_check.py b/tests/startup_address_console_check.py index e451d3e45a..24fc9f4434 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. - eleven textures, each drawn once; every pixel of the 512x128 target is + fourteen textures, each drawn once; every pixel of the 512x128 target is compared with the texel the view names; then two held descriptions and one texture whose address is announced as XG rows after it was published @@ -145,6 +145,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"), ] @@ -195,18 +200,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 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 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 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: @@ -239,19 +251,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 @@ -371,8 +389,7 @@ def check_gate(directory, consumer, backend, mode): usage = "usage: startup_address_console_check.py [" + " | ".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])) diff --git a/tests/startup_address_srv.cpp b/tests/startup_address_srv.cpp index 38ba6ec090..a225708afc 100644 --- a/tests/startup_address_srv.cpp +++ b/tests/startup_address_srv.cpp @@ -260,7 +260,8 @@ int draw_bc_address_srvs(void* guest, void* list) } // X2W_TEST_CONSOLE_VIEW names a file of texels and X2W_TEST_CONSOLE_DESC the texture they belong to -// ("width,height,mips,format,layout,viewed mip"). No resource object exists at the address; one mip is +// ("width,height,mips,format,layout,viewed mip", then optionally ",1d" for a one-dimensional texture with a +// one-dimensional view). No resource object exists at the address; one mip is // viewed and drawn over the whole target. With X2W_TEST_CONSOLE_XG_ROWS=1 the address is first announced // the way the XG stand-in announces a copy of desktop-footprint rows; with =after the announcement comes // between the publication and the draw. @@ -268,22 +269,31 @@ int draw_console_address_srv(void* guest, void* list) { wchar_t path[MAX_PATH]{}; const DWORD length = GetEnvironmentVariableW(L"X2W_TEST_CONSOLE_VIEW", path, MAX_PATH); - char text[96]{}; + char text[96]{}, dimension[4]{}; unsigned width = 0, height = 0, mips = 0, format = 0, layout = 0, viewed = 0; - if (!length || length >= MAX_PATH || !GetEnvironmentVariableA("X2W_TEST_CONSOLE_DESC", text, sizeof(text)) || - std::sscanf(text, "%u,%u,%u,%u,%u,%u", &width, &height, &mips, &format, &layout, &viewed) != 6) return 43; + if (!length || length >= MAX_PATH || !GetEnvironmentVariableA("X2W_TEST_CONSOLE_DESC", text, sizeof(text))) return 43; + const int fields = std::sscanf(text, "%u,%u,%u,%u,%u,%u,%3s", &width, &height, &mips, &format, &layout, &viewed, dimension); + const bool one_d = fields == 7 && !std::strcmp(dimension, "1d"); + if (fields != 6 && !one_d) return 43; alignas(4096) static std::array backing{}; std::ifstream input(path, std::ios::binary); input.read(backing.data(), backing.size()); if (!input.gcount() || !input.eof()) return 43; - const D3D12_RESOURCE_DESC desc{D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, width, height, 1, static_cast(mips), - static_cast(format), {1, 0}, static_cast(layout), D3D12_RESOURCE_FLAG_NONE}; + const D3D12_RESOURCE_DESC desc{one_d ? D3D12_RESOURCE_DIMENSION_TEXTURE1D : D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, width, + height, 1, static_cast(mips), static_cast(format), {1, 0}, + static_cast(layout), D3D12_RESOURCE_FLAG_NONE}; ViewAt v{}; v.view.Format = desc.Format; - v.view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; v.view.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; - v.view.Texture2D.MostDetailedMip = viewed; - v.view.Texture2D.MipLevels = 1; + if (one_d) { + v.view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE1D; + v.view.Texture1D.MostDetailedMip = viewed; + v.view.Texture1D.MipLevels = 1; + } else { + v.view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; + v.view.Texture2D.MostDetailedMip = viewed; + v.view.Texture2D.MipLevels = 1; + } v.address = ptr(backing.data()); Word cpu = 0; if (!bind_view_table(guest, list, cpu)) return 42; diff --git a/tests/startup_gfx10_layout_check.cpp b/tests/startup_gfx10_layout_check.cpp index 72cfb94b67..f4db10a2b2 100644 --- a/tests/startup_gfx10_layout_check.cpp +++ b/tests/startup_gfx10_layout_check.cpp @@ -49,6 +49,13 @@ D3D12_RESOURCE_DESC texture(UINT width, UINT height, UINT mips, UINT slices, DXG return d; } +D3D12_RESOURCE_DESC texture_1d(UINT width, UINT mips, UINT slices, DXGI_FORMAT format, UINT layout) +{ + D3D12_RESOURCE_DESC d = texture(width, 1, mips, slices, format, layout); + d.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE1D; + return d; +} + // One format per element size: 1, 2, 4, 8 and 16 bytes. constexpr DXGI_FORMAT by_size[5] = {DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT}; @@ -162,7 +169,7 @@ void check_tile64() void check_distinct_and_round_trip() { - struct Shape { UINT width, height, mips, slices; DXGI_FORMAT format; UINT layout; }; + struct Shape { UINT width, height, mips, slices; DXGI_FORMAT format; UINT layout; bool one_d = false; }; const Shape shapes[] = { {1000, 520, 10, 1, DXGI_FORMAT_BC1_UNORM, 0x105}, {300, 200, 9, 2, DXGI_FORMAT_R8_UNORM, 0x109}, {512, 1056, 1, 1, DXGI_FORMAT_BC1_UNORM, 0x105}, {1024, 2112, 1, 1, DXGI_FORMAT_R16_UNORM, 0x105}, @@ -171,9 +178,11 @@ void check_distinct_and_round_trip() {2048, 2048, 12, 1, DXGI_FORMAT_BC5_UNORM, 0x109}, {100, 10, 3, 1, DXGI_FORMAT_R16G16B16A16_FLOAT, 0x100}, {257, 129, 9, 2, DXGI_FORMAT_R8_UNORM, 0x100}, {256, 256, 7, 1, DXGI_FORMAT_R32_FLOAT, 0x100}, {64, 64, 4, 3, DXGI_FORMAT_BC1_UNORM, 0x100}, + {300, 1, 9, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 0x100, true}, {4096, 1, 13, 1, DXGI_FORMAT_R8_UNORM, 0x100, true}, }; for (const Shape& s : shapes) { - const D3D12_RESOURCE_DESC d = texture(s.width, s.height, s.mips, s.slices, s.format, s.layout); + const D3D12_RESOURCE_DESC d = s.one_d ? texture_1d(s.width, s.mips, s.slices, s.format, s.layout) + : texture(s.width, s.height, s.mips, s.slices, s.format, s.layout); const std::string name = std::to_string(s.width) + "x" + std::to_string(s.height) + " layout " + std::to_string(s.layout); if (!x2w_startup::gfx10::supports(d)) { fail(name + ": refused"); @@ -225,6 +234,11 @@ void check_refusals() d = good; d.Width = 16385; refused("too wide", d); d = good; d.DepthOrArraySize = 0; refused("no slices", d); d = good; d.Layout = static_cast(0x101); d.MipLevels = 2; refused("256 B chain", d); + if (!x2w_startup::gfx10::supports(texture_1d(300, 9, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0x100))) + fail("linear 1D RGBA8 chain refused"); + refused("1D in a 4 KiB swizzle mode", texture_1d(256, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0x105)); + d = texture_1d(256, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0x100); d.Height = 2; refused("1D two rows high", d); + refused("1D block-compressed", texture_1d(256, 1, 1, DXGI_FORMAT_BC1_UNORM, 0x100)); } // The linear mode by hand: a 100x10 R16G16B16A16 texture with three mips. Each mip's pitch is its @@ -261,6 +275,9 @@ void check_address_textures() expect("64 KiB display R16 chain", texture(512, 512, 10, 1, DXGI_FORMAT_R16_UNORM, 0x10a), true); expect("desktop layout RGBA8", texture(1, 1, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0), false); expect("linear mode R8", texture(256, 128, 1, 1, DXGI_FORMAT_R8_UNORM, 0x100), true); + expect("linear 1D RGBA8 sRGB", texture_1d(512, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 0x100), true); + expect("linear 1D array", texture_1d(512, 1, 4, DXGI_FORMAT_R8G8B8A8_UNORM, 0x100), false); + expect("desktop layout 1D", texture_1d(512, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0), false); expect("XOR mode", texture(256, 256, 1, 1, DXGI_FORMAT_BC7_UNORM, 0x119), false); expect("row-major desktop layout", texture(256, 256, 1, 1, DXGI_FORMAT_BC7_UNORM, 1), false); expect("unknown element size", texture(256, 256, 1, 1, DXGI_FORMAT_R32G32B32_FLOAT, 0), false); @@ -343,6 +360,29 @@ void check_address_textures() v.Texture3D.MipLevels = 4; v.Texture3D.ResourceMinLODClamp = 1.0f; if (x2w_startup::address_view_fits(vol, v)) fail("3D volume view explicit LOD clamp"); + + const D3D12_RESOURCE_DESC row = texture_1d(300, 9, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0x100); + v = {}; + v.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + v.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + v.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE1D; + v.Texture1D.MipLevels = 9; + if (!x2w_startup::address_view_fits(row, v)) fail("whole 1D chain view"); + v.Texture1D.MostDetailedMip = 8; + v.Texture1D.MipLevels = 1; + if (!x2w_startup::address_view_fits(row, v)) fail("last 1D mip view"); + v.Texture1D.MipLevels = 2; + if (x2w_startup::address_view_fits(row, v)) fail("1D view past the chain"); + v.Texture1D.MostDetailedMip = 0; + v.Texture1D.MipLevels = 1; + v.Texture1D.ResourceMinLODClamp = 1.0f; + if (x2w_startup::address_view_fits(row, v)) fail("1D view explicit LOD clamp"); + v.Texture1D.ResourceMinLODClamp = 0.0f; + if (x2w_startup::address_view_fits(texture(300, 1, 9, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0x100), v)) + fail("1D view on a 2D texture"); + v.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; + v.Texture2D.MipLevels = 1; + if (x2w_startup::address_view_fits(row, v)) fail("2D view on a 1D texture"); } } // namespace @@ -382,7 +422,7 @@ int addrlib_linear_check() create.callbacks.freeSysMem = free_sys_mem; create.regValue.gbAddrConfig = 0x40 | 4u | (4u << 8); if (AddrCreate(&create, &created) != ADDR_OK) return 1; - struct Shape { UINT width, height, mips, slices; DXGI_FORMAT format; }; + struct Shape { UINT width, height, mips, slices; DXGI_FORMAT format; bool one_d = false; }; const Shape shapes[] = { {1, 1, 1, 1, DXGI_FORMAT_R8_UNORM}, {300, 7, 1, 1, DXGI_FORMAT_R8_UNORM}, {257, 129, 9, 2, DXGI_FORMAT_R8_UNORM}, {100, 10, 3, 2, DXGI_FORMAT_R16G16B16A16_FLOAT}, @@ -390,11 +430,15 @@ int addrlib_linear_check() {33, 17, 6, 3, DXGI_FORMAT_R16_UNORM}, {200, 100, 8, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB}, {48, 40, 4, 2, DXGI_FORMAT_R32G32B32A32_FLOAT}, {64, 64, 4, 3, DXGI_FORMAT_BC1_UNORM}, {128, 64, 6, 1, DXGI_FORMAT_BC7_UNORM}, + {300, 1, 9, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, true}, {4096, 1, 13, 1, DXGI_FORMAT_R8_UNORM, true}, + {1000, 1, 10, 1, DXGI_FORMAT_R16G16B16A16_FLOAT, true}, }; unsigned compared = 0, mismatches = 0; for (const Shape& s : shapes) { - const D3D12_RESOURCE_DESC d = texture(s.width, s.height, s.mips, s.slices, s.format, 0x100); - const std::string name = std::to_string(s.width) + "x" + std::to_string(s.height) + " format " + + const D3D12_RESOURCE_DESC d = s.one_d ? texture_1d(s.width, s.mips, s.slices, s.format, 0x100) + : texture(s.width, s.height, s.mips, s.slices, s.format, 0x100); + const AddrResourceType type = s.one_d ? ADDR_RSRC_TEX_1D : ADDR_RSRC_TEX_2D; + const std::string name = std::string(s.one_d ? "1D " : "") + std::to_string(s.width) + "x" + std::to_string(s.height) + " format " + std::to_string(s.format) + ", " + std::to_string(s.mips) + " mips"; if (!x2w_startup::gfx10::supports(d)) { fail(name + ": refused"); @@ -408,7 +452,7 @@ int addrlib_linear_check() info_out.size = sizeof info_out; info_in.flags.texture = 1; info_in.swizzleMode = ADDR_SW_LINEAR; - info_in.resourceType = ADDR_RSRC_TEX_2D; + info_in.resourceType = type; info_in.bpp = l.bytes_per_element * 8; info_in.width = (s.width + l.texels - 1) / l.texels; info_in.height = (s.height + l.texels - 1) / l.texels; @@ -427,7 +471,7 @@ int addrlib_linear_check() in.size = sizeof in; in.flags.texture = 1; in.swizzleMode = ADDR_SW_LINEAR; - in.resourceType = ADDR_RSRC_TEX_2D; + in.resourceType = type; in.bpp = info_in.bpp; in.unalignedWidth = info_in.width; in.unalignedHeight = info_in.height; @@ -481,6 +525,6 @@ int main(int argc, char** argv) std::printf("startup_gfx10_layout: %d FAILED\n", failures); return 1; } - std::printf("startup_gfx10_layout: PASS (30 equations, 5 4 KiB surfaces, 8 64 KiB chains, 10 tile plans, 13 round trips, 1 linear chain, 11 refusals, 19 address descriptions, 27 views)\n"); + std::printf("startup_gfx10_layout: PASS (30 equations, 5 4 KiB surfaces, 8 64 KiB chains, 10 tile plans, 15 round trips, 1 linear chain, 14 refusals, 22 address descriptions, 33 views)\n"); return 0; } From 80443a788123a91e2bec9cb2117d96a9504134c3 Mon Sep 17 00:00:00 2001 From: lewisalex86 Date: Thu, 26 Nov 2026 21:09:37 +0000 Subject: [PATCH 2/4] startup: read linear (0x100) textures in slot 70 Slot 70 refused a 2D texture whose Layout is the ADDR_SW_LINEAR word 0x100 because the extent of its rows was not established. Restate addrlib's Gfx10Lib::HwlComputeSurfaceInfoLinear in gfx10_layout.h: each mip's pitch is its rounded-up width aligned to 256 bytes, and the mips are packed from the smallest to the largest with no tail. Such textures then take the existing console-layout path. 1D and 3D linear textures stay refused. Tests: linear round trips, a hand-worked chain with a mip-order control, an optional comparison of every element address with addrlib, four exact linear draws in startup_address_console and an unpadded-pitch control. --- docs/experiments/startup-gfx10-linear.md | 57 +++++++++ docs/startup-runtime.md | 7 +- src/startup_stubs/address_texture.h | 7 +- src/startup_stubs/gfx10_layout.h | 41 +++++-- tests/cmake/startup_gfx10_linear.cmake | 21 ++++ tests/startup_address_console_check.py | 64 ++++++++-- tests/startup_gfx10_layout_check.cpp | 149 ++++++++++++++++++++++- 7 files changed, 315 insertions(+), 31 deletions(-) create mode 100644 docs/experiments/startup-gfx10-linear.md create mode 100644 tests/cmake/startup_gfx10_linear.cmake diff --git a/docs/experiments/startup-gfx10-linear.md b/docs/experiments/startup-gfx10-linear.md new file mode 100644 index 0000000000..330d225c6d --- /dev/null +++ b/docs/experiments/startup-gfx10-linear.md @@ -0,0 +1,57 @@ +# Slot-70 textures in the console linear layout (0x100) + +Device slot 70 publishes a texture by address. A description whose `Layout` is `0x100` (the swizzle +mode word for `ADDR_SW_LINEAR`) was refused with `reason=unsupported_description` unless it was a +single texel, because the extent of its rows was not established. This note establishes it from AMD +addrlib and reads such textures like the tiled console layouts. + +## Layout + +`Gfx10Lib::HwlComputeSurfaceInfoLinear` (Mesa 25.1.0, commit +[5c142e46](https://gitlab.freedesktop.org/mesa/mesa/-/blob/5c142e46f3f6e752ed745fd48912ebb8fad67145/src/amd/addrlib/src/gfx10/gfx10addrlib.cpp), +`src/amd/addrlib`, MIT) gives the linear mode: + +- The pitch of a mip is its width in elements, rounded up at each level (`GetMipSize`), then aligned + to `256 / element bytes` elements: 256 bytes. +- The mip rows are packed with no tail block. The mips run from the smallest to the largest, so the + largest mip comes last. +- A slice is the sum of its mips, and the array slices follow one another. + +`src/startup_stubs/gfx10_layout.h` restates this rule for two-dimensional textures. The rest of the +slot-70 console path is unchanged: view checks, the XG holds and the upload as desktop footprint rows. +One-dimensional and three-dimensional linear textures are still refused. + +## Results + +Build: `slot70/linear-layout` on main 6ee878d8, 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: 13 round trips (4 of them linear, including a 2-slice R8 chain and a 3-slice BC1 chain) and one hand-worked linear chain (a 100x10 RGBA16F texture with 3 mips: 32x3 elements at offset 0, 64x5 at 768, 128x10 at 3328, 13568 bytes a slice) | +| `startup_gfx10_layout_linear_order_control` | expected failure: with the largest mip first, all 6 offset and address checks fail | +| `startup_gfx10_layout_linear_addrlib` | PASS: 338,763 sizes and element addresses of 11 linear textures (R8 to RGBA32F, BC1, BC7, odd sizes, up to 9 mips and 3 slices) match `Addr2ComputeSurfaceInfo` and `Addr2ComputeSurfaceAddrFromCoord` with `ADDR_SW_LINEAR`; skips (77) without addrlib | +| `startup_address_console_{warp,hardware}` | PASS: 4 new linear draws are exact on all 65,536 pixels. They are RGBA8 100x40 (400-byte rows padded to 512); its 4-mip chain viewed at mip 0 and at mip 2; and BC1 200x96 (50 blocks padded to 64). The 7 earlier draws and the 3 held/late cases are unchanged | +| `startup_address_console_linear_unpadded_{warp,hardware}` | PASS (control): the same RGBA8 100x40 texture with rows written at 400 bytes is published, and 63,488 of 65,536 pixels differ | + +Without the `gfx10_layout.h` and `address_texture.h` change (main 6ee878d8), the first linear draw +reads the null view: pixel (0,0) is `00000000`, but `010300ff` was expected. There is also no +`published console layout` line in the log. + +Commands (PowerShell, at the repository root, after `. .\tools\dev.ps1`; addrlib fetched with +`tools/fetch_addrlib.py`): + +```powershell +cmake --preset dev -DXBOX2WINDOWS_ADDRLIB_DIR=/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 + +- 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. diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 886a6dc4fd..40b44cf97b 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -3335,7 +3335,8 @@ texture with that description exists at the address, its view is created as befo 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 +4 KiB and 64 KiB blocks in the standard and display orders, no XOR) or the linear mode `0x100` (rows +whose pitch is rounded up to 256 bytes, the mips stored from the smallest up), 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 @@ -3344,8 +3345,8 @@ after AMD addrlib, Mesa 25.1.0, `src/amd/addrlib`, MIT). A 256 B layout is taken 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 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. -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 +Anything else is refused as before and leaves the destination descriptor unchanged: layout `0` +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. diff --git a/src/startup_stubs/address_texture.h b/src/startup_stubs/address_texture.h index 11d8337391..b5cdcc5150 100644 --- a/src/startup_stubs/address_texture.h +++ b/src/startup_stubs/address_texture.h @@ -5,9 +5,10 @@ // 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. +// The console's linear mode (0x100) is one of those layouts: rows with addrlib's 256-byte pitch. +// 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. #include "startup_stubs/gfx10_layout.h" diff --git a/src/startup_stubs/gfx10_layout.h b/src/startup_stubs/gfx10_layout.h index 87deac0414..f088ca4bc3 100644 --- a/src/startup_stubs/gfx10_layout.h +++ b/src/startup_stubs/gfx10_layout.h @@ -5,8 +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. The address equations, block dimensions and mip-tail -// rules follow AMD addrlib as Mesa carries it under src/amd/addrlib, at the revision +// 0x101, 0x102, 0x105, 0x106, 0x109 and 0x10a, and the linear mode 0x100. 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: // Copyright (C) 2007-2024 Advanced Micro Devices, Inc. All rights reserved. @@ -16,7 +16,9 @@ // - src/core/addrlib2.cpp: ComputeThinBlockDimension (a block is 2^ceil(n/2) by 2^floor(n/2) elements) // and GetMipTailDim (the tail holds mips up to half a block wide and one block high). // - src/gfx10/gfx10addrlib.cpp: ComputeSurfaceInfoMacroTiled (the tail block comes first in a slice, -// then the mips from the smallest to the largest; offsets and origins inside the tail block). +// then the mips from the smallest to the largest; offsets and origins inside the tail block), and +// HwlComputeSurfaceInfoLinear (ADDR_SW_LINEAR: each mip is rows of a pitch rounded up to 256 bytes, +// the mips stored from the smallest to the largest, with no tail). // The rules are restated here; no addrlib code is included. // Measurements are in elements: one texel, or one 4x4 block of a block-compressed format. @@ -55,6 +57,9 @@ inline UINT swizzle_mode(const D3D12_RESOURCE_DESC& d) return (layout & ~0xffu) == 0x100 ? layout & 0xff : ~0u; } +// ADDR_SW_LINEAR: rows, not blocks. +constexpr UINT linear_mode = 0; + inline UINT block_log2(UINT mode) { switch (mode) { @@ -68,20 +73,22 @@ inline UINT block_log2(UINT mode) // A two-dimensional, single-sample texture whose memory this header can address. inline bool supports(const D3D12_RESOURCE_DESC& d) { - const UINT log2 = block_log2(swizzle_mode(d)); - if (!log2 || d.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || !element_of(d.Format).bytes) return false; + 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; 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 log2 >= 12 || d.MipLevels == 1; // a 256 B block has no mip tail here + return mode == linear_mode || log2 >= 12 || d.MipLevels == 1; // a 256 B block has no mip tail here } struct Layout { UINT bytes_per_element = 0, texels = 1, width = 0, height = 0, mips = 0, slices = 0; UINT block_bytes = 0, block_width = 0, block_height = 0; + bool is_linear = false; // rows of row_pitch[mip] elements; block_* then describe one 256-byte row step UINT first_tail = 0; // first mip inside the shared tail block; mips when there is none std::uint64_t slice_size = 0; std::array start{}; // byte offset of a mip in its slice std::array blocks_wide{}, origin_x{}, origin_y{}; + std::array row_pitch{}; // elements per row of a linear mip std::array x_bits{}, y_bits{}; // in-block byte offset contributed by a coordinate explicit Layout(const D3D12_RESOURCE_DESC& d) @@ -91,6 +98,25 @@ struct Layout { bytes_per_element = element.bytes; texels = element.texels; const UINT mode = swizzle_mode(d), log2 = block_log2(mode); + 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; + if (mode == linear_mode) { + // HwlComputeSurfaceInfoLinear: the pitch of each mip is its width (rounded up, GetMipSize) + // aligned to 256 bytes, and the smallest mip comes first. + is_linear = true; + first_tail = mips; + block_bytes = 256; + block_width = 256 / bytes_per_element; + block_height = 1; + std::uint64_t offset = 0; + for (UINT mip = mips; mip-- > 0;) { + row_pitch[mip] = (shifted(columns0, mip) + block_width - 1) / block_width * block_width; + start[mip] = offset; + offset += std::uint64_t{row_pitch[mip]} * shifted(rows0, mip) * bytes_per_element; + } + slice_size = offset; + return; + } UINT element_log2 = 0; while ((1u << element_log2) < bytes_per_element) ++element_log2; const UINT count_log2 = log2 - element_log2, width_log2 = (count_log2 + 1) / 2; @@ -126,8 +152,6 @@ struct Layout { } // Mip sizes for the layout round up at every level (addrlib GetMipSize). - const UINT columns0 = (width + texels - 1) / texels, rows0 = (height + texels - 1) / texels; - const auto shifted = [](UINT v, UINT mip) { return (std::max)(1u, (v + (1u << mip) - 1) >> mip); }; const UINT tail_mips = log2 - 4; // most mips one tail block holds, for 4 KiB and 64 KiB blocks first_tail = mips; std::array size{}; @@ -173,6 +197,7 @@ struct Layout { std::uint64_t address(UINT mip, UINT x, UINT y, UINT slice) const { 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]); const std::uint64_t block = std::uint64_t{y / block_height} * blocks_wide[mip] + x / block_width; return base + start[mip] + block * block_bytes + (x_bits[x % block_width] | y_bits[y % block_height]); diff --git a/tests/cmake/startup_gfx10_linear.cmake b/tests/cmake/startup_gfx10_linear.cmake new file mode 100644 index 0000000000..9f68899b9e --- /dev/null +++ b/tests/cmake/startup_gfx10_linear.cmake @@ -0,0 +1,21 @@ +# The console linear mode (0x100) in src/startup_stubs/gfx10_layout.h. The mutated run expects the largest +# mip first and is a negative control; the addrlib run compares every element address of several linear +# textures with addrlib's SW_LINEAR (Mesa 25.1.0, src/amd/addrlib, MIT) and skips (77) without addrlib. +add_test(NAME startup_gfx10_layout_linear_order_control COMMAND startup_gfx10_layout_check --mutate linear-largest-first) +set_tests_properties(startup_gfx10_layout_linear_order_control PROPERTIES WILL_FAIL TRUE) +if(XBOX2WINDOWS_ADDRLIB_DIR) + target_link_libraries(startup_gfx10_layout_check PRIVATE xbw_addrlib) + target_compile_definitions(startup_gfx10_layout_check PRIVATE XBOX2WINDOWS_HAVE_ADDRLIB) +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. +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}" + "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_address_console_check.py" + "$" "${backend}" linear-unpadded) + set_tests_properties(startup_address_console_linear_unpadded_${backend} PROPERTIES TIMEOUT 90 SKIP_RETURN_CODE 77) + endforeach() +endif() diff --git a/tests/startup_address_console_check.py b/tests/startup_address_console_check.py index be74340afa..e451d3e45a 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. - seven textures, each drawn once; every pixel of the 512x128 target is + eleven textures, each drawn once; every pixel of the 512x128 target is compared with the texel the view names; then two held descriptions and one texture whose address is announced as XG rows after it was published @@ -17,9 +17,12 @@ chunks at its fenced submit, so B draws payload 32; A submitted again afterwards would read reused chunks, so it is refused before the execute: the target, read back after that submit, still holds payload 32 on the right (not A's payload 31) + linear-unpadded the control described at check_linear_unpadded The backing bytes are built here, independently of src/startup_stubs/gfx10_layout.h, from the address -equations of AMD addrlib's GFX10 pattern tables, written out below. Reference: addrlib as Mesa carries it +equations of AMD addrlib's GFX10 pattern tables, written out below, and for the linear mode (0x100) from +HwlComputeSurfaceInfoLinear: rows whose pitch is the mip's rounded-up width aligned to 256 bytes, the mips +stored from the smallest to the largest. Reference: addrlib as Mesa carries it under src/amd/addrlib at the revision tools/fetch_addrlib.py pins (Mesa 25.1.0, commit 5c142e46f3f6e752ed745fd48912ebb8fad67145), files src/gfx10/gfx10SwizzlePattern.h, src/gfx10/gfx10addrlib.cpp and src/core/addrlib2.cpp, each with the notice "Copyright (C) 2007-2024 Advanced Micro Devices, Inc. All @@ -43,9 +46,22 @@ class Console: - def __init__(self, width, height, mips, element, texels, layout): + def __init__(self, width, height, mips, element, texels, layout, unpadded=False): self.width, self.height, self.mips, self.element, self.texels = width, height, mips, element, texels mode = layout & 0xff + columns, rows = -(-width // texels), -(-height // texels) + size = lambda v, mip: max(1, (v + (1 << mip) - 1) >> mip) + self.linear = mode == 0 + if self.linear: + # unpadded: rows exactly one mip wide, for the control at check_linear_unpadded. + align = 1 if unpadded else 256 // element + self.pitch, self.start, offset = {}, {}, 0 + for mip in range(mips - 1, -1, -1): + self.pitch[mip] = -(-size(columns, mip) // align) * align + self.start[mip] = offset + offset += self.pitch[mip] * size(rows, mip) * element + self.bytes = offset + return self.log2 = {1: 8, 2: 8, 5: 12, 6: 12, 9: 16, 10: 16}[mode] bits = (DISPLAY if mode in (2, 6, 10) else STANDARD)[element].split() x_next, y_next = (sum(b[0] == axis for b in bits) for axis in "XY") @@ -58,8 +74,6 @@ def __init__(self, width, height, mips, element, texels, layout): y_next += 1 self.bits = bits self.block_w, self.block_h = 1 << x_next, 1 << y_next - columns, rows = -(-width // texels), -(-height // texels) - size = lambda v, mip: max(1, (v + (1 << mip) - 1) >> mip) tail_mips = self.log2 - 4 self.first_tail = mips if mips > 1: @@ -96,6 +110,8 @@ def rows(self, mip): return -(-max(1, self.height >> mip) // self.texels) def address(self, mip, x, y): + if self.linear: + return self.start[mip] + (y * self.pitch[mip] + x) * self.element if mip >= self.first_tail: ox, oy = self.origin[mip] return self.in_block(ox + x, oy + y) @@ -124,15 +140,20 @@ def bc1_block(mip, x, y): ("RGBA8 256x256 chain 64 KiB display, tail mip 2", 256, 256, 4, RGBA8, 0x10a, 2), ("RGBA8 256x256 chain 64 KiB display, tail mip 3", 256, 256, 4, RGBA8, 0x10a, 3), ("RGBA8 40x24 256 B standard", 40, 24, 1, RGBA8, 0x101, 0), + # Linear: 100 texels are 400 bytes, so each row is padded to 512; 200 BC1 texels are 50 blocks, padded to 64. + ("RGBA8 100x40 linear", 100, 40, 1, RGBA8, 0x100, 0), + ("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), ] -def build(width, height, mips, fmt, layout): +def build(width, height, mips, fmt, layout, unpadded=False): """Backing bytes and, per mip, the RGBA texels a correct detile shows.""" texels = 4 if fmt == BC1 else 1 element = 8 if fmt == BC1 else 4 images = [] - console = Console(width, height, mips, element, texels, layout) + console = Console(width, height, mips, element, texels, layout, unpadded) backing = bytearray(console.bytes) seen = set() for mip in range(mips): @@ -173,9 +194,9 @@ def build(width, height, mips, fmt, layout): {"X2W_TEST_CONSOLE_XG_ROWS": "after"}) -def check(directory, consumer, backend, case, extra=None, held=None, late=False): +def check(directory, consumer, backend, case, extra=None, held=None, late=False, unpadded=False): name, width, height, mips, fmt, layout, viewed = case - backing, images = build(width, height, mips, fmt, layout) + 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) @@ -206,18 +227,33 @@ def check(directory, consumer, backend, case, extra=None, held=None, late=False) print(f"{backend} {name}: published, then {TARGET_W * TARGET_H} pixels read the null view") return 0 image = images[viewed] + wrong = 0 for y in range(TARGET_H): for x in range(TARGET_W): pixel = actual[4 * (y * TARGET_W + x):4 * (y * TARGET_W + x) + 4] expect = image[4 * ((y % h) * w + x % w):4 * ((y % h) * w + x % w) + 4] - if pixel != expect: + if pixel != expect and not unpadded: raise AssertionError(f"{name}: pixel ({x},{y}) actual {pixel.hex()} expected {expect.hex()}") + wrong += pixel != expect if "slot70 texture kind 1: published console layout" not in log: 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") + 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) + + GATE_PAYLOADS = 18 KEEP_PAYLOADS = 32 # tests/startup_stream_draw.cpp, X2W_TEST_CONSOLE_KEEP @@ -330,9 +366,13 @@ def check_gate(directory, consumer, backend, mode): GATES = ("gate", "gate-ring", "gate-ring-reuse", "gate-ring-keep", "gate-ring-keep-release") if __name__ == "__main__": - if len(sys.argv) not in (3, 4) or (len(sys.argv) == 4 and sys.argv[3] not in GATES): - usage = "usage: startup_address_console_check.py [gate | gate-ring | gate-ring-reuse | gate-ring-keep | gate-ring-keep-release]\n" + modes = GATES + ("linear-unpadded",) + if len(sys.argv) not in (3, 4) or (len(sys.argv) == 4 and sys.argv[3] not in modes): + usage = "usage: startup_address_console_check.py [" + " | ".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])) 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])) diff --git a/tests/startup_gfx10_layout_check.cpp b/tests/startup_gfx10_layout_check.cpp index 81a1ccc77b..72cfb94b67 100644 --- a/tests/startup_gfx10_layout_check.cpp +++ b/tests/startup_gfx10_layout_check.cpp @@ -3,6 +3,8 @@ // tables (written out below as the nibbles those rows name), for six swizzle modes and five element sizes; // - agreement with the three narrower layouts already in the tree (bc7_4k_s.h, bc64_chain.h, tile64_plan.h); // - the mip offsets docs/experiments.md records for a 1024x1024 six-mip BC7 chain; +// - the linear mode (0x100): mip offsets worked out by hand from addrlib's HwlComputeSurfaceInfoLinear, +// and, with --addrlib, every element address of several linear textures against addrlib itself; // - that every element of every subresource gets its own bytes inside the texture, and that a // tile followed by a detile returns the rows it started from. // @@ -167,6 +169,8 @@ void check_distinct_and_round_trip() {640, 360, 10, 1, DXGI_FORMAT_BC7_UNORM, 0x10a}, {257, 129, 9, 3, DXGI_FORMAT_R8G8B8A8_UNORM, 0x106}, {96, 40, 1, 1, DXGI_FORMAT_R16G16B16A16_FLOAT, 0x102}, {4, 4, 3, 1, DXGI_FORMAT_BC3_UNORM, 0x109}, {2048, 2048, 12, 1, DXGI_FORMAT_BC5_UNORM, 0x109}, + {100, 10, 3, 1, DXGI_FORMAT_R16G16B16A16_FLOAT, 0x100}, {257, 129, 9, 2, DXGI_FORMAT_R8_UNORM, 0x100}, + {256, 256, 7, 1, DXGI_FORMAT_R32_FLOAT, 0x100}, {64, 64, 4, 3, DXGI_FORMAT_BC1_UNORM, 0x100}, }; for (const Shape& s : shapes) { const D3D12_RESOURCE_DESC d = texture(s.width, s.height, s.mips, s.slices, s.format, s.layout); @@ -210,7 +214,8 @@ void check_refusals() }; D3D12_RESOURCE_DESC d = good; d.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; refused("desktop layout", d); - d = good; d.Layout = static_cast(0x100); refused("linear mode", d); + d = good; d.Layout = static_cast(0x100); d.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D; + 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); @@ -222,6 +227,23 @@ void check_refusals() d = good; d.Layout = static_cast(0x101); d.MipLevels = 2; refused("256 B chain", d); } +// The linear mode by hand: a 100x10 R16G16B16A16 texture with three mips. Each mip's pitch is its +// rounded-up width aligned to 32 elements (256 bytes), and the mips are stored from the smallest up: +// mip 2 is 32x3 elements at 0, mip 1 64x5 at 768, mip 0 128x10 at 3328, 13568 bytes a slice. +// The mutated run expects the largest mip first and is a negative control. +void check_linear(bool largest_first) +{ + const Layout l(texture(100, 10, 3, 2, DXGI_FORMAT_R16G16B16A16_FLOAT, 0x100)); + const std::uint64_t start[3] = {largest_first ? 0u : 3328u, largest_first ? 10240u : 768u, largest_first ? 12800u : 0u}; + const UINT pitch[3] = {128, 64, 32}; + if (!l.is_linear || l.first_tail != 3 || l.slice_size != 13568 || l.bytes() != 2 * 13568) fail("linear: slice size"); + for (UINT mip = 0; mip < 3; ++mip) { + if (l.start[mip] != start[mip] || l.row_pitch[mip] != pitch[mip]) fail("linear: mip " + std::to_string(mip)); + const std::uint64_t want = 13568 + start[mip] + (2ull * pitch[mip] + 3) * 8; + if (l.address(mip, 3, 2, 1) != want) fail("linear: element (3, 2) of slice 1, mip " + std::to_string(mip)); + } +} + // Which slot-70 descriptions are taken, and how their texels are read (address_texture.h). void check_address_textures() { @@ -238,7 +260,7 @@ void check_address_textures() expect("not sampled", d, false); expect("64 KiB display R16 chain", texture(512, 512, 10, 1, DXGI_FORMAT_R16_UNORM, 0x10a), true); expect("desktop layout RGBA8", texture(1, 1, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0), false); - expect("linear mode R8", texture(256, 128, 1, 1, DXGI_FORMAT_R8_UNORM, 0x100), false); + expect("linear mode R8", texture(256, 128, 1, 1, DXGI_FORMAT_R8_UNORM, 0x100), true); expect("XOR mode", texture(256, 256, 1, 1, DXGI_FORMAT_BC7_UNORM, 0x119), false); expect("row-major desktop layout", texture(256, 256, 1, 1, DXGI_FORMAT_BC7_UNORM, 1), false); expect("unknown element size", texture(256, 256, 1, 1, DXGI_FORMAT_R32G32B32_FLOAT, 0), false); @@ -324,14 +346,131 @@ void check_address_textures() } } // namespace +#ifndef XBOX2WINDOWS_HAVE_ADDRLIB +int addrlib_linear_check() +{ + std::puts("startup_gfx10_layout --addrlib: SKIP (built without addrlib; run tools/fetch_addrlib.py and configure with " + "-DXBOX2WINDOWS_ADDRLIB_DIR=/src/amd/addrlib)"); + return 77; +} +#else +#include "addrinterface.h" + +namespace { +VOID* ADDR_API alloc_sys_mem(const ADDR_ALLOCSYSMEM_INPUT* in) { return std::malloc(in->sizeInBytes); } +ADDR_E_RETURNCODE ADDR_API free_sys_mem(const ADDR_FREESYSMEM_INPUT* in) +{ + std::free(in->pVirtAddr); + return ADDR_OK; +} +} // namespace + +// Every element of every subresource of several linear textures, and their sizes, against +// Addr2ComputeSurfaceAddrFromCoord and Addr2ComputeSurfaceInfo with ADDR_SW_LINEAR on Mesa's "navi21" +// (gfx10.3) configuration, the one xg_swizzle_select_check uses: family 0x8F, revision 0x28, +// GB_ADDR_CONFIG 0x444. Sizes are given to addrlib in elements, so a BC texture is its 4x4 blocks. +int addrlib_linear_check() +{ + ADDR_CREATE_INPUT create{}; + ADDR_CREATE_OUTPUT created{}; + create.size = sizeof create; + created.size = sizeof created; + create.chipEngine = 0x0000000D; // CIASICIDGFXENGINE_ARCTICISLAND + create.chipFamily = 0x8F; + create.chipRevision = 0x28; + create.callbacks.allocSysMem = alloc_sys_mem; + create.callbacks.freeSysMem = free_sys_mem; + create.regValue.gbAddrConfig = 0x40 | 4u | (4u << 8); + if (AddrCreate(&create, &created) != ADDR_OK) return 1; + struct Shape { UINT width, height, mips, slices; DXGI_FORMAT format; }; + const Shape shapes[] = { + {1, 1, 1, 1, DXGI_FORMAT_R8_UNORM}, {300, 7, 1, 1, DXGI_FORMAT_R8_UNORM}, + {257, 129, 9, 2, DXGI_FORMAT_R8_UNORM}, {100, 10, 3, 2, DXGI_FORMAT_R16G16B16A16_FLOAT}, + {1920, 64, 1, 1, DXGI_FORMAT_R16G16B16A16_FLOAT}, {256, 256, 7, 1, DXGI_FORMAT_R32_FLOAT}, + {33, 17, 6, 3, DXGI_FORMAT_R16_UNORM}, {200, 100, 8, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB}, + {48, 40, 4, 2, DXGI_FORMAT_R32G32B32A32_FLOAT}, {64, 64, 4, 3, DXGI_FORMAT_BC1_UNORM}, + {128, 64, 6, 1, DXGI_FORMAT_BC7_UNORM}, + }; + unsigned compared = 0, mismatches = 0; + for (const Shape& s : shapes) { + const D3D12_RESOURCE_DESC d = texture(s.width, s.height, s.mips, s.slices, s.format, 0x100); + const std::string name = std::to_string(s.width) + "x" + std::to_string(s.height) + " format " + + std::to_string(s.format) + ", " + std::to_string(s.mips) + " mips"; + if (!x2w_startup::gfx10::supports(d)) { + fail(name + ": refused"); + ++mismatches; + continue; + } + const Layout l(d); + ADDR2_COMPUTE_SURFACE_INFO_INPUT info_in{}; + ADDR2_COMPUTE_SURFACE_INFO_OUTPUT info_out{}; + info_in.size = sizeof info_in; + info_out.size = sizeof info_out; + info_in.flags.texture = 1; + info_in.swizzleMode = ADDR_SW_LINEAR; + info_in.resourceType = ADDR_RSRC_TEX_2D; + info_in.bpp = l.bytes_per_element * 8; + info_in.width = (s.width + l.texels - 1) / l.texels; + info_in.height = (s.height + l.texels - 1) / l.texels; + info_in.numSlices = s.slices; + info_in.numMipLevels = s.mips; + info_in.numSamples = 1; + info_in.numFrags = 1; + ++compared; + if (Addr2ComputeSurfaceInfo(created.hLib, &info_in, &info_out) != ADDR_OK || info_out.surfSize != l.bytes() || + info_out.sliceSize != l.slice_size) { + fail(name + ": size " + std::to_string(l.bytes()) + ", addrlib " + std::to_string(info_out.surfSize)); + ++mismatches; + continue; + } + ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT in{}; + in.size = sizeof in; + in.flags.texture = 1; + in.swizzleMode = ADDR_SW_LINEAR; + in.resourceType = ADDR_RSRC_TEX_2D; + in.bpp = info_in.bpp; + in.unalignedWidth = info_in.width; + in.unalignedHeight = info_in.height; + in.numSlices = s.slices; + in.numMipLevels = s.mips; + in.numSamples = 1; + in.numFrags = 1; + unsigned wrong = 0; + for (in.slice = 0; in.slice < s.slices; ++in.slice) + for (in.mipId = 0; in.mipId < s.mips; ++in.mipId) + for (in.y = 0; in.y < l.rows(in.mipId); ++in.y) + for (in.x = 0; in.x < l.columns(in.mipId); ++in.x) { + ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT out{}; + out.size = sizeof out; + ++compared; + const std::uint64_t mine = l.address(in.mipId, in.x, in.y, in.slice); + if (Addr2ComputeSurfaceAddrFromCoord(created.hLib, &in, &out) != ADDR_OK || out.addr != mine) { + if (!wrong++) + fail(name + ": mip " + std::to_string(in.mipId) + " slice " + std::to_string(in.slice) + " (" + + std::to_string(in.x) + ", " + std::to_string(in.y) + ") at " + std::to_string(mine) + + ", addrlib " + std::to_string(out.addr)); + } + } + mismatches += wrong; + } + AddrDestroy(created.hLib); + std::printf("startup_gfx10_layout --addrlib: %u linear sizes and addresses compared, %u mismatches (Mesa 25.1.0 addrlib, " + "SW_LINEAR)\n", compared, mismatches); + return compared && !mismatches ? 0 : 1; +} +#endif + int main(int argc, char** argv) { + if (argc == 2 && std::string(argv[1]) == "--addrlib") return addrlib_linear_check(); const bool mutate = argc == 3 && std::string(argv[1]) == "--mutate" && std::string(argv[2]) == "display"; - if (argc != 1 && !mutate) { - std::printf("usage: startup_gfx10_layout_check [--mutate display]\n"); + const bool mutate_linear = argc == 3 && std::string(argv[1]) == "--mutate" && std::string(argv[2]) == "linear-largest-first"; + if (argc != 1 && !mutate && !mutate_linear) { + std::printf("usage: startup_gfx10_layout_check [--addrlib | --mutate display | --mutate linear-largest-first]\n"); return 2; } check_equations(mutate); + check_linear(mutate_linear); check_bc7_4k(); check_bc64(); check_tile64(); @@ -342,6 +481,6 @@ int main(int argc, char** argv) std::printf("startup_gfx10_layout: %d FAILED\n", failures); return 1; } - std::printf("startup_gfx10_layout: PASS (30 equations, 5 4 KiB surfaces, 8 64 KiB chains, 10 tile plans, 9 round trips, 11 refusals, 19 address descriptions, 27 views)\n"); + std::printf("startup_gfx10_layout: PASS (30 equations, 5 4 KiB surfaces, 8 64 KiB chains, 10 tile plans, 13 round trips, 1 linear chain, 11 refusals, 19 address descriptions, 27 views)\n"); return 0; } From 146bf76190c37e999341b16ad4962d025abfcce6 Mon Sep 17 00:00:00 2001 From: lewisalex86 Date: Fri, 27 Nov 2026 09:02:59 +0000 Subject: [PATCH 3/4] startup: refuse 1D arrays in gfx10::supports address_view_fits already refused a 1D array, but gfx10::supports took one. Refuse it there too, so the layout check and the view check agree, and name the case in startup_gfx10_layout's refusals. --- docs/experiments/startup-gfx10-linear-1d.md | 4 ++-- src/startup_stubs/gfx10_layout.h | 5 +++-- tests/startup_gfx10_layout_check.cpp | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/experiments/startup-gfx10-linear-1d.md b/docs/experiments/startup-gfx10-linear-1d.md index 0d0bfc43d9..86c7d66e8f 100644 --- a/docs/experiments/startup-gfx10-linear-1d.md +++ b/docs/experiments/startup-gfx10-linear-1d.md @@ -16,7 +16,7 @@ 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 and the tiled modes stay refused for 1D. + 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. @@ -30,7 +30,7 @@ Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 5090 (driver 32.0.16.1088) and Mic | 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), 14 refusals (new: 1D in `0x105`, 1D two rows high, 1D BC1), 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` | 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) | diff --git a/src/startup_stubs/gfx10_layout.h b/src/startup_stubs/gfx10_layout.h index 0f18b7a023..58df4e5976 100644 --- a/src/startup_stubs/gfx10_layout.h +++ b/src/startup_stubs/gfx10_layout.h @@ -72,14 +72,15 @@ inline UINT block_log2(UINT mode) } // A two-dimensional, single-sample texture whose memory this header can address, or a one-dimensional -// one in the linear mode. addrlib refuses a 1D surface taller than one row (HwlComputeSurfaceInfoLinear). +// one in the linear mode. 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) { const UINT mode = swizzle_mode(d), log2 = block_log2(mode); 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 || element.texels != 1) return false; + 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; } diff --git a/tests/startup_gfx10_layout_check.cpp b/tests/startup_gfx10_layout_check.cpp index f4db10a2b2..489a77c410 100644 --- a/tests/startup_gfx10_layout_check.cpp +++ b/tests/startup_gfx10_layout_check.cpp @@ -239,6 +239,7 @@ void check_refusals() refused("1D in a 4 KiB swizzle mode", texture_1d(256, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0x105)); d = texture_1d(256, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0x100); d.Height = 2; refused("1D two rows high", d); refused("1D block-compressed", texture_1d(256, 1, 1, DXGI_FORMAT_BC1_UNORM, 0x100)); + refused("1D array", texture_1d(256, 1, 2, DXGI_FORMAT_R8G8B8A8_UNORM, 0x100)); } // The linear mode by hand: a 100x10 R16G16B16A16 texture with three mips. Each mip's pitch is its @@ -525,6 +526,6 @@ int main(int argc, char** argv) std::printf("startup_gfx10_layout: %d FAILED\n", failures); return 1; } - std::printf("startup_gfx10_layout: PASS (30 equations, 5 4 KiB surfaces, 8 64 KiB chains, 10 tile plans, 15 round trips, 1 linear chain, 14 refusals, 22 address descriptions, 33 views)\n"); + std::printf("startup_gfx10_layout: PASS (30 equations, 5 4 KiB surfaces, 8 64 KiB chains, 10 tile plans, 15 round trips, 1 linear chain, 15 refusals, 22 address descriptions, 33 views)\n"); return 0; } From d190f0db48f0de1b643895d1c7fea874905318f3 Mon Sep 17 00:00:00 2001 From: lewisalex86 Date: Thu, 26 Nov 2026 22:20:21 +0000 Subject: [PATCH 4/4] startup: bind cube views of console-layout textures in slot 70 A TEXTURECUBE view of a 2D array of exactly six slices in a console layout is now taken by address_view_fits (the slices are the faces in D3D order), and a translation manifest srv of kind texcube binds it. The translator does not emit texcube yet (gfx2hlsl refuses dim:SQ_RSRC_IMG_CUBE); the draws here use a hand-written shader. Adds six layout cube cases, three exact cube draws and a reversed-face-order negative control. --- docs/experiments/startup-slot70-cube.md | 54 +++++++++++ docs/startup-runtime.md | 4 +- src/startup_stubs/address_texture.h | 6 +- src/startup_stubs/d3d12_draw.inl | 25 +++--- src/startup_stubs/d3d12_memory_srv.inl | 1 + tests/cmake/startup_slot70_cube.cmake | 11 +++ tests/startup_address_console_check.py | 113 +++++++++++++++++++++++- tests/startup_address_srv.cpp | 16 ++-- tests/startup_gfx10_layout_check.cpp | 24 ++++- 9 files changed, 232 insertions(+), 22 deletions(-) create mode 100644 docs/experiments/startup-slot70-cube.md create mode 100644 tests/cmake/startup_slot70_cube.cmake diff --git a/docs/experiments/startup-slot70-cube.md b/docs/experiments/startup-slot70-cube.md new file mode 100644 index 0000000000..64e6775ac4 --- /dev/null +++ b/docs/experiments/startup-slot70-cube.md @@ -0,0 +1,54 @@ +# Slot-70 cube views of console-layout textures + +Device slot 70 publishes a texture by address. A description that is a two-dimensional array of six slices +in a console layout, with a `TEXTURECUBE` view, was refused with `reason=unsupported_description`, because +`address_view_fits` had no cube view. This note takes such views and binds them in a translated draw that +declares a cube texture. + +The translator does not declare one yet: `tools/startup/gfx2hlsl.py` refuses an image instruction with +`dim:SQ_RSRC_IMG_CUBE` (`image dimension SQ_RSRC_IMG_CUBE`). Until it lowers cube sampling to a +`TextureCube` and writes the `texcube` manifest kind, no translated shader reads these views. The draws here +use a hand-written pixel shader and manifest. + +## Change + +- `src/startup_stubs/address_texture.h`: `address_view_fits` takes a `TEXTURECUBE` view of a 2D texture of + exactly six slices that fits the mip range with no LOD clamp. The faces are the slices in D3D order + (+X, -X, +Y, -Y, +Z, -Z). The slices are already addressed and uploaded like any 2D array. +- `src/startup_stubs/d3d12_memory_srv.inl`: the desktop format check also asks for + `D3D12_FORMAT_SUPPORT1_TEXTURECUBE` for a cube view. +- `src/startup_stubs/d3d12_draw.inl`: a manifest `srv` line of kind `texcube` (kind 5) binds a + `TEXTURECUBE` view. The view dimension of each kind is now in one function. + A cube view where the shader declares `tex2da`, or the reverse, still binds null (view dimension mismatch). + The d16 exact path still takes only kinds 1 to 4. + +## Results + +Build: `slot70/cube-views`, stacked on `slot70/linear-1d` (42c3bff5), 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: 39 views (new: a whole BC1 cube chain, its last mip, past the chain, an LOD clamp, a cube view of one slice and of an array of twelve) | +| `startup_address_console_{warp,hardware}` | PASS: 3 new cube draws are exact on all 65,536 pixels, covering every texel of all six faces: RGBA8 64x64 in `0x105`, its 4-mip chain viewed at mip 1, and BC1 64x64 in `0x105`. The shader point-samples each texel centre along the face's direction | +| `startup_address_console_cube_order_{warp,hardware}` | PASS (control): the first cube with face f written into slice 5 - f is published and all 65,536 pixels differ | + +Without the source change (42c3bff5), the first cube 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 +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|cube_order_(warp|hardware))$' -V +``` + +## Open + +- The translator side: `image_sample*` and `image_load*` with `dim:SQ_RSRC_IMG_CUBE`. A GFX10 cube sample + takes face-relative coordinates and a face index that the `v_cube*` instructions compute (which + `tools/startup/gfx2hlsl.py` already lowers). A lowering to `TextureCube` would rebuild a direction from + them. That is not attempted here. +- A cube view of a larger array, and cube arrays (`TEXTURECUBEARRAY`), stay refused. diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index caefcbd881..736a38439e 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -3344,9 +3344,9 @@ after AMD addrlib, Mesa 25.1.0, `src/amd/addrlib`, MIT). A 256 B layout is taken 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 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. +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. Anything else is refused as before and leaves the destination descriptor unchanged: layout `0` -without a live texture, three-dimensional and cube views, multisampled +without a live texture, three-dimensional views, cube views of other arrays, multisampled textures, the XOR swizzle modes and every other layout value. The texels must be readable and span at most 64 MiB. diff --git a/src/startup_stubs/address_texture.h b/src/startup_stubs/address_texture.h index 0cc8e8477c..96adf146b7 100644 --- a/src/startup_stubs/address_texture.h +++ b/src/startup_stubs/address_texture.h @@ -74,7 +74,7 @@ inline bool address_component_mapping(UINT mapping) return true; } -// A one-dimensional, two-dimensional or array view that stays inside the texture and reads its texels +// A one-dimensional, two-dimensional, array or cube 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) { @@ -98,6 +98,10 @@ inline bool address_view_fits(const D3D12_RESOURCE_DESC& r, const D3D12_SHADER_R mips_fit(v.Texture2DArray.MostDetailedMip, v.Texture2DArray.MipLevels) && inside(v.Texture2DArray.FirstArraySlice, v.Texture2DArray.ArraySize, r.DepthOrArraySize) && !v.Texture2DArray.PlaneSlice && v.Texture2DArray.ResourceMinLODClamp == 0.0f; + // A cube view reads the six slices of a two-dimensional array of six as its faces (+X, -X, +Y, -Y, +Z, -Z). + if (v.ViewDimension == D3D12_SRV_DIMENSION_TEXTURECUBE) + return r.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D && r.DepthOrArraySize == 6 && + mips_fit(v.TextureCube.MostDetailedMip, v.TextureCube.MipLevels) && v.TextureCube.ResourceMinLODClamp == 0.0f; if (v.ViewDimension == D3D12_SRV_DIMENSION_TEXTURE3D) return r.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D && mips_fit(v.Texture3D.MostDetailedMip, v.Texture3D.MipLevels) && diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index d4ed161c58..021dc2848e 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -150,7 +150,7 @@ const char* pixel_uav_view(ID3D12Device* device, const D3D12_RESOURCE_DESC& reso } struct Translation { - struct Srv { int kind, source, a, b; }; // kind 0 buffer, 1 2D texture, 2 2D array, 3 3D texture, 4 1D texture; source 0 table(param a, byte b), 1 vertex stream a, 2 root parameter a + struct Srv { int kind, source, a, b; }; // kind 0 buffer, 1 2D texture, 2 2D array, 3 3D texture, 4 1D texture, 5 cube; source 0 table(param a, byte b), 1 vertex stream a, 2 root parameter a enum UdKind { rect, base_vertex, start_instance, root_constant, stride, mrt_bits, d16_unorm16, desc_word3 }; struct Ud { int kind, a, b; }; int state = 0; // 1 ready, 2 unavailable @@ -327,7 +327,8 @@ void load_translation(Translation& tr, const std::string& rtv_request = {}) if (static_cast(i) == tr.uds.size() && ud.kind >= 0) tr.uds.push_back(ud); } else if (std::sscanf(line.c_str(), "srv %d %15s %15s %d %d", &i, kind, source, &x, &y) >= 4) { const int texture_kind = !std::strcmp(kind, "tex2d") ? 1 : !std::strcmp(kind, "tex2da") ? 2 : - !std::strcmp(kind, "tex3d") ? 3 : !std::strcmp(kind, "tex1d") ? 4 : 0; + !std::strcmp(kind, "tex3d") ? 3 : !std::strcmp(kind, "tex1d") ? 4 : + !std::strcmp(kind, "texcube") ? 5 : 0; Translation::Srv srv{texture_kind, !std::strcmp(source, "vb") ? 1 : !std::strcmp(source, "root") ? 2 : 0, x, y}; if (static_cast(i) == tr.srvs.size()) tr.srvs.push_back(srv); } else if (line.compare(0, 6, "wmask ") == 0) { @@ -1686,6 +1687,14 @@ void draw_dump_flush() log("x2w-draw per-draw dump: %d of %zu completed target copies written to %s", written, completed.size(), folder); } +// The view dimension a manifest texture kind declares (Translation::Srv::kind 1 to 5). +D3D12_SRV_DIMENSION translated_view_dimension(int kind) +{ + return kind == 1 ? D3D12_SRV_DIMENSION_TEXTURE2D : kind == 2 ? D3D12_SRV_DIMENSION_TEXTURE2DARRAY : + kind == 4 ? D3D12_SRV_DIMENSION_TEXTURE1D : kind == 5 ? D3D12_SRV_DIMENSION_TEXTURECUBE : + D3D12_SRV_DIMENSION_TEXTURE3D; +} + bool d16_srvs_ready(const Translation& tr, const Pass& pass, std::uint32_t (&d16_unorm16)[32]) { if (!tr.d16_srvs.any()) return true; @@ -1700,9 +1709,7 @@ bool d16_srvs_ready(const Translation& tr, const Pass& pass, std::uint32_t (&d16 const Translation::Srv& srv = tr.srvs[i]; if (srv.kind < 1 || srv.kind > 4 || srv.source != 0 || srv.a < 0 || srv.a >= 16 || srv.b < 0) return refuse(i, "non-table texture binding", srv.kind); - const auto dimension = srv.kind == 1 ? D3D12_SRV_DIMENSION_TEXTURE2D : - srv.kind == 2 ? D3D12_SRV_DIMENSION_TEXTURE2DARRAY : - srv.kind == 4 ? D3D12_SRV_DIMENSION_TEXTURE1D : D3D12_SRV_DIMENSION_TEXTURE3D; + const auto dimension = translated_view_dimension(srv.kind); const u64 entry = pass.view_tables[srv.a].record(static_cast(srv.b), 32); std::uint32_t words[8] = {}; if (!entry || !x2w_local::readable(reinterpret_cast(entry), 32)) @@ -2203,7 +2210,7 @@ bool resolve_pixel_uavs(const Translation& tr, const Pass& pass, PixelUavBinding return refuse(i, "the texture is also a render or depth target of this draw", reinterpret_cast(texture)); for (std::size_t s = 0; s < tr.srvs.size(); ++s) { const Translation::Srv& srv = tr.srvs[s]; - if (srv.kind < 1 || srv.kind > 4 || srv.source != 0 || srv.a < 0 || srv.a >= 16 || srv.b < 0) continue; + if (srv.kind < 1 || srv.kind > 5 || srv.source != 0 || srv.a < 0 || srv.a >= 16 || srv.b < 0) continue; const u64 srv_entry = pass.view_tables[srv.a].record(static_cast(srv.b), 32); std::uint32_t srv_words[8] = {}; if (!srv_entry || !x2w_local::readable(reinterpret_cast(srv_entry), 32)) continue; @@ -2412,10 +2419,8 @@ bool draw_translated(Wrapper* self, bool indexed, UINT count, UINT instances, UI (entry && x2w_local::readable(reinterpret_cast(entry), 32)); if (entry_ok) std::memcpy(words, formatted.entry ? formatted.words : reinterpret_cast(entry), 32); bool buffer_token_known = false; - if (srv.kind >= 1 && srv.kind <= 4) { - const auto dimension = srv.kind == 1 ? D3D12_SRV_DIMENSION_TEXTURE2D : - srv.kind == 2 ? D3D12_SRV_DIMENSION_TEXTURE2DARRAY : - srv.kind == 4 ? D3D12_SRV_DIMENSION_TEXTURE1D : D3D12_SRV_DIMENSION_TEXTURE3D; + if (srv.kind >= 1 && srv.kind <= 5) { + const auto dimension = translated_view_dimension(srv.kind); // A texture: the title's descriptor memory carries the id of the view it created there. ViewRecord record{}; bool known = false; diff --git a/src/startup_stubs/d3d12_memory_srv.inl b/src/startup_stubs/d3d12_memory_srv.inl index a14b834b28..806a806e59 100644 --- a/src/startup_stubs/d3d12_memory_srv.inl +++ b/src/startup_stubs/d3d12_memory_srv.inl @@ -119,6 +119,7 @@ bool desktop_address_view_supported(Wrapper* device, const D3D12_RESOURCE_DESC& : r.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE1D ? D3D12_FORMAT_SUPPORT1_TEXTURE1D : D3D12_FORMAT_SUPPORT1_TEXTURE2D; return (storage.Support1 & req) && + (v.ViewDimension != D3D12_SRV_DIMENSION_TEXTURECUBE || (storage.Support1 & D3D12_FORMAT_SUPPORT1_TEXTURECUBE)) && (r.MipLevels == 1 || (storage.Support1 & D3D12_FORMAT_SUPPORT1_MIP)); } diff --git a/tests/cmake/startup_slot70_cube.cmake b/tests/cmake/startup_slot70_cube.cmake new file mode 100644 index 0000000000..a08996ad58 --- /dev/null +++ b/tests/cmake/startup_slot70_cube.cmake @@ -0,0 +1,11 @@ +# Cube views of console-layout textures published by address (device slot 70). The cube draws run inside +# startup_address_console_{warp,hardware}; this is their negative control: the faces written in reverse slice +# order 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_cube_order_${backend} COMMAND "${CMAKE_COMMAND}" -E env "X2W_FXC=${STARTUP_FXC}" + "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_address_console_check.py" + "$" "${backend}" cube-order) + set_tests_properties(startup_address_console_cube_order_${backend} PROPERTIES TIMEOUT 90 SKIP_RETURN_CODE 77) + endforeach() +endif() diff --git a/tests/startup_address_console_check.py b/tests/startup_address_console_check.py index 24fc9f4434..7e61d6d4a0 100644 --- a/tests/startup_address_console_check.py +++ b/tests/startup_address_console_check.py @@ -1,7 +1,7 @@ """Draw textures published by address (device slot 70) whose texels are in a console layout. - fourteen textures, each drawn once; every pixel of the 512x128 target is - compared with the texel the view names; then two held descriptions + fourteen textures and three cubes, each drawn once; every pixel of the + 512x128 target is compared with the texel the view names; then two held descriptions and one texture whose address is announced as XG rows after it was published gate the upload lifetime control described at check_gate @@ -18,6 +18,7 @@ would read reused chunks, so it is refused before the execute: the target, read back after that submit, still holds payload 32 on the right (not A's payload 31) linear-unpadded the control described at check_linear_unpadded + cube-order the control described at check_cube_order The backing bytes are built here, independently of src/startup_stubs/gfx10_layout.h, from the address equations of AMD addrlib's GFX10 pattern tables, written out below, and for the linear mode (0x100) from @@ -276,6 +277,105 @@ def check_linear_unpadded(directory, consumer, backend): KEEP_PAYLOADS = 32 # tests/startup_stream_draw.cpp, X2W_TEST_CONSOLE_KEEP +# Cube views: a two-dimensional array of six in a console layout, each slice one face (+X, -X, +Y, -Y, +Z, +# -Z) and the slices one slice size apart (the whole mip chain of a slice). TextureCube has no Load, so the +# shader point-samples the centre of every texel of every face of the viewed mip: target column x picks face +# (x mod 6w) div w and column x mod w, row y picks row y mod w. The directions are the D3D cube face rules. +# name, side, mips, format, layout, viewed mip +CUBES = [ + ("RGBA8 64x64 cube 4 KiB standard", 64, 1, RGBA8, 0x105, 0), + ("RGBA8 64x64 cube 4 KiB standard chain, mip 1", 64, 4, RGBA8, 0x105, 1), + ("BC1 64x64 cube 4 KiB standard", 64, 1, BC1, 0x105, 0), +] + + +def cube_texel(face, mip, x, y): + texel = bytearray(rgba_texel(mip, x, y)) + texel[2] = (texel[2] + 37 * face) & 255 + return bytes(texel) + + +def build_cube(side, mips, fmt, layout, reversed_faces=False): + """Backing bytes and images[face][mip]. reversed_faces writes face f into slice 5 - f (the control).""" + texels = 4 if fmt == BC1 else 1 + element = 8 if fmt == BC1 else 4 + console = Console(side, side, mips, element, texels, layout) + backing = bytearray(6 * console.bytes) + images = [[None] * mips for _ in range(6)] + for face in range(6): + base = (5 - face if reversed_faces else face) * console.bytes + for mip in range(mips): + w = max(1, side >> mip) + image = bytearray(w * w * 4) + for y in range(console.rows(mip)): + for x in range(console.columns(mip)): + at = base + console.address(mip, x, y) + if fmt == BC1: + block, colour = bc1_block(mip + 3 * face, x, y) + backing[at:at + 8] = block + for row in range(4 * y, min(4 * y + 4, w)): + for column in range(4 * x, min(4 * x + 4, w)): + image[4 * (row * w + column):4 * (row * w + column) + 4] = colour + else: + texel = cube_texel(face, mip, x, y) + backing[at:at + 4] = texel + image[4 * (y * w + x):4 * (y * w + x) + 4] = texel + images[face][mip] = image + return backing, images + + +def check_cube(directory, consumer, backend, case, reversed_faces=False): + name, side, mips, fmt, layout, viewed = case + backing, images = build_cube(side, mips, fmt, layout, reversed_faces) + source = directory / "texels.bin" + source.write_bytes(backing) + w = max(1, side >> viewed) + hlsl = ("TextureCube t : register(t0);\n" + "SamplerState s : register(s0);\n" + "float4 main(float4 p : SV_Position) : SV_Target {\n" + f" uint x = uint(p.x) % {6 * w}, y = uint(p.y) % {w}, face = x / {w};\n" + f" float a = (float(x % {w}) + 0.5) / {w} * 2 - 1, b = (float(y) + 0.5) / {w} * 2 - 1;\n" + " float3 d = face == 0 ? float3(1, -b, -a) : face == 1 ? float3(-1, -b, a) :\n" + " face == 2 ? float3(a, 1, b) : face == 3 ? float3(a, -1, -b) :\n" + " face == 4 ? float3(a, -b, 1) : float3(-a, -b, -1);\n" + " return t.SampleLevel(s, d, 0);\n}\n") + trap_log = directory / "trap.log" + modes = {"X2W_TEST_CONSOLE_VIEW": str(source), "X2W_TRAP_LOG": str(trap_log), + "X2W_TEST_CONSOLE_DESC": f"{side},{side},{mips},{fmt},{layout},{viewed},cube"} + actual = draw_texture(directory, consumer, backend, hlsl, modes, + binding="srv 0 texcube table 0 0\nsmp 0 0 0 0 0") + if actual is None: + return 77 + if len(actual) != TARGET_W * TARGET_H * 4: + raise AssertionError(f"{name}: readback length {len(actual)}") + wrong = 0 + for y in range(TARGET_H): + for x in range(TARGET_W): + pixel = actual[4 * (y * TARGET_W + x):4 * (y * TARGET_W + x) + 4] + column = x % (6 * w) + image = images[column // w][viewed] + expect = image[4 * ((y % w) * w + column % w):4 * ((y % w) * w + column % w) + 4] + if pixel != expect and not reversed_faces: + raise AssertionError(f"{name}: pixel ({x},{y}) actual {pixel.hex()} expected {expect.hex()}") + wrong += pixel != expect + if "slot70 texture kind 1: published console layout" not in trap_log.read_text(errors="replace"): + raise AssertionError(f"{name}: no 'published console layout' line in the log") + if reversed_faces: + if not wrong: + raise AssertionError(f"{name}: faces written in reverse slice order drew exactly; the face order is not checked") + print(f"{backend} {name}, faces in reverse slice order: published, {wrong} of {TARGET_W * TARGET_H} pixels differ") + return 0 + print(f"{backend} {name}: {TARGET_W * TARGET_H} RGBA pixels exact over 6 faces") + return 0 + + +def check_cube_order(consumer, backend): + """The cube cases' negative control: the first cube with face f written into slice 5 - f. The runtime + reads slice f as face f, so the draw must differ from the texels.""" + with tempfile.TemporaryDirectory() as temporary: + return check_cube(Path(temporary), consumer, backend, CUBES[0], reversed_faces=True) + + def gate_colour(payload): """The colour of every texel of a payload; tests/startup_address_srv.cpp writes the same bytes.""" return bytes(((17 * payload + 3) & 255, (255 - 9 * payload) & 255, payload ^ 0x5a, 255)) @@ -384,12 +484,14 @@ def check_gate(directory, consumer, backend, mode): GATES = ("gate", "gate-ring", "gate-ring-reuse", "gate-ring-keep", "gate-ring-keep-release") if __name__ == "__main__": - modes = GATES + ("linear-unpadded",) + modes = GATES + ("linear-unpadded", "cube-order") if len(sys.argv) not in (3, 4) or (len(sys.argv) == 4 and sys.argv[3] not in modes): usage = "usage: startup_address_console_check.py [" + " | ".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": sys.exit(check_linear_unpadded(None, sys.argv[1], sys.argv[2])) + if len(sys.argv) == 4 and sys.argv[3] == "cube-order": + sys.exit(check_cube_order(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])) @@ -398,6 +500,11 @@ def check_gate(directory, consumer, backend, mode): result = check(Path(temporary), *sys.argv[1:3], case) if result: sys.exit(result) + for case in CUBES: + with tempfile.TemporaryDirectory() as temporary: + result = check_cube(Path(temporary), *sys.argv[1:3], case) + if result: + sys.exit(result) for case, extra, held in HELD: with tempfile.TemporaryDirectory() as temporary: result = check(Path(temporary), *sys.argv[1:3], case, extra, held) diff --git a/tests/startup_address_srv.cpp b/tests/startup_address_srv.cpp index a225708afc..a4be195600 100644 --- a/tests/startup_address_srv.cpp +++ b/tests/startup_address_srv.cpp @@ -261,7 +261,8 @@ int draw_bc_address_srvs(void* guest, void* list) // X2W_TEST_CONSOLE_VIEW names a file of texels and X2W_TEST_CONSOLE_DESC the texture they belong to // ("width,height,mips,format,layout,viewed mip", then optionally ",1d" for a one-dimensional texture with a -// one-dimensional view). No resource object exists at the address; one mip is +// one-dimensional view, or ",cube" for a two-dimensional array of six with a cube view). No resource object +// exists at the address; one mip is // viewed and drawn over the whole target. With X2W_TEST_CONSOLE_XG_ROWS=1 the address is first announced // the way the XG stand-in announces a copy of desktop-footprint rows; with =after the announcement comes // between the publication and the draw. @@ -269,18 +270,19 @@ int draw_console_address_srv(void* guest, void* list) { wchar_t path[MAX_PATH]{}; const DWORD length = GetEnvironmentVariableW(L"X2W_TEST_CONSOLE_VIEW", path, MAX_PATH); - char text[96]{}, dimension[4]{}; + char text[96]{}, dimension[5]{}; unsigned width = 0, height = 0, mips = 0, format = 0, layout = 0, viewed = 0; if (!length || length >= MAX_PATH || !GetEnvironmentVariableA("X2W_TEST_CONSOLE_DESC", text, sizeof(text))) return 43; - const int fields = std::sscanf(text, "%u,%u,%u,%u,%u,%u,%3s", &width, &height, &mips, &format, &layout, &viewed, dimension); + const int fields = std::sscanf(text, "%u,%u,%u,%u,%u,%u,%4s", &width, &height, &mips, &format, &layout, &viewed, dimension); const bool one_d = fields == 7 && !std::strcmp(dimension, "1d"); - if (fields != 6 && !one_d) return 43; + const bool cube = fields == 7 && !std::strcmp(dimension, "cube"); + if (fields != 6 && !one_d && !cube) return 43; alignas(4096) static std::array backing{}; std::ifstream input(path, std::ios::binary); input.read(backing.data(), backing.size()); if (!input.gcount() || !input.eof()) return 43; const D3D12_RESOURCE_DESC desc{one_d ? D3D12_RESOURCE_DIMENSION_TEXTURE1D : D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, width, - height, 1, static_cast(mips), static_cast(format), {1, 0}, + height, static_cast(cube ? 6 : 1), static_cast(mips), static_cast(format), {1, 0}, static_cast(layout), D3D12_RESOURCE_FLAG_NONE}; ViewAt v{}; v.view.Format = desc.Format; @@ -289,6 +291,10 @@ int draw_console_address_srv(void* guest, void* list) v.view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE1D; v.view.Texture1D.MostDetailedMip = viewed; v.view.Texture1D.MipLevels = 1; + } else if (cube) { + v.view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBE; + v.view.TextureCube.MostDetailedMip = viewed; + v.view.TextureCube.MipLevels = 1; } else { v.view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; v.view.Texture2D.MostDetailedMip = viewed; diff --git a/tests/startup_gfx10_layout_check.cpp b/tests/startup_gfx10_layout_check.cpp index 489a77c410..f0d54e13c1 100644 --- a/tests/startup_gfx10_layout_check.cpp +++ b/tests/startup_gfx10_layout_check.cpp @@ -384,6 +384,28 @@ void check_address_textures() v.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; v.Texture2D.MipLevels = 1; if (x2w_startup::address_view_fits(row, v)) fail("2D view on a 1D texture"); + + const D3D12_RESOURCE_DESC faces = texture(64, 64, 4, 6, DXGI_FORMAT_BC1_UNORM, 0x105); + v = {}; + v.Format = DXGI_FORMAT_BC1_UNORM; + v.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + v.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBE; + v.TextureCube.MipLevels = 4; + if (!x2w_startup::address_view_fits(faces, v)) fail("whole cube chain view"); + v.TextureCube.MostDetailedMip = 3; + v.TextureCube.MipLevels = 1; + if (!x2w_startup::address_view_fits(faces, v)) fail("last cube mip view"); + v.TextureCube.MipLevels = 2; + if (x2w_startup::address_view_fits(faces, v)) fail("cube view past the chain"); + v.TextureCube.MostDetailedMip = 0; + v.TextureCube.MipLevels = 1; + v.TextureCube.ResourceMinLODClamp = 1.0f; + if (x2w_startup::address_view_fits(faces, v)) fail("cube view explicit LOD clamp"); + v.TextureCube.ResourceMinLODClamp = 0.0f; + if (x2w_startup::address_view_fits(texture(64, 64, 4, 1, DXGI_FORMAT_BC1_UNORM, 0x105), v)) + fail("cube view on a single slice"); + if (x2w_startup::address_view_fits(texture(64, 64, 4, 12, DXGI_FORMAT_BC1_UNORM, 0x105), v)) + fail("cube view on an array of twelve"); } } // namespace @@ -526,6 +548,6 @@ int main(int argc, char** argv) std::printf("startup_gfx10_layout: %d FAILED\n", failures); return 1; } - std::printf("startup_gfx10_layout: PASS (30 equations, 5 4 KiB surfaces, 8 64 KiB chains, 10 tile plans, 15 round trips, 1 linear chain, 15 refusals, 22 address descriptions, 33 views)\n"); + std::printf("startup_gfx10_layout: PASS (30 equations, 5 4 KiB surfaces, 8 64 KiB chains, 10 tile plans, 15 round trips, 1 linear chain, 15 refusals, 22 address descriptions, 39 views)\n"); return 0; }