Skip to content
Open
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,9 @@ if(EXISTS "${INTAKE_PYTHON}")
add_test(NAME startup_mesh86_committed_root_probe_${backend} COMMAND "$<TARGET_FILE:startup_indirect_draw_indexed>"
${backend} mesh86-committed-root-probe)
set_tests_properties(startup_mesh86_committed_root_probe_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77)
add_test(NAME startup_mesh86_table_texture_probe_${backend} COMMAND "$<TARGET_FILE:startup_indirect_draw_indexed>"
${backend} mesh86-table-texture-probe)
set_tests_properties(startup_mesh86_table_texture_probe_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77)
foreach(mode IN ITEMS ordered_control skip-wait dual dual-skip-srv dual-skip-argument dual-init-only loose-root)
set(test_name startup_indirect_mesh_lease_${backend}_${mode})
add_test(NAME ${test_name} COMMAND "${INTAKE_PYTHON}" -B
Expand Down
64 changes: 64 additions & 0 deletions docs/experiments/native-mesh-table-texture-load.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Texture loads through a descriptor table in the mesh frontend

The C++ mesh frontend (`lower_mesh`) accepted image loads only through the Texture1D heap slot map (#3638). Any other
`image_load` stopped with `mesh image load lacks a remapped Texture1D heap contract`, or, without the slot map, with
`unsupported mesh instruction or EXEC state: image_load`.

It now also accepts an `image_load` (MIMG opcode 0, without D16) whose eight descriptor words were loaded from a
descriptor table. Like every other stage, it goes to the shared `image_io`, which:

- checks the opcode, the modifiers and that the eight descriptor words are contiguous and untouched;
- binds the table record as a texture SRV of the encoded dimension;
- emits `textureLoad`.

The slot 86 runtime already resolves such a texture SRV from the table record (`native_mesh86.inl`, 1D, 2D and 2D
array). Under a narrowed EXEC each written channel is marked as a partial write, as buffer loads already are.

The lowering declares the texture with a float result (`Texture2D<float4>`, `textureLoad.f32`), but a table record can
hold an integer view, for example `R8G8B8A8_UINT`. The slot 86 binder therefore checks each material texture record
in `mesh86_table_texture` before it binds or uploads anything. A UINT or SINT view refuses the draw with `native
Mesh86 material texture has an integer format`. An all-zero record still binds a typed null.

## Checks

`tests/native_direct_mesh_check.py`, next to `root-branch`: `s_load_dwordx8` reads a descriptor from table 1, then
`image_load v1, v[1:2], s[24:31] dmask:0x2 dim:2D unorm` reads one channel.

- `table-texture-load` and `-xy` (DMASK 0x3): a `Texture2D` handle and a two-coordinate `textureLoad`.
- `table-texture-load-skip`: the same load into v3 under `v_cmpx` and an EXECZ skip.
- `table-texture-load-skip-read-after`: v3 is 0 for every lane before the skip. Reading it after full EXEC returns is
refused (`graphics register undefined on an incoming path: 259`), because only some lanes overwrote it.
- `table-texture-load-d16` and `-overwritten` keep `unsupported image dimension or D16` and
`non-contiguous resource descriptor`.

`startup_mesh86_table_texture_probe_{warp,hardware}` checks the binder side. It creates one `R8G8B8A8_TYPELESS` 2D
texture through the guest API and writes guest SRVs of it into a guest heap. It then runs each 32-byte record through
the binder's check, using the fixture export `x2w_mesh86_table_texture_probe`, which is the same function the binder
calls:

| Record | Result |
|---|---|
| `R8G8B8A8_UNORM`, `Texture2D` | bound |
| `R8G8B8A8_UINT`, `Texture2D` | refused: integer format |
| `R8G8B8A8_SINT`, `Texture2D` | refused: integer format |
| `R8G8B8A8_UNORM`, `Texture2DArray` | refused: does not resolve to the expected SRV |
| all zero | bound (typed null) |

It checks the binding decision only, and submits no draw.

Controls:

- Without the frontend change, `table-texture-load` fails with `unsupported mesh instruction or EXEC state:
image_load`.
- Without the partial-write marking, `table-texture-load-skip-read-after` compiles, so its expected refusal is
missing.
- Without the integer-format check, the probe binds the UINT record and fails.

## Local requests

The 18 captured slot 86 requests behind the scalar loop of #3703 use only this form: `image_load` 2D, DMASK 0x2,
unorm, through a table record, about four per program. With #3707 applied on top of `main` (which has #3702 and #3704), all
18 now translate.
Each binds a 2D table texture, four table buffers, root constants, and the 128-byte root SRV of root parameter 3
(#3639). These are counts only, from `compile_dxil <dxc> <out> gfx1013-container-ms-texture-heap <request>.m86
<out>.cso`.
8 changes: 8 additions & 0 deletions src/gfx1013_direct_mesh.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,14 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout
if (full_exec) uniform_values.insert(word);
else if (whole_wave_execution() && !branch) active_uniform[word]={lane_active,word};
}
} else if (i.enc==Encoding::Image && i.op==0 && !(i.b>>31) && (full_exec || exec_skip) &&
((i.b>>16)&31)*4+8<=106 && state[((i.b>>16)&31)*4].type==Symbol::Type::descriptor) {
// A load through a descriptor-table texture (#3703): the shared lowering checks the opcode and the
// eight descriptor words and binds the table record as a texture SRV of the encoded dimension, which
// the slot 86 runtime resolves from the table. It writes one VGPR per DMASK channel.
alu.image_io(i,state);
if (!full_exec)
for (unsigned mask=(i.a>>8)&15, j=0; mask; mask&=mask-1, ++j) partial_writes.insert(256+i.dst+j);
} else if (i.enc==Encoding::Image && i.op==0 && layout.texture_heap_slot_map &&
(full_exec || exec_skip)) {
const auto base=((i.b>>16)&31)*4;
Expand Down
17 changes: 17 additions & 0 deletions src/startup_stubs/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5655,6 +5655,23 @@ extern "C" __declspec(dllexport) int x2w_mesh86_committed_root_probe(void* list,
return 1;
}

#ifdef X2W_NATIVE_SHADERS
// Fixture export (startup_indirect_draw_indexed mesh86-table-texture-probe): run the slot 86 binder's check of one
// 32-byte material texture table record for a 2D table load. Returns 1 when the record would be bound, 0 when the
// draw would be refused; *reason then holds the binder's refusal.
extern "C" __declspec(dllexport) int x2w_mesh86_table_texture_probe(const unsigned* words, const char** reason)
{
if (reason) *reason = nullptr;
if (!words) return 0;
UINT record[8];
std::memcpy(record, words, sizeof(record));
Mesh86Texture texture;
const char* refusal = mesh86_table_texture(record, D3D12_SRV_DIMENSION_TEXTURE2D, false, texture);
if (reason) *reason = refusal;
return refusal ? 0 : 1;
}
#endif

#ifdef X2W_NATIVE_SHADERS
// Xbox list slot 129 (vtable offset 0x408): DispatchMesh(x, y, z).
void __stdcall list_dispatch_mesh(Wrapper* self, UINT x, UINT y, UINT z)
Expand Down
28 changes: 24 additions & 4 deletions src/startup_stubs/native_mesh86.inl
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,26 @@ D3D12_SHADER_RESOURCE_VIEW_DESC mesh86_null_texture(D3D12_SRV_DIMENSION dimensio
return view;
}

// The 32-byte table record of one material texture, checked before anything is bound or uploaded. An all-zero
// record is a typed null. The frontend declares every table texture with a float result (Texture2D<float4> with
// textureLoad.f32 or a sample), so an integer view would bind an SRV the shader cannot read.
const char* mesh86_table_texture(const UINT (&words)[8], D3D12_SRV_DIMENSION dimension, bool compare,
Mesh86Texture& texture)
{
if (std::all_of(std::begin(words), std::end(words), [](UINT word) { return !word; })) {
texture.view = mesh86_null_texture(dimension, compare);
return nullptr;
}
if (!mesh86_texture(words, texture) || texture.view.ViewDimension != dimension)
return "native Mesh86 material texture does not resolve to the expected SRV";
// The stencil plane of a depth-stencil texture is an integer view too.
const auto format = texture.view.Format;
if (integer_uav_format(format) || format == DXGI_FORMAT_X24_TYPELESS_G8_UINT ||
format == DXGI_FORMAT_X32_TYPELESS_G8X24_UINT)
return "native Mesh86 material texture has an integer format";
return nullptr;
}

x2w_upload::Allocation mesh86_upload(Wrapper* list, UINT64 bytes)
{
auto* data = list_allocate_upload(list, bytes, D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT);
Expand Down Expand Up @@ -444,10 +464,10 @@ const char* bind_native_mesh86(Wrapper* self, Pass& pass, ID3D12GraphicsCommandL
Mesh86Texture texture;
const auto dim = source.image_dimension == 0 ? D3D12_SRV_DIMENSION_TEXTURE1D :
source.image_dimension == 1 ? D3D12_SRV_DIMENSION_TEXTURE2D : D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
if (std::all_of(std::begin(words), std::end(words), [](UINT word) { return !word; }))
texture.view = mesh86_null_texture(dim, source.kind == Kind::comparison_texture_srv);
else if (!mesh86_texture(words, texture) || texture.view.ViewDimension != dim || !image(texture))
return "native Mesh86 material texture does not resolve to the expected SRV";
if (const char* reason = mesh86_table_texture(words, dim, source.kind == Kind::comparison_texture_srv,
texture))
return reason;
if (!image(texture)) return "native Mesh86 material texture does not resolve to the expected SRV";
descriptors[slot] = {texture.resource, texture.view};
} else if (source.kind == Kind::typed_buffer_srv) {
UINT words[8];
Expand Down
25 changes: 25 additions & 0 deletions tests/native_direct_mesh_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,31 @@ def run_offen(name, words, error=None):
for marker in ('cbufferLoadLegacy','rawBufferLoad','phi i32','storeVertexOutput'):
assert marker in text, marker

# A load through a descriptor-table texture (#3703): s_load_dwordx8 s[24:31], s[16:17], 0 reads the eight
# descriptor words; image_load v1, v[1:2], s[24:31] dmask:0x2 dim:2D unorm reads one channel at (v1, v2).
texture_load = [0xbe910380, 0xf40c0608, 0xfa000000, 0xbf8cc07f] # s_mov_b32 s17, 0; load; s_waitcnt
def table_texture(image=(0xf0001208, 0x00060101), extra=(), skip=False, after=()):
body = [*extra, *image]
if skip: # v3 = 0 for every lane; then under v_cmpx_eq_u32 1, v0 and an EXECZ skip; then full EXEC
body = [0x7e060280, 0x7da40081, 0xbf880000 | len(body), *body, 0xbefe04c1, *after]
return texture_load + program[:7] + body + program[7:]
texture_2d = r'%dx\.types\.ResourceProperties \{ i32 2, i32 1033 \}' # Texture2D<4 x f32>
texture_read = r'@dx\.op\.textureLoad\.f32\(i32 66, %dx\.types\.Handle %[\w.]+, i32 0, i32 %[\w.]+, i32 %[\w.]+, i32 undef'
skip_into_v3 = (0xf0001208, 0x00060301) # the same load into v3
for name, words_in in (('table-texture-load', table_texture()),
('table-texture-load-xy', table_texture(image=(0xf0001308, 0x00060101))),
('table-texture-load-skip', table_texture(image=skip_into_v3, skip=True))):
text = run(name, words_in)
assert re.search(texture_2d, text) and re.search(texture_read, text), text
# Under the skip only some lanes overwrite v3, so its value once full EXEC returns is not one value for
# every lane and reading it is refused (without marking the load's write as partial, it would be accepted).
run('table-texture-load-skip-read-after',
table_texture(image=skip_into_v3, skip=True, after=[0x7e020303]), # v_mov_b32 v1, v3
'graphics register undefined on an incoming path: 259')
run('table-texture-load-d16', table_texture(image=(0xf0001208, 0x80060101)), 'unsupported image dimension or D16')
run('table-texture-load-overwritten', table_texture(extra=[0xbe990380]), # s_mov_b32 s25, 0
'non-contiguous resource descriptor')

# s20 = root0[0]; v_cmp_gt_u32_e64 vcc, s20, 6.
copy_root = [0xbe940315]
compare_root = [0xd4c4006a, 0x00010c14]
Expand Down
4 changes: 2 additions & 2 deletions tests/standin_exports_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_real_catalogs():
expected = set(modules[:8]) | {"xgameruntime.dll"}
check(set(catalogs) == expected,
f"load_catalogs keys {sorted(catalogs)} != {sorted(expected)}")
counts = {"xmem": 54, "d3d12_xs": 79, "acphal": 10, "chad": 5,
counts = {"xmem": 54, "d3d12_xs": 80, "acphal": 10, "chad": 5,
"xapu": 6, "xcrdapi": 3, "xg_xs": 2, "gameinput": 2}
for stem, path in DEFAULT_DEFS.items():
catalog = catalogs[stem + ".dll"]
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_real_catalogs():
== Counter({"trap": 9, "implemented": 1}),
"acphal status counts differ")
check(Counter(e.status for e in catalogs["d3d12_xs.dll"].entries.values())
== Counter({"implemented": 35, "unmeasured": 44}),
== Counter({"implemented": 35, "unmeasured": 45}),
"d3d12_xs status counts differ")
check(Counter(e.status for e in catalogs["xgameruntime.dll"].entries.values())
== Counter({"implemented": 38}),
Expand Down
Loading
Loading