diff --git a/README.md b/README.md index 722483312..1860b399a 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ XCL works only on unpacked game files you already own. It does not download, dec | Feature | State | What it does | Verified by | |---|---|---|---| -| **Shader recompiler** | ✅ | RDNA2 → HLSL → DXIL: VS, PS, CS, mesh (NGG), GS; atomics, LDS, scratch, images, samplers incl. static ones, wave ops, ray-tracing instructions; structured control flow; parallel DXC, disk cache | 26 698 / 26 698 programs of the retail pack; 0 DXC errors on random samples; per-instruction GPU tests | +| **Shader recompiler** | ✅ | RDNA2 → HLSL → DXIL: VS, PS, CS, mesh (NGG), GS; atomics, LDS, scratch, images, samplers incl. static ones, anisotropic cubemap sampling with unclamped explicit gradients, wave ops, ray-tracing instructions; structured control flow; parallel DXC, disk cache | 26 698 / 26 698 programs of the retail pack; 0 DXC errors on random samples; per-instruction GPU tests | | **Pipelines** | ✅ | PSOs from console shaders: VS+PS, CS, MS+PS, VS+GS+PS; root signature with the shaders' static samplers; non-blocking creation – a pipeline whose shaders are not compiled yet gets a stand-in at once and is built in the background | GPU tests drawing the game's own VS / PS pairs, also built in the background | | **D3D12.X compute** | ✅ | console device slots, console descriptor heaps (T# / V# / S#), buffers at their console addresses, compute command lists recorded in the console format and replayed (tables, barriers, clears, copies) | the game's BVH builder and FSR 4 record and run through XCL | | **D3D12.X graphics** | ✅ | device, resources and heaps (also placed in title memory), pipelines; the title's graphics command lists – draws, indirect draws, graphics root arguments, barriers, copies, clears – and command lists recorded by console code, replayed; `PresentX` and frame pacing into an XCL window | Minecraft Preview plays its worlds (millions of draws, none skipped); Fortnite and XDefiant draw their screens | diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs index 216240bd2..cd5eb5005 100644 --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -2321,17 +2321,22 @@ impl Em { match (&cmp, &grads, &lod, &bias) { (Some(z), _, _, _) if has_lz || !ps => format!("float4({t}_T.SampleCmpLevelZero({t}_S, {coord}, {z}).xxxx)"), (Some(z), _, _, _) => format!("float4({t}_T.SampleCmp({t}_S, {}).xxxx)", tail(format!("{coord}, {z}"))), - // cube maps: RDNA takes face-space 2D gradients, HLSL wants direction-space 3D - // ones (and has no clamp form) – the LOD from the gradients and the face size - (None, Some((dx, dy)), _, _) if dim == 3 => { - let len = |x: &[String]| format!("length(float2({}, {}))", x[0], x.get(1).cloned().unwrap_or("0.0f".into())); + (None, Some((dx, dy)), _, _) if dim == 3 && cl.is_some() => { + // Some AMD D3D12 drivers crashed on this SampleGrad clamp overload + // (PR #778). Keep the previous scalar LOD approximation for it. + let len = |g: &[String]| format!("length(float2({}, {}))", g[0], g[1]); let size = format!("{t}_cw"); self.line(&format!("uint {size} = 1u, {t}_ch = 1u, {t}_ce = 1u, {t}_cn = 1u; {t}_T.GetDimensions(0u, {size}, {t}_ch, {t}_ce, {t}_cn);")); let lod = format!("log2(max(max({}, {}) * (float){size}, 1e-8f))", len(dx), len(dy)); format!("{t}_T.SampleLevel({t}_S, {coord}, {})", floor(lod)) } (None, Some((dx, dy)), _, _) => { - let v = |x: &[String]| if x.len() == 1 { x[0].clone() } else { format!("float{}({})", x.len(), x.join(", ")) }; + let v = |x: &[String]| match dim { + // Differentiate cube_dir on this face: its major axis stays constant. + 3 => format!("cube_face_vector(2.0f * {}, 2.0f * {}, 0.0f, {})", x[0], x[1], coords[2]), + _ if x.len() == 1 => x[0].clone(), + _ => format!("float{}({})", x.len(), x.join(", ")), + }; format!("{t}_T.SampleGrad({t}_S, {})", tail(format!("{coord}, {}, {}", v(dx), v(dy)))) } (None, None, Some(l), _) => format!("{t}_T.SampleLevel({t}_S, {coord}, {l})"), @@ -5596,15 +5601,17 @@ float cube_id(float x, float y, float z) { if (abs(z) >= abs(x) && abs(z) >= abs float cube_sc(float x, float y, float z) { if (abs(z) >= abs(x) && abs(z) >= abs(y)) return z < 0.0f ? -x : x; if (abs(y) >= abs(x)) return x; return x < 0.0f ? z : -z; } float cube_tc(float x, float y, float z) { if (abs(z) >= abs(x) && abs(z) >= abs(y)) return -y; if (abs(y) >= abs(x)) return y < 0.0f ? -z : z; return -y; } float cube_ma(float x, float y, float z) { if (abs(z) >= abs(x) && abs(z) >= abs(y)) return 2.0f * z; if (abs(y) >= abs(x)) return 2.0f * y; return 2.0f * x; } +float3 cube_face_vector(float u, float v, float major, float face) { + uint f = ((uint)round(face)) % 8u; + bool neg = (f & 1u) != 0u; + float m = select(neg, -major, major); + return select(f < 2u, float3(m, -v, select(neg, u, -u)), + select(f < 4u, float3(u, m, select(neg, -v, v)), + float3(select(f == 4u, u, -u), -v, select(f == 4u, major, -major)))); +} // AMD cube coordinates (sc/|2ma| + 1.5, tc/|2ma| + 1.5, face) back to a direction float3 cube_dir(float s, float t, float face) { - float u = (s - 1.5f) * 2.0f; float v = (t - 1.5f) * 2.0f; uint f = ((uint)round(face)) % 8u; - if (f == 0u) return float3(1.0f, -v, -u); - if (f == 1u) return float3(-1.0f, -v, u); - if (f == 2u) return float3(u, 1.0f, v); - if (f == 3u) return float3(u, -1.0f, -v); - if (f == 4u) return float3(u, -v, 1.0f); - return float3(-u, -v, -1.0f); + return cube_face_vector((s - 1.5f) * 2.0f, (t - 1.5f) * 2.0f, 1.0f, face); } // the cube of a cube array the face coordinate (face + 8 · slice) is in float cube_slice(float face) { return (float)(((uint)round(face)) / 8u); } diff --git a/crates/xcl/src/gpu/recomp/runner.rs b/crates/xcl/src/gpu/recomp/runner.rs index c9748ab79..a424a31a7 100644 --- a/crates/xcl/src/gpu/recomp/runner.rs +++ b/crates/xcl/src/gpu/recomp/runner.rs @@ -144,8 +144,9 @@ pub struct TestTexture { pub height: u32, /// array slices (cube: 6 per cube) or depth pub depth: u32, + pub mip_levels: u16, pub texel_bytes: u32, - /// tightly packed texels, slice after slice + /// Tightly packed texels in D3D12 subresource order, with mips within each array slice. pub data: Vec, pub uav: bool, } @@ -192,7 +193,7 @@ unsafe fn bind_resources(dev: &ID3D12Device, list: &ID3D12GraphicsCommandList, t AddressU: sm.address, AddressV: sm.address, AddressW: sm.address, - MaxAnisotropy: 1, + MaxAnisotropy: if sm.filter == D3D12_FILTER_ANISOTROPIC { 16 } else { 1 }, ComparisonFunc: D3D12_COMPARISON_FUNC_NEVER, MaxLOD: f32::MAX, ..Default::default() @@ -207,6 +208,7 @@ unsafe fn bind_resources(dev: &ID3D12Device, list: &ID3D12GraphicsCommandList, t let mut total = 0u64; let mut plans = Vec::new(); for t in textures { + assert!(!t.uav || t.mip_levels == 1, "kernel UAV fixtures read back one mip"); let (dim, depth_or_array) = match t.dim { TexDim::D3 => (D3D12_RESOURCE_DIMENSION_TEXTURE3D, t.depth), _ => (D3D12_RESOURCE_DIMENSION_TEXTURE2D, t.depth), @@ -216,13 +218,13 @@ unsafe fn bind_resources(dev: &ID3D12Device, list: &ID3D12GraphicsCommandList, t Width: t.width as u64, Height: t.height, DepthOrArraySize: depth_or_array as u16, - MipLevels: 1, + MipLevels: t.mip_levels, Format: t.format, SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 }, Flags: if t.uav { D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS } else { D3D12_RESOURCE_FLAG_NONE }, ..Default::default() }; - let subs = if t.dim == TexDim::D3 { 1 } else { t.depth }; + let subs = u32::from(t.mip_levels) * if t.dim == TexDim::D3 { 1 } else { t.depth }; let mut fps = vec![D3D12_PLACED_SUBRESOURCE_FOOTPRINT::default(); subs as usize]; let mut size = 0u64; dev.GetCopyableFootprints(&rd, 0, subs, total, Some(fps.as_mut_ptr()), None, None, Some(&mut size)); @@ -236,16 +238,15 @@ unsafe fn bind_resources(dev: &ID3D12Device, list: &ID3D12GraphicsCommandList, t let mut p = std::ptr::null_mut(); up.Map(0, None, Some(&mut p)).map_err(e)?; for (t, fps) in textures.iter().zip(&plans) { - let row = (t.width * t.texel_bytes) as usize; - let slices = t.depth as usize; - for z in 0..slices { - let fp = if t.dim == TexDim::D3 { &fps[0] } else { &fps[z] }; - let slice_pitch = fp.Footprint.RowPitch as usize * t.height as usize; - let zoff = if t.dim == TexDim::D3 { z * slice_pitch } else { 0 }; - for y in 0..t.height as usize { - let src = &t.data[(z * t.height as usize + y) * row..][..row]; - let dst = (p as *mut u8).add(fp.Offset as usize + zoff + y * fp.Footprint.RowPitch as usize); + let mut offset = 0; + for fp in fps { + let row = (fp.Footprint.Width * t.texel_bytes) as usize; + let rows = fp.Footprint.Height as usize * fp.Footprint.Depth as usize; + for y in 0..rows { + let src = &t.data[offset..offset + row]; + let dst = (p as *mut u8).add(fp.Offset as usize + y * fp.Footprint.RowPitch as usize); std::ptr::copy_nonoverlapping(src.as_ptr(), dst, row); + offset += row; } } } @@ -272,25 +273,25 @@ unsafe fn bind_resources(dev: &ID3D12Device, list: &ID3D12GraphicsCommandList, t match t.dim { TexDim::D2 => { sv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; - sv.Anonymous.Texture2D = D3D12_TEX2D_SRV { MipLevels: 1, ..Default::default() }; + sv.Anonymous.Texture2D = D3D12_TEX2D_SRV { MipLevels: u32::from(t.mip_levels), ..Default::default() }; uv.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D; } TexDim::D2Array => { sv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DARRAY; - sv.Anonymous.Texture2DArray = D3D12_TEX2D_ARRAY_SRV { MipLevels: 1, ArraySize: t.depth, ..Default::default() }; + sv.Anonymous.Texture2DArray = D3D12_TEX2D_ARRAY_SRV { MipLevels: u32::from(t.mip_levels), ArraySize: t.depth, ..Default::default() }; uv.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; uv.Anonymous.Texture2DArray = D3D12_TEX2D_ARRAY_UAV { ArraySize: t.depth, ..Default::default() }; } TexDim::D3 => { sv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D; - sv.Anonymous.Texture3D = D3D12_TEX3D_SRV { MipLevels: 1, ..Default::default() }; + sv.Anonymous.Texture3D = D3D12_TEX3D_SRV { MipLevels: u32::from(t.mip_levels), ..Default::default() }; uv.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D; uv.Anonymous.Texture3D = D3D12_TEX3D_UAV { WSize: t.depth, ..Default::default() }; } TexDim::Cube => { // a cube array, as translated shaders declare it (depth = 6 per cube) sv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBEARRAY; - sv.Anonymous.TextureCubeArray = D3D12_TEXCUBE_ARRAY_SRV { MipLevels: 1, NumCubes: t.depth / 6, ..Default::default() }; + sv.Anonymous.TextureCubeArray = D3D12_TEXCUBE_ARRAY_SRV { MipLevels: u32::from(t.mip_levels), NumCubes: t.depth / 6, ..Default::default() }; uv.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; uv.Anonymous.Texture2DArray = D3D12_TEX2D_ARRAY_UAV { ArraySize: t.depth, ..Default::default() }; } diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index 5a8d73539..175ff1984 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -2294,7 +2294,7 @@ fn gpu_cube_array_slices() { } } } - let tex = [TestTexture { dim: TexDim::Cube, format: DXGI_FORMAT_R32G32B32A32_FLOAT, width: 2, height: 2, depth: 12, texel_bytes: 16, data, uav: false }]; + let tex = [TestTexture { dim: TexDim::Cube, format: DXGI_FORMAT_R32G32B32A32_FLOAT, width: 2, height: 2, depth: 12, mip_levels: 1, texel_bytes: 16, data, uav: false }]; let samp = [TestSampler { filter: D3D12_FILTER_MIN_MAG_MIP_POINT, address: D3D12_TEXTURE_ADDRESS_MODE_CLAMP, comparison: None }]; let r = runner::run_code_with(&code, &st, &[], &tex, &samp).unwrap(); for l in 0..64 { @@ -2306,6 +2306,191 @@ fn gpu_cube_array_slices() { } } +/// Compare with D3D12 sampling the same cube view using independently projected gradients. +#[test] +fn gpu_cube_sample_grad_matches_native_cube() { + if !gpu_ready() { + return; + } + use runner::{TestSampler, TestTexture, TexDim}; + use windows::Win32::Graphics::Direct3D12::*; + use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8G8B8A8_UNORM; + let code = prog(&[ + ("IMAGE_SAMPLE_D", "ENC_MIMG", &[("DIM", 3), ("VADDR", 0), ("SRSRC", 4), ("SSAMP", 6), ("DMASK", 3), ("VDATA", 20)], None), + ("IMAGE_SAMPLE_LZ", "ENC_MIMG", &[("DIM", 3), ("VADDR", 4), ("SRSRC", 4), ("SSAMP", 7), ("DMASK", 3), ("VDATA", 24)], None), + ]); + let mut st = KernelState::default(); + let format = crate::gpu::desc::gfx10_format(DXGI_FORMAT_R8G8B8A8_UNORM).unwrap(); + st.sgpr[16..24].copy_from_slice(&tsharp(0, format, 11)); + st.sgpr[31] = 1; + // D3D cube face normal, increasing s, increasing t. + let axes = [ + ([1., 0., 0.], [0., 0., -1.], [0., -1., 0.]), + ([-1., 0., 0.], [0., 0., 1.], [0., -1., 0.]), + ([0., 1., 0.], [1., 0., 0.], [0., 0., 1.]), + ([0., -1., 0.], [1., 0., 0.], [0., 0., -1.]), + ([0., 0., 1.], [1., 0., 0.], [0., -1., 0.]), + ([0., 0., -1.], [-1., 0., 0.], [0., -1., 0.]), + ]; + for (lane, r) in st.vgpr.iter_mut().enumerate() { + let face = lane % 6; + let cube = lane / 6 % 2; + let gradients = match lane / 12 % 4 { + 0 => [8.0, 0.0, 0.0, 1.0], + 1 => [1.0, 0.0, 0.0, 8.0], + 2 => [6.0, 6.0, -0.5, 0.5], + _ => [6.0, -6.0, 0.5, 0.5], + }; + r[..4].copy_from_slice(&gradients.map(|g| f(g / 32.0))); + let (u, v) = (12.5 / 32.0, 19.5 / 32.0); + r[4..7].copy_from_slice(&[f(1.0 + u), f(1.0 + v), f((8 * cube + face) as f32)]); + let (n, s, t) = axes[face]; + for k in 0..3 { + r[8 + k] = f(n[k] + (2.0 * u - 1.0) * s[k] + (2.0 * v - 1.0) * t[k]); + r[12 + k] = f((gradients[0] * s[k] + gradients[1] * t[k]) / 16.0); + r[15 + k] = f((gradients[2] * s[k] + gradients[3] * t[k]) / 16.0); + } + r[11] = f(cube as f32); + } + let mut data = Vec::new(); + for slice in 0..12 { + for (width, column, diagonal) in [(32, 12, 7), (16, 6, 3)] { + for y in 0..width { + for x in 0..width { + let stripe = if x == column { 160 } else { 0 }; + let diagonal_stripe = if x + diagonal == y { 64 } else { 0 }; + data.extend_from_slice(&[stripe + diagonal_stripe + y, slice * 16 + 8, 0, 255]); + } + } + } + } + let textures = [TestTexture { + dim: TexDim::Cube, format: DXGI_FORMAT_R8G8B8A8_UNORM, width: 32, height: 32, depth: 12, + mip_levels: 2, texel_bytes: 4, data, uav: false, + }]; + let samplers = [D3D12_FILTER_ANISOTROPIC, D3D12_FILTER_MIN_MAG_MIP_POINT].map(|filter| TestSampler { + filter, address: D3D12_TEXTURE_ADDRESS_MODE_CLAMP, comparison: None, + }); + let result = runner::run_code_with(&code, &st, &[], &textures, &samplers).unwrap(); + let wave_size = if runner::split_wave64() { 32 } else { 64 }; + let hlsl = format!(r#" +RWByteAddressBuffer io : register(u0); +RWByteAddressBuffer res : register(u1); +[WaveSize({wave_size})] +[numthreads(64, 1, 1)] +void main(uint lane : SV_GroupIndex) {{ + uint at = ({} + lane * {}) * 4; + TextureCubeArray cube = ResourceDescriptorHeap[NonUniformResourceIndex(io.Load(16 * 4))]; + SamplerState samp = SamplerDescriptorHeap[NonUniformResourceIndex(io.Load(27 * 4) & 0xFFFu)]; + float4 direction = asfloat(io.Load4(at + 8 * 4)); + float3 dx = asfloat(io.Load3(at + 12 * 4)); + float3 dy = asfloat(io.Load3(at + 15 * 4)); + res.Store2(at + 20 * 4, asuint(cube.SampleGrad(samp, direction, dx, dy).rg)); +}} +"#, super::KERNEL_SGPRS, super::KERNEL_VGPRS); + let dxil = super::dxc::compile(&hlsl, "main", "cs_6_6", &[]).unwrap(); + let native = runner::run_with(&dxil, &st, &[], &textures, &samplers).unwrap(); + for (lane, (r, reference)) in result.vgpr.iter().zip(&native.vgpr).enumerate() { + let channel = |i: usize| f32::from_bits(r[i]); + let slice = lane / 6 % 2 * 6 + lane % 6; + let slice_id = (slice * 16 + 8) as f32 / 255.0; + assert!((channel(24) - 243.0 / 255.0).abs() < 0.005, "lane {lane}: point-sampled texel {}", channel(24)); + assert!((channel(25) - slice_id).abs() < 0.005, "lane {lane}: point-sampled slice {}", channel(25)); + for i in [20, 21] { + let expected = f32::from_bits(reference[i]); + let got = channel(i); + assert!((got - expected).abs() < 0.005, "lane {lane}, v{i}: translated cube {got}, native cube {expected}"); + } + } +} + +/// Linear filtering straddles each of the twelve edges. Check from both incident +/// faces, at the boundary and a quarter texel inside it. +#[test] +fn gpu_cube_sample_grad_edges() { + if !gpu_ready() { + return; + } + use runner::{TestSampler, TestTexture, TexDim}; + use windows::Win32::Graphics::Direct3D12::*; + use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R32_FLOAT; + let code = prog(&[("IMAGE_SAMPLE_D", "ENC_MIMG", &[("DIM", 3), ("VADDR", 0), ("SRSRC", 4), ("SSAMP", 6), ("DMASK", 1), ("VDATA", 10)], None)]); + // Rows are +X, -X, +Y, -Y, +Z, -Z. Columns are left, right, top, bottom. + let adjacent = [[4, 5, 2, 3], [5, 4, 2, 3], [1, 0, 5, 4], + [1, 0, 4, 5], [1, 0, 2, 3], [0, 1, 2, 3]]; + let mut st = KernelState::default(); + st.sgpr[16..24].copy_from_slice(&tsharp(0, 22, 11)); + let mut expected = Vec::new(); + for (lane, r) in st.vgpr.iter_mut().enumerate() { + let (face, edge) = (lane / 4 % 6, lane % 4); + let inset = if lane / 24 % 2 == 0 { 0.0 } else { 0.25 }; + let d = inset / 8.0; + let (u, v) = [(d, 0.375), (1.0 - d, 0.375), (0.375, d), (0.375, 1.0 - d)][edge]; + r[..7].copy_from_slice(&[f(0.125), 0, 0, f(0.125), f(1.0 + u), f(1.0 + v), f(face as f32)]); + expected.push((0.5 + inset) * face as f32 + (0.5 - inset) * adjacent[face][edge] as f32); + } + let data = (0..6).flat_map(|face| (0..64).flat_map(move |_| (face as f32).to_le_bytes())).collect(); + let tex = TestTexture { dim: TexDim::Cube, format: DXGI_FORMAT_R32_FLOAT, width: 8, height: 8, depth: 6, mip_levels: 1, texel_bytes: 4, data, uav: false }; + let samp = TestSampler { filter: D3D12_FILTER_MIN_MAG_MIP_LINEAR, address: D3D12_TEXTURE_ADDRESS_MODE_CLAMP, comparison: None }; + let result = runner::run_code_with(&code, &st, &[], &[tex], &[samp]).unwrap(); + for (lane, want) in expected.into_iter().enumerate() { + let got = f32::from_bits(result.vgpr[lane][10]); + assert!((got - want).abs() < 0.02, "lane {lane}: seam {got}, expected {want}"); + } +} + +/// On +X, check the gradient-selected mip and minimum LODs above and below it. +#[test] +fn gpu_cube_sample_grad_min_lod() { + if !gpu_ready() { + return; + } + use windows::Win32::Graphics::Direct3D12::*; + use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT_R32_FLOAT, DXGI_SAMPLE_DESC}; + let mut ps = Vec::new(); + for (k, value) in [0.125, 0.0, 0.0, 0.125, 1.5, 1.5, 0.0, 2.0].into_iter().enumerate() { + ps.extend(ins("V_MOV_B32", "ENC_VOP1", &[("VDST", 4 + k as u64), ("SRC0", 255)], Some(f(value)))); + } + for (op, dst) in [("IMAGE_SAMPLE_D", 12), ("IMAGE_SAMPLE_D_CL", 13)] { + ps.extend(ins(op, "ENC_MIMG", &[("DIM", 3), ("VADDR", 4), ("SRSRC", 4), ("SSAMP", 6), ("DMASK", 1), ("VDATA", dst)], None)); + } + for register in [4, 7] { + ps.extend(ins("V_MOV_B32", "ENC_VOP1", &[("VDST", register), ("SRC0", 255)], Some(f(0.5)))); + } + for (minimum, dst) in [(1.0, 14), (2.5, 15)] { + ps.extend(ins("V_MOV_B32", "ENC_VOP1", &[("VDST", 11), ("SRC0", 255)], Some(f(minimum)))); + ps.extend(ins("IMAGE_SAMPLE_D_CL", "ENC_MIMG", &[("DIM", 3), ("VADDR", 4), ("SRSRC", 4), ("SSAMP", 6), ("DMASK", 1), ("VDATA", dst)], None)); + } + ps.extend(ins("EXP", "ENC_EXP", &[("TGT", 0), ("EN", 0xF), ("VSRC0", 12), ("VSRC1", 13), ("VSRC2", 14), ("VSRC3", 15), ("DONE", 1), ("VM", 1)], None)); + ps.extend(ins("S_ENDPGM", "ENC_SOPP", &[], None)); + let res = D3D12_RESOURCE_DESC { + Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D, Width: 8, Height: 8, DepthOrArraySize: 6, MipLevels: 4, + Format: DXGI_FORMAT_R32_FLOAT, SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 }, ..Default::default() + }; + let mut srv = D3D12_SHADER_RESOURCE_VIEW_DESC { + Format: res.Format, ViewDimension: D3D12_SRV_DIMENSION_TEXTURECUBEARRAY, + Shader4ComponentMapping: D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING, ..Default::default() + }; + srv.Anonymous.TextureCubeArray = D3D12_TEXCUBE_ARRAY_SRV { MipLevels: 4, NumCubes: 1, ..Default::default() }; + // The point-filtered sample reads only the centre of +X. + let mut data = Vec::new(); + for mip in 0..4 { + let width = 8 >> mip; + for _ in 0..width * width { + data.extend_from_slice(&(1.0 + mip as f32).to_le_bytes()); + } + } + let texture = runner::ViewTexture { res, srv, data, row_bytes: 8 * 4 }; + let mut sgprs = vec![0u32; 32]; + sgprs[16..24].copy_from_slice(&tsharp(0, 22, 11)); + let sampler = [2 | 2 << 3 | 2 << 6, 0xFFF << 12, 2 << 26, 0]; + sgprs[24..28].copy_from_slice(&sampler); + let pixels = draw_console_views(None, Some(&ps), &[[0.0, 0.0], [0.0, 32.0], [32.0, 0.0]], &sgprs, &[texture], &[crate::gpu::desc::sampler_d3d12(&sampler, false)]); + for p in pixels { + assert_eq!(p, [1.0, 3.0, 3.0, 3.5]); + } +} + #[test] fn gpu_images_sample_load_store_atomic() { if !gpu_ready() { @@ -2366,10 +2551,10 @@ fn gpu_images_sample_load_store_atomic() { } } let tex = vec![ - TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R32G32B32A32_FLOAT, width: 4, height: 4, depth: 1, texel_bytes: 16, data: t0, uav: false }, - TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R32_UINT, width: 4, height: 4, depth: 1, texel_bytes: 4, data: vec![0xEE; 64], uav: true }, - TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R32_UINT, width: 1, height: 1, depth: 1, texel_bytes: 4, data: vec![0; 4], uav: true }, - TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R32_UINT, width: 1, height: 1, depth: 1, texel_bytes: 4, data: vec![0; 4], uav: true }, + TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R32G32B32A32_FLOAT, width: 4, height: 4, depth: 1, mip_levels: 1, texel_bytes: 16, data: t0, uav: false }, + TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R32_UINT, width: 4, height: 4, depth: 1, mip_levels: 1, texel_bytes: 4, data: vec![0xEE; 64], uav: true }, + TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R32_UINT, width: 1, height: 1, depth: 1, mip_levels: 1, texel_bytes: 4, data: vec![0; 4], uav: true }, + TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R32_UINT, width: 1, height: 1, depth: 1, mip_levels: 1, texel_bytes: 4, data: vec![0; 4], uav: true }, ]; let samp = vec![ TestSampler { filter: D3D12_FILTER_MIN_MAG_MIP_POINT, address: D3D12_TEXTURE_ADDRESS_MODE_CLAMP, comparison: None }, @@ -2443,7 +2628,7 @@ fn gpu_static_samplers_from_constants_in_code() { } } } - let tex = vec![TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R32G32B32A32_FLOAT, width: 4, height: 4, depth: 1, texel_bytes: 16, data: t0, uav: false }]; + let tex = vec![TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R32G32B32A32_FLOAT, width: 4, height: 4, depth: 1, mip_levels: 1, texel_bytes: 16, data: t0, uav: false }]; let r = runner::run_code_with(&code, &st, &[], &tex, &[]).unwrap(); for l in 0..64 { let v = &r.vgpr[l]; @@ -2484,7 +2669,7 @@ fn gpu_images_a16_d16() { } } } - let tex = vec![TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R32G32B32A32_FLOAT, width: 4, height: 4, depth: 1, texel_bytes: 16, data: t0, uav: false }]; + let tex = vec![TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R32G32B32A32_FLOAT, width: 4, height: 4, depth: 1, mip_levels: 1, texel_bytes: 16, data: t0, uav: false }]; let samp = vec![TestSampler { filter: D3D12_FILTER_MIN_MAG_MIP_POINT, address: D3D12_TEXTURE_ADDRESS_MODE_CLAMP, comparison: None }]; let r = runner::run_code_with(&code, &st, &[], &tex, &samp).unwrap(); for l in 0..64 { @@ -3069,7 +3254,7 @@ fn gpu_image_sample_offset() { } } } - let tex = vec![TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R32G32B32A32_FLOAT, width: 4, height: 4, depth: 1, texel_bytes: 16, data: t0, uav: false }]; + let tex = vec![TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R32G32B32A32_FLOAT, width: 4, height: 4, depth: 1, mip_levels: 1, texel_bytes: 16, data: t0, uav: false }]; let samp = vec![TestSampler { filter: D3D12_FILTER_MIN_MAG_MIP_POINT, address: D3D12_TEXTURE_ADDRESS_MODE_CLAMP, comparison: None }]; let r = runner::run_code_with(&code, &st, &[], &tex, &samp).unwrap(); for l in 0..64 {