diff --git a/lib/gpu-buffer.js b/lib/gpu-buffer.js index b5fb6c7..b3cb94a 100644 --- a/lib/gpu-buffer.js +++ b/lib/gpu-buffer.js @@ -116,7 +116,7 @@ const getTypeData = (type, attributes, otherStructLayouts) => { const parseAttributes = (str) => { const attributes = {}; for (const attr of str.split(",").filter((attr) => attr.length > 0)) { - const match = attr.match(/(\w+)(\((.*)\))?/); // foo(bar) + const match = attr.match(/@(\w+)(\((.*)\))?/); // @foo(bar) const [_, identifier, __, value] = match; attributes[identifier] = value; } @@ -131,7 +131,8 @@ const parseStructLayout = (identifier, body, structLayouts) => { .split(";") .filter((s) => s.length > 0); for (const line of lines) { - const fieldMatch = line.match(/(\[\[(.*?)\]\])? ?(\w+) ?: ?(\[\[(.*?)\]\])? ?(.*)/); // [[...]] foo : [[...]] bar; + console.log(line); + const fieldMatch = line.match(/(\[\[(.*?)\]\])? ?(\w+) ?: ?(\[\[(.*?)\]\])? ?(.*)/); // @a(...) @b(...) foo : @c(...) @d(...) bar; const [_, __, leftAttributes, identifier, ___, rightAttributes, type] = fieldMatch; const typeData = getTypeData(type, parseAttributes(rightAttributes ?? ""), structLayouts); diff --git a/shaders/wgsl/bloomBlur.wgsl b/shaders/wgsl/bloomBlur.wgsl index cfcaf75..4a8a63a 100644 --- a/shaders/wgsl/bloomBlur.wgsl +++ b/shaders/wgsl/bloomBlur.wgsl @@ -5,13 +5,13 @@ struct Config { direction : vec2; }; -[[group(0), binding(0)]] var config : Config; -[[group(0), binding(1)]] var linearSampler : sampler; -[[group(0), binding(2)]] var tex : texture_2d; -[[group(0), binding(3)]] var outputTex : texture_storage_2d; +@group(0) @binding(0) var config : Config; +@group(0) @binding(1) var linearSampler : sampler; +@group(0) @binding(2) var tex : texture_2d; +@group(0) @binding(3) var outputTex : texture_storage_2d; struct ComputeInput { - [[builtin(global_invocation_id)]] id : vec3; + @builtin(global_invocation_id) id : vec3; }; fn gaussianPDF(x : f32) -> f32 { @@ -20,7 +20,7 @@ fn gaussianPDF(x : f32) -> f32 { ) / config.bloomRadius; } -[[stage(compute), workgroup_size(32, 1, 1)]] fn computeMain(input : ComputeInput) { +@stage(compute) @workgroup_size(32, 1, 1) fn computeMain(input : ComputeInput) { var coord = vec2(input.id.xy); var outputSize = textureDimensions(outputTex); diff --git a/shaders/wgsl/bloomCombine.wgsl b/shaders/wgsl/bloomCombine.wgsl index 0cdefda..77b0385 100644 --- a/shaders/wgsl/bloomCombine.wgsl +++ b/shaders/wgsl/bloomCombine.wgsl @@ -2,24 +2,24 @@ struct Config { pyramidHeight : f32; }; -[[group(0), binding(0)]] var config : Config; -[[group(0), binding(1)]] var linearSampler : sampler; +@group(0) @binding(0) var config : Config; +@group(0) @binding(1) var linearSampler : sampler; // Currently mipmap textures aren't working as expected in Firefox Nightly -// [[group(0), binding(2)]] var tex : texture_2d; -// [[group(0), binding(3)]] var outputTex : texture_storage_2d; +// @group(0) @binding(2) var tex : texture_2d; +// @group(0) @binding(3) var outputTex : texture_storage_2d; -[[group(0), binding(2)]] var tex1 : texture_2d; -[[group(0), binding(3)]] var tex2 : texture_2d; -[[group(0), binding(4)]] var tex3 : texture_2d; -[[group(0), binding(5)]] var tex4 : texture_2d; -[[group(0), binding(6)]] var outputTex : texture_storage_2d; +@group(0) @binding(2) var tex1 : texture_2d; +@group(0) @binding(3) var tex2 : texture_2d; +@group(0) @binding(4) var tex3 : texture_2d; +@group(0) @binding(5) var tex4 : texture_2d; +@group(0) @binding(6) var outputTex : texture_storage_2d; struct ComputeInput { - [[builtin(global_invocation_id)]] id : vec3; + @builtin(global_invocation_id) id : vec3; }; -[[stage(compute), workgroup_size(32, 1, 1)]] fn computeMain(input : ComputeInput) { +@stage(compute) @workgroup_size(32, 1, 1) fn computeMain(input : ComputeInput) { var coord = vec2(input.id.xy); var outputSize = textureDimensions(outputTex); diff --git a/shaders/wgsl/endPass.wgsl b/shaders/wgsl/endPass.wgsl index 3ac1d32..dab4468 100644 --- a/shaders/wgsl/endPass.wgsl +++ b/shaders/wgsl/endPass.wgsl @@ -1,18 +1,18 @@ -[[group(0), binding(0)]] var nearestSampler : sampler; -[[group(0), binding(1)]] var tex : texture_2d; +@group(0) @binding(0) var nearestSampler : sampler; +@group(0) @binding(1) var tex : texture_2d; struct VertOutput { - [[builtin(position)]] Position : vec4; - [[location(0)]] uv : vec2; + @builtin(position) Position : vec4; + @location(0) uv : vec2; }; -[[stage(vertex)]] fn vertMain([[builtin(vertex_index)]] index : u32) -> VertOutput { +@stage(vertex) fn vertMain(@builtin(vertex_index) index : u32) -> VertOutput { var uv = vec2(f32(index % 2u), f32((index + 1u) % 6u / 3u)); var position = vec4(uv * 2.0 - 1.0, 1.0, 1.0); return VertOutput(position, uv); } -[[stage(fragment)]] fn fragMain(input : VertOutput) -> [[location(0)]] vec4 { +@stage(fragment) fn fragMain(input : VertOutput) -> @location(0) vec4 { var uv = input.uv; uv.y = 1.0 - uv.y; return textureSample( tex, nearestSampler, uv ); diff --git a/shaders/wgsl/imagePass.wgsl b/shaders/wgsl/imagePass.wgsl index 3d242e6..7bb1110 100644 --- a/shaders/wgsl/imagePass.wgsl +++ b/shaders/wgsl/imagePass.wgsl @@ -2,15 +2,15 @@ struct Config { bloomStrength : f32; }; -[[group(0), binding(0)]] var config : Config; -[[group(0), binding(1)]] var linearSampler : sampler; -[[group(0), binding(2)]] var tex : texture_2d; -[[group(0), binding(3)]] var bloomTex : texture_2d; -[[group(0), binding(4)]] var backgroundTex : texture_2d; -[[group(0), binding(5)]] var outputTex : texture_storage_2d; +@group(0) @binding(0) var config : Config; +@group(0) @binding(1) var linearSampler : sampler; +@group(0) @binding(2) var tex : texture_2d; +@group(0) @binding(3) var bloomTex : texture_2d; +@group(0) @binding(4) var backgroundTex : texture_2d; +@group(0) @binding(5) var outputTex : texture_storage_2d; struct ComputeInput { - [[builtin(global_invocation_id)]] id : vec3; + @builtin(global_invocation_id) id : vec3; }; fn getBrightness(uv : vec2) -> vec4 { @@ -19,7 +19,7 @@ fn getBrightness(uv : vec2) -> vec4 { return min((primary + bloom) * (2.0 - config.bloomStrength), vec4(1.0)); } -[[stage(compute), workgroup_size(32, 1, 1)]] fn computeMain(input : ComputeInput) { +@stage(compute) @workgroup_size(32, 1, 1) fn computeMain(input : ComputeInput) { // Resolve the invocation ID to a texel coordinate var coord = vec2(input.id.xy); diff --git a/shaders/wgsl/palettePass.wgsl b/shaders/wgsl/palettePass.wgsl index e490f53..67cb2e1 100644 --- a/shaders/wgsl/palettePass.wgsl +++ b/shaders/wgsl/palettePass.wgsl @@ -13,16 +13,16 @@ struct Time { frames : i32; }; -[[group(0), binding(0)]] var config : Config; -[[group(0), binding(1)]] var palette : Palette; -[[group(0), binding(2)]] var time : Time; -[[group(0), binding(3)]] var linearSampler : sampler; -[[group(0), binding(4)]] var tex : texture_2d; -[[group(0), binding(5)]] var bloomTex : texture_2d; -[[group(0), binding(6)]] var outputTex : texture_storage_2d; +@group(0) @binding(0) var config : Config; +@group(0) @binding(1) var palette : Palette; +@group(0) @binding(2) var time : Time; +@group(0) @binding(3) var linearSampler : sampler; +@group(0) @binding(4) var tex : texture_2d; +@group(0) @binding(5) var bloomTex : texture_2d; +@group(0) @binding(6) var outputTex : texture_storage_2d; struct ComputeInput { - [[builtin(global_invocation_id)]] id : vec3; + @builtin(global_invocation_id) id : vec3; }; let PI : f32 = 3.14159265359; @@ -42,7 +42,7 @@ fn getBrightness(uv : vec2) -> vec4 { return min((primary + bloom) * (2.0 - config.bloomStrength), vec4(1.0)); } -[[stage(compute), workgroup_size(32, 1, 1)]] fn computeMain(input : ComputeInput) { +@stage(compute) @workgroup_size(32, 1, 1) fn computeMain(input : ComputeInput) { // Resolve the invocation ID to a texel coordinate var coord = vec2(input.id.xy); diff --git a/shaders/wgsl/rainPass.wgsl b/shaders/wgsl/rainPass.wgsl index fd0c5bd..25b6ccf 100644 --- a/shaders/wgsl/rainPass.wgsl +++ b/shaders/wgsl/rainPass.wgsl @@ -60,38 +60,38 @@ struct CellData { }; // Shared bindings -[[group(0), binding(0)]] var config : Config; -[[group(0), binding(1)]] var time : Time; +@group(0) @binding(0) var config : Config; +@group(0) @binding(1) var time : Time; // Compute-specific bindings -[[group(0), binding(2)]] var cells_RW : CellData; +@group(0) @binding(2) var cells_RW : CellData; // Render-specific bindings -[[group(0), binding(2)]] var scene : Scene; -[[group(0), binding(3)]] var linearSampler : sampler; -[[group(0), binding(4)]] var msdfTexture : texture_2d; -[[group(0), binding(5)]] var cells_RO : CellData; +@group(0) @binding(2) var scene : Scene; +@group(0) @binding(3) var linearSampler : sampler; +@group(0) @binding(4) var msdfTexture : texture_2d; +@group(0) @binding(5) var cells_RO : CellData; // Shader params struct ComputeInput { - [[builtin(global_invocation_id)]] id : vec3; + @builtin(global_invocation_id) id : vec3; }; struct VertInput { - [[builtin(vertex_index)]] index : u32; + @builtin(vertex_index) index : u32; }; struct VertOutput { - [[builtin(position)]] Position : vec4; - [[location(0)]] uv : vec2; - [[location(1)]] channel : vec3; - [[location(2)]] glyph : vec4; + @builtin(position) Position : vec4; + @location(0) uv : vec2; + @location(1) channel : vec3; + @location(2) glyph : vec4; }; struct FragOutput { - [[location(0)]] color : vec4; - [[location(1)]] highPassColor : vec4; + @location(0) color : vec4; + @location(1) highPassColor : vec4; }; // Constants @@ -147,7 +147,7 @@ fn getCycleSpeed(rainTime : f32, brightness : f32) -> f32 { var localCycleSpeed = 0.0; if (config.cycleStyle == 0 && brightness > 0.0) { localCycleSpeed = pow(1.0 - brightness, 4.0); - } elseif (config.cycleStyle == 1) { + } else if (config.cycleStyle == 1) { localCycleSpeed = fract(rainTime); } return config.animationSpeed * config.cycleSpeed * localCycleSpeed; @@ -194,7 +194,7 @@ fn applyRippleEffect(effect : f32, simTime : f32, screenPos : vec2) -> f32 if (config.rippleType == 0) { var boxDistance = abs(ripplePos) * vec2(1.0, config.glyphHeightToWidth); rippleDistance = max(boxDistance.x, boxDistance.y); - } elseif (config.rippleType == 1) { + } else if (config.rippleType == 1) { rippleDistance = length(ripplePos); } @@ -277,7 +277,7 @@ fn computeResult (isFirstFrame : bool, previousResult : vec4, glyphPos : ve return result; } -[[stage(compute), workgroup_size(32, 1, 1)]] fn computeMain(input : ComputeInput) { +@stage(compute) @workgroup_size(32, 1, 1) fn computeMain(input : ComputeInput) { // Resolve the invocation ID to a cell coordinate var row = i32(input.id.y); @@ -305,7 +305,7 @@ fn computeResult (isFirstFrame : bool, previousResult : vec4, glyphPos : ve // vec2(1.0, 1.0), vec2(0.0, 1.0), vec2(1.0, 0.0) // ); -[[stage(vertex)]] fn vertMain(input : VertInput) -> VertOutput { +@stage(vertex) fn vertMain(input : VertInput) -> VertOutput { var volumetric = bool(config.volumetric); @@ -383,7 +383,7 @@ fn getSymbolUV(glyphCycle : f32) -> vec2 { // Fragment shader -[[stage(fragment)]] fn fragMain(input : VertOutput) -> FragOutput { +@stage(fragment) fn fragMain(input : VertOutput) -> FragOutput { var volumetric = bool(config.volumetric); var uv = input.uv; diff --git a/shaders/wgsl/resurrectionPass.wgsl b/shaders/wgsl/resurrectionPass.wgsl index 91fe0b7..275132c 100644 --- a/shaders/wgsl/resurrectionPass.wgsl +++ b/shaders/wgsl/resurrectionPass.wgsl @@ -9,15 +9,15 @@ struct Time { frames : i32; }; -[[group(0), binding(0)]] var config : Config; -[[group(0), binding(1)]] var time : Time; -[[group(0), binding(2)]] var linearSampler : sampler; -[[group(0), binding(3)]] var tex : texture_2d; -[[group(0), binding(4)]] var bloomTex : texture_2d; -[[group(0), binding(5)]] var outputTex : texture_storage_2d; +@group(0) @binding(0) var config : Config; +@group(0) @binding(1) var time : Time; +@group(0) @binding(2) var linearSampler : sampler; +@group(0) @binding(3) var tex : texture_2d; +@group(0) @binding(4) var bloomTex : texture_2d; +@group(0) @binding(5) var outputTex : texture_storage_2d; struct ComputeInput { - [[builtin(global_invocation_id)]] id : vec3; + @builtin(global_invocation_id) id : vec3; }; let PI : f32 = 3.14159265359; @@ -56,7 +56,7 @@ fn hslToRgb(h : f32, s : f32, l : f32) -> vec3 { ); } -[[stage(compute), workgroup_size(32, 1, 1)]] fn computeMain(input : ComputeInput) { +@stage(compute) @workgroup_size(32, 1, 1) fn computeMain(input : ComputeInput) { // Resolve the invocation ID to a texel coordinate var coord = vec2(input.id.xy); diff --git a/shaders/wgsl/stripePass.wgsl b/shaders/wgsl/stripePass.wgsl index 2bce982..98518f2 100644 --- a/shaders/wgsl/stripePass.wgsl +++ b/shaders/wgsl/stripePass.wgsl @@ -9,16 +9,16 @@ struct Time { frames : i32; }; -[[group(0), binding(0)]] var config : Config; -[[group(0), binding(1)]] var time : Time; -[[group(0), binding(2)]] var linearSampler : sampler; -[[group(0), binding(3)]] var tex : texture_2d; -[[group(0), binding(4)]] var bloomTex : texture_2d; -[[group(0), binding(5)]] var stripeTexture : texture_2d; -[[group(0), binding(6)]] var outputTex : texture_storage_2d; +@group(0) @binding(0) var config : Config; +@group(0) @binding(1) var time : Time; +@group(0) @binding(2) var linearSampler : sampler; +@group(0) @binding(3) var tex : texture_2d; +@group(0) @binding(4) var bloomTex : texture_2d; +@group(0) @binding(5) var stripeTexture : texture_2d; +@group(0) @binding(6) var outputTex : texture_storage_2d; struct ComputeInput { - [[builtin(global_invocation_id)]] id : vec3; + @builtin(global_invocation_id) id : vec3; }; let PI : f32 = 3.14159265359; @@ -38,7 +38,7 @@ fn getBrightness(uv : vec2) -> vec4 { return min((primary + bloom) * (2.0 - config.bloomStrength), vec4(1.0)); } -[[stage(compute), workgroup_size(32, 1, 1)]] fn computeMain(input : ComputeInput) { +@stage(compute) @workgroup_size(32, 1, 1) fn computeMain(input : ComputeInput) { // Resolve the invocation ID to a texel coordinate var coord = vec2(input.id.xy);