diff --git a/crates/xcl/src/gpu/dxil/kernel.rs b/crates/xcl/src/gpu/dxil/kernel.rs index d28a2ffcb..fb9d78e1a 100644 --- a/crates/xcl/src/gpu/dxil/kernel.rs +++ b/crates/xcl/src/gpu/dxil/kernel.rs @@ -37,7 +37,7 @@ pub struct KernelOptions { /// Version of the direct translator's output, part of the on-disk translation cache's /// identity (`recomp::pso`): bump it on any change that alters the emitted containers /// (the `gpu/dxil` sources are not in build.rs's translator source hash). -pub const TRANSLATOR_VERSION: u32 = 7; +pub const TRANSLATOR_VERSION: u32 = 8; /// `XCL_DIRECT_DXIL=1`: console compute shaders (and the kernel tests) go through this /// translator, with the HLSL path as the fallback for what it cannot translate yet. diff --git a/crates/xcl/src/gpu/dxil/lower_image.rs b/crates/xcl/src/gpu/dxil/lower_image.rs index 55767084b..0289a2c40 100644 --- a/crates/xcl/src/gpu/dxil/lower_image.rs +++ b/crates/xcl/src/gpu/dxil/lower_image.rs @@ -854,15 +854,23 @@ impl Lw { let tmps = tmps.clone(); self.guarded(is, &mut |lw| { let tex: Texture = lw.s.heap_texture(tw0, kind, false, ct, 4, true); - // Emit all TextureLoad calls before GetDimensions in this basic block: - // AMD's DXIL compiler (amdxc64.dll) hits a null-pointer dereference - // (0xc0000005) when dx.op.getDimensions precedes dx.op.textureLoad on a - // dynamically indexed heap Texture2DMS/Texture2DMSArray in the same block. - let loads: Vec<[Value; 4]> = samples.iter().map(|&sv| lw.s.texture_load_sample(tex, sv, &coords)).collect(); + // The sample count comes first, in its own block: an out-of-range `ld2dms` + // index is undefined and faults on RDNA4, so lanes at or past the count load + // sample 0 (the result is still zeroed below). The loads then start a new + // block so no TextureLoad follows GetDimensions in one basic block (#1900: + // AMD's DXIL compiler, amdxc64.dll, dereferences null when dx.op.getDimensions + // precedes dx.op.textureLoad on a dynamically indexed heap Texture2DMS(Array) + // in the same block). let dims = lw.s.get_dimensions(tex.handle, None); let count = lw.s.m.extract(dims, 3); - for (si, (&sv, r)) in samples.iter().zip(loads).enumerate() { - let inside = lw.cmp(Pred::ULt, sv, count); + let loads_block = lw.block(Some(1)); + lw.br(loads_block); + lw.s.m.set_block(loads_block); + let inside: Vec = samples.iter().map(|&sv| lw.cmp(Pred::ULt, sv, count)).collect(); + let first = lw.c(0); + let clamped: Vec = samples.iter().zip(&inside).map(|(&sv, &ok)| lw.sel(ok, sv, first)).collect(); + let loads: Vec<[Value; 4]> = clamped.iter().map(|&sv| lw.s.texture_load_sample(tex, sv, &coords)).collect(); + for (si, (&inside, r)) in inside.iter().zip(loads).enumerate() { for k in 0..4 { let b = lw.bits(r[k]); let zz = lw.c(0);