Skip to content

Add read_only decoration to variables. - #1120

Closed
dj2 wants to merge 1 commit into
gpuweb:mainfrom
dj2:ro
Closed

dj2 wants to merge 1 commit into
gpuweb:mainfrom
dj2:ro

Conversation

@dj2

@dj2 dj2 commented Sep 30, 2020

Copy link
Copy Markdown
Member

This CL adds the read_only decoration to variables. This may only be
used on storage_buffer storage class variables.

Issue #935

This CL adds the `read_only` decoration to variables. This may only be
used on `storage_buffer` storage class variables.

Issue #935
@dj2 dj2 added the wgsl WebGPU Shading Language Issues label Sep 30, 2020
@dj2 dj2 added this to the MVP milestone Sep 30, 2020
@dj2
dj2 requested review from dneto0 and kvark September 30, 2020 15:19
@dj2 dj2 self-assigned this Sep 30, 2020
@dj2

dj2 commented Sep 30, 2020

Copy link
Copy Markdown
Member Author

I put this on the variable instead of the type. Putting it on the type gets more complicated in SPIR-V as you may need to generate the same type multiple times with different decorations. If the same struct is used for a uniform and storage_buffer variable one would have NonWritable members but the other wouldn't.

Moving to the variable cleaners that up with the further restriction that read_only may only decorate storage_buffer variables. We then decorate the OpVariable in SPIR-V.

@kvark

kvark commented Sep 30, 2020

Copy link
Copy Markdown
Contributor

I put this on the variable instead of the type. Putting it on the type gets more complicated in SPIR-V as you may need to generate the same type multiple times with different decorations. If the same struct is used for a uniform and storage_buffer variable one would have NonWritable members but the other wouldn't.

I specifically requested us to be consistent here. This argument already applies to texture types (where the read-only/write-only is a property of the type in WGSL but the variable in SPIR-V), so nothing new to be handled by the implementation. We need to have both textures and buffers read-only properties be either on the variable, or on the type, but not mixed up.

@dneto0 dneto0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is the right change.

@dj2

dj2 commented Sep 30, 2020

Copy link
Copy Markdown
Member Author

Yup, I understand the consistency argument and I think we need to talk about it. From a SPIR-V perspective, this way makes the most sense. Maybe there is a better way to do this, or maybe we need to revisit the texture types and move the ro, wo to the variable there as well?

@kvark

kvark commented Sep 30, 2020

Copy link
Copy Markdown
Contributor

From a SPIR-V perspective, this way makes the most sense.

Which way? The current way of this PR? or the current spec for WGSL textures?

I think we can go either way. Having the textures separated at the type level makes up for a stronger grammer, but ultimately not require, and we'd be totally fine validating this at shader module creation time.

@dneto0

dneto0 commented Sep 30, 2020 •

Copy link
Copy Markdown
Contributor

We need to have both textures and buffers read-only properties be either on the variable, or on the type, but not mixed up.

There's may be a significant distinction. The texture types are only accessed via builtin, and the available builtins are determined by types, so it's highly suggestive to distinguish the textures by type.

For buffers, the variables are accessed directly. So there's less of a reason to distinguish by type.

Read-only-ness for buffers is like the const qualifier in C++. It goes with a value type, and distinguishes poitner-to-const vs. pointer-to-non-const.

But this is worth talking through.


edited first line to properly show that it was a quote

@dneto0

dneto0 commented Sep 30, 2020

Copy link
Copy Markdown
Contributor

By "goes with a value type" I mean is not used for overload resolution, specifically. (If I remember correctly.)

@kvark

kvark commented Sep 30, 2020

Copy link
Copy Markdown
Contributor

The texture types are only accessed via builtin, and the available builtins are determined by types, so it's highly suggestive to distinguish the textures by type.

We could make it so textureLoad and textureStore accept a texture_storage_xxx at the type level. Then the validation rules say that the former is only valid for read-only storage textures, and the latter is only valid for write-only storage textures, based on the access qualifiers on the global variable.

The downside is that it's a little bit more abstract than what we have today (somewhat related to the discussion about abstracting away the grammar for decorators, builtins, etc). The upside is that it would map perfectly to SPIR-V.

Here is a quick table showing the differences between the target APIs with regards to read-only property:

Backend Buffer Texture
SPIR-V variable variable
HLSL type type
Metal variable type

If the property is on the type, it's making the SPIR-V frontend work more complicated. It may need to generate a duplicate type in case the same SPIR-V type is used as both write-only and read-only, for example.

If the property is on the variable, it's making the HLSL and Metal backends potentially do more work. Similarly, they may need to generate a duplicate type if there are multiple variables using the same WGSL type but with different access qualifiers.

@kdashg

kdashg commented Oct 2, 2020

Copy link
Copy Markdown
Contributor

Can we see some examples of the various problems here? I'm having trouble following the concerns.

@dj2

dj2 commented Oct 6, 2020

Copy link
Copy Markdown
Member Author

As discussed in the 2020-10-06 meeting, I'm closing this. We're investigating putting the access modifier on the type for textures and will do the same here, or re-open this PR if that fails for whatever reason.

@dj2 dj2 closed this Oct 6, 2020
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.

4 participants