In HLSL buffer types support array subscripting syntax for loads and
stores. This change fleshes out the subscript operators to become array
accesses on the underlying handle pointer. This will allow LLVM
optimization passes to optimize resource accesses the same way any other
memory access would be optimized.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/lib/Sema/HLSLExternalSemaSource.cpp | ||
---|---|---|
220 | If we reuse this function for StructuredBuffer, then const subscript return a const reference could be better? | |
clang/test/CodeGenHLSL/buffer-array-operator.hlsl | ||
5 | Maybe change In to RWBuffer<float4> | |
17 | Where is the this.addr coming from? |
clang/lib/Sema/HLSLExternalSemaSource.cpp | ||
---|---|---|
220 | Why? Since this should get inlined return value optimization should eliminate the redundant copies. | |
clang/test/CodeGenHLSL/buffer-array-operator.hlsl | ||
5 | None of the added code here depends on the template parameter type. Putting a vector in increases the complexity of the output, but I'm unsure it extends the test coverage meaningfully. | |
17 | That is how clang generates stored locations for input parameters. |
clang/test/CodeGenHLSL/buffer-array-operator.hlsl | ||
---|---|---|
4 | Why add const instead of using Buffer directly? |
clang/test/CodeGenHLSL/buffer-array-operator.hlsl | ||
---|---|---|
4 | Making this const forces the const methods to be used. It is just to drive the correct validation and code generation. |
clang/test/CodeGenHLSL/buffer-array-operator.hlsl | ||
---|---|---|
4 | So maybe we don't need Buffer at all, just use const RWBuffer for read-only usage? |
clang/test/CodeGenHLSL/buffer-array-operator.hlsl | ||
---|---|---|
4 | I think there would likely be some code incompatibilities if we alias Buffer to const RWBuffer, but that would be interesting to consider. |
Updating based on PR feedback and rebasing.
- Rebased on main today
- Made const subscript return type const &
clang/lib/Sema/HLSLExternalSemaSource.cpp | ||
---|---|---|
243 | As currently implemented it is an unsigned int. I should include the doc link in the description: Eventually I think we'll need to introduce size types to HLSL, but we currently don't really use them. |
Updating based on @aaron.ballman's feedback.
- Change reinterpret_cast -> static_cast
- Aaron likes auto more than me... but all in good places :D
LGTM aside from a nit that was missed. Thanks for switching to static_cast, that makes me happier. :-)
clang/lib/Sema/HLSLExternalSemaSource.cpp | ||
---|---|---|
109 | Missed from the previous suggestion. |
Missed from the previous suggestion.