Bug 278946

Summary: [WGSL] Default initialization of [[position]] can lead to division by zero depending on the hardware implementation
Product: WebKit Reporter: Mike Wyrzykowski <mwyrzykowski>
Component: WebGPUAssignee: Nobody <webkit-unassigned>
Status: NEW    
Severity: Normal CC: mwyrzykowski, tzagallo, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Mike Wyrzykowski
Reported 2024-08-30 13:59:48 PDT
Since position performs an effective division https://www.w3.org/TR/WGSL/#position-builtin-value its default initializer should be 0,0,0,1 instead of 0,0,0,0. Otherwise this result is undefined, as v.position is not written to. Specifically, on Apple Silicon it renders the pixel but on AMD / Intel, the render is skipped because (x,y,z)/w = (0,0,0)/0 = inf: struct VertexOutput { @builtin(position) position : vec4f, @location(0) @interpolate(flat) something: u32, } @vertex fn v(@location(0) fromVertexBuffer: u32) -> VertexOutput { var v = VertexOutput(); v.something = fromVertexBuffer; return v; } @fragment fn f(@location(0) @interpolate(flat) something: u32) -> @location(0) u32 { return something; }
Attachments
Mike Wyrzykowski
Comment 1 2024-08-30 14:19:04 PDT
Related: https://github.com/gpuweb/gpuweb/issues/4845 Instead of changing the initializer, we may want to insert a clamp at the end, like: position.w = select(position.w, 1., position.w == 0)
Radar WebKit Bug Importer
Comment 2 2024-08-30 14:28:05 PDT
Note You need to log in before you can comment on or make changes to this bug.