Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
31 changes: 19 additions & 12 deletions crates/xcl/src/gpu/recomp/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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})"),
Expand Down Expand Up @@ -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); }
Expand Down
35 changes: 18 additions & 17 deletions crates/xcl/src/gpu/recomp/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
pub uav: bool,
}
Expand Down Expand Up @@ -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()
Expand All @@ -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),
Expand All @@ -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));
Expand All @@ -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;
}
}
}
Expand All @@ -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() };
}
Expand Down
Loading
Loading