Skip to content
Closed
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 = 6;
pub const TRANSLATOR_VERSION: u32 = 7;

/// `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
11 changes: 8 additions & 3 deletions crates/xcl/src/gpu/dxil/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,16 +900,21 @@ impl Module {
w.record(MODULE_CODE_VERSION, &[1]);

// Attribute groups: 1 = nounwind readnone, 2 = nounwind readonly,
// 3 = nounwind, 4 = noduplicate nounwind.
// 3 = nounwind, 4 = noduplicate nounwind, 5 = the entry function: f32 denormals
// flushed (without it the driver chooses, per operation).
w.enter_block(BLOCK_PARAMATTR_GROUP);
const FN: u64 = 0xFFFF_FFFF;
w.record(PARAMATTR_GRP_CODE_ENTRY, &[1, FN, 0, ATTR_NOUNWIND, 0, ATTR_READNONE]);
w.record(PARAMATTR_GRP_CODE_ENTRY, &[2, FN, 0, ATTR_NOUNWIND, 0, ATTR_READONLY]);
w.record(PARAMATTR_GRP_CODE_ENTRY, &[3, FN, 0, ATTR_NOUNWIND]);
w.record(PARAMATTR_GRP_CODE_ENTRY, &[4, FN, 0, ATTR_NODUPLICATE, 0, ATTR_NOUNWIND]);
// string attribute: 4, key, 0, value, 0
let mut ftz = vec![5, FN, 4];
ftz.extend(b"fp32-denorm-mode\0ftz\0".iter().map(|&c| c as u64));
w.record(PARAMATTR_GRP_CODE_ENTRY, &ftz);
w.end_block();
w.enter_block(BLOCK_PARAMATTR);
for g in 1..=4 {
for g in 1..=5 {
w.record(PARAMATTR_CODE_ENTRY, &[g]);
}
w.end_block();
Expand All @@ -934,7 +939,7 @@ impl Module {
// gc, unnamed_addr, prologue, dllstorage, comdat, prefix, personality]
w.record(
MODULE_CODE_FUNCTION,
&[f.ty.0 as u64, 0, (!f.defined) as u64, LINKAGE_EXTERNAL, f.attrs.index(), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
&[f.ty.0 as u64, 0, (!f.defined) as u64, LINKAGE_EXTERNAL, if f.defined { 5 } else { f.attrs.index() }, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
);
}

Expand Down
15 changes: 15 additions & 0 deletions crates/xcl/src/gpu/dxil/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,18 @@ fn batched_replacements_match_one_at_a_time() {
panic!("validator rejected the kernel:\n{e}");
}
}

/// The entry function asks for flushed f32 denormals, so the driver does not choose.
#[test]
fn the_entry_function_flushes_f32_denormals() {
let c = sample_kernel(32);
if let Err(e) = validate::validate(&c) {
panic!("validator: {e}");
}
let dis = validate::disassemble(&c).expect("disassembly");
let attrs = "\"fp32-denorm-mode\"=\"ftz\"";
assert!(dis.contains(attrs), "no {attrs}:\n{dis}");
let entry = dis.lines().find(|l| l.starts_with("define void @")).expect("entry");
let group = entry.rsplit('#').next().unwrap().trim_end_matches(" {").trim();
assert!(dis.lines().any(|l| l.starts_with(&format!("attributes #{group} ")) && l.contains(attrs)), "{entry}\n{dis}");
}
Loading