diff --git a/lib/wgputoy/bind.ts b/lib/wgputoy/bind.ts index 08a7388..d50575f 100644 --- a/lib/wgputoy/bind.ts +++ b/lib/wgputoy/bind.ts @@ -93,7 +93,12 @@ class BufferBinding implements Binding { // bind: (buffer: GPUBuffer) => GPUBufferBinding; decl: string; - constructor(params) { + constructor(params: { + host: H; + device: GPUBuffer; + layout: GPUBufferBindingLayout; + decl: string; + }) { this.host = params.host; this.device = params.device; this.layout = params.layout; @@ -124,7 +129,12 @@ class TextureBinding implements Binding { layout: GPUTextureBindingLayout; decl: string; - constructor(params) { + constructor(params: { + device: GPUTexture; + view: GPUTextureView; + layout: GPUTextureBindingLayout; + decl: string; + }) { this.device = params.device; this.view = params.view; this.layout = params.layout; @@ -383,7 +393,7 @@ export class Bindings { size: USER_DATA_BYTES, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST }), - layout: { ...storageBuffer, buffer: { type: 'read-only-storage' } }, + layout: { ...storageBuffer, type: 'read-only-storage' }, // bind: (buffer) => ({ offset: 0, size: USER_DATA_BYTES }), decl: 'var data: Data' }); @@ -454,7 +464,7 @@ export class Bindings { dimension: '2d-array' }), layout: { - sampleType: 'float', + sampleType: passF32 ? 'unfilterable-float' : 'float', viewDimension: '2d-array', multisampled: false }, diff --git a/lib/wgputoy/preprocessor.ts b/lib/wgputoy/preprocessor.ts index bd9a137..bf7483c 100644 --- a/lib/wgputoy/preprocessor.ts +++ b/lib/wgputoy/preprocessor.ts @@ -6,8 +6,6 @@ import { fetchInclude, parseUint32, WGSLError } from './utils'; // Regular expressions for preprocessing const RE_COMMENT = /(\/\/.*|\/\*[\s\S]*?\*\/)/g; -const RE_QUOTES = /"((?:[^\\"]|\\.)*)"/g; -const RE_CHEVRONS = /<(.*)>/; const RE_WORD = /[a-zA-Z_][a-zA-Z0-9_]*/g; const STRING_MAX_LEN = 20; @@ -130,7 +128,7 @@ export class Preprocessor { // Handle string literals if enabled if (this.specialStrings) { let error: WGSLError | null = null; - line = line.replace(RE_QUOTES, match => { + line = line.replace(/"((?:[^\\"]|\\.)*)"/g, match => { try { const unescaped = JSON.parse(match) as string; const chars = Array.from(unescaped).map(c => c.charCodeAt(0)); @@ -173,17 +171,17 @@ export class Preprocessor { throw new WGSLError('Invalid #include syntax', lineNum); } - const nameMatcher = tokens[1].match(RE_QUOTES) || tokens[1].match(RE_CHEVRONS); + const nameMatcher = tokens[1].match(/"(.*)"/) || tokens[1].match(/<(.*)>/); if (!nameMatcher) { throw new WGSLError('Path must be enclosed in quotes or chevrons', lineNum); } const name = nameMatcher[1]; - if (RE_CHEVRONS.test(tokens[1]) && name === 'string') { + if (/<.*>/.test(tokens[1]) && name === 'string') { this.specialStrings = true; } - const includePath = RE_CHEVRONS.test(tokens[1]) ? `std/${name}` : name; + const includePath = /<.*>/.test(tokens[1]) ? `std/${name}` : name; const includeContent = await fetchInclude(includePath); if (!includeContent) {