================
@@ -1028,6 +1034,52 @@ static bool isVkPipelineBuiltin(const ASTContext
&AstContext, FunctionDecl *FD,
}
}
+static void validateVkBuiltinUsage(Sema &S, FunctionDecl *FD,
+ const DeclaratorDecl *D,
+ const HLSLVkBuiltInAttr *Attr,
+ IOType CurrentIOType) {
+ const ASTContext &AstContext = S.getASTContext();
+ if (AstContext.getTargetInfo().getTriple().getOS() != llvm::Triple::Vulkan)
+ return;
+
+ StringRef BuiltIn = Attr->getBuiltIn();
+
+ QualType T =
+ (D == FD ? FD->getReturnType() : D->getType()).getNonReferenceType();
+ const auto *ShaderAttr = FD->getAttr<HLSLShaderAttr>();
+ assert(ShaderAttr && "Entry point has no shader attribute");
+ llvm::Triple::EnvironmentType Stage = ShaderAttr->getType();
+ bool IsIn = any(CurrentIOType & IOType::In);
+ bool IsOut = any(CurrentIOType & IOType::Out);
+
+ if (BuiltIn == "PointSize") {
+ if (!T->isFloatingType())
+ S.Diag(Attr->getLocation(), diag::err_hlsl_vk_builtin_wrong_type)
+ << BuiltIn << S.getASTContext().FloatTy;
+
+ // PointSize is a per-vertex value, so patch-constant (hull/domain)
+ // and per-primitive (mesh) data never carries it.
+ // Note: Sema does not set this bit yet.
+ bool IsPatchConstantOrPrimitive =
+ any(CurrentIOType & IOType::PatchConstantOrPrimitive);
+ bool LegalStage =
+ !IsPatchConstantOrPrimitive &&
+ ((Stage == llvm::Triple::Vertex && IsOut) ||
+ Stage == llvm::Triple::Hull || Stage == llvm::Triple::Domain ||
+ Stage == llvm::Triple::Geometry ||
+ (Stage == llvm::Triple::Pixel && IsIn) ||
+ (Stage == llvm::Triple::Mesh && IsOut));
----------------
dnovillo wrote:
`PointSize` can't be a pixel shader input in Vulkan
(VUID-PointSize-PointSize-04314), but we are accepting it here:
```hlsl
float4 main([[vk::builtin("PointSize")]] float s : PSIZE) : SV_Target { return
s.xxxx; }
```
Could you reject it as a pixel input with a diagnostic, and update the docs and
the stages test to match?
https://github.com/llvm/llvm-project/pull/231275
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits