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
12 changes: 8 additions & 4 deletions src/startup_stubs/d3d12_compute_dispatch.inl
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,14 @@ const char* compute_token_output(Wrapper* list, const std::uint32_t* words, Comp
// backing is the host buffer used by subsequent object-based GPU commands.
// This mode does not imply CPU aliasing or make a partial view authoritative.
static const bool copied_views = x2w_local::env_on("X2W_COPIED_OBJECT_UAV");
const bool whole_copy = copied_views && info->placement == Placement::copied_buffer &&
output.offset == 0 && output.bytes == info->bytes && output.bytes == output.backing.Width;
if (placed.alias != resource && !whole_copy)
return "an output token's backing does not uniquely alias its guest byte interval";
if (placed.alias != resource) {
if (info->placement != Placement::copied_buffer)
return "an output token's backing does not uniquely alias its guest byte interval";
if (output.offset || output.bytes != info->bytes || output.bytes != output.backing.Width)
return "an output UAV covers only part of a copied placement";
if (!copied_views)
return "a whole copied output UAV requires X2W_COPIED_OBJECT_UAV";
}
} else {
D3D12_HEAP_PROPERTIES heap{};
D3D12_HEAP_FLAGS flags{};
Expand Down
7 changes: 5 additions & 2 deletions tests/native_compute_pack_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def hardware(cli, consumer, sdk):
words, result = dispatch(work, str(consumer), env, "dispatch")
assert words == [C.SENTINEL] * C.WORDS and lines(result, "refused:"), result.stderr
env["X2W_D3D12_COMPUTE_OUTPUT_TRACE"] = "1"
for mode in ("raw", "structured", "typed", "wrong-slot", "copied"):
env.pop("X2W_COPIED_OBJECT_UAV", None)
for mode in ("raw", "structured", "typed", "wrong-slot", "copied", "copied-whole"):
words, result = dispatch(work, str(consumer), env, f"dispatch-uav-token-{mode}")
expected = [C.SENTINEL] * C.WORDS
if mode in ("raw", "structured", "typed"):
Expand All @@ -84,7 +85,9 @@ def hardware(cli, consumer, sdk):
elif mode == "wrong-slot":
assert lines(result, "does not identify a slot-19 UAV"), result.stderr
else:
assert lines(result, "does not uniquely alias its guest byte interval"), result.stderr
reason = ("an output UAV covers only part of a copied placement" if mode == "copied"
else "a whole copied output UAV requires X2W_COPIED_OBJECT_UAV")
assert lines(result, reason), result.stderr
assert lines(result, "use=copy-source-attempt") and not lines(result, "use=copy-read-recorded"), result.stderr
assert lines(result, "use=map-guest-read-request") and lines(result, "x2w-compute-output-submit"), result.stderr
assert words == expected, (mode, words[:16], expected[:16], result.stderr)
Expand Down
9 changes: 7 additions & 2 deletions tests/startup_stream_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,18 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin
DXGI_FORMAT_UNKNOWN, {1, 0}, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS};
if (!(output = make_committed(device, D3D12_HEAP_TYPE_DEFAULT, desc, D3D12_RESOURCE_STATE_COMMON))) return 71;
}
if (mode == "dispatch-uav-token-copied") {
const bool whole_copy = mode == "dispatch-uav-token-copied-whole";
if (mode == "dispatch-uav-token-copied" || whole_copy) {
const D3D12_RESOURCE_DESC desc{D3D12_RESOURCE_DIMENSION_BUFFER, 0, words * sizeof(UINT), 1, 1, 1,
DXGI_FORMAT_UNKNOWN, {1, 0}, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS};
if (FAILED(static_cast<HRESULT>(invoke(device, 133, between, word(&desc), D3D12_RESOURCE_STATE_COMMON, 0,
word(&__uuidof(ID3D12Resource)), word(&output))))) return 71;
copied_token_output = output;
if (whole_copy) {
view.Buffer.FirstElement = 0;
view.Buffer.NumElements = words;
}
}
if (mode == "dispatch-uav-token-copied") copied_token_output = output;
// Byte 32 is not a descriptor of the heap on every adapter (WARP): the view is created at byte 64 and its
// token copied to byte 32, as a title copies descriptors.
invoke(device, 19, word(output), 0, word(&view), cpu + 64);
Expand Down
Loading