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 crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 15 additions & 7 deletions crates/xcl/src/gpu/dxil/lower_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value> = samples.iter().map(|&sv| lw.cmp(Pred::ULt, sv, count)).collect();
let first = lw.c(0);
let clamped: Vec<Value> = 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);
Expand Down
Loading