Skip to content

Commit

Permalink
[ser] General err_hlsl_ser_unsupported diagnostic / formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
simoll committed Feb 25, 2025
1 parent ab7786e commit ba11d4f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 28 deletions.
6 changes: 2 additions & 4 deletions tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -7968,10 +7968,8 @@ def err_hlsl_unsupported_semantic_index: Error<

// SER Change Starts
// Shader Execution Reordering
def err_hlsl_ser_invalid_shader_kind : Error<
"Shader kind '%0' incompatible with shader execution reordering (has to be raygeneration, closesthit or miss)">;
def err_hlsl_reorder_invalid_shader_kind : Error<
"Shader kind '%0' incompatible with MaybeReorderThread intrinsic (only in raygeneration)">;
def err_hlsl_ser_unsupported : Error<
"%0 is unavailable in shader stage '%1' (requires %select{'raygeneration'|'raygeneration', 'closesthit' or 'miss'}2)">;
def err_hlsl_ser_invalid_version : Error<
"Shader execution reordering requires target profile lib_6_9+ (was %0)">;
// SER Change Ends
Expand Down
4 changes: 2 additions & 2 deletions tools/clang/lib/CodeGen/CodeGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
.getConstantArrayType(eltTy, llvm::APInt(32, count),
ArrayType::ArraySizeModifier::Normal, 0)
.getTypePtr();
} else if (hlsl::IsHLSLHitObjectType(T)) {
} else if (hlsl::IsHLSLHitObjectType(T))
return hlsl::dxilutil::GetHLSLHitObjectType(&TheModule);
} else
else
return ConvertRecordDeclType(RT->getDecl());
}
// HLSL Change Ends
Expand Down
17 changes: 9 additions & 8 deletions tools/clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4932,9 +4932,8 @@ class HLSLExternalSource : public ExternalSemaSource {
// Exceptions:
// - Vulkan-specific intrinsics live in the 'vk::' namespace.
// - DirectX-specific intrinsics live in the 'dx::' namespace.
if (isQualified && !isGlobalNamespace && !isVkNamespace && !isDxNamespace) {
if (isQualified && !isGlobalNamespace && !isVkNamespace && !isDxNamespace)
return false;
}

const DeclarationNameInfo declName = ULE->getNameInfo();
IdentifierInfo *idInfo = declName.getName().getAsIdentifierInfo();
Expand Down Expand Up @@ -4999,9 +4998,8 @@ class HLSLExternalSource : public ExternalSemaSource {
NamespaceDecl *nsDecl = m_hlslNSDecl;
if (isVkNamespace)
nsDecl = m_vkNSDecl;
else if (isDxNamespace) {
else if (isDxNamespace)
nsDecl = m_dxNSDecl;
}
DXASSERT(tableName,
"otherwise IDxcIntrinsicTable::GetTableName() failed");
intrinsicFuncDecl =
Expand Down Expand Up @@ -11590,21 +11588,24 @@ void Sema::DiagnoseReachableCallForSER(CallExpr *CE, DXIL::ShaderKind EntrySK,
}

// Return for anything that is not a HitObject intrinsic.
unsigned ErrDiagID = 0;
std::string FeatureStr = "Shader Execution Reordering";
bool OnlySupportedInRG = false;
switch (opCode) {
default:
return;
case hlsl::IntrinsicOp::IOP_DxMaybeReorderThread:
FeatureStr = "dx::MaybeReorderThread";
OnlySupportedInRG = true;
ValidEntryForHitObject &= EntrySK == DXIL::ShaderKind::RayGeneration;
ErrDiagID = diag::err_hlsl_reorder_invalid_shader_kind;
break;
case hlsl::IntrinsicOp::MOP_DxHitObject_MakeNop:
ErrDiagID = diag::err_hlsl_ser_invalid_shader_kind;
break;
}

if (!ValidEntryForHitObject) {
Diag(Loc, ErrDiagID) << ShaderModel::FullNameFromKind(EntrySK);
Diag(Loc, diag::err_hlsl_ser_unsupported)
<< FeatureStr << ShaderModel::FullNameFromKind(EntrySK)
<< !OnlySupportedInRG;
Diag(EntryFD->getLocation(), diag::note_hlsl_entry_defined_here);
}

Expand Down
4 changes: 2 additions & 2 deletions tools/clang/lib/Sema/SemaHLSLDiagnoseTU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ class HLSLDisallowSERDiagnoseVisitor
if (!hlsl::IsHLSLHitObjectType(TL.getType()))
return true;

S.Diag(TL.getLocStart(), diag::err_hlsl_ser_invalid_shader_kind)
<< ShaderModel::FullNameFromKind(EntrySK);
S.Diag(TL.getLocStart(), diag::err_hlsl_ser_unsupported)
<< "dx::HitObject" << ShaderModel::FullNameFromKind(EntrySK) << true;
S.Diag(EntryDecl->getLocation(), diag::note_hlsl_entry_defined_here);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tools/clang/lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10942,7 +10942,7 @@ bool Sema::buildOverloadedCallSet(Scope *S, Expr *Fn,
ULE->getQualifier()->getAsNamespace()->getName() == "dx";

assert((!ULE->getQualifier() || isVkNamespace || isDxNamespace) &&
"non-vk qualified name with ADL");
"non-name qualified name with ADL");
// HLSL Change Ends

// We don't perform ADL for implicit declarations of builtins.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ struct [raypayload] Payload
struct Attribs { float2 barys; };
void CallReorder()
{
// expected-error@+6{{Shader kind 'compute' incompatible with MaybeReorderThread intrinsic (only in raygeneration)}}
// expected-error@+5{{Shader kind 'callable' incompatible with MaybeReorderThread intrinsic (only in raygeneration)}}
// expected-error@+4{{Shader kind 'intersection' incompatible with MaybeReorderThread intrinsic (only in raygeneration)}}
// expected-error@+3{{Shader kind 'anyhit' incompatible with MaybeReorderThread intrinsic (only in raygeneration)}}
// expected-error@+2{{Shader kind 'closesthit' incompatible with MaybeReorderThread intrinsic (only in raygeneration)}}
// expected-error@+1{{Shader kind 'miss' incompatible with MaybeReorderThread intrinsic (only in raygeneration)}}
// expected-error@+6{{dx::MaybeReorderThread is unavailable in shader stage 'compute' (requires 'raygeneration')}}
// expected-error@+5{{dx::MaybeReorderThread is unavailable in shader stage 'callable' (requires 'raygeneration')}}
// expected-error@+4{{dx::MaybeReorderThread is unavailable in shader stage 'intersection' (requires 'raygeneration')}}
// expected-error@+3{{dx::MaybeReorderThread is unavailable in shader stage 'anyhit' (requires 'raygeneration')}}
// expected-error@+2{{dx::MaybeReorderThread is unavailable in shader stage 'closesthit' (requires 'raygeneration')}}
// expected-error@+1{{dx::MaybeReorderThread is unavailable in shader stage 'miss' (requires 'raygeneration')}}
dx::MaybeReorderThread(0,0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ void UseHitObject() {
[shader("compute")]
[numthreads(4,4,4)]
void mainHitCS(uint ix : SV_GroupIndex, uint3 id : SV_GroupThreadID) {
// expected-error@-7{{Shader kind 'compute' incompatible with shader execution reordering (has to be raygeneration, closesthit or miss)}}
// expected-error@-7{{dx::HitObject is unavailable in shader stage 'compute' (requires 'raygeneration', 'closesthit' or 'miss')}}
UseHitObject();
}

// expected-note@+2{{entry function defined here}}
[shader("callable")]
void mainHitCALL(inout Attribs attrs) {
// expected-error@-14{{Shader kind 'callable' incompatible with shader execution reordering (has to be raygeneration, closesthit or miss)}}
// expected-error@-14{{dx::HitObject is unavailable in shader stage 'callable' (requires 'raygeneration', 'closesthit' or 'miss')}}
UseHitObject();
}

// expected-note@+2{{entry function defined here}}
[shader("intersection")]
void mainHitIS() {
// expected-error@-21{{Shader kind 'intersection' incompatible with shader execution reordering (has to be raygeneration, closesthit or miss)}}
// expected-error@-21{{dx::HitObject is unavailable in shader stage 'intersection' (requires 'raygeneration', 'closesthit' or 'miss')}}
UseHitObject();
}

// expected-note@+2{{entry function defined here}}
[shader("anyhit")]
void mainHitAH(inout Payload pld, in Attribs attrs) {
// expected-error@-28{{Shader kind 'anyhit' incompatible with shader execution reordering (has to be raygeneration, closesthit or miss)}}
// expected-error@-28{{dx::HitObject is unavailable in shader stage 'anyhit' (requires 'raygeneration', 'closesthit' or 'miss')}}
UseHitObject();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// expected-note@+1{{entry function defined here}}
float main(RayDesc rayDesc: RAYDESC) : OUT {
// expected-error@+1{{Shader kind 'vertex' incompatible with shader execution reordering (has to be raygeneration, closesthit or miss)}}
// expected-error@+1{{dx::HitObject is unavailable in shader stage 'vertex' (requires 'raygeneration', 'closesthit' or 'miss')}}
dx::HitObject hit;
return 0.f;
}

0 comments on commit ba11d4f

Please sign in to comment.