Closed Ipotrick closed 2 months ago
This is because the this parameter of a member function is passed via inout convention. Which means the entire struct is read into thread local memory/register and passed in, and the object value after the call is written back to the original location. This means that this parameter will always be in threadlocal memory space.
We will need to add a diagnostic to prevent calling atomics like this.
Ok. I think thats quite unfortunate, id prefer if this
was a reference.
I agree with you that this is not ideal for this particular case. We can consider adding a [ref] attribute in addition to [mutating] which causes this to be passed by true reference. However there are still a lot of unanswered questions in language and IR design around true references and I don't think we are ready to roll out this feature yet.
I added [__ref] that you can use instead of [mutating] to make this passed by reference (currently implemented by inlining) instead of by inout.
For the following repro:
I get the following validation error for the generated spirv:
This only happens when tester is a member function. As soon as tester is a free function taking a pointer to Buf this error vanishes.
Config: