Skip to content

Store type for buffer does not have to be structure#2401

Merged
dneto0 merged 7 commits intogpuweb:mainfrom
dneto0:issue-2188-buffer-non-struct
Jan 19, 2022
Merged

Store type for buffer does not have to be structure#2401
dneto0 merged 7 commits intogpuweb:mainfrom
dneto0:issue-2188-buffer-non-struct

Conversation

@dneto0
Copy link
Contributor

@dneto0 dneto0 commented Dec 8, 2021

  • Modify an example showing a runtime-sized array as the store type
    for a storage buffer.

Fixes: #2188


Preview | Diff

@dneto0 dneto0 added the wgsl WebGPU Shading Language Issues label Dec 8, 2021
@dneto0 dneto0 added this to the V1.0 milestone Dec 8, 2021
@dneto0
Copy link
Contributor Author

dneto0 commented Dec 8, 2021

cc: @ben-clayton @Kangz

wgsl/index.bs Outdated

// Uniform buffer. Always read-only, and has more restrictive layout rules.
struct ParamsTable {};
struct ParamsTable {gain: f32;};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Structures always have at least one member. Fix this example.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2021

Previews, as seen when this build job started (64aace6):
WebGPU | IDL
WGSL
Explainer

@Kangz
Copy link
Contributor

Kangz commented Dec 9, 2021

This is great!

@kvark
Copy link
Contributor

kvark commented Dec 15, 2021

Just because we can support non-structures doesn't mean we should. Is this supported by anything except Metal in lower level APIS? There is a few of us feeling that WGSL would be a better language if it only allows structures and arrays in this position, not arbitrary types. #2188 (comment)

Copy link
Contributor

@alan-baker alan-baker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this likely needs a change in the WebGPU spec for GPUProgrammableShaderStage validation. That validation explicitly refers to structures for the WGSL variable.

@dneto0 dneto0 force-pushed the issue-2188-buffer-non-struct branch from 64aace6 to 5fc2495 Compare January 11, 2022 22:37
@dneto0
Copy link
Contributor Author

dneto0 commented Jan 11, 2022

Only a rebase for now...

@github-actions
Copy link
Contributor

Previews, as seen when this build job started (5fc2495):
WebGPU | IDL
WGSL
Explainer

@dneto0 dneto0 requested a review from alan-baker January 11, 2022 22:50
@github-actions
Copy link
Contributor

Previews, as seen when this build job started (0510cf7):
WebGPU | IDL
WGSL
Explainer

@github-actions
Copy link
Contributor

Previews, as seen when this build job started (a8efbee):
WebGPU | IDL
WGSL
Explainer

@dneto0 dneto0 force-pushed the issue-2188-buffer-non-struct branch from a8efbee to 8833b30 Compare January 12, 2022 22:47
@github-actions
Copy link
Contributor

Previews, as seen when this build job started (8833b30):
WebGPU | IDL
WGSL
Explainer

@github-actions
Copy link
Contributor

Previews, as seen when this build job started (2959e17):
WebGPU | IDL
WGSL
Explainer

@github-actions
Copy link
Contributor

Previews, as seen when this build job started (2f834e6):
WebGPU | IDL
WGSL
Explainer

* Modify an example showing a runtime-sized array as the store type
  for a storage buffer.

Fixes: gpuweb#2188
The store type of the corresponding variable is not always
going to be a structure type. Qualify the rule accordingly.
Define 'minimum binding size' in WGSL spec, and link to it from WebGPU.
Repeat the rule in both places (to be helpful).

The minimum binding size for a var with store type |T| is
max(AlignOf(T),SizeOf(T)), and explain why the AlignOf part is needed:
it's because sometimes we have to wrap |T| in a struct.

This also replaces the old rule in WGSL which confusingly dependend
on the storage class.  The storage class aspect is already embedded
in the alignment and size constraints for the variable.
Underlying APIs don't need the extra padding at the end of any
structure which might wrap the store type for the buffer variable.
@dneto0 dneto0 force-pushed the issue-2188-buffer-non-struct branch from 2f834e6 to bf408ae Compare January 19, 2022 21:20
@dneto0
Copy link
Contributor Author

dneto0 commented Jan 19, 2022

I did a rebase and resolve conflicts.
Need to apply feedback

@github-actions
Copy link
Contributor

Previews, as seen when this build job started (bf408ae):
WebGPU | IDL
WGSL
Explainer

- Link to SizeOf in the WGSL spec
- More carefully describe the motivation for the min-binding-size
  constraint.
@github-actions
Copy link
Contributor

Previews, as seen when this build job started (8f7f725):
WebGPU | IDL
WGSL
Explainer

"Mapping" is how the buffer's storage is paged into host-accessible
address space. That's a different concept entirely, and would only
confuse things.
@github-actions
Copy link
Contributor

Previews, as seen when this build job started (bdce411):
WebGPU | IDL
WGSL
Explainer

@dneto0 dneto0 merged commit 5a0cbb2 into gpuweb:main Jan 19, 2022
github-actions bot added a commit that referenced this pull request Jan 19, 2022
SHA: 5a0cbb2
Reason: push, by @dneto0

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Jan 19, 2022
SHA: 5a0cbb2
Reason: push, by @dneto0

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Jan 19, 2022
SHA: 5a0cbb2
Reason: push, by @dneto0

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
RobinMorisset pushed a commit to RobinMorisset/gpuweb that referenced this pull request Jan 24, 2022
* Store type for buffer does not have to be structure

* Modify an example showing a runtime-sized array as the store type
  for a storage buffer.

Fixes: gpuweb#2188

* Update the API-side rules about minBindingSize

The store type of the corresponding variable is not always
going to be a structure type. Qualify the rule accordingly.

* Rework minimum binding size in both WebGPU and WGSL spec

Define 'minimum binding size' in WGSL spec, and link to it from WebGPU.
Repeat the rule in both places (to be helpful).

The minimum binding size for a var with store type |T| is
max(AlignOf(T),SizeOf(T)), and explain why the AlignOf part is needed:
it's because sometimes we have to wrap |T| in a struct.

This also replaces the old rule in WGSL which confusingly dependend
on the storage class.  The storage class aspect is already embedded
in the alignment and size constraints for the variable.

* Simplify minimum binding size to Sizeof(store-type)

Underlying APIs don't need the extra padding at the end of any
structure which might wrap the store type for the buffer variable.

* Update API-side to SizeOf(store-type)

* Apply review feedback

- Link to SizeOf in the WGSL spec
- More carefully describe the motivation for the min-binding-size
  constraint.

* Simplify, and avoid using the word "mapping"

"Mapping" is how the buffer's storage is paged into host-accessible
address space. That's a different concept entirely, and would only
confuse things.
RobinMorisset pushed a commit to RobinMorisset/gpuweb that referenced this pull request Jan 24, 2022
* Store type for buffer does not have to be structure

* Modify an example showing a runtime-sized array as the store type
  for a storage buffer.

Fixes: gpuweb#2188

* Update the API-side rules about minBindingSize

The store type of the corresponding variable is not always
going to be a structure type. Qualify the rule accordingly.

* Rework minimum binding size in both WebGPU and WGSL spec

Define 'minimum binding size' in WGSL spec, and link to it from WebGPU.
Repeat the rule in both places (to be helpful).

The minimum binding size for a var with store type |T| is
max(AlignOf(T),SizeOf(T)), and explain why the AlignOf part is needed:
it's because sometimes we have to wrap |T| in a struct.

This also replaces the old rule in WGSL which confusingly dependend
on the storage class.  The storage class aspect is already embedded
in the alignment and size constraints for the variable.

* Simplify minimum binding size to Sizeof(store-type)

Underlying APIs don't need the extra padding at the end of any
structure which might wrap the store type for the buffer variable.

* Update API-side to SizeOf(store-type)

* Apply review feedback

- Link to SizeOf in the WGSL spec
- More carefully describe the motivation for the min-binding-size
  constraint.

* Simplify, and avoid using the word "mapping"

"Mapping" is how the buffer's storage is paged into host-accessible
address space. That's a different concept entirely, and would only
confuse things.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wgsl WebGPU Shading Language Issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Storage variables shouldn't be required to be structs

5 participants