Skip to content

Require valid outputcontrolpoints on Hull shader - #6196

Merged
Natalie Chouinard (sudonatalie) merged 3 commits into
microsoft:mainfrom
sudonatalie:require-outputcontrolpoints
Mar 25, 2024
Merged

Natalie Chouinard (sudonatalie) merged 3 commits into
microsoft:mainfrom
sudonatalie:require-outputcontrolpoints

Conversation

@sudonatalie

Copy link
Copy Markdown
Collaborator

According to the documentation: "A hull shader is implemented with an HLSL function, and has the following properties: [...] The shader output is between 1 and 32 control points".

https://learn.microsoft.com/en-us/windows/win32/direct3d11/direct3d-11-advanced-stages-tessellation#hull-shader-stage

This change adds a check to verify that the outputcontrolpoints attribute is set on Hull shaders and has an argument in the valid range.

Fixes #3733 (by making the error consistent between backends)

@sudonatalie

Copy link
Copy Markdown
Collaborator Author

Chris B (@llvm-beanz) The cases where outputcontrolpoints was 0 or unset currently pass with the DXIL backend, but it seems like this shouldn't be the case. What do you think of this change?

@sudonatalie

Copy link
Copy Markdown
Collaborator Author

Tex Riddell (@tex3d) Any thoughts on this? If it's too breaking of a change to error, do you have any insight into the expected behavior of outputcontrolpoints being unset or zero that could help us implement it correctly on the SPIR-V side?

According to the documentation: "A hull shader is implemented with an
HLSL function, and has the following properties: [...] The shader output
is between 1 and 32 control points".

https://learn.microsoft.com/en-us/windows/win32/direct3d11/direct3d-11-advanced-stages-tessellation#hull-shader-stage

This change adds a check to verify that the outputcontrolpoints
attribute is set on Hull shaders and has an argument in the valid range.

Fixes microsoft#3733 (by making the error consistent between backends)
@pow2clk

Copy link
Copy Markdown
Collaborator

In terms of the DXIL that would be generated if 0 were allowed, it's just placed on the list of attributes for the hull entry point functions.

I expect that drivers may consume this fine, but it could only mean that the domain shader wouldn't be run at all. I can't imagine why this would be a useful thing to do even in the most contrived case.

@pow2clk Gregory Roth (pow2clk) 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.

We discussed the need for a validation error. Turns out it exists, but it's a bit more permissive:
text:

"output control point count must be [0..%0]. %1 specified.",

implementation:
if (outputControlPointCount > DXIL::kMaxIAPatchControlPointCount) {

test:
TEST_F(ValidationTest, HsAttributeFail) {

The existence of a validation error gives me some hesitation that I didn't have this morning, but at the least if we're changing the diagnostic, we should change the validation test and text as well as add a test at the same time.

Comment thread tools/clang/lib/Sema/SemaHLSL.cpp Resolved
@sudonatalie

Copy link
Copy Markdown
Collaborator Author

Looking into the validator changes...

@github-actions

github-actions Bot commented Feb 27, 2024 •

Copy link
Copy Markdown
Contributor

⚠️ Python code formatter, darker found issues in your code. ⚠️

You can test this locally with the following command:
darker --check --diff -r 696a13a2a8d007e625c11d46f650b3a91ed72a3a..c679d6fdbdbaf936d8c0e977647f96484dcbc579 utils/hct/hctdb.py
View the diff from darker here.
--- hctdb.py	2024-02-27 18:36:29.000000 +0000
+++ hctdb.py	2024-03-25 17:22:57.471712 +0000
@@ -7587,11 +7587,11 @@
             "Instr.AtomicIntrinNonUAV", "Non-UAV destination to atomic intrinsic."
         )
         self.add_valrule_msg(
             "Instr.SVConflictingLaunchMode",
             "Input system values are compatible with node shader launch mode.",
-            "Call to DXIL intrinsic %0 (%1) is not allowed in node shader launch type %2"
+            "Call to DXIL intrinsic %0 (%1) is not allowed in node shader launch type %2",
         )
         self.add_valrule("Instr.AtomicConst", "Constant destination to atomic.")
 
         # Work-Graphs
         self.add_valrule(
  • Check this box to apply formatting changes to this branch.

@sudonatalie

Copy link
Copy Markdown
Collaborator Author

This change is ready for re-review!

@sudonatalie

Copy link
Copy Markdown
Collaborator Author

Ping Tex Riddell (@tex3d), this change is just waiting on your review.

@pow2clk Gregory Roth (pow2clk) 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.

Thanks for addressing the validation conflict!

@sudonatalie

Copy link
Copy Markdown
Collaborator Author

I don't know why the formatter auto-apply is failing, but I'm going to bypass it since it's modifying a line that isn't touched in this PR anyways.

@sudonatalie
Natalie Chouinard (sudonatalie) merged commit 122464a into microsoft:main Mar 25, 2024
@sudonatalie
Natalie Chouinard (sudonatalie) deleted the require-outputcontrolpoints branch March 25, 2024 17:41
@sudonatalie

Copy link
Copy Markdown
Collaborator Author

I see this failing the GitHub Pages workflow, taking a look...

Natalie Chouinard (sudonatalie) added a commit to sudonatalie/DirectXShaderCompiler that referenced this pull request Mar 25, 2024
This test landed after microsoft#6196 was created but before it was merged, and
had an invalid attribute that is now caught and causing test failues at
head.
Natalie Chouinard (sudonatalie) added a commit that referenced this pull request Mar 26, 2024
This test landed after #6196 was created but before it was merged, and
had an invalid attribute that is now caught and causing test failures at
head.
Xiang Li (python3kgae) added a commit that referenced this pull request Mar 29, 2024
)

Error message was updated in #6196 which cause test fail on older
validator.

Since this issue is only caused by error message update, the validation
itself is still the same.
The compiler didn't generate anything that behaves badly with older
validators.

So just limit these tests to sm6.8+ to make it work on older validator.
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.

[SPIR-V] [outputcontrolpoints(0)] or missing outputcontrolpoints Hull stage attribute crash the compiler (works with DXIL backend)

3 participants