KhronosGroup / KhronosGroup/GLSL
Allow passing readonly SSBO members as "in" parameters
- Dominant language
- JavaScript
- Stars
- 458
- Forks
- 114
- Avg merge
- 4m
- Merged PRs (30d)
- 1
Description
In https://github.com/KhronosGroup/glslang/issues/1870, glslang was changed to reject passing a readonly buffer member to a function if the formal parameter is not qualified as readonly. The spec language is:
> Variables qualified with coherent, volatile, readonly, or writeonly may not be passed to functions whose formal parameters lack such qualifiers. (See section 6.1 “Function Definitions” for more detail on function calling.)
This made sense when image_load_store was added to GLSL (before SSBOs), since any image variable is a reference to memory. It was also a convenient way to say "you can't pass a readonly image to imageStore()." Then when SSBOs came along, they were added to this section by just saying "it's the same as with images":
> The memory qualifiers coherent, volatile, restrict, readonly, and writeonly may be used in the declaration of buffer variables (i.e., members of shader storage blocks). When a buffer variable is declared with a memory qualifier, the behavior specified for memory accesses involving image variables described above applies identically to memory accesses involving that buffer variable.
But consider the following example using a readonly buffer:
```
layout(set = 0, binding = 0, std430) readonly restrict buffer A {
float b;
} a;
void main()
{
round(a.b);
}
```
According to this spec language, it is illegal to pass a.b to round() because a.b is readonly (inherited from its parent) and round's formal parameter is not qualified as readonly. However, round's formal parameter is implicitly *in*, and IMO it should be valid to pass a readonly buffer member as an in parameter. *in* is defined as "The keyword *in* is used as a qualifier to denote a parameter is to be copied in, but not copied out."
My mental model for this is something like "Reading a readonly buffer member returns an rvalue. values passed to an *in* parameter must be rvalues. Therefore it is valid to pass a readonly buffer member to an *in* parameter."
I propose we relax the GLSL spec to allow passing readonly buffer members to formal parameters qualified with *in*. To be consistent, it probably also makes sense to allow passing writeonly buffer members to formal parameters qualified with *out*.
Contributor guide
Assessment
This issue has not been assessed yet.