|
@@ -17,6 +17,7 @@
|
|
|
#include "clang/AST/Expr.h"
|
|
|
#include "clang/AST/ExprCXX.h"
|
|
|
#include "clang/AST/ExternalASTSource.h"
|
|
|
+#include "clang/AST/HlslBuiltinTypeDeclBuilder.h"
|
|
|
#include "clang/AST/TypeLoc.h"
|
|
|
#include "clang/Sema/SemaDiagnostic.h"
|
|
|
#include "clang/Sema/Sema.h"
|
|
@@ -238,22 +239,6 @@ CanQualType GetHLSLObjectHandleType(ASTContext& context)
|
|
|
return context.IntTy;
|
|
|
}
|
|
|
|
|
|
-/// <summary>Adds a handle field to the specified record.</summary>
|
|
|
-static
|
|
|
-void AddHLSLHandleField(ASTContext& context, DeclContext* recordDecl, QualType handleQualType)
|
|
|
-{
|
|
|
- IdentifierInfo& handleId = context.Idents.get(StringRef("h"), tok::TokenKind::identifier);
|
|
|
- TypeSourceInfo* fieldTypeSource = context.getTrivialTypeSourceInfo(handleQualType, NoLoc);
|
|
|
- const bool MutableFalse = false;
|
|
|
- const InClassInitStyle initStyle = InClassInitStyle::ICIS_NoInit;
|
|
|
- FieldDecl* handleDecl = FieldDecl::Create(
|
|
|
- context, recordDecl, NoLoc, NoLoc, &handleId, handleQualType, fieldTypeSource, nullptr, MutableFalse, initStyle);
|
|
|
- handleDecl->setAccess(AccessSpecifier::AS_private);
|
|
|
- handleDecl->setImplicit(true);
|
|
|
-
|
|
|
- recordDecl->addDecl(handleDecl);
|
|
|
-}
|
|
|
-
|
|
|
static
|
|
|
void AddSubscriptOperator(
|
|
|
ASTContext& context, unsigned int templateDepth, TemplateTypeParmDecl *elementTemplateParamDecl,
|
|
@@ -297,52 +282,15 @@ void hlsl::AddHLSLMatrixTemplate(ASTContext& context, ClassTemplateDecl* vectorT
|
|
|
DXASSERT_NOMSG(matrixTemplateDecl != nullptr);
|
|
|
DXASSERT_NOMSG(vectorTemplateDecl != nullptr);
|
|
|
|
|
|
- DeclContext* currentDeclContext = context.getTranslationUnitDecl();
|
|
|
-
|
|
|
// Create a matrix template declaration in translation unit scope.
|
|
|
// template<typename element, int row_count, int col_count> matrix { ... }
|
|
|
- IdentifierInfo& elementTemplateParamId = context.Idents.get(StringRef("element"), tok::TokenKind::identifier);
|
|
|
- TemplateTypeParmDecl *elementTemplateParamDecl = TemplateTypeParmDecl::Create(
|
|
|
- context, currentDeclContext, NoLoc, NoLoc,
|
|
|
- FirstTemplateDepth, FirstParamPosition, &elementTemplateParamId, TypenameFalse, ParameterPackFalse);
|
|
|
- elementTemplateParamDecl->setDefaultArgument(context.getTrivialTypeSourceInfo(context.FloatTy));
|
|
|
- QualType intType = context.IntTy;
|
|
|
- Expr *literalIntFour = IntegerLiteral::Create(
|
|
|
- context, llvm::APInt(context.getIntWidth(intType), 4), intType, NoLoc);
|
|
|
- IdentifierInfo& rowCountParamId = context.Idents.get(StringRef("row_count"), tok::TokenKind::identifier);
|
|
|
- NonTypeTemplateParmDecl* rowCountTemplateParamDecl = NonTypeTemplateParmDecl::Create(
|
|
|
- context, currentDeclContext, NoLoc, NoLoc,
|
|
|
- FirstTemplateDepth, FirstParamPosition + 1, &rowCountParamId, intType, ParameterPackFalse, context.getTrivialTypeSourceInfo(intType));
|
|
|
- rowCountTemplateParamDecl->setDefaultArgument(literalIntFour);
|
|
|
- IdentifierInfo& colCountParamId = context.Idents.get(StringRef("col_count"), tok::TokenKind::identifier);
|
|
|
- NonTypeTemplateParmDecl* colCountTemplateParamDecl = NonTypeTemplateParmDecl::Create(
|
|
|
- context, currentDeclContext, NoLoc, NoLoc,
|
|
|
- FirstTemplateDepth, FirstParamPosition + 2, &colCountParamId, intType, ParameterPackFalse, context.getTrivialTypeSourceInfo(intType));
|
|
|
- colCountTemplateParamDecl->setDefaultArgument(literalIntFour);
|
|
|
- NamedDecl* templateParameters[] =
|
|
|
- {
|
|
|
- elementTemplateParamDecl, rowCountTemplateParamDecl, colCountTemplateParamDecl
|
|
|
- };
|
|
|
- TemplateParameterList* templateParameterList = TemplateParameterList::Create(
|
|
|
- context, NoLoc, NoLoc, templateParameters, _countof(templateParameters), NoLoc);
|
|
|
-
|
|
|
- IdentifierInfo& matrixId = context.Idents.get(StringRef("matrix"), tok::TokenKind::identifier);
|
|
|
- CXXRecordDecl* templateRecordDecl = CXXRecordDecl::Create(
|
|
|
- context, TagDecl::TagKind::TTK_Class, currentDeclContext, NoLoc, NoLoc, &matrixId,
|
|
|
- nullptr, DelayTypeCreationTrue);
|
|
|
- ClassTemplateDecl* classTemplateDecl = ClassTemplateDecl::Create(
|
|
|
- context, currentDeclContext, NoLoc, DeclarationName(&matrixId),
|
|
|
- templateParameterList, templateRecordDecl, nullptr);
|
|
|
- templateRecordDecl->setDescribedClassTemplate(classTemplateDecl);
|
|
|
- templateRecordDecl->addAttr(FinalAttr::CreateImplicit(context, FinalAttr::Keyword_final));
|
|
|
-
|
|
|
- // Requesting the class name specialization will fault in required types.
|
|
|
- QualType T = classTemplateDecl->getInjectedClassNameSpecialization();
|
|
|
- T = context.getInjectedClassNameType(templateRecordDecl, T);
|
|
|
- assert(T->isDependentType() && "Class template type is not dependent?");
|
|
|
- classTemplateDecl->setLexicalDeclContext(currentDeclContext);
|
|
|
- templateRecordDecl->setLexicalDeclContext(currentDeclContext);
|
|
|
- templateRecordDecl->startDefinition();
|
|
|
+ BuiltinTypeDeclBuilder typeDeclBuilder(context.getTranslationUnitDecl(), "matrix");
|
|
|
+ TemplateTypeParmDecl* elementTemplateParamDecl = typeDeclBuilder.addTypeTemplateParam("element", (QualType)context.FloatTy);
|
|
|
+ NonTypeTemplateParmDecl* rowCountTemplateParamDecl = typeDeclBuilder.addIntegerTemplateParam("row_count", context.IntTy, 4);
|
|
|
+ NonTypeTemplateParmDecl* colCountTemplateParamDecl = typeDeclBuilder.addIntegerTemplateParam("col_count", context.IntTy, 4);
|
|
|
+ typeDeclBuilder.startDefinition();
|
|
|
+ CXXRecordDecl* templateRecordDecl = typeDeclBuilder.getRecordDecl();
|
|
|
+ ClassTemplateDecl* classTemplateDecl = typeDeclBuilder.getTemplateDecl();
|
|
|
|
|
|
// Add an 'h' field to hold the handle.
|
|
|
// The type is vector<element, col>[row].
|
|
@@ -352,20 +300,20 @@ void hlsl::AddHLSLMatrixTemplate(ASTContext& context, ClassTemplateDecl* vectorT
|
|
|
context, NestedNameSpecifierLoc(), NoLoc, rowCountTemplateParamDecl,
|
|
|
false,
|
|
|
DeclarationNameInfo(rowCountTemplateParamDecl->getDeclName(), NoLoc),
|
|
|
- intType, ExprValueKind::VK_RValue);
|
|
|
+ context.IntTy, ExprValueKind::VK_RValue);
|
|
|
|
|
|
Expr *rowSizeExpr = DeclRefExpr::Create(
|
|
|
context, NestedNameSpecifierLoc(), NoLoc, colCountTemplateParamDecl,
|
|
|
false,
|
|
|
DeclarationNameInfo(colCountTemplateParamDecl->getDeclName(), NoLoc),
|
|
|
- intType, ExprValueKind::VK_RValue);
|
|
|
+ context.IntTy, ExprValueKind::VK_RValue);
|
|
|
|
|
|
QualType vectorType = context.getDependentSizedExtVectorType(
|
|
|
elementType, rowSizeExpr, SourceLocation());
|
|
|
QualType vectorArrayType = context.getDependentSizedArrayType(
|
|
|
vectorType, sizeExpr, ArrayType::Normal, 0, SourceRange());
|
|
|
|
|
|
- AddHLSLHandleField(context, templateRecordDecl, vectorArrayType);
|
|
|
+ typeDeclBuilder.addField("h", vectorArrayType);
|
|
|
|
|
|
// Add an operator[]. The operator ranges from zero to rowcount-1, and returns a vector of colcount elements.
|
|
|
const unsigned int templateDepth = 0;
|
|
@@ -376,22 +324,7 @@ void hlsl::AddHLSLMatrixTemplate(ASTContext& context, ClassTemplateDecl* vectorT
|
|
|
colCountTemplateParamDecl, context.UnsignedIntTy,
|
|
|
templateRecordDecl, vectorTemplateDecl, ForConstTrue);
|
|
|
|
|
|
- templateRecordDecl->completeDefinition();
|
|
|
-
|
|
|
- classTemplateDecl->setImplicit(true);
|
|
|
- templateRecordDecl->setImplicit(true);
|
|
|
-
|
|
|
- // Both declarations need to be present for correct handling.
|
|
|
- currentDeclContext->addDecl(classTemplateDecl);
|
|
|
- currentDeclContext->addDecl(templateRecordDecl);
|
|
|
-
|
|
|
-#ifdef DBG
|
|
|
- // Verify that we can read the field member from the template record.
|
|
|
- DeclContext::lookup_result lookupResult = templateRecordDecl->lookup(
|
|
|
- DeclarationName(&context.Idents.get(StringRef("h"))));
|
|
|
- DXASSERT(!lookupResult.empty(), "otherwise matrix handle cannot be looked up");
|
|
|
-#endif
|
|
|
-
|
|
|
+ typeDeclBuilder.completeDefinition();
|
|
|
*matrixTemplateDecl = classTemplateDecl;
|
|
|
}
|
|
|
|
|
@@ -405,53 +338,20 @@ void hlsl::AddHLSLVectorTemplate(ASTContext& context, ClassTemplateDecl** vector
|
|
|
{
|
|
|
DXASSERT_NOMSG(vectorTemplateDecl != nullptr);
|
|
|
|
|
|
- DeclContext* currentDeclContext = context.getTranslationUnitDecl();
|
|
|
-
|
|
|
// Create a vector template declaration in translation unit scope.
|
|
|
// template<typename element, int element_count> vector { ... }
|
|
|
- IdentifierInfo& elementTemplateParamId = context.Idents.get(StringRef("element"), tok::TokenKind::identifier);
|
|
|
- TemplateTypeParmDecl *elementTemplateParamDecl = TemplateTypeParmDecl::Create(
|
|
|
- context, currentDeclContext, NoLoc, NoLoc,
|
|
|
- FirstTemplateDepth, FirstParamPosition, &elementTemplateParamId, TypenameFalse, ParameterPackFalse);
|
|
|
- elementTemplateParamDecl->setDefaultArgument(context.getTrivialTypeSourceInfo(context.FloatTy));
|
|
|
- QualType intType = context.IntTy;
|
|
|
- Expr *literalIntFour = IntegerLiteral::Create(
|
|
|
- context, llvm::APInt(context.getIntWidth(intType), 4), intType, NoLoc);
|
|
|
- IdentifierInfo& colCountParamId = context.Idents.get(StringRef("element_count"), tok::TokenKind::identifier);
|
|
|
- NonTypeTemplateParmDecl* colCountTemplateParamDecl = NonTypeTemplateParmDecl::Create(
|
|
|
- context, currentDeclContext, NoLoc, NoLoc,
|
|
|
- FirstTemplateDepth, FirstParamPosition + 1, &colCountParamId, intType, ParameterPackFalse, nullptr);
|
|
|
- colCountTemplateParamDecl->setDefaultArgument(literalIntFour);
|
|
|
- NamedDecl* templateParameters[] =
|
|
|
- {
|
|
|
- elementTemplateParamDecl, colCountTemplateParamDecl
|
|
|
- };
|
|
|
- TemplateParameterList* templateParameterList = TemplateParameterList::Create(
|
|
|
- context, NoLoc, NoLoc, templateParameters, _countof(templateParameters), NoLoc);
|
|
|
-
|
|
|
- IdentifierInfo& vectorId = context.Idents.get(StringRef("vector"), tok::TokenKind::identifier);
|
|
|
- CXXRecordDecl* templateRecordDecl = CXXRecordDecl::Create(
|
|
|
- context, TagDecl::TagKind::TTK_Class, currentDeclContext, NoLoc, NoLoc, &vectorId,
|
|
|
- nullptr, DelayTypeCreationTrue);
|
|
|
- ClassTemplateDecl* classTemplateDecl = ClassTemplateDecl::Create(
|
|
|
- context, currentDeclContext, NoLoc, DeclarationName(&vectorId),
|
|
|
- templateParameterList, templateRecordDecl, nullptr);
|
|
|
- templateRecordDecl->setDescribedClassTemplate(classTemplateDecl);
|
|
|
- templateRecordDecl->addAttr(FinalAttr::CreateImplicit(context, FinalAttr::Keyword_final));
|
|
|
-
|
|
|
- // Requesting the class name specialization will fault in required types.
|
|
|
- QualType T = classTemplateDecl->getInjectedClassNameSpecialization();
|
|
|
- T = context.getInjectedClassNameType(templateRecordDecl, T);
|
|
|
- assert(T->isDependentType() && "Class template type is not dependent?");
|
|
|
- classTemplateDecl->setLexicalDeclContext(currentDeclContext);
|
|
|
- templateRecordDecl->setLexicalDeclContext(currentDeclContext);
|
|
|
- templateRecordDecl->startDefinition();
|
|
|
+ BuiltinTypeDeclBuilder typeDeclBuilder(context.getTranslationUnitDecl(), "vector");
|
|
|
+ TemplateTypeParmDecl* elementTemplateParamDecl = typeDeclBuilder.addTypeTemplateParam("element", (QualType)context.FloatTy);
|
|
|
+ NonTypeTemplateParmDecl* colCountTemplateParamDecl = typeDeclBuilder.addIntegerTemplateParam("element_count", context.IntTy, 4);
|
|
|
+ typeDeclBuilder.startDefinition();
|
|
|
+ CXXRecordDecl* templateRecordDecl = typeDeclBuilder.getRecordDecl();
|
|
|
+ ClassTemplateDecl* classTemplateDecl = typeDeclBuilder.getTemplateDecl();
|
|
|
|
|
|
Expr *vecSizeExpr = DeclRefExpr::Create(
|
|
|
context, NestedNameSpecifierLoc(), NoLoc, colCountTemplateParamDecl,
|
|
|
false,
|
|
|
DeclarationNameInfo(colCountTemplateParamDecl->getDeclName(), NoLoc),
|
|
|
- intType, ExprValueKind::VK_RValue);
|
|
|
+ context.IntTy, ExprValueKind::VK_RValue);
|
|
|
|
|
|
const unsigned int templateDepth = 0;
|
|
|
QualType resultType = context.getTemplateTypeParmType(
|
|
@@ -459,7 +359,7 @@ void hlsl::AddHLSLVectorTemplate(ASTContext& context, ClassTemplateDecl** vector
|
|
|
QualType vectorType = context.getDependentSizedExtVectorType(
|
|
|
resultType, vecSizeExpr, SourceLocation());
|
|
|
// Add an 'h' field to hold the handle.
|
|
|
- AddHLSLHandleField(context, templateRecordDecl, vectorType);
|
|
|
+ typeDeclBuilder.addField("h", vectorType);
|
|
|
|
|
|
// Add an operator[]. The operator ranges from zero to colcount-1, and returns a scalar.
|
|
|
|
|
@@ -478,48 +378,18 @@ void hlsl::AddHLSLVectorTemplate(ASTContext& context, ClassTemplateDecl** vector
|
|
|
context.DeclarationNames.getCXXOperatorName(OO_Subscript), ForConstFalse);
|
|
|
AddHLSLVectorSubscriptAttr(functionDecl, context);
|
|
|
|
|
|
- templateRecordDecl->completeDefinition();
|
|
|
-
|
|
|
- classTemplateDecl->setImplicit(true);
|
|
|
- templateRecordDecl->setImplicit(true);
|
|
|
-
|
|
|
- // Both declarations need to be present for correct handling.
|
|
|
- currentDeclContext->addDecl(classTemplateDecl);
|
|
|
- currentDeclContext->addDecl(templateRecordDecl);
|
|
|
-
|
|
|
-#ifdef DBG
|
|
|
- // Verify that we can read the field member from the template record.
|
|
|
- DeclContext::lookup_result lookupResult = templateRecordDecl->lookup(
|
|
|
- DeclarationName(&context.Idents.get(StringRef("h"))));
|
|
|
- DXASSERT(!lookupResult.empty(), "otherwise vector handle cannot be looked up");
|
|
|
-#endif
|
|
|
-
|
|
|
+ typeDeclBuilder.completeDefinition();
|
|
|
*vectorTemplateDecl = classTemplateDecl;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Adds a new record type in the specified context with the given name. The record type will have a handle field.
|
|
|
/// </summary>
|
|
|
-void hlsl::AddRecordTypeWithHandle(ASTContext& context, _Outptr_ CXXRecordDecl** typeDecl, _In_z_ const char* typeName)
|
|
|
-{
|
|
|
- DXASSERT_NOMSG(typeDecl != nullptr);
|
|
|
- DXASSERT_NOMSG(typeName != nullptr);
|
|
|
-
|
|
|
- *typeDecl = nullptr;
|
|
|
-
|
|
|
- DeclContext* currentDeclContext = context.getTranslationUnitDecl();
|
|
|
- IdentifierInfo& newTypeId = context.Idents.get(StringRef(typeName), tok::TokenKind::identifier);
|
|
|
- CXXRecordDecl* newDecl = CXXRecordDecl::Create(
|
|
|
- context, TagDecl::TagKind::TTK_Struct, currentDeclContext, NoLoc, NoLoc, &newTypeId, nullptr);
|
|
|
- newDecl->setLexicalDeclContext(currentDeclContext);
|
|
|
- newDecl->setFreeStanding();
|
|
|
- newDecl->addAttr(FinalAttr::CreateImplicit(context, FinalAttr::Keyword_final));
|
|
|
- newDecl->startDefinition();
|
|
|
- AddHLSLHandleField(context, newDecl, QualType(GetHLSLObjectHandleType(context)));
|
|
|
- currentDeclContext->addDecl(newDecl);
|
|
|
- newDecl->completeDefinition();
|
|
|
-
|
|
|
- *typeDecl = newDecl;
|
|
|
+CXXRecordDecl* hlsl::DeclareRecordTypeWithHandle(ASTContext& context, StringRef name) {
|
|
|
+ BuiltinTypeDeclBuilder typeDeclBuilder(context.getTranslationUnitDecl(), name, TagDecl::TagKind::TTK_Struct);
|
|
|
+ typeDeclBuilder.startDefinition();
|
|
|
+ typeDeclBuilder.addField("h", GetHLSLObjectHandleType(context));
|
|
|
+ return typeDeclBuilder.completeDefinition();
|
|
|
}
|
|
|
|
|
|
// creates a global static constant unsigned integer with value.
|
|
@@ -537,71 +407,58 @@ static void AddConstUInt(clang::ASTContext& context, DeclContext *DC, StringRef
|
|
|
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_* = *;
|
|
|
- AddConstUInt(context, curDC, StringRef("RAY_FLAG_NONE"), (unsigned)DXIL::RayFlag::None);
|
|
|
- AddConstUInt(context, curDC, StringRef("RAY_FLAG_FORCE_OPAQUE"), (unsigned)DXIL::RayFlag::ForceOpaque);
|
|
|
- AddConstUInt(context, curDC, StringRef("RAY_FLAG_FORCE_NON_OPAQUE"), (unsigned)DXIL::RayFlag::ForceNonOpaque);
|
|
|
- AddConstUInt(context, curDC, StringRef("RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH"), (unsigned)DXIL::RayFlag::AcceptFirstHitAndEndSearch);
|
|
|
- AddConstUInt(context, curDC, StringRef("RAY_FLAG_SKIP_CLOSEST_HIT_SHADER"), (unsigned)DXIL::RayFlag::SkipClosestHitShader);
|
|
|
- AddConstUInt(context, curDC, StringRef("RAY_FLAG_CULL_BACK_FACING_TRIANGLES"), (unsigned)DXIL::RayFlag::CullBackFacingTriangles);
|
|
|
- AddConstUInt(context, curDC, StringRef("RAY_FLAG_CULL_FRONT_FACING_TRIANGLES"), (unsigned)DXIL::RayFlag::CullFrontFacingTriangles);
|
|
|
- AddConstUInt(context, curDC, StringRef("RAY_FLAG_CULL_OPAQUE"), (unsigned)DXIL::RayFlag::CullOpaque);
|
|
|
- AddConstUInt(context, curDC, StringRef("RAY_FLAG_CULL_NON_OPAQUE"), (unsigned)DXIL::RayFlag::CullNonOpaque);
|
|
|
+static void AddConstUInt(clang::ASTContext& context, StringRef name, unsigned val) {
|
|
|
+ AddConstUInt(context, context.getTranslationUnitDecl(), name, val);
|
|
|
}
|
|
|
|
|
|
-/// <summary> Adds a constant integers for hit kinds </summary>
|
|
|
-void hlsl::AddHitKinds(ASTContext& context) {
|
|
|
- DeclContext *curDC = context.getTranslationUnitDecl();
|
|
|
- // static const uint HIT_KIND_* = *;
|
|
|
- AddConstUInt(context, curDC, StringRef("HIT_KIND_NONE"), (unsigned)DXIL::HitKind::None);
|
|
|
- AddConstUInt(context, curDC, StringRef("HIT_KIND_TRIANGLE_FRONT_FACE"), (unsigned)DXIL::HitKind::TriangleFrontFace);
|
|
|
- AddConstUInt(context, curDC, StringRef("HIT_KIND_TRIANGLE_BACK_FACE"), (unsigned)DXIL::HitKind::TriangleBackFace);
|
|
|
-}
|
|
|
-
|
|
|
-/// <summary> Adds a constant integers for state object flags </summary>
|
|
|
-void hlsl::AddStateObjectFlags(ASTContext& context) {
|
|
|
- DeclContext *curDC = context.getTranslationUnitDecl();
|
|
|
-
|
|
|
- AddConstUInt(context, curDC, StringRef("STATE_OBJECT_FLAGS_ALLOW_LOCAL_DEPENDENCIES_ON_EXTERNAL_DEFINITONS"), (unsigned)DXIL::StateObjectFlags::AllowLocalDependenciesOnExternalDefinitions);
|
|
|
- AddConstUInt(context, curDC, StringRef("STATE_OBJECT_FLAGS_ALLOW_EXTERNAL_DEPENDENCIES_ON_LOCAL_DEFINITIONS"), (unsigned)DXIL::StateObjectFlags::AllowExternalDependenciesOnLocalDefinitions);
|
|
|
-}
|
|
|
-
|
|
|
-/// <summary> Adds const integers for committed status </summary>
|
|
|
-void hlsl::AddCommittedStatus(ASTContext& context) {
|
|
|
- DeclContext *curDC = context.getTranslationUnitDecl();
|
|
|
- // typedef uint COMMITTED_STATUS;
|
|
|
- IdentifierInfo &enumId = context.Idents.get(StringRef("COMMITTED_STATUS"), tok::TokenKind::identifier);
|
|
|
- TypeSourceInfo *uintTypeSource = context.getTrivialTypeSourceInfo(context.UnsignedIntTy, NoLoc);
|
|
|
- TypedefDecl *enumDecl = TypedefDecl::Create(context, curDC, NoLoc, NoLoc, &enumId, uintTypeSource);
|
|
|
+// Adds a top-level enum with the given enumerants.
|
|
|
+struct Enumerant { StringRef name; unsigned value; };
|
|
|
+static void AddTypedefPseudoEnum(ASTContext& context, StringRef name, ArrayRef<Enumerant> enumerants) {
|
|
|
+ DeclContext* curDC = context.getTranslationUnitDecl();
|
|
|
+ // typedef uint <name>;
|
|
|
+ IdentifierInfo& enumId = context.Idents.get(name, tok::TokenKind::identifier);
|
|
|
+ TypeSourceInfo* uintTypeSource = context.getTrivialTypeSourceInfo(context.UnsignedIntTy, NoLoc);
|
|
|
+ TypedefDecl* enumDecl = TypedefDecl::Create(context, curDC, NoLoc, NoLoc, &enumId, uintTypeSource);
|
|
|
curDC->addDecl(enumDecl);
|
|
|
enumDecl->setImplicit(true);
|
|
|
- // static const uint COMMITTED_* = *;
|
|
|
- AddConstUInt(context, curDC, StringRef("COMMITTED_NOTHING"), (unsigned)DXIL::CommittedStatus::CommittedNothing);
|
|
|
- AddConstUInt(context, curDC, StringRef("COMMITTED_TRIANGLE_HIT"), (unsigned)DXIL::CommittedStatus::CommittedTriangleHit);
|
|
|
- AddConstUInt(context, curDC, StringRef("COMMITTED_PROCEDURAL_PRIMITIVE_HIT"), (unsigned)DXIL::CommittedStatus::CommittedProceduralPrimitiveHit);
|
|
|
+ // static const uint <enumerant.name> = <enumerant.value>;
|
|
|
+ for (const Enumerant& enumerant : enumerants) {
|
|
|
+ AddConstUInt(context, curDC, enumerant.name, enumerant.value);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-/// <summary> Adds const integers for candidate type </summary>
|
|
|
-void hlsl::AddCandidateType(ASTContext& context) {
|
|
|
- DeclContext *curDC = context.getTranslationUnitDecl();
|
|
|
- // typedef uint CANDIDATE_TYPE;
|
|
|
- IdentifierInfo &enumId = context.Idents.get(StringRef("CANDIDATE_TYPE"), tok::TokenKind::identifier);
|
|
|
- TypeSourceInfo *uintTypeSource = context.getTrivialTypeSourceInfo(context.UnsignedIntTy, NoLoc);
|
|
|
- TypedefDecl *enumDecl = TypedefDecl::Create(context, curDC, NoLoc, NoLoc, &enumId, uintTypeSource);
|
|
|
- curDC->addDecl(enumDecl);
|
|
|
- enumDecl->setImplicit(true);
|
|
|
- // static const uint CANDIDATE_* = *;
|
|
|
- AddConstUInt(context, curDC, StringRef("CANDIDATE_NON_OPAQUE_TRIANGLE"), (unsigned)DXIL::CandidateType::CandidateNonOpaqueTriangle);
|
|
|
- AddConstUInt(context, curDC, StringRef("CANDIDATE_PROCEDURAL_PRIMITIVE"), (unsigned)DXIL::CandidateType::CandidateProceduralPrimitive);
|
|
|
+/// <summary> Adds all constants and enums for ray tracing </summary>
|
|
|
+void hlsl::AddRayTracingConstants(ASTContext& context) {
|
|
|
+ AddTypedefPseudoEnum(context, "RAY_FLAG", {
|
|
|
+ { "RAY_FLAG_NONE", (unsigned)DXIL::RayFlag::None },
|
|
|
+ { "RAY_FLAG_FORCE_OPAQUE", (unsigned)DXIL::RayFlag::ForceOpaque },
|
|
|
+ { "RAY_FLAG_FORCE_NON_OPAQUE", (unsigned)DXIL::RayFlag::ForceNonOpaque },
|
|
|
+ { "RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH", (unsigned)DXIL::RayFlag::AcceptFirstHitAndEndSearch },
|
|
|
+ { "RAY_FLAG_SKIP_CLOSEST_HIT_SHADER", (unsigned)DXIL::RayFlag::SkipClosestHitShader },
|
|
|
+ { "RAY_FLAG_CULL_BACK_FACING_TRIANGLES", (unsigned)DXIL::RayFlag::CullBackFacingTriangles },
|
|
|
+ { "RAY_FLAG_CULL_FRONT_FACING_TRIANGLES", (unsigned)DXIL::RayFlag::CullFrontFacingTriangles },
|
|
|
+ { "RAY_FLAG_CULL_OPAQUE", (unsigned)DXIL::RayFlag::CullOpaque },
|
|
|
+ { "RAY_FLAG_CULL_NON_OPAQUE", (unsigned)DXIL::RayFlag::CullNonOpaque },
|
|
|
+ });
|
|
|
+
|
|
|
+ AddTypedefPseudoEnum(context, "COMMITTED_STATUS", {
|
|
|
+ { "COMMITTED_NOTHING", (unsigned)DXIL::CommittedStatus::CommittedNothing },
|
|
|
+ { "COMMITTED_TRIANGLE_HIT", (unsigned)DXIL::CommittedStatus::CommittedTriangleHit },
|
|
|
+ { "COMMITTED_PROCEDURAL_PRIMITIVE_HIT", (unsigned)DXIL::CommittedStatus::CommittedProceduralPrimitiveHit }
|
|
|
+ });
|
|
|
+
|
|
|
+ AddTypedefPseudoEnum(context, "CANDIDATE_TYPE", {
|
|
|
+ { "CANDIDATE_NON_OPAQUE_TRIANGLE", (unsigned)DXIL::CandidateType::CandidateNonOpaqueTriangle },
|
|
|
+ { "CANDIDATE_PROCEDURAL_PRIMITIVE", (unsigned)DXIL::CandidateType::CandidateProceduralPrimitive }
|
|
|
+ });
|
|
|
+
|
|
|
+ // static const uint HIT_KIND_* = *;
|
|
|
+ AddConstUInt(context, StringRef("HIT_KIND_NONE"), (unsigned)DXIL::HitKind::None);
|
|
|
+ AddConstUInt(context, StringRef("HIT_KIND_TRIANGLE_FRONT_FACE"), (unsigned)DXIL::HitKind::TriangleFrontFace);
|
|
|
+ AddConstUInt(context, StringRef("HIT_KIND_TRIANGLE_BACK_FACE"), (unsigned)DXIL::HitKind::TriangleBackFace);
|
|
|
+
|
|
|
+ AddConstUInt(context, StringRef("STATE_OBJECT_FLAGS_ALLOW_LOCAL_DEPENDENCIES_ON_EXTERNAL_DEFINITONS"), (unsigned)DXIL::StateObjectFlags::AllowLocalDependenciesOnExternalDefinitions);
|
|
|
+ AddConstUInt(context, StringRef("STATE_OBJECT_FLAGS_ALLOW_EXTERNAL_DEPENDENCIES_ON_LOCAL_DEFINITIONS"), (unsigned)DXIL::StateObjectFlags::AllowExternalDependenciesOnLocalDefinitions);
|
|
|
}
|
|
|
|
|
|
static
|
|
@@ -765,79 +622,29 @@ void hlsl::AddStdIsEqualImplementation(clang::ASTContext& context, clang::Sema&
|
|
|
/// Adds a new template type in the specified context with the given name. The record type will have a handle field.
|
|
|
/// </summary>
|
|
|
/// <parm name="context">AST context to which template will be added.</param>
|
|
|
-/// <parm name="typeDecl">After execution, template declaration.</param>
|
|
|
-/// <parm name="recordDecl">After execution, record declaration for template.</param>
|
|
|
/// <parm name="typeName">Name of template to create.</param>
|
|
|
/// <parm name="templateArgCount">Number of template arguments (one or two).</param>
|
|
|
/// <parm name="defaultTypeArgValue">If assigned, the default argument for the element template.</param>
|
|
|
-void hlsl::AddTemplateTypeWithHandle(
|
|
|
+CXXRecordDecl* hlsl::DeclareTemplateTypeWithHandle(
|
|
|
ASTContext& context,
|
|
|
- _Outptr_ ClassTemplateDecl** typeDecl,
|
|
|
- _Outptr_ CXXRecordDecl** recordDecl,
|
|
|
- _In_z_ const char* typeName,
|
|
|
+ StringRef name,
|
|
|
uint8_t templateArgCount,
|
|
|
- _In_opt_ TypeSourceInfo* defaultTypeArgValue
|
|
|
-)
|
|
|
+ _In_opt_ TypeSourceInfo* defaultTypeArgValue)
|
|
|
{
|
|
|
- DXASSERT_NOMSG(typeDecl != nullptr);
|
|
|
- DXASSERT_NOMSG(recordDecl != nullptr);
|
|
|
- DXASSERT_NOMSG(typeName != nullptr);
|
|
|
-
|
|
|
DXASSERT(templateArgCount != 0, "otherwise caller should be creating a class or struct");
|
|
|
DXASSERT(templateArgCount <= 2, "otherwise the function needs to be updated for a different template pattern");
|
|
|
|
|
|
- DeclContext* currentDeclContext = context.getTranslationUnitDecl();
|
|
|
-
|
|
|
// Create an object template declaration in translation unit scope.
|
|
|
// templateArgCount=1: template<typename element> typeName { ... }
|
|
|
// templateArgCount=2: template<typename element, int count> typeName { ... }
|
|
|
- IdentifierInfo& elementTemplateParamId = context.Idents.get(StringRef("element"), tok::TokenKind::identifier);
|
|
|
- TemplateTypeParmDecl *elementTemplateParamDecl = TemplateTypeParmDecl::Create(
|
|
|
- context, currentDeclContext, NoLoc, NoLoc,
|
|
|
- FirstTemplateDepth, FirstParamPosition, &elementTemplateParamId, TypenameFalse, ParameterPackFalse);
|
|
|
- QualType intType = context.IntTy;
|
|
|
-
|
|
|
- if (defaultTypeArgValue != nullptr)
|
|
|
- {
|
|
|
- elementTemplateParamDecl->setDefaultArgument(defaultTypeArgValue);
|
|
|
- }
|
|
|
-
|
|
|
+ BuiltinTypeDeclBuilder typeDeclBuilder(context.getTranslationUnitDecl(), name);
|
|
|
+ TemplateTypeParmDecl* elementTemplateParamDecl = typeDeclBuilder.addTypeTemplateParam("element", defaultTypeArgValue);
|
|
|
NonTypeTemplateParmDecl* countTemplateParamDecl = nullptr;
|
|
|
- if (templateArgCount > 1) {
|
|
|
- IdentifierInfo& countParamId = context.Idents.get(StringRef("count"), tok::TokenKind::identifier);
|
|
|
- countTemplateParamDecl = NonTypeTemplateParmDecl::Create(
|
|
|
- context, currentDeclContext, NoLoc, NoLoc,
|
|
|
- FirstTemplateDepth, FirstParamPosition + 1, &countParamId, intType, ParameterPackFalse, nullptr);
|
|
|
- // Zero means default here. The count is decided by runtime.
|
|
|
- Expr *literalIntZero = IntegerLiteral::Create(
|
|
|
- context, llvm::APInt(context.getIntWidth(intType), 0), intType, NoLoc);
|
|
|
- countTemplateParamDecl->setDefaultArgument(literalIntZero);
|
|
|
- }
|
|
|
- NamedDecl* templateParameters[] =
|
|
|
- {
|
|
|
- elementTemplateParamDecl, countTemplateParamDecl
|
|
|
- };
|
|
|
- TemplateParameterList* templateParameterList = TemplateParameterList::Create(
|
|
|
- context, NoLoc, NoLoc, templateParameters, templateArgCount, NoLoc);
|
|
|
-
|
|
|
- IdentifierInfo& typeId = context.Idents.get(StringRef(typeName), tok::TokenKind::identifier);
|
|
|
- CXXRecordDecl* templateRecordDecl = CXXRecordDecl::Create(
|
|
|
- context, TagDecl::TagKind::TTK_Class, currentDeclContext, NoLoc, NoLoc, &typeId,
|
|
|
- nullptr, DelayTypeCreationTrue);
|
|
|
- ClassTemplateDecl* classTemplateDecl = ClassTemplateDecl::Create(
|
|
|
- context, currentDeclContext, NoLoc, DeclarationName(&typeId),
|
|
|
- templateParameterList, templateRecordDecl, nullptr);
|
|
|
- templateRecordDecl->setDescribedClassTemplate(classTemplateDecl);
|
|
|
- templateRecordDecl->addAttr(FinalAttr::CreateImplicit(context, FinalAttr::Keyword_final));
|
|
|
-
|
|
|
- // Requesting the class name specialization will fault in required types.
|
|
|
- QualType T = classTemplateDecl->getInjectedClassNameSpecialization();
|
|
|
- T = context.getInjectedClassNameType(templateRecordDecl, T);
|
|
|
- assert(T->isDependentType() && "Class template type is not dependent?");
|
|
|
- classTemplateDecl->setLexicalDeclContext(currentDeclContext);
|
|
|
- templateRecordDecl->setLexicalDeclContext(currentDeclContext);
|
|
|
- templateRecordDecl->startDefinition();
|
|
|
- // Many more things to come here, like constructors and the like....
|
|
|
+ if (templateArgCount > 1)
|
|
|
+ countTemplateParamDecl = typeDeclBuilder.addIntegerTemplateParam("count", context.IntTy, 0);
|
|
|
+
|
|
|
+ typeDeclBuilder.startDefinition();
|
|
|
+ CXXRecordDecl* templateRecordDecl = typeDeclBuilder.getRecordDecl();
|
|
|
|
|
|
// Add an 'h' field to hold the handle.
|
|
|
QualType elementType = context.getTemplateTypeParmType(
|
|
@@ -847,11 +654,11 @@ void hlsl::AddTemplateTypeWithHandle(
|
|
|
// Only need array type for inputpatch and outputpatch.
|
|
|
// Avoid Texture2DMS which may use 0 count.
|
|
|
// TODO: use hlsl types to do the check.
|
|
|
- !typeId.getName().startswith("Texture")) {
|
|
|
+ !name.startswith("Texture")) {
|
|
|
Expr *countExpr = DeclRefExpr::Create(
|
|
|
context, NestedNameSpecifierLoc(), NoLoc, countTemplateParamDecl, false,
|
|
|
DeclarationNameInfo(countTemplateParamDecl->getDeclName(), NoLoc),
|
|
|
- intType, ExprValueKind::VK_RValue);
|
|
|
+ context.IntTy, ExprValueKind::VK_RValue);
|
|
|
|
|
|
elementType = context.getDependentSizedArrayType(
|
|
|
elementType, countExpr, ArrayType::ArraySizeModifier::Normal, 0,
|
|
@@ -859,31 +666,17 @@ void hlsl::AddTemplateTypeWithHandle(
|
|
|
|
|
|
// InputPatch and OutputPatch also have a "Length" static const member for the number of control points
|
|
|
IdentifierInfo& lengthId = context.Idents.get(StringRef("Length"), tok::TokenKind::identifier);
|
|
|
- TypeSourceInfo* lengthTypeSource = context.getTrivialTypeSourceInfo(intType.withConst());
|
|
|
+ TypeSourceInfo* lengthTypeSource = context.getTrivialTypeSourceInfo(context.IntTy.withConst());
|
|
|
VarDecl* lengthValueDecl = VarDecl::Create(context, templateRecordDecl, NoLoc, NoLoc, &lengthId,
|
|
|
- intType.withConst(), lengthTypeSource, SC_Static);
|
|
|
+ context.IntTy.withConst(), lengthTypeSource, SC_Static);
|
|
|
lengthValueDecl->setInit(countExpr);
|
|
|
lengthValueDecl->setAccess(AS_public);
|
|
|
templateRecordDecl->addDecl(lengthValueDecl);
|
|
|
}
|
|
|
|
|
|
- AddHLSLHandleField(context, templateRecordDecl, elementType);
|
|
|
-
|
|
|
- templateRecordDecl->completeDefinition();
|
|
|
+ typeDeclBuilder.addField("h", elementType);
|
|
|
|
|
|
- // Both declarations need to be present for correct handling.
|
|
|
- currentDeclContext->addDecl(classTemplateDecl);
|
|
|
- currentDeclContext->addDecl(templateRecordDecl);
|
|
|
-
|
|
|
-#ifdef DBG
|
|
|
- // Verify that we can read the field member from the template record.
|
|
|
- DeclContext::lookup_result lookupResult = templateRecordDecl->lookup(
|
|
|
- DeclarationName(&context.Idents.get(StringRef("h"))));
|
|
|
- DXASSERT(!lookupResult.empty(), "otherwise template object handle cannot be looked up");
|
|
|
-#endif
|
|
|
-
|
|
|
- *typeDecl = classTemplateDecl;
|
|
|
- *recordDecl = templateRecordDecl;
|
|
|
+ return typeDeclBuilder.completeDefinition();
|
|
|
}
|
|
|
|
|
|
FunctionTemplateDecl* hlsl::CreateFunctionTemplateDecl(
|
|
@@ -988,75 +781,14 @@ CXXMethodDecl* hlsl::CreateObjectFunctionDeclarationWithParams(
|
|
|
return functionDecl;
|
|
|
}
|
|
|
|
|
|
-void hlsl::AddRayQueryTemplate(
|
|
|
- ASTContext& context,
|
|
|
- _Outptr_ ClassTemplateDecl** typeDecl,
|
|
|
- _Outptr_ CXXRecordDecl** recordDecl
|
|
|
-)
|
|
|
-{
|
|
|
- DXASSERT_NOMSG(typeDecl != nullptr);
|
|
|
- DXASSERT_NOMSG(recordDecl != nullptr);
|
|
|
-
|
|
|
- DeclContext* currentDeclContext = context.getTranslationUnitDecl();
|
|
|
-
|
|
|
- // Create a RayQuery template declaration in translation unit scope.
|
|
|
- // template<uint flags> RayQuery { ... }
|
|
|
- QualType uintType = context.UnsignedIntTy;
|
|
|
-
|
|
|
- NonTypeTemplateParmDecl* flagsTemplateParamDecl = nullptr;
|
|
|
- IdentifierInfo& countParamId = context.Idents.get(StringRef("flags"), tok::TokenKind::identifier);
|
|
|
- flagsTemplateParamDecl = NonTypeTemplateParmDecl::Create(
|
|
|
- context, currentDeclContext, NoLoc, NoLoc,
|
|
|
- FirstTemplateDepth, FirstParamPosition, &countParamId, uintType, ParameterPackFalse, nullptr);
|
|
|
-
|
|
|
- // Should flags default to zero?
|
|
|
- Expr *literalIntZero = IntegerLiteral::Create(
|
|
|
- context, llvm::APInt(context.getIntWidth(uintType), 0), uintType, NoLoc);
|
|
|
- flagsTemplateParamDecl->setDefaultArgument(literalIntZero);
|
|
|
-
|
|
|
- NamedDecl* templateParameters[] =
|
|
|
- {
|
|
|
- flagsTemplateParamDecl
|
|
|
- };
|
|
|
- TemplateParameterList* templateParameterList = TemplateParameterList::Create(
|
|
|
- context, NoLoc, NoLoc, templateParameters, 1, NoLoc);
|
|
|
-
|
|
|
- IdentifierInfo& typeId = context.Idents.get(StringRef("RayQuery"), tok::TokenKind::identifier);
|
|
|
- CXXRecordDecl* templateRecordDecl = CXXRecordDecl::Create(
|
|
|
- context, TagDecl::TagKind::TTK_Class, currentDeclContext, NoLoc, NoLoc, &typeId,
|
|
|
- nullptr, DelayTypeCreationTrue);
|
|
|
- ClassTemplateDecl* classTemplateDecl = ClassTemplateDecl::Create(
|
|
|
- context, currentDeclContext, NoLoc, DeclarationName(&typeId),
|
|
|
- templateParameterList, templateRecordDecl, nullptr);
|
|
|
- templateRecordDecl->setDescribedClassTemplate(classTemplateDecl);
|
|
|
- templateRecordDecl->addAttr(FinalAttr::CreateImplicit(context, FinalAttr::Keyword_final));
|
|
|
-
|
|
|
- // Requesting the class name specialization will fault in required types.
|
|
|
- QualType T = classTemplateDecl->getInjectedClassNameSpecialization();
|
|
|
- T = context.getInjectedClassNameType(templateRecordDecl, T);
|
|
|
- assert(T->isDependentType() && "Class template type is not dependent?");
|
|
|
- classTemplateDecl->setLexicalDeclContext(currentDeclContext);
|
|
|
- templateRecordDecl->setLexicalDeclContext(currentDeclContext);
|
|
|
- templateRecordDecl->startDefinition();
|
|
|
-
|
|
|
- // Add an 'h' field to hold the handle.
|
|
|
- AddHLSLHandleField(context, templateRecordDecl, uintType);
|
|
|
-
|
|
|
- templateRecordDecl->completeDefinition();
|
|
|
-
|
|
|
- // Both declarations need to be present for correct handling.
|
|
|
- currentDeclContext->addDecl(classTemplateDecl);
|
|
|
- currentDeclContext->addDecl(templateRecordDecl);
|
|
|
-
|
|
|
-#ifdef DBG
|
|
|
- // Verify that we can read the field member from the template record.
|
|
|
- DeclContext::lookup_result lookupResult = templateRecordDecl->lookup(
|
|
|
- DeclarationName(&context.Idents.get(StringRef("h"))));
|
|
|
- DXASSERT(!lookupResult.empty(), "otherwise template object handle cannot be looked up");
|
|
|
-#endif
|
|
|
-
|
|
|
- *typeDecl = classTemplateDecl;
|
|
|
- *recordDecl = templateRecordDecl;
|
|
|
+CXXRecordDecl* hlsl::DeclareUIntTemplatedTypeWithHandle(
|
|
|
+ ASTContext& context, StringRef typeName, StringRef templateParamName) {
|
|
|
+ // template<uint kind> RayQuery/FeedbackTexture2D[Array] { ... }
|
|
|
+ BuiltinTypeDeclBuilder typeDeclBuilder(context.getTranslationUnitDecl(), typeName);
|
|
|
+ typeDeclBuilder.addIntegerTemplateParam(templateParamName, context.UnsignedIntTy);
|
|
|
+ typeDeclBuilder.startDefinition();
|
|
|
+ typeDeclBuilder.addField("h", context.UnsignedIntTy); // Add an 'h' field to hold the handle.
|
|
|
+ return typeDeclBuilder.completeDefinition();
|
|
|
}
|
|
|
|
|
|
bool hlsl::IsIntrinsicOp(const clang::FunctionDecl *FD) {
|