summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-ast-base.cpp10
-rw-r--r--source/slang/slang-ast-base.h1
-rw-r--r--source/slang/slang-ast-builder.h5
-rw-r--r--source/slang/slang.cpp2
-rw-r--r--source/slang/slang.natvis3
-rw-r--r--tools/slang-unit-test/unit-test-module-ptr.cpp92
6 files changed, 100 insertions, 13 deletions
diff --git a/source/slang/slang-ast-base.cpp b/source/slang/slang-ast-base.cpp
index a1624fcba..ac18da404 100644
--- a/source/slang/slang-ast-base.cpp
+++ b/source/slang/slang-ast-base.cpp
@@ -23,15 +23,7 @@ void NodeBase::_initDebug(ASTNodeType inAstNodeType, ASTBuilder* inAstBuilder)
}
DeclRefBase* Decl::getDefaultDeclRef()
{
- if (auto astBuilder = getCurrentASTBuilder())
- {
- const Index currentEpoch = astBuilder->getEpoch();
- if (currentEpoch != m_defaultDeclRefEpoch || !m_defaultDeclRef)
- {
- m_defaultDeclRef = astBuilder->getOrCreate<DirectDeclRef>(this);
- m_defaultDeclRefEpoch = currentEpoch;
- }
- }
+ SLANG_ASSERT(m_defaultDeclRef);
return m_defaultDeclRef;
}
diff --git a/source/slang/slang-ast-base.h b/source/slang/slang-ast-base.h
index 2b5de61e8..8c2f7afa7 100644
--- a/source/slang/slang-ast-base.h
+++ b/source/slang/slang-ast-base.h
@@ -793,7 +793,6 @@ public:
private:
SLANG_UNREFLECTED DeclRefBase* m_defaultDeclRef = nullptr;
- SLANG_UNREFLECTED Index m_defaultDeclRefEpoch = -1;
};
class Expr : public SyntaxNode
diff --git a/source/slang/slang-ast-builder.h b/source/slang/slang-ast-builder.h
index bd5c9b4e3..cae380e40 100644
--- a/source/slang/slang-ast-builder.h
+++ b/source/slang/slang-ast-builder.h
@@ -693,7 +693,10 @@ protected:
auto val = (Val*)(node);
val->m_resolvedValEpoch = getEpoch();
}
-
+ else if (node->getClassInfo().isSubClassOf(*ASTClassInfo::getInfo(Decl::kType)))
+ {
+ ((Decl*)node)->m_defaultDeclRef = getOrCreate<DirectDeclRef>((Decl*)node);
+ }
return node;
}
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 38988ca46..5ec199658 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -4598,7 +4598,7 @@ void Module::_processFindDeclsExportSymbolsRec(Decl* decl)
if (_canExportDeclSymbol(decl->astNodeType))
{
// It's a reference to a declaration in another module, so first get the symbol name.
- String mangledName = getMangledName(getASTBuilder(), decl);
+ String mangledName = getMangledName(getCurrentASTBuilder(), decl);
Index index = Index(m_mangledExportPool.add(mangledName));
diff --git a/source/slang/slang.natvis b/source/slang/slang.natvis
index 70b57e339..341a390f2 100644
--- a/source/slang/slang.natvis
+++ b/source/slang/slang.natvis
@@ -426,7 +426,8 @@
<Type Name="Slang::Val" Inheritable="true">
<DisplayString Optional="true" Condition="astNodeType == Slang::ASTNodeType::DeclRefType">DeclRefType#{_debugUID} {*(Val*)(((Slang::DeclRefType*)this)->m_operands.m_buffer[0].values.nodeOperand)}</DisplayString>
<DisplayString Condition="astNodeType == Slang::ASTNodeType::DeclRefType">DeclRefType {*(Val*)(((Slang::DeclRefType*)this)->m_operands.m_buffer[0].values.nodeOperand)}</DisplayString>
- <DisplayString Condition="astNodeType == Slang::ASTNodeType::DirectDeclRef">DirectRef {*(Decl*)m_operands.m_buffer[0].values.nodeOperand}</DisplayString>
+ <DisplayString Optional="true" Condition="astNodeType == Slang::ASTNodeType::DirectDeclRef">DirectRef#{_debugUID} {*(Decl*)m_operands.m_buffer[0].values.nodeOperand}</DisplayString>
+ <DisplayString Condition="astNodeType == Slang::ASTNodeType::DirectDeclRef">DirectRef {*(Decl*)m_operands.m_buffer[0].values.nodeOperand}</DisplayString>
<DisplayString Optional="true">{astNodeType,en} #{_debugUID}</DisplayString>
<DisplayString>{astNodeType,en}</DisplayString>
diff --git a/tools/slang-unit-test/unit-test-module-ptr.cpp b/tools/slang-unit-test/unit-test-module-ptr.cpp
new file mode 100644
index 000000000..1c11b69fb
--- /dev/null
+++ b/tools/slang-unit-test/unit-test-module-ptr.cpp
@@ -0,0 +1,92 @@
+// unit-test-module-ptr.cpp
+
+#include "core/slang-memory-file-system.h"
+#include "slang-com-ptr.h"
+#include "slang.h"
+#include "unit-test/slang-unit-test.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+using namespace Slang;
+
+SLANG_UNIT_TEST(modulePtr)
+{
+ const char* testModuleSource = R"(
+ module test_module;
+
+ public void atomicFunc(__ref Atomic<int> ptr) {
+ ptr.add(1);
+ }
+ )";
+
+ const char* testSource = R"(
+ import "test_module";
+
+ RWStructuredBuffer<Atomic<int>> input0;
+
+ [shader("compute")]
+ [numthreads(1,1,1)]
+ void computeMain(uint3 workGroup : SV_GroupID)
+ {
+ atomicFunc(input0[0]);
+ }
+ )";
+ ComPtr<ISlangMutableFileSystem> memoryFileSystem =
+ ComPtr<ISlangMutableFileSystem>(new Slang::MemoryFileSystem());
+
+ ComPtr<slang::IGlobalSession> globalSession;
+ SLANG_CHECK(slang_createGlobalSession(SLANG_API_VERSION, globalSession.writeRef()) == SLANG_OK);
+ slang::TargetDesc targetDesc = {};
+ targetDesc.format = SLANG_SPIRV;
+ targetDesc.profile = globalSession->findProfile("spirv_1_5");
+ slang::SessionDesc sessionDesc = {};
+ sessionDesc.targetCount = 1;
+ sessionDesc.targets = &targetDesc;
+ sessionDesc.compilerOptionEntryCount = 0;
+ sessionDesc.fileSystem = memoryFileSystem;
+
+ // Precompile test_module to file.
+ {
+ ComPtr<slang::ISession> session;
+ SLANG_CHECK(globalSession->createSession(sessionDesc, session.writeRef()) == SLANG_OK);
+
+ ComPtr<slang::IBlob> diagnosticBlob;
+ auto module = session->loadModuleFromSourceString(
+ "test_module",
+ "test_module.slang",
+ testModuleSource,
+ diagnosticBlob.writeRef());
+ SLANG_CHECK(module != nullptr);
+
+ ComPtr<slang::IBlob> moduleBlob;
+ module->serialize(moduleBlob.writeRef());
+ memoryFileSystem->saveFile(
+ "test_module.slang-module",
+ moduleBlob->getBufferPointer(),
+ moduleBlob->getBufferSize());
+ }
+
+ // compile test.
+ {
+ ComPtr<slang::ISession> session;
+ SLANG_CHECK(globalSession->createSession(sessionDesc, session.writeRef()) == SLANG_OK);
+
+ ComPtr<slang::IBlob> diagnosticBlob;
+ auto module = session->loadModuleFromSourceString(
+ "test",
+ "test.slang",
+ testSource,
+ diagnosticBlob.writeRef());
+ SLANG_CHECK(module != nullptr);
+
+ ComPtr<slang::IComponentType> linkedProgram;
+ module->link(linkedProgram.writeRef());
+
+ ComPtr<slang::IBlob> code;
+
+ linkedProgram->getTargetCode(0, code.writeRef(), diagnosticBlob.writeRef());
+
+ SLANG_CHECK(code->getBufferSize() > 0);
+ }
+}