Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions docs/experiments/startup-slot70-cube.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion src/startup_stubs/address_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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) &&
Expand Down
25 changes: 15 additions & 10 deletions src/startup_stubs/d3d12_draw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -484,7 +484,8 @@ void load_translation(Translation& tr, const std::string& rtv_request = {})
if (static_cast<std::size_t>(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<std::size_t>(i) == tr.srvs.size()) tr.srvs.push_back(srv);
} else if (line.compare(0, 6, "wmask ") == 0) {
Expand Down Expand Up @@ -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;
Expand All @@ -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<u64>(srv.b), 32);
std::uint32_t words[8] = {};
if (!entry || !x2w_local::readable(reinterpret_cast<const void*>(entry), 32))
Expand Down Expand Up @@ -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<u64>(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<u64>(srv.b), 32);
std::uint32_t srv_words[8] = {};
if (!srv_entry || !x2w_local::readable(reinterpret_cast<const void*>(srv_entry), 32)) continue;
Expand Down Expand Up @@ -2759,10 +2766,8 @@ bool draw_translated(Wrapper* self, bool indexed, UINT count, UINT instances, UI
(entry && x2w_local::readable(reinterpret_cast<const void*>(entry), 32));
if (entry_ok) std::memcpy(words, formatted.entry ? formatted.words : reinterpret_cast<const void*>(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;
Expand Down
1 change: 1 addition & 0 deletions src/startup_stubs/d3d12_memory_srv.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
11 changes: 11 additions & 0 deletions tests/cmake/startup_slot70_cube.cmake
Original file line number Diff line number Diff line change
@@ -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"
"$<TARGET_FILE:startup_stream_consumer>" "${backend}" cube-order)
set_tests_properties(startup_address_console_cube_order_${backend} PROPERTIES TIMEOUT 90 SKIP_RETURN_CODE 77)
endforeach()
endif()
Loading
Loading