|
@@ -518,6 +518,50 @@ void hlsl::AddRecordTypeWithHandle(ASTContext& context, _Outptr_ CXXRecordDecl**
|
|
*typeDecl = newDecl;
|
|
*typeDecl = newDecl;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// creates a global static constant unsigned integer with value.
|
|
|
|
+// equivalent to: static const uint name = val;
|
|
|
|
+static void AddConstInt(clang::ASTContext& context, DeclContext *DC, StringRef name, int val) {
|
|
|
|
+ IdentifierInfo &Id = context.Idents.get(name, tok::TokenKind::identifier);
|
|
|
|
+ QualType type = context.getConstType(context.UnsignedIntTy);
|
|
|
|
+ VarDecl *varDecl = VarDecl::Create(context, DC, NoLoc, NoLoc, &Id, type,
|
|
|
|
+ context.getTrivialTypeSourceInfo(type),
|
|
|
|
+ clang::StorageClass::SC_Static);
|
|
|
|
+ Expr *exprVal = IntegerLiteral::Create(
|
|
|
|
+ context, llvm::APInt(context.getIntWidth(type), val), type, NoLoc);
|
|
|
|
+ varDecl->setInit(exprVal);
|
|
|
|
+ varDecl->setImplicit(true);
|
|
|
|
+ DC->addDecl(varDecl);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// <summary> Adds a const integers for ray flags </summary>
|
|
|
|
+void hlsl::AddRayFlags(ASTContext& context) {
|
|
|
|
+ DeclContext *curDC = context.getTranslationUnitDecl();
|
|
|
|
+ // typedef uint RAY_FLAG;
|
|
|
|
+ IdentifierInfo &rayFlagId = context.Idents.get(StringRef("RAY_FLAG"), tok::TokenKind::identifier);
|
|
|
|
+ TypeSourceInfo *uintTypeSource = context.getTrivialTypeSourceInfo(context.UnsignedIntTy, NoLoc);
|
|
|
|
+ TypedefDecl *rayFlagDecl = TypedefDecl::Create(context, curDC, NoLoc, NoLoc, &rayFlagId, uintTypeSource);
|
|
|
|
+ curDC->addDecl(rayFlagDecl);
|
|
|
|
+ rayFlagDecl->setImplicit(true);
|
|
|
|
+ // static const uint RAY_FLAG_* = *;
|
|
|
|
+ AddConstInt(context, curDC, StringRef("RAY_FLAG_NONE"), 0x00);
|
|
|
|
+ AddConstInt(context, curDC, StringRef("RAY_FLAG_FORCE_OPAQUE"), 0x01);
|
|
|
|
+ AddConstInt(context, curDC, StringRef("RAY_FLAG_FORCE_NON_OPAQUE"), 0x02);
|
|
|
|
+ AddConstInt(context, curDC, StringRef("RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH"), 0x04);
|
|
|
|
+ AddConstInt(context, curDC, StringRef("RAY_FLAG_SKIP_CLOSEST_HIT_SHADER"), 0x08);
|
|
|
|
+ AddConstInt(context, curDC, StringRef("RAY_FLAG_CULL_BACK_FACING_TRIANGLES"), 0x10);
|
|
|
|
+ AddConstInt(context, curDC, StringRef("RAY_FLAG_CULL_FRONT_FACING_TRIANGLES"), 0x20);
|
|
|
|
+ AddConstInt(context, curDC, StringRef("RAY_FLAG_CULL_OPAQUE"), 0x40);
|
|
|
|
+ AddConstInt(context, curDC, StringRef("RAY_FLAG_CULL_NON_OPAQUE"), 0x80);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// <summary> Adds a constant integers for hit kinds </summary>
|
|
|
|
+void hlsl::AddHitKinds(ASTContext& context) {
|
|
|
|
+ DeclContext *curDC = context.getTranslationUnitDecl();
|
|
|
|
+ // static const uint HIT_KIND_* = *;
|
|
|
|
+ AddConstInt(context, curDC, StringRef("HIT_KIND_TRIANGLE_FRONT_FACE"), 0xfe);
|
|
|
|
+ AddConstInt(context, curDC, StringRef("HIT_KIND_TRIANGLE_BACK_FACE"), 0xff);
|
|
|
|
+}
|
|
|
|
+
|
|
static
|
|
static
|
|
Expr* IntConstantAsBoolExpr(clang::Sema& sema, uint64_t value)
|
|
Expr* IntConstantAsBoolExpr(clang::Sema& sema, uint64_t value)
|
|
{
|
|
{
|