瀏覽代碼

Support TraceRay and ReportIntersection which has user-define param at front-end.

Xiang Li 7 年之前
父節點
當前提交
bc2e19b771

+ 2 - 0
include/dxc/HlslIntrinsicOp.h

@@ -60,6 +60,8 @@ import hctdb_instrhelp
   IOP_QuadReadAcrossX,
   IOP_QuadReadAcrossX,
   IOP_QuadReadAcrossY,
   IOP_QuadReadAcrossY,
   IOP_QuadReadLaneAt,
   IOP_QuadReadLaneAt,
+  IOP_ReportIntersection,
+  IOP_TraceRay,
   IOP_WaveActiveAllEqual,
   IOP_WaveActiveAllEqual,
   IOP_WaveActiveAllTrue,
   IOP_WaveActiveAllTrue,
   IOP_WaveActiveAnyTrue,
   IOP_WaveActiveAnyTrue,

+ 5 - 1
include/dxc/dxcapi.internal.h

@@ -82,7 +82,11 @@ enum LEGAL_INTRINSIC_COMPTYPES {
   LICOMPTYPE_UINT16 = 28,
   LICOMPTYPE_UINT16 = 28,
   LICOMPTYPE_NUMERIC16_ONLY = 29,
   LICOMPTYPE_NUMERIC16_ONLY = 29,
 
 
-  LICOMPTYPE_COUNT = 30
+  LICOMPTYPE_RAYDESC = 30,
+  LICOMPTYPE_ACCELERATION_STRUCT = 31,
+  LICOMPTYPE_USER_DEFINE_TYPE = 32,
+
+  LICOMPTYPE_COUNT = 33
 };
 };
 
 
 static const BYTE IA_SPECIAL_BASE = 0xf0;
 static const BYTE IA_SPECIAL_BASE = 0xf0;

+ 2 - 0
lib/HLSL/HLModule.cpp

@@ -781,6 +781,8 @@ bool HLModule::IsHLSLObjectType(llvm::Type *Ty) {
     name = name.ltrim("RW");
     name = name.ltrim("RW");
     if (name == "ByteAddressBuffer")
     if (name == "ByteAddressBuffer")
       return true;
       return true;
+    if (name == "RayTracingAccelerationStructure")
+      return true;
 
 
     if (name.startswith("Buffer"))
     if (name.startswith("Buffer"))
       return true;
       return true;

+ 3 - 1
lib/HLSL/HLOperationLower.cpp

@@ -4300,7 +4300,9 @@ IntrinsicLower gLowerTable[static_cast<unsigned>(IntrinsicOp::Num_Intrinsics)] =
     {IntrinsicOp::IOP_QuadReadAcrossDiagonal, TranslateQuadReadAcross, DXIL::OpCode::QuadOp},
     {IntrinsicOp::IOP_QuadReadAcrossDiagonal, TranslateQuadReadAcross, DXIL::OpCode::QuadOp},
     {IntrinsicOp::IOP_QuadReadAcrossX, TranslateQuadReadAcross, DXIL::OpCode::QuadOp},
     {IntrinsicOp::IOP_QuadReadAcrossX, TranslateQuadReadAcross, DXIL::OpCode::QuadOp},
     {IntrinsicOp::IOP_QuadReadAcrossY, TranslateQuadReadAcross, DXIL::OpCode::QuadOp},
     {IntrinsicOp::IOP_QuadReadAcrossY, TranslateQuadReadAcross, DXIL::OpCode::QuadOp},
-    {IntrinsicOp::IOP_QuadReadLaneAt,  TranslateQuadReadLaneAt, DXIL::OpCode::NumOpCodes},
+    {IntrinsicOp::IOP_QuadReadLaneAt,  TranslateQuadReadLaneAt, DXIL::OpCode::NumOpCodes},
+    {IntrinsicOp::IOP_ReportIntersection, EmptyLower, DXIL::OpCode::NumOpCodes},
+    {IntrinsicOp::IOP_TraceRay, EmptyLower, DXIL::OpCode::NumOpCodes},
     {IntrinsicOp::IOP_WaveActiveAllEqual, TranslateWaveAllEqual, DXIL::OpCode::WaveActiveAllEqual},
     {IntrinsicOp::IOP_WaveActiveAllEqual, TranslateWaveAllEqual, DXIL::OpCode::WaveActiveAllEqual},
     {IntrinsicOp::IOP_WaveActiveAllTrue, TranslateWaveA2B, DXIL::OpCode::WaveAllTrue},
     {IntrinsicOp::IOP_WaveActiveAllTrue, TranslateWaveA2B, DXIL::OpCode::WaveAllTrue},
     {IntrinsicOp::IOP_WaveActiveAnyTrue, TranslateWaveA2B, DXIL::OpCode::WaveAnyTrue},
     {IntrinsicOp::IOP_WaveActiveAnyTrue, TranslateWaveA2B, DXIL::OpCode::WaveAnyTrue},

+ 2 - 0
tools/clang/include/clang/Basic/DiagnosticSemaKinds.td

@@ -7661,6 +7661,8 @@ def err_hlsl_intrinsic_template_arg_requires_2018: Error<
 def err_hlsl_intrinsic_template_arg_scalar_vector_16: Error<
 def err_hlsl_intrinsic_template_arg_scalar_vector_16: Error<
    "Explicit template arguments on intrinsic %0 are limited one to scalar or vector type up to 16 bytes in size.">;
    "Explicit template arguments on intrinsic %0 are limited one to scalar or vector type up to 16 bytes in size.">;
 }
 }
+def err_hlsl_no_struct_user_define_type: Error<
+   "User define type intrinsic arg must be struct">;
 def err_hlsl_missing_maxvertexcount_attr: Error<
 def err_hlsl_missing_maxvertexcount_attr: Error<
    "GS entry point must have the maxvertexcount attribute">;
    "GS entry point must have the maxvertexcount attribute">;
 def err_hlsl_missing_patchconstantfunc_attr: Error<
 def err_hlsl_missing_patchconstantfunc_attr: Error<

+ 3 - 0
tools/clang/lib/AST/HlslTypes.cpp

@@ -379,6 +379,9 @@ bool IsHLSLResourceType(clang::QualType type) {
 
 
     if (name == "ConstantBuffer")
     if (name == "ConstantBuffer")
       return true;
       return true;
+
+    if (name == "RayTracingAccelerationStructure")
+      return true;
   }
   }
   return false;
   return false;
 }
 }

+ 3 - 1
tools/clang/lib/CodeGen/CGHLSLMS.cpp

@@ -1077,7 +1077,8 @@ static DxilResource::Kind KeywordToKind(StringRef keyword) {
   isBuffer |= keyword == "RasterizerOrderedBuffer";
   isBuffer |= keyword == "RasterizerOrderedBuffer";
   if (isBuffer)
   if (isBuffer)
     return DxilResource::Kind::TypedBuffer;
     return DxilResource::Kind::TypedBuffer;
-
+  if (keyword == "RayTracingAccelerationStructure")
+    return DxilResource::Kind::RTAccelerationStructure;
   return DxilResource::Kind::Invalid;
   return DxilResource::Kind::Invalid;
 }
 }
 
 
@@ -2109,6 +2110,7 @@ static DxilResourceBase::Class KeywordToClass(const std::string &keyword) {
 
 
   bool isSRV = keyword == "Buffer";
   bool isSRV = keyword == "Buffer";
   isSRV |= keyword == "ByteAddressBuffer";
   isSRV |= keyword == "ByteAddressBuffer";
+  isSRV |= keyword == "RayTracingAccelerationStructure";
   isSRV |= keyword == "StructuredBuffer";
   isSRV |= keyword == "StructuredBuffer";
   isSRV |= keyword == "Texture1D";
   isSRV |= keyword == "Texture1D";
   isSRV |= keyword == "Texture1DArray";
   isSRV |= keyword == "Texture1DArray";

+ 135 - 10
tools/clang/lib/Sema/SemaHLSL.cpp

@@ -180,6 +180,10 @@ enum ArBasicKind {
 
 
   AR_OBJECT_WAVE,
   AR_OBJECT_WAVE,
 
 
+  AR_OBJECT_RAY_DESC,
+  AR_OBJECT_ACCELARATION_STRUCT,
+  AR_OBJECT_USER_DEFINE_TYPE,
+
   AR_BASIC_MAXIMUM_COUNT
   AR_BASIC_MAXIMUM_COUNT
 };
 };
 
 
@@ -438,6 +442,9 @@ const UINT g_uBasicKindProps[] =
 
 
   BPROP_OBJECT,   // AR_OBJECT_WAVE
   BPROP_OBJECT,   // AR_OBJECT_WAVE
 
 
+  LICOMPTYPE_RAYDESC,               // AR_OBJECT_WAVE
+  LICOMPTYPE_ACCELERATION_STRUCT,   // AR_OBJECT_WAVE
+  LICOMPTYPE_USER_DEFINE_TYPE,      // AR_OBJECT_WAVE
   // AR_BASIC_MAXIMUM_COUNT
   // AR_BASIC_MAXIMUM_COUNT
 };
 };
 
 
@@ -1059,6 +1066,24 @@ static const ArBasicKind g_SamplerCT[] =
   AR_BASIC_UNKNOWN
   AR_BASIC_UNKNOWN
 };
 };
 
 
+static const ArBasicKind g_RayDescCT[] =
+{
+  AR_OBJECT_RAY_DESC,
+  AR_BASIC_UNKNOWN
+};
+
+static const ArBasicKind g_AccelarationStructCT[] =
+{
+  AR_OBJECT_ACCELARATION_STRUCT,
+  AR_BASIC_UNKNOWN
+};
+
+static const ArBasicKind g_UDTCT[] =
+{
+  AR_OBJECT_USER_DEFINE_TYPE,
+  AR_BASIC_UNKNOWN
+};
+
 static const ArBasicKind g_StringCT[] =
 static const ArBasicKind g_StringCT[] =
 {
 {
   AR_OBJECT_STRING,
   AR_OBJECT_STRING,
@@ -1147,7 +1172,10 @@ const ArBasicKind* g_LegalIntrinsicCompTypes[] =
   g_Float16CT,          // LICOMPTYPE_FLOAT16
   g_Float16CT,          // LICOMPTYPE_FLOAT16
   g_Int16CT,            // LICOMPTYPE_INT16
   g_Int16CT,            // LICOMPTYPE_INT16
   g_UInt16CT,           // LICOMPTYPE_UINT16
   g_UInt16CT,           // LICOMPTYPE_UINT16
-  g_Numeric16OnlyCT     // LICOMPTYPE_NUMERIC16_ONLY
+  g_Numeric16OnlyCT,    // LICOMPTYPE_NUMERIC16_ONLY
+  g_RayDescCT,          // LICOMPTYPE_RAYDESC
+  g_AccelarationStructCT,   // LICOMPTYPE_ACCELERATION_STRUCT,
+  g_UDTCT,              // LICOMPTYPE_USER_DEFINE_TYPE
 };
 };
 C_ASSERT(ARRAYSIZE(g_LegalIntrinsicCompTypes) == LICOMPTYPE_COUNT);
 C_ASSERT(ARRAYSIZE(g_LegalIntrinsicCompTypes) == LICOMPTYPE_COUNT);
 
 
@@ -1218,7 +1246,9 @@ const ArBasicKind g_ArBasicKindsAsTypes[] =
 
 
   AR_OBJECT_LEGACY_EFFECT,      // Used for all unsupported but ignored legacy effect types
   AR_OBJECT_LEGACY_EFFECT,      // Used for all unsupported but ignored legacy effect types
 
 
-  AR_OBJECT_WAVE
+  AR_OBJECT_WAVE,
+  AR_OBJECT_RAY_DESC,
+  AR_OBJECT_ACCELARATION_STRUCT,
 };
 };
 
 
 // Count of template arguments for basic kind of objects that look like templates (one or more type arguments).
 // Count of template arguments for basic kind of objects that look like templates (one or more type arguments).
@@ -1286,6 +1316,8 @@ const uint8_t g_ArBasicKindsTemplateCount[] =
 
 
   0, // AR_OBJECT_LEGACY_EFFECT   // Used for all unsupported but ignored legacy effect types
   0, // AR_OBJECT_LEGACY_EFFECT   // Used for all unsupported but ignored legacy effect types
   0, // AR_OBJECT_WAVE
   0, // AR_OBJECT_WAVE
+  0, // AR_OBJECT_RAY_DESC,
+  0, // AR_OBJECT_ACCELARATION_STRUCT,
 };
 };
 
 
 C_ASSERT(_countof(g_ArBasicKindsAsTypes) == _countof(g_ArBasicKindsTemplateCount));
 C_ASSERT(_countof(g_ArBasicKindsAsTypes) == _countof(g_ArBasicKindsTemplateCount));
@@ -1362,7 +1394,9 @@ const SubscriptOperatorRecord g_ArBasicKindsSubscripts[] =
   // SPIRV change ends
   // SPIRV change ends
 
 
   { 0, MipsFalse, SampleFalse }, // AR_OBJECT_LEGACY_EFFECT (legacy effect objects)
   { 0, MipsFalse, SampleFalse }, // AR_OBJECT_LEGACY_EFFECT (legacy effect objects)
-  { 0, MipsFalse, SampleFalse }  // AR_OBJECT_WAVE
+  { 0, MipsFalse, SampleFalse },  // AR_OBJECT_WAVE
+  { 0, MipsFalse, SampleFalse },  // AR_OBJECT_RAY_DESC,
+  { 0, MipsFalse, SampleFalse },  // AR_OBJECT_ACCELARATION_STRUCT,
 };
 };
 
 
 C_ASSERT(_countof(g_ArBasicKindsAsTypes) == _countof(g_ArBasicKindsSubscripts));
 C_ASSERT(_countof(g_ArBasicKindsAsTypes) == _countof(g_ArBasicKindsSubscripts));
@@ -1460,7 +1494,10 @@ const char* g_ArBasicTypeNames[] =
   "<internal inner type object>",
   "<internal inner type object>",
 
 
   "deprecated effect object",
   "deprecated effect object",
-  "wave_t"
+  "wave_t",
+  "ray_desc",
+  "RayTracingAccelerationStructure",
+  "UserDefineType"
 };
 };
 
 
 C_ASSERT(_countof(g_ArBasicTypeNames) == AR_BASIC_MAXIMUM_COUNT);
 C_ASSERT(_countof(g_ArBasicTypeNames) == AR_BASIC_MAXIMUM_COUNT);
@@ -1610,7 +1647,7 @@ FunctionDecl *AddHLSLIntrinsicFunction(
     _In_ const HLSL_INTRINSIC *pIntrinsic,
     _In_ const HLSL_INTRINSIC *pIntrinsic,
     _In_count_(functionArgTypeCount) QualType *functionArgQualTypes,
     _In_count_(functionArgTypeCount) QualType *functionArgQualTypes,
     _In_range_(0, g_MaxIntrinsicParamCount - 1) size_t functionArgTypeCount) {
     _In_range_(0, g_MaxIntrinsicParamCount - 1) size_t functionArgTypeCount) {
-  DXASSERT(functionArgTypeCount - 1 < g_MaxIntrinsicParamCount,
+  DXASSERT(functionArgTypeCount - 1 <= g_MaxIntrinsicParamCount,
            "otherwise g_MaxIntrinsicParamCount should be larger");
            "otherwise g_MaxIntrinsicParamCount should be larger");
   DeclContext *currentDeclContext = context.getTranslationUnitDecl();
   DeclContext *currentDeclContext = context.getTranslationUnitDecl();
 
 
@@ -1630,7 +1667,13 @@ FunctionDecl *AddHLSLIntrinsicFunction(
   for (size_t i = 1; i < functionArgTypeCount; i++) {
   for (size_t i = 1; i < functionArgTypeCount; i++) {
     // Change out/inout param to reference type.
     // Change out/inout param to reference type.
     if (paramMods[i-1].isAnyOut()) {
     if (paramMods[i-1].isAnyOut()) {
-      functionArgQualTypes[i] = context.getLValueReferenceType(functionArgQualTypes[i]);
+      QualType Ty = functionArgQualTypes[i];
+      // Aggregate type will be indirect param convert to pointer type.
+      // Don't need add reference for it.
+      if ((!Ty->isArrayType() && !Ty->isRecordType()) ||
+          hlsl::IsHLSLVecMatType(Ty)) {
+        functionArgQualTypes[i] = context.getLValueReferenceType(Ty);
+      }
     }
     }
   }
   }
 
 
@@ -1760,7 +1803,7 @@ public:
   }
   }
 
 
 private:
 private:
-  QualType m_args[g_MaxIntrinsicParamCount];
+  QualType m_args[g_MaxIntrinsicParamCount+1];
   size_t m_argLength;
   size_t m_argLength;
   const HLSL_INTRINSIC* m_intrinsicSource;
   const HLSL_INTRINSIC* m_intrinsicSource;
   mutable FunctionDecl* m_functionDecl;
   mutable FunctionDecl* m_functionDecl;
@@ -2351,6 +2394,58 @@ static void AddHLSLSubscriptAttr(Decl *D, ASTContext &context, HLSubscriptOpcode
   D->addAttr(HLSLIntrinsicAttr::CreateImplicit(context, group, "", static_cast<unsigned>(opcode)));
   D->addAttr(HLSLIntrinsicAttr::CreateImplicit(context, group, "", static_cast<unsigned>(opcode)));
 }
 }
 
 
+static void CreateSimpleField(clang::ASTContext &context,
+                              CXXRecordDecl *recordDecl, StringRef Name,
+                              QualType Ty) {
+  IdentifierInfo &fieldId =
+      context.Idents.get(Name, tok::TokenKind::identifier);
+  TypeSourceInfo *filedTypeSource = context.getTrivialTypeSourceInfo(Ty, NoLoc);
+  const bool MutableFalse = false;
+  const InClassInitStyle initStyle = InClassInitStyle::ICIS_NoInit;
+
+  FieldDecl *fieldDecl =
+      FieldDecl::Create(context, recordDecl, NoLoc, NoLoc, &fieldId, Ty,
+                        filedTypeSource, nullptr, MutableFalse, initStyle);
+  fieldDecl->setAccess(AccessSpecifier::AS_public);
+  fieldDecl->setImplicit(true);
+
+  recordDecl->addDecl(fieldDecl);
+}
+
+// struct RayDesc
+//{
+//    float3 Origin;
+//    float  TMin;
+//    float3 Direction;
+//    float  TMax;
+//};
+static CXXRecordDecl *CreateRayDescStruct(clang::ASTContext &context,
+                                          QualType float3Ty) {
+  DeclContext *currentDeclContext = context.getTranslationUnitDecl();
+  IdentifierInfo &rayDesc =
+      context.Idents.get(StringRef("RayDesc"), tok::TokenKind::identifier);
+  CXXRecordDecl *rayDescDecl = CXXRecordDecl::Create(
+      context, TagTypeKind::TTK_Struct, currentDeclContext, NoLoc, NoLoc,
+      &rayDesc, nullptr, DelayTypeCreationTrue);
+  rayDescDecl->startDefinition();
+
+  QualType floatTy = context.FloatTy;
+  // float3 Origin;
+  CreateSimpleField(context, rayDescDecl, "Origin", float3Ty);
+  // float TMin;
+  CreateSimpleField(context, rayDescDecl, "TMin", floatTy);
+  // float3 Direction;
+  CreateSimpleField(context, rayDescDecl, "Direction", float3Ty);
+  // float  TMax;
+  CreateSimpleField(context, rayDescDecl, "TMax", floatTy);
+
+  rayDescDecl->completeDefinition();
+  // Both declarations need to be present for correct handling.
+  currentDeclContext->addDecl(rayDescDecl);
+  rayDescDecl->setImplicit(true);
+  return rayDescDecl;
+}
+
 //
 //
 // This is similar to clang/Analysis/CallGraph, but the following differences
 // This is similar to clang/Analysis/CallGraph, but the following differences
 // motivate this:
 // motivate this:
@@ -2962,6 +3057,10 @@ private:
       const char* typeName = g_ArBasicTypeNames[kind];
       const char* typeName = g_ArBasicTypeNames[kind];
       uint8_t templateArgCount = g_ArBasicKindsTemplateCount[i];
       uint8_t templateArgCount = g_ArBasicKindsTemplateCount[i];
       CXXRecordDecl* recordDecl = nullptr;
       CXXRecordDecl* recordDecl = nullptr;
+      if (kind == AR_OBJECT_RAY_DESC) {
+        QualType float3Ty = LookupVectorType(HLSLScalarType::HLSLScalarType_float, 3);
+        recordDecl = CreateRayDescStruct(*m_context, float3Ty);
+      } else
       if (templateArgCount == 0)
       if (templateArgCount == 0)
       {
       {
         AddRecordTypeWithHandle(*m_context, &recordDecl, typeName);
         AddRecordTypeWithHandle(*m_context, &recordDecl, typeName);
@@ -3597,7 +3696,9 @@ public:
     case AR_OBJECT_APPEND_STRUCTURED_BUFFER:
     case AR_OBJECT_APPEND_STRUCTURED_BUFFER:
     case AR_OBJECT_CONSUME_STRUCTURED_BUFFER:
     case AR_OBJECT_CONSUME_STRUCTURED_BUFFER:
     case AR_OBJECT_WAVE:
     case AR_OBJECT_WAVE:
-{
+    case AR_OBJECT_ACCELARATION_STRUCT:
+    case AR_OBJECT_RAY_DESC:
+    {
         const ArBasicKind* match = std::find(g_ArBasicKindsAsTypes, &g_ArBasicKindsAsTypes[_countof(g_ArBasicKindsAsTypes)], kind);
         const ArBasicKind* match = std::find(g_ArBasicKindsAsTypes, &g_ArBasicKindsAsTypes[_countof(g_ArBasicKindsAsTypes)], kind);
         DXASSERT(match != &g_ArBasicKindsAsTypes[_countof(g_ArBasicKindsAsTypes)], "otherwise can't find constant in basic kinds");
         DXASSERT(match != &g_ArBasicKindsAsTypes[_countof(g_ArBasicKindsAsTypes)], "otherwise can't find constant in basic kinds");
         size_t index = match - g_ArBasicKindsAsTypes;
         size_t index = match - g_ArBasicKindsAsTypes;
@@ -4928,6 +5029,22 @@ bool HLSLExternalSource::MatchArguments(
     pIntrinsicArg = &pIntrinsic->pArgs[iArg];
     pIntrinsicArg = &pIntrinsic->pArgs[iArg];
     DXASSERT(pIntrinsicArg->uTemplateId != INTRIN_TEMPLATE_VARARGS, "no vararg support");
     DXASSERT(pIntrinsicArg->uTemplateId != INTRIN_TEMPLATE_VARARGS, "no vararg support");
 
 
+    if (pIntrinsicArg->uLegalComponentTypes == LICOMPTYPE_USER_DEFINE_TYPE) {
+      DXASSERT(objectElement.isNull(), "");
+      QualType Ty = pCallArg->getType();
+      // Must be user define type for LICOMPTYPE_USER_DEFINE_TYPE arg.
+      if (!Ty->isRecordType() ||
+          hlsl::IsHLSLVecMatType(Ty) ||
+          hlsl::IsHLSLResourceType(Ty)) {
+        m_sema->Diag(pCallArg->getExprLoc(),
+                     diag::err_hlsl_no_struct_user_define_type);
+        return false;
+      }
+      objectElement = Ty;
+      ++iArg;
+      continue;
+    }
+
     // If we are a type and templateID requires one, this isn't a match.
     // If we are a type and templateID requires one, this isn't a match.
     if (pIntrinsicArg->uTemplateId == INTRIN_TEMPLATE_FROM_TYPE) {
     if (pIntrinsicArg->uTemplateId == INTRIN_TEMPLATE_FROM_TYPE) {
       ++iArg;
       ++iArg;
@@ -5089,6 +5206,9 @@ bool HLSLExternalSource::MatchArguments(
     if (pArgument->uTemplateId == INTRIN_TEMPLATE_FROM_TYPE) {
     if (pArgument->uTemplateId == INTRIN_TEMPLATE_FROM_TYPE) {
       continue; // Already verified that this is available.
       continue; // Already verified that this is available.
     }
     }
+    if (pArgument->uLegalComponentTypes == LICOMPTYPE_USER_DEFINE_TYPE) {
+      continue;
+    }
 
 
     const ArTypeObjectKind *pTT = g_LegalIntrinsicTemplates[pArgument->uLegalTemplates];
     const ArTypeObjectKind *pTT = g_LegalIntrinsicTemplates[pArgument->uLegalTemplates];
     if (AR_TOBJ_UNKNOWN != Template[i]) {
     if (AR_TOBJ_UNKNOWN != Template[i]) {
@@ -5160,6 +5280,7 @@ bool HLSLExternalSource::MatchArguments(
     QualType pNewType;
     QualType pNewType;
     unsigned int quals = 0; // qualifications for this argument
     unsigned int quals = 0; // qualifications for this argument
 
 
+
     // If we have no type, set it to our input type (templatized)
     // If we have no type, set it to our input type (templatized)
     if (pArgument->uTemplateId == INTRIN_TEMPLATE_FROM_TYPE) {
     if (pArgument->uTemplateId == INTRIN_TEMPLATE_FROM_TYPE) {
       // Use the templated input type, but resize it if the
       // Use the templated input type, but resize it if the
@@ -5214,8 +5335,12 @@ bool HLSLExternalSource::MatchArguments(
         }
         }
         pNewType = objectElement;
         pNewType = objectElement;
       }
       }
-    }
-    else {
+    } else if (pArgument->uLegalComponentTypes == LICOMPTYPE_USER_DEFINE_TYPE) {
+      if (objectElement.isNull()) {
+        return false;
+      }
+      pNewType = objectElement;
+    } else {
       ArBasicKind pEltType;
       ArBasicKind pEltType;
 
 
       // ComponentType, if the Id is special then it gets the
       // ComponentType, if the Id is special then it gets the

File diff suppressed because it is too large
+ 151 - 130
tools/clang/lib/Sema/gen_intrin_main_tables_15.h


+ 1 - 1
tools/clang/test/CodeGenHLSL/abs1.hlsl

@@ -2,7 +2,7 @@
 
 
 // CHECK: main
 // CHECK: main
 // After lowering, these would turn into multiple abs calls rather than a 4 x float
 // After lowering, these would turn into multiple abs calls rather than a 4 x float
-// CHECK: call <4 x float> @"dx.hl.op..<4 x float> (i32, <4 x float>)"(i32 60,
+// CHECK: call <4 x float> @"dx.hl.op..<4 x float> (i32, <4 x float>)"(i32 62,
 
 
 float4 main(float4 a : A) : SV_TARGET {
 float4 main(float4 a : A) : SV_TARGET {
   return abs(a*a.yxxx);
   return abs(a*a.yxxx);

+ 22 - 0
tools/clang/test/CodeGenHLSL/quick-test/ray_trace2.hlsl

@@ -0,0 +1,22 @@
+// RUN: %dxc -E main -T lib_6_2 %s | FileCheck %s
+
+//CHECK: User define type intrinsic arg must be struct
+
+RayTracingAccelerationStructure Acc;
+
+uint RayFlags;
+uint InstanceInclusionMask;
+uint RayContributionToHitGroupIndex;
+uint MultiplierForGeometryContributionToHitGroupIndex;
+uint MissShaderIndex;
+
+RayDesc Ray;
+
+
+float4 emit(inout float2 f2 )  {
+  TraceRay(Acc,RayFlags,InstanceInclusionMask,
+           RayContributionToHitGroupIndex,
+           MultiplierForGeometryContributionToHitGroupIndex,MissShaderIndex , Ray, f2);
+
+   return 2.6;
+}

+ 7 - 0
tools/clang/test/CodeGenHLSL/quick-test/ray_trace4.hlsl

@@ -0,0 +1,7 @@
+// RUN: %dxc -E main -T lib_6_2 %s | FileCheck %s
+
+//CHECK: User define type intrinsic arg must be struct
+
+float main(float THit : t, uint HitKind : h, float2 f2 : F) {
+  return ReportIntersection(THit, HitKind, f2);
+}

+ 1 - 1
tools/clang/unittests/HLSL/ExtensionTest.cpp

@@ -735,7 +735,7 @@ TEST_F(ExtensionTest, UnsignedOpcodeIsUnchanged) {
   // changes the test will need to be updated to reflect the new opcode.
   // changes the test will need to be updated to reflect the new opcode.
   VERIFY_IS_TRUE(
   VERIFY_IS_TRUE(
     disassembly.npos !=
     disassembly.npos !=
-    disassembly.find("call i32 @test_unsigned(i32 117, "));
+    disassembly.find("call i32 @test_unsigned(i32 119, "));
 }
 }
 
 
 TEST_F(ExtensionTest, ResourceExtensionIntrinsic) {
 TEST_F(ExtensionTest, ResourceExtensionIntrinsic) {

+ 5 - 0
utils/hct/gen_intrin_main.txt

@@ -267,6 +267,11 @@ $type1 [[]] QuadReadAcrossX(in numeric<> value);
 $type1 [[]] QuadReadAcrossY(in numeric<> value);
 $type1 [[]] QuadReadAcrossY(in numeric<> value);
 $type1 [[]] QuadReadAcrossDiagonal(in numeric<> value);
 $type1 [[]] QuadReadAcrossDiagonal(in numeric<> value);
 
 
+// RayTracing
+void [[]]  TraceRay(in acceleration_struct AccelerationStructure, in uint RayFlags, in uint InstanceInclusionMask, in uint RayContributionToHitGroupIndex, in uint MultiplierForGeometryContributionToHitGroupIndex, in uint MissShaderIndex, in ray_desc Ray, inout udt Payload);
+
+bool [[]]  ReportIntersection(in float THit, in uint HitKind, in udt Attributes);
+
 } namespace
 } namespace
 
 
 namespace StreamMethods {
 namespace StreamMethods {

+ 4 - 1
utils/hct/hctdb.py

@@ -1959,6 +1959,9 @@ class db_hlsl(object):
             "sampler_cube": "LICOMPTYPE_SAMPLERCUBE",
             "sampler_cube": "LICOMPTYPE_SAMPLERCUBE",
             "sampler_cmp": "LICOMPTYPE_SAMPLERCMP",
             "sampler_cmp": "LICOMPTYPE_SAMPLERCMP",
             "sampler": "LICOMPTYPE_SAMPLER",
             "sampler": "LICOMPTYPE_SAMPLER",
+            "ray_desc" : "LICOMPTYPE_RAYDESC",
+            "acceleration_struct" : "LICOMPTYPE_ACCELERATION_STRUCT",
+            "udt" : "LICOMPTYPE_USER_DEFINE_TYPE",
             "void": "LICOMPTYPE_VOID",
             "void": "LICOMPTYPE_VOID",
             "string": "LICOMPTYPE_STRING",
             "string": "LICOMPTYPE_STRING",
             "wave": "LICOMPTYPE_WAVE"}
             "wave": "LICOMPTYPE_WAVE"}
@@ -2085,7 +2088,7 @@ class db_hlsl(object):
                         template_list = "LITEMPLATE_ANY"
                         template_list = "LITEMPLATE_ANY"
                     else:
                     else:
                         base_type = type_name
                         base_type = type_name
-                        if base_type.startswith("sampler") or base_type.startswith("string") or base_type.startswith("wave"):
+                        if base_type.startswith("sampler") or base_type.startswith("string") or base_type.startswith("wave") or base_type.startswith("acceleration_struct") or base_type.startswith("ray_desc"):
                             template_list = "LITEMPLATE_OBJECT"
                             template_list = "LITEMPLATE_OBJECT"
                         else:
                         else:
                             template_list = "LITEMPLATE_SCALAR"
                             template_list = "LITEMPLATE_SCALAR"

Some files were not shown because too many files changed in this diff