Skip to content

Commit f651c62

Browse files
authored
[0043] groupshared arguments (#742)
Expand on proposal about groupshared arguments. proof of concept: https://github.com/spall/DirectXShaderCompiler/tree/groupsharedParam
1 parent cbdda0f commit f651c62

1 file changed

Lines changed: 60 additions & 7 deletions

File tree

proposals/0043-groupshared-arguments.md

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ title: "0043 - `groupshared` Arguments"
33
params:
44
authors:
55
- llvm-beanz: Chris Bieneman
6+
- spall: Sarah Spall
67
sponsors:
7-
- tbd: TBD
8-
status: Under Consideration
8+
- spall: Sarah Spall
9+
status: Under Review
910
---
1011

1112
* Planned Version: 202x
@@ -29,12 +30,45 @@ parameter declarations. The keyword when applied to a parameter declaration of
2930
type `T`, alters the qualified type of the parameter to a `groupshared T &`
3031
(a reference to `groupshared` memory of type `T`).
3132

33+
```c++
34+
void fn(groupshared uint4 A) {}
35+
```
36+
3237
No implicit or explicit conversion can change the memory space of an object. To
3338
perform such a conversion, a user must declare a new object in the destination
3439
memory space and initialize it appropriately. For overload resolution, the
3540
parameter type must be an exact match in order for overload resolution to
3641
succeed since no conversions will be valid.
3742
43+
Allowed:
44+
```c++
45+
void fn(groupshared uint4 A) {
46+
float4 LocalA = (float4) A;
47+
doesSomething(LocalA);
48+
A = (uint4) LocalA;
49+
}
50+
```
51+
52+
Not Allowed:
53+
```c++
54+
void fn(groupshared uint4 A) {}
55+
void fn2() {
56+
float4 B = 1.0.xxxx;
57+
fn(B); // Error:
58+
fn((uint4)B); // Error:
59+
}
60+
```
61+
62+
There is a mostly working proof of concept which includes test cases showing
63+
valid cases and error cases. From my tests on this proof of concept it
64+
appears this feature can safely
65+
be enabled in all earlier language modes, but a warning should be added to let
66+
users know they are using a language feature added in a newer language mode and
67+
it might not be portable to older HLSL compilers.
68+
69+
It also looks like all types can be supported as groupshared arguments, including
70+
user-defined data types.
71+
3872
## Alternatives considered
3973
4074
[Reference
@@ -46,9 +80,28 @@ This more minimal feature has material benefit today for both DXC and Clang, and
4680
can avoid Clang requiring special case handling for library functions. As such,
4781
this proposal is preferred to waiting until references can be finalized.
4882
49-
## Outstanding Questions
83+
## Detailed Design
84+
85+
Any type which is valid for a `groupshared` variable is valid as a
86+
`groupshared` function parameter declaration.
87+
88+
### Errors and Warnings
89+
90+
The `groupshared` type annotation keyword will be allowed on function parameter
91+
declarations. In language modes before HLSL 202x, a warning will be produced,
92+
but it should still be supported if the compiler supports the feature.
93+
94+
A function annotated with either `export` or `[noinline]` will not be allowed to
95+
have function parameter declarations annotated with `groupshared`. Doing so
96+
will produce an error.
97+
98+
The argument to a `groupshared` function parameter must be a `groupshared`
99+
variable. If it is not, an error will be produced.
100+
101+
The argument to a `groupshared` function parameter must be of the same exact
102+
type as the function parameter. No implicit or explicit conversions are
103+
allowed. If they are not exactly the same, an error will be produced.
104+
105+
## Open Questions
50106
51-
* Can we enable this feature in earlier language modes? I think yes, but we
52-
should explore.
53-
* DXC does some odd handling for user-defined data types, does this work in DXC
54-
or do we need to limit the types it can apply to?
107+
Can this be supported in SPIRV?

0 commit comments

Comments
 (0)