This is an archive of the discontinued LLVM Phabricator instance.

[HLSL] CodeGen hlsl resource binding.
ClosedPublic

Authored by python3kgae on Aug 1 2022, 4:42 PM.

Details

Summary

''register(ID, space)'' like register(t3, space1) will be translated into
i32 3, i32 1 as the last 2 operands for resource annotation metadata.

NamedMetadata for CBuffers and SRVs are added as "hlsl.srvs" and "hlsl.cbufs".

Diff Detail

Event Timeline

python3kgae created this revision.Aug 1 2022, 4:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 4:42 PM
python3kgae requested review of this revision.Aug 1 2022, 4:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 4:42 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Anastasia added inline comments.Aug 3 2022, 5:19 AM
clang/lib/CodeGen/CGHLSLRuntime.h
52

Does this apply to buffers only? In which case it might be better to either nest this into Buffer definition or rename into something like BufferResBinding. Also adding some documenting comments would help here, even if they could just refer to the language documentation.

73

This is not part of this change but any reason why it is a protected member and not private?

94

Similarly - is this buffer specific? Then you could either rename to addBufferResourceAnnotation or make this a member of a Buffer instead...

python3kgae marked an inline comment as done.

Rename ResBinding and addResourceAnnotation to BufferResBinding and addBufferResourceAnnotation.

python3kgae marked an inline comment as done.Aug 4 2022, 4:48 PM
beanz added inline comments.Aug 5 2022, 6:33 AM
clang/lib/CodeGen/CGHLSLRuntime.h
73

I wrote that code, and had a vague idea of a use case in my head where we might provide subclasses of the HLSLRuntime, but in retrospect that is unlikely anytime soon, so we could safely make that private.

Add resource shape to metadata.
Conflict with https://reviews.llvm.org/D135110, will rebase once https://reviews.llvm.org/D135110 is in.

Herald added a project: Restricted Project. · View Herald TranscriptOct 13 2022, 4:22 PM

Fix clang-format missed by arc lint

beanz added inline comments.Oct 14 2022, 12:24 PM
clang/include/clang/Basic/HLSLRuntime.h
31 ↗(On Diff #467812)

If this is only used in the clangCodeGen library, we can move it into libLLVMFrontendHLSL to share instead of keeping them in sync.

clang/lib/CodeGen/CGHLSLRuntime.cpp
223

Shouldn't this be using FrontendResource?

289

since we're relying on these two enums basically being identical, can you add static_asserts up near the top of this file to ensure that they are the same? It would be unfortunate if in the future one got updated and the other didn't.

python3kgae marked 3 inline comments as done.

Rebase to use FrontendResource.

beanz added inline comments.Oct 17 2022, 2:10 PM
clang/lib/CodeGen/CGHLSLRuntime.h
73

The ResourceCounters here was a stand-in for allocating resource indices.

If you have a different path for allocating these, we shouldn't need the counter anymore. I'm a little concerned that it looks like you're not allocating these in code generation. Can you explain how you intend to allocate indices? Is there a reason not to do this in code gen?

beanz accepted this revision.Oct 17 2022, 2:20 PM
beanz added inline comments.
clang/lib/CodeGen/CGHLSLRuntime.h
73

Wait... I guess I actually fed the ResourceCounter to the ID, which is fine.

I don't like that we're not allocating the indices in codegen, but we can address that in a subsequent patch.

This revision is now accepted and ready to land.Oct 17 2022, 2:20 PM
python3kgae added inline comments.Oct 17 2022, 2:22 PM
clang/lib/CodeGen/CGHLSLRuntime.h
73

The reason not to do it in codeGen is that we have to remove unused global resources even in Od and update the ID in the backend.

The plan is to allocate the ID after unused global resources are deleted.

This revision was automatically updated to reflect the committed changes.