diff --git a/docs/experiments.md b/docs/experiments.md index 13e4d28d40..444607997d 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -37,6 +37,8 @@ BOUND_CTRL to unusable sources. [Experiment and reproduction commands](experimen Lane reads may refill `vcc_lo` and, in wave32, `vcc_hi` as ordinary scalar data. [Experiment and reproduction commands](experiments/native-lane-access-compute.md) +[Descriptor lane spill experiment](experiments/native-lane-spill-descriptor.md) + ## 64-bit scalar operations in direct compute `s_bfm_b64`, `s_cselect_b64` and `s_not_b64` lower to two scalar words. diff --git a/docs/experiments/native-lane-spill-descriptor.md b/docs/experiments/native-lane-spill-descriptor.md new file mode 100644 index 0000000000..b8688eca35 --- /dev/null +++ b/docs/experiments/native-lane-spill-descriptor.md @@ -0,0 +1,35 @@ +# Descriptor lane spills in direct compute DXIL + +The direct C++ path can carry an immediate table descriptor, a table +pointer word, a root address word or an unbound value through a constant +guest VGPR lane. An unbound value refilled is still unbound and is refused +where it is used. +The CFG tracks the identity per VGPR and guest lane. A symbolic spill or +refill emits no DXIL. A refilled descriptor still has to pass the usual +binding checks. A numeric write clears only its lane's identity. Any +other write to a VGPR holding symbolic lanes is refused. +Joins require the same identity on each path. If any path has a symbol +but the identity differs, the refill is refused. + +Numeric lane operations use the existing DXIL lowering. In a split +guest wave64, that lowering selects the physical lane and exchanges +values between the wave32 halves as needed. Symbolic slots use the guest +lane before the physical mapping. Indexed descriptors that carry a +runtime index remain outside this experiment. + +The source-built fixture spills four SRV descriptor words into lanes +0 through 3 and two numeric words into lanes 4 and 5, then clobbers the +descriptor SGPRs. It refills the six words and stores the loaded SRV +value and both numeric values for every lane. The CPU reference covers +192 written words across two wave32 workgroups and 1,872 guard and +unwritten words. Compile controls cover VGPR and SGPR lane selectors, +a VALU overwrite followed by descriptor refill, a conflicting CFG +join, and a direct VALU read of a VGPR with symbolic lanes. + +```powershell +cmake --build --preset dev --target compile_dxil native_store_replay +ctest --preset dev --no-tests=error -R '^native_lane_spill_descriptor_(warp|hardware)$' +``` + +The fixture is registered for Microsoft WARP and the default hardware +adapter. It requires shader model 6.6 and wave32 support. diff --git a/src/gfx1013_compute_native.cpp b/src/gfx1013_compute_native.cpp index 6513357d47..f0c894e72b 100644 --- a/src/gfx1013_compute_native.cpp +++ b/src/gfx1013_compute_native.cpp @@ -431,7 +431,82 @@ struct Symbol { bool operator==(const Symbol &r) const { return type == r.type && value == r.value && offset == r.offset && index_mask == r.index_mask && definition == r.definition; } }; -using State = std::array; +struct State { + std::array scalar{}; + // Encoded VGPR and guest lane. A join can lose the identity while + // retaining the fact that some path omitted the runtime lane write. + std::map, std::optional> lane_spills; + Symbol &operator[](unsigned n) { return scalar[n]; } + const Symbol &operator[](unsigned n) const { return scalar[n]; } + const Symbol &at(unsigned n) const { return scalar.at(n); } + size_t size() const { return scalar.size(); } + auto begin() { return scalar.begin(); } + auto end() { return scalar.end(); } + auto begin() const { return scalar.begin(); } + auto end() const { return scalar.end(); } + bool has_spill(unsigned reg) const { + const auto it = lane_spills.lower_bound({reg, 0}); + return it != lane_spills.end() && it->first.first == reg; + } + void clear_spills(unsigned reg, unsigned count = 1) { + lane_spills.erase(lane_spills.lower_bound({reg, 0}), lane_spills.lower_bound({reg + count, 0})); + } +}; +static std::optional constant32(const Inst &i, unsigned r) { + static constexpr Word floats[]{0x3f000000, 0xbf000000, 0x3f800000, 0xbf800000, 0x40000000, + 0xc0000000, 0x40800000, 0xc0800000, 0x3e22f983}; + if (r >= 128 && r <= 192) return r - 128; + if (r >= 193 && r <= 208) return Word(192) - r; + if (r >= 240 && r <= 248) return floats[r - 240]; + if (r == 255) return i.literal; + return {}; +} +static std::optional guest_spill_lane(const Inst &i, bool wave64) { + if (auto selector = constant32(i, i.src[1])) + return *selector & (wave64 ? 63 : 31); + return {}; +} +static bool identity_spill(const Symbol &s) { + // Indexed descriptors and their derived fields still use an SGPR's + // runtime index. Erasing a lane operation would lose that payload. + // An unbound value stays unbound after a refill, so it is refused at its use. + return !s.numeric() && + s.type != Symbol::Type::indexed_descriptor && !s.definition; +} +static void clear_vector_spills(const Inst &i, State &s) { + if (s.lane_spills.empty()) return; + switch (i.enc) { + case Encoding::Vop1: case Encoding::Vop2: case Encoding::Vop3: case Encoding::Mix: + if (i.dst >= 256 && i.name != "v_nop") { + const bool pair = i.name == "v_mad_u64_u32" || i.name == "v_mad_i64_i32" || i.name == "v_lshlrev_b64" || + i.name == "v_lshrrev_b64" || i.name == "v_ashrrev_i64"; + s.clear_spills(i.dst, pair ? 2 : 1); + if (i.name == "v_swap_b32") s.clear_spills(i.src[0]); + } + break; + case Encoding::Mubuf: + if (i.name == "buffer_load_dword") { + constexpr unsigned widths[]{1, 2, 4, 3}; + s.clear_spills(256 + i.dst, widths[i.op & 3]); + } else if (i.name == "buffer_load_format" || i.name.substr(0, 8) == "tbuffer_") + s.clear_spills(256 + i.dst, (i.op & 3) + 1); + else if (i.name == "global_load_dword" || + (i.name.substr(0, 14) == "buffer_atomic_" && (i.a & 0x4000))) + s.clear_spills(256 + i.dst); + break; + case Encoding::Image: + if (i.op != 8) { + unsigned count = 0; + for (unsigned mask = (i.a >> 8) & 15; mask; mask >>= 1) + count += mask & 1; + if (i.op == 68) count = 4; + if (i.b >> 31) count = (count + 1) / 2; + s.clear_spills(256 + i.dst, count); + } + break; + default: break; + } +} // FSSM root descriptors carry a guest address in two SGPRs. Preserve the // identity of each half through scalar moves and CFG joins (Victory resource.rs). void bind_root_address(State &state, const ShaderRootInput &input, unsigned limit) { @@ -486,12 +561,32 @@ static std::optional byte_descriptor_field(const Inst &i, const State &s return field(a,T::byte_oob); return {}; } -State transfer(const Inst &i, State s, bool wave64, bool graphics, bool heap_window = false) { +State transfer(const Inst &i, State s, bool wave64, bool graphics, bool heap_window, bool direct) { auto set = [&](unsigned n, Symbol v) { if (n >= s.size()) refuse(i.pc, "invalid SGPR"); s[n] = v; }; + if (direct && !graphics) { + if (i.name == "v_writelane_b32") { + if (auto lane = guest_spill_lane(i, wave64)) { + const auto key = std::make_pair(i.dst, *lane); + const auto value = source(i, i.src[0], s); + if (i.src[0] <= 105 && identity_spill(value)) + s.lane_spills[key] = value; + else + s.lane_spills.erase(key); + } + return s; + } + if (i.name == "v_readlane_b32") { + const auto lane = guest_spill_lane(i, wave64); + const auto slot = lane ? s.lane_spills.find({i.src[0], *lane}) : s.lane_spills.end(); + set(i.dst, slot != s.lane_spills.end() && slot->second ? *slot->second : Symbol{}); + return s; + } + clear_vector_spills(i, s); + } auto mask = carry_destination(i); const bool compared = graphics && i.enc == Encoding::Vopc && i.dst < 106 && i.name.substr(0,6) == "v_cmp_"; if (mask || compared) { @@ -696,14 +791,14 @@ Program parse(const string &code, unsigned entry, const State &initial, bool gra auto k = work.front(); work.pop_front(); auto &i = p.code[k]; - auto after = transfer(i, p.before[k], wave64, graphics, heap_window); + auto after = transfer(i, p.before[k], wave64, graphics, heap_window, graph); auto merge = [&](size_t t) { bool changed = !p.reached[t]; auto &in = p.before[t]; if (changed) { in = after; p.reached[t] = true; - } else + } else { for (unsigned n = 0; n < in.size(); ++n) if (!(in[n] == after[n])) { Symbol merged{}; @@ -714,6 +809,16 @@ Program parse(const string &code, unsigned entry, const State &initial, bool gra changed = true; } } + for (auto &[key, value] : in.lane_spills) { + const auto other = after.lane_spills.find(key); + if (value && (other == after.lane_spills.end() || !(other->second == value))) { + value.reset(); + changed = true; + } + } + for (const auto &slot : after.lane_spills) + changed |= in.lane_spills.emplace(slot.first, std::nullopt).second; + } if (changed) work.push_back(t); }; @@ -732,16 +837,10 @@ string reg(unsigned n) { return n >= 256 ? "v" + to_string(n - 256) : "s" + to_s string operand(const Inst &i, unsigned n) { if ((n <= 105) || n == 106 || n == 126 || n >= 256) return reg(n); - if (n >= 128 && n <= 208) - return hexword(n <= 192 ? n - 128 : 192u - n); if (n == 253) return "uint(scc)"; - if (n == 255) - return hexword(i.literal); - constexpr Word f[] = {0x3f000000, 0xbf000000, 0x3f800000, 0xbf800000, 0x40000000, - 0xc0000000, 0x40800000, 0xc0800000, 0x3e22f983}; - if (n >= 240 && n <= 248) - return hexword(f[n - 240]); + if (auto constant = constant32(i, n)) + return hexword(*constant); refuse(i.pc, "unsupported operand " + to_string(n)); } enum class AluType { Bits, Float, ToFloat }; diff --git a/src/gfx1013_direct_compute.inl b/src/gfx1013_direct_compute.inl index 7048ddf074..ab2af39305 100644 --- a/src/gfx1013_direct_compute.inl +++ b/src/gfx1013_direct_compute.inl @@ -1,18 +1,9 @@ // Lower the shared decoded CFG to DXIL operations. A scalar register holds one // 32-bit word per wave. Ordinary vector writes retain their old value on inactive lanes. struct DirectCompute { - static constexpr Word inline_float_words[]{0x3f000000, 0xbf000000, 0x3f800000, 0xbf800000, 0x40000000, - 0xc0000000, 0x40800000, 0xc0800000, 0x3e22f983}; - // The same nine constants as binary16, which an f16 operand reads instead of the f32 pattern. + // The nine inline float constants as binary16, which an f16 operand reads instead of the f32 pattern. static constexpr Word inline_half_words[]{0x3800, 0xb800, 0x3c00, 0xbc00, 0x4000, 0xc000, 0x4400, 0xc400, 0x3118}; - static std::optional constant32(const Inst &i, unsigned r) { - if (r >= 128 && r <= 192) return r - 128; - if (r >= 193 && r <= 208) return Word(192) - r; - if (r >= 240 && r <= 248) return inline_float_words[r - 240]; - if (r == 255) return i.literal; - return {}; - } static void validate_lane_shape(const Inst &i, unsigned threads, unsigned width) { const auto constant = constant32(i, i.src[1]); const auto remaining = threads % width; @@ -50,6 +41,8 @@ struct DirectCompute { std::map graphics_registers; string graphics_predicate; unsigned graphics_pc = 0; + const State *compute_state = nullptr; + unsigned compute_pc = 0; bool perspective_center_pair = false; bool exact_pixel_entry = false; bool helper_result_unobserved = false; @@ -72,7 +65,7 @@ struct DirectCompute { ir.setup << " " << name << " = alloca i32, align 4\n"; return name; } - string read(unsigned r) { + string read_storage(unsigned r) { if (graphics_input) { auto guarded = guarded_ij.find(r); if (guarded != guarded_ij.end()) @@ -89,7 +82,17 @@ struct DirectCompute { } return ir.value("load i32, i32* " + address(r) + ", align 4"); } + string read(unsigned r) { + if (compute_state && compute_state->has_spill(r)) + refuse(compute_pc, "symbolic VGPR lane read of " + reg(r)); + return read_storage(r); + } + bool lane_write = false; // v_writelane_b32 updates one lane of a VGPR that may hold symbolic lanes void write(unsigned r, const string &value) { + // A VGPR write the analysis did not model as clearing its symbolic lanes + // would let a later v_readlane_b32 return a stale identity. + if (compute_state && !lane_write && compute_state->has_spill(r)) + refuse(compute_pc, "write to a VGPR holding symbolic lanes: " + reg(r)); if (graphics_input) { guarded_ij.erase(r); graphics_registers[r] = value; @@ -123,7 +126,7 @@ struct DirectCompute { // subsequent implicit LOD or quad operation can inspect helpers. write(r, value); } else - write(r, select(graphics_input ? graphics_predicate : active(), value, read(r))); + write(r, select(graphics_input ? graphics_predicate : active(), value, read_storage(r))); } string operand32(const Inst &i, unsigned n) { if (graphics_input && n == 106) @@ -2159,19 +2162,37 @@ struct DirectCompute { refuse(i.pc, "lane read/write register operand"); const unsigned width = wave64 ? 64 : 32; const unsigned selector = i.src[1]; + const auto guest = guest_spill_lane(i, wave64); + const unsigned vector = reading ? i.src[0] : i.dst; + if (guest && reading) { + const auto slot = state.lane_spills.find({vector, *guest}); + if (slot != state.lane_spills.end()) { + if (!slot->second) + refuse(i.pc, "symbolic VGPR lane read has conflicting incoming values"); + if (i.dst > 105) + refuse(i.pc, "symbolic VGPR lane read needs an ordinary SGPR destination"); + return; // Transfer associated the destination SGPR with this identity. + } + } + if (!reading && i.src[0] <= 105 && identity_spill(state[i.src[0]])) { + if (!guest) + refuse(i.pc, "symbolic VGPR lane write needs a constant lane"); + return; + } string selected; if (selector <= 105 || (!wave64 && selector == 107)) { + if (state.has_spill(vector)) + refuse(i.pc, "symbolic VGPR lane read or write needs a constant lane"); selected = ir.binary("and", val(1), to_string(width - 1)); } else { - const auto constant = constant32(i, selector); - if (!constant) + if (!guest) refuse(i.pc, "lane read/write needs a constant or SGPR lane"); - selected = to_string(*constant & (width - 1)); + selected = to_string(*guest); } if (reading) { const auto physical = wave64 ? ir.binary("and", selected, "31") : selected; auto value = ir.invoke("i32", "waveReadLaneAt.i32", 117, - {{"i32", val(0)}, {"i32", physical}}, "nounwind"); + {{"i32", read_storage(vector)}, {"i32", physical}}, "nounwind"); if (wave64) { const auto halves = exchange_halves(value); value = select(cmp("uge", selected, "32"), halves[1], halves[0]); @@ -2180,7 +2201,9 @@ struct DirectCompute { } else { const auto guest_lane = wave64 ? ir.binary("or", lane, select(upper_half, "32", "0")) : lane; // The lane selector is the sole write predicate, independent of guest EXEC. - write(i.dst, select(cmp("eq", guest_lane, selected), val(0), read(i.dst))); + lane_write = true; + write(i.dst, select(cmp("eq", guest_lane, selected), val(0), read_storage(i.dst))); + lane_write = false; } return; } @@ -3152,6 +3175,8 @@ struct DirectCompute { } for (size_t k = 0; k < p.code.size(); ++k) { const auto &i = p.code[k]; + compute_pc = i.pc; + compute_state = &p.before[k]; if (labels.count(i.pc)) { if (k && p.code[k - 1].name != "s_endpgm" && !p.code[k - 1].branch()) ir.body << " br label %pc" << i.pc << "\n"; diff --git a/tests/cmake/native_lane_spill_descriptor.cmake b/tests/cmake/native_lane_spill_descriptor.cmake new file mode 100644 index 0000000000..113f84e2be --- /dev/null +++ b/tests/cmake/native_lane_spill_descriptor.cmake @@ -0,0 +1,9 @@ +if(TARGET compile_dxil AND TARGET native_store_replay AND + EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + foreach(adapter IN ITEMS warp hardware) + add_test(NAME native_lane_spill_descriptor_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/native_lane_spill_descriptor_check.py" "$" + "$" "${DXC_BIN_DIR}" "${adapter}") + set_tests_properties(native_lane_spill_descriptor_${adapter} PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60) + endforeach() +endif() diff --git a/tests/native_lane_spill_descriptor_check.py b/tests/native_lane_spill_descriptor_check.py new file mode 100644 index 0000000000..b90cbc5ab1 --- /dev/null +++ b/tests/native_lane_spill_descriptor_check.py @@ -0,0 +1,105 @@ +"""Exercise symbolic descriptor spills and numeric spills in the same VGPR.""" +from pathlib import Path +import struct +import subprocess +import sys +import tempfile + +from native_compute_clear_check import write_request +from native_lane_access_check import readlane, vop2, writelane +from native_scalar_lds_check import scalar, sop1, vmove + + +LAUNCH = struct.pack("<7I", 0, 0, 0, 32 | 1 << 16, 1, 0, 0x8c) +SPILL = 1 +ROOT = "DescriptorTable(SRV(t0,numDescriptors=8)),DescriptorTable(UAV(u0,numDescriptors=8))" + + +def load_descriptor(dst, table_pair, byte_offset): + return [0xf4080000 | dst << 6 | table_pair // 2, 0xfa000000 | byte_offset] + + +def spill_descriptor(first): + return [word for lane in range(4) for word in writelane(SPILL, first + lane, 128 + lane)] + + +def program(control=""): + # s20:21 and s22:23 are the table pointers. s6 is the workgroup ID. + words = [sop1(3, 20, 4), sop1(3, 21, 128), sop1(3, 22, 5), sop1(3, 23, 128), + *load_descriptor(32, 20, 32), *load_descriptor(36, 22, 32), 0xbf8cc07f, + vmove(SPILL, 128), scalar(0x1e, 7, 6, 137), + vop2(0x1a, 8, 132, 0), vop2(0x25, 8, 7, 8), vop2(0x1a, 2, 130, 0)] + if control == "join": + left, right = spill_descriptor(32), spill_descriptor(44) + words += [*load_descriptor(44, 20, 64), 0xbf8cc07f, + 0xbf840000 | (len(left) + 1), *left, 0xbf820000 | len(right), *right] + else: + words += spill_descriptor(32) + words += [*writelane(SPILL, 139, 132), *writelane(SPILL, 150, 133)] + words += [sop1(3, reg, 128) for reg in range(32, 36)] + if control == "overwrite": + words += [vmove(SPILL, 128)] + if control == "valu": + words += [vmove(3, 256 + SPILL)] + if control == "sgpr_selector": + words += [sop1(3, 10, 128), *readlane(32, SPILL, 10)] + for lane in range(4): + selector = 256 + 2 if control == "vgpr_selector" and lane == 0 else 128 + lane + words += readlane(32 + lane, SPILL, selector) + words += [*readlane(10, SPILL, 132), *readlane(11, SPILL, 133), + 0xe0301000, 0x80080902, 0xbf8c0f70, vmove(10, 10), vmove(11, 11)] + for slot, vgpr in enumerate((9, 10, 11)): + words += [0xe0701000 | 4 * slot, 0x80090008 | vgpr << 8] + return words + [0xbf810000] + + +def reference(): + source = [0x7fff8000, 0x40008001, 0x007fff81, 0xfc003c00, 0x0001bc00, 0x42987ec5] + expected = [0x69696969] * 2064 + for group in range(2): + for lane in range(32): + base = 8 + 4 * (32 * group + lane) + expected[base:base + 3] = [source[lane % len(source)], 11, 22] + return expected + + +def main(cli, replay, sdk, adapter): + with tempfile.TemporaryDirectory() as directory: + work = Path(directory) + source, root_file = work / "root.hlsl", work / "root.bin" + source.write_text(f'#define SIG "{ROOT}"') + subprocess.run([Path(sdk) / "dxc.exe", "-T", "rootsig_1_1", "-E", "SIG", + "-Fo", root_file, source], check=True) + root = root_file.read_bytes() + cache = work / "cache" + controls = { + "vgpr_selector": "lane read/write needs a constant or SGPR lane", + "sgpr_selector": "needs a constant lane", + "overwrite": "write to a VGPR holding symbolic lanes", + "join": "symbolic VGPR lane read has conflicting incoming values", + "valu": "symbolic VGPR lane read of v1", + } + for control, diagnostic in controls.items(): + marker = write_request(work, program(control), root, LAUNCH) + dest = work / f"{control}.cso" + run = subprocess.run([cli, sdk, cache, "gfx1013-direct-cs@0", marker, dest], + capture_output=True, text=True) + assert run.returncode and diagnostic in run.stdout + run.stderr, (control, run.stdout, run.stderr) + assert not dest.exists(), control + + marker = write_request(work, program(), root, LAUNCH) + dest = work / "readback.bin" + mode = "--direct-warp" if adapter == "warp" else "--direct" + run = subprocess.run([replay, sdk, marker, cache, "0", dest, mode]) + if run.returncode == 77: + return 77 + run.check_returncode() + actual = struct.unpack("<2064I", dest.read_bytes()) + mismatches = [(i, a, e) for i, (a, e) in enumerate(zip(actual, reference())) if a != e] + assert not mismatches, mismatches[:12] + print("Two workgroups matched 192 descriptor-spill and numeric-spill words and all guards.") + return 0 + + +if __name__ == "__main__": + sys.exit(main(*sys.argv[1:])) diff --git a/tests/native_store_replay.cpp b/tests/native_store_replay.cpp index b124f77be9..1c2250dae6 100644 --- a/tests/native_store_replay.cpp +++ b/tests/native_store_replay.cpp @@ -5,8 +5,10 @@ #include #include #include +#include #include #include +#include #include using Microsoft::WRL::ComPtr; @@ -62,27 +64,44 @@ void report_adapter(ID3D12Device* device) { int wmain(int argc, wchar_t **argv) { if (argc != 6 && argc != 7) return 2; try { + const auto mode = argc == 7 ? std::wstring_view(argv[6]) : std::wstring_view{}; + const bool warp = mode == L"--direct-warp"; + ComPtr adapter; + if (warp) { + ComPtr factory; + check(CreateDXGIFactory1(IID_PPV_ARGS(&factory)), "DXGI factory"); + const auto warp_hr = factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter)); + if (warp_hr == DXGI_ERROR_NOT_FOUND || warp_hr == DXGI_ERROR_UNSUPPORTED) return 77; + check(warp_hr, "WARP adapter"); + } ComPtr device; - if (GetEnvironmentVariableW(L"XBOX2WINDOWS_ADAPTER", nullptr, 0)) { - bool unmatched = false; - device = create_device(false, unmatched, [](IUnknown* adapter, REFIID iid, void** result) { - return D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_12_0, iid, result); - }, stderr); - if (!device) { - if (!unmatched) - std::fputs("Unable to enumerate D3D12 hardware adapters\n", stderr); - return 2; - } - } else { - const auto device_hr = D3D12CreateDevice(nullptr,D3D_FEATURE_LEVEL_12_0,IID_PPV_ARGS(&device)); + if (warp) { + // --direct-warp: the WARP adapter chosen above. + const auto device_hr = D3D12CreateDevice(adapter.Get(),D3D_FEATURE_LEVEL_12_0,IID_PPV_ARGS(&device)); if (device_hr == DXGI_ERROR_UNSUPPORTED) return 77; check(device_hr, "device"); + } else { + if (GetEnvironmentVariableW(L"XBOX2WINDOWS_ADAPTER", nullptr, 0)) { + bool unmatched = false; + device = create_device(false, unmatched, [](IUnknown* adapter, REFIID iid, void** result) { + return D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_12_0, iid, result); + }, stderr); + if (!device) { + if (!unmatched) + std::fputs("Unable to enumerate D3D12 hardware adapters\n", stderr); + return 2; + } + } else { + const auto device_hr = D3D12CreateDevice(nullptr,D3D_FEATURE_LEVEL_12_0,IID_PPV_ARGS(&device)); + if (device_hr == DXGI_ERROR_UNSUPPORTED) return 77; + check(device_hr, "device"); + } + report_adapter(device.Get()); } - report_adapter(device.Get()); ShaderDxilCompiler compiler(argv[1]); fs::path marker=argv[2], dest=argv[5]; - const bool null_array = argc == 7 && std::wstring_view(argv[6]) == L"--direct-null-srv"; - const bool direct = null_array || (argc == 7 && std::wstring_view(argv[6]) == L"--direct"); + const bool null_array = mode == L"--direct-null-srv"; + const bool direct = null_array || warp || mode == L"--direct"; if (direct) { D3D12_FEATURE_DATA_SHADER_MODEL model{D3D_SHADER_MODEL_6_6}; D3D12_FEATURE_DATA_D3D12_OPTIONS1 waves{};