This is an archive of the discontinued LLVM Phabricator instance.

[HLSL] Initial codegen for SV_GroupIndex
ClosedPublic

Authored by beanz on Aug 4 2022, 2:09 PM.

Details

Summary

Semantic parameters aren't passed as actual parameters, instead they are
populated from intrinsics which are generally lowered to reads from
dedicated hardware registers.

This change modifies clang CodeGen to emit the intrinsic calls and
populate the parameter's LValue with the result of the intrinsic call
for SV_GroupIndex.

The result of this is to make the actual passed argument ignored, which
will make it easy to clean up later in an IR pass.

Diff Detail

Event Timeline

beanz created this revision.Aug 4 2022, 2:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2022, 2:09 PM
beanz requested review of this revision.Aug 4 2022, 2:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2022, 2:09 PM
python3kgae added inline comments.Aug 4 2022, 2:12 PM
clang/test/CodeGenHLSL/semantics/GroupIndex-codegen.hlsl
5

Does this change plan to support cases where SV_GroupIndex is inside a struct?
If yes, we need a test for that.

beanz updated this revision to Diff 451660.Aug 10 2022, 3:35 PM

This is a fairly significant reworking of this patch to handle entry functions being called (which I hadn't anticipated). There may be some additional tweaks required, but the general flow here is:

(1) Don't prevent mangling of entry functions, this allows us to generate calls based on the mangled function name which makes things happy.
(2) Do codegen the function with parameters following the C++ codegen paths with no alterations
(3) Also generate a c-exported, unmanged, void(void) function for each entry which populates semantic arguments and calls into the mangled entry function

This solution results in code generation that covers the required cases, and the optimizer can (and will) eliminate the wrapper function in all cases that it can, and in any case that it can't the compiler will explode because recurison is not allowed in HLSL unless it can be translated to a loop by the compiler.

Fun right?

This now depends on D131625, which is a small change to enforce that all entry parameters have semantic annotations.

python3kgae added inline comments.Aug 10 2022, 5:51 PM
clang/lib/CodeGen/CGHLSLRuntime.cpp
19

Does this mean CGHLSLRuntime is only for DirectX backend?

147

FIXME: support struct parameter which may not have Annotation attribute.

163

Need to move all attributes from Fn to EntryFn.
And make Fn a normal function.

beanz added inline comments.Aug 10 2022, 7:29 PM
clang/lib/CodeGen/CGHLSLRuntime.cpp
19

No, it is fairly normal to include target intrinsics throughout codegen. That said, I'm not handling non-DirectX intrinsics nor am I verifying the appropriate target, so I should make some adjustment here.

163

Yes on the function attributes.

What do you mean by "normal function" as written it is an external linkage function, which matches what we expect in DXIL.

python3kgae added inline comments.Aug 11 2022, 8:54 AM
clang/lib/CodeGen/CGHLSLRuntime.cpp
163

By "normal function" I mean remove the special attribute like HLSLEntry, numofthreads.

beanz updated this revision to Diff 453418.Aug 17 2022, 1:51 PM

Handling function attributes appropriately.

aaron.ballman added inline comments.Aug 18 2022, 10:16 AM
clang/lib/CodeGen/CGHLSLRuntime.cpp
92–136
105–106
120–139
133
clang/lib/CodeGen/CGHLSLRuntime.h
52–54

These parameters should have names so people don't think the parameters aren't used.

beanz updated this revision to Diff 454677.Aug 22 2022, 7:49 PM

Updates based on review feedback.

This revision is now accepted and ready to land.Aug 23 2022, 6:28 AM
This revision was automatically updated to reflect the committed changes.