From 806f6a0c49aece5c295cf78a9ff719e5d8f80fb1 Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Mon, 1 Jul 2024 17:13:41 -0700 Subject: [PATCH] support minBindingSize in bindGroupLayouts --- src/data-definitions.ts | 5 +++- test/tests/data-definition-test.js | 44 ++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/data-definitions.ts b/src/data-definitions.ts index 1d61a74..0677f12 100644 --- a/src/data-definitions.ts +++ b/src/data-definitions.ts @@ -281,7 +281,9 @@ function getBindGroupLayoutEntry(resource: VariableInfo, visibility: GPUShaderSt return { binding, visibility, - buffer: { }, + buffer: { + ...(resource.size && { minBindingSize: resource.size }), + }, }; case ResourceType.Storage: return { @@ -289,6 +291,7 @@ function getBindGroupLayoutEntry(resource: VariableInfo, visibility: GPUShaderSt visibility, buffer: { type: (access === '' || access === 'read') ? 'read-only-storage' : 'storage', + ...(resource.size && { minBindingSize: resource.size }), }, }; case ResourceType.Texture: { diff --git a/test/tests/data-definition-test.js b/test/tests/data-definition-test.js index b83d7ca..395e362 100644 --- a/test/tests/data-definition-test.js +++ b/test/tests/data-definition-test.js @@ -216,8 +216,8 @@ describe('data-definition-tests', () => { @group(0) @binding(5) var texExt: texture_external; @group(1) @binding(0) var u: mat4x4f; @group(1) @binding(1) var s: mat4x4f; - @group(1) @binding(2) var sr: mat4x4f; - @group(1) @binding(3) var srw: mat4x4f; + @group(1) @binding(2) var sr: array; + @group(1) @binding(3) var srw: array; @group(3) @binding(0) var tsR: texture_storage_2d; @group(3) @binding(1) var tsW: texture_storage_2d; @group(3) @binding(2) var tsRW: texture_storage_2d; @@ -283,21 +283,29 @@ describe('data-definition-tests', () => { }, "sr": { "typeDefinition": { - "size": 64, - "type": "mat4x4f", + "size": 160, + "numElements": 10, + "elementType": { + "size": 16, + "type": "vec4f", + }, }, "group": 1, "binding": 2, - "size": 64, + "size": 160, }, "srw": { "typeDefinition": { - "size": 64, - "type": "mat4x4f", + "size": 0, + "numElements": 0, + "elementType": { + "size": 16, + "type": "vec4f", + }, }, "group": 1, "binding": 3, - "size": 64, + "size": 0, }, }, "storageTextures": { @@ -449,7 +457,9 @@ describe('data-definition-tests', () => { "entry": { "binding": 0, "visibility": 1, - "buffer": {}, + "buffer": { + "minBindingSize": 64, + }, }, }, { @@ -460,6 +470,7 @@ describe('data-definition-tests', () => { "visibility": 1, "buffer": { "type": "read-only-storage", + "minBindingSize": 64, }, }, }, @@ -471,6 +482,7 @@ describe('data-definition-tests', () => { "visibility": 1, "buffer": { "type": "read-only-storage", + "minBindingSize": 160, }, }, }, @@ -546,8 +558,8 @@ describe('data-definition-tests', () => { @group(0) @binding(5) var texExt: texture_external; @group(1) @binding(0) var u: mat4x4f; @group(1) @binding(1) var s: mat4x4f; - @group(1) @binding(2) var sr: mat4x4f; - @group(1) @binding(3) var srw: mat4x4f; + @group(1) @binding(2) var sr: array; + @group(1) @binding(3) var srw: array; @group(3) @binding(0) var tsR: texture_storage_2d; @group(3) @binding(1) var tsW: texture_storage_2d; @group(3) @binding(2) var tsRW: texture_storage_2d; @@ -630,13 +642,16 @@ describe('data-definition-tests', () => { { binding: 0, visibility: 1, - buffer: {}, + buffer: { + minBindingSize: 64, + }, }, { binding: 1, visibility: 1, buffer: { type: 'read-only-storage', + minBindingSize: 64, }, }, { @@ -644,6 +659,7 @@ describe('data-definition-tests', () => { visibility: 1, buffer: { type: 'read-only-storage', + minBindingSize: 160, }, }, { @@ -816,6 +832,7 @@ describe('data-definition-tests', () => { binding: 1, visibility: 4, buffer: { + minBindingSize: 16, }, }, ], @@ -858,12 +875,14 @@ describe('data-definition-tests', () => { binding: 3, visibility: 4, buffer: { + minBindingSize: 16, }, }, { binding: 4, visibility: 4, buffer: { + minBindingSize: 16, }, }, ], @@ -899,6 +918,7 @@ describe('data-definition-tests', () => { binding: 3, visibility: 1, buffer: { + minBindingSize: 16, }, }, ],