diff --git a/src/gfx1013_compute_native.cpp b/src/gfx1013_compute_native.cpp index 44c8491a31..4b8cf017a1 100644 --- a/src/gfx1013_compute_native.cpp +++ b/src/gfx1013_compute_native.cpp @@ -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) { @@ -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") diff --git a/src/gfx1013_direct_compute.inl b/src/gfx1013_direct_compute.inl index e4f095d4cc..bb4c9bfa62 100644 --- a/src/gfx1013_direct_compute.inl +++ b/src/gfx1013_direct_compute.inl @@ -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> 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) { diff --git a/tests/startup_compute_dispatch_native_check.py b/tests/startup_compute_dispatch_native_check.py index 2a0809e72a..d622bc9858 100644 --- a/tests/startup_compute_dispatch_native_check.py +++ b/tests/startup_compute_dispatch_native_check.py @@ -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})') diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index 47db85b485..675646b3ed 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -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; @@ -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(value); }; void* placed[2]{}; UINT descriptors[2][4]{}; @@ -318,7 +320,7 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin } else { std::memcpy(reinterpret_cast(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(cpu + sizeof(descriptors[0])), 0, sizeof(descriptors[1])); std::memcpy(reinterpret_cast(cpu + 32), descriptors[1], sizeof(descriptors[1])); }