summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-09-01 13:47:26 -0700
committerGitHub <noreply@github.com>2020-09-01 13:47:26 -0700
commit5c56479c7b742f94ebf4a97d93826b2a5e4f279d (patch)
treefdd348b67d09b7af5603532d4015036bee588062
parent69025ad82238a7402b18d9c566fac1574faef684 (diff)
Support dynamic existential shader parameters in render-test (#1525)
* Support dynamic existential shader parameters in render-test * Fix linux build error. * Fixes. * Fix code review issues. * Fix gcc error. * More fixes. * More fixes.
-rw-r--r--slang.h15
-rw-r--r--source/core/slang-platform.cpp8
-rw-r--r--source/core/slang-platform.h6
-rw-r--r--source/core/slang-shared-library.cpp4
-rw-r--r--source/core/slang-shared-library.h2
-rw-r--r--source/slang/slang.cpp9
-rw-r--r--tools/render-test/cpu-compute-util.cpp52
-rw-r--r--tools/render-test/cpu-compute-util.h5
-rw-r--r--tools/render-test/render-test-main.cpp1
-rw-r--r--tools/render-test/shader-input-layout.cpp30
-rw-r--r--tools/render-test/shader-input-layout.h13
-rw-r--r--tools/slang-test/slang-test-main.cpp2
12 files changed, 135 insertions, 12 deletions
diff --git a/slang.h b/slang.h
index 1b79f97ab..13df1121e 100644
--- a/slang.h
+++ b/slang.h
@@ -890,7 +890,15 @@ extern "C"
@param name The name of the function
@return The function pointer related to the name or nullptr if not found
*/
- virtual SLANG_NO_THROW SlangFuncPtr SLANG_MCALL findFuncByName(char const* name) = 0;
+ inline SlangFuncPtr SLANG_MCALL findFuncByName(char const* name)
+ {
+ return reinterpret_cast<SlangFuncPtr>(findSymbolAddressByName(name));
+ }
+ /** Get a symbol by name. If the library is unloaded will only return nullptr.
+ @param name The name of the symbol
+ @return The pointer related to the name or nullptr if not found
+ */
+ virtual SLANG_NO_THROW void* SLANG_MCALL findSymbolAddressByName(char const* name) = 0;
};
#define SLANG_UUID_ISlangSharedLibrary { 0x9c9d5bc5, 0xeb61, 0x496f,{ 0x80, 0xd7, 0xd1, 0x47, 0xc4, 0xa2, 0x37, 0x30 } };
@@ -3374,6 +3382,11 @@ SLANG_API SlangResult spCompileRequest_getModule(
SlangInt translationUnitIndex,
slang::IModule** outModule);
+/** Get the `ISession` handle behind the `SlangCompileRequest`.
+*/
+SLANG_API SlangResult spCompileRequest_getSession(
+ SlangCompileRequest* request,
+ slang::ISession** outSession);
#endif
/* DEPRECATED DEFINITIONS
diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp
index d02951e0b..10b9b576b 100644
--- a/source/core/slang-platform.cpp
+++ b/source/core/slang-platform.cpp
@@ -128,10 +128,10 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY);
::FreeLibrary((HMODULE)handle);
}
-/* static */SharedLibrary::FuncPtr SharedLibrary::findFuncByName(Handle handle, char const* name)
+/* static */ void* SharedLibrary::findSymbolAddressByName(Handle handle, char const* name)
{
SLANG_ASSERT(handle);
- return (FuncPtr)GetProcAddress((HMODULE)handle, name);
+ return GetProcAddress((HMODULE)handle, name);
}
/* static */void SharedLibrary::appendPlatformFileName(const UnownedStringSlice& name, StringBuilder& dst)
@@ -173,10 +173,10 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY);
dlclose(handle);
}
-/* static */SharedLibrary::FuncPtr SharedLibrary::findFuncByName(Handle handle, char const* name)
+/* static */void* SharedLibrary::findSymbolAddressByName(Handle handle, char const* name)
{
SLANG_ASSERT(handle);
- return (FuncPtr)dlsym((void*)handle, name);
+ return dlsym((void*)handle, name);
}
/* static */void SharedLibrary::appendPlatformFileName(const UnownedStringSlice& name, StringBuilder& dst)
diff --git a/source/core/slang-platform.h b/source/core/slang-platform.h
index 767e83c1d..804e2b773 100644
--- a/source/core/slang-platform.h
+++ b/source/core/slang-platform.h
@@ -93,10 +93,10 @@ namespace Slang
/// @param The valid handle returned from load
static void unload(Handle handle);
- /// Given a shared library handle and a name, return the associated function
- /// Return nullptr if function is not found
+ /// Given a shared library handle and a name, return the associated object
+ /// Return nullptr if object is not found
/// @param The shared library handle as returned by loadPlatformLibrary
- static FuncPtr findFuncByName(Handle handle, char const* name);
+ static void* findSymbolAddressByName(Handle handle, char const* name);
/// Append to the end of dst, the name, with any platform specific additions
/// The input name should be unadorned with any 'lib' prefix or extension
diff --git a/source/core/slang-shared-library.cpp b/source/core/slang-shared-library.cpp
index b09f345c7..746e14e4c 100644
--- a/source/core/slang-shared-library.cpp
+++ b/source/core/slang-shared-library.cpp
@@ -82,9 +82,9 @@ DefaultSharedLibrary::~DefaultSharedLibrary()
}
}
-SlangFuncPtr DefaultSharedLibrary::findFuncByName(char const* name)
+void* DefaultSharedLibrary::findSymbolAddressByName(char const* name)
{
- return SharedLibrary::findFuncByName(m_sharedLibraryHandle, name);
+ return SharedLibrary::findSymbolAddressByName(m_sharedLibraryHandle, name);
}
}
diff --git a/source/core/slang-shared-library.h b/source/core/slang-shared-library.h
index 0b5c5b2d7..c29f16289 100644
--- a/source/core/slang-shared-library.h
+++ b/source/core/slang-shared-library.h
@@ -52,7 +52,7 @@ class DefaultSharedLibrary : public ISlangSharedLibrary, public RefObject
SLANG_REF_OBJECT_IUNKNOWN_ALL
// ISlangSharedLibrary
- virtual SLANG_NO_THROW SlangFuncPtr SLANG_MCALL findFuncByName(char const* name) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW void* SLANG_MCALL findSymbolAddressByName(char const* name) SLANG_OVERRIDE;
/// Ctor.
DefaultSharedLibrary(const SharedLibrary::Handle sharedLibraryHandle):
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index c78ca0a4d..889ac8203 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -3652,6 +3652,15 @@ SLANG_API SlangResult spCompileRequest_getModule(
return SLANG_OK;
}
+SLANG_API SlangResult spCompileRequest_getSession(
+ SlangCompileRequest* request,
+ slang::ISession** outSession)
+{
+ auto session = Slang::asInternal(request)->getLinkage();
+ *outSession = Slang::ComPtr<slang::ISession>(session).detach();
+ return SLANG_OK;
+}
+
SLANG_API SlangResult spCompileRequest_getEntryPoint(
SlangCompileRequest* request,
SlangInt entryPointIndex,
diff --git a/tools/render-test/cpu-compute-util.cpp b/tools/render-test/cpu-compute-util.cpp
index 70536afe9..6e1fc12cf 100644
--- a/tools/render-test/cpu-compute-util.cpp
+++ b/tools/render-test/cpu-compute-util.cpp
@@ -359,6 +359,58 @@ static SlangResult _newTexture(const InputTextureDesc& desc, slang::TypeLayoutRe
return false;
}
+SlangResult CPUComputeUtil::populateRTTIEntries(
+ ShaderCompilerUtil::OutputAndLayout& compilationAndLayout,
+ ISlangSharedLibrary* sharedLib)
+{
+ Slang::ComPtr<slang::ISession> linkage;
+ spCompileRequest_getSession(compilationAndLayout.output.request, linkage.writeRef());
+ auto& inputLayout = compilationAndLayout.layout;
+ for (auto& entry : inputLayout.entries)
+ {
+ for (auto& rtti : entry.rttiEntries)
+ {
+ void* ptrValue = nullptr;
+ switch (rtti.type)
+ {
+ case RTTIDataEntryType::RTTIObject:
+ ptrValue = sharedLib->findSymbolAddressByName(rtti.typeName.getBuffer());
+ break;
+ case RTTIDataEntryType::WitnessTable:
+ {
+ auto reflection = slang::ShaderReflection::get(compilationAndLayout.output.request);
+ auto concreteType = reflection->findTypeByName(rtti.typeName.getBuffer());
+ if (!concreteType)
+ return SLANG_FAIL;
+ auto interfaceType = reflection->findTypeByName(rtti.interfaceName.getBuffer());
+ if (!interfaceType)
+ return SLANG_FAIL;
+ ISlangBlob* outName = nullptr;
+ linkage->getTypeConformanceWitnessMangledName(concreteType, interfaceType, &outName);
+ if (!outName)
+ return SLANG_FAIL;
+ ptrValue = sharedLib->findSymbolAddressByName((char*)outName->getBufferPointer());
+ break;
+ }
+ default:
+ break;
+ }
+ if (rtti.offset >= 0 && rtti.offset + sizeof(ptrValue) <= entry.bufferData.getCount() * sizeof(decltype(entry.bufferData[0])))
+ {
+ memcpy(
+ ((char*)entry.bufferData.getBuffer()) + rtti.offset,
+ &ptrValue,
+ sizeof(ptrValue));
+ }
+ else
+ {
+ return SLANG_FAIL;
+ }
+ }
+ }
+ return SLANG_OK;
+}
+
/* static */SlangResult CPUComputeUtil::calcBindings(const ShaderCompilerUtil::OutputAndLayout& compilationAndLayout, Context& outContext)
{
auto request = compilationAndLayout.output.request;
diff --git a/tools/render-test/cpu-compute-util.h b/tools/render-test/cpu-compute-util.h
index c66650506..01b781ca7 100644
--- a/tools/render-test/cpu-compute-util.h
+++ b/tools/render-test/cpu-compute-util.h
@@ -55,6 +55,11 @@ struct CPUComputeUtil
/// Runs code across run styles and makes sure output buffers match
static SlangResult checkStyleConsistency(ISlangSharedLibrary* sharedLib, const uint32_t dispatchSize[3], const ShaderCompilerUtil::OutputAndLayout& compilationAndLayout);
+ /// Query and fill in the RTTI pointer values in data buffers.
+ static SlangResult populateRTTIEntries(
+ ShaderCompilerUtil::OutputAndLayout& compilationAndLayout,
+ ISlangSharedLibrary* sharedLib);
+
static SlangResult calcBindings(const ShaderCompilerUtil::OutputAndLayout& compilationAndLayout, Context& outContext);
static SlangResult calcExecuteInfo(ExecuteStyle style, ISlangSharedLibrary* sharedLib, const uint32_t dispatchSize[3], const ShaderCompilerUtil::OutputAndLayout& compilationAndLayout, Context& context, ExecuteInfo& out);
diff --git a/tools/render-test/render-test-main.cpp b/tools/render-test/render-test-main.cpp
index 25486c722..42d82edf6 100644
--- a/tools/render-test/render-test-main.cpp
+++ b/tools/render-test/render-test-main.cpp
@@ -650,6 +650,7 @@ static SlangResult _innerMain(Slang::StdWriters* stdWriters, SlangSession* sessi
// calculate binding
CPUComputeUtil::Context context;
+ SLANG_RETURN_ON_FAIL(CPUComputeUtil::populateRTTIEntries(compilationAndLayout, sharedLibrary.get()));
SLANG_RETURN_ON_FAIL(CPUComputeUtil::calcBindings(compilationAndLayout, context));
// Get the execution info from the lib
diff --git a/tools/render-test/shader-input-layout.cpp b/tools/render-test/shader-input-layout.cpp
index 5e487f1ad..edf617f76 100644
--- a/tools/render-test/shader-input-layout.cpp
+++ b/tools/render-test/shader-input-layout.cpp
@@ -398,8 +398,37 @@ namespace renderer_test
parser.Read("=");
parser.Read("[");
+ uint32_t offset = 0;
while (!parser.IsEnd() && !parser.LookAhead("]"))
{
+ RTTIDataEntry rttiEntry;
+ if (parser.LookAhead("rtti"))
+ {
+ parser.ReadToken();
+ parser.Read("(");
+ rttiEntry.type = RTTIDataEntryType::RTTIObject;
+ rttiEntry.typeName = parser.ReadWord();
+ rttiEntry.offset = offset;
+ parser.Read(")");
+ offset += 8;
+ entry.rttiEntries.add(rttiEntry);
+ continue;
+ }
+ else if (parser.LookAhead("witness"))
+ {
+ parser.ReadToken();
+ parser.Read("(");
+ rttiEntry.type = RTTIDataEntryType::WitnessTable;
+ rttiEntry.typeName = parser.ReadWord();
+ parser.Read(",");
+ rttiEntry.interfaceName = parser.ReadWord();
+ rttiEntry.offset = offset;
+ parser.Read(")");
+ offset += 8;
+ entry.rttiEntries.add(rttiEntry);
+ continue;
+ }
+
bool negate = false;
if(parser.NextToken().Type == TokenType::OpSub)
{
@@ -419,6 +448,7 @@ namespace renderer_test
if(negate) floatNum = -floatNum;
entry.bufferData.add(*(unsigned int*)&floatNum);
}
+ offset += 4;
}
parser.Read("]");
}
diff --git a/tools/render-test/shader-input-layout.h b/tools/render-test/shader-input-layout.h
index 4c8d0dfa2..4abbd6fb5 100644
--- a/tools/render-test/shader-input-layout.h
+++ b/tools/render-test/shader-input-layout.h
@@ -63,11 +63,24 @@ struct ArrayDesc
int size = 0;
};
+enum class RTTIDataEntryType
+{
+ RTTIObject, WitnessTable
+};
+struct RTTIDataEntry
+{
+ RTTIDataEntryType type;
+ Slang::String typeName;
+ Slang::String interfaceName;
+ unsigned int offset;
+};
+
class ShaderInputLayoutEntry
{
public:
ShaderInputType type;
Slang::List<unsigned int> bufferData;
+ Slang::List<RTTIDataEntry> rttiEntries;
InputTextureDesc textureDesc;
InputBufferDesc bufferDesc;
InputSamplerDesc samplerDesc;
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp
index b2e2bb55c..3a15c6e61 100644
--- a/tools/slang-test/slang-test-main.cpp
+++ b/tools/slang-test/slang-test-main.cpp
@@ -1576,7 +1576,7 @@ static TestResult runCPPCompilerSharedLibrary(TestContext* context, TestInput& i
typedef int(*TestFunc)(int intValue, const char* textValue, char* outTextValue);
// We could capture output if we passed in a ISlangWriter - but for that to work we'd need a
- TestFunc testFunc = (TestFunc)SharedLibrary::findFuncByName(handle, "test");
+ TestFunc testFunc = (TestFunc)SharedLibrary::findSymbolAddressByName(handle, "test");
if (testFunc)
{
value = testFunc(inValue, inBuffer, buffer);