Skip to content

Commit

Permalink
support minBindingSize in bindGroupLayouts
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jul 2, 2024
1 parent 1ca52b6 commit 6cf4052
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/data-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,17 @@ function getBindGroupLayoutEntry(resource: VariableInfo, visibility: GPUShaderSt
return {
binding,
visibility,
buffer: { },
buffer: {
...(resource.size && { minBindingSize: resource.size }),
},
};
case ResourceType.Storage:
return {
binding,
visibility,
buffer: {
type: (access === '' || access === 'read') ? 'read-only-storage' : 'storage',
...(resource.size && { minBindingSize: resource.size }),
},
};
case ResourceType.Texture: {
Expand Down
44 changes: 32 additions & 12 deletions test/tests/data-definition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ describe('data-definition-tests', () => {
@group(0) @binding(5) var texExt: texture_external;
@group(1) @binding(0) var<uniform> u: mat4x4f;
@group(1) @binding(1) var<storage> s: mat4x4f;
@group(1) @binding(2) var<storage, read> sr: mat4x4f;
@group(1) @binding(3) var<storage, read_write> srw: mat4x4f;
@group(1) @binding(2) var<storage, read> sr: array<vec4f, 10>;
@group(1) @binding(3) var<storage, read_write> srw: array<vec4f>;
@group(3) @binding(0) var tsR: texture_storage_2d<rgba8unorm, read>;
@group(3) @binding(1) var tsW: texture_storage_2d<rgba32float, write>;
@group(3) @binding(2) var tsRW: texture_storage_2d<rgba16uint, read_write>;
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -449,7 +457,9 @@ describe('data-definition-tests', () => {
"entry": {
"binding": 0,
"visibility": 1,
"buffer": {},
"buffer": {
"minBindingSize": 64,
},
},
},
{
Expand All @@ -460,6 +470,7 @@ describe('data-definition-tests', () => {
"visibility": 1,
"buffer": {
"type": "read-only-storage",
"minBindingSize": 64,
},
},
},
Expand All @@ -471,6 +482,7 @@ describe('data-definition-tests', () => {
"visibility": 1,
"buffer": {
"type": "read-only-storage",
"minBindingSize": 160,
},
},
},
Expand Down Expand Up @@ -546,8 +558,8 @@ describe('data-definition-tests', () => {
@group(0) @binding(5) var texExt: texture_external;
@group(1) @binding(0) var<uniform> u: mat4x4f;
@group(1) @binding(1) var<storage> s: mat4x4f;
@group(1) @binding(2) var<storage, read> sr: mat4x4f;
@group(1) @binding(3) var<storage, read_write> srw: mat4x4f;
@group(1) @binding(2) var<storage, read> sr: array<vec4f, 10>;
@group(1) @binding(3) var<storage, read_write> srw: array<vec4f>;
@group(3) @binding(0) var tsR: texture_storage_2d<rgba8unorm, read>;
@group(3) @binding(1) var tsW: texture_storage_2d<rgba32float, write>;
@group(3) @binding(2) var tsRW: texture_storage_2d<rgba16uint, read_write>;
Expand Down Expand Up @@ -630,20 +642,24 @@ describe('data-definition-tests', () => {
{
binding: 0,
visibility: 1,
buffer: {},
buffer: {
minBindingSize: 64,
},
},
{
binding: 1,
visibility: 1,
buffer: {
type: 'read-only-storage',
minBindingSize: 64,
},
},
{
binding: 2,
visibility: 1,
buffer: {
type: 'read-only-storage',
minBindingSize: 160,
},
},
{
Expand Down Expand Up @@ -816,6 +832,7 @@ describe('data-definition-tests', () => {
binding: 1,
visibility: 4,
buffer: {
minBindingSize: 16,
},
},
],
Expand Down Expand Up @@ -858,12 +875,14 @@ describe('data-definition-tests', () => {
binding: 3,
visibility: 4,
buffer: {
minBindingSize: 16,
},
},
{
binding: 4,
visibility: 4,
buffer: {
minBindingSize: 16,
},
},
],
Expand Down Expand Up @@ -899,6 +918,7 @@ describe('data-definition-tests', () => {
binding: 3,
visibility: 1,
buffer: {
minBindingSize: 16,
},
},
],
Expand Down

0 comments on commit 6cf4052

Please sign in to comment.