Skip to content

Commit

Permalink
Require outputtopology attribute on Hull shader
Browse files Browse the repository at this point in the history
There was an existing check in DXIL validation that failed when the
outputtopology was not set for a Hull shader. Rather than duplicate this
check in the SPIR-V backend/validator, it seems correct to check that it
is present in Sema.

This PR needs review from someone who is more familiar with the HLSL spec
for hull shaders to verify that this check is correct though.

Fixes microsoft#3740
  • Loading branch information
sudonatalie committed Jan 8, 2024
1 parent 79f55f2 commit 4e4fc65
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15143,6 +15143,9 @@ void DiagnoseHullEntry(Sema &S, FunctionDecl *FD, llvm::StringRef StageName) {
if (!Attr)
S.Diags.Report(FD->getLocation(), diag::err_hlsl_missing_attr)
<< StageName << "patchconstantfunc";
if (!(FD->getAttr<HLSLOutputTopologyAttr>()))
S.Diags.Report(FD->getLocation(), diag::err_hlsl_missing_attr)
<< StageName << "outputtopology";

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct OUTPUT
};

[outputcontrolpoints(3)]
[outputtopology("point")]
[patchconstantfunc("foo")]

INPUT main(InputPatch<INPUT, 3> Input,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %dxc -T hs_6_0 -E Hull %s | FileCheck %s

struct ControlPoint { float4 position : POSITION; };
struct HullPatchOut {
float edge [3] : SV_TessFactor;
float inside : SV_InsideTessFactor;
};

HullPatchOut HullConst (InputPatch<ControlPoint,3> v) { return (HullPatchOut)0; }

//CHECK: error: hull entry point must have a valid outputtopology attribute

[domain("tri")]
[partitioning("fractional_odd")]
[patchconstantfunc("HullConst")]
[outputcontrolpoints(3)]
ControlPoint Hull (InputPatch<ControlPoint,3> v, uint id : SV_OutputControlPointID) { return v[id]; }
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ float4 fooey()
[shader("hull")]
// CHECK: error: patch constant function 'NotFooey' must be defined
[patchconstantfunc("NotFooey")]
[outputtopology("point")]
float4 main(float a : A, float b:B) : SV_TARGET
{
float4 f = b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ HSPerPatchData HSPerPatchFunc1()

[shader("hull")]
[patchconstantfunc("HSPerPatchFunc1")]
[outputtopology("point")]
float4 main(float a : A, float b:B) : SV_TARGET
{
float4 f = b;
Expand Down

0 comments on commit 4e4fc65

Please sign in to comment.