Przeglądaj źródła

Add RayFlag and HitKind to DxilConstants.h, add HIT_KIND_NONE.

Tex Riddell 7 lat temu
rodzic
commit
433ae70a2e

+ 20 - 0
include/dxc/HLSL/DxilConstants.h

@@ -1072,6 +1072,26 @@ namespace DXIL {
     UseNativeLowPrecision
   };
 
+  // Corresponds to HIT_FLAG_* in HLSL
+  enum class RayFlag : uint8_t {
+    None = 0x00,
+    ForceOpaque = 0x01,
+    ForceNonOpaque = 0x02,
+    AcceptFirstHitAndEndSearch = 0x04,
+    SkipClosestHitShader = 0x08,
+    CullBackFacingTriangles = 0x10,
+    CullFrontFacingTriangles = 0x20,
+    CullOpaque = 0x40,
+    CullNonOpaque = 0x80,
+  };
+
+  // Corresponds to HIT_KIND_* in HLSL
+  enum class HitKind : uint8_t {
+    None = 0x00,
+    TriangleFrontFace = 0xFE,
+    TriangleBackFace = 0xFF,
+  };
+
 
   extern const char* kLegacyLayoutString;
   extern const char* kNewLayoutString;

+ 13 - 12
tools/clang/lib/AST/ASTContextHLSL.cpp

@@ -513,7 +513,7 @@ void hlsl::AddRecordTypeWithHandle(ASTContext& context, _Outptr_ CXXRecordDecl**
 
 // creates a global static constant unsigned integer with value.
 // equivalent to: static const uint name = val;
-static void AddConstInt(clang::ASTContext& context, DeclContext *DC, StringRef name, int val) {
+static void AddConstUInt(clang::ASTContext& context, DeclContext *DC, StringRef name, unsigned val) {
   IdentifierInfo &Id = context.Idents.get(name, tok::TokenKind::identifier);
   QualType type = context.getConstType(context.UnsignedIntTy);
   VarDecl *varDecl = VarDecl::Create(context, DC, NoLoc, NoLoc, &Id, type,
@@ -536,23 +536,24 @@ void hlsl::AddRayFlags(ASTContext& context) {
   curDC->addDecl(rayFlagDecl);
   rayFlagDecl->setImplicit(true);
   // static const uint RAY_FLAG_* = *;
-  AddConstInt(context, curDC, StringRef("RAY_FLAG_NONE"), 0x00);
-  AddConstInt(context, curDC, StringRef("RAY_FLAG_FORCE_OPAQUE"), 0x01);
-  AddConstInt(context, curDC, StringRef("RAY_FLAG_FORCE_NON_OPAQUE"), 0x02);
-  AddConstInt(context, curDC, StringRef("RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH"), 0x04);
-  AddConstInt(context, curDC, StringRef("RAY_FLAG_SKIP_CLOSEST_HIT_SHADER"), 0x08);
-  AddConstInt(context, curDC, StringRef("RAY_FLAG_CULL_BACK_FACING_TRIANGLES"), 0x10);
-  AddConstInt(context, curDC, StringRef("RAY_FLAG_CULL_FRONT_FACING_TRIANGLES"), 0x20);
-  AddConstInt(context, curDC, StringRef("RAY_FLAG_CULL_OPAQUE"), 0x40);
-  AddConstInt(context, curDC, StringRef("RAY_FLAG_CULL_NON_OPAQUE"), 0x80);
+  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);
 }
 
 /// <summary> Adds a constant integers for hit kinds </summary>
 void hlsl::AddHitKinds(ASTContext& context) {
   DeclContext *curDC = context.getTranslationUnitDecl();
   // static const uint HIT_KIND_* = *;
-  AddConstInt(context, curDC, StringRef("HIT_KIND_TRIANGLE_FRONT_FACE"), 0xfe);
-  AddConstInt(context, curDC, StringRef("HIT_KIND_TRIANGLE_BACK_FACE"), 0xff);
+  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);
 }
 
 static

+ 3 - 2
tools/clang/test/HLSL/raytracings.hlsl

@@ -12,14 +12,15 @@ void run() {
     RAY_FLAG_CULL_OPAQUE                     +
     RAY_FLAG_CULL_NON_OPAQUE;
 
-  rayFlags += RAY_FLAG_INVALID;                             /* expected-note@? {{'RAY_FLAG_NONE' declared here}} */ /* expected-error {{use of undeclared identifier 'RAY_FLAG_INVALID'; did you mean 'RAY_FLAG_NONE'?}} */
+  rayFlags += RAY_FLAG_INVALID;                             /* expected-note@? {{'RAY_FLAG_NONE' declared here}} expected-error {{use of undeclared identifier 'RAY_FLAG_INVALID'; did you mean 'RAY_FLAG_NONE'?}} */
 
   int intFlag = RAY_FLAG_CULL_OPAQUE;
 
   int hitKindFlag =
     HIT_KIND_TRIANGLE_FRONT_FACE + HIT_KIND_TRIANGLE_BACK_FACE;
 
-  hitKindFlag += HIT_KIND_INVALID;                          /* expected-error {{use of undeclared identifier 'HIT_KIND_INVALID'}} */
+  hitKindFlag += HIT_KIND_INVALID;                          /* expected-note@? {{'HIT_KIND_NONE' declared here}} expected-error {{use of undeclared identifier 'HIT_KIND_INVALID'; did you mean 'HIT_KIND_NONE'?}} */
+
 
   BuiltInTriangleIntersectionAttributes attr;
   attr.barycentrics = float2(0.3f, 0.4f);