5353#include <bitset>
5454#include <float.h>
5555
56- std::optional<bool> disableHLSLIntrinsicsGlobalVariableBecauseIDontCare = std::nullopt;
57-
5856enum ArBasicKind {
5957 AR_BASIC_BOOL,
6058 AR_BASIC_LITERAL_FLOAT,
@@ -2996,6 +2994,9 @@ static TypedefDecl *CreateGlobalTypedef(ASTContext *context, const char *ident,
29962994
29972995class HLSLExternalSource : public ExternalSemaSource {
29982996private:
2997+
2998+ const bool m_disableHLSLIntrinsics;
2999+
29993000 // Inner types.
30003001 struct FindStructBasicTypeResult {
30013002 ArBasicKind Kind; // Kind of struct (eg, AR_OBJECT_TEXTURE2D)
@@ -4115,13 +4116,14 @@ class HLSLExternalSource : public ExternalSemaSource {
41154116 }
41164117
41174118public:
4118- HLSLExternalSource()
4119+ HLSLExternalSource(bool disableHLSLIntrinsics )
41194120 : m_matrixTemplateDecl(nullptr), m_vectorTemplateDecl(nullptr),
41204121 m_vkIntegralConstantTemplateDecl(nullptr),
41214122 m_vkLiteralTemplateDecl(nullptr),
41224123 m_vkBufferPointerTemplateDecl(nullptr), m_hlslNSDecl(nullptr),
41234124 m_vkNSDecl(nullptr), m_dxNSDecl(nullptr), m_context(nullptr),
4124- m_sema(nullptr), m_hlslStringTypedef(nullptr) {
4125+ m_sema(nullptr), m_hlslStringTypedef(nullptr),
4126+ m_disableHLSLIntrinsics(disableHLSLIntrinsics) {
41254127 memset(m_matrixTypes, 0, sizeof(m_matrixTypes));
41264128 memset(m_matrixShorthandTypes, 0, sizeof(m_matrixShorthandTypes));
41274129 memset(m_vectorTypes, 0, sizeof(m_vectorTypes));
@@ -5133,8 +5135,11 @@ class HLSLExternalSource : public ExternalSemaSource {
51335135 bool IsValidObjectElement(LPCSTR tableName, IntrinsicOp op,
51345136 QualType objectElement);
51355137
5136- static bool checkIfIntrinsicIsAllowed(StringRef intrinsicNameIdentifier)
5138+ bool checkIfIntrinsicIsAllowed(StringRef intrinsicNameIdentifier)
51375139 {
5140+ if (!m_disableHLSLIntrinsics)
5141+ return true;
5142+
51385143 static const std::unordered_set<std::string> allowedHLSLIntrinsics = {
51395144 "Abort",
51405145 "AcceptHitAndEndSearch",
@@ -5220,10 +5225,7 @@ class HLSLExternalSource : public ExternalSemaSource {
52205225 "TraceRay",
52215226 "TraceRayInline",
52225227 "WorldRayDirection",
5223- "WorldRayOrigin",
5224- "WorldToObject",
5225- "WorldToObject3x4",
5226- "WorldToObject4x3"
5228+ "WorldRayOrigin"
52275229 };
52285230
52295231 auto it = allowedHLSLIntrinsics.find(std::string(intrinsicNameIdentifier));
@@ -5237,7 +5239,7 @@ class HLSLExternalSource : public ExternalSemaSource {
52375239 StringRef nameIdentifier,
52385240 size_t argumentCount) {
52395241 // TODO: only check if the flag "devsh-disable-hlsl-intrinsics" is enabled
5240- if (shouldDisableHLSLIntrinsics() && !checkIfIntrinsicIsAllowed(nameIdentifier))
5242+ if (!checkIfIntrinsicIsAllowed(nameIdentifier))
52415243 {
52425244 return IntrinsicDefIter::CreateStart(
52435245 table, tableSize, table + tableSize,
@@ -13560,8 +13562,8 @@ hlsl::TrySubscriptIndexInitialization(clang::Sema *self, clang::Expr *SrcExpr,
1356013562
1356113563/// <summary>Performs HLSL-specific initialization on the specified
1356213564/// context.</summary>
13563- void hlsl::InitializeASTContextForHLSL(ASTContext &context) {
13564- HLSLExternalSource *hlslSource = new HLSLExternalSource();
13565+ void hlsl::InitializeASTContextForHLSL(ASTContext &context, bool ignoreHLSLIntrinsics ) {
13566+ HLSLExternalSource *hlslSource = new HLSLExternalSource(ignoreHLSLIntrinsics );
1356513567 IntrusiveRefCntPtr<ExternalASTSource> externalSource(hlslSource);
1356613568 if (hlslSource->Initialize(context)) {
1356713569 context.setExternalSource(externalSource);
0 commit comments