Skip to content

Commit

Permalink
Allow pointers to existential values.
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe committed Dec 7, 2024
1 parent 0e19fc9 commit 5c5d220
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
12 changes: 9 additions & 3 deletions source/slang/slang-check-expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4066,21 +4066,27 @@ Expr* SemanticsVisitor::MaybeDereference(Expr* inExpr)
for (;;)
{
auto baseType = expr->type;
QualType elementType;
if (auto pointerLikeType = as<PointerLikeType>(baseType))
{
auto elementType = QualType(pointerLikeType->getElementType());
elementType = QualType(pointerLikeType->getElementType());
}
else if (auto ptrType = as<PtrType>(baseType))
{
elementType = QualType(ptrType->getValueType());
}
if (elementType.type)
{
elementType.isLeftValue = baseType.isLeftValue;
elementType.hasReadOnlyOnTarget = baseType.hasReadOnlyOnTarget;
elementType.isWriteOnly = baseType.isWriteOnly;

auto derefExpr = m_astBuilder->create<DerefExpr>();
derefExpr->base = expr;
derefExpr->type = elementType;

expr = derefExpr;
continue;
}

// Default case: just use the expression as-is
return expr;
}
Expand Down
5 changes: 3 additions & 2 deletions source/slang/slang-check-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ bool isManagedType(Type* type)
{
if (auto declRefValueType = as<DeclRefType>(type))
{
if (as<ClassDecl>(declRefValueType->getDeclRef().getDecl()))
auto decl = declRefValueType->getDeclRef().getDecl();
if (as<ClassDecl>(decl))
return true;
if (as<InterfaceDecl>(declRefValueType->getDeclRef().getDecl()))
if (as<InterfaceDecl>(decl) && decl->findModifier<ComInterfaceAttribute>())
return true;
}
return false;
Expand Down
12 changes: 6 additions & 6 deletions tests/spirv/existential-ptr.slang
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -target spirv -emit-spirv-directly -output-using-type
//DISABLED_TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -target wgpu
//DISABLED_TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -target d3d12
//DISABLED_TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -target d3d11
//DISABLED_TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -target metal
//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -emit-spirv-directly -output-using-type
//DISABLED_TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -wgpu
//DISABLED_TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -d3d12
//DISABLED_TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -d3d11
//DISABLED_TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -metal

interface IFoo
{
Expand All @@ -27,7 +27,7 @@ struct Bar : IFoo
uniform IFoo* pFoo;

//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0], stride=4);
RWStructuredBuffer<int> outputBuffer;
RWStructuredBuffer<float> outputBuffer;

[numthreads(1,1,1)]
void computeMain()
Expand Down

0 comments on commit 5c5d220

Please sign in to comment.