WebGPU Shading Language
WebGPU Shading Language (WGSL, internet media type: ) is a high-level shading language and the normative shader language for the WebGPU API on the web. WGSL's syntax is influenced by Rust and is designed with strong static validation, explicit resource binding, and portability in mind for secure execution in browsers. In web contexts, WebGPU implementations accept WGSL source and perform compilation to platform-specific intermediate forms (for example, to SPIR‑V, DXIL, or MSL via the user agent), but such backends are not exposed to web content. Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.
WebGPU Shading Language (WGSL, internet media type: ) is a high-level shading language and the normative shader language for the WebGPU API on the web. WGSL's syntax is influenced by Rust and is designed with strong static validation, explicit resource binding, and portability in mind for secure execution in browsers. In web contexts, WebGPU implementations accept WGSL source and perform compilation to platform-specific intermediate forms (for example, to SPIR‑V, DXIL, or MSL via the user agent), but such backends are not exposed to web content. /* Transforms positions by an MVP matrix and passes through color. */ struct VertexInput { @location(0) position : vec3f, // vec3f is an alias for vec3 @location(1) color : vec3f, }; struct VertexOutput { @builtin(position) clip_position : vec4f, @location(0) color : vec3f, }; @group(0) @binding(0) var mvp : mat4x4f; @vertex fn main(v_in : VertexInput) -> VertexOutput { var v_out : VertexOutput; v_out.clip_position = mvp * vec4f(v_in.position, 1.0); v_out.color = v_in.color; return v_out; } /* Writes an interpolated color with opaque alpha. */ @fragment fn main(@location(0) color : vec3f) -> @location(0) vec4f { return vec4f(color, 1.0); } If half-precision ( vec4h , shorthand for vec4 ) is desired, the code must be prefaced with a enable f16; statement. /* Doubles elements from an input buffer into an output buffer. */ struct Params { element_count : u32, }; @group(0) @binding(0) var in_data : array ; @group(0) @binding(1) var out_data : array ; @group(0) @binding(2) var params : Params; @compute @workgroup_size(64) fn main(@builtin(global_invocation_id) gid : vec3 ) { let idx : u32 = gid.x; if (idx >= params.element_count) { return; } out_data[idx] = in_data[idx] * 2.0; }
Cite this
"WebGPU Shading Language". 1773784718. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1344039943 JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy