mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-15 21:09:29 -07:00
Binding syntax changes
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -5,13 +5,13 @@ struct Config {
|
||||
direction : vec2<f32>;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var<uniform> config : Config;
|
||||
[[group(0), binding(1)]] var linearSampler : sampler;
|
||||
[[group(0), binding(2)]] var tex : texture_2d<f32>;
|
||||
[[group(0), binding(3)]] var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
@group(0) @binding(0) var<uniform> config : Config;
|
||||
@group(0) @binding(1) var linearSampler : sampler;
|
||||
@group(0) @binding(2) var tex : texture_2d<f32>;
|
||||
@group(0) @binding(3) var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
|
||||
struct ComputeInput {
|
||||
[[builtin(global_invocation_id)]] id : vec3<u32>;
|
||||
@builtin(global_invocation_id) id : vec3<u32>;
|
||||
};
|
||||
|
||||
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<i32>(input.id.xy);
|
||||
var outputSize = textureDimensions(outputTex);
|
||||
|
||||
@@ -2,24 +2,24 @@ struct Config {
|
||||
pyramidHeight : f32;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var<uniform> config : Config;
|
||||
[[group(0), binding(1)]] var linearSampler : sampler;
|
||||
@group(0) @binding(0) var<uniform> 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<f32>;
|
||||
// [[group(0), binding(3)]] var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
// @group(0) @binding(2) var tex : texture_2d<f32>;
|
||||
// @group(0) @binding(3) var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
|
||||
[[group(0), binding(2)]] var tex1 : texture_2d<f32>;
|
||||
[[group(0), binding(3)]] var tex2 : texture_2d<f32>;
|
||||
[[group(0), binding(4)]] var tex3 : texture_2d<f32>;
|
||||
[[group(0), binding(5)]] var tex4 : texture_2d<f32>;
|
||||
[[group(0), binding(6)]] var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
@group(0) @binding(2) var tex1 : texture_2d<f32>;
|
||||
@group(0) @binding(3) var tex2 : texture_2d<f32>;
|
||||
@group(0) @binding(4) var tex3 : texture_2d<f32>;
|
||||
@group(0) @binding(5) var tex4 : texture_2d<f32>;
|
||||
@group(0) @binding(6) var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
|
||||
struct ComputeInput {
|
||||
[[builtin(global_invocation_id)]] id : vec3<u32>;
|
||||
@builtin(global_invocation_id) id : vec3<u32>;
|
||||
};
|
||||
|
||||
[[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<i32>(input.id.xy);
|
||||
var outputSize = textureDimensions(outputTex);
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
[[group(0), binding(0)]] var nearestSampler : sampler;
|
||||
[[group(0), binding(1)]] var tex : texture_2d<f32>;
|
||||
@group(0) @binding(0) var nearestSampler : sampler;
|
||||
@group(0) @binding(1) var tex : texture_2d<f32>;
|
||||
|
||||
struct VertOutput {
|
||||
[[builtin(position)]] Position : vec4<f32>;
|
||||
[[location(0)]] uv : vec2<f32>;
|
||||
@builtin(position) Position : vec4<f32>;
|
||||
@location(0) uv : vec2<f32>;
|
||||
};
|
||||
|
||||
[[stage(vertex)]] fn vertMain([[builtin(vertex_index)]] index : u32) -> VertOutput {
|
||||
@stage(vertex) fn vertMain(@builtin(vertex_index) index : u32) -> VertOutput {
|
||||
var uv = vec2<f32>(f32(index % 2u), f32((index + 1u) % 6u / 3u));
|
||||
var position = vec4<f32>(uv * 2.0 - 1.0, 1.0, 1.0);
|
||||
return VertOutput(position, uv);
|
||||
}
|
||||
|
||||
[[stage(fragment)]] fn fragMain(input : VertOutput) -> [[location(0)]] vec4<f32> {
|
||||
@stage(fragment) fn fragMain(input : VertOutput) -> @location(0) vec4<f32> {
|
||||
var uv = input.uv;
|
||||
uv.y = 1.0 - uv.y;
|
||||
return textureSample( tex, nearestSampler, uv );
|
||||
|
||||
@@ -2,15 +2,15 @@ struct Config {
|
||||
bloomStrength : f32;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var<uniform> config : Config;
|
||||
[[group(0), binding(1)]] var linearSampler : sampler;
|
||||
[[group(0), binding(2)]] var tex : texture_2d<f32>;
|
||||
[[group(0), binding(3)]] var bloomTex : texture_2d<f32>;
|
||||
[[group(0), binding(4)]] var backgroundTex : texture_2d<f32>;
|
||||
[[group(0), binding(5)]] var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
@group(0) @binding(0) var<uniform> config : Config;
|
||||
@group(0) @binding(1) var linearSampler : sampler;
|
||||
@group(0) @binding(2) var tex : texture_2d<f32>;
|
||||
@group(0) @binding(3) var bloomTex : texture_2d<f32>;
|
||||
@group(0) @binding(4) var backgroundTex : texture_2d<f32>;
|
||||
@group(0) @binding(5) var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
|
||||
struct ComputeInput {
|
||||
[[builtin(global_invocation_id)]] id : vec3<u32>;
|
||||
@builtin(global_invocation_id) id : vec3<u32>;
|
||||
};
|
||||
|
||||
fn getBrightness(uv : vec2<f32>) -> vec4<f32> {
|
||||
@@ -19,7 +19,7 @@ fn getBrightness(uv : vec2<f32>) -> vec4<f32> {
|
||||
return min((primary + bloom) * (2.0 - config.bloomStrength), vec4<f32>(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<i32>(input.id.xy);
|
||||
|
||||
@@ -13,16 +13,16 @@ struct Time {
|
||||
frames : i32;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var<uniform> config : Config;
|
||||
[[group(0), binding(1)]] var<uniform> palette : Palette;
|
||||
[[group(0), binding(2)]] var<uniform> time : Time;
|
||||
[[group(0), binding(3)]] var linearSampler : sampler;
|
||||
[[group(0), binding(4)]] var tex : texture_2d<f32>;
|
||||
[[group(0), binding(5)]] var bloomTex : texture_2d<f32>;
|
||||
[[group(0), binding(6)]] var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
@group(0) @binding(0) var<uniform> config : Config;
|
||||
@group(0) @binding(1) var<uniform> palette : Palette;
|
||||
@group(0) @binding(2) var<uniform> time : Time;
|
||||
@group(0) @binding(3) var linearSampler : sampler;
|
||||
@group(0) @binding(4) var tex : texture_2d<f32>;
|
||||
@group(0) @binding(5) var bloomTex : texture_2d<f32>;
|
||||
@group(0) @binding(6) var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
|
||||
struct ComputeInput {
|
||||
[[builtin(global_invocation_id)]] id : vec3<u32>;
|
||||
@builtin(global_invocation_id) id : vec3<u32>;
|
||||
};
|
||||
|
||||
let PI : f32 = 3.14159265359;
|
||||
@@ -42,7 +42,7 @@ fn getBrightness(uv : vec2<f32>) -> vec4<f32> {
|
||||
return min((primary + bloom) * (2.0 - config.bloomStrength), vec4<f32>(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<i32>(input.id.xy);
|
||||
|
||||
@@ -60,38 +60,38 @@ struct CellData {
|
||||
};
|
||||
|
||||
// Shared bindings
|
||||
[[group(0), binding(0)]] var<uniform> config : Config;
|
||||
[[group(0), binding(1)]] var<uniform> time : Time;
|
||||
@group(0) @binding(0) var<uniform> config : Config;
|
||||
@group(0) @binding(1) var<uniform> time : Time;
|
||||
|
||||
// Compute-specific bindings
|
||||
[[group(0), binding(2)]] var<storage, read_write> cells_RW : CellData;
|
||||
@group(0) @binding(2) var<storage, read_write> cells_RW : CellData;
|
||||
|
||||
// Render-specific bindings
|
||||
[[group(0), binding(2)]] var<uniform> scene : Scene;
|
||||
[[group(0), binding(3)]] var linearSampler : sampler;
|
||||
[[group(0), binding(4)]] var msdfTexture : texture_2d<f32>;
|
||||
[[group(0), binding(5)]] var<storage, read> cells_RO : CellData;
|
||||
@group(0) @binding(2) var<uniform> scene : Scene;
|
||||
@group(0) @binding(3) var linearSampler : sampler;
|
||||
@group(0) @binding(4) var msdfTexture : texture_2d<f32>;
|
||||
@group(0) @binding(5) var<storage, read> cells_RO : CellData;
|
||||
|
||||
// Shader params
|
||||
|
||||
struct ComputeInput {
|
||||
[[builtin(global_invocation_id)]] id : vec3<u32>;
|
||||
@builtin(global_invocation_id) id : vec3<u32>;
|
||||
};
|
||||
|
||||
struct VertInput {
|
||||
[[builtin(vertex_index)]] index : u32;
|
||||
@builtin(vertex_index) index : u32;
|
||||
};
|
||||
|
||||
struct VertOutput {
|
||||
[[builtin(position)]] Position : vec4<f32>;
|
||||
[[location(0)]] uv : vec2<f32>;
|
||||
[[location(1)]] channel : vec3<f32>;
|
||||
[[location(2)]] glyph : vec4<f32>;
|
||||
@builtin(position) Position : vec4<f32>;
|
||||
@location(0) uv : vec2<f32>;
|
||||
@location(1) channel : vec3<f32>;
|
||||
@location(2) glyph : vec4<f32>;
|
||||
};
|
||||
|
||||
struct FragOutput {
|
||||
[[location(0)]] color : vec4<f32>;
|
||||
[[location(1)]] highPassColor : vec4<f32>;
|
||||
@location(0) color : vec4<f32>;
|
||||
@location(1) highPassColor : vec4<f32>;
|
||||
};
|
||||
|
||||
// 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>) -> f32
|
||||
if (config.rippleType == 0) {
|
||||
var boxDistance = abs(ripplePos) * vec2<f32>(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<f32>, 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<f32>, glyphPos : ve
|
||||
// vec2<f32>(1.0, 1.0), vec2<f32>(0.0, 1.0), vec2<f32>(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<f32> {
|
||||
|
||||
// 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;
|
||||
|
||||
@@ -9,15 +9,15 @@ struct Time {
|
||||
frames : i32;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var<uniform> config : Config;
|
||||
[[group(0), binding(1)]] var<uniform> time : Time;
|
||||
[[group(0), binding(2)]] var linearSampler : sampler;
|
||||
[[group(0), binding(3)]] var tex : texture_2d<f32>;
|
||||
[[group(0), binding(4)]] var bloomTex : texture_2d<f32>;
|
||||
[[group(0), binding(5)]] var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
@group(0) @binding(0) var<uniform> config : Config;
|
||||
@group(0) @binding(1) var<uniform> time : Time;
|
||||
@group(0) @binding(2) var linearSampler : sampler;
|
||||
@group(0) @binding(3) var tex : texture_2d<f32>;
|
||||
@group(0) @binding(4) var bloomTex : texture_2d<f32>;
|
||||
@group(0) @binding(5) var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
|
||||
struct ComputeInput {
|
||||
[[builtin(global_invocation_id)]] id : vec3<u32>;
|
||||
@builtin(global_invocation_id) id : vec3<u32>;
|
||||
};
|
||||
|
||||
let PI : f32 = 3.14159265359;
|
||||
@@ -56,7 +56,7 @@ fn hslToRgb(h : f32, s : f32, l : f32) -> vec3<f32> {
|
||||
);
|
||||
}
|
||||
|
||||
[[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<i32>(input.id.xy);
|
||||
|
||||
@@ -9,16 +9,16 @@ struct Time {
|
||||
frames : i32;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var<uniform> config : Config;
|
||||
[[group(0), binding(1)]] var<uniform> time : Time;
|
||||
[[group(0), binding(2)]] var linearSampler : sampler;
|
||||
[[group(0), binding(3)]] var tex : texture_2d<f32>;
|
||||
[[group(0), binding(4)]] var bloomTex : texture_2d<f32>;
|
||||
[[group(0), binding(5)]] var stripeTexture : texture_2d<f32>;
|
||||
[[group(0), binding(6)]] var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
@group(0) @binding(0) var<uniform> config : Config;
|
||||
@group(0) @binding(1) var<uniform> time : Time;
|
||||
@group(0) @binding(2) var linearSampler : sampler;
|
||||
@group(0) @binding(3) var tex : texture_2d<f32>;
|
||||
@group(0) @binding(4) var bloomTex : texture_2d<f32>;
|
||||
@group(0) @binding(5) var stripeTexture : texture_2d<f32>;
|
||||
@group(0) @binding(6) var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
|
||||
struct ComputeInput {
|
||||
[[builtin(global_invocation_id)]] id : vec3<u32>;
|
||||
@builtin(global_invocation_id) id : vec3<u32>;
|
||||
};
|
||||
|
||||
let PI : f32 = 3.14159265359;
|
||||
@@ -38,7 +38,7 @@ fn getBrightness(uv : vec2<f32>) -> vec4<f32> {
|
||||
return min((primary + bloom) * (2.0 - config.bloomStrength), vec4<f32>(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<i32>(input.id.xy);
|
||||
|
||||
Reference in New Issue
Block a user