Skip to content
Open
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
26 changes: 24 additions & 2 deletions docs/experiments/native-global-srv-heap-replay.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ ctest --preset dev --no-tests=error -R "^native_global_srv_heap_replay(_warp|_ha
- With the high-word check removed, both tests fail at the `mov_high` controls.
- `ctest --preset dev --no-tests=error -R "native_|startup_compute|compile_dxil" -j 8`: 415 tests, 404 passed and
11 skipped (77, WARP).
- Formatted loads through the byte window (original #3034 result for #3023): `tbuffer_load_format_*` through the rewritten descriptor now reads
the same raw view as `buffer_load_dword` (`src/gfx1013_compute_mtbuf.inl` picks `byte_window_srv` when word 1 is the
stride-cleared word). Before, it was refused with "non-contiguous resource descriptor". On the local capture with the
raw contract forced and a typed heap load prototyped (both uncommitted), 861 of the 2,689 requests stopped first at
this refusal; with the change they move on to other, already-known refusals. `native_global_srv_heap_replay_hardware`
passes with 94 assertions (record, compile and replay of a 32_UINT `tbuffer_load_format_x` through the heap window
for selections 0 and 1, the cross-slot mismatch control, the loop guard for the formatted load, and a compile-only
8_8_8_8_UNORM case). `native_mtbuf_hardware` repeats its 11-format value check through a byte window of its table SRV
and matches, including the element at the end of the view that returns 0 (`tests/native_store_replay.cpp` accepts
the window binding as the same raw view). `native_direct_container` compiles both formats through a compute table
window and refuses the window without the byte-count product. Against `837728dd` the heap check fails at the
`twindow_loop` shape (text "non-contiguous resource descriptor").

## Limits

Expand All @@ -153,8 +165,18 @@ ctest --preset dev --no-tests=error -R "^native_global_srv_heap_replay(_warp|_ha
byte-address rewrite consumes it. The fixture's descriptor words are never evaluated, so a stride above 1 and the
size rule of the contract are not exercised. The HLSL path's `heap_stride_srv` (`src/gfx1013_compute_native.cpp`,
used by `tests/native_compute_grid.cpp`) is unchanged.
- A formatted load (`tbuffer_load_format_*`) bounds its element with the size of the desktop raw view
(`getDimensions`) and returns 0 for the whole element when it does not fit. A runtime that binds a byte window
must create the raw view with the exact guest window's byte count. The heap replay uses identity channel order.
A published table manifest marks the MTBUF window with `srv <i> buf table <param> <byte> identity_dst_sel`, including
after a frontend cache hit. The compute binder checks word 3's DST_SEL of the hardware descriptor or the
component mapping of a slot 18 buffer SRV before binding the raw view for the exact range. The in-process
path falls through to that manifest for a byte window.
- `startup_compute_mtbuf_window_{hardware,warp}` compares 12 pairs and the surrounding guards through the published
path for both a hardware descriptor and a buffer SRV token. A 44-byte window holds five full pairs. The partial
pair and the later pairs read zero. Swapped X/Y selectors refuse before Dispatch, and the output keeps its sentinel.
- Typed loads (`buffer_load_format_*`) through a heap descriptor and scalar loads through the rewritten descriptor stay
refused. The startup runtime
does not pass a contract yet, so none of this reaches a title run (#3023).
refused. The startup runtime does not yet pass the required contract for GPU-selected heap loads, so that heap route
does not reach a title run (#3023).
- The captured `select` must be the slot index the dispatch addresses; producing it from a title capture is outside this
fixture.
9 changes: 6 additions & 3 deletions src/direct_compute_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Bytes encode(const NativeComputeShader &program) {
for (const auto &b : program.bindings) {
word(out, static_cast<uint32_t>(b.kind));
for (unsigned n : {b.root_parameter, b.byte_offset, b.shader_register, b.required_bytes, b.array_count,
b.array_position, b.image_dimension, unsigned(b.scalar_table)})
b.array_position, b.image_dimension, unsigned(b.scalar_table), unsigned(b.requires_identity_dst_sel)})
word(out, n);
}
word(out, static_cast<uint32_t>(program.constants.size()));
Expand Down Expand Up @@ -134,6 +134,7 @@ NativeComputeShader decode(std::string_view bytes) {
auto kind = static_cast<ComputeViewKind>(in.count(static_cast<unsigned>(ComputeViewKind::float3_texture_uav)));
ComputeViewBinding b{kind, in.word(), in.word(), in.word(), in.word(), in.word(), in.word(), in.count(7)};
b.scalar_table = static_cast<ComputeViewBinding::ScalarTable>(in.count(unsigned(ComputeViewBinding::ScalarTable::srv)));
b.requires_identity_dst_sel = in.count(1) != 0;
const bool sampler_heap = kind == ComputeViewKind::heap_sampler;
if (!b.array_count || b.array_position >= b.array_count ||
(sampler_heap ? b.root_parameter != compute_sampler_heap
Expand Down Expand Up @@ -795,8 +796,10 @@ std::optional<std::string> format_compute_runtime_manifest(const NativeComputeSh
return refuse("SRV registers not contiguous");
if (b.kind == ComputeViewKind::buffer_srv || b.kind == ComputeViewKind::raw_vector_srv ||
b.kind == ComputeViewKind::byte_window_srv) {
srv_lines << "srv " << b.shader_register << " buf table " << b.root_parameter << ' ' << b.byte_offset
<< '\n';
srv_lines << "srv " << b.shader_register << " buf table " << b.root_parameter << ' ' << b.byte_offset;
if (b.requires_identity_dst_sel)
srv_lines << " identity_dst_sel";
srv_lines << '\n';
} else if (b.kind == ComputeViewKind::texture_srv && b.array_count == 1 &&
(b.image_dimension == 0 || b.image_dimension == 1 || b.image_dimension == 2 ||
b.image_dimension == 5)) {
Expand Down
9 changes: 7 additions & 2 deletions src/gfx1013_compute_mtbuf.inl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// MTBUF uses the instruction's explicit format and the descriptor's byte range.
// Format numbers follow tools/disasm_rdna2.py MTBUF_FORMATS. Conversion and
// unaligned addressing follow gfx2hlsl.tbuffer / ldu, cross-checked against
// Victory 9376fd6 format_load. Only the runtime-checked identity raw SRV is used.
// Victory 9376fd6 format_load. Only the runtime-checked identity raw SRV is used, or
// its byte window (the byte-address rewrite of the descriptor, read as the same raw view).
enum class ChannelNumber { unorm, snorm, uscaled, sscaled, uint_, sint, float_ };
struct MtbufFamily {
unsigned first, last, bits, components;
Expand Down Expand Up @@ -53,7 +54,11 @@ void formatted_byte_load(const Inst &i, const State &s) {
refuse(i.pc, "MTBUF destination tuple overflow");
const unsigned width = family->bits;
const auto numeric = static_cast<ChannelNumber>(unsigned(family->first_number) + format - family->first);
const auto handle = resource(i, s, (i.b >> 16 & 31) * 4, ComputeViewKind::raw_vector_srv, 4);
// The byte-address rewrite of a descriptor (stride cleared in word 1) is read as the same raw view, as for MUBUF.
const unsigned base = (i.b >> 16 & 31) * 4;
const bool window = s.at(base + 1).type == Symbol::Type::zero_stride_word;
const auto kind = window ? ComputeViewKind::byte_window_srv : ComputeViewKind::raw_vector_srv;
const auto handle = resource(i, s, base, kind, 4, nullptr, window);
const unsigned scalar_offset = i.b >> 24;
auto addr = to_string(i.a & 4095);
if (scalar_offset != 125 && scalar_offset != 128)
Expand Down
1 change: 1 addition & 0 deletions src/gfx1013_compute_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct ComputeViewBinding {
unsigned image_dimension = 1; // ISA dimension field; 1 denotes Texture2D.
enum class ScalarTable { unknown, reflected_cbv, declared_cbv, srv };
ScalarTable scalar_table = ScalarTable::unknown;
bool requires_identity_dst_sel = false;
};
bool apply_reflected_table_use(ComputeViewBinding &binding, const GuestShaderStage &stage,
std::optional<unsigned> packed_sgpr = {});
Expand Down
7 changes: 6 additions & 1 deletion src/gfx1013_direct_compute.inl
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ struct DirectCompute {
}
std::set<std::pair<unsigned,unsigned>> read_write_raw_views;
string resource(const Inst &i, const State &s, unsigned base, ComputeViewKind kind, unsigned bytes,
unsigned *bound_register = nullptr) {
unsigned *bound_register = nullptr, bool requires_identity_dst_sel = false) {
const auto &symbol = s.at(base);
const bool indexed = symbol.type == Symbol::Type::indexed_descriptor;
if (indexed && symbol.value == compute_resource_heap)
Expand All @@ -372,6 +372,8 @@ struct DirectCompute {
(kind == ComputeViewKind::buffer_srv || kind == ComputeViewKind::raw_vector_srv ||
kind == ComputeViewKind::byte_window_srv) &&
read_write_raw_views.count({symbol.value, symbol.offset})) {
if (requires_identity_dst_sel)
refuse(i.pc, "a writable MTBUF byte window has no verified view contract");
// Both instructions read the same descriptor table entry. A
// second, SRV binding would conflict with its writable resource state.
kind = ComputeViewKind::raw_buffer_uav;
Expand All @@ -384,6 +386,9 @@ struct DirectCompute {
});
if (it == analysis.result.bindings.end())
throw std::logic_error("missing direct binding");
if (requires_identity_dst_sel)
for (unsigned j = 0; j < count; ++j)
it[j].requires_identity_dst_sel = true;
if (bound_register) *bound_register = it->shader_register;
const bool raw = kind == ComputeViewKind::raw_buffer_uav || kind == ComputeViewKind::buffer_srv ||
kind == ComputeViewKind::raw_vector_srv || kind == ComputeViewKind::byte_window_srv ||
Expand Down
9 changes: 8 additions & 1 deletion src/startup_stubs/d3d12_compute_dispatch.inl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct ComputeTranslation {
std::uint32_t at = 0, times = 0;
Source source = root_constant;
D3D12_UAV_DIMENSION uav_dimension = D3D12_UAV_DIMENSION_UNKNOWN;
bool requires_identity_dst_sel = false;
bool root = false;
bool atomic_uint_texture = false;
unsigned channels = 4;
Expand Down Expand Up @@ -193,6 +194,11 @@ const char* load_compute_translation(ComputeTranslation& tr)
tr.uds.push_back({a, 0, false, false, -1, 0, 0, 0, source()});
else if (std::sscanf(line.c_str(), "srv %u buf table %d %d%n", &i, &a, &b, &used) == 3 && whole() && i == tr.srvs.size())
tr.srvs.push_back({a, b});
else if (std::sscanf(line.c_str(), "srv %u buf table %d %d identity_dst_sel%n", &i, &a, &b, &used) == 3 && whole() &&
i == tr.srvs.size()) {
tr.srvs.push_back({a, b});
tr.srvs.back().requires_identity_dst_sel = true;
}
else if (std::sscanf(line.c_str(), "srv %u buf root %d%n", &i, &a, &used) == 2 && whole() && a >= 0 &&
i == tr.srvs.size()) {
tr.srvs.push_back({a, 0});
Expand Down Expand Up @@ -646,7 +652,8 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch&
}
if (!output) {
// Each condition of a complete GPU-backed buffer range has its own reason.
const IndirectBufferView view = indirect_table_buffer(self, words, false, &reason, 16u << 20, true);
const IndirectBufferView view = indirect_table_buffer(self, words, false, &reason, 16u << 20, true,
slot.requires_identity_dst_sel);
if (view.source == 1) InterlockedIncrement(&compute_inputs_gpu_copied);
if (view.source == 2) {
InterlockedIncrement(&compute_inputs_snapshot);
Expand Down
7 changes: 6 additions & 1 deletion src/startup_stubs/d3d12_draw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -2362,7 +2362,7 @@ bool title_input_snapshot_enabled()
IndirectBufferView indirect_table_buffer(Wrapper* self, const std::uint32_t* words, bool allow_address_alias = false,
const char** why = nullptr,
u64 limit = u64{4} << D3D12_REQ_BUFFER_RESOURCE_TEXEL_COUNT_2_TO_EXP,
bool allow_title_snapshot = false)
bool allow_title_snapshot = false, bool requires_identity_dst_sel = false)
{
const auto refuse = [why](const char* reason) {
if (why) *why = reason;
Expand All @@ -2379,13 +2379,16 @@ IndirectBufferView indirect_table_buffer(Wrapper* self, const std::uint32_t* wor
if (words[1] < view_records().size()) record = view_records()[words[1]];
ReleaseSRWLockShared(&note_lock);
if (record.slot == 17 && record.desc_bytes >= 12) {
if (requires_identity_dst_sel) return refuse("an MTBUF byte window requires a buffer SRV");
UINT size = 0;
std::memcpy(&address, record.desc, 8);
std::memcpy(&size, record.desc + 8, 4);
bytes = size;
} else if (record.slot == 18 && record.desc_bytes >= 40) {
D3D12_SHADER_RESOURCE_VIEW_DESC view{};
std::memcpy(&view, record.desc, 40);
if (requires_identity_dst_sel && view.Shader4ComponentMapping != D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING)
return refuse("an MTBUF byte window requires identity component mapping");
owner = as_wrapper(reinterpret_cast<const void*>(record.resource));
if (!owner || owner->own().kind != resource_kind || !owner->own().real ||
view.ViewDimension != D3D12_SRV_DIMENSION_BUFFER) return refuse("an input view token is not a buffer view of a desktop resource");
Expand Down Expand Up @@ -2416,6 +2419,8 @@ IndirectBufferView indirect_table_buffer(Wrapper* self, const std::uint32_t* wor
return refuse("an input view token is not a buffer view of a desktop resource");
}
} else {
if (requires_identity_dst_sel && (words[3] & 0xfffu) != 0xfacu)
return refuse("an MTBUF byte window requires identity DST_SEL");
address = words[0] | (u64{words[1] & 0xffff} << 32);
stride = (words[1] >> 16) & 0x3fff;
bytes = u64{stride ? stride : 1} * words[2];
Expand Down
10 changes: 10 additions & 0 deletions tests/cmake/startup_compute_mtbuf_window.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if(TARGET compile_dxil AND TARGET startup_stream_consumer AND TARGET offscreen_check AND EXISTS "${INTAKE_PYTHON}"
AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll")
foreach(adapter IN ITEMS warp hardware)
add_test(NAME startup_compute_mtbuf_window_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_mtbuf_window_check.py"
"$<TARGET_FILE:compile_dxil>" "$<TARGET_FILE:startup_stream_consumer>" "$<TARGET_FILE:offscreen_check>"
"${DXC_BIN_DIR}" ${adapter})
set_tests_properties(startup_compute_mtbuf_window_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
endforeach()
endif()
17 changes: 17 additions & 0 deletions tests/native_direct_container_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,23 @@ def atomic_program(instructions):
broken[10] = 0xbf800000 # Leave NUM_RECORDS in elements instead of bytes.
check("byte-count-missing-product", "gfx1013-container-ps",
patched_pixel(len(broken), broken, table=True), "non-contiguous resource descriptor")
# The same rewrite in compute, read by MTBUF loads through s[28:31] (v_mov_b32 v5, 0 as the offset):
# tbuffer_load_format_x v8, v5, s[28:31], 0 format:[BUF_FMT_32_UINT] offen and
# tbuffer_load_format_xyzw v[8:11], v5, s[28:31], 0 format:[BUF_FMT_8_8_8_8_UNORM] offen.
tbuffer_view = [*byte_view[:13], 0x7e0a0280]
check("compute-tbuffer-byte-window", cs, compute(words(*tbuffer_view, 0xe8a01000, 0x80070805, end), table=True))
check("compute-tbuffer-byte-window-unorm", cs,
compute(words(*tbuffer_view, 0xe9c31000, 0x80070805, end), table=True))
# Over-acceptance control only: without the byte-count product the window fields do not match.
tbuffer_broken = tbuffer_view.copy()
tbuffer_broken[10] = 0xbf800000
check("compute-tbuffer-byte-count-missing-product", cs,
compute(words(*tbuffer_broken, 0xe8a01000, 0x80070805, end), table=True),
"non-contiguous resource descriptor")
# A writable access and the MTBUF read use the same table descriptor; the read has no verified view contract.
check("compute-tbuffer-writable-byte-window", cs,
compute(words(*tbuffer_view, 0xe0701000, 0x80070805, 0xe8a01000, 0x80070805, end), table=True),
"a writable MTBUF byte window has no verified view contract")
# Convert v11 to a half in the high word of v6, retaining v6.low.
# Widen the selected high word back from a scalar source into v7.
halves = [0x7e0c02ff, 0xa5a53600, 0x7e1602ff, 0x3f801000, 0x7e0c14f9, 0x06150b,
Expand Down
Loading
Loading