5353#include <bitset>
5454#include <float.h>
5555
56+ std::optional<bool> disableHLSLIntrinsicsGlobalVariableBecauseIDontCare = std::nullopt;
57+
5658enum ArBasicKind {
5759 AR_BASIC_BOOL,
5860 AR_BASIC_LITERAL_FLOAT,
@@ -5133,22 +5135,14 @@ class HLSLExternalSource : public ExternalSemaSource {
51335135
51345136 static bool checkIfIntrinsicIsAllowed(StringRef intrinsicNameIdentifier)
51355137 {
5136- static const std::unordered_set<std::string> forbiddenHLSLIntrinsics = {
5137- "D3DCOLORtoUBYTE4",
5138+ static const std::unordered_set<std::string> allowedHLSLIntrinsics = {
51385139 "Abort",
51395140 "AcceptHitAndEndSearch",
5140- "AddUint64",
51415141 "AllocateRayQuery",
5142- "AllMemoryBarrier",
5143- "AllMemoryBarrierWithGroupSync",
5144- "Append",
5145- "Barrier",
51465142 "CallShader",
5147- "CalculateLevelOfDetail",
5148- "CalculateLevelOfDetailUnclamped",
5149- "CheckAccessFullyMapped",
51505143 "CommitNonOpaqueTriangleHit",
51515144 "CommitProceduralPrimitiveHit",
5145+ "CommittedGeometryIndex",
51525146 "CommittedInstanceContributionToHitGroupIndex",
51535147 "CommittedInstanceID",
51545148 "CommittedInstanceIndex",
@@ -5163,9 +5157,6 @@ class HLSLExternalSource : public ExternalSemaSource {
51635157 "CommittedTriangleFrontFace",
51645158 "CommittedWorldToObject3x4",
51655159 "CommittedWorldToObject4x3",
5166- "Consume",
5167- "Count",
5168- "CreateResourceFromHeap",
51695160 "CandidateGeometryIndex",
51705161 "CandidateInstanceContributionToHitGroupIndex",
51715162 "CandidateInstanceID",
@@ -5182,29 +5173,11 @@ class HLSLExternalSource : public ExternalSemaSource {
51825173 "CandidateType",
51835174 "CandidateWorldToObject3x4",
51845175 "CandidateWorldToObject4x3",
5185- "DispatchMesh",
51865176 "DispatchRaysDimensions",
51875177 "DispatchRaysIndex",
5188- "EvaluateAttributeAtSample",
5189- "EvaluateAttributeCentroid",
5190- "EvaluateAttributeSnapped",
5191- "FinishedCrossGroupSharing",
51925178 "FromRayQuery",
5193- "Gather",
5194- "GatherAlpha",
5195- "GatherBlue",
5196- "GatherCmp",
5197- "GatherCmpAlpha",
5198- "GatherCmpBlue",
5199- "GatherCmpGreen",
5200- "GatherCmpRed",
5201- "GatherGreen",
5202- "GatherRaw",
5203- "GatherRed",
52045179 "GeometryIndex",
5205- "GetAttributeAtVertex",
5206- "GetBufferContents",
5207- "GetDimensions",
5180+ "GetGeometryIndex",
52085181 "GetHitKind",
52095182 "GetInstanceID",
52105183 "GetInstanceIndex",
@@ -5216,258 +5189,45 @@ class HLSLExternalSource : public ExternalSemaSource {
52165189 "GetRayFlags",
52175190 "GetRayTCurrent",
52185191 "GetRayTMin",
5219- "GetRemainingRecursionLevels",
5220- "GetRenderTargetSampleCount",
5221- "GetRenderTargetSamplePosition",
5222- "GetSamplePosition",
52235192 "GetShaderTableIndex",
52245193 "GetWorldRayDirection",
52255194 "GetWorldRayOrigin",
52265195 "GetWorldToObject3x4",
52275196 "GetWorldToObject4x3",
52285197 "HitKind",
52295198 "IgnoreHit",
5230- "IncrementCounter",
52315199 "InstanceID",
52325200 "InstanceIndex",
5233- "InterlockedAdd",
5234- "InterlockedAdd64",
5235- "InterlockedAnd",
5236- "InterlockedAnd64",
5237- "InterlockedCompareExchange",
5238- "InterlockedCompareExchange64",
5239- "InterlockedCompareExchangeFloatBitwise",
5240- "InterlockedCompareStore",
5241- "InterlockedCompareStore64",
5242- "InterlockedCompareStoreFloatBitwise",
5243- "InterlockedExchange",
5244- "InterlockedExchange64",
5245- "InterlockedExchangeFloat",
5246- "InterlockedMax",
5247- "InterlockedMax64",
5248- "InterlockedMin",
5249- "InterlockedMin64",
5250- "InterlockedOr",
5251- "InterlockedOr64",
5252- "InterlockedXor",
5253- "InterlockedXor64",
52545201 "Invoke",
52555202 "IsHit",
52565203 "IsMiss",
52575204 "IsNop",
5258- "IsValid",
5259- "Load",
52605205 "LoadLocalRootTableConstant",
52615206 "MakeMiss",
52625207 "MakeNop",
52635208 "MaybeReorderThread",
5264- "NonUniformResourceIndex",
52655209 "ObjectRayDirection",
52665210 "ObjectRayOrigin",
52675211 "ObjectToWorld",
52685212 "ObjectToWorld3x4",
52695213 "ObjectToWorld4x3",
5270- "OutputComplete",
52715214 "PrimitiveIndex",
52725215 "Proceed",
5273- "Process2DQuadTessFactorsAvg",
5274- "Process2DQuadTessFactorsMax",
5275- "Process2DQuadTessFactorsMin",
5276- "ProcessIsolineTessFactors",
5277- "ProcessQuadTessFactorsAvg",
5278- "ProcessQuadTessFactorsMax",
5279- "ProcessQuadTessFactorsMin",
5280- "ProcessTriTessFactorsAvg",
5281- "ProcessTriTessFactorsMax",
5282- "ProcessTriTessFactorsMin",
5283- "QuadAll",
5284- "QuadAny",
5285- "QuadReadAcrossDiagonal",
5286- "QuadReadAcrossX",
5287- "QuadReadAcrossY",
5288- "QuadReadLaneAt",
5289- "RawBufferLoad",
5290- "RawBufferStore",
52915216 "RayFlags",
52925217 "RayTCurrent",
52935218 "RayTMin",
5294- "ReadClock",
52955219 "ReportHit",
5296- "RestartStrip",
5297- "SetMeshOutputCounts",
5298- "SubpassLoad",
52995220 "TraceRay",
53005221 "TraceRayInline",
53015222 "WorldRayDirection",
53025223 "WorldRayOrigin",
53035224 "WorldToObject",
53045225 "WorldToObject3x4",
5305- "WorldToObject4x3",
5306- "WriteSamplerFeedback",
5307- "WriteSamplerFeedbackBias",
5308- "WriteSamplerFeedbackGrad",
5309- "WriteSamplerFeedbackLevel",
5310- "__builtin_MatVecMul",
5311- "__builtin_MatVecMulAdd",
5312- "__builtin_OuterProductAccumulate",
5313- "__builtin_VectorAccumulate",
5314- "abort",
5315- "abs",
5316- "acos",
5317- "all",
5318- "and",
5319- "any",
5320- "asdouble",
5321- "asfloat",
5322- "asfloat16",
5323- "asin",
5324- "asint",
5325- "asint16",
5326- "asuint",
5327- "asuint16",
5328- "atan",
5329- "atan2",
5330- "ceil",
5331- "clamp",
5332- "clip",
5333- "cos",
5334- "cosh",
5335- "countbits",
5336- "cross",
5337- "ddx",
5338- "ddx_coarse",
5339- "ddx_fine",
5340- "ddy",
5341- "ddy_coarse",
5342- "ddy_fine",
5343- "degrees",
5344- "determinant",
5345- "distance",
5346- "dot",
5347- "dot2add",
5348- "dot4add_i8packed",
5349- "dot4add_u8packed",
5350- "dst",
5351- "exp",
5352- "exp2",
5353- "ext_execution_mode",
5354- "ext_execution_mode_id",
5355- "f16tof32",
5356- "f32tof16",
5357- "faceforward",
5358- "firstbithigh",
5359- "firstbitlow",
5360- "floor",
5361- "fma",
5362- "fmod",
5363- "frac",
5364- "frexp",
5365- "fwidth",
5366- "isfinite",
5367- "isinf",
5368- "isnan",
5369- "isnormal",
5370- "ldexp",
5371- "length",
5372- "lerp",
5373- "lit",
5374- "log",
5375- "log10",
5376- "log2",
5377- "mad",
5378- "max",
5379- "min",
5380- "modf",
5381- "msad4",
5382- "mul",
5383- "normalize",
5384- "or",
5385- "pack_clamp_s8",
5386- "pack_clamp_u8",
5387- "pack_s8",
5388- "pack_u8",
5389- "pow",
5390- "printf",
5391- "radians",
5392- "rcp",
5393- "reflect",
5394- "refract",
5395- "reinterpret_pointer_cast",
5396- "reversebits",
5397- "round",
5398- "rsqrt",
5399- "saturate",
5400- "select",
5401- "sign",
5402- "sin",
5403- "sincos",
5404- "sinh",
5405- "smoothstep",
5406- "source_mark",
5407- "sqrt",
5408- "static_pointer_cast",
5409- "step",
5410- "tan",
5411- "tanh",
5412- "tex1D",
5413- "tex1Dbias",
5414- "tex1Dgrad",
5415- "tex1Dlod",
5416- "tex1Dproj",
5417- "tex2D",
5418- "tex2Dbias",
5419- "tex2Dgrad",
5420- "tex2Dlod",
5421- "tex2Dproj",
5422- "tex3D",
5423- "tex3Dbias",
5424- "tex3Dgrad",
5425- "tex3Dlod",
5426- "tex3Dproj",
5427- "texCUBE",
5428- "texCUBEbias",
5429- "texCUBEgrad",
5430- "texCUBElod",
5431- "texCUBEproj",
5432- "transpose",
5433- "trunc",
5434- "unpack_s8s16",
5435- "unpack_s8s32",
5436- "unpack_u8u16",
5437- "unpack_u8u32",
5438- "WaveActiveAllEqual",
5439- "WaveActiveAllTrue",
5440- "WaveActiveAnyTrue",
5441- "WaveActiveBallot",
5442- "WaveActiveBitAnd",
5443- "WaveActiveBitOr",
5444- "WaveActiveBitXor",
5445- "WaveActiveCountBits",
5446- "WaveActiveMax",
5447- "WaveActiveMin",
5448- "WaveActiveProduct",
5449- "WaveActiveSum",
5450- "WaveGetLaneCount",
5451- "WaveGetLaneIndex",
5452- "WaveIsFirstLane",
5453- "WaveMatch",
5454- "WaveMultiPrefixBitAnd",
5455- "WaveMultiPrefixBitOr",
5456- "WaveMultiPrefixBitXor",
5457- "WaveMultiPrefixCountBits",
5458- "WaveMultiPrefixProduct",
5459- "WaveMultiPrefixSum",
5460- "WavePrefixCountBits",
5461- "WavePrefixProduct",
5462- "WavePrefixSum",
5463- "WaveReadLaneAt",
5464- "WaveReadLaneFirst"
5465-
5226+ "WorldToObject4x3"
54665227 };
54675228
5468- auto it = forbiddenHLSLIntrinsics.find(std::string(intrinsicNameIdentifier));
5469-
5470- return it == forbiddenHLSLIntrinsics.end();
5229+ auto it = allowedHLSLIntrinsics.find(std::string(intrinsicNameIdentifier));
5230+ return it != allowedHLSLIntrinsics.end();
54715231 }
54725232
54735233 // Returns the iterator with the first entry that matches the requirement
@@ -5477,7 +5237,7 @@ class HLSLExternalSource : public ExternalSemaSource {
54775237 StringRef nameIdentifier,
54785238 size_t argumentCount) {
54795239 // TODO: only check if the flag "devsh-disable-hlsl-intrinsics" is enabled
5480- if (!checkIfIntrinsicIsAllowed(nameIdentifier))
5240+ if (shouldDisableHLSLIntrinsics() && !checkIfIntrinsicIsAllowed(nameIdentifier))
54815241 {
54825242 return IntrinsicDefIter::CreateStart(
54835243 table, tableSize, table + tableSize,
0 commit comments