-
Notifications
You must be signed in to change notification settings - Fork 814
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
HLSL: implement numthreads for compute shaders #572
Conversation
|
||
if ((attr = attributes.find("numthreads")) != attributes.end()) { | ||
// TODO: handle multiple entry points. TIntermediate presently only tracks one set of thread counts. | ||
if (parseContext.parsingEntryPoint()) { |
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 considered exposing inEntryPoint before, for knowing if parameters were for functions or entry point, but the grammar doesn't know when that bit gets set, and it is not set until the entry point is partially parsed. That's how remapEntryPointIO()
came about.
Given that the grammar can't depend on knowing whether parsingEntryPoint() is valid or not, is there a cleaner way, which keeps policy more cleanly in the parse helper?
E.g., acceptFunctionDefinition
in the parse helper is where the decision is made about how to pass on numthreads
?
namespace glslang { | ||
class TIntermAggregate; | ||
|
||
typedef std::unordered_map<TString, TIntermAggregate*> TAttributeMap; |
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.
Is string representing specific things like numthreads
and flatten
? What about the design alternative of using an enum { numthreads, flatten, ... max } and an array[max], so that string manipulation dies at parsing? Or does that break down?
Thanks for comments - repushed with these changes:
|
if (numThreadliterals != nullptr && inEntryPoint) { | ||
const TIntermSequence& sequence = numThreadliterals->getSequence(); | ||
|
||
// TODO: handle multiple entry points. TIntermediate presently only tracks one set of thread counts. |
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.
Not sure I follow.
TIntermediate only handles one entry point, and generally the parser/intermediate design is centered around that. If a SPIR-V module were in the future to have multiple entry points, it would be because multiple TIntermediate each made a SPIR-V module, and the modules got merged (most recent thinking of how to do that), rather than the whole stack learned to handle multiple entry points.
Shader entry functions are different semantics from a regular function at the source level, in the AST, and in SPIR-V. So, I think the best way to handle, say, source with real multiple entry points is to compile it multiple times, once per entry point, and get correct SPIR-V modules for each, and then use a SPIR-V merger.
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 see; that was down to a misunderstanding on my part then. Will fix comment.
I think the code is fine. I only questioned a comment; curious if we're on the same page about it. |
This PR adds handling of the numthreads attribute for compute shaders, as well as a general infrastructure for returning attribute values from acceptAttributes, which may be needed in other cases, e.g, unroll(x), or merely to know if some attribute without params was given. A map of enum values from TAttributeType to TIntermAggregate nodes is built and returned. It can be queried with operator[] on the map. In the future there may be a need to also handle strings (e.g, for patchconstantfunc), and those can be easily added into the class if needed. New test is in hlsl.numthreads.comp.
Removed WIP, re-pushed with a number of comment changes, updated commit message, and forward declaring the TAttributeMap class to avoid #including it from inside other headers. |
HLSL: implement numthreads for compute shaders
This PR adds handling of the numthreads attribute for compute shaders, as well as a general
infrastructure for returning attribute values from acceptAttributes, which may be needed in other
cases, e.g, unroll(x), or merely to know if some attribute without params was given.
A map of enum values from TAttributeType to TIntermAggregate nodes is built and returned. It
can be queried with operator[] on the map. In the future there may be a need to also handle
strings (e.g, for patchconstantfunc), and those can be easily added into the class if needed.
New test is in hlsl.numthreads.comp.