Skip to content

[hlsl/msl-out] Incorrect result for clamp(x, low, high) if low > high #4387

@hasali19

Description

@hasali19

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions