Skip to content

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

Merged
Cassandra Beckley (cassiebeckley) merged 15 commits into
microsoft:mainfrom
cassiebeckley:inline-spirv-builtin
Jan 2, 2024
Merged

Cassandra Beckley (cassiebeckley) merged 15 commits into
microsoft:mainfrom
cassiebeckley:inline-spirv-builtin

Conversation

@cassiebeckley

Copy link
Copy Markdown
Contributor

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 Cassandra Beckley (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

Steven Perron (s-perron) commented Nov 16, 2023 •

Copy link
Copy Markdown
Collaborator

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.

@s-perron Steven Perron (s-perron) left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Contributor Author

Steven Perron (@s-perron) lmk what you think of this approach.

@s-perron

Copy link
Copy Markdown
Collaborator

Steven Perron (@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
Copy Markdown
Contributor 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
Copy Markdown
Collaborator

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.

@Keenuts Nathan Gauër (Keenuts) left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread tools/clang/lib/SPIRV/SpirvEmitter.cpp Resolved

@s-perron Steven Perron (s-perron) left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Contributor 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.

@s-perron Steven Perron (s-perron) left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Contributor Author

I've added a const requirement for ext_builtin_input

Comment thread tools/clang/lib/SPIRV/SpirvEmitter.cpp Resolved
Comment thread tools/clang/lib/SPIRV/SpirvEmitter.cpp Resolved
@cassiebeckley
Cassandra Beckley (cassiebeckley) merged commit 9dacbe3 into microsoft:main Jan 2, 2024
@cassiebeckley
Cassandra Beckley (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