summaryrefslogtreecommitdiffstats
path: root/tools/render-test/slang-support.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-12-03 08:23:05 -0800
committerGitHub <noreply@github.com>2020-12-03 08:23:05 -0800
commit44c0a56974b664e50b2cb8cb6f10740b19c4e02f (patch)
treed6141003be376bdb2c0037178b649b6b2aae673e /tools/render-test/slang-support.cpp
parentad5dda9261bae63e32bcb914b109fcb5c92faf25 (diff)
Add shader object parameter binding to renderer_test. (#1622)
* Add shader object parameter binding to renderer_test. * remove multiple-definitions.hlsl * Fix cuda implementation. Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'tools/render-test/slang-support.cpp')
-rw-r--r--tools/render-test/slang-support.cpp60
1 files changed, 56 insertions, 4 deletions
diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp
index 78c730cab..baa745b14 100644
--- a/tools/render-test/slang-support.cpp
+++ b/tools/render-test/slang-support.cpp
@@ -20,7 +20,7 @@ static const char fragmentEntryPointName[] = "fragmentMain";
static const char computeEntryPointName[] = "computeMain";
static const char rtEntryPointName[] = "raygenMain";
-static gfx::StageType _translateStage(SlangStage slangStage)
+gfx::StageType translateStage(SlangStage slangStage)
{
switch(slangStage)
{
@@ -50,12 +50,12 @@ static gfx::StageType _translateStage(SlangStage slangStage)
}
}
-/* static */ SlangResult ShaderCompilerUtil::compileProgram(SlangSession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out)
+/* static */ SlangResult ShaderCompilerUtil::_compileProgramImpl(SlangSession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out)
{
out.reset();
SlangCompileRequest* slangRequest = spCreateCompileRequest(session);
- out.request = slangRequest;
+ out.m_requestForKernels = slangRequest;
out.session = session;
// Parse all the extra args
@@ -215,7 +215,7 @@ static gfx::StageType _translateStage(SlangStage slangStage)
size_t codeSize = 0;
char const* code = (char const*) spGetEntryPointCode(slangRequest, int(ee), &codeSize);
- auto gfxStage = _translateStage(actualEntryPoint.slangStage);
+ auto gfxStage = translateStage(actualEntryPoint.slangStage);
ShaderProgram::KernelDesc kernelDesc;
kernelDesc.stage = gfxStage;
@@ -231,6 +231,58 @@ static gfx::StageType _translateStage(SlangStage slangStage)
return SLANG_OK;
}
+/* static */ SlangResult ShaderCompilerUtil::compileProgram(SlangSession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out)
+{
+ if( input.passThrough == SLANG_PASS_THROUGH_NONE )
+ {
+ return _compileProgramImpl(session, options, input, request, out);
+ }
+ else
+ {
+ bool canUseSlangForPrecompile = false;
+ switch (input.passThrough)
+ {
+ case SLANG_PASS_THROUGH_DXC:
+ case SLANG_PASS_THROUGH_FXC:
+ canUseSlangForPrecompile = true;
+ break;
+ default:
+ break;
+ }
+ // If we are doing a HLSL pass-through compilation, then we can't rely
+ // on the downstream compiler for the reflection information that
+ // will drive all of our parameter binding. As such, we will first
+ // compile with Slang to get reflection information, and then
+ // compile in another pass using the desired downstream compiler
+ // so that we can get the refleciton information we need.
+ //
+ Output slangOutput;
+ if (canUseSlangForPrecompile)
+ {
+ ShaderCompilerUtil::Input slangInput = input;
+ slangInput.sourceLanguage = SLANG_SOURCE_LANGUAGE_SLANG;
+ slangInput.passThrough = SLANG_PASS_THROUGH_NONE;
+ // TODO: we want to pass along a flag to skip codegen...
+
+
+ SLANG_RETURN_ON_FAIL(_compileProgramImpl(session, options, slangInput, request, slangOutput));
+ }
+
+ // Now we have what we need to be able to do the downstream compile better.
+ //
+ // TODO: We should be able to use the output from the Slang compilation
+ // to fill in the actual entry points to be used for this compilation,
+ // so that discovery of entry points via `[shader(...)]` attributes will work.
+ //
+ SLANG_RETURN_ON_FAIL(_compileProgramImpl(session, options, input, request, out));
+
+ out.m_extraRequestForReflection = slangOutput.getRequestForReflection();
+ slangOutput.m_requestForKernels = nullptr;
+
+ return SLANG_OK;
+ }
+}
+
/* static */SlangResult ShaderCompilerUtil::readSource(const String& inSourcePath, List<char>& outSourceText)
{
// Read in the source code