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 fdf95e29a2..ed27d52db1 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -3562,7 +3562,7 @@ 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. A three-dimensional description is taken in one layout only: `0x105` (4 KiB standard), one mip, one @@ -3573,7 +3573,7 @@ viewed as a Texture3D. addrlib lays a 3D resource in a standard or display mode 16-byte elements, and blocks follow along x, then y, then a layer of blocks at a time along z, with every side padded to whole blocks. Each depth layer is copied to its own footprint rows. Anything else is refused as before and leaves the destination descriptor unchanged: layout `0` -without a live texture, cube views, three-dimensional descriptions in any +without a live texture, cube views of other arrays, three-dimensional descriptions in any other layout, with a mip chain or with a block-compressed format, 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 6908dbf3b7..972e6d89b2 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -153,7 +153,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 @@ -484,7 +484,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) { @@ -2000,6 +2001,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; @@ -2014,9 +2023,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)) @@ -2535,7 +2542,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; @@ -2759,10 +2766,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 c37445c857..80af4ca834 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 47d5f9c48c..ae8f8fdc90 100644 --- a/tests/startup_address_console_check.py +++ b/tests/startup_address_console_check.py @@ -1,9 +1,9 @@ """Draw textures published by address (device slot 70) whose texels are in a console layout. - 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 + fourteen textures, three cubes 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 gate the upload lifetime control described at check_gate gate-ring the same draws with X2W_TEST_ADDRESS_UPLOAD_RING=1: the 256 MiB ring refuses the uploads past its cap, the refused draws read the null view @@ -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 @@ -380,6 +381,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)) @@ -488,12 +588,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])) @@ -502,6 +604,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 in VOLUMES: with tempfile.TemporaryDirectory() as temporary: result = check_volume(Path(temporary), *sys.argv[1:3], case) diff --git a/tests/startup_address_srv.cpp b/tests/startup_address_srv.cpp index fb0d866158..9e45d833a4 100644 --- a/tests/startup_address_srv.cpp +++ b/tests/startup_address_srv.cpp @@ -261,8 +261,9 @@ 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, 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 +// one-dimensional view, ",cube" for a two-dimensional array of six with a cube 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) @@ -274,15 +275,16 @@ int draw_console_address_srv(void* guest, void* list) 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; + const bool cube = fields == 7 && !std::strcmp(extra, "cube"); + const unsigned depth = fields == 7 && !one_d && !cube ? static_cast(std::strtoul(extra, nullptr, 10)) : 0; + if (fields != 6 && !one_d && !cube && !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{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), + 0, width, height, static_cast(depth ? depth : 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; @@ -291,6 +293,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 if (depth) { v.view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D; v.view.Texture3D.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; }