diff --git a/docs/experiments/startup-gfx10-linear-1d.md b/docs/experiments/startup-gfx10-linear-1d.md new file mode 100644 index 0000000000..86c7d66e8f --- /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, 1D arrays and the tiled modes stay refused for 1D. +- `address_texture.h`: a 1D array is refused, since the draw uploads a 1D texture only when it is not + an array (`d3d12_draw.inl`). `address_view_fits` takes a `TEXTURE1D` view of a 1D texture that fits + the mip range with no LOD clamp. +- `d3d12_memory_srv.inl`: the desktop format check asks for `D3D12_FORMAT_SUPPORT1_TEXTURE1D` for a + 1D texture. + +## Results + +Build: `slot70/linear-1d`, stacked on `slot70/linear-layout` (ce2d6f50), dev preset (debug layer on). +Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 5090 (driver 32.0.16.1088) and Microsoft WARP. + +| Test | Result | +| --- | --- | +| `startup_gfx10_layout` | PASS: 15 round trips (2 new 1D linear shapes: RGBA8 sRGB 300 with 9 mips, R8 4096 with 13 mips), 15 refusals (new: 1D in `0x105`, 1D two rows high, 1D BC1, a 1D array), 22 address descriptions (new: a 1D texture is accepted, a 1D array and a desktop-layout 1D texture are refused), 33 views (new: the whole 1D chain, its last mip, past the chain, an LOD clamp, a 1D view of a 2D texture and a 2D view of a 1D texture) | +| `startup_gfx10_layout_linear_addrlib` | PASS: 349,547 sizes and element addresses match addrlib, now with three 1D textures (`ADDR_RSRC_TEX_1D`: RGBA8 sRGB 300 with 9 mips, R8 4096 with 13 mips, RGBA16F 1000 with 10 mips) | +| `startup_address_console_{warp,hardware}` | PASS: 3 new 1D draws through a `Texture1D` view are exact on all 65,536 pixels: RGBA8 300 with one mip, and its 4-mip chain viewed at mip 0 and at mip 2 | +| `startup_address_console_linear_unpadded_{warp,hardware}` | PASS (control): the 4-mip 1D chain with its mips packed without padding (mip 2 at 152 instead of 256) is published and all 65,536 pixels of the mip-2 draw differ; the 2D case is unchanged (63,488 differ) | + +Without the source change (ce2d6f50), the first 1D draw reads the null view: pixel (0,0) is +`00000000`, but `010300ff` was expected. + +Commands (PowerShell, at the repository root, after `. .\tools\dev.ps1`): + +```powershell +cmake --preset dev -DXBOX2WINDOWS_ADDRLIB_DIR=/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 4bc6129eb9..fdf95e29a2 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -3560,9 +3560,10 @@ draw that samples the view copies each mip of each array slice from that layout footprint rows (`src/startup_stubs/gfx10_layout.h`: address equations, block sizes and mip-tail rules after AMD addrlib, Mesa 25.1.0, `src/amd/addrlib`, MIT). A 256 B layout is taken with one mip only. -The description must be two-dimensional, at most 16384 texels a side, with 1 to 15 mips, one sample, +The description must be two-dimensional, or in the linear mode `0x100` one-dimensional and not an array (one row per mip, no block-compressed format), at most 16384 texels a side, with 1 to 15 mips, one sample, no target, depth or unordered-access flag, and a format with a known element size (8- to 128-bit -texels and BC1 to BC7, whose largest mip must then be whole 4x4 blocks). The view must use a supported typed format that matches the storage format or belongs to its typeless parent. The 2D or 2D-array view must fit the mip and slice ranges. A mismatched or interior view overlapping a live resource preserves the destination descriptor. +texels and BC1 to BC7, whose largest mip must then be whole 4x4 blocks). The view must use a supported typed format that matches the storage format or belongs to its typeless parent. The 1D, 2D or 2D-array view must match the texture's dimension and fit the mip and slice ranges. A mismatched or interior view overlapping a live resource preserves the destination descriptor. + A three-dimensional description is taken in one layout only: `0x105` (4 KiB standard), one mip, one sample, at most 2048 texels on each side and an uncompressed format with a known element size, 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 513207bb1d..c37445c857 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 8781557779..0445d4036c 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: @@ -80,13 +81,20 @@ inline bool supports_volume(const D3D12_RESOURCE_DESC& d) d.MipLevels == 1 && d.SampleDesc.Count == 1; } -// A two-dimensional, single-sample texture whose memory this header can address, or a volume -// supports_volume takes. +// A two-dimensional, single-sample texture whose memory this header can address, a one-dimensional +// one in the linear mode, or a volume supports_volume takes. addrlib refuses a 1D surface taller than one row (HwlComputeSurfaceInfoLinear). A 1D +// array is refused here as well as in address_view_fits: the draw uploads a 1D texture only when it is not an array. inline bool supports(const D3D12_RESOURCE_DESC& d) { if (d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D) return supports_volume(d); const UINT mode = swizzle_mode(d), log2 = block_log2(mode); - if ((!log2 && mode != linear_mode) || d.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || !element_of(d.Format).bytes) return false; + const Element element = element_of(d.Format); + if ((!log2 && mode != linear_mode) || !element.bytes) return false; + if (d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE1D) { + if (mode != linear_mode || d.Height != 1 || d.DepthOrArraySize != 1 || element.texels != 1) return false; + } else if (d.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D) { + return false; + } if (!d.Width || !d.Height || d.Width > 16384 || d.Height > 16384 || !d.DepthOrArraySize) return false; if (!d.MipLevels || d.MipLevels > max_mips || d.SampleDesc.Count != 1) return false; return mode == linear_mode || log2 >= 12 || d.MipLevels == 1; // a 256 B block has no mip tail here 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 c8a542be39..47d5f9c48c 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 and two volumes, each drawn once; every pixel of the + fourteen textures and two volumes, each drawn once; every pixel of the 512x128 target is compared with the texel the view names; then three held descriptions and one texture whose address is announced as XG rows after it was published @@ -171,6 +171,11 @@ def bc1_block(mip, x, y): ("RGBA8 100x40 linear chain, mip 0", 100, 40, 4, RGBA8, 0x100, 0), ("RGBA8 100x40 linear chain, mip 2", 100, 40, 4, RGBA8, 0x100, 2), ("BC1 200x96 linear", 200, 96, 1, BC1, 0x100, 0), + # Linear one-dimensional textures (a trailing "1d"): one row per mip, each mip padded to 256 bytes and + # stored from the smallest up, so mip 0 of the 300-texel chain starts at 1536, not at 0. + ("RGBA8 300 1D linear", 300, 1, 1, RGBA8, 0x100, 0, "1d"), + ("RGBA8 300 1D linear chain, mip 0", 300, 1, 4, RGBA8, 0x100, 0, "1d"), + ("RGBA8 300 1D linear chain, mip 2", 300, 1, 4, RGBA8, 0x100, 2, "1d"), ] @@ -299,18 +304,25 @@ def build(width, height, mips, fmt, layout, unpadded=False): def check(directory, consumer, backend, case, extra=None, held=None, late=False, unpadded=False): - name, width, height, mips, fmt, layout, viewed = case + name, width, height, mips, fmt, layout, viewed, *dimension = case + one_d = dimension == ["1d"] backing, images = build(width, height, mips, fmt, layout, unpadded) source = directory / "texels.bin" source.write_bytes(backing) w, h = max(1, width >> viewed), max(1, height >> viewed) - hlsl = ("Texture2D 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: @@ -343,19 +355,25 @@ def check(directory, consumer, backend, case, extra=None, held=None, late=False, raise AssertionError(f"{name}: no 'published console layout' line in the log") if unpadded: if not wrong: - raise AssertionError(f"{name}: rows written without the 256-byte pitch drew exactly; the pitch is not checked") - print(f"{backend} {name}, rows without the 256-byte pitch: published, {wrong} of {TARGET_W * TARGET_H} pixels differ") + raise AssertionError(f"{name}: texels written without the 256-byte padding drew exactly; the padding is not checked") + print(f"{backend} {name}, without the 256-byte padding: published, {wrong} of {TARGET_W * TARGET_H} pixels differ") return 0 print(f"{backend} {name}: {TARGET_W * TARGET_H} RGBA pixels exact") return 0 def check_linear_unpadded(directory, consumer, backend): - """The linear cases' negative control: the first linear texture with its rows written one mip wide - (400 bytes) instead of at the 256-byte pitch (512). The runtime reads the padded pitch, so the draw must - differ from the texels; an exact draw means the linear cases do not test the pitch.""" - case = next(c for c in CASES if c[5] == 0x100) - return check(directory, consumer, backend, case, unpadded=True) + """The linear cases' negative control. The first 2D linear texture has its rows written one mip wide + (400 bytes) instead of at the 256-byte pitch (512), and the 1D chain viewed at mip 2 has its mips packed + without padding, so mip 2 starts at 152 instead of 256. The runtime reads the padded layout, so each draw + must differ from the texels; an exact draw means the linear cases do not test the padding.""" + for name in ("RGBA8 100x40 linear", "RGBA8 300 1D linear chain, mip 2"): + case = next(c for c in CASES if c[0] == name) + with tempfile.TemporaryDirectory() as temporary: + result = check(Path(temporary), consumer, backend, case, unpadded=True) + if result: + return result + return 0 GATE_PAYLOADS = 18 @@ -475,8 +493,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 f07a2a616c..fb0d866158 100644 --- a/tests/startup_address_srv.cpp +++ b/tests/startup_address_srv.cpp @@ -260,29 +260,38 @@ 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", and a depth for a volume viewed as a Texture3D). 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 +// ("width,height,mips,format,layout,viewed mip", then optionally ",1d" for a one-dimensional texture with a +// one-dimensional view, or ",depth" for a volume viewed as a Texture3D). 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. 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]{}; - unsigned width = 0, height = 0, mips = 0, format = 0, layout = 0, viewed = 0, depth = 0; - if (!length || length >= MAX_PATH || !GetEnvironmentVariableA("X2W_TEST_CONSOLE_DESC", text, sizeof(text)) || - std::sscanf(text, "%u,%u,%u,%u,%u,%u,%u", &width, &height, &mips, &format, &layout, &viewed, &depth) < 6) return 43; + char text[96]{}, extra[8]{}; + 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,%7s", &width, &height, &mips, &format, &layout, &viewed, extra); + const bool one_d = fields == 7 && !std::strcmp(extra, "1d"); + const unsigned depth = fields == 7 && !one_d ? static_cast(std::strtoul(extra, nullptr, 10)) : 0; + if (fields != 6 && !one_d && !depth) 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{depth ? D3D12_RESOURCE_DIMENSION_TEXTURE3D : D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, width, - height, static_cast(depth ? depth : 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 + : depth ? D3D12_RESOURCE_DIMENSION_TEXTURE3D : D3D12_RESOURCE_DIMENSION_TEXTURE2D, + 0, width, height, static_cast(depth ? depth : 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.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; - if (depth) { + if (one_d) { + v.view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE1D; + v.view.Texture1D.MostDetailedMip = viewed; + v.view.Texture1D.MipLevels = 1; + } else if (depth) { v.view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D; v.view.Texture3D.MostDetailedMip = viewed; v.view.Texture3D.MipLevels = 1; diff --git a/tests/startup_gfx10_layout_check.cpp b/tests/startup_gfx10_layout_check.cpp index 72cfb94b67..489a77c410 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,12 @@ 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)); + 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 @@ -261,6 +276,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 +361,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 +423,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 +431,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 +453,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 +472,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 +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, 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, 15 refusals, 22 address descriptions, 33 views)\n"); return 0; }