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
4 changes: 2 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"xmem_shim_test_controls", "startup_stub_xcrdapi", "startup_stub_xcrdapi_break_window_control",
"xmem_run_break_readers_check", "xmem_run_break_readers_control", "xmem_cross_call_merge_check",
"xmem_placeholder_split_check", "xmem_map_split_first_check", "startup_dstorage_break_window_check",
"xmem_page_runs_device_check", "linear_buffer_backing_check", "existing_heap_shared_buffer_check",
"xmem_page_runs_device_check", "linear_buffer_backing_check", "existing_heap_shared_buffer_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",
"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"
]
Expand All @@ -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|existing_heap_shared_buffer(_offset_control)?_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|existing_heap_shared_buffer(_offset_control)?_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference|native_.*_(ir|dxil|controls)|native_direct_mesh|startup_triage_run|mesh86_typed_vsharp_[a-z_]+)$"
}
}
},
Expand Down
7 changes: 7 additions & 0 deletions src/gfx1013_direct_mesh.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,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;
Expand Down
1 change: 1 addition & 0 deletions src/startup_stubs/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 30 additions & 0 deletions src/startup_stubs/mesh86_typed_vsharp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 <cstdint>

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;
}

// 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
44 changes: 31 additions & 13 deletions src/startup_stubs/native_mesh86.inl
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ x2w_startup::ComPtr<ID3D12RootSignature> make_native_mesh86_root(
const bool indexed_raw = view.kind == Kind::indexed_raw_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 || indexed_raw;
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;
const bool table = type == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
require(table ? !(view.byte_offset & 31) :
!image && !indexed_raw && !view.byte_offset && (type == D3D12_ROOT_PARAMETER_TYPE_SRV ||
type == D3D12_ROOT_PARAMETER_TYPE_CBV),
!image && !indexed_raw && !typed && !view.byte_offset &&
(type == D3D12_ROOT_PARAMETER_TYPE_SRV || type == D3D12_ROOT_PARAMETER_TYPE_CBV),
"invalid native Mesh86 SRV source");
require(!indexed_raw || (view.array_count == 1 && view.required_bytes &&
!(view.required_bytes % 4) && view.required_bytes <= 2048),
Expand Down Expand Up @@ -404,6 +406,25 @@ 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 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 &&
(!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 (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);
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 ||
Expand All @@ -427,6 +448,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]{};
Expand Down Expand Up @@ -482,16 +509,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;
Expand Down
53 changes: 53 additions & 0 deletions tests/cmake/mesh86_typed_vsharp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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 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)
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 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;")
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()
94 changes: 94 additions & 0 deletions tests/mesh86_typed_vsharp_check.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// 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 [<case>] (no argument runs all cases)
// Every mismatch prints "FAIL: <case>: ..." to stderr and exits non-zero.
#include "startup_stubs/mesh86_typed_vsharp.h"

#include <cstdint>
#include <cstdio>
#include <cstring>
#include <initializer_list>

using x2w_startup::mesh86_typed_dword_format;
using x2w_startup::mesh86_typed_identity_map;
using x2w_startup::mesh86_typed_linear;

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 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");
}
}

struct Case {
const char* name;
void (*run)(const char*);
};

const Case cases[]{{"identity_map", identity_map},
{"dword_formats", dword_formats},
{"other_formats", other_formats},
{"linear_addressing", linear_addressing},
{"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;
}
Loading
Loading