-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[HLSL][SPIR-V] Handle SV_Position builtin in PS #141759
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
Changes from 6 commits
84fd2cd
cbf88ce
ca842d2
3598e67
6aaed03
ce43937
57b5483
bbc3540
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -764,6 +764,13 @@ void SemaHLSL::CheckSemanticAnnotation( | |
return; | ||
DiagnoseAttrStageMismatch(AnnotationAttr, ST, {llvm::Triple::Compute}); | ||
break; | ||
case attr::HLSLSV_Position: | ||
// TODO(#143523): allow use on other shader types & output once the overall | ||
// semantic logic is implemented. | ||
if (ST == llvm::Triple::Pixel) | ||
return; | ||
DiagnoseAttrStageMismatch(AnnotationAttr, ST, {llvm::Triple::Pixel}); | ||
break; | ||
default: | ||
llvm_unreachable("Unknown HLSLAnnotationAttr"); | ||
} | ||
|
@@ -1147,6 +1154,26 @@ void SemaHLSL::handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL) { | |
HLSLSV_DispatchThreadIDAttr(getASTContext(), AL)); | ||
} | ||
|
||
bool SemaHLSL::diagnosePositionType(QualType T, const ParsedAttr &AL) { | ||
const auto *VT = T->getAs<VectorType>(); | ||
|
||
if (!T->hasFloatingRepresentation() || (VT && VT->getNumElements() > 4)) { | ||
Diag(AL.getLoc(), diag::err_hlsl_attr_invalid_type) | ||
<< AL << "float/float1/float2/float3"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what you mean by 'use language to indicate the range'. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean some thing like float vector between 1 and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I still don't get it, you mean passing Right now the error message is:
If we used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just thinking with shader model 6.9 allowing n dimensional vectors should we be future proof this so we don’t have to iterate all the float vectors. That said the coop vectors stuff is more for compute shaders so what you have is probably fine. |
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void SemaHLSL::handleSV_PositionAttr(Decl *D, const ParsedAttr &AL) { | ||
auto *VD = cast<ValueDecl>(D); | ||
if (!diagnosePositionType(VD->getType(), AL)) | ||
return; | ||
|
||
D->addAttr(::new (getASTContext()) HLSLSV_PositionAttr(getASTContext(), AL)); | ||
} | ||
|
||
void SemaHLSL::handleSV_GroupThreadIDAttr(Decl *D, const ParsedAttr &AL) { | ||
auto *VD = cast<ValueDecl>(D); | ||
if (!diagnoseInputIDType(VD->getType(), AL)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// RUN: %clang_cc1 -triple spirv-unknown-vulkan1.3-pixel -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s | ||
|
||
// CHECK: @sv_position = external thread_local addrspace(7) externally_initialized constant <4 x float>, !spirv.Decorations !0 | ||
|
||
// CHECK: define void @main() {{.*}} { | ||
float4 main(float4 p : SV_Position) { | ||
// CHECK: %[[#P:]] = load <4 x float>, ptr addrspace(7) @sv_position, align 16 | ||
// CHECK: %[[#R:]] = call spir_func <4 x float> @_Z4mainDv4_f(<4 x float> %[[#P]]) | ||
return p; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-pixel -x hlsl -finclude-default-header -o - %s -ast-dump | FileCheck %s | ||
|
||
float4 main(float4 a : SV_Position) { | ||
// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:8 main 'float4 (float4)' | ||
// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:20 a 'float4':'vector<float, 4>' | ||
// CHECK-NEXT: HLSLSV_PositionAttr 0x{{[0-9a-fA-F]+}} <{{.*}}> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-vertex -x hlsl -finclude-default-header -o - %s -verify | ||
|
||
// expected-error@+1 {{attribute 'SV_Position' is unsupported in 'vertex' shaders, requires pixel}} | ||
float4 main(float4 a : SV_Position) { | ||
return a; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.