Skip to content
4 changes: 4 additions & 0 deletions tools/clang/lib/AST/ASTContextHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,10 @@ void hlsl::AddRaytracingConstants(ASTContext &context) {
AddConstUInt(
context, StringRef("RAYTRACING_PIPELINE_FLAG_SKIP_PROCEDURAL_PRIMITIVES"),
(unsigned)DXIL::RaytracingPipelineFlags::SkipProceduralPrimitives);
AddConstUInt(context, context.getTranslationUnitDecl(),
StringRef("RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS"),
(unsigned)DXIL::RaytracingPipelineFlags::AllowOpacityMicromaps,
ConstructAvailabilityAttribute(context, VT69));
Comment thread
tex3d marked this conversation as resolved.
}

/// <summary> Adds all constants and enums for sampler feedback </summary>
Expand Down
32 changes: 25 additions & 7 deletions tools/clang/lib/Sema/SemaHLSLDiagnoseTU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ std::vector<FunctionDecl *> GetAllExportedFDecls(clang::Sema *self) {
}

void GatherGlobalsWithInitializers(
DeclContext *DC, llvm::SmallVectorImpl<VarDecl *> &GlobalsWithInit) {
DeclContext *DC, llvm::SmallVectorImpl<VarDecl *> &GlobalsWithInit,
llvm::SmallVectorImpl<VarDecl *> &SubObjects) {
for (auto *D : DC->decls()) {
// Skip built-ins and function decls.
if (D->isImplicit() || isa<FunctionDecl>(D))
Expand All @@ -310,11 +311,19 @@ void GatherGlobalsWithInitializers(
// Add if user-defined static or groupshared global with initializer.
if (VD->hasInit() && VD->hasGlobalStorage() &&
(VD->getStorageClass() == SC_Static ||
VD->hasAttr<HLSLGroupSharedAttr>()))
VD->hasAttr<HLSLGroupSharedAttr>())) {
// Place subobjects in a separate collection.
if (const RecordType *RT = VD->getType()->getAs<RecordType>()) {
if (RT->getDecl()->hasAttr<HLSLSubObjectAttr>()) {
SubObjects.push_back(VD);
Comment thread
tex3d marked this conversation as resolved.
continue;
}
}
GlobalsWithInit.push_back(VD);
}
} else if (auto *DC = dyn_cast<DeclContext>(D)) {
// Recurse into DeclContexts like namespace, cbuffer, class/struct, etc.
GatherGlobalsWithInitializers(DC, GlobalsWithInit);
GatherGlobalsWithInitializers(DC, GlobalsWithInit, SubObjects);
}
}
}
Expand Down Expand Up @@ -592,14 +601,24 @@ void hlsl::DiagnoseTranslationUnit(clang::Sema *self) {
hlsl::ShaderModel::GetByName(self->getLangOpts().HLSLProfile.c_str());

llvm::SmallVector<VarDecl *, 16> GlobalsWithInit;
GatherGlobalsWithInitializers(self->getASTContext().getTranslationUnitDecl(),
GlobalsWithInit);

llvm::SmallVector<VarDecl *, 16> SubObjects;
std::set<FunctionDecl *> DiagnosedRecursiveDecls;
llvm::SmallPtrSet<CallExpr *, 16> DiagnosedCalls;
llvm::SmallPtrSet<DeclRefExpr *, 16> DeclAvailabilityChecked;
llvm::SmallSet<SourceLocation, 16> DiagnosedTypeLocs;

GatherGlobalsWithInitializers(self->getASTContext().getTranslationUnitDecl(),
GlobalsWithInit, SubObjects);

if (shaderModel->GetKind() == DXIL::ShaderKind::Library) {
DXIL::NodeLaunchType NodeLaunchTy = DXIL::NodeLaunchType::Invalid;
HLSLReachableDiagnoseVisitor Visitor(
self, shaderModel, shaderModel->GetKind(), NodeLaunchTy, nullptr,
DiagnosedCalls, DeclAvailabilityChecked, DiagnosedTypeLocs);
for (VarDecl *VD : SubObjects)
Visitor.TraverseDecl(VD);
}

// for each FDecl, check for recursion
for (FunctionDecl *FDecl : FDeclsToCheck) {
CallGraphWithRecurseGuard callGraph;
Expand Down Expand Up @@ -705,7 +724,6 @@ void hlsl::DiagnoseTranslationUnit(clang::Sema *self) {
<< PatchConstantFunctionReturnIdx;
}
}

DXIL::ShaderKind EntrySK = shaderModel->GetKind();
DXIL::NodeLaunchType NodeLaunchTy = DXIL::NodeLaunchType::Invalid;
if (EntrySK == DXIL::ShaderKind::Library) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %dxilver 1.9 | %dxc -T lib_6_9 %s | FileCheck %s
// RUN: %dxilver 1.9 | %dxc -T lib_6_9 -ast-dump %s | FileCheck -check-prefix=AST %s
// RUN: %dxilver 1.9 | %dxc -T lib_6_9 -ast-dump-implicit %s | FileCheck -check-prefix=ASTIMPL %s


// CHECK: ; RaytracingPipelineConfig1 rpc = { MaxTraceRecursionDepth = 32, Flags = RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS };

// AST: TranslationUnitDecl 0x{{.+}} <<invalid sloc>> <invalid sloc>
// AST-NEXT: VarDecl 0x{{.+}} rpc 'RaytracingPipelineConfig1' static cinit
// AST-NEXT: InitListExpr 0x{{.+}} 'RaytracingPipelineConfig1'
// AST-NEXT: ImplicitCastExpr 0x{{.+}} 'unsigned int' <IntegralCast>
// AST-NEXT: IntegerLiteral 0x{{.+}} 'literal int' 32
// AST-NEXT: ImplicitCastExpr 0x{{.+}} 'unsigned int' <LValueToRValue>
// AST-NEXT: DeclRefExpr 0x{{.+}} 'const unsigned int' lvalue Var 0x{{.+}} 'RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS' 'const unsigned int'
// ASTIMPL: VarDecl 0x{{.+}} <<invalid sloc>> <invalid sloc> implicit referenced RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS 'const unsigned int' static cinit
// ASTIMPL-NEXT: IntegerLiteral 0x{{.+}} <<invalid sloc>> 'const unsigned int' 1024
// ASTIMPL-NEXT: AvailabilityAttr 0x{{.+}} <<invalid sloc>> Implicit 6.9 0 0 ""

RaytracingPipelineConfig1 rpc = { 32, RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS };
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %dxc -T lib_6_8 -verify %s

// expected-warning@+1{{potential misuse of built-in constant 'RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS' in shader model lib_6_8; introduced in shader model 6.9}}
RaytracingPipelineConfig1 rpc = { 32, RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS };


2 changes: 2 additions & 0 deletions tools/clang/tools/dxcompiler/dxcdisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,8 @@ static const char *FlagToString(DXIL::RaytracingPipelineFlags Flag) {
return "RAYTRACING_PIPELINE_FLAG_SKIP_TRIANGLES";
case DXIL::RaytracingPipelineFlags::SkipProceduralPrimitives:
return "RAYTRACING_PIPELINE_FLAG_SKIP_PROCEDURAL_PRIMITIVES";
case DXIL::RaytracingPipelineFlags::AllowOpacityMicromaps:
return "RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS";
}
return "<invalid RaytracingPipelineFlags>";
}
Expand Down