diff --git a/CMakeLists.txt b/CMakeLists.txt index 0992048972..cc2bc7534c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2048,6 +2048,7 @@ if(OFFSCREEN_AGILITY_620_DIR) endforeach() target_compile_definitions(offscreen_check PRIVATE OFFSCREEN_AGILITY_620) target_compile_definitions(startup_indirect_draw_indexed PRIVATE OFFSCREEN_AGILITY_620) + target_compile_definitions(startup_stream_consumer PRIVATE OFFSCREEN_AGILITY_620) endif() set(OFFSCREEN_WARP_DIR "" CACHE PATH "Directory containing an app-local x64 d3d10warp.dll (Microsoft.Direct3D.WARP)") if(OFFSCREEN_WARP_DIR) diff --git a/docs/experiments.md b/docs/experiments.md index d9ff3f351e..da3b132c31 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -17819,3 +17819,16 @@ ctest --preset dev --no-tests=error -R '^(pixel_aot_f16_cvt_norm_warp|pixel_aot_ Linux controls (including exhaustive verification against `fractions.Fraction` across all 63,488 finite binary16 values and single-instruction DPP16/DPP8 permutation-to-intrinsic checks pinning `QuadReadAcross{X,Y,Diagonal}` and `QuadReadLaneAt` lane order), `form_coverage_check.check_f16_cvt_norm_forms`, and Python mutation checks ran locally; Ubuntu LLVM 15 `pixel_aot_binary` round-trips run on PR CI, while `pixel_aot_f16_cvt_norm_{warp,hardware}` runs in `dev`/`release` presets and `main` CI (not `ctest --preset pr`). The draw harness compiles each fixture both optimized (`-denorm preserve`) and unoptimized (`-Od -denorm ftz`) so DXC retains the pure-`uint` conversion arithmetic in DXIL rather than constant-folding `plain_e32`/`plain_e64`/`sdwa` to immediate stores (note: because no binary32 float ops are emitted in `cvt_norm_{i16,u16}_f16`, `-denorm ftz` produces the same integer instructions as `-denorm preserve`). Independent Windows 11 (`26200.9974`, DXC `1.9.2602.17`, `debug_layer=unavailable`) measurements on `bd8f6f42` ([comment 1](https://github.com/R0Y00/Xbox2Windows/pull/2857#issuecomment-7196200555)) and `3100f363` ([comment 2](https://github.com/R0Y00/Xbox2Windows/pull/2857#issuecomment-7200844836)) passed `pixel_aot_f16_cvt_norm_hardware` (`AMD Radeon RX 9070 XT` `1002:7550`, driver `32.0.32029.2010`) and `pixel_aot_f16_cvt_norm_warp` with `max_absolute_error=0`, all 20 mutation draws mismatching, and DXIL disassembly confirming the `-Od` pass retains the `mul`/`lshr`/`shl` integer path. Scope limits: under `#839`'s static finite-proof contract (`half16_arith_source` / `half16_dpp_source`), operands are statically known per-lane uniform values, so device draw readbacks do not distinguish lane-routing changes on `dpp16`/`dpp8` (the permutation-to-intrinsic mapping is pinned statically in `check_f16_cvt_norm_controls`), mutation draws compile optimized rather than `-Od`, and the exhaustive 63,488-value check runs in Python rather than on-device. + + +## Native raw pixel buffer UAV binding + +The native graphics cache and draw stand-in support a single raw pixel UAV from a tracked descriptor table for a direct non-indexed draw without SRVs. The manifest records the table parameter and byte offset; the runtime requires an aligned raw R32_TYPELESS buffer view with valid bounds, UAV resource flags and compatible state, retains the resource, and orders consecutive UAV uses. Typed/structured views, mixed views and other draw paths are outside this slice (#3212, #3215; separate from #3094/#2981). + +```powershell +cmake --preset dev +cmake --build --preset dev --target startup_stream_consumer d3d12_xs_shim compile_dxil native_raw_buffer_view_check +ctest --preset dev --no-tests=error -j1 -R '^(native_pixel_raw_uav_(warp|hardware)|native_raw_buffer_view_controls)$' +``` + +Repeat with the release preset. The source-built shader pair goes through request publication, native DXIL, actual PSO/draw and GPU readback. The fixture checks full buffer and color-target contents, nonzero/short/end views, decoy and invalid descriptors; the validator also checks alignment and bounds. Local RX 7900 XT/WARP Debug and Release runs passed 54 cases (3,456 DWORDs and 1,728 pixels); the independent review over main 886a5a28 reproduced the same counts on RTX 4060 Laptop and WARP with the D3D12 debug layer enabled and zero errors. Actual title rendering impact is not established. diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index 5af615e14c..7b90da781a 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -856,6 +856,14 @@ std::optional format_graphics_runtime_manifest(const DirectGraphics const auto &b = bindings.views[bindings.srv_count + j]; if (b.root_parameter >= 16 || b.array_count != 1) return std::nullopt; + if (b.kind == ComputeViewKind::raw_buffer_uav) { + // First slice: one pixel UAV with no other resource views. Vertex stores, + // mixed views and aliases need their own runtime acceptance. + if (uav_count != 1 || bindings.srv_count || !pair.vertex.bindings.empty()) + return std::nullopt; + uav_lines << "uav " << j << " raw table " << b.root_parameter << ' ' << b.byte_offset << '\n'; + continue; + } if (b.kind != ComputeViewKind::texture_uav && b.kind != ComputeViewKind::half4_texture_uav) return std::nullopt; if (b.image_dimension != 1 && b.image_dimension != 5) diff --git a/src/native_buffer_store_view.h b/src/native_buffer_store_view.h index 592d611ed9..adda2c12a4 100644 --- a/src/native_buffer_store_view.h +++ b/src/native_buffer_store_view.h @@ -46,7 +46,8 @@ inline bool native_buffer_store_view(const ComputeViewBinding &binding, D3D12_UN if (view.Buffer.StructureByteStride) return false; UINT stride = binding.required_bytes; if (binding.kind == ComputeViewKind::raw_buffer_uav) { - if (view.Format != DXGI_FORMAT_R32_TYPELESS || view.Buffer.Flags != D3D12_BUFFER_UAV_FLAG_RAW) + if (view.Format != DXGI_FORMAT_R32_TYPELESS || view.Buffer.Flags != D3D12_BUFFER_UAV_FLAG_RAW || + view.Buffer.FirstElement % (D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT / 4)) return false; stride = 4; } else if (view.Buffer.Flags) { diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index 849c9bc687..6bdf121e42 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -13,12 +13,13 @@ // A pixel-stage image store (#1996 item F, #2742): tools/startup/gfx2hlsl.py writes 'uav N tex2d|tex2da table P O' // for the RWTexture2D or RWTexture2DArray at u, whose descriptor is at byte O of the title's -// root table P. Only that form is read; a view qualifier or a 'channels' field, as in the compute line, is refused. +// root table P. The native compiler also emits raw table views; a view qualifier or a 'channels' field, as in the compute line, is refused. // A trailing 'typedload' means the binding must also support a typed UAV load. The translator does not emit it // for a component store, which does not read the texel. struct PixelUav { unsigned index = 0, parameter = 0, offset = 0; bool array = false; + bool raw = false; bool needs_typed_load = false; }; constexpr unsigned pixel_uav_limit = 8; @@ -39,9 +40,10 @@ const char* read_pixel_uav_line(const std::string& line, PixelUav& out) }; if (w.size() < 2 || w[0] != "uav" || !number(w[1], out.index)) return "malformed view index"; if (w.size() < 3) return "missing view kind"; - if (w[2] == "raw" || w[2] == "table") return "buffer view (raw uav) is not bound"; - if (w[2] != "tex2d" && w[2] != "tex2da") return "only tex2d and tex2da views are bound"; + if (w[2] == "table") return "legacy untyped buffer view is not bound"; + if (w[2] != "tex2d" && w[2] != "tex2da" && w[2] != "raw") return "only tex2d, tex2da and raw views are bound"; out.array = w[2] == "tex2da"; + out.raw = w[2] == "raw"; if (w.size() > 3 && (w[3] == "float" || w[3] == "uint" || w[3] == "sint")) return "a view qualifier is not read for pixel stores"; if (w.size() < 4 || w[3] != "table") return "view source is not a table"; if (w.size() < 6) return "missing table parameter or offset"; @@ -49,6 +51,7 @@ const char* read_pixel_uav_line(const std::string& line, PixelUav& out) if (!number(w[4], out.parameter) || out.parameter >= 16) return "table parameter out of range"; if (!number(w[5], out.offset)) return "malformed table offset"; out.needs_typed_load = w.size() == 7; + if (out.raw && (out.needs_typed_load || out.offset % 32)) return "raw view requires an aligned table record without typedload"; return nullptr; } @@ -500,7 +503,7 @@ void load_translation(Translation& tr, const std::string& rtv_request = {}) load_pso_recipes(tr); if (previously_missing) InterlockedDecrement(&translation_missing); InterlockedIncrement(&translation_ready); - log("x2w-draw pipeline %016llx translated: %zu entry values, %zu resources, %zu writable textures, %zu static samplers, sampler_heap=%u", + log("x2w-draw pipeline %016llx translated: %zu entry values, %zu resources, %zu writable views, %zu static samplers, sampler_heap=%u", tr.key, tr.uds.size(), tr.srvs.size(), tr.uavs.size(), tr.samplers.statics.size(), tr.samplers.heap ? 1u : 0u); } @@ -2361,7 +2364,7 @@ struct PixelUavBinding { D3D12_UNORDERED_ACCESS_VIEW_DESC view{}; }; -// draw_lock held. The writable textures of tr (#1996 F), from the unordered-access views the title created at +// draw_lock held. The writable views of tr (#1996 F), from the unordered-access views the title created at // their table entries (pixel_uav_view). False, with the reason logged, when one cannot be bound as the program // expects: the draw is then not translated, and no other view is bound in its place. bool resolve_pixel_uavs(const Translation& tr, const Pass& pass, PixelUavBinding* out) @@ -2374,6 +2377,11 @@ bool resolve_pixel_uavs(const Translation& tr, const Pass& pass, PixelUavBinding }; for (std::size_t i = 0; i < tr.uavs.size(); ++i) { const PixelUav& uav = tr.uavs[i]; + if (uav.raw) { + const UINT stride = device_of(the_device)->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); + if (stride < 32 || uav.offset % stride) + return refuse(i, "raw UAV offset is not a descriptor boundary", uav.offset); + } const x2w_startup::ViewTable& table = pass.view_tables[uav.parameter]; if (!table.address) return refuse(i, "no descriptor table at the parameter", uav.parameter); const u64 entry = table.record(uav.offset, 32); @@ -2401,8 +2409,21 @@ bool resolve_pixel_uavs(const Translation& tr, const Pass& pass, PixelUavBinding title_view.Format = desktop_format(title_view.Format); } const D3D12_RESOURCE_DESC desc = texture->GetDesc(); - const char* reason = pixel_uav_view(device_of(the_device), desc, described ? &title_view : nullptr, - uav.array, out[i].view, uav.needs_typed_load); + const char* reason = nullptr; + if (uav.raw) { + const auto* info = resource_info(resource); + if (!(desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)) + return refuse(i, "resource lacks ALLOW_UNORDERED_ACCESS", record.resource); + const x2w::ComputeViewBinding binding{x2w::ComputeViewKind::raw_buffer_uav, uav.parameter, uav.offset, uav.index, 4}; + if (!described || record.counter || !info || info->initial_state != D3D12_RESOURCE_STATE_COMMON || + desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER || + !x2w::native_buffer_store_view(binding, title_view, desc.Width)) + return refuse(i, "incompatible raw buffer UAV", record.resource); + out[i].view = title_view; + } else { + reason = pixel_uav_view(device_of(the_device), desc, described ? &title_view : nullptr, + uav.array, out[i].view, uav.needs_typed_load); + } if (reason) { static LONG refused_view; if (first_calls(refused_view, 16)) @@ -2524,8 +2545,17 @@ bool draw_translated(Wrapper* self, bool indexed, UINT count, UINT instances, UI ReleaseSRWLockExclusive(&draw_lock); return false; } + const bool raw_uav = std::any_of(tr->uavs.begin(), tr->uavs.end(), [](const PixelUav& uav) { return uav.raw; }); + // ponytail: prove direct draws with one writable buffer first. SRVs and indexed + // draws can alias it through guest addresses, so do not guess their independence. + if (raw_uav && (indexed || indirect || tr->uavs.size() != 1 || !tr->srvs.empty())) { + log("x2w-draw %016llx raw UAV requires one writable view and a direct non-indexed draw without SRVs", tr->key); + ReleaseSRWLockExclusive(&draw_lock); + return false; + } PixelUavBinding uav_bindings[pixel_uav_limit]; - if (!resolve_pixel_uavs(*tr, pass, uav_bindings)) { + if (!resolve_pixel_uavs(*tr, pass, uav_bindings) || + (raw_uav && !retain_with_recording(self, x2w_startup::ComPtr(uav_bindings[0].resource)))) { ReleaseSRWLockExclusive(&draw_lock); return false; } @@ -2901,6 +2931,12 @@ bool draw_translated(Wrapper* self, bool indexed, UINT count, UINT instances, UI for (UINT j = 0; j < tr->uavs.size(); ++j) { const D3D12_CPU_DESCRIPTOR_HANDLE dest{draw_heap->GetCPUDescriptorHandleForHeapStart().ptr + SIZE_T{first + n + j} * draw_heap_increment}; require_state(self, uav_bindings[j].resource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + if (tr->uavs[j].raw) { + D3D12_RESOURCE_BARRIER barrier{}; + barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV; + barrier.UAV.pResource = uav_bindings[j].resource; + list->ResourceBarrier(1, &barrier); + } device_of(the_device)->CreateUnorderedAccessView(uav_bindings[j].resource, nullptr, &uav_bindings[j].view, dest); static LONG shown; if (first_calls(shown, 6)) { diff --git a/src/startup_stubs/d3d12_xs_device.cpp b/src/startup_stubs/d3d12_xs_device.cpp index d625696612..8f8b43a7fc 100644 --- a/src/startup_stubs/d3d12_xs_device.cpp +++ b/src/startup_stubs/d3d12_xs_device.cpp @@ -82,6 +82,7 @@ #include "state_block_blend.h" #include "title_heap_memory.h" #include "startup_stubs/xmem_section_buffer.h" +#include "native_buffer_store_view.h" #ifdef X2W_NATIVE_SHADERS // d3d12_xs_shim only: the C++ shader compiler (startup_stubs/d3d12_compute_dispatch.inl) #include "gfx1013_compute_native.h" #include "shader_dxil_compiler.h" diff --git a/tests/cmake/native_pixel_raw_uav.cmake b/tests/cmake/native_pixel_raw_uav.cmake new file mode 100644 index 0000000000..5783309cd4 --- /dev/null +++ b/tests/cmake/native_pixel_raw_uav.cmake @@ -0,0 +1,14 @@ +# Source-built native pixel buffer writes through the runtime-published graphics cache. +add_executable(native_raw_buffer_view_check tests/native_raw_buffer_view_check.cpp) +target_include_directories(native_raw_buffer_view_check PRIVATE src) +target_compile_features(native_raw_buffer_view_check PRIVATE cxx_std_17) +add_test(NAME native_raw_buffer_view_controls COMMAND native_raw_buffer_view_check) +if(TARGET compile_dxil AND TARGET startup_stream_consumer + AND EXISTS "${INTAKE_PYTHON}" AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + foreach(backend IN ITEMS warp hardware) + add_test(NAME native_pixel_raw_uav_${backend} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/native_pixel_raw_uav_check.py" + "$" "$" "${DXC_BIN_DIR}" ${backend}) + set_tests_properties(native_pixel_raw_uav_${backend} PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 120) + endforeach() +endif() diff --git a/tests/native_pixel_raw_uav_check.py b/tests/native_pixel_raw_uav_check.py new file mode 100644 index 0000000000..396dada5a9 --- /dev/null +++ b/tests/native_pixel_raw_uav_check.py @@ -0,0 +1,127 @@ +"""Source-built native pixel buffer store through the actual graphics cache and draw.""" +import os +import re +from pathlib import Path +import subprocess +import sys +import tempfile +from types import SimpleNamespace + +from native_direct_container_check import patched_pixel, signature +from native_startup_request_cache_check import stream_vertex_container +from startup_pixel_uav_check import run_case, DRAWN_LINE, CLEAR + +VALUE = 0x11223344 + + +def shader(stride): + vop1 = lambda op, dst, src: 0x7e000000 | dst << 17 | op << 9 | src + vop2 = lambda op, dst, src0, src1: op << 25 | dst << 17 | src1 << 9 | src0 + # Load the second guest descriptor. Pixel (x,y) writes DWORD 4*y+x + # relative to that view; the triangle covers x=0..3, y=0..3. + code = [0xbe810380, 0xf40c0200, 0xfa000000 | stride, + vop1(7, 0, 256), vop1(7, 1, 257), + vop2(0x1a, 1, 130, 1), vop2(0x1c, 0, 257, 0), + vop2(0x1a, 0, 130, 0), vop1(1, 4, 255), VALUE, + 0xe0701000, 0x80020400, vop1(1, 2, 242), vop1(1, 3, 128)] + return patched_pixel(len(code), code, table=True, input_address=3 << 8, + input_signature=((b"ISG1", signature(b"SV_Position", 1)),), + export=(0xf800180f, 0x02030302)) + + +def main(cli, consumer, sdk, backend, baseline=False): + with tempfile.TemporaryDirectory() as tmp: + folder = Path(tmp) + cache = folder / "cache" + cache.mkdir() + vs, ps, root = (folder / n for n in ("vs", "ps", "root")) + vs.write_bytes(stream_vertex_container()) + ps.write_bytes(shader(32)) + env = dict(os.environ, X2W_SHADER_CACHE=str(cache), X2W_D3D12_PERMISSIVE="1", + X2W_D3D12_LIST_NOOP="1", X2W_D3D12_RENDER="1", X2W_D3D12_DEVICE_NOOP="1", + X2W_TEST_PIXEL_UAV="raw-ok", X2W_TEST_DEBUG_LAYER="1", X2W_D3D12_DEBUG="0") + publish = dict(env) + publish.pop("X2W_TEST_DEBUG_LAYER") + if backend == "hardware": + publish["X2W_TEST_DISPATCH_HARDWARE"] = "1" + probe = subprocess.run([consumer, vs, ps, root], env=publish, capture_output=True, text=True) + if probe.returncode == 77: + sys.exit(77) + assert probe.returncode == 0, probe.stderr + stride = int(re.search(r"raw descriptor stride: (\d+)", probe.stdout)[1]) + assert stride >= 32 + print(f"guest descriptor stride: {stride}") + if stride != 32: + for entry in cache.iterdir(): + entry.unlink() + ps.write_bytes(shader(stride)) + subprocess.run([consumer, vs, ps, root], env=publish, check=True, capture_output=True) + line = f"uav 0 raw table 0 {stride}" + result = subprocess.run([cli, sdk, folder/"frontend", "gfx1013-container-pair", "--requests", cache, cache], + capture_output=True, text=True) + print(result.stdout, result.stderr, flush=True) + assert result.returncode == 0, result.stderr + stage, = cache.glob("*.ps.cso") + manifest = stage.with_name(stage.name.replace(".ps.cso", ".txt")) + if baseline: + assert not manifest.exists(), "baseline unexpectedly published raw UAV" + # Pair compilation succeeds on baseline; supply only the missing manifest + # to isolate the real runtime's independent refusal. + manifest.write_text("x2w-manifest 2\nud 1\nudsrc 0 rect\n" + line + "\nparams 0\ntargets 0\n") + text = manifest.read_text() + assert line in text.splitlines(), text + program = SimpleNamespace(directory=folder, cache=cache, consumer=consumer, vs=vs, ps=ps, root=root) + + def check(name, start=None, count=16, reason=None, decoy=False): + rc, out, log, pixels, words = run_case(program, name, env, backend) + if rc == 77: + print(out) + sys.exit(77) + assert rc == 0, (name, rc, out, log) + assert "device removed reason: 0x00000000" in out, out + if "debug layer: on" in out: + assert "debug layer: on, errors: 0" in out, out + expected = [0xabcd0000 + i for i in range(64)] + if start is not None: + base = (0 if decoy else 32) + start + expected[base:base+count] = [VALUE]*count + assert words == expected, (name, [(i, hex(a), hex(b)) for i,(a,b) in enumerate(zip(words,expected)) if a!=b], len(words), out, log) + assert (DRAWN_LINE in log) == (start is not None), (name, log) + if reason: + assert reason in log, (name, log) + red = bytes((255,0,0,255)) + assert pixels == ((red*4 + CLEAR*4)*4 if start is not None else CLEAR*32), (name, pixels.hex(), log) + print(name, "64 DWORDs + 32 pixels exact;", next((l for l in out.splitlines() if l.startswith("adapter=")), ""), next((l for l in out.splitlines() if l.startswith("debug layer:")), ""), flush=True) + + if baseline: + check("raw-ok", reason="buffer view (raw uav) is not bound") + return + check("raw-ok", 4) + check("raw-short", 4, 8) + check("raw-last", 16) + for name, reason in ( + ("raw-typed", "incompatible raw buffer UAV"), + ("raw-structured", "incompatible raw buffer UAV"), + ("raw-no-ua", "resource lacks ALLOW_UNORDERED_ACCESS"), + ("raw-missing", "table entry holds no view"), + ("raw-srv", "table entry is not an unordered-access view"), + ("raw-no-table", "no descriptor table at the parameter"), + ): + check(name, reason=reason) + # A different live descriptor at offset zero must change the written buffer. + manifest.write_text(text.replace(line, "uav 0 raw table 0 0")) + check("raw-ok.decoy", 4, decoy=True) + manifest.write_text(text.replace(line, "uav 0 raw table 0 4096")) + check("raw-ok.out-of-table", reason="table entry outside the bound table") + manifest.write_text(text.replace(line, "uav 0 raw table 0 1")) + check("raw-ok.unaligned", reason="raw view requires an aligned table record without typedload") + manifest.write_text(text.replace(line, line + " typedload")) + check("raw-ok.typedload", reason="raw view requires an aligned table record without typedload") + if stride > 32: + manifest.write_text(text.replace(line, "uav 0 raw table 0 32")) + check("raw-ok.wrong-stride", reason="raw UAV offset is not a descriptor boundary") + print(backend, f"{13 + (stride > 32)} raw UAV cases passed") + + +if __name__ == "__main__": + main(*sys.argv[1:5], baseline=len(sys.argv) == 6 and sys.argv[5] == "baseline") diff --git a/tests/native_raw_buffer_view_check.cpp b/tests/native_raw_buffer_view_check.cpp new file mode 100644 index 0000000000..a8238bb36c --- /dev/null +++ b/tests/native_raw_buffer_view_check.cpp @@ -0,0 +1,44 @@ +#include "native_buffer_store_view.h" +#include +#include + +int main() +{ + const x2w::ComputeViewBinding binding{x2w::ComputeViewKind::raw_buffer_uav, 0, 32, 0, 4}; + D3D12_UNORDERED_ACCESS_VIEW_DESC view{DXGI_FORMAT_R32_TYPELESS, D3D12_UAV_DIMENSION_BUFFER}; + view.Buffer.FirstElement = 4; + view.Buffer.NumElements = 16; + view.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; + const auto valid = [&](D3D12_UNORDERED_ACCESS_VIEW_DESC v, UINT64 bytes) { + return x2w::native_buffer_store_view(binding, v, bytes); + }; + if (!valid(view, 128) || valid(view, 79)) return 1; + auto last = view; + last.Buffer.FirstElement = 16; + if (!valid(last, 128) || valid(last, 127)) return 2; + auto invalid = view; + invalid.Buffer.FirstElement = 5; + if (valid(invalid, 128)) return 3; + invalid = view; + invalid.Buffer.FirstElement = (std::numeric_limits::max)() - 3; + if (valid(invalid, 128)) return 4; + invalid = view; + invalid.Buffer.NumElements = 0; + if (valid(invalid, 128)) return 5; + invalid.Buffer.NumElements = 29; + if (valid(invalid, 128)) return 6; + invalid = view; + invalid.Buffer.CounterOffsetInBytes = 4096; + if (valid(invalid, 128)) return 7; + invalid = view; + invalid.Buffer.StructureByteStride = 4; + if (valid(invalid, 128)) return 8; + invalid = view; + invalid.Format = DXGI_FORMAT_R32_UINT; + if (valid(invalid, 128)) return 9; + invalid = view; + invalid.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE; + if (valid(invalid, 128)) return 10; + std::puts("raw buffer view: aligned and exact-end accepted; truncated, unaligned, overflowing, empty, counter, stride, format and flags refused"); + return 0; +} diff --git a/tests/startup_pixel_uav.cpp b/tests/startup_pixel_uav.cpp index 92b887f801..4be914345c 100644 --- a/tests/startup_pixel_uav.cpp +++ b/tests/startup_pixel_uav.cpp @@ -39,7 +39,7 @@ std::uint32_t array_sentinel(UINT s, UINT m, UINT texel, UINT c) { return 0xd000 struct Fixture { ID3D12Device* desktop = nullptr; - bool array_mode = false; + bool array_mode = false, raw_mode = false; void* resources[textures]{}; ComPtr natives[textures]; void* array_resources[3]{}; @@ -236,6 +236,90 @@ bool copy_array(ID3D12Device* device, bool to_texture, std::vector* words) +{ + constexpr UINT bytes = 32 * 4; + auto staging = buffer(device, upload ? D3D12_HEAP_TYPE_UPLOAD : D3D12_HEAP_TYPE_READBACK, 2 * bytes, + upload ? D3D12_RESOURCE_STATE_GENERIC_READ : D3D12_RESOURCE_STATE_COPY_DEST); + Copier copier; + if (!staging || !copier.open(device)) return false; + std::uint32_t* data = nullptr; + if (upload) { + if (FAILED(staging->Map(0, nullptr, reinterpret_cast(&data)))) return false; + for (UINT i = 0; i < 64; ++i) data[i] = 0xabcd0000u + i; + staging->Unmap(0, nullptr); + } + for (UINT t = 0; t < 2; ++t) { + auto* resource = fixture.natives[t].Get(); + const auto state = upload ? D3D12_RESOURCE_STATE_COPY_DEST : D3D12_RESOURCE_STATE_COPY_SOURCE; + barrier(copier.list.Get(), resource, D3D12_RESOURCE_STATE_COMMON, state); + if (upload) copier.list->CopyBufferRegion(resource, 0, staging.Get(), t * bytes, bytes); + else copier.list->CopyBufferRegion(staging.Get(), t * bytes, resource, 0, bytes); + barrier(copier.list.Get(), resource, state, D3D12_RESOURCE_STATE_COMMON); + } + if (!copier.run()) return false; + if (upload) return true; + if (FAILED(staging->Map(0, nullptr, reinterpret_cast(&data)))) return false; + words->assign(data, data + 64); + staging->Unmap(0, nullptr); + return true; +} + +int draw_raw_uavs(ID3D12Device* desktop, void* guest, void* list, const std::string& mode) +{ + D3D12_FEATURE_DATA_SHADER_MODEL shader_model{D3D_SHADER_MODEL_6_6}; + if (FAILED(desktop->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &shader_model, sizeof(shader_model))) || + shader_model.HighestShaderModel < D3D_SHADER_MODEL_6_6) { + std::puts("raw pixel UAV: shader model 6.6 unavailable (skip)"); + return 77; + } + using Create = HRESULT (WINAPI*)(void*, const D3D12_HEAP_PROPERTIES*, UINT, const D3D12_RESOURCE_DESC*, UINT, + const void*, void*, UINT, const void*, REFIID, void**); + const auto create = reinterpret_cast((*static_cast(guest))[127]); + const D3D12_HEAP_PROPERTIES heap{D3D12_HEAP_TYPE_DEFAULT}; + for (UINT t = 0; t < 2; ++t) { + const D3D12_RESOURCE_DESC desc{D3D12_RESOURCE_DIMENSION_BUFFER, 0, 128, 1, 1, 1, DXGI_FORMAT_UNKNOWN, + {1, 0}, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, t == 1 && mode == "raw-no-ua" ? D3D12_RESOURCE_FLAG_NONE : + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS}; + if (FAILED(create(guest, &heap, 0, &desc, D3D12_RESOURCE_STATE_COMMON, nullptr, nullptr, 0, nullptr, + __uuidof(ID3D12Resource), &fixture.resources[t])) || !fixture.resources[t]) return 70; + fixture.natives[t] = native_of(guest, fixture.resources[t]); + if (!fixture.natives[t]) return 71; + } + if (!copy_raw(desktop, true, nullptr)) return 72; + struct Extended { D3D12_DESCRIPTOR_HEAP_DESC desc; Word address, bytes; }; + Extended desc{{D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 4, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE}, 0, 0}; + void* views = nullptr; + if (FAILED(static_cast(invoke(guest, 14, ptr(&desc), ptr(&__uuidof(ID3D12DescriptorHeap)), ptr(&views))))) return 73; + const Word cpu = invoke(views, 9), gpu = invoke(views, 10); + const UINT stride = static_cast(invoke(guest, 15, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV)); + if (!cpu || !gpu || stride < 32) return 73; + D3D12_UNORDERED_ACCESS_VIEW_DESC view{DXGI_FORMAT_R32_TYPELESS, D3D12_UAV_DIMENSION_BUFFER}; + view.Buffer.FirstElement = 4; + view.Buffer.NumElements = 16; + view.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; + invoke(guest, 19, ptr(fixture.resources[0]), 0, ptr(&view), cpu); + if (mode == "raw-short") view.Buffer.NumElements = 8; + if (mode == "raw-last") view.Buffer.FirstElement = 16; + if (mode == "raw-typed") { view.Format = DXGI_FORMAT_R32_UINT; view.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE; } + if (mode == "raw-structured") { + view.Format = DXGI_FORMAT_UNKNOWN; view.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE; view.Buffer.StructureByteStride = 4; + } + if (mode == "raw-srv") { + D3D12_SHADER_RESOURCE_VIEW_DESC srv{DXGI_FORMAT_R32_TYPELESS, D3D12_SRV_DIMENSION_BUFFER, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING}; + srv.Buffer.NumElements = 32; srv.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW; + invoke(guest, 18, ptr(fixture.resources[1]), ptr(&srv), cpu + stride); + } else if (mode != "raw-missing") { + invoke(guest, 19, ptr(fixture.resources[1]), 0, ptr(&view), cpu + stride); + } + std::printf("raw pixel UAV case %s, title descriptor stride %u\n", mode.c_str(), stride); + invoke(list, 32, 1, ptr(&views)); + if (mode != "raw-no-table") invoke(list, 36, 0, gpu); + invoke(list, 12, 3, 1); + return 0; +} + ID3D12InfoQueue* debug_messages() { static ComPtr queue; @@ -250,6 +334,8 @@ int draw_pixel_uavs(ID3D12Device* desktop, void* guest, void* list) GetEnvironmentVariableA("X2W_TEST_PIXEL_UAV", mode, sizeof(mode)); const std::string which(mode); fixture.desktop = desktop; + fixture.raw_mode = which.rfind("raw-", 0) == 0; + if (fixture.raw_mode) return draw_raw_uavs(desktop, guest, list, which); fixture.array_mode = which.rfind("arr-", 0) == 0; if (fixture.array_mode) { using Create = HRESULT (WINAPI*)(void*, const D3D12_HEAP_PROPERTIES*, UINT, const D3D12_RESOURCE_DESC*, UINT, const void*, @@ -406,7 +492,8 @@ int draw_pixel_uavs(ID3D12Device* desktop, void* guest, void* list) int report_pixel_uavs(const char* pixels) { std::vector words; - const bool copied = fixture.array_mode ? copy_array(fixture.desktop, false, &words) : copy_all(fixture.desktop, false, &words); + const bool copied = fixture.raw_mode ? copy_raw(fixture.desktop, false, &words) : + fixture.array_mode ? copy_array(fixture.desktop, false, &words) : copy_all(fixture.desktop, false, &words); if (copied) { std::ofstream out(std::string(pixels) + ".uav", std::ios::binary); out.write(reinterpret_cast(words.data()), static_cast(words.size() * 4)); diff --git a/tests/startup_pixel_uav_check.py b/tests/startup_pixel_uav_check.py index 8fd0594b59..94b03618bb 100644 --- a/tests/startup_pixel_uav_check.py +++ b/tests/startup_pixel_uav_check.py @@ -14,8 +14,9 @@ view, an SRV, a texture without ALLOW_UNORDERED_ACCESS, an integer view, a view of mip 1, a 2D-array view, an entry outside the bound table, no table at the parameter, the same texture also bound as an SRV of the draw, and a texture E that is also the draw's render target (bound through list slot 50). -Manifest lines: a view qualifier (float, uint, and the compute line with 'channels 4'), another image kind, a buffer -line, a 'channels' field and a view index out of order are refused when the manifest is loaded. +Manifest lines: a view qualifier (float, uint, and the compute line with 'channels 4'), another image kind, +a 'channels' field and a view index out of order are refused when the manifest is loaded. A raw buffer +line naming a texture is refused during view resolution. Exec: the v_cmpx variants of the program, through the same runtime path: exec on writes the texel, exec off leaves it. Control: the exec-off shader recompiled with the guard removed from the store must write the texel, and the check must report it. @@ -66,8 +67,8 @@ ('a.float-line', 'uav 0 tex2d float table 0 0', None, 'uav line refused (a view qualifier is not read for pixel stores)'), ('a.compute-line', 'uav 0 tex2d float table 0 0 channels 4', None, 'uav line refused (a view qualifier is not read for pixel stores)'), - ('a.tex3d-line', 'uav 0 tex3d table 0 0', None, 'uav line refused (only tex2d and tex2da views are bound)'), - ('a.buffer-line', 'uav 0 raw table 0 0', None, 'uav line refused (buffer view (raw uav) is not bound)'), + ('a.tex3d-line', 'uav 0 tex3d table 0 0', None, 'uav line refused (only tex2d, tex2da and raw views are bound)'), + ('a.buffer-line', 'uav 0 raw table 0 0', None, 'uav 0 refused: incompatible raw buffer UAV'), ('a.uint-line', 'uav 0 tex2d uint table 0 0', None, 'uav line refused (a view qualifier is not read for pixel stores)'), ('a.channels-field', 'uav 0 tex2d table 0 0 channels 4', None, 'uav line refused (unexpected field after the table offset)'), diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index 47db85b485..0b811cf6e1 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -17,6 +17,13 @@ #include "startup_stream_setup.h" #include "startup_slot67_indirect.h" +#ifdef OFFSCREEN_AGILITY_620 +extern "C" { +__declspec(dllexport) extern const UINT D3D12SDKVersion = 620; +__declspec(dllexport) const char* D3D12SDKPath = ".\\D3D12\\"; +} +#endif + using Microsoft::WRL::ComPtr; extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(IUnknown*, const void*, REFIID, void**); extern "C" __declspec(dllimport) void x2w_d3d12_compute_census(); diff --git a/tests/startup_stream_setup.cpp b/tests/startup_stream_setup.cpp index c92d9b49ff..526d22997d 100644 --- a/tests/startup_stream_setup.cpp +++ b/tests/startup_stream_setup.cpp @@ -141,7 +141,13 @@ int prepare_stream_pipeline(const char* vs_path, const char* ps_path, const char D3D12_ROOT_SIGNATURE_DESC root_desc{}; const bool joined_table = GetEnvironmentVariableW(L"X2W_TEST_JOINED_TABLE", nullptr, 0) != 0; const bool vertex_srv_pair = GetEnvironmentVariableW(L"X2W_TEST_COPIED_VERTEX_SRV_PAIR", nullptr, 0) != 0; - const D3D12_DESCRIPTOR_RANGE srv{D3D12_DESCRIPTOR_RANGE_TYPE_SRV, joined_table || vertex_srv_pair ? 2u : 1u, 0, 0, 0}; + char pixel_uav_mode[32]{}; + GetEnvironmentVariableA("X2W_TEST_PIXEL_UAV", pixel_uav_mode, sizeof(pixel_uav_mode)); + const bool raw_pixel = std::strncmp(pixel_uav_mode, "raw-", 4) == 0; + if (raw_pixel) + std::printf("raw descriptor stride: %llu\n", static_cast(invoke(device, 15, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV))); + const D3D12_DESCRIPTOR_RANGE srv{raw_pixel ? D3D12_DESCRIPTOR_RANGE_TYPE_UAV : D3D12_DESCRIPTOR_RANGE_TYPE_SRV, + raw_pixel ? 4u : (joined_table || vertex_srv_pair ? 2u : 1u), 0, 0, 0}; D3D12_ROOT_PARAMETER textured_parameters[2]{}; if (textured) { D3D12_ROOT_PARAMETER& table = textured_parameters[0];