mirror of
https://github.com/ivall/xcl.git
synced 2026-11-24 05:14:57 +01:00
Merge pull request #68 from Foniass/nvidia-uav-barriers-fract
This commit is contained in:
@@ -4535,7 +4535,9 @@ float mad_nf(float a, float b, float c) { precise float p = a * b; precise float
|
||||
float med3f(float a, float b, float c) { return max(min(a, b), min(max(a, b), c)); }
|
||||
uint med3u(uint a, uint b, uint c) { return max(min(a, b), min(max(a, b), c)); }
|
||||
int med3i(int a, int b, int c) { return max(min(a, b), min(max(a, b), c)); }
|
||||
float fract_f(float x) { return min(x - floor(x), asfloat(0x3F7FFFFFu)); }
|
||||
// x - floor(x) below 1.0 (RDNA: a NaN stays NaN and ±inf gives NaN – min() would return the
|
||||
// clamp for both: HLSL min returns its non-NaN operand)
|
||||
float fract_f(float x) { float r = x - floor(x); return select(r >= 1.0f, asfloat(0x3F7FFFFFu), r); }
|
||||
uint cvt_u32(float f) { return select(or(isnan(f), f <= 0.0f), 0u, select(f >= 4294967296.0f, 0xFFFFFFFFu, (uint)f)); }
|
||||
int cvt_i32(float f) { return select(isnan(f), 0, select(f <= -2147483648.0f, (int)0x80000000u, select(f >= 2147483648.0f, 0x7FFFFFFF, (int)f))); }
|
||||
int i24(uint v) { return ((int)(v << 8)) >> 8; }
|
||||
|
||||
@@ -4098,3 +4098,30 @@ fn mesh_wave32_rejects_cross_half_operations() {
|
||||
assert!(split.hlsl.contains("xcl_logical_wave64 = true;"));
|
||||
assert!(split.complete(), "{:?}", split.unsupported_why);
|
||||
}
|
||||
|
||||
/// v_fract_f32 at the edges, as RDNA computes it (x - floor(x) kept below 1.0): ±inf gives
|
||||
/// NaN and a NaN stays NaN – a `min()` clamp returned 0.99999994 there on NVIDIA (HLSL min
|
||||
/// returns its non-NaN operand); a tiny negative value rounds to the largest float below 1.
|
||||
#[test]
|
||||
fn gpu_fract_f32_edges() {
|
||||
if !gpu_ready() {
|
||||
return;
|
||||
}
|
||||
let code = prog(&[("V_FRACT_F32", "ENC_VOP1", &[("VDST", 2), ("SRC0", V + 1)], None)]);
|
||||
let inputs = [f32::INFINITY, f32::NEG_INFINITY, f32::NAN, -0.0, 1.5, -0.25, -(2f32.powi(-25)), 7.0];
|
||||
let mut st = KernelState::default();
|
||||
for (l, r) in st.vgpr.iter_mut().enumerate() {
|
||||
r[1] = inputs[l % inputs.len()].to_bits();
|
||||
}
|
||||
let r = runner::run_code(&code, &st, &[]).unwrap();
|
||||
for l in 0..64 {
|
||||
let (x, got) = (inputs[l % inputs.len()], f32::from_bits(r.vgpr[l][2]));
|
||||
if x.is_infinite() || x.is_nan() {
|
||||
assert!(got.is_nan(), "lane {l}: fract({x}) = {got}, want NaN");
|
||||
} else if x == -(2f32.powi(-25)) {
|
||||
assert_eq!(r.vgpr[l][2], 0x3F7F_FFFF, "lane {l}: fract({x}) below 1.0");
|
||||
} else {
|
||||
assert_eq!(got.to_bits(), (x - x.floor()).to_bits(), "lane {l}: fract({x})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1649,7 +1649,9 @@ pub(super) unsafe extern "system" fn resource_barrier_x(this: *mut c_void, n: u3
|
||||
if barriers.is_null() || n == 0 {
|
||||
return;
|
||||
}
|
||||
let mut out: Vec<[u32; 8]> = Vec::with_capacity(n as usize);
|
||||
let mut out: Vec<[u32; 8]> = Vec::with_capacity(n as usize + 1);
|
||||
// a UAV barrier for all resources is in `out` / a transition from or to UNORDERED_ACCESS
|
||||
let (mut any_uav, mut uav_transition) = (false, false);
|
||||
for k in 0..n as usize {
|
||||
let mut b = barriers.add(k).read_unaligned();
|
||||
let (ty, flags) = (b[0], b[1]);
|
||||
@@ -1674,6 +1676,17 @@ pub(super) unsafe extern "system" fn resource_barrier_x(this: *mut c_void, n: u3
|
||||
// (the list would fail to Close) – an aliasing barrier for any resources instead
|
||||
b[2..6].fill(0);
|
||||
}
|
||||
if ty == 2 {
|
||||
// UAV (resource +8): translated shaders reach title memory through XCL's memory
|
||||
// window buffers – other resources over the same memory – which a UAV barrier for
|
||||
// the title's resource alone does not order (AMD drivers wait and flush for any UAV
|
||||
// barrier, NVIDIA's need not): a UAV barrier for all resources, once per batch
|
||||
b[2..4].fill(0);
|
||||
if any_uav {
|
||||
continue;
|
||||
}
|
||||
any_uav = true;
|
||||
}
|
||||
if ty == 0 {
|
||||
// transition: resource (+8), subresource (+16), before (+20), after (+24)
|
||||
let (before, after) = (b[5], b[6]);
|
||||
@@ -1692,9 +1705,14 @@ pub(super) unsafe extern "system" fn resource_barrier_x(this: *mut c_void, n: u3
|
||||
if b[5] == b[6] {
|
||||
continue;
|
||||
}
|
||||
// UAV writes before (or after) the transition: the same holds for the window buffers
|
||||
uav_transition |= (b[5] | b[6]) & UNORDERED_ACCESS != 0;
|
||||
}
|
||||
out.push(b);
|
||||
}
|
||||
if uav_transition && !any_uav {
|
||||
out.push([2, 0, 0, 0, 0, 0, 0, 0]);
|
||||
}
|
||||
if !out.is_empty() {
|
||||
pc::<unsafe extern "system" fn(*mut c_void, u32, *const [u32; 8])>(this, PC_RESOURCE_BARRIER)(this, out.len() as u32, out.as_ptr());
|
||||
}
|
||||
@@ -1703,6 +1721,9 @@ pub(super) unsafe extern "system" fn resource_barrier_x(this: *mut c_void, n: u3
|
||||
/// D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER | INDEX_BUFFER: valid for buffers only
|
||||
const BUFFER_ONLY_STATES: u32 = 0x1 | 0x2;
|
||||
|
||||
/// D3D12_RESOURCE_STATE_UNORDERED_ACCESS
|
||||
const UNORDERED_ACCESS: u32 = 0x8;
|
||||
|
||||
/// Whether `res` is a buffer (null / unknown: taken as one – its states are left alone).
|
||||
unsafe fn is_buffer(res: usize) -> bool {
|
||||
let r = res as *mut c_void;
|
||||
|
||||
Reference in New Issue
Block a user