Skip to content
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

[spirv] support vk::ext_execution_mode_id(..) #4190

Merged
merged 4 commits into from
Jan 21, 2022

Conversation

jaebaek
Copy link
Collaborator

@jaebaek jaebaek commented Jan 17, 2022

As a part of HLSL version of GL_EXT_spirv_intrinsics, this commit adds
vk::ext_execution_mode_id(..) intrinsic function. In addition, it allows users
to enable capabilites and extensions via vk::ext_execution_mode[_id](..)
using [[vk::ext_capability(..)]] and [[vk::ext_extension(..)]].

Related to #3919

@jaebaek jaebaek added the spirv Work related to SPIR-V label Jan 17, 2022
@jaebaek jaebaek self-assigned this Jan 17, 2022
@jaebaek
Copy link
Collaborator Author

jaebaek commented Jan 17, 2022

@jiaolu Hi, Jiao Lu. This commit will add vk::ext_execution_mode_id(..). Could you please give me some feedback if you have any concerns?

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

// CHECK: OpExecutionMode {{%\w+}} StencilRefReplacingEXT
// CHECK: OpExecutionMode {{%\w+}} SubgroupSize 32
// CHECK: OpDecorate {{%\w+}} BuiltIn FragStencilRefEXT

[[vk::ext_decorate(11, 5014)]]
int main() : SV_Target0 {

[[vk::ext_capability(5055)]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the vk::ext_execution_mode function call with extension and capability looks a little bit heavy

i think we might introduce new intrinsic functions directly.
vk::ext_capability(5055);
vk::ext_extension("SPV_KHR_shader_clock")

or
put these vk::attributes before entry functions.

[[vk::ext_capability(5055)]]
[[vk::ext_extension("SPV_KHR_shader_clock")]]
[[vk::ext_decorate(11, 5014)]]
int main() : SV_Target0 {
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I also thought we have to add separate functions for capabilities and extensions.

However, in our email discussion (between you and me and Tobias Hector) a few months ago, Tobias Hector said

users don’t have to think about which extensions/capabilities they need to use when pulling in a header, and so they could pull in headers without any worry that they’re adding unnecessary capabilities to their code. So if you wanted to use e.g. clockRealtime2x32EXT, you’d just include the header and call clockRealtime2x32EXT. If you include the header and don’t call it? No worries – no extra capabilities/extensions specified.

This is the motivation to add capabilities and extensions as attributes in the initial GLSL version of GL_EXT_spirv_intrinsics design.

For example, I think Tobias Hector is worried about the following case:

// Separate functions for capabilities and extensions:
#ifdef ENABLE_DEMOTE_TO_HELPER
vk::ext_capability(/* DemoteToHelperInvocationEXT */ 5379);
vk::ext_extension("SPV_EXT_demote_to_helper_invocation");
#endif

#ifdef OPTION1
[[vk::ext_instruction(/*OpDemoteToHelperInvocationEXT*/ 5380)]]
void DemoteToHelperInvocation();
#endif

#ifdef OPTION2
[[vk::ext_instruction(/*OpIsHelperInvocationEXT*/ 5381)]]
bool IsHelperInvocation();
#endif

// With attributes
#ifdef OPTION1
[[vk::ext_capability(/* DemoteToHelperInvocationEXT */ 5379)]]
[[vk::ext_extension("SPV_EXT_demote_to_helper_invocation")]]
[[vk::ext_instruction(/*OpDemoteToHelperInvocationEXT*/ 5380)]]
void DemoteToHelperInvocation();
#endif

#ifdef OPTION2
[[vk::ext_capability(/* DemoteToHelperInvocationEXT */ 5379)]]
[[vk::ext_extension("SPV_EXT_demote_to_helper_invocation")]]
[[vk::ext_instruction(/*OpIsHelperInvocationEXT*/ 5381)]]
bool IsHelperInvocation();
#endif

When the code size becomes big e.g., more than 3000 lines and many preprocessor based options and header files, users can miss enabling capabilites and extensions if we separate them from vk::ext_instruction or vk::ext_execution_mode or vk::ext_type_def.

I agree with Tobias Hector's opinion. Just I think it would be unlikely that users use this feature for actual game shaders that has more than 1000 lines. I guess it would be mainly used by hardware vendors to test new specs.
However, since we can prevent users from making mistakes using some language design, I think this is a reasonable direction to go.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I also thought we have to add separate functions for capabilities and extensions.

However, in our email discussion (between you and me and Tobias Hector) a few months ago, Tobias Hector said

users don’t have to think about which extensions/capabilities they need to use when pulling in a header, and so they could pull in headers without any worry that they’re adding unnecessary capabilities to their code. So if you wanted to use e.g. clockRealtime2x32EXT, you’d just include the header and call clockRealtime2x32EXT. If you include the header and don’t call it? No worries – no extra capabilities/extensions specified.

This is the motivation to add capabilities and extensions as attributes in the initial GLSL version of GL_EXT_spirv_intrinsics design.

For example, I think Tobias Hector is worried about the following case:

// Separate functions for capabilities and extensions:
#ifdef ENABLE_DEMOTE_TO_HELPER
vk::ext_capability(/* DemoteToHelperInvocationEXT */ 5379);
vk::ext_extension("SPV_EXT_demote_to_helper_invocation");
#endif

#ifdef OPTION1
[[vk::ext_instruction(/*OpDemoteToHelperInvocationEXT*/ 5380)]]
void DemoteToHelperInvocation();
#endif

#ifdef OPTION2
[[vk::ext_instruction(/*OpIsHelperInvocationEXT*/ 5381)]]
bool IsHelperInvocation();
#endif

// With attributes
#ifdef OPTION1
[[vk::ext_capability(/* DemoteToHelperInvocationEXT */ 5379)]]
[[vk::ext_extension("SPV_EXT_demote_to_helper_invocation")]]
[[vk::ext_instruction(/*OpDemoteToHelperInvocationEXT*/ 5380)]]
void DemoteToHelperInvocation();
#endif

#ifdef OPTION2
[[vk::ext_capability(/* DemoteToHelperInvocationEXT */ 5379)]]
[[vk::ext_extension("SPV_EXT_demote_to_helper_invocation")]]
[[vk::ext_instruction(/*OpIsHelperInvocationEXT*/ 5381)]]
bool IsHelperInvocation();
#endif

When the code size becomes big e.g., more than 3000 lines and many preprocessor based options and header files, users can miss enabling capabilites and extensions if we separate them from vk::ext_instruction or vk::ext_execution_mode or vk::ext_type_def.

I agree with Tobias Hector's opinion. Just I think it would be unlikely that users use this feature for actual game shaders that has more than 1000 lines. I guess it would be mainly used by hardware vendors to test new specs. However, since we can prevent users from making mistakes using some language design, I think this is a reasonable direction to go.

thanks, it makes sense.

tools/clang/lib/SPIRV/SpirvEmitter.h Outdated Show resolved Hide resolved
@AppVeyorBot
Copy link

Copy link
Collaborator

@sudonatalie sudonatalie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jaebaek jaebaek merged commit 29874c9 into microsoft:master Jan 21, 2022
@jaebaek jaebaek deleted the ext_execution_mode_id branch January 21, 2022 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spirv Work related to SPIR-V
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants