[Webkit-unassigned] [Bug 261862] New: [WGSL] discard keyword is not supported
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Wed Sep 20 22:31:44 PDT 2023
https://bugs.webkit.org/show_bug.cgi?id=261862
Bug ID: 261862
Summary: [WGSL] discard keyword is not supported
Product: WebKit
Version: WebKit Nightly Build
Hardware: Unspecified
OS: Unspecified
Status: NEW
Severity: Normal
Priority: P2
Component: WebGPU
Assignee: webkit-unassigned at lists.webkit.org
Reporter: mwyrzykowski at apple.com
Support discard - https://www.w3.org/TR/WGSL/#discard-statement
It should emit "discard_fragment()" in the generated metal, see section 6.10.1.2 of the metal shading language specification.
Example shader from https://webgpu.github.io/webgpu-samples/samples/deferredRendering which uses discard
@group(0) @binding(0) var gBufferNormal: texture_2d<f32>;
@group(0) @binding(1) var gBufferAlbedo: texture_2d<f32>;
@group(0) @binding(2) var gBufferDepth: texture_depth_2d;
struct LightData {
position : vec4<f32>,
color : vec3<f32>,
radius : f32,
}
struct LightsBuffer {
lights: array<LightData>,
}
@group(1) @binding(0) var<storage, read> lightsBuffer: LightsBuffer;
struct Config {
numLights : u32,
}
struct Camera {
viewProjectionMatrix : mat4x4<f32>,
invViewProjectionMatrix : mat4x4<f32>,
}
@group(1) @binding(1) var<uniform> config: Config;
@group(1) @binding(2) var<uniform> camera: Camera;
fn world_from_screen_coord(coord : vec2<f32>, depth_sample: f32) -> vec3<f32> {
// reconstruct world-space position from the screen coordinate.
let posClip = vec4(coord.x * 2.0 - 1.0, (1.0 - coord.y) * 2.0 - 1.0, depth_sample, 1.0);
let posWorldW = camera.invViewProjectionMatrix * posClip;
let posWorld = posWorldW.xyz / posWorldW.www;
return posWorld;
}
@fragment
fn main(
@builtin(position) coord : vec4<f32>
) -> @location(0) vec4<f32> {
var result : vec3<f32>;
let depth = textureLoad(
gBufferDepth,
vec2<i32>(floor(coord.xy)),
0
);
// Don't light the sky.
if (depth >= 1.0) {
discard;
}
let bufferSize = textureDimensions(gBufferDepth);
let coordUV = coord.xy / vec2<f32>(bufferSize);
let position = world_from_screen_coord(coordUV, depth);
let normal = textureLoad(
gBufferNormal,
vec2<i32>(floor(coord.xy)),
0
).xyz;
let albedo = textureLoad(
gBufferAlbedo,
vec2<i32>(floor(coord.xy)),
0
).rgb;
for (var i = 0u; i < config.numLights; i++) {
let L = lightsBuffer.lights[i].position.xyz - position;
let distance = length(L);
if (distance > lightsBuffer.lights[i].radius) {
continue;
}
let lambert = max(dot(normal, normalize(L)), 0.0);
result += vec3<f32>(
lambert * pow(1.0 - distance / lightsBuffer.lights[i].radius, 2.0) * lightsBuffer.lights[i].color * albedo
);
}
// some manual ambient
result += vec3(0.2);
return vec4(result, 1.0);
}
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20230921/70687988/attachment.htm>
More information about the webkit-unassigned
mailing list