They removed [[block]] from WGSL struct declarations.

This commit is contained in:
Rezmason
2021-12-14 23:01:53 -08:00
parent 17b6d7b9aa
commit 68ad689e1e
8 changed files with 19 additions and 19 deletions

View File

@@ -50,7 +50,7 @@ export default async (canvas, config) => {
GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST, GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST,
}; };
const timeUniforms = structs.from(`[[block]] struct Time { seconds : f32; frames : i32; };`).Time; const timeUniforms = structs.from(`struct Time { seconds : f32; frames : i32; };`).Time;
const timeBuffer = makeUniformBuffer(device, timeUniforms); const timeBuffer = makeUniformBuffer(device, timeUniforms);
const context = { const context = {

View File

@@ -123,7 +123,7 @@ const parseAttributes = (str) => {
return attributes; return attributes;
}; };
const parseStructLayout = (identifier, body, isBlock, structLayouts) => { const parseStructLayout = (identifier, body, structLayouts) => {
const fields = []; const fields = [];
let byteOffset = 0; let byteOffset = 0;
const lines = body const lines = body
@@ -154,7 +154,7 @@ const parseStructLayout = (identifier, body, isBlock, structLayouts) => {
const minSizeInBytes = byteOffset; const minSizeInBytes = byteOffset;
const align = Math.max(...fields.map((field) => field.align)); const align = Math.max(...fields.map((field) => field.align));
const size = Math.ceil(minSizeInBytes / align) * align; const size = Math.ceil(minSizeInBytes / align) * align;
return { identifier, isBlock, fields, size, align }; return { identifier, fields, size, align };
}; };
const parseStructLayoutsFromShader = (wgsl) => { const parseStructLayoutsFromShader = (wgsl) => {
@@ -164,10 +164,10 @@ const parseStructLayoutsFromShader = (wgsl) => {
.replace(/\s+/gm, " "); // convert all contiguous whitespace to single space characters .replace(/\s+/gm, " "); // convert all contiguous whitespace to single space characters
const structLayouts = {}; const structLayouts = {};
const structMatches = Array.from(wgsl.matchAll(/(\[\[block\]\])? ?struct (\w+) ?\{(.*?)\};/g)); // [[block]] struct Foo {...} const structMatches = Array.from(wgsl.matchAll(/struct (\w+) ?\{(.*?)\};/g)); // struct Foo {...}
for (const structMatch of structMatches) { for (const structMatch of structMatches) {
const [_, block, identifier, body] = structMatch; const [_, identifier, body] = structMatch;
const layout = parseStructLayout(identifier, body, block != null, structLayouts); const layout = parseStructLayout(identifier, body, structLayouts);
if (layout != null) { if (layout != null) {
structLayouts[layout.identifier] = layout; structLayouts[layout.identifier] = layout;
} }

View File

@@ -1,6 +1,6 @@
let ONE_OVER_SQRT_2PI = 0.39894; let ONE_OVER_SQRT_2PI = 0.39894;
[[block]] struct Config { struct Config {
bloomRadius : f32; bloomRadius : f32;
direction : vec2<f32>; direction : vec2<f32>;
}; };

View File

@@ -1,4 +1,4 @@
[[block]] struct Config { struct Config {
bloomStrength : f32; bloomStrength : f32;
pyramidHeight : f32; pyramidHeight : f32;
}; };

View File

@@ -1,13 +1,13 @@
[[block]] struct Config { struct Config {
ditherMagnitude : f32; ditherMagnitude : f32;
backgroundColor : vec3<f32>; backgroundColor : vec3<f32>;
}; };
[[block]] struct Palette { struct Palette {
colors : array<vec3<f32>, 512>; colors : array<vec3<f32>, 512>;
}; };
[[block]] struct Time { struct Time {
seconds : f32; seconds : f32;
frames : i32; frames : i32;
}; };

View File

@@ -1,7 +1,7 @@
// This shader module is the star of the show. // This shader module is the star of the show.
// It is where the cell states update and the symbols get drawn to the screen. // It is where the cell states update and the symbols get drawn to the screen.
[[block]] struct Config { struct Config {
// common properties used for compute and rendering // common properties used for compute and rendering
animationSpeed : f32; animationSpeed : f32;
glyphSequenceLength : i32; glyphSequenceLength : i32;
@@ -41,20 +41,20 @@
}; };
// The properties that change over time get their own buffer. // The properties that change over time get their own buffer.
[[block]] struct Time { struct Time {
seconds : f32; seconds : f32;
frames : i32; frames : i32;
}; };
// The properties related to the size of the canvas get their own buffer. // The properties related to the size of the canvas get their own buffer.
[[block]] struct Scene { struct Scene {
screenSize : vec2<f32>; screenSize : vec2<f32>;
camera : mat4x4<f32>; camera : mat4x4<f32>;
transform : mat4x4<f32>; transform : mat4x4<f32>;
}; };
// The array of cells that the compute shader updates, and the fragment shader draws. // The array of cells that the compute shader updates, and the fragment shader draws.
[[block]] struct CellData { struct CellData {
cells: array<vec4<f32>>; cells: array<vec4<f32>>;
}; };

View File

@@ -1,9 +1,9 @@
[[block]] struct Config { struct Config {
ditherMagnitude : f32; ditherMagnitude : f32;
backgroundColor : vec3<f32>; backgroundColor : vec3<f32>;
}; };
[[block]] struct Time { struct Time {
seconds : f32; seconds : f32;
frames : i32; frames : i32;
}; };

View File

@@ -1,9 +1,9 @@
[[block]] struct Config { struct Config {
ditherMagnitude : f32; ditherMagnitude : f32;
backgroundColor : vec3<f32>; backgroundColor : vec3<f32>;
}; };
[[block]] struct Time { struct Time {
seconds : f32; seconds : f32;
frames : i32; frames : i32;
}; };