Skip to content

Commit

Permalink
Avoid adding types to default namespace (#6700)
Browse files Browse the repository at this point in the history
Some of the types that have been added to the vk namespace were being
added to the default namespace when compiling for DXIL. The if
conditions were such that they would fall through to a default case.

The solution is to explicitly add code that we should skip adding those
builtin types when the vk namespace is not defined.

Fixes #6646.
  • Loading branch information
s-perron authored Jun 21, 2024
1 parent 1f8f796 commit 8b18659
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
26 changes: 18 additions & 8 deletions tools/clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3817,29 +3817,41 @@ class HLSLExternalSource : public ExternalSemaSource {
recordDecl = m_ThreadNodeOutputRecordsTemplateDecl->getTemplatedDecl();
}
#ifdef ENABLE_SPIRV_CODEGEN
else if (kind == AR_OBJECT_VK_SPIRV_TYPE && m_vkNSDecl) {
else if (kind == AR_OBJECT_VK_SPIRV_TYPE) {
if (!m_vkNSDecl)
continue;
recordDecl =
DeclareInlineSpirvType(*m_context, m_vkNSDecl, typeName, false);
recordDecl->setImplicit(true);
} else if (kind == AR_OBJECT_VK_SPIRV_OPAQUE_TYPE && m_vkNSDecl) {
} else if (kind == AR_OBJECT_VK_SPIRV_OPAQUE_TYPE) {
if (!m_vkNSDecl)
continue;
recordDecl =
DeclareInlineSpirvType(*m_context, m_vkNSDecl, typeName, true);
recordDecl->setImplicit(true);
} else if (kind == AR_OBJECT_VK_INTEGRAL_CONSTANT && m_vkNSDecl) {
} else if (kind == AR_OBJECT_VK_INTEGRAL_CONSTANT) {
if (!m_vkNSDecl)
continue;
recordDecl =
DeclareVkIntegralConstant(*m_context, m_vkNSDecl, typeName,
&m_vkIntegralConstantTemplateDecl);
recordDecl->setImplicit(true);
} else if (kind == AR_OBJECT_VK_LITERAL && m_vkNSDecl) {
} else if (kind == AR_OBJECT_VK_LITERAL) {
if (!m_vkNSDecl)
continue;
recordDecl = DeclareTemplateTypeWithHandleInDeclContext(
*m_context, m_vkNSDecl, typeName, 1, nullptr);
recordDecl->setImplicit(true);
m_vkLiteralTemplateDecl = recordDecl->getDescribedClassTemplate();
} else if (kind == AR_OBJECT_VK_SPV_INTRINSIC_TYPE && m_vkNSDecl) {
} else if (kind == AR_OBJECT_VK_SPV_INTRINSIC_TYPE) {
if (!m_vkNSDecl)
continue;
recordDecl = DeclareUIntTemplatedTypeWithHandleInDeclContext(
*m_context, m_vkNSDecl, typeName, "id");
recordDecl->setImplicit(true);
} else if (kind == AR_OBJECT_VK_SPV_INTRINSIC_RESULT_ID && m_vkNSDecl) {
} else if (kind == AR_OBJECT_VK_SPV_INTRINSIC_RESULT_ID) {
if (!m_vkNSDecl)
continue;
recordDecl = DeclareTemplateTypeWithHandleInDeclContext(
*m_context, m_vkNSDecl, typeName, 1, nullptr);
recordDecl->setImplicit(true);
Expand Down Expand Up @@ -4505,8 +4517,6 @@ class HLSLExternalSource : public ExternalSemaSource {
int startDepth = (templateArgCount == 0) ? 0 : 1;
CXXRecordDecl *recordDecl = m_objectTypeDecls[i];
if (recordDecl == nullptr) {
DXASSERT(kind == AR_OBJECT_WAVE,
"else objects other than reserved not initialized");
continue;
}

Expand Down
12 changes: 12 additions & 0 deletions tools/clang/test/SemaHLSL/vk.types.in.dxil.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %dxc -T ps_6_0 -E PSMain -fcgl %s -verify

static const integral_constant MyVar; // expected-error{{unknown type name 'integral_constant'}}
static const SpirvType MyVar; // expected-error{{unknown type name 'SpirvType'}}
static const SpirvOpaqueType MyVar; // expected-error{{unknown type name 'SpirvOpaqueType'}}
static const Literal MyVar; // expected-error{{unknown type name 'Literal'}}

float4 PSMain() : SV_TARGET
{
return float4(1.0, 1.0, 1.0, 1.0);
}

0 comments on commit 8b18659

Please sign in to comment.