Skip to content

Commit 206b775

Browse files
authored
[OMM] Add D3D Flag RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS, and run d3dreflect tests (microsoft#7239)
This PR adds a new flag, RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS, according to the spec. It can be used with `RaytracingPipelineConfig1` subobjects. We expect this new flag to be represented in the output. Additionally, d3dreflect tests are run to ensure that when a rayquery object is using the new OMM enablement flags, that the minimum shader model target is 6.9. Fixes microsoft#7190
1 parent 5ff9cbc commit 206b775

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
lines changed

tools/clang/lib/AST/ASTContextHLSL.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,10 @@ void hlsl::AddRaytracingConstants(ASTContext &context) {
699699
AddConstUInt(
700700
context, StringRef("RAYTRACING_PIPELINE_FLAG_SKIP_PROCEDURAL_PRIMITIVES"),
701701
(unsigned)DXIL::RaytracingPipelineFlags::SkipProceduralPrimitives);
702+
AddConstUInt(context, context.getTranslationUnitDecl(),
703+
StringRef("RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS"),
704+
(unsigned)DXIL::RaytracingPipelineFlags::AllowOpacityMicromaps,
705+
ConstructAvailabilityAttribute(context, VT69));
702706
}
703707

704708
/// <summary> Adds all constants and enums for sampler feedback </summary>

tools/clang/lib/Sema/SemaHLSLDiagnoseTU.cpp

+25-7
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ std::vector<FunctionDecl *> GetAllExportedFDecls(clang::Sema *self) {
301301
}
302302

303303
void GatherGlobalsWithInitializers(
304-
DeclContext *DC, llvm::SmallVectorImpl<VarDecl *> &GlobalsWithInit) {
304+
DeclContext *DC, llvm::SmallVectorImpl<VarDecl *> &GlobalsWithInit,
305+
llvm::SmallVectorImpl<VarDecl *> &SubObjects) {
305306
for (auto *D : DC->decls()) {
306307
// Skip built-ins and function decls.
307308
if (D->isImplicit() || isa<FunctionDecl>(D))
@@ -310,11 +311,19 @@ void GatherGlobalsWithInitializers(
310311
// Add if user-defined static or groupshared global with initializer.
311312
if (VD->hasInit() && VD->hasGlobalStorage() &&
312313
(VD->getStorageClass() == SC_Static ||
313-
VD->hasAttr<HLSLGroupSharedAttr>()))
314+
VD->hasAttr<HLSLGroupSharedAttr>())) {
315+
// Place subobjects in a separate collection.
316+
if (const RecordType *RT = VD->getType()->getAs<RecordType>()) {
317+
if (RT->getDecl()->hasAttr<HLSLSubObjectAttr>()) {
318+
SubObjects.push_back(VD);
319+
continue;
320+
}
321+
}
314322
GlobalsWithInit.push_back(VD);
323+
}
315324
} else if (auto *DC = dyn_cast<DeclContext>(D)) {
316325
// Recurse into DeclContexts like namespace, cbuffer, class/struct, etc.
317-
GatherGlobalsWithInitializers(DC, GlobalsWithInit);
326+
GatherGlobalsWithInitializers(DC, GlobalsWithInit, SubObjects);
318327
}
319328
}
320329
}
@@ -592,14 +601,24 @@ void hlsl::DiagnoseTranslationUnit(clang::Sema *self) {
592601
hlsl::ShaderModel::GetByName(self->getLangOpts().HLSLProfile.c_str());
593602

594603
llvm::SmallVector<VarDecl *, 16> GlobalsWithInit;
595-
GatherGlobalsWithInitializers(self->getASTContext().getTranslationUnitDecl(),
596-
GlobalsWithInit);
597-
604+
llvm::SmallVector<VarDecl *, 16> SubObjects;
598605
std::set<FunctionDecl *> DiagnosedRecursiveDecls;
599606
llvm::SmallPtrSet<CallExpr *, 16> DiagnosedCalls;
600607
llvm::SmallPtrSet<DeclRefExpr *, 16> DeclAvailabilityChecked;
601608
llvm::SmallSet<SourceLocation, 16> DiagnosedTypeLocs;
602609

610+
GatherGlobalsWithInitializers(self->getASTContext().getTranslationUnitDecl(),
611+
GlobalsWithInit, SubObjects);
612+
613+
if (shaderModel->GetKind() == DXIL::ShaderKind::Library) {
614+
DXIL::NodeLaunchType NodeLaunchTy = DXIL::NodeLaunchType::Invalid;
615+
HLSLReachableDiagnoseVisitor Visitor(
616+
self, shaderModel, shaderModel->GetKind(), NodeLaunchTy, nullptr,
617+
DiagnosedCalls, DeclAvailabilityChecked, DiagnosedTypeLocs);
618+
for (VarDecl *VD : SubObjects)
619+
Visitor.TraverseDecl(VD);
620+
}
621+
603622
// for each FDecl, check for recursion
604623
for (FunctionDecl *FDecl : FDeclsToCheck) {
605624
CallGraphWithRecurseGuard callGraph;
@@ -705,7 +724,6 @@ void hlsl::DiagnoseTranslationUnit(clang::Sema *self) {
705724
<< PatchConstantFunctionReturnIdx;
706725
}
707726
}
708-
709727
DXIL::ShaderKind EntrySK = shaderModel->GetKind();
710728
DXIL::NodeLaunchType NodeLaunchTy = DXIL::NodeLaunchType::Invalid;
711729
if (EntrySK == DXIL::ShaderKind::Library) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %dxilver 1.9 | %dxc -T lib_6_9 %s | FileCheck %s
2+
// RUN: %dxilver 1.9 | %dxc -T lib_6_9 -ast-dump %s | FileCheck -check-prefix=AST %s
3+
// RUN: %dxilver 1.9 | %dxc -T lib_6_9 -ast-dump-implicit %s | FileCheck -check-prefix=ASTIMPL %s
4+
5+
6+
// CHECK: ; RaytracingPipelineConfig1 rpc = { MaxTraceRecursionDepth = 32, Flags = RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS };
7+
8+
// AST: TranslationUnitDecl 0x{{.+}} <<invalid sloc>> <invalid sloc>
9+
// AST-NEXT: VarDecl 0x{{.+}} rpc 'RaytracingPipelineConfig1' static cinit
10+
// AST-NEXT: InitListExpr 0x{{.+}} 'RaytracingPipelineConfig1'
11+
// AST-NEXT: ImplicitCastExpr 0x{{.+}} 'unsigned int' <IntegralCast>
12+
// AST-NEXT: IntegerLiteral 0x{{.+}} 'literal int' 32
13+
// AST-NEXT: ImplicitCastExpr 0x{{.+}} 'unsigned int' <LValueToRValue>
14+
// AST-NEXT: DeclRefExpr 0x{{.+}} 'const unsigned int' lvalue Var 0x{{.+}} 'RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS' 'const unsigned int'
15+
// ASTIMPL: VarDecl 0x{{.+}} <<invalid sloc>> <invalid sloc> implicit referenced RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS 'const unsigned int' static cinit
16+
// ASTIMPL-NEXT: IntegerLiteral 0x{{.+}} <<invalid sloc>> 'const unsigned int' 1024
17+
// ASTIMPL-NEXT: AvailabilityAttr 0x{{.+}} <<invalid sloc>> Implicit 6.9 0 0 ""
18+
19+
RaytracingPipelineConfig1 rpc = { 32, RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %dxc -T lib_6_8 -verify %s
2+
3+
// 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}}
4+
RaytracingPipelineConfig1 rpc = { 32, RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS };
5+
6+

tools/clang/tools/dxcompiler/dxcdisassembler.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,8 @@ static const char *FlagToString(DXIL::RaytracingPipelineFlags Flag) {
671671
return "RAYTRACING_PIPELINE_FLAG_SKIP_TRIANGLES";
672672
case DXIL::RaytracingPipelineFlags::SkipProceduralPrimitives:
673673
return "RAYTRACING_PIPELINE_FLAG_SKIP_PROCEDURAL_PRIMITIVES";
674+
case DXIL::RaytracingPipelineFlags::AllowOpacityMicromaps:
675+
return "RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS";
674676
}
675677
return "<invalid RaytracingPipelineFlags>";
676678
}

0 commit comments

Comments
 (0)