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
2 changes: 2 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ jobs:
(["tests/startup_compute_readfirstlane_check.py", "--llvm-mc", "llvm-mc-15"], {}),
(["tests/startup_compute_gather_l_check.py", "--llvm-mc", "llvm-mc-15"], {}),
(["tests/startup_compute_buffer_atomics_check.py", "--llvm-mc", "llvm-mc-15"], {}),
(["tests/startup_compute_store_d16_x_check.py", "binary", "llvm-mc-15"], {}),
(["tests/startup_image_gather_c_lz_check.py", "--llvm-mc", "llvm-mc-15"], {}),
(["tests/startup_image_sample_c_check.py", "binary", "llvm-mc-15"], {}),
(["tests/startup_image_3d_check.py", "binary", "llvm-mc-15"], {}),
Expand Down Expand Up @@ -218,6 +219,7 @@ jobs:
tests/startup_compute_image_store_d16_check.py \
tests/startup_compute_gather_l_check.py \
tests/startup_compute_buffer_atomics_check.py \
tests/startup_compute_store_d16_x_check.py \
tests/startup_image_gather_c_lz_check.py \
tests/startup_image_sample_c_check.py \
tests/startup_image_3d_check.py \
Expand Down
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3535,6 +3535,22 @@ if(EXISTS "${INTAKE_PYTHON}")
"$<TARGET_FILE:offscreen_check>" ${adapter})
set_tests_properties(startup_gfx2hlsl_neg_dispatch_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
endforeach()
# gfx2hlsl compute buffer_store_format_d16_x: multi-format, bounds/OOB, atomic CAS RMW and EXEC guard (Refs #2274).
add_test(NAME startup_compute_store_d16_x_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/startup_compute_store_d16_x_check.py")
foreach(adapter IN ITEMS warp hardware)
add_test(NAME startup_compute_store_d16_x_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/startup_compute_store_d16_x_check.py" dispatch "${DXC_EXECUTABLE}"
"$<TARGET_FILE:offscreen_check>" ${adapter})
set_tests_properties(startup_compute_store_d16_x_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
foreach(control IN ITEMS f32-drop-store f32-wrong-half f32-drop-oob unorm16-trunc p-drop-soffset p-drop-keep s-fold-soff-stride e-drop-exec b-short-binding b-tight-host-guard)
add_test(NAME startup_compute_store_d16_x_${control}_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/startup_compute_store_d16_x_check.py" control ${control} "${DXC_EXECUTABLE}"
"$<TARGET_FILE:offscreen_check>" ${adapter})
set_tests_properties(startup_compute_store_d16_x_${control}_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77
PASS_REGULAR_EXPRESSION "control ${control}: rejected at word=[0-9]+ ")
endforeach()
endforeach()
# gfx2hlsl compute stage: entry registers, numthreads and the offen buffer store, dispatched on a plain device (#1412).
add_test(NAME startup_gfx2hlsl_compute_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_compute_check.py")
Expand Down
18 changes: 18 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -14642,6 +14642,24 @@ case. The three mutations mismatched 32, 8 and 16 words respectively on both ada
ctest --preset dev --no-tests=error -j 1 -R '^startup_gfx2hlsl_compute_(controls|warp|hardware)$' -V
```

### Startup compute formatted 16-bit single-channel buffer stores

[The startup translator](../tools/startup/gfx2hlsl.py) (`op_buffer_store_format_d16_x`, refs `#2274`) lowers compute MUBUF `buffer_store_format_d16_x` (`0x84`) through four untouched words of a fixed native table descriptor (`uav <slot> table <param> <offset>`), requesting `udsrc` entries `uav_descword3`, `uav_stride` (unmasked `DW1 >> 16`, so `stride > 0x3fffu` rejects nonzero `CACHE_SWIZZLE`/`SWIZZLE_ENABLE` bits 31:30) and `uav_numrecords` for that UAV slot. After a branch, the descriptor must come from a local table load with a proven entry root pointer; non-compute stages, modified descriptors (including stride clears), shared load/store descriptors, lane-mask `soffset`, illegal binary `lds`/reserved MUBUF bits, and unsupported modifiers (`glc`, `slc`, `dlc`, `tfe`, `lds`) are refused with `Unsupported`.

Supported 1-channel formats (`BUF_FMT_32_FLOAT` 22, `BUF_FMT_16_FLOAT` 13, `BUF_FMT_16_UNORM` 7, `BUF_FMT_16_SNORM` 8, `BUF_FMT_16_UINT` 11, `BUF_FMT_16_SINT` 12, in both GFX10 unified and legacy `DFMT`/`NFMT` encodings) extract the low 16 bits of `vdata`, enforce `DST_SEL_X == 4`, zero reserved/swizzle/`ADD_TID_ENABLE`/`TYPE` bits, and RDNA 2 ISA §8.1.5 Table 35 bounds modes: `OOB_SELECT == 0` (`SQ_OOB_INDEX_AND_OFFSET`, requires `stride != 0`, checks `idx < num_records` and `rec_off + elem_bytes <= stride` where `rec_off = voff + imm_off`, while `soffset` adds to base address) and `OOB_SELECT == 3` (`SQ_OOB_COMPLETE` raw mode, requires `stride == 0`, checks `soffset + rec_off + elem_bytes <= num_records`). `OOB_SELECT` `1` (`INDEX_ONLY`) and `2` (`NUM_RECORDS_0` / disabled bounds), mismatched `stride`/`OOB_SELECT`, 32-bit address overflow, misaligned addresses, and OOB lanes are no-ops. Separately from guest `num_records`/`stride`, `store_format_d16_x` queries `buf.GetDimensions(uav_bytes)` on the bound raw UAV and exits before `buf.Store` (`uav_bytes < 4u || addr > uav_bytes - 4u`) or before `buf.Load(base)` and `buf.InterlockedCompareExchange(base, ...)` (`uav_bytes < 4u || base > uav_bytes - 4u`) whenever the enclosing aligned DWORD `[base, base + 4)` exceeds the host view. Stores use 4-byte aligned `Store` for `32_FLOAT` and a lock-free `InterlockedCompareExchange` CAS loop for 2-byte aligned 16-bit formats, under an `if (exec & 1)` lane guard when `EXEC` is not proven entry-full.

[The `buffer_store_format_d16_x` check](../tests/startup_compute_store_d16_x_check.py) covers pure-Python unit/manifest/encoding/provenance/refusal checks (including static ordering of `GetDimensions` and host-backing guards before `Store`, `Load`, and `InterlockedCompareExchange`) and dispatches six source-built `gfx1013` compute programs through descriptor-table raw views (`offscreen_check --compute-store-sized-case` with optional `uav_words`): `F` (all six formats + legacy encodings + 7 no-op descriptor/OOB/swizzle checks), `P` (`OOB_SELECT=3` raw bounds + `stride=0` + `offen` + SGPR `soffset` + concurrent adjacent halves), `S` (`OOB_SELECT=0` structured with `soffset=16 > stride=8`), `E` (`idxen offen` + local descriptor reload after `s_cbranch_execz` + inner `s_and_saveexec_b32` EXEC guard), `B`/`B-short` (`OOB_SELECT=3, stride=0, num_records=6` writing `addr = 0, 2, 4` against padded `uav_words=2` and short `uav_words=1` host bindings), and `C` (256 concurrent threads hammering the same low/high 16-bit halfwords to verify atomic CAS without bitwise-OR or torn corruption). On both WARP (`Microsoft Basic Render Driver` `1414:008c`, driver `10.0.26100.9818`) and `NVIDIA GeForce RTX 4070 SUPER` (`10de:2783`, driver `32.0.16.2114`) with the D3D12 debug layer enabled, all 18 deterministic dispatch cases matched all `320` words (`mismatches=0`, `debug_errors=0 debug_warnings=0`), Case `C` produced valid atomic halfword values with 319 untouched sentinels (`debug_errors=0 debug_warnings=0`), and all ten controls rejected cleanly on both adapters (`f32-drop-store`, `f32-wrong-half`, `f32-drop-oob`, `unorm16-trunc`, `p-drop-soffset`, `p-drop-keep`, `s-fold-soff-stride`, `e-drop-exec`, plus `b-short-binding` and `b-tight-host-guard` at `word=1` with `debug_errors=0 debug_warnings=0`).

```powershell
. .\tools\dev.ps1
cmake --preset release
cmake --build --preset release --target offscreen_check
ctest --preset release --no-tests=error -j 1 -R "^startup_compute_store_d16_x" -V
python -B tests/startup_compute_store_d16_x_check.py binary llvm-mc-15
```

Not covered here: `llvm-mc-15` assembly step on Linux CI (`binary`), `OOB_SELECT=3` with nonzero stride, multi-channel `buffer_store_format_d16_{xy,xyz,xyzw}`, `buffer_store_format_d16_hi_x`, and live runtime slot-67 dispatch binding of `uav_descword3`/`uav_stride`/`uav_numrecords`.

### First active lane at compute entry

The startup compute translator accepts `s_ff1_i32_b32 sN, exec_lo` in the
Expand Down
40 changes: 27 additions & 13 deletions tests/compute_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ UINT texture_words_per_texel(DXGI_FORMAT format)

static UINT input_word(UINT i) { return 0x8b02a7f1u + i * 0x413b1u; }

// source replaces the generated t0 words when a store case supplies its own, and initial
// replaces the sentinel words that seed the output buffer.
// source replaces the generated t0 words when a store case supplies its own, initial replaces the
// sentinel words that seed the output buffer, and root_constants replaces the b0 CBV constants.
static void fill_upload(ID3D12Resource* upload, const std::array<UINT, capacity>* source = nullptr,
const std::array<UINT, capacity>* initial = nullptr)
const std::array<UINT, capacity>* initial = nullptr,
const std::array<UINT, constants.size()>* root_constants = nullptr)
{
void* mapped = nullptr;
const D3D12_RANGE no_reads{};
Expand All @@ -81,7 +82,8 @@ static void fill_upload(ID3D12Resource* upload, const std::array<UINT, capacity>
}
auto* cb = static_cast<unsigned char*>(mapped) + constants_offset;
std::memset(cb, 0, 4 * alignment);
std::memcpy(cb, constants.data(), sizeof(constants));
const auto& cb0 = root_constants ? *root_constants : constants;
std::memcpy(cb, cb0.data(), sizeof(cb0));
for (UINT i = 1; i < 4; ++i) std::memcpy(cb + i * alignment, &constants[12 + i], sizeof(UINT));
upload->Unmap(0, nullptr);
}
Expand Down Expand Up @@ -148,8 +150,11 @@ static ComPtr<ID3D12Resource> upload_texture(ID3D12Device* device, ID3D12Graphic
static ComPtr<ID3D12DescriptorHeap> bind_tables(ID3D12Device* device, ID3D12GraphicsCommandList* list,
ID3D12Resource* input, ID3D12Resource* output,
ID3D12Resource* texture = nullptr, UINT output_register = uavs - 1, UINT output_mip = 0,
UINT input_register = srvs - 1, UINT texture_first_mip = 0)
UINT input_register = srvs - 1, UINT texture_first_mip = 0,
UINT output_words = capacity)
{
if (output_words == 0 || output_words > capacity)
throw std::runtime_error("Invalid compute UAV word count");
D3D12_DESCRIPTOR_HEAP_DESC desc{};
desc.NumDescriptors = uavs + srvs;
desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
Expand All @@ -161,7 +166,7 @@ static ComPtr<ID3D12DescriptorHeap> bind_tables(ID3D12Device* device, ID3D12Grap
D3D12_UNORDERED_ACCESS_VIEW_DESC uav{};
uav.Format = DXGI_FORMAT_R32_TYPELESS;
uav.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
uav.Buffer.NumElements = capacity;
uav.Buffer.NumElements = output_words;
uav.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
if (output_register >= uavs) throw std::runtime_error("Invalid output register");
const auto output_desc = output->GetDesc();
Expand Down Expand Up @@ -241,9 +246,11 @@ static void run_compute(ID3D12Device* device, bool tables, D3D12_SHADER_BYTECODE
D3D12_SHADER_BYTECODE rootBytes, bool conversion_pair = false,
const StoreCase* store = nullptr, const std::vector<UINT>* texels = nullptr,
DXGI_FORMAT texture_format = DXGI_FORMAT_UNKNOWN, ID3D12Resource* rendered_texture = nullptr,
bool dpp_case = false, bool sized_views = false, UINT texture_first_mip = 0)
bool dpp_case = false, bool sized_views = false, UINT texture_first_mip = 0,
UINT uav_words = capacity)
{
if ((texels || rendered_texture) && !tables) throw std::runtime_error("An image load needs the descriptor-table signature");
if (uav_words == 0 || uav_words > capacity) throw std::runtime_error("Invalid compute UAV word count");
ComPtr<ID3D12RootSignature> signature;
check(device->CreateRootSignature(0, rootBytes.pShaderBytecode, rootBytes.BytecodeLength, IID_PPV_ARGS(&signature)),
"Create compute root signature");
Expand All @@ -258,7 +265,8 @@ static void run_compute(ID3D12Device* device, bool tables, D3D12_SHADER_BYTECODE
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
auto readback = make_buffer(device, bytes, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST);
fill_upload(input.Get(), store && store->has_source ? &store->source : nullptr,
store && store->has_initial ? &store->initial : nullptr);
store && store->has_initial ? &store->initial : nullptr,
store ? &store->root_constants : nullptr);
ComputeCommands commands(device, pipeline.Get());
auto& list = commands.list;
ComPtr<ID3D12Resource> texture_upload, texture;
Expand All @@ -273,7 +281,7 @@ static void run_compute(ID3D12Device* device, bool tables, D3D12_SHADER_BYTECODE
// signature's UAV range starts at u0, while the root-descriptor path keeps u12.
auto* image = rendered_texture ? rendered_texture : texture.Get();
// A sized-view case binds both raw buffers at u0 and t0, so GetDimensions reports the view's byte size.
heap = sized_views ? bind_tables(device, list.Get(), input.Get(), output.Get(), nullptr, 0, 0, 0)
heap = sized_views ? bind_tables(device, list.Get(), input.Get(), output.Get(), nullptr, 0, 0, 0, 0, uav_words)
: bind_tables(device, list.Get(), input.Get(), output.Get(), image, image ? 0 : uavs - 1,
0, srvs - 1, texture_first_mip);
} else {
Expand Down Expand Up @@ -341,8 +349,10 @@ void check_compute(ID3D12Device* device, bool tables)
}

void check_compute_file(ID3D12Device* device, const char* path, bool conversion_pair, const char* reference,
bool dpp_case, bool sized_views)
bool dpp_case, bool sized_views, UINT uav_words)
{
if (sized_views && uav_words > capacity)
throw std::runtime_error("Invalid compute UAV word count");
std::ifstream file(path, std::ios::binary | std::ios::ate);
if (!file) throw std::runtime_error(std::string("Could not open compute shader: ") + path);
const auto size = file.tellg();
Expand Down Expand Up @@ -383,12 +393,16 @@ void check_compute_file(ID3D12Device* device, const char* path, bool conversion_
store.has_source = true;
}
}
if (sized_views)
if (sized_views) {
const UINT effective_uav_words = uav_words ? uav_words : capacity;
if (effective_uav_words > capacity)
throw std::runtime_error("Invalid compute UAV word count");
run_compute(device, true, shader, {compute_tables, sizeof(compute_tables)}, false, &store, nullptr,
DXGI_FORMAT_UNKNOWN, nullptr, dpp_case, true);
else
DXGI_FORMAT_UNKNOWN, nullptr, dpp_case, true, 0, effective_uav_words);
} else {
run_compute(device, false, shader, {compute_root, sizeof(compute_root)}, false, &store, nullptr,
DXGI_FORMAT_UNKNOWN, nullptr, dpp_case);
}
} else {
run_compute(device, false, shader, shader, conversion_pair);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/desktop_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void check_spirv_compaction(ID3D12Device* device, const char* shader_path);
void check_spirv_compare_sampler(ID3D12Device* device, const char* shader_path, const char* ordinary_register,
const char* reference_path, const char* descriptors = nullptr);
void check_compute_file(ID3D12Device* device, const char* path, bool conversion_pair, const char* reference = nullptr,
bool dpp_case = false, bool sized_views = false);
bool dpp_case = false, bool sized_views = false, UINT uav_words = 0);
void check_compute_texture_file(ID3D12Device* device, const char* path, const char* reference);
bool check_compute_texture_msaa_file(ID3D12Device* device, const char* path, const char* reference,
const char* vs_path, const char* ps_path);
Expand Down
16 changes: 12 additions & 4 deletions tests/offscreen_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,19 @@ OperationResult run_compute_store_case(const OperationContext& ctx)
return {OutcomeKind::pass, nullptr};
}

// The store case with both raw buffers bound as descriptor-table views of the full 1280 bytes, so a
// shader reading a descriptor's size sees the view size (root descriptors carry none).
// The store case with both raw buffers bound as descriptor-table views (defaulting to the full 1280
// bytes, or an explicit uav_words count in [1, 320]), so a shader reading a descriptor's size sees
// the view size (root descriptors carry none).
OperationResult run_compute_store_sized_case(const OperationContext& ctx)
{
check_compute_file(ctx.device, ctx.argv[3], false, ctx.argv[4], false, true);
UINT uav_words = 0;
if (ctx.argc == 6) {
const std::string_view text = ctx.argv[5];
const auto [end, error] = std::from_chars(text.data(), text.data() + text.size(), uav_words);
if (error != std::errc{} || end != text.data() + text.size() || uav_words == 0)
throw std::runtime_error("Invalid compute UAV word count");
}
check_compute_file(ctx.device, ctx.argv[3], false, ctx.argv[4], false, true, uav_words);
return {OutcomeKind::pass, nullptr};
}

Expand Down Expand Up @@ -1578,7 +1586,7 @@ const OperationSpec kOperations[] = {
{"--compute-root-file", 4, 4, nullptr, kNoGate, run_compute_root_file},
{"--ffx-immediate-conversion", 4, 4, nullptr, kNoGate, run_ffx_immediate_conversion},
{"--compute-store-case", 5, 5, nullptr, kNoGate, run_compute_store_case},
{"--compute-store-sized-case", 5, 5, nullptr, kNoGate, run_compute_store_sized_case},
{"--compute-store-sized-case", 5, 6, nullptr, kNoGate, run_compute_store_sized_case},
{"--compute-store-dpp-case", 5, 5, nullptr, kGateShaderWave, run_compute_store_dpp_case},
{"--compute-store-case-atomic64", 5, 5, nullptr, kGateComputeAtomic64, run_compute_store_case},
{"--compute-texture-case", 5, 5, nullptr, kNoGate, run_compute_texture_case},
Expand Down
Loading
Loading