diff --git a/CHANGELOG.md b/CHANGELOG.md index 33c703a..a815d31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Guest execution uses original, purpose-built test programs. Commercial Xbox game remains unsupported. ### Added +- Investigated the two wave-operation failures of the vendored victory-shader tests under D3DMetal (`docs/research/shader-wave-semantics.md`). Measured device capabilities with a new original D3D12 host (`workloads/d3d12-wave-probe/d3d12_run.c caps`): shader model 6.6, wave operations supported, waves exactly 32 lanes, no double-precision shader operations. Established the cause of `a_sum_of_halves_where_lanes_have_left_...`: the test lowers for 64-lane hosts and runs on the 32-lane device, and the recompiler already refuses that program for 32 lanes; the test now checks the device's wave width (`Host::wave_lane_count_max`) and asserts that refusal. `whole_wave_f64_sum_and_cvt_f32_f64` remains failing: the PR's wave-width explanation does not apply (it is a Wave32 program); the one native-double site in the recompiler and the missing double support are consistent with the cause but unproven, because an independent compiler run was not authorized. HLSL probe sources are committed uncompiled. Local, not independently reproduced. - Integrated skakwy's `victory-shader` (GFX10/RDNA 2 machine code to DXIL SM 6.6 recompiler, about 43,500 lines of Rust) as `crates/victory-shader`, with provenance in its `UPSTREAM.md`, the Mesa notice preserved and 19 lines of lint-only edits to upstream files. Added `translate_native` and tests that translate BetterXen's own gfx1030 fixtures to DXIL and run them on the Apple GPU through D3D12 under CrossOver 26.3 (D3DMetal), plus `scripts/hybrid/run-shader-gpu-tests.sh`, which runs them through `betterxen-hybrid run`. Local results on the M4, not independently reproduced: 177 upstream CPU-side tests pass on macOS; all 6 fixtures with expected words (add, float-exact, bitwise-branch, or, shifts, ashr) matched the manifest on the GPU, with a negative control; the GPU tests fail without D3D12 instead of skipping; the full upstream suite under CrossOver has 224 passed, 2 failed (wave-wide reductions), 3 ignored. DXIL validation by `dxil.dll` was not run. The native RDNA-to-Metal compiler is unchanged. See `docs/research/victory-shader-integration.md`. - Added `--stall-timeout` and a memory-settle wait to `betterxen-hybrid run`/`bench` (#385): a run that prints nothing for the given time is stopped and classified `stalled`, and after any stop the supervisor waits (up to `--settle-bound`, default 60 s) until free memory is back above the start threshold and records whether it recovered. Based on supervision lessons from skakwy's victory-mac (reimplemented, not copied). Also fixes a defect found by the first real stall run: stopping a bottle used `CX_BOTTLE`, which does not select the bottle, so a stopped Windows process kept running; it now sets `WINEPREFIX`. Verified with 4 new unit tests (stub launcher) and a real CrossOver 26.3 run on the M4: a silent workload was stopped as `stalled` after 4.7 s of a 120 s timeout, nothing was left running, and the next run passed. The low-memory recovery path is only tested with an injected memory reader. Not independently reviewed. - Added `betterxen-hybrid run` and `bench`: launch a Windows program through an installed CrossOver (`bin/wine --bottle`, an interface CodeWeavers does not document for macOS), with timeout, the memory guard, failure classification (passed, failed exit, timed out, stopped on low memory, cannot execute, no graphics device), sampled CrossOver process memory and CPU, thermal notes, recognised host-noise diagnostics and frame statistics, and write a JSON record; `bench` repeats a workload across graphics backends. Locally verified with 24 unit tests (stub launcher) and with real runs on CrossOver 26.3 on the Apple M4. diff --git a/crates/victory-shader/src/emit/host.rs b/crates/victory-shader/src/emit/host.rs index a51d0ac..be3b502 100644 --- a/crates/victory-shader/src/emit/host.rs +++ b/crates/victory-shader/src/emit/host.rs @@ -82,6 +82,24 @@ fn err(e: windows::core::Error) -> String { } impl Host { + /// The widest wave the device reports (`D3D12_OPTIONS1.WaveLaneCountMax`), or `None` when the + /// device does not report wave operations. BetterXen addition: tests that lower for a given + /// host wave width must not run on a narrower device (see wave64_tests.rs). + pub fn wave_lane_count_max(&self) -> Option { + let mut o = D3D12_FEATURE_DATA_D3D12_OPTIONS1::default(); + // SAFETY: `o` is a correctly sized, writable feature-data struct for this feature. + unsafe { + self.device + .CheckFeatureSupport( + D3D12_FEATURE_D3D12_OPTIONS1, + (&mut o as *mut D3D12_FEATURE_DATA_D3D12_OPTIONS1).cast(), + std::mem::size_of::() as u32, + ) + .ok()?; + } + (o.WaveOps.as_bool() && o.WaveLaneCountMax > 0).then_some(o.WaveLaneCountMax) + } + /// The default adapter, or WARP with `warp` (or `VICTORY_WARP=1`). pub fn new(warp: bool) -> Result { let warp = warp || std::env::var("VICTORY_WARP").is_ok_and(|v| v == "1"); diff --git a/crates/victory-shader/src/emit/wave64_tests.rs b/crates/victory-shader/src/emit/wave64_tests.rs index 55cc55d..05d7f70 100644 --- a/crates/victory-shader/src/emit/wave64_tests.rs +++ b/crates/victory-shader/src/emit/wave64_tests.rs @@ -235,6 +235,23 @@ fn a_sum_of_halves_where_lanes_have_left_is_the_consoles_tree_bit_for_bit() { words[1] = 0xBF88_0000 | (words.len() as u32 - 2); let native = native(&words); let p = ir::build(&native.code, native.wave64, native.vgprs).expect("ir::build"); + // BetterXen correction (research/shader-wave-semantics): this program is lowered for a host + // of 64-lane waves. A device whose waves are narrower cannot run that lowering: its lanes 32 + // and up do not exist, and the observed result was 0 instead of the tree. Such a device + // must be offered the lowering for its own width instead, which the recompiler refuses for + // this program ("a wave sum of 16-bit floats where not every lane runs"): the test then + // asserts that refusal, which is the correct behaviour, rather than reporting a failure + // or silently skipping. + if let Some(w) = Host::new(false).ok().and_then(|h| h.wave_lane_count_max()).filter(|&w| w < 64) { + let refused = lowered_on(&native, &p, &HashSet::new(), w); + assert!( + matches!(&refused, Err(ShaderError::Unsupported { what, .. }) if what.contains("16-bit floats where not every lane runs")), + "a {w}-lane device must be refused this program, got {:?}", + refused.as_ref().map(|_| "a shader") + ); + eprintln!("device waves are {w} lanes; refused for that width as expected; not run on the device"); + return; + } let shader = lowered_on(&native, &p, &HashSet::new(), 64).expect("lower"); if let Ok(mut v) = validator::Validator::load(validator::Validator::default_path().as_deref()) { let mut copy = shader.dxil.clone(); diff --git a/docs/README.md b/docs/README.md index 0aeb14d..e4d44e1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -70,6 +70,7 @@ checkpoints retain their original evidence scope. - [Shader inputs](research/shader-containers.md) and [risk register](risk-register.md) — Input provenance and unresolved engineering risks. - [Upstream integration audit](research/upstream-integration-audit.md) — Source-level review of external macOS compatibility projects, licence and provenance decisions, and what was implemented in `crates/hybrid`. - [victory-shader integration](research/victory-shader-integration.md) — The vendored GFX10-to-DXIL recompiler, how BetterXen's fixtures run through it on the GPU under CrossOver, and what is not verified. +- [Shader wave-semantics investigation](research/shader-wave-semantics.md) — Why two upstream wave tests fail under D3DMetal: device capabilities, what is established and what is not. - [CrossOver baseline](research/crossover-baseline-2026-11-25.md) — First executions of original workloads under CrossOver 26.3 on the M4, backend comparison and its limits. - [Windows cross-toolchain](research/hybrid-toolchain.md) — Pinned llvm-mingw release, how original Windows workloads are built, and what was and was not executed. - [Texture format inventory](research/texture-formats.md) — Formats and layouts by stage (decode, layout, native upload, sampling, guest), their public specifications, unknowns and ranked follow-ups. diff --git a/docs/research/shader-wave-semantics.md b/docs/research/shader-wave-semantics.md new file mode 100644 index 0000000..1e5dfbc --- /dev/null +++ b/docs/research/shader-wave-semantics.md @@ -0,0 +1,49 @@ +# Shader wave-operation failures under D3DMetal: investigation + +Branch `research/shader-wave-semantics`, based on PR #391. Evidence class B (runs on one machine: Apple M4, 24 GiB, macOS 27.0, CrossOver 26.3.0.39832, default backend), not independently reproduced. The two failures are the ones recorded in `victory-shader-integration.md`. This note separates what is **established** from what is **a hypothesis**. + +## Device capabilities (measured with BetterXen's own host, `workloads/d3d12-wave-probe/d3d12_run.c caps`) + +| Field | Value | +| --- | --- | +| Adapter reported | "AMD Compatibility Mode", vendor 0x1002, 18,186 MB (D3DMetal's reported identity; the hardware is the M4) | +| Device created at feature level | 12_1 | +| Highest shader model | 6.6 | +| `WaveOps` | supported | +| `WaveLaneCountMin` / `Max` | 32 / 32 (waves are exactly 32 lanes; `TotalLaneCount` 1024) | +| `DoublePrecisionFloatShaderOps` | **0** (no double-precision shader operations) | +| `Int64ShaderOps` | supported | +| Min-precision support | 0x2 (16-bit) | + +## Failure 2: `a_sum_of_halves_where_lanes_have_left_is_the_consoles_tree_bit_for_bit` (established) + +**Cause: a wrong test precondition (a subgroup-size assumption), not a translation error.** + +1. The test lowers the program with `lowered_on(.., 64)`, "for a host of 64-lane waves (AMD)" per its own comment, then dispatches it on the default device without asking that device's wave width. +2. The device's waves are exactly 32 lanes (table above). A program written for 64-lane waves reads lanes 32 to 63, which do not exist; the observed result was `0x0` against the expected tree `0x5914`. +3. It is the only test in that file that lowers for 64 lanes (line 238); the sibling `a_sum_of_halves_over_the_wave_is_the_consoles_tree_bit_for_bit` lowers for 32 (line 160) and passes on the same device. +4. Lowering this same program for a 32-lane host does not produce a wrong shader: the recompiler refuses it with `Unsupported: a wave sum of 16-bit floats where not every lane runs`. So the recompiler already behaves correctly; it states a limit instead of emitting something wrong. +5. The expected value `0x5914` is derived on the host by integer 16-bit float arithmetic in the test itself, independent of the recompiler. + +**Correction made (test, not recompiler):** `Host::wave_lane_count_max()` (new, from `D3D12_OPTIONS1`), and the test now checks the device first. On a device narrower than 64 lanes it asserts the refusal above and returns, printing why; on a 64-lane device it runs the original hardware comparison unchanged. After the change the test passes on this device, and what it verifies there is "the recompiler refuses a 64-lane-only program for a 32-lane host", not "the sum is correct on the GPU". The correct-sum claim stays **unverified on 32-lane hardware** and has not been run on a 64-lane device. + +## Failure 1: `whole_wave_f64_sum_and_cvt_f32_f64` (hypothesis, not yet proven) + +Observed: a Wave32 program with 4 launched threads, each contributing 1.25, should store 5.0 (`0x40a00000` as f32); it stores `0x00000000`. The program is Wave32 on a 32-lane device, so **the wave-width hypothesis from the PR does not apply to this test**. + +What is established from the source and the capability record: +- The recompiler emits native `double` DXIL in exactly one place: `active_f64_sum` (`makeDouble`, `waveActiveOp.f64` with opcode 119, `splitDouble`; sets the shader's "doubles" flag). Every other fp64 instruction uses upstream's integer emulation (`emit/f64.rs`), which upstream states exists because "the host (D3DMetal, Metal) has no fp64"; those tests pass here. +- The device reports `DoublePrecisionFloatShaderOps = 0`. +- D3DMetal nevertheless created the pipeline and ran it, returning zero rather than failing. + +Hypothesis consistent with all of that: native double operations in DXIL are not honoured by D3DMetal on this hardware, and the one native-double site in the recompiler is therefore wrong for this backend; the recompiler should use its own integer f64 add for the cross-lane reduction as it does everywhere else. **Not yet established**, because every run so far went through the recompiler itself. Independent evidence needs a native-double shader from a different compiler (`hlsl/sum_f64_4.hlsl`, `hlsl/add_f64_4.hlsl`: a double sum across lanes and a plain double add, to separate "doubles" from "wave operations on doubles"), plus `hlsl/sum_f32_4.hlsl` and `hlsl/lanes4.hlsl` as controls. These need Microsoft's DXC (open source, GitHub release v1.9.2609, `dxc_2026_09_29.zip`, SHA-256 `ad31b1fc…a7e7f1`, matching the release digest) run under CrossOver to compile them. That step has not been done: the permission system blocked running the downloaded compiler and it was not retried. The sources are committed and marked not compiled or run. + +No recompiler change is proposed for failure 1 until that evidence exists. + +## Reproduce +```sh +scripts/hybrid/run-shader-gpu-tests.sh betterxen-test all # expect: 1 failure (whole_wave_f64_sum_and_cvt_f32_f64) +# capabilities (needs the d3d12_run.exe built from workloads/d3d12-wave-probe/d3d12_run.c with llvm-mingw): +# x86_64-w64-mingw32-clang -O2 -o d3d12_run.exe d3d12_run.c -ld3d12 -ldxgi -ldxguid +# CrossOver bin/wine --bottle ./d3d12_run.exe caps +``` diff --git a/workloads/d3d12-wave-probe/d3d12_run.c b/workloads/d3d12-wave-probe/d3d12_run.c new file mode 100644 index 0000000..d1ec496 --- /dev/null +++ b/workloads/d3d12-wave-probe/d3d12_run.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Original BetterXen workload (shader wave-semantics investigation): a minimal Direct3D 12 +// compute host that is independent of the vendored recompiler. +// +// d3d12_run.exe caps +// Prints the default adapter and the device capabilities relevant to wave operations. +// d3d12_run.exe run +// Creates a root signature with one root UAV (u0), a compute PSO from the DXIL file, +// fills a UAV buffer of dwords with 0xDEADBEEF, dispatches groups +// and prints every dword read back as `out 0x`. A dword that stays +// 0xDEADBEEF was never written. +// +// Status: `caps` has been compiled and run under CrossOver 26.3 on the M4. `run` has been +// compiled only; it has not been executed yet. +// Exit codes: 0 ran, 2 no device, 3 pipeline creation failed, 4 other D3D12 failure. +#define COBJMACROS +#include +#include +#include +#include +#include + +#define CK(x, what) do { HRESULT h_ = (x); if (FAILED(h_)) { \ + printf("FAIL %s hr=0x%08lx\n", what, (unsigned long)h_); return 4; } } while (0) + +static ID3D12Device *make_device(void) { + ID3D12Device *dev = NULL; + static const D3D_FEATURE_LEVEL levels[] = {D3D_FEATURE_LEVEL_12_1, D3D_FEATURE_LEVEL_12_0, D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0}; + for (unsigned i = 0; i < sizeof levels / sizeof *levels; i++) { + if (SUCCEEDED(D3D12CreateDevice(NULL, levels[i], &IID_ID3D12Device, (void **)&dev))) { + printf("device_created_at_feature_level=0x%x\n", (unsigned)levels[i]); + return dev; + } + } + return NULL; +} + +static int caps(void) { + ID3D12Device *dev = make_device(); + if (!dev) { printf("NO DEVICE\n"); return 2; } + LUID luid; dev->lpVtbl->GetAdapterLuid(dev, &luid); // (the C macro cannot return a struct) + IDXGIFactory4 *f = NULL; + if (SUCCEEDED(CreateDXGIFactory1(&IID_IDXGIFactory4, (void **)&f))) { + IDXGIAdapter1 *ad = NULL; + if (SUCCEEDED(IDXGIFactory4_EnumAdapterByLuid(f, luid, &IID_IDXGIAdapter1, (void **)&ad))) { + DXGI_ADAPTER_DESC1 d; IDXGIAdapter1_GetDesc1(ad, &d); + char n[128]; size_t i = 0; for (; d.Description[i] && i < 127; i++) n[i] = (char)d.Description[i]; n[i] = 0; + printf("adapter=%s vendor=0x%x device=0x%x vram_mb=%u shared_mb=%u\n", n, d.VendorId, d.DeviceId, + (unsigned)(d.DedicatedVideoMemory >> 20), (unsigned)(d.SharedSystemMemory >> 20)); + } + } + D3D12_FEATURE_DATA_SHADER_MODEL sm = {D3D_SHADER_MODEL_6_7}; + HRESULT h = ID3D12Device_CheckFeatureSupport(dev, D3D12_FEATURE_SHADER_MODEL, &sm, sizeof sm); + if (FAILED(h)) { sm.HighestShaderModel = D3D_SHADER_MODEL_6_6; h = ID3D12Device_CheckFeatureSupport(dev, D3D12_FEATURE_SHADER_MODEL, &sm, sizeof sm); } + printf("highest_shader_model=0x%x (query hr=0x%08lx)\n", (unsigned)sm.HighestShaderModel, (unsigned long)h); + D3D12_FEATURE_DATA_D3D12_OPTIONS o = {0}; + h = ID3D12Device_CheckFeatureSupport(dev, D3D12_FEATURE_D3D12_OPTIONS, &o, sizeof o); + printf("options: hr=0x%08lx double_ops=%d min_precision=0x%x resource_binding_tier=%d\n", (unsigned long)h, o.DoublePrecisionFloatShaderOps, (unsigned)o.MinPrecisionSupport, (int)o.ResourceBindingTier); + D3D12_FEATURE_DATA_D3D12_OPTIONS1 o1 = {0}; + h = ID3D12Device_CheckFeatureSupport(dev, D3D12_FEATURE_D3D12_OPTIONS1, &o1, sizeof o1); + printf("options1: hr=0x%08lx wave_ops=%d wave_lane_count_min=%u wave_lane_count_max=%u total_lane_count=%u expanded_compute_resource_states=%d int64_shader_ops=%d\n", + (unsigned long)h, o1.WaveOps, o1.WaveLaneCountMin, o1.WaveLaneCountMax, o1.TotalLaneCount, o1.ExpandedComputeResourceStates, o1.Int64ShaderOps); + return 0; +} + +static int run(const char *path, unsigned groups, unsigned dwords) { + FILE *fp = fopen(path, "rb"); + if (!fp) { printf("FAIL open %s\n", path); return 4; } + fseek(fp, 0, SEEK_END); long n = ftell(fp); fseek(fp, 0, SEEK_SET); + void *code = malloc((size_t)n); + if (fread(code, 1, (size_t)n, fp) != (size_t)n) { printf("FAIL read\n"); return 4; } + fclose(fp); + ID3D12Device *dev = make_device(); + if (!dev) { printf("NO DEVICE\n"); return 2; } + + D3D12_ROOT_PARAMETER rp = {0}; + rp.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV; + rp.Descriptor.ShaderRegister = 0; + rp.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; + D3D12_ROOT_SIGNATURE_DESC rsd = {0}; + rsd.NumParameters = 1; rsd.pParameters = &rp; + ID3DBlob *blob = NULL, *err = NULL; + CK(D3D12SerializeRootSignature(&rsd, D3D_ROOT_SIGNATURE_VERSION_1, &blob, &err), "serialize root signature"); + ID3D12RootSignature *rs = NULL; + CK(ID3D12Device_CreateRootSignature(dev, 0, ID3D10Blob_GetBufferPointer(blob), ID3D10Blob_GetBufferSize(blob), &IID_ID3D12RootSignature, (void **)&rs), "create root signature"); + + D3D12_COMPUTE_PIPELINE_STATE_DESC pd = {0}; + pd.pRootSignature = rs; + pd.CS.pShaderBytecode = code; pd.CS.BytecodeLength = (SIZE_T)n; + ID3D12PipelineState *pso = NULL; + HRESULT h = ID3D12Device_CreateComputePipelineState(dev, &pd, &IID_ID3D12PipelineState, (void **)&pso); + if (FAILED(h)) { printf("PSO_FAILED hr=0x%08lx\n", (unsigned long)h); return 3; } + + UINT64 bytes = (UINT64)dwords * 4; + D3D12_HEAP_PROPERTIES hp_def = {0}, hp_up = {0}, hp_rb = {0}; + hp_def.Type = D3D12_HEAP_TYPE_DEFAULT; hp_up.Type = D3D12_HEAP_TYPE_UPLOAD; hp_rb.Type = D3D12_HEAP_TYPE_READBACK; + D3D12_RESOURCE_DESC rd = {0}; + rd.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; rd.Width = bytes; rd.Height = 1; rd.DepthOrArraySize = 1; rd.MipLevels = 1; + rd.Format = DXGI_FORMAT_UNKNOWN; rd.SampleDesc.Count = 1; rd.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; + ID3D12Resource *def, *up, *rb; + D3D12_RESOURCE_DESC rdu = rd; rdu.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + CK(ID3D12Device_CreateCommittedResource(dev, &hp_def, D3D12_HEAP_FLAG_NONE, &rdu, D3D12_RESOURCE_STATE_COPY_DEST, NULL, &IID_ID3D12Resource, (void **)&def), "create default"); + CK(ID3D12Device_CreateCommittedResource(dev, &hp_up, D3D12_HEAP_FLAG_NONE, &rd, D3D12_RESOURCE_STATE_GENERIC_READ, NULL, &IID_ID3D12Resource, (void **)&up), "create upload"); + CK(ID3D12Device_CreateCommittedResource(dev, &hp_rb, D3D12_HEAP_FLAG_NONE, &rd, D3D12_RESOURCE_STATE_COPY_DEST, NULL, &IID_ID3D12Resource, (void **)&rb), "create readback"); + unsigned *p; CK(ID3D12Resource_Map(up, 0, NULL, (void **)&p), "map upload"); + for (unsigned i = 0; i < dwords; i++) p[i] = 0xDEADBEEFu; + ID3D12Resource_Unmap(up, 0, NULL); + + D3D12_COMMAND_QUEUE_DESC qd = {0}; + qd.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; + ID3D12CommandQueue *q; CK(ID3D12Device_CreateCommandQueue(dev, &qd, &IID_ID3D12CommandQueue, (void **)&q), "queue"); + ID3D12CommandAllocator *al; CK(ID3D12Device_CreateCommandAllocator(dev, D3D12_COMMAND_LIST_TYPE_DIRECT, &IID_ID3D12CommandAllocator, (void **)&al), "allocator"); + ID3D12GraphicsCommandList *cl; CK(ID3D12Device_CreateCommandList(dev, 0, D3D12_COMMAND_LIST_TYPE_DIRECT, al, pso, &IID_ID3D12GraphicsCommandList, (void **)&cl), "list"); + ID3D12GraphicsCommandList_CopyBufferRegion(cl, def, 0, up, 0, bytes); + D3D12_RESOURCE_BARRIER b = {0}; + b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + b.Transition.pResource = def; b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; + b.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST; b.Transition.StateAfter = D3D12_RESOURCE_STATE_UNORDERED_ACCESS; + ID3D12GraphicsCommandList_ResourceBarrier(cl, 1, &b); + ID3D12GraphicsCommandList_SetComputeRootSignature(cl, rs); + ID3D12GraphicsCommandList_SetComputeRootUnorderedAccessView(cl, 0, ID3D12Resource_GetGPUVirtualAddress(def)); + ID3D12GraphicsCommandList_Dispatch(cl, groups, 1, 1); + b.Transition.StateBefore = D3D12_RESOURCE_STATE_UNORDERED_ACCESS; b.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE; + ID3D12GraphicsCommandList_ResourceBarrier(cl, 1, &b); + ID3D12GraphicsCommandList_CopyBufferRegion(cl, rb, 0, def, 0, bytes); + CK(ID3D12GraphicsCommandList_Close(cl), "close"); + ID3D12CommandList *lists[1] = {(ID3D12CommandList *)cl}; + ID3D12CommandQueue_ExecuteCommandLists(q, 1, lists); + ID3D12Fence *fence; CK(ID3D12Device_CreateFence(dev, 0, D3D12_FENCE_FLAG_NONE, &IID_ID3D12Fence, (void **)&fence), "fence"); + HANDLE ev = CreateEventA(NULL, FALSE, FALSE, NULL); + CK(ID3D12CommandQueue_Signal(q, fence, 1), "signal"); + ID3D12Fence_SetEventOnCompletion(fence, 1, ev); + if (WaitForSingleObject(ev, 30000) != WAIT_OBJECT_0) { printf("FAIL timeout waiting for the GPU\n"); return 4; } + CK(ID3D12Resource_Map(rb, 0, NULL, (void **)&p), "map readback"); + for (unsigned i = 0; i < dwords; i++) printf("out %u 0x%08x\n", i, p[i]); + return 0; +} + +int main(int argc, char **argv) { + if (argc == 2 && !strcmp(argv[1], "caps")) return caps(); + if (argc == 5 && !strcmp(argv[1], "run")) return run(argv[2], (unsigned)atoi(argv[3]), (unsigned)atoi(argv[4])); + printf("usage: d3d12_run caps | run \n"); + return 1; +} diff --git a/workloads/d3d12-wave-probe/hlsl/README.md b/workloads/d3d12-wave-probe/hlsl/README.md new file mode 100644 index 0000000..f19074b --- /dev/null +++ b/workloads/d3d12-wave-probe/hlsl/README.md @@ -0,0 +1,7 @@ +# Wave-semantics HLSL probes (NOT YET COMPILED OR RUN) + +Original BetterXen sources, GPL-3.0-or-later. They are meant to be compiled with Microsoft's +open-source DXC (`dxc -T cs_6_6 -E main`) and dispatched with `d3d12_run.exe run`. Neither step has +been done: running the downloaded DXC under CrossOver was not authorized in the session that wrote +them, and `d3d12_run.exe run` has only been compiled, not executed (`caps` has been run). +Expected values are worked out by hand from the HLSL specification and listed in each file. diff --git a/workloads/d3d12-wave-probe/hlsl/add_f64_4.hlsl b/workloads/d3d12-wave-probe/hlsl/add_f64_4.hlsl new file mode 100644 index 0000000..75ffab7 --- /dev/null +++ b/workloads/d3d12-wave-probe/hlsl/add_f64_4.hlsl @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// No wave operation: a plain double addition 1.25 + 0.75 = 2.0 (0x4000000000000000), to separate +// "doubles unsupported" from "wave operations on doubles unsupported". +// Expected (by hand): low word 0x00000000, high word 0x40000000. +RWByteAddressBuffer o : register(u0); +[numthreads(4, 1, 1)] +void main(uint t : SV_GroupIndex) { + double a = 1.25, b = 0.75 + (double)(t - t); + double s = a + b; + uint lo, hi; + asuint(s, lo, hi); + o.Store2(t * 8, uint2(lo, hi)); +} diff --git a/workloads/d3d12-wave-probe/hlsl/lanes4.hlsl b/workloads/d3d12-wave-probe/hlsl/lanes4.hlsl new file mode 100644 index 0000000..7139f1b --- /dev/null +++ b/workloads/d3d12-wave-probe/hlsl/lanes4.hlsl @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Expected (by hand): each launched thread t stores (laneCount << 8) | t, where laneCount is the +// device's wave width (32 per the capability record), so 0x2000, 0x2001, 0x2002, 0x2003. +RWByteAddressBuffer o : register(u0); +[numthreads(4, 1, 1)] +void main(uint t : SV_GroupIndex) { o.Store(t * 4, (WaveGetLaneCount() << 8) | WaveGetLaneIndex()); } diff --git a/workloads/d3d12-wave-probe/hlsl/sum_f32_4.hlsl b/workloads/d3d12-wave-probe/hlsl/sum_f32_4.hlsl new file mode 100644 index 0000000..ec9a792 --- /dev/null +++ b/workloads/d3d12-wave-probe/hlsl/sum_f32_4.hlsl @@ -0,0 +1,5 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Expected (by hand): 4 threads each add 1.25f, every launched lane reads 5.0 = 0x40a00000. +RWByteAddressBuffer o : register(u0); +[numthreads(4, 1, 1)] +void main(uint t : SV_GroupIndex) { o.Store(t * 4, asuint(WaveActiveSum(1.25f))); } diff --git a/workloads/d3d12-wave-probe/hlsl/sum_f64_4.hlsl b/workloads/d3d12-wave-probe/hlsl/sum_f64_4.hlsl new file mode 100644 index 0000000..bf49e30 --- /dev/null +++ b/workloads/d3d12-wave-probe/hlsl/sum_f64_4.hlsl @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Expected (by hand): 4 threads each add the double 1.25; the sum is 5.0, whose bit pattern is +// 0x4014000000000000, so each lane stores low word 0x00000000 and high word 0x40140000. +// The device reports DoublePrecisionFloatShaderOps = 0; this probe shows what actually happens. +RWByteAddressBuffer o : register(u0); +[numthreads(4, 1, 1)] +void main(uint t : SV_GroupIndex) { + double s = WaveActiveSum(1.25); + uint lo, hi; + asuint(s, lo, hi); + o.Store2(t * 8, uint2(lo, hi)); +}