Skip to content
Draft
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
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1913,13 +1913,30 @@ foreach(backend IN ITEMS warp hardware)
set_tests_properties(startup_mesh_xmem_writer_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_MESH86_FIXTURE_XMEM=$<TARGET_FILE:xmem_shim>")
endforeach()
add_executable(mesh57_derive_alloc_check tests/mesh57_derive_alloc_check.cpp src/gfx1013_isa.cpp)
target_include_directories(mesh57_derive_alloc_check PRIVATE src src/startup_stubs)
target_compile_features(mesh57_derive_alloc_check PRIVATE cxx_std_17)
add_test(NAME mesh57_derive_alloc COMMAND mesh57_derive_alloc_check)

get_filename_component(DXC_BIN_DIR "${DXC_EXECUTABLE}" DIRECTORY)

if(TARGET compile_dxil AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll")
foreach(backend warp hardware)
add_test(NAME native_fixed_mesh57_${backend} COMMAND startup_indirect_draw_indexed ${backend} mesh)
set_tests_properties(native_fixed_mesh57_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_TEST_NATIVE_MESH57=1;X2W_NATIVE_SHADERS=${DXC_BIN_DIR}")
foreach(mode derived derived-off derived-bad derived-depth derived-reviewed derived-untranslated derived-root derived-root-unset derived-root-table derived-slot55 derived-slot55-mask)
add_test(NAME startup_indirect_mesh_${mode}_${backend}
COMMAND startup_indirect_draw_indexed ${backend} mesh-${mode})
set_tests_properties(startup_indirect_mesh_${mode}_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_NATIVE_SHADERS=${DXC_BIN_DIR}")
endforeach()
foreach(mode derived-dxc derived-dxc-reviewed)
add_test(NAME startup_indirect_mesh_${mode}_${backend}
COMMAND startup_indirect_draw_indexed ${backend} mesh-${mode})
set_tests_properties(startup_indirect_mesh_${mode}_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_MESH57_DXC_DIR=${DXC_BIN_DIR}")
endforeach()
add_test(NAME native_fixed_mesh57_mrt_${backend} COMMAND startup_indirect_draw_indexed ${backend} mesh)
set_tests_properties(native_fixed_mesh57_mrt_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_TEST_NATIVE_MESH57=1;X2W_TEST_NATIVE_MESH57_MRT=1;X2W_NATIVE_SHADERS=${DXC_BIN_DIR}")
Expand Down
63 changes: 63 additions & 0 deletions docs/experiments/native-fixed-mesh57.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,66 @@ pixel entry. A creation archive alone preserves the two register blocks but
does not assign hardware register meanings to their offsets. Reproduce the
source-built positive and altered-stage controls with
`ctest --preset dev --no-tests=error -R '^native_direct_mesh$'`.

## Opt-in immediate allocation

`X2W_MESH57_DERIVE_STATE=1`, together with `X2W_SHADER_CACHE` and a compiler directory, can build one desktop mesh pipeline for a direct `DispatchMesh` `ExecuteIndirect` when no reviewed `.mesh57-state` file was opened for that slot 57 pipeline. That is the `graphics/mesh_profile_missing` refusal: a slot 57 mesh with captured stages and no desktop pipeline. The switch does not change the reviewed profile. With the switch unset, the indirect call keeps the existing refusal. `graphics/no_translation` is a different refusal (no captured stages, or the call is not this slot 57 mesh) and this switch does not forward it.

`X2W_MESH57_DXC_DIR` is the directory of `dxcompiler.dll` and `dxil.dll` for this path alone. It does not turn on native translation for other graphics or compute programs. `X2W_NATIVE_SHADERS` is still accepted as the compiler directory for this one pipeline, and setting it also turns that other translation on. When neither directory is set, the call stays refused and the log says `derived mesh needs the native shader compiler`.

On the Windows test PC at `aed2c0c7`, `X2W_MESH57_DERIVE_STATE=1` with no compiler directory logged that refusal and forwarded nothing. Setting `X2W_NATIVE_SHADERS` compiled this path and also translated other programs, which refused fixed graphics entries and compute views before any `ExecuteIndirect`. A startup run that wants only this path sets `X2W_MESH57_DERIVE_STATE=1`, `X2W_MESH57_DXC_DIR`, and `X2W_SHADER_CACHE`, and leaves `X2W_NATIVE_SHADERS` unset.

At `075e4611` the same PC ran 420 seconds with the derive switch and `X2W_MESH57_DXC_DIR` set and `X2W_NATIVE_SHADERS` unset. Menus stayed up. `DispatchMesh` `ExecuteIndirect` still refused 656,186 calls in the graphics-pipeline bucket and forwarded none. The log showed 16 lines, all `derived mesh needs a fixed slot 57 pair`. That 16 is the old log cap, not the number of calls that entered derivation. With the switch on, every `DispatchMesh` `ExecuteIndirect` is now counted, including ones that never enter derivation.

Derivation runs for a direct list whose bound pipeline is slot 57, or slot 55 whose base chain ends at slot 57, when that pipeline has no desktop pipeline and no cached mesh stage. Anything else is counted and left on the existing refusal:

- `not a direct list`
- `no pipeline bound`
- `desktop pipeline already set`
- `cached mesh stage`
- `no pipeline record`
- `pipeline is slot 86` (a stream mesh, or a pipeline that already has a slot 86 key)
- `pipeline is a derived slot 55` (the base chain does not end at slot 57)
- `pipeline is not slot 57`

A slot 57 record is a fixed pair only when the captured descriptor is 768 bytes, the vertex span at `+0x48` is empty, the mesh length at `+0x70` is non-zero, and both the mesh and pixel bytes were copied at creation. Otherwise the call is counted under one of:

- `slot 57 descriptor is shorter than the fixed prefix` (under 120 bytes, so the stage words were not read)
- `slot 57 descriptor is not 768 bytes`
- `slot 57 descriptor has a vertex span` (the capture skips the mesh and pixel copies)
- `slot 57 descriptor has no mesh stage length`
- `slot 57 mesh stage was not captured` (the bytes were unreadable or larger than 1 MiB)
- `slot 57 pixel stage is absent from the descriptor` (the pixel pointer and the pixel length are both zero; the mesh copy is kept)
- `slot 57 pixel stage was not captured` (the descriptor names a pixel span whose bytes were not kept)

Those seven still refuse. The 768-byte rule stays: a shorter descriptor cannot be checked against a reviewed `.mesh57-state` file. While the switch is on, publishing a slot 57 request no longer drops the captured stage bytes, so a later call whose first refusal depended on the command list can still see them.

The first time a reason is seen, stderr gets one `x2w-render mesh57-derive sample` line: the reason, the creating slot (`path`), the derived-from slot (`base`), descriptor and stage sizes, the vertex, mesh and pixel lengths from the descriptor, the pipeline key, the list type, whether a desktop pipeline or a slot 86 key is present, the guest root (`root`, `const`, `other`, `heap`), the first parameter types (`params`), and the first slot 55 patch tags and sizes (`patches`). The line has no file path. `params` uses `t` for a descriptor table, `cN` for an N-dword constant block, `cbv`, `srv`, and `uav`. `patches` uses `tag:bytes`. A sample with no root parameters or no patch list prints `-`. Every 300 presented frames the heartbeat adds `x2w-render mesh57-derive:` with the call count of each reason, then `x2w-render mesh57-derive forwards:` with the `forwarded` count. That count is the number of calls that installed a desktop pipeline from this path.

A startup run on the Windows test PC recorded 653,708 refused `DispatchMesh` `ExecuteIndirect` calls in 420 seconds and forwarded none. Across draw and mesh, the graphics-pipeline census counted `graphics/no_translation` 446,421 and `graphics/mesh_profile_missing` 427,428. This switch is only the second of those, and only the immediate-allocation shape below. Slot 86 meshes with no cached stage stay refused.

The accepted program writes `m0` with one `s_mov_b32` of an integer immediate and the next instruction is the only `s_sendmsg` `GS_ALLOC_REQ` (`0xbf900009`). The immediate is `(primitives << 12) | vertices`, both counts are in 1..64, and the high byte is clear. A group-memory count exchange (`0xbf8a0000`) or an `s_mov_b32` of `exec_lo` is refused. The derived layout is one wave64 group of 64 threads, triangle topology, and group stride 0. Stride 0 is accepted because this program does not read the group id; the lowerer skips that multiply. The pixel shader must be a constant `MRT0` export with no resource bindings.

An empty guest root is unchanged. One 32-bit constant parameter of 1..8 dwords and no other parameters is bound, including when the guest root is heap indexed: user SGPR s8 is that block, and the draw copies it into a desktop b0 the same way a reviewed constant profile does. The constant words must already be set on the list. The heap base itself is not bound; a shader that reads it is refused by the lowerer. A heap-indexed root with any other shape (`derived mesh guest root is heap indexed`), a descriptor or root descriptor (`derived mesh guest root has descriptors`), or any other constant shape (`derived mesh guest root constants do not fit one user block`) stays refused. Those need a reviewed SGPR map; this path does not invent one.

A slot 55 pipeline reuses that derived mesh when every patch record is a blend patch (tag 2, 0x14c bytes) or the patch list is empty. The last blend patch replaces the base blend. Tag 2 is the only slot 55 record this repository applies: the graphics path reads that blend descriptor and does not apply any other tag. Depth and raster for a slot 57 base come from its state block, not from a patch tag. A record whose tag is not 2 stays refused, and the reason names that tag (for example `slot 55 patch tag 3 is not applied`). A list whose size is not a whole number of 0x14c records stays `slot 55 patches are not applied`. The sample lists the first records either way. The base's shader, root, and depth rules are unchanged.

Fixed function state comes from state block A. The mesh layout word at `+0x004` must be 6. Blend words are read at the mesh shift (`+0x54` on top of `+0xD0`). Depth and stencil must decode as disabled; an enabled test is refused rather than given a guessed depth format. The color target is the one single-sample target bound on that direct list, with a viewport and a scissor and no depth view. The rasterizer is solid, cull none, and depth clip. Those three values are not read from the register block. A `.mesh57-state` file that is present, including one whose bytes do not match, keeps the reviewed path and this switch does not create a pipeline.

A failed derivation is remembered for that pipeline. Attachment and root mismatches are not: a later direct list can still be the first accepted call. The desktop pipeline then keeps the color format of that call.

From the x64 Windows build environment, with DXC available to the native shader stand-in:

```powershell
ctest --preset dev -j 1 --no-tests=error -R "mesh57_derive_alloc|startup_indirect_mesh_derived"
```

`startup_indirect_mesh_derived_{warp,hardware}` forwards one group and reads a white texel at `(2,0)` on a 4 by 2 target. `derived-dxc` does the same with only `X2W_MESH57_DXC_DIR` set, and the process clears `X2W_NATIVE_SHADERS` before the call. `derived-root` is that program plus one guest constant at s8, with the word set, and paints the same texel. `derived-slot55` draws through a slot 55 pipeline with no patches and paints the same texel. `derived-off` leaves the switch unset. `derived-bad` has no immediate allocation. `derived-depth` enables the depth test in the register block. `derived-reviewed` and `derived-dxc-reviewed` supply a profile file that does not match; the second does that with only `X2W_MESH57_DXC_DIR` set. `derived-untranslated` is a slot 57 pipeline with no captured mesh or pixel program. `derived-root-unset` omits the constant word. `derived-root-table` uses a descriptor table. `derived-slot55-mask` applies a blend patch with a zero write mask. Those leave the clear color. Each returns 77 when mesh shaders or the command signature are unavailable. `mesh57_derive_alloc` checks the allocation reader, the root decision, the slot 55 patch rule, and the forwards line without a device.

On the Windows test PC at `f358a2ed`, a 420 second run with `X2W_TRANSLATED_INDIRECT_DRAW=1`, `X2W_MESH57_DERIVE_STATE=1`, and `X2W_MESH57_DXC_DIR` set forwarded nothing. The derive census was `slot 57 pixel stage was not captured` 47823, `derived mesh keeps a non-empty guest root refused` 152144, and `pipeline is a derived slot 55` 180066. The non-empty sample had both stages (mesh 9536 bytes, pixel 4352 bytes). The slot 55 sample was a 332-byte descriptor whose base was slot 57 and whose stage lengths were unread. That root refusal is replaced by the three root reasons above, and a slot 55 call now uses its slot 57 base when the patches are blend records. A 4352-byte pixel is still not a constant export, and a program that is not the one immediate allocation is still refused.

On the Windows test PC at `54331137`, the same switches, a 420 second run, forwarded nothing (`x2w-render mesh57-derive forwards: 0`). The census was `derived mesh guest root is heap indexed` 353719, `slot 57 pixel stage was not captured` 130628, and `slot 55 patches are not applied` 514994. The heap-indexed sample was path 57, descriptor 768, mesh 9536, pixel 4352, state A 504, state B 80, root 5, one constant dword, four other parameters, heap 1024. The pixel sample was path 57, mesh 1408, pixel length 0, state A 464, root 5, two constant dwords, four other parameters, heap 3072. The slot 55 sample was one 332-byte record on a slot 57 base with that same five-parameter root and heap 3072.

The capture copies a pixel stage only when its length is non-zero and the bytes are readable. A zero pointer and a zero length is an empty span: the copy is skipped and the mesh bytes stay. The 1408-byte mesh in that sample was kept, so the pixel words in the creation descriptor were zero. An unreadable non-zero span fails the snapshot and drops both stages; this sample is not that case, and nothing writes the pixel stage after creation. A slot 55 record is state, not a shader. This path does not invent a pixel shader. A zero pixel length is now `slot 57 pixel stage is absent from the descriptor`.

Heap 1024 is the view-heap flag (`0x400`). Heap 3072 is that flag plus the sampler-heap flag (`0xC00`). No reviewed map in this repository assigns user SGPRs for a five-parameter heap-indexed root on the mesh path. The maps that do exist are different ABIs. Raw graphics, and the reflected graphics path, start user SGPRs at s8: a descriptor table is one SGPR, a 32-bit constant block is one SGPR per dword, and a root CBV, SRV, or UAV is two SGPRs, with the heaps following when their flags are set. That layout is for a graphics stage. Direct compute without a reflected stage starts at s4 with the same parameter packing, and both heap flags occupy the next two SGPRs only when they exactly fill the user SGPR count. The 1024 sample has only the view-heap flag, and s4 is the compute ABI. A reviewed `.mesh57-state` profile stores the SGPR, the root parameter, and the count for that one program. These pipelines have no such file. The missing map is the physical user SGPR of each of the five parameters, and the user SGPR of the resource heap (and of the sampler heap when `0x800` is set). The stored root parameter keeps the type, and for a constant block the dword count; a descriptor table's ranges are not kept. This path does not guess the SGPRs. The sample line records the types so the map can be raised with the measured parameter kinds.
Loading
Loading