The spec defines the semantics of clamp(x, low, high) to be min(max(x, low), high). Naga directly translates clamp to the equivalent functions in metal and hlsl. However, the metal spec states that this is UB if low > high, and directx can be seen to produce the incorrect result below.
struct d {
a : i32,
}
@group(0) @binding(0)
var<storage, read_write> f : d;
@stage(compute) @workgroup_size(1)
fn main() {
f = d(clamp(3, 46, 6));
}
This program produces 46 when run with directx, but 6 with vulkan.
The spec defines the semantics of
clamp(x, low, high)to bemin(max(x, low), high). Naga directly translatesclampto the equivalent functions in metal and hlsl. However, the metal spec states that this is UB if low > high, and directx can be seen to produce the incorrect result below.This program produces 46 when run with directx, but 6 with vulkan.