Skip to content

Commit f861f41

Browse files
committed
Implemented intrinsic disabling logic
1 parent e86cd31 commit f861f41

File tree

1 file changed

+348
-0
lines changed

1 file changed

+348
-0
lines changed

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 348 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5131,12 +5131,360 @@ class HLSLExternalSource : public ExternalSemaSource {
51315131
bool IsValidObjectElement(LPCSTR tableName, IntrinsicOp op,
51325132
QualType objectElement);
51335133

5134+
static bool checkIfIntrinsicIsAllowed(StringRef intrinsicNameIdentifier)
5135+
{
5136+
static const std::unordered_set<std::string> forbiddenHLSLIntrinsics = {
5137+
"D3DCOLORtoUBYTE4",
5138+
"Abort",
5139+
"AcceptHitAndEndSearch",
5140+
"AddUint64",
5141+
"AllocateRayQuery",
5142+
"AllMemoryBarrier",
5143+
"AllMemoryBarrierWithGroupSync",
5144+
"Append",
5145+
"Barrier",
5146+
"CallShader",
5147+
"CalculateLevelOfDetail",
5148+
"CalculateLevelOfDetailUnclamped",
5149+
"CheckAccessFullyMapped",
5150+
"CommitNonOpaqueTriangleHit",
5151+
"CommitProceduralPrimitiveHit",
5152+
"CommittedInstanceContributionToHitGroupIndex",
5153+
"CommittedInstanceID",
5154+
"CommittedInstanceIndex",
5155+
"CommittedObjectRayDirection",
5156+
"CommittedObjectRayOrigin",
5157+
"CommittedObjectToWorld3x4",
5158+
"CommittedObjectToWorld4x3",
5159+
"CommittedPrimitiveIndex",
5160+
"CommittedRayT",
5161+
"CommittedStatus",
5162+
"CommittedTriangleBarycentrics",
5163+
"CommittedTriangleFrontFace",
5164+
"CommittedWorldToObject3x4",
5165+
"CommittedWorldToObject4x3",
5166+
"Consume",
5167+
"Count",
5168+
"CreateResourceFromHeap",
5169+
"CandidateGeometryIndex",
5170+
"CandidateInstanceContributionToHitGroupIndex",
5171+
"CandidateInstanceID",
5172+
"CandidateInstanceIndex",
5173+
"CandidateObjectRayDirection",
5174+
"CandidateObjectRayOrigin",
5175+
"CandidateObjectToWorld3x4",
5176+
"CandidateObjectToWorld4x3",
5177+
"CandidatePrimitiveIndex",
5178+
"CandidateProceduralPrimitiveNonOpaque",
5179+
"CandidateTriangleBarycentrics",
5180+
"CandidateTriangleFrontFace",
5181+
"CandidateTriangleRayT",
5182+
"CandidateType",
5183+
"CandidateWorldToObject3x4",
5184+
"CandidateWorldToObject4x3",
5185+
"DispatchMesh",
5186+
"DispatchRaysDimensions",
5187+
"DispatchRaysIndex",
5188+
"EvaluateAttributeAtSample",
5189+
"EvaluateAttributeCentroid",
5190+
"EvaluateAttributeSnapped",
5191+
"FinishedCrossGroupSharing",
5192+
"FromRayQuery",
5193+
"Gather",
5194+
"GatherAlpha",
5195+
"GatherBlue",
5196+
"GatherCmp",
5197+
"GatherCmpAlpha",
5198+
"GatherCmpBlue",
5199+
"GatherCmpGreen",
5200+
"GatherCmpRed",
5201+
"GatherGreen",
5202+
"GatherRaw",
5203+
"GatherRed",
5204+
"GeometryIndex",
5205+
"GetAttributeAtVertex",
5206+
"GetBufferContents",
5207+
"GetDimensions",
5208+
"GetHitKind",
5209+
"GetInstanceID",
5210+
"GetInstanceIndex",
5211+
"GetObjectRayDirection",
5212+
"GetObjectRayOrigin",
5213+
"GetObjectToWorld3x4",
5214+
"GetObjectToWorld4x3",
5215+
"GetPrimitiveIndex",
5216+
"GetRayFlags",
5217+
"GetRayTCurrent",
5218+
"GetRayTMin",
5219+
"GetRemainingRecursionLevels",
5220+
"GetRenderTargetSampleCount",
5221+
"GetRenderTargetSamplePosition",
5222+
"GetSamplePosition",
5223+
"GetShaderTableIndex",
5224+
"GetWorldRayDirection",
5225+
"GetWorldRayOrigin",
5226+
"GetWorldToObject3x4",
5227+
"GetWorldToObject4x3",
5228+
"HitKind",
5229+
"IgnoreHit",
5230+
"IncrementCounter",
5231+
"InstanceID",
5232+
"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",
5254+
"Invoke",
5255+
"IsHit",
5256+
"IsMiss",
5257+
"IsNop",
5258+
"IsValid",
5259+
"Load",
5260+
"LoadLocalRootTableConstant",
5261+
"MakeMiss",
5262+
"MakeNop",
5263+
"MaybeReorderThread",
5264+
"NonUniformResourceIndex",
5265+
"ObjectRayDirection",
5266+
"ObjectRayOrigin",
5267+
"ObjectToWorld",
5268+
"ObjectToWorld3x4",
5269+
"ObjectToWorld4x3",
5270+
"OutputComplete",
5271+
"PrimitiveIndex",
5272+
"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",
5291+
"RayFlags",
5292+
"RayTCurrent",
5293+
"RayTMin",
5294+
"ReadClock",
5295+
"ReportHit",
5296+
"RestartStrip",
5297+
"SetMeshOutputCounts",
5298+
"SubpassLoad",
5299+
"TraceRay",
5300+
"TraceRayInline",
5301+
"WorldRayDirection",
5302+
"WorldRayOrigin",
5303+
"WorldToObject",
5304+
"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+
5466+
};
5467+
5468+
auto it = forbiddenHLSLIntrinsics.find(std::string(intrinsicNameIdentifier));
5469+
5470+
return it == forbiddenHLSLIntrinsics.end();
5471+
}
5472+
51345473
// Returns the iterator with the first entry that matches the requirement
51355474
IntrinsicDefIter FindIntrinsicByNameAndArgCount(const HLSL_INTRINSIC *table,
51365475
size_t tableSize,
51375476
StringRef typeName,
51385477
StringRef nameIdentifier,
51395478
size_t argumentCount) {
5479+
// TODO: only check if the flag "devsh-disable-hlsl-intrinsics" is enabled
5480+
if (!checkIfIntrinsicIsAllowed(nameIdentifier))
5481+
{
5482+
return IntrinsicDefIter::CreateStart(
5483+
table, tableSize, table + tableSize,
5484+
IntrinsicTableDefIter::CreateStart(m_intrinsicTables, typeName,
5485+
nameIdentifier, argumentCount));
5486+
}
5487+
51405488
// This is implemented by a linear scan for now.
51415489
// We tested binary search on tables, and there was no performance gain on
51425490
// samples probably for the following reasons.

0 commit comments

Comments
 (0)