Skip to content

Commit

Permalink
Allow enum cases to be used in attribute arguments. (shader-slang#5478)
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe authored Nov 3, 2024
1 parent f4d5aa7 commit 5f4980a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions source/slang/slang-check-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6602,6 +6602,7 @@ bool SemanticsVisitor::checkInterfaceConformance(
{
if (!isAssociatedTypeDecl(requiredMemberDecl.getDecl()))
continue;
ensureDecl(requiredMemberDecl, DeclCheckState::ReadyForReference);
auto requiredMemberDeclRef = m_astBuilder->getLookupDeclRef(
subTypeConformsToSuperInterfaceWitness,
requiredMemberDecl.getDecl());
Expand All @@ -6623,6 +6624,7 @@ bool SemanticsVisitor::checkInterfaceConformance(
continue;
if (requiredMemberDecl.as<DerivativeRequirementDecl>())
continue;
ensureDecl(requiredMemberDecl, DeclCheckState::ReadyForReference);
auto requiredMemberDeclRef = m_astBuilder->getLookupDeclRef(
subTypeConformsToSuperInterfaceWitness,
requiredMemberDecl.getDecl());
Expand Down
6 changes: 6 additions & 0 deletions source/slang/slang-check-expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2038,6 +2038,12 @@ IntVal* SemanticsVisitor::tryConstantFoldExpr(
}
else if (auto enumRef = declRef.as<EnumCaseDecl>())
{
auto enumTypeDecl = enumRef.getParent().getDecl();
if (enumTypeDecl && !enumTypeDecl->checkState.isBeingChecked())
{
ensureDecl(enumRef.getParent(), DeclCheckState::DefinitionChecked);
}

// The cases in an `enum` declaration can also be used as constant expressions,
if (auto tagExpr = getTagExpr(m_astBuilder, enumRef))
{
Expand Down
18 changes: 18 additions & 0 deletions tests/language-feature/enums/enum-in-binding.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//TEST:SIMPLE(filecheck=CHECK): -target spirv

// CHECK: OpDecorate %g_buffer Binding 2

enum class E {
A,
B,
C
}

[vk::binding(E.C)]
RWStructuredBuffer<float> g_buffer;

[numthreads(1,1,1)]
void main()
{
g_buffer[0] = 1.0f;
}

0 comments on commit 5f4980a

Please sign in to comment.