-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IRWArray
interface, and make StructuredBuffer conform to them.
#5097
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me.
writeToBuffer(outputBuffer, 0, 1.0f); | ||
|
||
// CHECK: 4.0 | ||
writeToArray(arr, 0, 4.0f); | ||
outputBuffer[1] = readFromArray(arr, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am little confused by the inconsistency with writeToBuffer
.
If I do writeToBuffer(outputBuffer, ...)
, it will modify outputBuffer
.
But if I do writeToBuffer(arr, ...)
, it wouldn't modify arr
.
When I look at the function signature alone, it shouldn't modify the first argument because it doesn't have out
nor inout
modifier.
void writeToBuffer<U, T : IRWArray<U>>(T array, int index, U value)
When used with RWStructuredBuffer, T array
works as if it is inout T array
, which seems inconsistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is a little unfortunate, but at the moment there isn't a better solution.
RWStructuredBuffer itself should be viewed as T*
, that is a handle to an array. Therefore, The structuredbuffer itself is a non-mutable object (represented as a uniform parameter), and therefore you can't pass it into a function that expects an inout
parameter, because you can't assign buffer
to something else, it is readonly.
In contract, for arrays you do want to mutate its content, so inout
is needed there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The essence in this is that RWStructuredBuffer
is Array<T>*
and not an array, but there is no correponding interface to represent a "reference to an array" right now, and even if we do, we can't construct a reference object to a real array in order to satisfy that interface anyways.
Closes #5098.
Closes #5099.
This adds
IRWArray
interface to generic functions to read/write arrays.Makes StructuredBuffer conform to IArray, and RWStructuredBuffer conform to IRWArray.
Most part of this PR is about adding the ability to synthesize a __subscript implementation from an interface requirement.
For example,
The PR fills in the missing pieces in
trySynthesizeMemberRequirement
to handle the subscript requirement case, just like how properties are handled. In fact a lot of the logic in synthesizing the accessors of a property decl is refactored into a shared sub-routine and reused for the subscript case.This PR also removes the warning on unmodified
inout
parameter since it frequently gets in the way if there is an interface that requiresinout parameter
and the implementation doesn't actually modify it. There is adhoc logic to silence the warning if the method is implementing an interface method, but that doesn't really work for generic functions. Overall I think this warning is kind of annoying and not easy to get it right, so removing.