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

[SPIR-V] Implement vk::ext_builtin_input and vk::ext_builtin_output #6027

Merged
merged 15 commits into from
Jan 2, 2024

Conversation

cassiebeckley
Copy link
Collaborator

I definitely think it would look better if we allowed these attributes on variables, ie microsoft/hlsl-specs#76. I haven't fully investigated how involved it would be to implement, but my intuition is that it wouldn't take that much more work.

Fixes #4217.

@cassiebeckley cassiebeckley changed the title [SPIR-V] Implmenet vk::ext_builtin_input and vk::ext_builtin_output [SPIR-V] Implement vk::ext_builtin_input and vk::ext_builtin_output Nov 16, 2023
@s-perron
Copy link
Collaborator

s-perron commented Nov 16, 2023

I definitely think it would look better if we allowed these attributes on variables

That could be better. Let me know if you think the implementation would be to complicated. We can go back and change HLSL specs. This might also make is easier to pass as a parameter to a function. If it is a function, we cannot do that.

Copy link
Collaborator

@s-perron s-perron left a comment

Choose a reason for hiding this comment

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

Looks good. Just a little style comment.

@cassiebeckley
Copy link
Collaborator Author

@s-perron lmk what you think of this approach.

@s-perron
Copy link
Collaborator

@s-perron lmk what you think of this approach.

I think this looks good. We should probably add more testing. For example, what happens if the builtin is passed as a parameter to a function?

Making the variable static is not a problem. The input and output variables are not shared, and static tells you that. I wonder if we should enforce that. Add an error if we try to apply the attribute to a variable that is not static. We should update the spec to say that.

@cassiebeckley
Copy link
Collaborator Author

I think this looks good. We should probably add more testing. For example, what happens if the builtin is passed as a parameter to a function?

Do you mean something like someFunction(gl_NumWorkGroups)? If so, I've added a test case. I've also added an error message enforcing static for ext_builtin_input and ext_builtin_output.

@Keenuts
Copy link
Collaborator

Keenuts commented Nov 21, 2023

Hello!

Found another cases where the diagnostic should be improved

[[vk::ext_builtin_output(/* FragStencilRefEXT */ 5014)]]
static int output;

[[vk::ext_builtin_input(/* FragStencilRefEXT */ 5014)]]
static int input;

[[vk::ext_extension("SPV_EXT_shader_stencil_export")]]
void main() {
  int tmp = input;
  output = 10;
}
$ dxc -T ps_6_0 -E main -fcgl -spirv repro.hlsl
repro.hlsl:10:3: error: cannot assign to input variable
  output = 10;

If input is not read, it works. The error seems wrong as it puts the blame on output, which is marked as output. We may want to error out before, if 2 variables share the same builtin but with different I/O.

Copy link
Collaborator

@Keenuts Keenuts left a comment

Choose a reason for hiding this comment

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

Fine with this.
It's easy to make the validation fails, but I'd assume that's like inline assembly, you are on your own to make sure you use this correctly.

Copy link
Collaborator

@s-perron s-perron left a comment

Choose a reason for hiding this comment

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

Just a couple more test to add.

@cassiebeckley
Copy link
Collaborator Author

If input is not read, it works. The error seems wrong as it puts the blame on output, which is marked as output. We may want to error out before, if 2 variables share the same builtin but with different I/O.

Sure, I've added an error for that.

Copy link
Collaborator

@s-perron s-perron left a comment

Choose a reason for hiding this comment

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

Okay, we let this sit until we update HLSL specs, and hear back from the community on some of the finer details.

@cassiebeckley
Copy link
Collaborator Author

I've added a const requirement for ext_builtin_input

@cassiebeckley cassiebeckley enabled auto-merge (squash) November 23, 2023 03:47
@cassiebeckley cassiebeckley merged commit 9dacbe3 into microsoft:main Jan 2, 2024
@cassiebeckley cassiebeckley deleted the inline-spirv-builtin branch January 17, 2024 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[SPIRV] Missing gl_NumWorkGroups
3 participants