summaryrefslogtreecommitdiffstats
path: root/tools/render-test
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 /tools/render-test
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.
Diffstat (limited to 'tools/render-test')
-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
5 files changed, 101 insertions, 0 deletions
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;