diff --git a/.github/workflows/d3d12.yml b/.github/workflows/d3d12.yml index 3cf56fa817..bd81adf715 100644 --- a/.github/workflows/d3d12.yml +++ b/.github/workflows/d3d12.yml @@ -69,11 +69,9 @@ jobs: # The features of the executable people run (d3d12/scripts/build-nvidia.ps1, without dlss); no other step builds them. - name: Build as shipped (diagnostics, mimalloc) run: cargo build -p leonida --features diagnostics,mimalloc --locked - # The software adapter of the runner does not do the depth bounds test as this one expects, and #2663 fixes that - # in the renderer; drop the --skip with it. A failing test here also stops the crates after leonida-gpu. - name: Tests (no GPU, no game data) timeout-minutes: 30 - run: cargo test --workspace --exclude xtask --locked -- --skip depth_bounds_pipeline_loads_and_filters_draws + run: cargo test --workspace --exclude xtask --locked # tests/replay.rs is compiled only with the diagnostics feature. - name: Replay test (diagnostics) timeout-minutes: 15 diff --git a/d3d12/crates/leonida-gpu/src/pipeline/host.rs b/d3d12/crates/leonida-gpu/src/pipeline/host.rs index 3ab7cbc626..85cc8cd35e 100644 --- a/d3d12/crates/leonida-gpu/src/pipeline/host.rs +++ b/d3d12/crates/leonida-gpu/src/pipeline/host.rs @@ -338,7 +338,9 @@ impl GraphicsState { pub(crate) fn screen_pass(&self) -> bool { self.inputs.is_empty() && (self.depth_format == DXGI_FORMAT_UNKNOWN - || !self.depth.DepthEnable.as_bool() && !self.depth.StencilEnable.as_bool()) + || !self.depth.DepthEnable.as_bool() + && !self.depth.StencilEnable.as_bool() + && !self.depth_bounds) && self.targets.NumRenderTargets > 0 && self.topology == D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE } @@ -440,7 +442,11 @@ impl GraphicsState { }) .collect(); let bounds = if self.depth_bounds { - " depth-bounds" + if !self.depth.DepthEnable.as_bool() && self.depth_format != DXGI_FORMAT_UNKNOWN { + " depth-bounds-always" + } else { + " depth-bounds" + } } else { "" }; @@ -460,17 +466,20 @@ impl GraphicsState { fn depth1(&self) -> D3D12_DEPTH_STENCIL_DESC1 { let d = &self.depth; - D3D12_DEPTH_STENCIL_DESC1 { - DepthEnable: d.DepthEnable, - DepthWriteMask: d.DepthWriteMask, - DepthFunc: d.DepthFunc, - StencilEnable: d.StencilEnable, - StencilReadMask: d.StencilReadMask, - StencilWriteMask: d.StencilWriteMask, - FrontFace: d.FrontFace, - BackFace: d.BackFace, - DepthBoundsTestEnable: self.depth_bounds.into(), - } + effective_depth_bounds_desc( + D3D12_DEPTH_STENCIL_DESC1 { + DepthEnable: d.DepthEnable, + DepthWriteMask: d.DepthWriteMask, + DepthFunc: d.DepthFunc, + StencilEnable: d.StencilEnable, + StencilReadMask: d.StencilReadMask, + StencilWriteMask: d.StencilWriteMask, + FrontFace: d.FrontFace, + BackFace: d.BackFace, + DepthBoundsTestEnable: self.depth_bounds.into(), + }, + self.depth_format, + ) } /// The vertex buffer slots the input layout reads. @@ -1137,6 +1146,30 @@ pub(super) fn stream_pipeline( ) } +/// Normalizes host `DEPTH_STENCIL1` state for pipelines with `DepthBoundsTestEnable`. +/// +/// When a depth buffer is bound (`dsv_format != DXGI_FORMAT_UNKNOWN`) and +/// `DepthBoundsTestEnable` is enabled with `DepthEnable` off, WARP (and drivers +/// that gate early-Z DSV fetches on `DepthEnable || StencilEnable`) bypass the +/// depth-stencil stage completely and pass fragments outside `[min, max]`. +/// Enabling `DepthEnable` with `COMPARISON_FUNC_ALWAYS` and +/// `DEPTH_WRITE_MASK_ZERO` is a no-op on depth comparison and writes (including +/// on read-only DSVs) while keeping the depth-bounds test active. +fn effective_depth_bounds_desc( + mut depth: D3D12_DEPTH_STENCIL_DESC1, + dsv_format: DXGI_FORMAT, +) -> D3D12_DEPTH_STENCIL_DESC1 { + if depth.DepthBoundsTestEnable.as_bool() + && !depth.DepthEnable.as_bool() + && dsv_format != DXGI_FORMAT_UNKNOWN + { + depth.DepthEnable = true.into(); + depth.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ZERO; + depth.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS; + } + depth +} + /// A graphics pipeline enabling the depth bounds test: `D3D12_GRAPHICS_PIPELINE_STATE_DESC` /// has no field for `DepthBoundsTestEnable`, so it is created and loaded as a /// pipeline-state stream with `DEPTH_STENCIL1`. @@ -1148,6 +1181,7 @@ fn graphics_depth_bounds_pipeline( name: Option<&str>, ) -> windows::core::Result { use windows::core::Interface; + let depth = effective_depth_bounds_desc(depth, d.DSVFormat); #[repr(C)] struct Stream { root: Sub<*mut std::ffi::c_void>, @@ -1611,8 +1645,8 @@ mod tests { let Some(host) = host() else { return; }; - if !host.depth_bounds() { - eprintln!("no host depth bounds support; skipped"); + if !host.depth_bounds() || !device_supports_depth_bounds_sm60(&host.device) { + eprintln!("no host SM 6.0 depth bounds support; skipped"); return; } let Some(dxc) = dxc() else { @@ -1620,8 +1654,8 @@ mod tests { return; }; let dir = tempfile::tempdir().unwrap(); - let vs = compile(&dxc, dir.path(), VS, "vs_6_5"); - let ps = compile(&dxc, dir.path(), PS, "ps_6_5"); + let vs = compile(&dxc, dir.path(), VS, "vs_6_0"); + let ps = compile(&dxc, dir.path(), PS, "ps_6_0"); let (root, root_blob) = root_signature(&host.device, &[], &[], false).unwrap(); let mut g = GraphicsState::default(); @@ -1770,16 +1804,52 @@ mod tests { out.unwrap() }; + let (rtv_heap, dsv_heap, rtv, dsv) = { + // SAFETY: dedicated per-test 1-slot CPU descriptor heaps isolate RTV/DSV handles + // from concurrent `Host::rtv` / `Host::dsv` ring wraparound during parallel test runs. + unsafe { + let rtv_heap: ID3D12DescriptorHeap = host + .device + .CreateDescriptorHeap(&D3D12_DESCRIPTOR_HEAP_DESC { + Type: D3D12_DESCRIPTOR_HEAP_TYPE_RTV, + NumDescriptors: 1, + ..Default::default() + }) + .unwrap(); + let dsv_heap: ID3D12DescriptorHeap = host + .device + .CreateDescriptorHeap(&D3D12_DESCRIPTOR_HEAP_DESC { + Type: D3D12_DESCRIPTOR_HEAP_TYPE_DSV, + NumDescriptors: 1, + ..Default::default() + }) + .unwrap(); + let rtv = rtv_heap.GetCPUDescriptorHandleForHeapStart(); + let dsv = dsv_heap.GetCPUDescriptorHandleForHeapStart(); + host.device.CreateRenderTargetView(&color, None, rtv); + host.device.CreateDepthStencilView(&depth, None, dsv); + (rtv_heap, dsv_heap, rtv, dsv) + } + }; + let _keep_heaps = (&rtv_heap, &dsv_heap); + let run_draw = |min: f32, max: f32| -> u8 { let mut state = crate::draw::State::default(); let first_list = host.new_list().unwrap(); + // Clear targets before the command-list cut so `State::replay` on the + // continuation list sets `OMSetDepthBounds` without an intervening clear. + // SAFETY: open command list and live CPU descriptor handles. + unsafe { + first_list.list.ClearRenderTargetView(rtv, &[0.0; 4], None); + first_list + .list + .ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH, 0.5, 0, None); + } state.set_depth_bounds(&first_list, min, max); first_list.close(); // Replay onto a second host list, exercising `State::replay`. let list = host.new_list().unwrap(); state.replay(&list); - let rtv = host.rtv(Some(&color), None); - let dsv = host.dsv(&depth, None); let vp = D3D12_VIEWPORT { TopLeftX: 0.0, TopLeftY: 0.0, @@ -1796,8 +1866,6 @@ mod tests { }; // SAFETY: open command list, live resources and views. unsafe { - list.list.ClearRenderTargetView(rtv, &[0.0; 4], None); - list.list.ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH, 0.5, 0, None); list.list.OMSetRenderTargets(1, Some(&rtv), false, Some(&dsv)); list.list.RSSetViewports(&[vp]); list.list.RSSetScissorRects(&[rect]); @@ -1840,7 +1908,7 @@ mod tests { )]); } list.close(); - host.execute(&[&list]); + host.execute(&[&first_list, &list]); let mut ptr = std::ptr::null_mut(); // SAFETY: `execute` waited for the GPU; readback holds 1024 bytes. unsafe { @@ -1855,6 +1923,432 @@ mod tests { assert_eq!(run_draw(0.4, 0.6), 255, "depth 0.5 inside [0.4, 0.6] must pass"); } + #[test] + fn depth_bounds_without_depth_test_enables_noop_always_depth_only_with_dsv() { + let mut g = GraphicsState { + depth_bounds: true, + depth_format: DXGI_FORMAT_D32_FLOAT, + ..GraphicsState::default() + }; + g.depth.DepthEnable = false.into(); + g.depth.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL; + g.depth.DepthFunc = D3D12_COMPARISON_FUNC_LESS; + assert!(!g.screen_pass()); + + let d1 = g.depth1(); + assert!(d1.DepthEnable.as_bool()); + assert_eq!(d1.DepthWriteMask, D3D12_DEPTH_WRITE_MASK_ZERO); + assert_eq!(d1.DepthFunc, D3D12_COMPARISON_FUNC_ALWAYS); + assert!(d1.DepthBoundsTestEnable.as_bool()); + assert!(g.describe().contains("depth-bounds")); + + // Without a DSV format, DepthEnable stays false so D3D12 validation is happy. + g.depth_format = DXGI_FORMAT_UNKNOWN; + let d_unknown = g.depth1(); + assert!(!d_unknown.DepthEnable.as_bool()); + assert!(d_unknown.DepthBoundsTestEnable.as_bool()); + + // When DepthEnable is already true, the caller's comparison and write mask stay intact. + g.depth_format = DXGI_FORMAT_D32_FLOAT; + g.depth.DepthEnable = true.into(); + g.depth.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL; + g.depth.DepthFunc = D3D12_COMPARISON_FUNC_GREATER_EQUAL; + let d_explicit = g.depth1(); + assert!(d_explicit.DepthEnable.as_bool()); + assert_eq!(d_explicit.DepthWriteMask, D3D12_DEPTH_WRITE_MASK_ALL); + assert_eq!(d_explicit.DepthFunc, D3D12_COMPARISON_FUNC_GREATER_EQUAL); + } + + fn device_supports_depth_bounds_sm60(device: &ID3D12Device) -> bool { + let mut opts2 = D3D12_FEATURE_DATA_D3D12_OPTIONS2::default(); + let mut model = D3D12_FEATURE_DATA_SHADER_MODEL { + HighestShaderModel: D3D_SHADER_MODEL_6_0, + }; + // SAFETY: queries `D3D12_FEATURE_D3D12_OPTIONS2` and `D3D12_FEATURE_SHADER_MODEL`. + let ok = unsafe { + device + .CheckFeatureSupport( + D3D12_FEATURE_D3D12_OPTIONS2, + (&raw mut opts2).cast(), + size_of_val(&opts2) as u32, + ) + .is_ok() + && device + .CheckFeatureSupport( + D3D12_FEATURE_SHADER_MODEL, + (&raw mut model).cast(), + size_of_val(&model) as u32, + ) + .is_ok() + }; + ok && opts2.DepthBoundsTestSupported.as_bool() + && model.HighestShaderModel.0 >= D3D_SHADER_MODEL_6_0.0 + } + + #[test] + fn depth_bounds_without_depth_test_filters_on_warp_and_in_parallel() { + use windows::Win32::System::Threading::{CreateEventW, INFINITE, WaitForSingleObject}; + use windows::core::Interface; + + let Some(dxc) = dxc() else { + eprintln!("no PC dxc.exe; skipped"); + return; + }; + let dir = tempfile::tempdir().unwrap(); + let vs = compile(&dxc, dir.path(), VS, "vs_6_0"); + let ps = compile(&dxc, dir.path(), PS, "ps_6_0"); + + let run_parallel_depth_bounds_check = |device: &ID3D12Device, label: &'static str| { + let Ok((root, _)) = root_signature(device, &[], &[], false) else { + eprintln!("{label}: root signature unavailable; skipped"); + return; + }; + let mut g = GraphicsState::default(); + #[repr(C, align(8))] + struct Sub21(u32, D3D12_DEPTH_STENCIL_DESC1); + let sub = Sub21( + 21, + D3D12_DEPTH_STENCIL_DESC1 { + DepthEnable: false.into(), + DepthWriteMask: D3D12_DEPTH_WRITE_MASK_ZERO, + DepthFunc: D3D12_COMPARISON_FUNC_ALWAYS, + DepthBoundsTestEnable: true.into(), + ..Default::default() + }, + ); + // SAFETY: `sub` is a complete subobject 21. + unsafe { g.read(21, (&raw const sub).cast()) }; + g.rasterizer.CullMode = D3D12_CULL_MODE_NONE; + g.targets.NumRenderTargets = 1; + g.targets.RTFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; + g.depth_format = DXGI_FORMAT_D32_FLOAT; + + let desc = D3D12_GRAPHICS_PIPELINE_STATE_DESC { + // SAFETY: borrowed pointer, never released by the descriptor. + pRootSignature: unsafe { std::mem::transmute_copy(&root) }, + VS: code(&vs), + PS: code(&ps), + BlendState: g.blend, + SampleMask: g.sample_mask, + RasterizerState: g.rasterizer, + DepthStencilState: g.depth, + IBStripCutValue: g.strip_cut, + PrimitiveTopologyType: D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, + NumRenderTargets: 1, + RTVFormats: g.targets.RTFormats, + DSVFormat: g.depth_format, + SampleDesc: g.samples, + ..Default::default() + }; + let pso = graphics_depth_bounds_pipeline(device, &root, &desc, g.depth1(), None) + .expect("depth-bounds PSO made"); + + // SAFETY: creates a direct command queue for isolated parallel submissions. + let queue: ID3D12CommandQueue = unsafe { + device.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC { + Type: D3D12_COMMAND_LIST_TYPE_DIRECT, + ..Default::default() + }) + } + .unwrap(); + + std::thread::scope(|s| { + for worker in 0..4usize { + let (device, queue, root, pso) = (&device, &queue, &root, &pso); + s.spawn(move || { + // SAFETY: per-thread D3D12 resources, heaps, allocator, command list, fence, and event. + unsafe { + let rtv_heap: ID3D12DescriptorHeap = device + .CreateDescriptorHeap(&D3D12_DESCRIPTOR_HEAP_DESC { + Type: D3D12_DESCRIPTOR_HEAP_TYPE_RTV, + NumDescriptors: 1, + ..Default::default() + }) + .unwrap(); + let dsv_heap: ID3D12DescriptorHeap = device + .CreateDescriptorHeap(&D3D12_DESCRIPTOR_HEAP_DESC { + Type: D3D12_DESCRIPTOR_HEAP_TYPE_DSV, + NumDescriptors: 2, + ..Default::default() + }) + .unwrap(); + let rtv = rtv_heap.GetCPUDescriptorHandleForHeapStart(); + let dsv_rw = dsv_heap.GetCPUDescriptorHandleForHeapStart(); + let dsv_ro = D3D12_CPU_DESCRIPTOR_HANDLE { + ptr: dsv_rw.ptr + + device.GetDescriptorHandleIncrementSize( + D3D12_DESCRIPTOR_HEAP_TYPE_DSV, + ) as usize, + }; + + let default_heap = D3D12_HEAP_PROPERTIES { + Type: D3D12_HEAP_TYPE_DEFAULT, + ..Default::default() + }; + let color_desc = D3D12_RESOURCE_DESC { + Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D, + Width: 4, + Height: 4, + DepthOrArraySize: 1, + MipLevels: 1, + Format: DXGI_FORMAT_R8G8B8A8_UNORM, + SampleDesc: DXGI_SAMPLE_DESC { + Count: 1, + Quality: 0, + }, + Flags: D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, + ..Default::default() + }; + let mut color: Option = None; + device + .CreateCommittedResource( + &default_heap, + D3D12_HEAP_FLAG_NONE, + &color_desc, + D3D12_RESOURCE_STATE_RENDER_TARGET, + Some(&D3D12_CLEAR_VALUE { + Format: DXGI_FORMAT_R8G8B8A8_UNORM, + Anonymous: D3D12_CLEAR_VALUE_0 { Color: [0.0; 4] }, + }), + &mut color, + ) + .unwrap(); + let color = color.unwrap(); + + let depth_desc = D3D12_RESOURCE_DESC { + Format: DXGI_FORMAT_D32_FLOAT, + Flags: D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL, + ..color_desc + }; + let mut depth: Option = None; + device + .CreateCommittedResource( + &default_heap, + D3D12_HEAP_FLAG_NONE, + &depth_desc, + D3D12_RESOURCE_STATE_DEPTH_WRITE, + Some(&D3D12_CLEAR_VALUE { + Format: DXGI_FORMAT_D32_FLOAT, + Anonymous: D3D12_CLEAR_VALUE_0 { + DepthStencil: D3D12_DEPTH_STENCIL_VALUE { + Depth: 0.5, + Stencil: 0, + }, + }, + }), + &mut depth, + ) + .unwrap(); + let depth = depth.unwrap(); + + device.CreateRenderTargetView(&color, None, rtv); + device.CreateDepthStencilView(&depth, None, dsv_rw); + let ro_desc = D3D12_DEPTH_STENCIL_VIEW_DESC { + Format: DXGI_FORMAT_D32_FLOAT, + ViewDimension: D3D12_DSV_DIMENSION_TEXTURE2D, + Flags: D3D12_DSV_FLAG_READ_ONLY_DEPTH, + ..Default::default() + }; + device.CreateDepthStencilView(&depth, Some(&ro_desc), dsv_ro); + + let mut readback: Option = None; + device + .CreateCommittedResource( + &D3D12_HEAP_PROPERTIES { + Type: D3D12_HEAP_TYPE_READBACK, + ..Default::default() + }, + D3D12_HEAP_FLAG_NONE, + &D3D12_RESOURCE_DESC { + Dimension: D3D12_RESOURCE_DIMENSION_BUFFER, + Width: 1024, + Height: 1, + DepthOrArraySize: 1, + MipLevels: 1, + SampleDesc: DXGI_SAMPLE_DESC { + Count: 1, + Quality: 0, + }, + Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR, + ..Default::default() + }, + D3D12_RESOURCE_STATE_COPY_DEST, + None, + &mut readback, + ) + .unwrap(); + let readback = readback.unwrap(); + + let alloc: ID3D12CommandAllocator = device + .CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT) + .unwrap(); + let list: ID3D12GraphicsCommandList = device + .CreateCommandList( + 0, + D3D12_COMMAND_LIST_TYPE_DIRECT, + &alloc, + None, + ) + .unwrap(); + list.Close().unwrap(); + let list1: ID3D12GraphicsCommandList1 = list.cast().unwrap(); + let fence: ID3D12Fence = + device.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap(); + let event = CreateEventW(None, false, false, None).unwrap(); + let mut fence_val = 0u64; + + let cases = [ + (0.6f32, 1.0f32, false, 0u8), + (0.0f32, 0.4f32, true, 0u8), + (0.4f32, 0.6f32, false, 255u8), + (0.5f32, 0.5f32, true, 255u8), + ]; + + for iter in 0..8usize { + let (lo, hi, read_only, expected) = + cases[(worker + iter) % cases.len()]; + alloc.Reset().unwrap(); + list.Reset(&alloc, None).unwrap(); + list.ClearRenderTargetView(rtv, &[0.0; 4], None); + list.ClearDepthStencilView( + dsv_rw, + D3D12_CLEAR_FLAG_DEPTH, + 0.5, + 0, + None, + ); + if read_only { + list.ResourceBarrier(&[crate::host::transition( + &depth, + D3D12_RESOURCE_STATE_DEPTH_WRITE, + D3D12_RESOURCE_STATE_DEPTH_READ, + )]); + } + let active_dsv = if read_only { dsv_ro } else { dsv_rw }; + list1.OMSetDepthBounds(lo, hi); + list.OMSetRenderTargets(1, Some(&rtv), false, Some(&active_dsv)); + list.RSSetViewports(&[D3D12_VIEWPORT { + TopLeftX: 0.0, + TopLeftY: 0.0, + Width: 4.0, + Height: 4.0, + MinDepth: 0.0, + MaxDepth: 1.0, + }]); + list.RSSetScissorRects(&[windows::Win32::Foundation::RECT { + left: 0, + top: 0, + right: 4, + bottom: 4, + }]); + list.SetGraphicsRootSignature(root); + list.SetPipelineState(pso); + list.IASetPrimitiveTopology( + windows::Win32::Graphics::Direct3D::D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST, + ); + list.DrawInstanced(3, 1, 0, 0); + if read_only { + list.ResourceBarrier(&[crate::host::transition( + &depth, + D3D12_RESOURCE_STATE_DEPTH_READ, + D3D12_RESOURCE_STATE_DEPTH_WRITE, + )]); + } + list.ResourceBarrier(&[crate::host::transition( + &color, + D3D12_RESOURCE_STATE_RENDER_TARGET, + D3D12_RESOURCE_STATE_COPY_SOURCE, + )]); + let dst = D3D12_TEXTURE_COPY_LOCATION { + pResource: std::mem::transmute_copy(&readback), + Type: D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT, + Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { + PlacedFootprint: D3D12_PLACED_SUBRESOURCE_FOOTPRINT { + Offset: 0, + Footprint: D3D12_SUBRESOURCE_FOOTPRINT { + Format: DXGI_FORMAT_R8G8B8A8_UNORM, + Width: 4, + Height: 4, + Depth: 1, + RowPitch: 256, + }, + }, + }, + }; + let src = D3D12_TEXTURE_COPY_LOCATION { + pResource: std::mem::transmute_copy(&color), + Type: D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, + Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { + SubresourceIndex: 0, + }, + }; + list.CopyTextureRegion(&dst, 0, 0, 0, &src, None); + list.ResourceBarrier(&[crate::host::transition( + &color, + D3D12_RESOURCE_STATE_COPY_SOURCE, + D3D12_RESOURCE_STATE_RENDER_TARGET, + )]); + list.Close().unwrap(); + + queue + .ExecuteCommandLists(&[Some(list.cast().unwrap())]); + fence_val += 1; + queue.Signal(&fence, fence_val).unwrap(); + fence.SetEventOnCompletion(fence_val, event).unwrap(); + WaitForSingleObject(event, INFINITE); + + let mut ptr = std::ptr::null_mut(); + readback.Map(0, None, Some(&mut ptr)).unwrap(); + let pixel = *ptr.cast::(); + readback.Unmap(0, None); + assert_eq!( + pixel, expected, + "{label} worker {worker} iter {iter} bounds [{lo}, {hi}] read_only={read_only}" + ); + } + let _ = windows::Win32::Foundation::CloseHandle(event); + } + }); + } + }); + }; + + let mut tested_luid = None; + if let Ok(warp_adapter) = crate::host::warp_adapter() { + let mut warp_dev: Option = None; + // SAFETY: creates a standalone WARP device for software depth-bounds verification. + if unsafe { + D3D12CreateDevice( + &warp_adapter, + windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_12_0, + &mut warp_dev, + ) + } + .is_ok() + && let Some(warp_dev) = warp_dev + && device_supports_depth_bounds_sm60(&warp_dev) + { + // SAFETY: `GetAdapterLuid` is a plain query on a live device. + let luid = unsafe { warp_dev.GetAdapterLuid() }; + tested_luid = Some((luid.HighPart, luid.LowPart)); + run_parallel_depth_bounds_check(&warp_dev, "warp"); + } else { + eprintln!("WARP adapter lacks SM 6.0 depth-bounds support; skipped WARP pass"); + } + } else { + eprintln!("no WARP adapter; skipped WARP pass"); + } + if let Some(host) = host() + && device_supports_depth_bounds_sm60(&host.device) + { + // SAFETY: `GetAdapterLuid` is a plain query on a live device. + let luid = unsafe { host.device.GetAdapterLuid() }; + if tested_luid != Some((luid.HighPart, luid.LowPart)) { + run_parallel_depth_bounds_check(&host.device, "host"); + } + } + } + fn element(format: DXGI_FORMAT, offset: u32) -> D3D12_INPUT_ELEMENT_DESC { D3D12_INPUT_ELEMENT_DESC { SemanticName: PCSTR(c"TEXCOORD".as_ptr().cast()), diff --git a/docs/README.md b/docs/README.md index 289ff89791..dccea162da 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,7 +13,7 @@ method, scope and caveats. No game data is included. | [boot_leads.md](boot_leads.md) | Open leads that may move the retail boot further (TLS at module index 0, feature level at device creation, command-list replay, descriptor words, shader corpus count, frame pacing), each with where it lands, how to implement it and how to test it, and a status table: BL-2, BL-5 and BL-6 are done, BL-3 and BL-4 have open pull requests, BL-1 waits for a retail confirmation. | | [rpf.md](rpf.md) | RPF9 archive layout, the carve tools and the unreadable encrypted TOC. | | [linux.md](linux.md) | Linux in one page: what runs natively and what runs under Wine or Proton, the Ubuntu packages, `Build.sh`, the runtime cross-build, and why there is no native Linux `gta6rt`. | -| [running.md](running.md) | Running the game per platform and GPU (Linux/Wine with AMD, Linux/Proton and Windows with NVIDIA, Windows with AMD, Intel, macOS): build, shaders, pipeline pre-compile, driver settings, environment, what to expect; each value measured by us, reported by others (linked) or TBD. | +| [running.md](running.md) | Running the game per platform and GPU (Linux/Wine with AMD and NVIDIA, Linux/Proton and Windows with NVIDIA, Windows with AMD, Intel, macOS): build, shaders, pipeline pre-compile, driver settings, environment, what to expect; each value measured by us, reported by others (linked) or TBD. | | [testing.md](testing.md) | Running the GPU tests on your own GPU: setup per OS, wave64 emulation, running without a GPU on Mesa llvmpipe, and known problems. | | [gpu_test_results.md](gpu_test_results.md) | Published GPU test results by hardware, driver and commit, with pass, skip and failure counts. | | [progress_dashboard.md](progress_dashboard.md) | A local page of what works, what changed since it last passed and what blocks next: unit and runtime tests, the translator contract by confirmation method, measured imports, corpus counts and, with `--github`, CI and the D3D- items (`tools/progress_dashboard.py`). | diff --git a/docs/linux_proton.md b/docs/linux_proton.md index 8117a01f53..fd73f6cb34 100644 --- a/docs/linux_proton.md +++ b/docs/linux_proton.md @@ -106,7 +106,10 @@ What it does: the run folder's `session/cache`, so it is cold; with a kept cache the caller's variables stay. - **Traces:** `gta6rt --run` with `--trace` and `--trace-d3d12`, a fresh `--overlay` and save folder in the run folder. Every other `LEONIDA_*` variable reaches the runtime unchanged, so `LEONIDA_INPUT_SCRIPT=a@210,a@240` - presses A as above. Arguments after `--` go to `gta6rt`. + presses A as above. Arguments after `--` go to `gta6rt`. The + [Linux, Wine, NVIDIA section of running.md](running.md#linux-wine-nvidia-geforce-rtx-3060-12-gb) reports runs + with a local change that leaves this trace off (`LEONIDA_NO_TRACE_D3D12=1`); `main`'s script always passes + `--trace-d3d12`. - **Summary:** `tools/game_run_summary.py` prints the run time, how it ended, exceptions by code, D3D12 calls by outcome, presents, the most frequent failing calls and the `[rt]` lines by category with numbers masked. It never prints a log line. `--screenshot-every S` captures the game window into the run folder (ImageMagick's `import` and diff --git a/docs/running.md b/docs/running.md index a6c003ba2f..b155f4d76a 100644 --- a/docs/running.md +++ b/docs/running.md @@ -171,6 +171,46 @@ Reported by others: [#1608, comment 7184700506](https://github.com/ubiquitariani The black stretch before it is graphics pipelines of 1-2.6 MB SPIR-V compiling one at a time, 5-10 s each. - **Known problems:** nothing ray-traced is in the picture. +## Linux, Wine, NVIDIA (GeForce RTX 3060 12 GB) + +Reported by others: [#2464, comment 7299367912](https://github.com/ProjectLeonida/mandy/issues/2464#issuecomment-7299367912) +and [comment 7300173397](https://github.com/ProjectLeonida/mandy/issues/2464#issuecomment-7300173397) (desktop, 31 GB +of RAM, no swap, 12 threads; NVIDIA 620.70.10; Debian 13, kernel 6.12.118; Wine 11.22 staging). Not run by us. + +- **Build:** clang-cl + xwin cross-build of `main` `d8ca18240`, RelWithDebInfo. +- **Shaders:** `make_game.py --stages check,shaders,runtime --wave64-emulate on`: 26,503 main, 2,684 library, + 2,713 FSPX, 52 BVH and 12 executable sets, `spirv-val` clean. +- **Pipeline pre-compile:** none. The runs reused a 1.7 GB journal that three earlier runs had filled; the opening + sequence's night scene alone built 763 graphics and 619 compute pipelines (2,296 modules, 732 MiB of SPIR-V, + 45 minutes in `vkCreate*Pipeline` across the run), and the builds ended within two minutes of the last present. +- **Driver and OS:** no GPU timeout change. The runs sat in a systemd cgroup with `MemoryMax=24G` and no swap. With + the defaults one run was killed at 22.3 GB, 21 minutes in, before a world frame; another had drawn the city night + street when it was killed at 22.2 GB. The 1024/2048 arenas hold the earlier world runs at 19-20 GB, but the later + shots still reached 23.6 GB. +- **Environment:** `LEONIDA_DEVICE_TYPE=6`, `LEONIDA_MAP_READBACK=1`, `LEONIDA_COMPUTE_WARMUP=0`, + `LEONIDA_SERIAL_BIG_COMPILES=0`, `LEONIDA_FRAME_PACING=1`, `LEONIDA_PRESENT_NO_TEAR=1`, `LEONIDA_SUBMIT_ASYNC=4`, + `LEONIDA_KEYBOARD_PAD=always`, `LEONIDA_ARENA_MB=1024`, `LEONIDA_GEOMETRY_MB=2048`, + `LEONIDA_TITLE_WINDOWS_MB=4096`, `LEONIDA_SKIP_COMPUTE=,...` with the names of this pack's 723 + library compute programs of 2 MiB or more (the page's 724 is the maintainers' count; 676 of theirs are + ray-tracing resolve), and the title's watchdog off with its KICK values set. `LEONIDA_STRAY_RO_HEAL=1` is needed + on this build and driver: without it a run ended at 47 s (exit 5) writing to a title page the runtime had marked + read-only. That last detail is from an earlier run on the same machine, not in the two linked comments. +- **Command:** `scripts/run_game_wine.sh --build --exe + --game-dir --shaders --out --seconds 3600 --visible`, with + the arguments described in [linux_proton.md](linux_proton.md#running-the-game-under-wine-with-one-command). These + runs used a local change to the script: `LEONIDA_NO_TRACE_D3D12=1` makes it pass no `--trace-d3d12`, while `main` + always passes it; the trace costs a mutex, an fprintf and an fflush per D3D12 call, so a run with `main`'s script + writes it too. +- **What to expect:** the first-run UI at 30 frames/s, the account picker, then the story load; with a warm journal + the first world frame is 20-34 minutes in. The opening sequence draws at 1-3 frames per 10-16 s, 0.06-0.30 + frames/s, with cgroup memory at 19-20 GB and up to 23.6 GB later in the sequence. 12 GB of VRAM does not hold the + scene; the earlier runs spilled VRAM to host memory once the 12 GB card was full. +- **Known problems:** the night scene ends a run in one of two ways. With the list values on, one console value + wait stayed unmet for 101 minutes with no presents and no queue calls, and no gate was released unmet, including + in the stalled case; with `LEONIDA_LIST_VALUES=0` the scene draws further and then the device is lost (five + compute queues in flight, and `VK_EXT_device_fault` gave no address on this driver). What the picture lacks there + is not measured. + ## Windows, NVIDIA Reported by others: [#2019](https://github.com/ubiquitarianism/leonida/issues/2019) (RTX 5090 32 GB, driver 616.92, diff --git a/docs/testing.md b/docs/testing.md index ec629ccb36..abfd277cd0 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -150,8 +150,11 @@ python -I scripts/red_green.py target dir takes several GB; delete the folder (and run `git worktree prune`) when done. - It prints the tests that go from red to green, those that pass on red and fail on green, those that fail on both (failing on `main` too), and those found on one side only. The verdict is one of: `red then green` (exit 0), - `no red`, `red does not build`, `green fails`, `red not constructible`, `green not constructible`, `no tests ran` - (exit 1). `--json` prints all of it. + `no red`, `red does not build`, `green fails`, `red not constructible`, `green not constructible`, `no tests ran`, + `compiler crashed` (exit 1). `--json` prints all of it. +- A crashed compiler is not a build error: rustc or a build script ending with a Windows crash status (such as + 0xC0000005, an access violation), an internal compiler error, or a failed allocation. That side builds again once, + and the report says so; a second crash gives `compiler crashed`. Run it again later, or on another machine. - `red does not build` is the case the fork-CI steps above call "does not build without the pull request's new file": the test needs the new code, which does not show that it catches the bug. - `--crate ` adds a crate, `--no-cargo` or `--no-python` leaves one kind out, `--base ` tests on another diff --git a/gpu-test-results/RadeonProVegaII-RADV.txt b/gpu-test-results/RadeonProVegaII-RADV.txt new file mode 100644 index 0000000000..2831222fd5 --- /dev/null +++ b/gpu-test-results/RadeonProVegaII-RADV.txt @@ -0,0 +1,48 @@ +GPU: AMD Radeon Pro Vega II (Vega 20 / gfx906, PCI 1002:66a3, 32 GiB HBM2 per GPU) +Driver: Mesa RADV 26.0.8-1ubuntu0.3, Vulkan 1.4.335; deviceName: AMD Radeon Graphics (RADV VEGA20) +Subgroup: default/min/max 64/64/64, native64_compute=true. Geometry shaders: yes. + No VK_EXT_mesh_shader or VK_KHR_fragment_shader_barycentric; per_vertex_inputs=false. +OS/host: Ubuntu 26.04 LTS x86_64, kernel 7.0.0-43-generic, Intel Xeon W-3245, 373 GiB OS-visible RAM. +Commit: a73a57e1339be072baf5522351c8ec7f1482b56b (upstream main) +Tools: GCC 15.2.0, CMake 4.2.3, Ninja 1.13.2, Vulkan headers 1.4.341, + LLVM/llvm-mc 21.1.8 (AMDGPU), SPIRV-Tools 2026.1, Python 3.14.4. + +Three identical Vulkan devices enumerated, not pooled. All runs pinned one physical GPU at a time +with the RADV ICD and DRI_PRIME=pci-!; llvmpipe excluded. The full suite and pipeline check +used PCI 0000:1e:00.0; the dedicated wave64 graphics suite used 0000:0b:00.0. Release harnesses +and scripts came from the same commit. LEONIDA_W64_EMULATE=0; no forced 32-wide subgroup. + +run_gpu_tests.py --require-pass --assembler spirv-as (unfiltered): + 277 inputs; 276 translated, all 276 passed spirv-val. The f16 fallback refused ps_ij_computed. + 209/268 passed, 58 skipped, 1 failed (exit 1). + Skips: 27 require 32 lanes on request; 19 delegated to or require Windows D3D12; 6 mesh; + 4 require native fragment barycentrics; 1 computed I/J; 1 delegated to w64_graphics.py. + +vk_pipeline_check on that synthetic index (--jobs 4 --large-parallel 1): + 276 modules created, 0 failed. 266 pipelines created, 10 skipped, 0 failed (exit 0). + CS 139/139, GS 1/1, VS 12/12, PS 114/118 (4 barycentric skips), MS 0/6 (6 mesh skips). + Pipeline creation is not shader execution and does not establish wave32 semantics on this GPU. + +LEONIDA_BARY_FALLBACK=1, same unfiltered run on 0000:1e:00.0: + All four fixtures skipped above for native barycentrics passed through the geometry fallback: + ps_bary, ps_persp_bary, ps_uniform_branch and ps_scc_mask32. + 213/268 passed, 54 skipped, 1 failed (exit 1). Translation and spirv-val stayed at 276/277; + ps_ij_computed was still skipped on this main commit. The only failure was still cs_imgatomic_ext. + +check.py on the full run_gpu_tests.py output, with the same harness build and f16 fallback: + 159/234 passed, 74 skipped, 1 failed (exit 1), the same cs_imgatomic_ext readback. + Standalone, unfiltered build.py stopped earlier: llvm-mc cannot encode the text-only cs_dpp_cmp + DPP compare. The check.py counts above use the combined runner's output, not this partial build. + +w64_graphics.py on the dedicated fixtures assembled by build.py: + 18/30 passed (10 tier A, 8 tier B), 12 tier C skipped, 0 failed. This fixed-64 adapter cannot + provide both widths for the partition comparison; no external W64G_REF was supplied. + +Failure control: cs_imgatomic_ext reported six incorrect SINT words in its 3D cases. On the same +GPU, changing only the synthetic input to the corrected volume descriptor from #1518 (1bbf8a9b), +without changing the translator, harness or expectations, passed 1/1: all 64 words of each of the +UINT image, SINT image and volume matched. The original failure is included above; it is a fixture +descriptor mismatch, not evidence of a Vega wave64 execution bug. + +Hand-written repository fixtures only; no game files used for this record. +AI-assisted: yes diff --git a/scripts/red_green.py b/scripts/red_green.py index 1af2fd1677..7d8305f453 100644 --- a/scripts/red_green.py +++ b/scripts/red_green.py @@ -20,7 +20,8 @@ toolchain applies) and the changed `tests/**/test*.py` files with unittest, on both sides, in one worktree and one cargo target dir under --work-dir (default `/red-green`), red first. It keeps both between runs: the second run on the same crates builds only what changed. C++ `runtime/` tests are not run here (docs/testing.md has -the fork-CI way). +the fork-CI way). A side whose compiler crashed (a Windows crash status of rustc or a build script, an internal +compiler error, a failed allocation) builds again once; a second crash is the verdict `compiler crashed`. Exit 0: at least one test went from red to green and no test that passes on red fails on green. 1: any other verdict. 2: a usage or git error. @@ -272,7 +273,16 @@ def crates_of(tree: Path, paths: list[str]) -> list[str]: return names -def cargo_tests(tree: Path, crates: list[str], cargo: str, target: Path) -> dict: +# A crashed compiler, not an error in the code: rustc or a build script ending with a Windows crash status +# (0xC0000005 access violation, 0xC00000FD stack overflow, 0xC0000409 abort, ...), an internal compiler error, or a +# failed allocation. Such a side runs again once (a crash of a test binary stays a test result). +COMPILER_CRASH = re.compile( + r"process didn't exit successfully: `[^`]*(?:rustc|build-script-\w+)[^`]*` \(exit (?:code|status): " + r"(0x[cC][0-9a-fA-F]{7}(?:, \w+)?)\)" + r"|(internal compiler error)|(the compiler unexpectedly panicked)|(memory allocation of \d+ bytes failed)") + + +def cargo_once(tree: Path, crates: list[str], cargo: str, target: Path) -> dict: cmd = [sys.executable, cargo] if cargo.endswith(".py") else [cargo] cmd += ["test", "--locked", "--no-fail-fast"] + [a for c in crates for a in ("-p", c)] env = dict(os.environ, CARGO_TARGET_DIR=str(target)) @@ -290,7 +300,21 @@ def cargo_tests(tree: Path, crates: list[str], cargo: str, target: Path) -> dict elif error is None and CARGO_ERROR.match(line): error = line.strip() no_build = r.returncode != 0 and not tests - return {"tests": tests, "no_build": (error or f"cargo exit {r.returncode}") if no_build else None} + crash = COMPILER_CRASH.search(out) if no_build else None + return {"tests": tests, "no_build": (error or f"cargo exit {r.returncode}") if no_build and not crash else None, + "crash": next(g for g in crash.groups() if g) if crash else None} + + +def cargo_tests(tree: Path, crates: list[str], cargo: str, target: Path) -> dict: + first = cargo_once(tree, crates, cargo, target) + if not first["crash"]: + return {"tests": first["tests"], "no_build": first["no_build"]} + print(f"red_green: the compiler crashed ({first['crash']}), running again", file=sys.stderr) + again = cargo_once(tree, crates, cargo, target) + result = {"tests": again["tests"], "no_build": again["no_build"], "rerun_after": first["crash"]} + if again["crash"]: + result["compiler_crashed"] = again["crash"] + return result PY_TEST = re.compile(r"^(\w+) \(([\w.]+)\)(?:\n[^\n]*?)? \.\.\. (ok|FAIL|ERROR|skipped|expected failure|unexpected success)", @@ -318,12 +342,14 @@ def python_tests(tree: Path, files: list[str]) -> dict: def side(tree: Path, crates: list[str], py_files: list[str], cargo: str, target: Path) -> dict: - result = {"tests": {}, "no_build": []} + result = {"tests": {}, "no_build": [], "compiler_crashed": None, "rerun_after": None} for part in ([cargo_tests(tree, crates, cargo, target)] if crates else []) + \ ([python_tests(tree, py_files)] if py_files else []): result["tests"].update(part["tests"]) if part["no_build"]: result["no_build"].append(part["no_build"]) + for key in ("compiler_crashed", "rerun_after"): + result[key] = result[key] or part.get(key) return result @@ -355,6 +381,9 @@ def compare(red: dict | None, green: dict | None) -> dict: def verdict(red_why: str | None, green_why: str | None, red: dict | None, green: dict | None, rows: dict) -> str: if green_why: return "green not constructible" + # Twice in a row on a side: the build cannot tell anything; not a code error, run it again later. + if any(s and s.get("compiler_crashed") for s in (red, green)): + return "compiler crashed" green_failed = rows["regressions"] or any(r.endswith("(failed)") for r in rows["only_on_green"]) if green and green["no_build"] or green_failed: return "green fails" @@ -379,6 +408,10 @@ def report(r: dict) -> str: s = r[name] if s and s["no_build"]: out.append(f"{name} does not build: " + "; ".join(s["no_build"])) + if s and s.get("compiler_crashed"): + out.append(f"{name}: the compiler crashed twice ({s['compiler_crashed']})") + elif s and s.get("rerun_after"): + out.append(f"{name}: the compiler crashed once ({s['rerun_after']}), the second build is the one shown") rows = r["rows"] labels = {"red_to_green": "red then green", "regressions": "pass on red, FAIL on green", "fail_on_both": "fail on both (failing on the base too?)", "only_on_green": "only on green", diff --git a/tests/semantic/test_salu_wqm32.py b/tests/semantic/test_salu_wqm32.py index 5ab78a0695..3d0f23c391 100644 --- a/tests/semantic/test_salu_wqm32.py +++ b/tests/semantic/test_salu_wqm32.py @@ -5,7 +5,7 @@ Covers both: - Data path (32-bit nibble expansion + SCC) via tools/rdna2spirv.py -> spirv_mini_interp.py. - Lane-mask path (32-lane wave32, 8 quads) via tools/rdna2spirv.py -> spirv_wave_interp.py (vertex stage - uses OpGroupNonUniformShuffle for quad_any; fragment/compute stages are checked for OpGroupNonUniformQuadSwap). + uses OpGroupNonUniformBallot for quad_any; the fragment stage is checked for OpGroupNonUniformQuadSwap). Standard library only; no game data. """ diff --git a/tests/test_red_green.py b/tests/test_red_green.py index 4d20e5c902..5f4b895298 100644 --- a/tests/test_red_green.py +++ b/tests/test_red_green.py @@ -47,7 +47,32 @@ ''' +# A cargo whose rustc crashes like an access violation on Windows: always, or on its first call only (a marker file +# beside it), then the stub above. +CRASH_STUB = r''' +import os, runpy, sys +here = os.path.dirname(os.path.abspath(__file__)) +mark = os.path.join(here, "crashed") +if __MODE__ == "always" or not os.path.exists(mark): + open(mark, "w").close() + print(" Compiling foo v0.1.0") + print("error: could not compile `foo` (lib test)") + print("") + print("Caused by:") + print(" process didn't exit successfully: `rustc --crate-name foo --edition=2021 src/lib.rs --test` " + "(exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)") + sys.exit(101) +runpy.run_path(os.path.join(here, "cargo_stub.py"), run_name="__main__") +''' + + class Repo: + def crash_stub(self, mode): + path = os.path.join(self.tmp.name, f"cargo_crash_{mode}.py") + with open(path, "w", encoding="utf-8") as f: + f.write(CRASH_STUB.replace("__MODE__", repr(mode))) + return path + def __init__(self, test): self.tmp = tempfile.TemporaryDirectory(prefix="red-green-test-", ignore_cleanup_errors=True) test.addCleanup(self.tmp.cleanup) @@ -211,6 +236,50 @@ def test_a_test_of_a_new_tool_does_not_import_on_red(self): self.assertEqual(code, 1) +class CompilerCrash(unittest.TestCase): + def fixed_repo(self): + repo = crate_repo(self) + repo.commit("fix", {"d3d12/crates/foo/src/lib.rs": LIB.replace(" 1\n", " 2\n").replace( + "fn value_is_one() {\n assert_eq!(super::value(), 1);", + "fn value_is_two() {\n assert_eq!(super::value(), 2);")}) + return repo + + def test_a_compiler_that_crashes_once_is_run_again(self): + repo = self.fixed_repo() + code, r, err = repo.run("--cargo", repo.crash_stub("once")) + self.assertEqual((code, r["verdict"]), (0, "red then green"), r) + self.assertEqual(r["red"]["rerun_after"], "0xc0000005, STATUS_ACCESS_VIOLATION") + self.assertIsNone(r["red"]["compiler_crashed"]) + self.assertIn("the compiler crashed (0xc0000005, STATUS_ACCESS_VIOLATION), running again", err) + + def test_a_compiler_that_crashes_twice_is_not_a_build_error(self): + repo = self.fixed_repo() + code, r, _ = repo.run("--cargo", repo.crash_stub("always")) + self.assertEqual((code, r["verdict"]), (1, "compiler crashed"), r) + self.assertEqual(r["red"]["compiler_crashed"], "0xc0000005, STATUS_ACCESS_VIOLATION") + self.assertEqual(r["red"]["no_build"], []) + self.assertIn("red: the compiler crashed twice", rg.report(r)) + + def test_what_counts_as_a_crashed_compiler(self): + crashed = [ + " process didn't exit successfully: `C:\\x\\rustc.exe --crate-name a` (exit code: 0xc00000fd, STATUS_STACK_OVERFLOW)", + " process didn't exit successfully: `C:\\t\\build\\a-1\\build-script-build` (exit code: 0xc0000409)", + "error: internal compiler error: compiler/rustc_middle/src/ty/mod.rs:1: oops", + "note: the compiler unexpectedly panicked. this is a bug.", + "memory allocation of 1048576 bytes failed", + ] + for line in crashed: + self.assertIsNotNone(rg.COMPILER_CRASH.search(line), line) + not_crashed = [ + # A test binary that crashes is a test result, and an ordinary failure is a build error. + " process didn't exit successfully: `C:\\t\\debug\\deps\\foo-0123456789abcdef.exe` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)", + " process didn't exit successfully: `C:\\x\\rustc.exe --crate-name a` (exit code: 1)", + "error[E0425]: cannot find value `x` in this scope", + ] + for line in not_crashed: + self.assertIsNone(rg.COMPILER_CRASH.search(line), line) + + class Hunks(unittest.TestCase): def diff(self, old, new): with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmp: diff --git a/tools/rdna2spirv.py b/tools/rdna2spirv.py index 80b641633e..d6f0db65b8 100644 --- a/tools/rdna2spirv.py +++ b/tools/rdna2spirv.py @@ -7281,11 +7281,10 @@ def wave_mask(self, a): def quad_any(self, v): """This lane's value after whole-quad mode: all ones if any of the 4 lanes of its quad (4n .. 4n+3 of the wave) has `v` non-zero, else 0. A quad never crosses the 32/32 half of a wave64, so a 32-wide subgroup is - exact. Without emulation the subgroup's quad ops do it (the invocations of a quad are 4 consecutive subgroup - invocations; in a fragment shader the 2x2 quad, which on hardware is also 4 consecutive lanes; vertex, - geometry and mesh shaders shuffle, as quad operations are only guaranteed in fragment and compute stages); - emulated, the four lanes' values are read through the exchange buffer. Not handled: an absent invocation in - a partial quad (a compute group whose size is not a multiple of 4) gives an undefined value natively.""" + exact. Without emulation the subgroup's ops do it: in a fragment shader the 2x2 quad, which on hardware is + also 4 consecutive lanes; every other stage ballots, so a partial quad (fewer than 4 of the quad's lanes + running, e.g. 2 active lanes of a 32-lane subgroup) is exact too, as a lane's bit is set only when it is + running with `v` non-zero. Emulated, the four lanes' values are read through the exchange buffer.""" b = self.tmp() self.emit(f"{b} = OpSelect %uint {self.tmp_bool_nz(v)} {self.cu(1)} {self.cu(0)}") if self.emulate: @@ -7314,10 +7313,11 @@ def quad_any(self, v): self.emit(f"{o} = OpBitwiseOr %uint {acc} {sw}") acc = o else: - # Non-fragment stages (CS/VS/GS/MS) can have partial quads (subgroup size or thread count not a multiple - # of 4), where QuadSwap or unguarded shuffles from absent lanes are undefined in SPIR-V. Ballot sets bit l - # iff lane l is running with `v != 0`, so extracting this lane's 4-bit quad nibble is exact on any partial - # subgroup up to 128 lanes without needing GroupNonUniformQuad or any shuffle. + # Non-fragment stages (CS/VS/GS/MS) can have partial quads (fewer than 4 of the quad's lanes running: a + # subgroup or workgroup size not a multiple of 4, or a partial wave, e.g. 2 active lanes of a 32-lane + # subgroup), where QuadSwap or unguarded shuffles from absent lanes are undefined in SPIR-V. Ballot sets + # bit l iff lane l is running with `v != 0`, so extracting this lane's 4-bit quad nibble is exact on any + # partial subgroup up to 128 lanes without needing GroupNonUniformQuad or any shuffle. self.uses_subgroup = self.uses_ballot = True nz = self.tmp_bool_nz(v) bal, widx, word, qoff, shifted, acc = (self.tmp() for _ in range(6))