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
10 changes: 9 additions & 1 deletion src/gfx1013_compute_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,8 @@ struct Emit {
refuse(i.pc, "a sampler heap descriptor is read as a resource");
const bool byte_window = kind == ComputeViewKind::byte_window_srv ||
(kind == ComputeViewKind::raw_buffer_uav && width == 4 &&
(i.name == "buffer_store_raw" ||
(i.name == "buffer_store_raw" || i.name == "buffer_load_dword" ||
i.enc == Encoding::Smem ||
(i.name.substr(0, 14) == "buffer_atomic_" && !(i.a & 0x2000u))) &&
state[base + 1].type == Symbol::Type::zero_stride_word);
for (unsigned j = 1; j < width; ++j) {
Expand Down Expand Up @@ -1583,6 +1584,13 @@ static NativeComputeShader translate_program(const ComputeRequest &request, unsi
compiler.wave64 = wave64;
compiler.heap_view = heap_view;
compiler.heap_window = heap_window;
for (size_t i = 0; i < program.code.size(); ++i) {
const auto& inst = program.code[i];
if (!program.reached[i] || inst.enc != Encoding::Mubuf || inst.name != "buffer_store_raw") continue;
const auto& symbol = program.before[i].at(((inst.b >> 16) & 31) * 4);
if (symbol.type == Symbol::Type::descriptor)
compiler.read_write_raw_views.emplace(symbol.value, symbol.offset);
}
if (threads % (wave64 ? 64 : 32))
for (const auto &i : program.code)
if (i.name == "v_readlane_b32" || i.name == "v_writelane_b32")
Expand Down
9 changes: 9 additions & 0 deletions src/gfx1013_direct_compute.inl
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,21 @@ struct DirectCompute {
ir.features |= 16 | 0x40000000;
return ir.heap_handle(ir.binary("add", read(base), to_string(symbol.offset / 32)), 11, 0);
}
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) {
const auto &symbol = s.at(base);
const bool indexed = symbol.type == Symbol::Type::indexed_descriptor;
if (indexed && symbol.value == compute_resource_heap)
return heap_resource(i, s, base, kind, bytes);
if (!indexed && symbol.type == Symbol::Type::descriptor &&
(kind == ComputeViewKind::buffer_srv || kind == ComputeViewKind::raw_vector_srv ||
kind == ComputeViewKind::byte_window_srv) &&
read_write_raw_views.count({symbol.value, symbol.offset})) {
// Both instructions read the same descriptor table entry. A
// second, SRV binding would conflict with its writable resource state.
kind = ComputeViewKind::raw_buffer_uav;
}
const unsigned count = indexed ? 1 + symbol.index_mask / 32 : 1;
analysis.binding(i, s, base, 4, kind, bytes);
auto it = std::find_if(analysis.result.bindings.begin(), analysis.result.bindings.end(), [&](const auto &b) {
Expand Down
9 changes: 9 additions & 0 deletions tests/startup_compute_dispatch_native_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ def main(consumer, dxc_dir, adapter):
f'native translation is refused by that name with every word untouched; {controls}; the first '
f'program matches all {C.WORDS} words through its published translation')
sys.exit(77)
shared_loads = LOADS_X4[:4] + bytes.fromhex('200000fa') + LOADS_X4[8:]
(directory / 'program').write_bytes(case_a.replace(LOAD_X8, shared_loads))
got, result = dispatch(directory, consumer, dict(env, X2W_NATIVE_SHADERS_ONLY='1'), 'dispatch-read-write-uav')
expected[288:] = [C.input_word(i) for i in range(288, C.WORDS)]
assert not mismatch(got, expected, result), mismatch(got, expected, result)
assert lines(result, '0 inputs, 1 outputs'), result.stderr[-3000:]
errors = [line for line in lines(result, 'x2w-d3d12-debug ') if ' sev=0 ' in line or ' sev=1 ' in line]
assert not errors, errors[0]
print('shared guest UAV: in-place reads and writes matched with untouched tail')
print(f'startup_compute_dispatch_native: PASS on {adapter} (all {C.WORDS} words match after the in-process '
f'translation from an empty cache, and again with a published translation in the cache; the plain table '
f'layout is refused when bound; {controls})')
Expand Down
4 changes: 3 additions & 1 deletion tests/startup_stream_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ static void* make_committed(void* device, D3D12_HEAP_TYPE type, const D3D12_RESO
static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::string& mode)
{
constexpr UINT words = 320;
const bool shared_uav = mode == "dispatch-read-write-uav";
const bool indirect = mode.rfind("dispatch-indirect-", 0) == 0;
const bool root_srv = mode.rfind("dispatch-root-srv", 0) == 0;
const UINT groups = mode == "dispatch-indirect-zero" ? 0u : mode == "dispatch-indirect-2" ? 2u : 5u;
Expand All @@ -241,6 +242,7 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin
!from_file("X2W_TEST_DISPATCH_FIELDS", fields, sizeof(fields))) return 2;
UINT input[words];
std::memcpy(input, buffers[0], sizeof(input));
if (shared_uav) std::memcpy(buffers[1], input, sizeof(input));
const auto word = [](const void* value) { return reinterpret_cast<StreamWord>(value); };
void* placed[2]{};
UINT descriptors[2][4]{};
Expand Down Expand Up @@ -318,7 +320,7 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin
} else {
std::memcpy(reinterpret_cast<void*>(cpu), descriptors, sizeof(descriptors));
}
if (mode == "dispatch-records32") { // the output's descriptor at table byte 32, none at byte 16
if (mode == "dispatch-records32" || shared_uav) { // the output's descriptor at table byte 32, none at byte 16
std::memset(reinterpret_cast<void*>(cpu + sizeof(descriptors[0])), 0, sizeof(descriptors[1]));
std::memcpy(reinterpret_cast<void*>(cpu + 32), descriptors[1], sizeof(descriptors[1]));
}
Expand Down
Loading