From 8f769c7e4a5ab11a61f77b2692100b59fd201f5c Mon Sep 17 00:00:00 2001 From: Luuk Motz Date: Tue, 1 Dec 2026 18:47:31 +0100 Subject: [PATCH 1/3] shader, runtime: lower and bind mesh format loads from a descriptor-table V# The mesh frontend accepted buffer_load_format_x only from a resource heap slot. Skinned slot 86 programs read the V# whole from a bound descriptor table instead and were refused with "formatted mesh load lacks an R32_UINT resource heap contract". Translator: a format load whose V# comes from a bound table goes through the shared typed-buffer SRV path, as in vertex and pixel shaders, which checks the table binding and all four descriptor words. The #3720 control that kept this route refused under heap tokens now checks that it compiles without a token view. Runtime: slot 86 accepts a one-dword typed_buffer_srv from a descriptor table and binds it as an R32_UINT buffer view through the same checks as a typed heap slot (R32_UINT token view, or a raw V# with the identity component map and a 4-byte stride). A raw table V# must also name a 32-bit format (32_UINT, 32_SINT or 32_FLOAT), so the view returns the dword the guest load would. Those word 3 checks live in mesh86_typed_vsharp.h with unit tests and two mutation controls. Part of #3703. Co-Authored-By: Claude Opus 5.5 --- src/gfx1013_direct_mesh.inl | 7 +++ src/startup_stubs/d3d12_xs_device.cpp | 1 + src/startup_stubs/mesh86_typed_vsharp.h | 23 +++++++ src/startup_stubs/native_mesh86.inl | 39 ++++++++---- tests/cmake/mesh86_typed_vsharp.cmake | 43 +++++++++++++ tests/mesh86_typed_vsharp_check.cpp | 83 +++++++++++++++++++++++++ tests/native_direct_mesh_check.py | 30 ++++++++- 7 files changed, 213 insertions(+), 13 deletions(-) create mode 100644 src/startup_stubs/mesh86_typed_vsharp.h create mode 100644 tests/cmake/mesh86_typed_vsharp.cmake create mode 100644 tests/mesh86_typed_vsharp_check.cpp diff --git a/src/gfx1013_direct_mesh.inl b/src/gfx1013_direct_mesh.inl index 575612d031..879d7a11d1 100644 --- a/src/gfx1013_direct_mesh.inl +++ b/src/gfx1013_direct_mesh.inl @@ -1484,6 +1484,13 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout alu.write(i.dst+j,j>=1 && j<=3 ? texture_metadata[j-1] : string{}); } state=next; + } else if (i.name=="buffer_load_format" && i.op==0 && (full_exec || exec_skip) && + ((i.a&0x3ffff)==0x2000 || (i.a&0x3ffff)==0) && + state[((i.b>>16)&31)*4].type==Symbol::Type::descriptor) { + // A V# read whole from a bound descriptor table: the shared typed-buffer SRV path checks the + // table binding and all four descriptor words, as it does for vertex and pixel shaders. + alu.memory(i,state); + if (!full_exec) partial_writes.insert(256+i.dst); } else if (i.name=="buffer_load_format" && i.op==0 && (full_exec || exec_skip) && ((i.a&0x3ffff)==0x2000 || (i.a&0x3ffff)==0)) { const auto base=((i.b>>16)&31)*4; diff --git a/src/startup_stubs/d3d12_xs_device.cpp b/src/startup_stubs/d3d12_xs_device.cpp index 0a3ddf5832..21aa22eb0d 100644 --- a/src/startup_stubs/d3d12_xs_device.cpp +++ b/src/startup_stubs/d3d12_xs_device.cpp @@ -14,6 +14,7 @@ #define X2W_TRAP_MODULE_ID 7 #include "startup_stubs/indexed_resource_list.h" #include "startup_stubs/indirect_cross_list_copy.h" +#include "startup_stubs/mesh86_typed_vsharp.h" #include "startup_stubs/trap.h" #include "x2w_build_rev.h" #include "xmem_page_batch.h" diff --git a/src/startup_stubs/mesh86_typed_vsharp.h b/src/startup_stubs/mesh86_typed_vsharp.h new file mode 100644 index 0000000000..1b8a64fc82 --- /dev/null +++ b/src/startup_stubs/mesh86_typed_vsharp.h @@ -0,0 +1,23 @@ +// Slot 86 typed buffer sources (buffer_load_format_x) read from a guest V# that is not a view token. +// The desktop view is R32_UINT with 4-byte elements, so the V# must not reorder or drop channels and +// must name a format whose X channel is the stored dword. +#pragma once + +#include + +namespace x2w_startup { + +// Word 3 bits 11:0: DST_SEL_X..W = X, Y, Z, W (4, 5, 6, 7). +inline bool mesh86_typed_identity_map(std::uint32_t word3) +{ + return (word3 & 0xfffu) == 0xfacu; +} + +// Word 3 bits 18:12: BUF_FMT_32_UINT (20), BUF_FMT_32_SINT (21) or BUF_FMT_32_FLOAT (22). +inline bool mesh86_typed_dword_format(std::uint32_t word3) +{ + const std::uint32_t format = (word3 >> 12) & 0x7fu; + return format >= 20u && format <= 22u; +} + +} // namespace x2w_startup diff --git a/src/startup_stubs/native_mesh86.inl b/src/startup_stubs/native_mesh86.inl index c699f03321..bfd7c2455c 100644 --- a/src/startup_stubs/native_mesh86.inl +++ b/src/startup_stubs/native_mesh86.inl @@ -68,10 +68,13 @@ x2w_startup::ComPtr make_native_mesh86_root( const bool image = view.kind == Kind::texture_srv || view.kind == Kind::comparison_texture_srv; const bool scalar = view.kind == Kind::buffer_srv || view.kind == Kind::raw_vector_srv || view.kind == Kind::byte_window_srv || view.kind == Kind::root_buffer_srv; - require(view.shader_register == i && view.root_parameter < guest.size() && (image || scalar) && + // buffer_load_format_x from a V# in a descriptor table: one 32-bit component per element. + const bool typed = view.kind == Kind::typed_buffer_srv && view.required_bytes == 4; + require(view.shader_register == i && view.root_parameter < guest.size() && (image || scalar || typed) && (!image || view.image_dimension == 0 || view.image_dimension == 1 || view.image_dimension == 5), "unsupported native Mesh86 SRV shape"); const auto type = guest[view.root_parameter].type; + require(!typed || type == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE, "invalid native Mesh86 SRV source"); require(type == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE ? !(view.byte_offset & 31) : !image && !view.byte_offset && (type == D3D12_ROOT_PARAMETER_TYPE_SRV || type == D3D12_ROOT_PARAMETER_TYPE_CBV), @@ -396,6 +399,23 @@ const char* bind_native_mesh86(Wrapper* self, Pass& pass, ID3D12GraphicsCommandL buffer_states.emplace_back(view.resource, view.upload); return nullptr; }; + // A buffer_load_format_x source, from a heap slot or a table: an R32_UINT view of 4-byte elements. + // A table V# must also name a 32-bit data format (see mesh86_typed_vsharp.h), so the R32_UINT view returns + // the same dword the guest format load would. + const auto typed_dword = [&](UINT slot, const UINT (&words)[8], bool table = false) -> const char* { + Mesh86Texture typed; + if (words[0] == view_token_magic && + (!mesh86_texture(words, typed) || typed.view.ViewDimension != D3D12_SRV_DIMENSION_BUFFER || + typed.view.Format != DXGI_FORMAT_R32_UINT || typed.view.Buffer.Flags || typed.view.Buffer.StructureByteStride)) + return "native Mesh86 typed buffer slot is not R32_UINT"; + if (words[0] != view_token_magic && !x2w_startup::mesh86_typed_identity_map(words[3])) + return "native Mesh86 typed buffer descriptor uses another component map"; + if (table && words[0] != view_token_magic && !x2w_startup::mesh86_typed_dword_format(words[3])) + return "native Mesh86 typed buffer descriptor is not a 32-bit format"; + const auto view = indirect_table_buffer(self, words, false, nullptr, 16u << 20, 4, true); + if (view.stride != 4) return "native Mesh86 typed buffer view has the wrong stride"; + return buffer(slot, view, true); + }; const auto image = [&](Mesh86Texture& texture) { if (!mesh86_realize_texture(self, pass, texture)) return false; return !texture.resource || !texture_states.insert(texture.resource).second || @@ -419,6 +439,12 @@ const char* bind_native_mesh86(Wrapper* self, Pass& pass, ID3D12GraphicsCommandL else if (!mesh86_texture(words, texture) || texture.view.ViewDimension != dim || !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]; + if (!mesh86_read_record(pass.view_tables[source.root_parameter], source.byte_offset, words)) + return "native Mesh86 typed buffer descriptor is outside its table"; + if (const char* reason = typed_dword(slot, words, true)) return reason; + strides[source.shader_register] = 4; } else { const char* reason = nullptr; UINT words[8]{}; @@ -468,16 +494,7 @@ const char* bind_native_mesh86(Wrapper* self, Pass& pass, ID3D12GraphicsCommandL UINT words[8]; if (slot >= pass.mesh_heap_slots || !mesh86_read_record(pass.title_view_heap, UINT64{slot} * 32, words)) return "native Mesh86 typed buffer slot is outside the bound heap"; - Mesh86Texture typed; - if (words[0] == view_token_magic && - (!mesh86_texture(words, typed) || typed.view.ViewDimension != D3D12_SRV_DIMENSION_BUFFER || - typed.view.Format != DXGI_FORMAT_R32_UINT || typed.view.Buffer.Flags || typed.view.Buffer.StructureByteStride)) - return "native Mesh86 typed buffer slot is not R32_UINT"; - if (words[0] != view_token_magic && (words[3] & 0xfffu) != 0xfacu) - return "native Mesh86 typed buffer descriptor uses another component map"; - const auto view = indirect_table_buffer(self, words, false, nullptr, 16u << 20, 4, true); - if (view.stride != 4) return "native Mesh86 typed buffer view has the wrong stride"; - if (const char* reason = buffer(slot, view, true)) return reason; + if (const char* reason = typed_dword(slot, words)) return reason; } const auto add_image = [&](Mesh86Texture& texture) { if (descriptors.size() >= D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_1) return no_index; diff --git a/tests/cmake/mesh86_typed_vsharp.cmake b/tests/cmake/mesh86_typed_vsharp.cmake new file mode 100644 index 0000000000..5cb7c02af0 --- /dev/null +++ b/tests/cmake/mesh86_typed_vsharp.cmake @@ -0,0 +1,43 @@ +# Unit tests for src/startup_stubs/mesh86_typed_vsharp.h: the V# word 3 checks slot 86 applies before it binds +# a buffer_load_format_x source from a descriptor table as an R32_UINT view. Header-only, no device. +add_executable(mesh86_typed_vsharp_check tests/mesh86_typed_vsharp_check.cpp) +target_include_directories(mesh86_typed_vsharp_check PRIVATE src) +target_compile_features(mesh86_typed_vsharp_check PRIVATE cxx_std_17) +foreach(mesh86_typed_vsharp_case IN ITEMS identity_map dword_formats other_formats guest_words) + add_test(NAME mesh86_typed_vsharp_${mesh86_typed_vsharp_case} + COMMAND mesh86_typed_vsharp_check ${mesh86_typed_vsharp_case}) + set_tests_properties(mesh86_typed_vsharp_${mesh86_typed_vsharp_case} PROPERTIES TIMEOUT 60) +endforeach() + +# Mutation controls: each builds the check against a copy of the header with one guard changed and runs the +# case that guard must catch. Each control must fail (WILL_FAIL TRUE). +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS src/startup_stubs/mesh86_typed_vsharp.h) +file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/startup_stubs/mesh86_typed_vsharp.h" mesh86_typed_vsharp_text) +foreach(mesh86_typed_vsharp_mut IN ITEMS wide_format any_map) + if(mesh86_typed_vsharp_mut STREQUAL "wide_format") + # The 32-bit formats widened by one: other_formats sees 23 accepted. + set(mesh86_typed_vsharp_from "format <= 22u") + set(mesh86_typed_vsharp_to "format <= 23u") + set(mesh86_typed_vsharp_case other_formats) + else() + # The component map is no longer checked: identity_map sees a swizzle accepted. + set(mesh86_typed_vsharp_from "return (word3 & 0xfffu) == 0xfacu;") + set(mesh86_typed_vsharp_to "return word3 == word3;") + set(mesh86_typed_vsharp_case identity_map) + endif() + string(REPLACE "${mesh86_typed_vsharp_from}" "${mesh86_typed_vsharp_to}" + mesh86_typed_vsharp_mutated "${mesh86_typed_vsharp_text}") + if(mesh86_typed_vsharp_mutated STREQUAL mesh86_typed_vsharp_text) + message(FATAL_ERROR "mesh86_typed_vsharp.h lost the anchor for mesh86_typed_vsharp_${mesh86_typed_vsharp_mut}_mut") + endif() + set(mesh86_typed_vsharp_dir "${CMAKE_CURRENT_BINARY_DIR}/mesh86_typed_vsharp_${mesh86_typed_vsharp_mut}") + file(MAKE_DIRECTORY "${mesh86_typed_vsharp_dir}/startup_stubs") + file(WRITE "${mesh86_typed_vsharp_dir}/startup_stubs/mesh86_typed_vsharp.h" "${mesh86_typed_vsharp_mutated}") + add_executable(mesh86_typed_vsharp_${mesh86_typed_vsharp_mut}_mut tests/mesh86_typed_vsharp_check.cpp) + target_include_directories(mesh86_typed_vsharp_${mesh86_typed_vsharp_mut}_mut BEFORE PRIVATE + "${mesh86_typed_vsharp_dir}" src) + target_compile_features(mesh86_typed_vsharp_${mesh86_typed_vsharp_mut}_mut PRIVATE cxx_std_17) + add_test(NAME mesh86_typed_vsharp_${mesh86_typed_vsharp_mut}_mut + COMMAND mesh86_typed_vsharp_${mesh86_typed_vsharp_mut}_mut ${mesh86_typed_vsharp_case}) + set_tests_properties(mesh86_typed_vsharp_${mesh86_typed_vsharp_mut}_mut PROPERTIES WILL_FAIL TRUE TIMEOUT 60) +endforeach() diff --git a/tests/mesh86_typed_vsharp_check.cpp b/tests/mesh86_typed_vsharp_check.cpp new file mode 100644 index 0000000000..df54645ac2 --- /dev/null +++ b/tests/mesh86_typed_vsharp_check.cpp @@ -0,0 +1,83 @@ +// Unit and header-mutation tests for src/startup_stubs/mesh86_typed_vsharp.h: the V# word 3 checks that +// let slot 86 bind a buffer_load_format_x source from a descriptor table as an R32_UINT view. +// +// Usage: mesh86_typed_vsharp_check [] (no argument runs all cases) +// Every mismatch prints "FAIL: : ..." to stderr and exits non-zero. +#include "startup_stubs/mesh86_typed_vsharp.h" + +#include +#include +#include +#include + +using x2w_startup::mesh86_typed_dword_format; +using x2w_startup::mesh86_typed_identity_map; + +namespace { +int failures = 0; + +void expect(const char* name, bool ok, const char* what) +{ + if (!ok) { + std::fprintf(stderr, "FAIL: %s: %s\n", name, what); + ++failures; + } +} + +std::uint32_t with_format(std::uint32_t format) { return 0xfacu | (format << 12); } + +void identity_map(const char* n) +{ + expect(n, mesh86_typed_identity_map(0xfacu), "XYZW accepted"); + expect(n, mesh86_typed_identity_map(0xffffffacu), "upper bits ignored"); + expect(n, !mesh86_typed_identity_map(0xfadu), "DST_SEL_X = Y refused"); + expect(n, !mesh86_typed_identity_map(0x688u), "ZYX0 refused"); + expect(n, !mesh86_typed_identity_map(0u), "all-zero map refused"); +} + +void dword_formats(const char* n) +{ + for (std::uint32_t format : {20u, 21u, 22u}) + expect(n, mesh86_typed_dword_format(with_format(format)), "32-bit format accepted"); +} + +void other_formats(const char* n) +{ + for (std::uint32_t format : {0u, 1u, 19u, 23u, 56u, 77u, 127u}) + expect(n, !mesh86_typed_dword_format(with_format(format)), "non-32-bit format refused"); +} + +void guest_words(const char* n) +{ + // Word 3 of the V#s the title synthesizes for root SRVs: 32_UINT and 32_FLOAT, identity map. + for (std::uint32_t word3 : {0x11014facu, 0x31016facu}) { + expect(n, mesh86_typed_identity_map(word3), "guest map accepted"); + expect(n, mesh86_typed_dword_format(word3), "guest format accepted"); + } +} + +struct Case { + const char* name; + void (*run)(const char*); +}; + +const Case cases[]{{"identity_map", identity_map}, + {"dword_formats", dword_formats}, + {"other_formats", other_formats}, + {"guest_words", guest_words}}; +} // namespace + +int main(int argc, char** argv) +{ + bool found = argc < 2; + for (const auto& c : cases) { + if (argc >= 2 && std::strcmp(argv[1], c.name)) continue; + found = true; + c.run(c.name); + } + if (!found) { + std::fprintf(stderr, "FAIL: unknown case %s\n", argv[1]); + return 2; + } + return failures ? 1 : 0; +} diff --git a/tests/native_direct_mesh_check.py b/tests/native_direct_mesh_check.py index 7fa7767e90..92ddfdc863 100644 --- a/tests/native_direct_mesh_check.py +++ b/tests/native_direct_mesh_check.py @@ -698,6 +698,28 @@ def skip_load(body, seed=True): 'unsupported mesh instruction or EXEC state: buffer_load_format_xy') run('typed-heap-xy-skip', skip_load([0xe0042000, 0x80080a01]), 'unsupported mesh instruction or EXEC state: buffer_load_format_xy') + # The same load from a V# read whole out of a bound descriptor table (root parameter 1, t0) goes + # through the shared typed-buffer SRV path instead of the resource heap. + heap_layout = layout.read_text() + layout.write_text('mesh1 128 3 1 2 128 64\nconstants 21 0 1\ntable 16 1') + table_setup = [0xbe910380, 0xf4080608, 0xfa000000] # s_mov_b32 s17, 0; s_load_dwordx4 s[24:27], s[16:17], 0 + table_idxen = [0xe0002000, 0x80060a01] # buffer_load_format_x v10, v1, s[24:27], 0 idxen + def table_load(body, seed=True): + pre = [0x7e140287] if seed else [] # v_mov_b32 v10, 7 + return table_setup + exported[:7] + pre + [0x7da40081, 0xbf880000 | len(body), *body, 0xbefe04c1] + exported[7:] + text = run('typed-table', table_setup + [0x7e020280] + table_idxen + exported) # v1 = 0 + assert 'bufferLoad.i32' in text and 'createHandleFromHeap' not in text, text + text = run('typed-table-lane-skip', table_load(table_idxen)) + assert 'bufferLoad.i32' in text and 'createHandleFromHeap' not in text, text + assert re.search(r'select i1 %[\w.]+, i32 %[\w.]+, i32 7\b', text), text + assert re.search(r'phi i32 \[ 7, %mesh_empty\d+ \]', text), text + run('typed-table-lane-skip-undef', table_load(table_idxen, seed=False), + 'graphics register undefined on an incoming path: 266') + run('typed-table-xy', table_setup + [0x7e020280, 0xe0042000, 0x80060a01] + exported, + 'unsupported mesh instruction or EXEC state: buffer_load_format_xy') + run('typed-table-no-skip', table_setup + exported[:7] + [0x7e140287, 0x7da40081, *table_idxen, 0xbefe04c1] + + exported[7:], 'unsupported mesh instruction or EXEC state: buffer_load_format_x') + layout.write_text(heap_layout) run('typed-heap-offset-skip', skip_load([0xe0002004, 0x80080a01]), 'formatted load requires zero or a single linear index') # Inside a whole-wave lane-limit skip (v_cmpx_gt_u32 + s_cbranch_execz), a fresh destination VGPR keeps its @@ -841,7 +863,7 @@ def assert_token_guard(text, reads): 'heap_tokens') result, out = compile_mesh('token-root-route', typed+exported) assert result.returncode == 0 and 'requires_heap_tokens' not in result.stdout, result.stdout + result.stderr - # Negative controls: another scale, no scale, a raw read, an overwritten descriptor word and a table descriptor in a skip. + # Negative controls: another scale, no scale, a raw read and an overwritten descriptor word. layout.write_text(token_layout) unaligned = 'mesh heap token byte offset is not a proven multiple of 32' run('token-shift4',select_word+[0x8f248424]+heap_base+selected_fetch+formatted+exported,unaligned) @@ -852,7 +874,11 @@ def assert_token_guard(text, reads): 'overwritten mesh heap descriptor') table_in_skip = (select_word[:3] + exported[:7] + [0x7e140287, 0x7da40081, 0xbf880002, 0xe0002000, 0x80080a01, 0xbefe04c1] + exported[7:]) - run('typed-table-in-skip', table_in_skip, 'formatted mesh load lacks an R32_UINT resource heap contract') + # A V# read from a bound table is not a heap slot: with heap tokens on, it still takes the typed table + # SRV route (see typed-table above) and needs no token view. + result, out = compile_mesh('typed-table-in-skip', table_in_skip) + assert result.returncode == 0 and 'requires_heap_tokens' not in result.stdout, result.stdout + result.stderr + assert 'bufferLoad.i32' in subprocess.check_output([sdk/'dxc.exe','-dumpbin',out], text=True) layout.write_text('mesh1 128 3 1 2 128 64\nconstants 21 0 1') widen_only = [ 0xbe96047e, # s_mov_b64 s[22:23], exec From b445b8cd7399a055c829d4b6face0036bde9d8c4 Mon Sep 17 00:00:00 2001 From: Luuk Motz Date: Tue, 1 Dec 2026 21:22:56 +0100 Subject: [PATCH 2/3] startup: refuse swizzled or thread-ID typed mesh86 V#s A raw V# with SWIZZLE_ENABLE (word 1 bit 31) or ADD_TID_ENABLE (word 3 bit 23) set addresses elements differently from the linear R32_UINT view slot 86 binds, so refuse it on both the heap and the table route. Add a linear_addressing unit case with two header mutation controls, and run the mesh86_typed_vsharp tests in the pr preset. Co-Authored-By: Claude Opus 5.5 --- CMakePresets.json | 2 +- src/startup_stubs/mesh86_typed_vsharp.h | 7 +++++++ src/startup_stubs/native_mesh86.inl | 6 ++++-- tests/cmake/mesh86_typed_vsharp.cmake | 14 ++++++++++++-- tests/mesh86_typed_vsharp_check.cpp | 11 +++++++++++ 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 6bd4804f08..0c03d3ba40 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -50,7 +50,7 @@ "displayName": "Windows pull request smoke tests", "filter": { "include": { - "name": "^(bcpack_all_formats(_golden_control)?|startup_bcpack_storage|desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_mesh57_real_shape|startup_mesh57_runtime(_[a-z]+)?_warp|native_fixed_mesh57_published_pair(_refusal)?_warp|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_(dispatch|constants|count)_inline_warp|startup_inline_retire_(on|control)_warp|startup_resource_retire_title_inline_warp_debug0|startup_table_lock_(control_)?warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_indirect_mesh_cache_heap(_wide)?_warp|runtime_mesh86_cache_cli_check|startup_shader_cache_key|startup_present_readback|startup_present_planes(_control)?|startup_present_composite_(warp|overlay_removed_control_warp)|startup_mesh_title_snapshot_warp|startup_list_copy_(warp|title_snapshot_warp|validation(_[a-z_]+_control)?)|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference|native_.*_(ir|dxil|controls)|native_direct_mesh|startup_triage_run)$" + "name": "^(bcpack_all_formats(_golden_control)?|startup_bcpack_storage|desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_mesh57_real_shape|startup_mesh57_runtime(_[a-z]+)?_warp|native_fixed_mesh57_published_pair(_refusal)?_warp|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_(dispatch|constants|count)_inline_warp|startup_inline_retire_(on|control)_warp|startup_resource_retire_title_inline_warp_debug0|startup_table_lock_(control_)?warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_indirect_mesh_cache_heap(_wide)?_warp|runtime_mesh86_cache_cli_check|startup_shader_cache_key|startup_present_readback|startup_present_planes(_control)?|startup_present_composite_(warp|overlay_removed_control_warp)|startup_mesh_title_snapshot_warp|startup_list_copy_(warp|title_snapshot_warp|validation(_[a-z_]+_control)?)|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference|native_.*_(ir|dxil|controls)|native_direct_mesh|mesh86_typed_vsharp_[a-z_]+|startup_triage_run)$" } } }, diff --git a/src/startup_stubs/mesh86_typed_vsharp.h b/src/startup_stubs/mesh86_typed_vsharp.h index 1b8a64fc82..aee6530b98 100644 --- a/src/startup_stubs/mesh86_typed_vsharp.h +++ b/src/startup_stubs/mesh86_typed_vsharp.h @@ -20,4 +20,11 @@ inline bool mesh86_typed_dword_format(std::uint32_t word3) return format >= 20u && format <= 22u; } +// Element i at base + i * stride: word 1 bit 31 (SWIZZLE_ENABLE) and word 3 bit 23 (ADD_TID_ENABLE) clear. +// Either bit changes which bytes a lane reads, and a linear desktop view would not. +inline bool mesh86_typed_linear(std::uint32_t word1, std::uint32_t word3) +{ + return !(word1 & 0x80000000u) && !(word3 & 0x00800000u); +} + } // namespace x2w_startup diff --git a/src/startup_stubs/native_mesh86.inl b/src/startup_stubs/native_mesh86.inl index bfd7c2455c..56a277df2f 100644 --- a/src/startup_stubs/native_mesh86.inl +++ b/src/startup_stubs/native_mesh86.inl @@ -400,8 +400,8 @@ const char* bind_native_mesh86(Wrapper* self, Pass& pass, ID3D12GraphicsCommandL return nullptr; }; // A buffer_load_format_x source, from a heap slot or a table: an R32_UINT view of 4-byte elements. - // A table V# must also name a 32-bit data format (see mesh86_typed_vsharp.h), so the R32_UINT view returns - // the same dword the guest format load would. + // A raw V# must address elements linearly, and a table V# must also name a 32-bit data format (see + // mesh86_typed_vsharp.h), so the R32_UINT view returns the same dword the guest format load would. const auto typed_dword = [&](UINT slot, const UINT (&words)[8], bool table = false) -> const char* { Mesh86Texture typed; if (words[0] == view_token_magic && @@ -410,6 +410,8 @@ const char* bind_native_mesh86(Wrapper* self, Pass& pass, ID3D12GraphicsCommandL return "native Mesh86 typed buffer slot is not R32_UINT"; if (words[0] != view_token_magic && !x2w_startup::mesh86_typed_identity_map(words[3])) return "native Mesh86 typed buffer descriptor uses another component map"; + if (words[0] != view_token_magic && !x2w_startup::mesh86_typed_linear(words[1], words[3])) + return "native Mesh86 typed buffer descriptor is swizzled or adds the thread ID"; if (table && words[0] != view_token_magic && !x2w_startup::mesh86_typed_dword_format(words[3])) return "native Mesh86 typed buffer descriptor is not a 32-bit format"; const auto view = indirect_table_buffer(self, words, false, nullptr, 16u << 20, 4, true); diff --git a/tests/cmake/mesh86_typed_vsharp.cmake b/tests/cmake/mesh86_typed_vsharp.cmake index 5cb7c02af0..2145c3a48d 100644 --- a/tests/cmake/mesh86_typed_vsharp.cmake +++ b/tests/cmake/mesh86_typed_vsharp.cmake @@ -3,7 +3,7 @@ add_executable(mesh86_typed_vsharp_check tests/mesh86_typed_vsharp_check.cpp) target_include_directories(mesh86_typed_vsharp_check PRIVATE src) target_compile_features(mesh86_typed_vsharp_check PRIVATE cxx_std_17) -foreach(mesh86_typed_vsharp_case IN ITEMS identity_map dword_formats other_formats guest_words) +foreach(mesh86_typed_vsharp_case IN ITEMS identity_map dword_formats other_formats linear_addressing guest_words) add_test(NAME mesh86_typed_vsharp_${mesh86_typed_vsharp_case} COMMAND mesh86_typed_vsharp_check ${mesh86_typed_vsharp_case}) set_tests_properties(mesh86_typed_vsharp_${mesh86_typed_vsharp_case} PROPERTIES TIMEOUT 60) @@ -13,12 +13,22 @@ endforeach() # case that guard must catch. Each control must fail (WILL_FAIL TRUE). set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS src/startup_stubs/mesh86_typed_vsharp.h) file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/startup_stubs/mesh86_typed_vsharp.h" mesh86_typed_vsharp_text) -foreach(mesh86_typed_vsharp_mut IN ITEMS wide_format any_map) +foreach(mesh86_typed_vsharp_mut IN ITEMS wide_format any_map any_swizzle any_tid) if(mesh86_typed_vsharp_mut STREQUAL "wide_format") # The 32-bit formats widened by one: other_formats sees 23 accepted. set(mesh86_typed_vsharp_from "format <= 22u") set(mesh86_typed_vsharp_to "format <= 23u") set(mesh86_typed_vsharp_case other_formats) + elseif(mesh86_typed_vsharp_mut STREQUAL "any_swizzle") + # SWIZZLE_ENABLE is no longer checked: linear_addressing sees a swizzled V# accepted. + set(mesh86_typed_vsharp_from "!(word1 & 0x80000000u)") + set(mesh86_typed_vsharp_to "(word1 == word1)") + set(mesh86_typed_vsharp_case linear_addressing) + elseif(mesh86_typed_vsharp_mut STREQUAL "any_tid") + # ADD_TID_ENABLE is no longer checked: linear_addressing sees a thread-ID V# accepted. + set(mesh86_typed_vsharp_from "!(word3 & 0x00800000u)") + set(mesh86_typed_vsharp_to "(word3 == word3)") + set(mesh86_typed_vsharp_case linear_addressing) else() # The component map is no longer checked: identity_map sees a swizzle accepted. set(mesh86_typed_vsharp_from "return (word3 & 0xfffu) == 0xfacu;") diff --git a/tests/mesh86_typed_vsharp_check.cpp b/tests/mesh86_typed_vsharp_check.cpp index df54645ac2..084d1d6a86 100644 --- a/tests/mesh86_typed_vsharp_check.cpp +++ b/tests/mesh86_typed_vsharp_check.cpp @@ -12,6 +12,7 @@ using x2w_startup::mesh86_typed_dword_format; using x2w_startup::mesh86_typed_identity_map; +using x2w_startup::mesh86_typed_linear; namespace { int failures = 0; @@ -47,12 +48,21 @@ void other_formats(const char* n) expect(n, !mesh86_typed_dword_format(with_format(format)), "non-32-bit format refused"); } +void linear_addressing(const char* n) +{ + expect(n, mesh86_typed_linear(0x00040000u, 0x31016facu), "stride 4, no swizzle, no thread ID accepted"); + expect(n, mesh86_typed_linear(0x7fffffffu, 0xff7fffffu), "other word 1 and word 3 bits ignored"); + expect(n, !mesh86_typed_linear(0x80040000u, 0x31016facu), "SWIZZLE_ENABLE refused"); + expect(n, !mesh86_typed_linear(0x00040000u, 0x31816facu), "ADD_TID_ENABLE refused"); +} + void guest_words(const char* n) { // Word 3 of the V#s the title synthesizes for root SRVs: 32_UINT and 32_FLOAT, identity map. for (std::uint32_t word3 : {0x11014facu, 0x31016facu}) { expect(n, mesh86_typed_identity_map(word3), "guest map accepted"); expect(n, mesh86_typed_dword_format(word3), "guest format accepted"); + expect(n, mesh86_typed_linear(0u, word3), "guest word 3 adds no thread ID"); } } @@ -64,6 +74,7 @@ struct Case { const Case cases[]{{"identity_map", identity_map}, {"dword_formats", dword_formats}, {"other_formats", other_formats}, + {"linear_addressing", linear_addressing}, {"guest_words", guest_words}}; } // namespace From 49ec29116f7f4aa54d8e6a034f57b4fa898a5e3e Mon Sep 17 00:00:00 2001 From: Luuk Motz Date: Tue, 1 Dec 2026 21:32:23 +0100 Subject: [PATCH 3/3] build: build the mesh86_typed_vsharp checks in the pr preset The pr test filter runs mesh86_typed_vsharp_*, but the pr build preset only builds its listed targets, so CI reported the tests as not run. Co-Authored-By: Claude Opus 5.5 --- CMakePresets.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakePresets.json b/CMakePresets.json index 0c03d3ba40..70c38b7e72 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -36,7 +36,9 @@ "xmem_placeholder_split_check", "xmem_map_split_first_check", "startup_dstorage_break_window_check", "xmem_page_runs_device_check", "linear_buffer_backing_check", "bcpack_formats_check", "startup_stub_consumer", "startup_inline_retire", "startup_resource_retire_title", "startup_table_lock", - "native_compute_ir_dump", "native_pixel_ir_dump", "native_store_replay", "native_raw_buffer_view_check" + "native_compute_ir_dump", "native_pixel_ir_dump", "native_store_replay", "native_raw_buffer_view_check", + "mesh86_typed_vsharp_check", "mesh86_typed_vsharp_wide_format_mut", "mesh86_typed_vsharp_any_map_mut", + "mesh86_typed_vsharp_any_swizzle_mut", "mesh86_typed_vsharp_any_tid_mut" ] }, { "name": "release", "configurePreset": "release" },