summaryrefslogtreecommitdiffstats
path: root/tools/render-test
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-02-20 12:24:00 -0800
committerGitHub <noreply@github.com>2024-02-20 12:24:00 -0800
commit4d20fd329956ac89408b1628a8291fea01bc9a6d (patch)
tree8e62d9c1ec05142fd25d0b31073fdb56d44691b0 /tools/render-test
parent8e9b61e3bac69dbb37a1451b62302e688a017ced (diff)
Refactor compiler option representations. (#3598)
* Refactor compiler option representation. * Fix binary compatibility. * Add a test for specifying compiler options at link time. * Fix binary compatibility. * Fix binary compatibility. * Fix backward compatibility on matrix layout. * Fix. * Fix. * Fix. * Fix gfx. * Fix gfx. * Fix dynamic dispatch. * Polish.
Diffstat (limited to 'tools/render-test')
-rw-r--r--tools/render-test/options.cpp1
-rw-r--r--tools/render-test/render-test-main.cpp21
-rw-r--r--tools/render-test/slang-support.cpp30
-rw-r--r--tools/render-test/slang-support.h6
4 files changed, 37 insertions, 21 deletions
diff --git a/tools/render-test/options.cpp b/tools/render-test/options.cpp
index 4b62eb60b..1d7c3cc2e 100644
--- a/tools/render-test/options.cpp
+++ b/tools/render-test/options.cpp
@@ -62,7 +62,6 @@ static gfx::DeviceType _toRenderType(Slang::RenderApiType apiType)
{
args.setArgs(argv, argc);
}
-
SLANG_RETURN_ON_FAIL(outOptions.downstreamArgs.stripDownstreamArgs(args, 0, &sink));
CommandLineReader reader(&args, &sink);
diff --git a/tools/render-test/render-test-main.cpp b/tools/render-test/render-test-main.cpp
index 1f2b3a5ae..02c0ea86a 100644
--- a/tools/render-test/render-test-main.cpp
+++ b/tools/render-test/render-test-main.cpp
@@ -153,16 +153,19 @@ protected:
struct AssignValsFromLayoutContext
{
IDevice* device;
+ slang::ISession* slangSession;
ShaderOutputPlan& outputPlan;
slang::ProgramLayout* slangReflection;
IAccelerationStructure* accelerationStructure;
AssignValsFromLayoutContext(
IDevice* device,
+ slang::ISession* slangSession,
ShaderOutputPlan& outputPlan,
slang::ProgramLayout* slangReflection,
IAccelerationStructure* accelerationStructure)
: device(device)
+ , slangSession(slangSession)
, outputPlan(outputPlan)
, slangReflection(slangReflection)
, accelerationStructure(accelerationStructure)
@@ -389,7 +392,8 @@ struct AssignValsFromLayoutContext
slangType = slangTypeLayout->getType();
}
- ComPtr<IShaderObject> shaderObject = device->createShaderObject(slangType);
+ ComPtr<IShaderObject> shaderObject;
+ device->createShaderObject2(slangSession, slangType, ShaderObjectContainerType::None, shaderObject.writeRef());
SLANG_RETURN_ON_FAIL(assign(ShaderCursor(shaderObject), srcVal->contentVal));
dstCursor.setObject(shaderObject);
@@ -478,15 +482,16 @@ struct AssignValsFromLayoutContext
};
SlangResult _assignVarsFromLayout(
- IDevice* device,
- IShaderObject* shaderObject,
+ IDevice* device,
+ slang::ISession* slangSession,
+ IShaderObject* shaderObject,
ShaderInputLayout const& layout,
ShaderOutputPlan& ioOutputPlan,
slang::ProgramLayout* slangReflection,
IAccelerationStructure* accelerationStructure)
{
AssignValsFromLayoutContext context(
- device, ioOutputPlan, slangReflection, accelerationStructure);
+ device, slangSession, ioOutputPlan, slangReflection, accelerationStructure);
ShaderCursor rootCursor = ShaderCursor(shaderObject);
return context.assign(rootCursor, layout.rootVal);
}
@@ -495,6 +500,8 @@ Result RenderTestApp::applyBinding(PipelineType pipelineType, ICommandEncoder* e
{
auto slangReflection = (slang::ProgramLayout*)spGetReflection(
m_compilationOutput.output.getRequestForReflection());
+ ComPtr<slang::ISession> slangSession;
+ m_compilationOutput.output.m_requestForKernels->getSession(slangSession.writeRef());
switch (pipelineType)
{
@@ -504,6 +511,7 @@ Result RenderTestApp::applyBinding(PipelineType pipelineType, ICommandEncoder* e
auto rootObject = computeEncoder->bindPipeline(m_pipelineState);
SLANG_RETURN_ON_FAIL(_assignVarsFromLayout(
m_device,
+ slangSession,
rootObject,
m_compilationOutput.layout,
m_outputPlan,
@@ -517,6 +525,7 @@ Result RenderTestApp::applyBinding(PipelineType pipelineType, ICommandEncoder* e
auto rootObject = renderEncoder->bindPipeline(m_pipelineState);
SLANG_RETURN_ON_FAIL(_assignVarsFromLayout(
m_device,
+ slangSession,
rootObject,
m_compilationOutput.layout,
m_outputPlan,
@@ -541,7 +550,7 @@ SlangResult RenderTestApp::initialize(
// We begin by compiling the shader file and entry points that specified via the options.
//
- SLANG_RETURN_ON_FAIL(ShaderCompilerUtil::compileWithLayout(device->getSlangSession(), options, input, m_compilationOutput));
+ SLANG_RETURN_ON_FAIL(ShaderCompilerUtil::compileWithLayout(device->getSlangSession()->getGlobalSession(), options, input, m_compilationOutput));
m_shaderInputLayout = m_compilationOutput.layout;
// Once the shaders have been compiled we load them via the underlying API.
@@ -641,7 +650,7 @@ Result RenderTestApp::_initializeShaders(
Options::ShaderProgramType shaderType,
const ShaderCompilerUtil::Input& input)
{
- SLANG_RETURN_ON_FAIL(ShaderCompilerUtil::compileWithLayout(device->getSlangSession(), m_options, input, m_compilationOutput));
+ SLANG_RETURN_ON_FAIL(ShaderCompilerUtil::compileWithLayout(device->getSlangSession()->getGlobalSession(), m_options, input, m_compilationOutput));
m_shaderInputLayout = m_compilationOutput.layout;
m_shaderProgram = device->createProgram(m_compilationOutput.output.desc);
return m_shaderProgram ? SLANG_OK : SLANG_FAIL;
diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp
index c598e4ea5..f585abe5b 100644
--- a/tools/render-test/slang-support.cpp
+++ b/tools/render-test/slang-support.cpp
@@ -71,14 +71,19 @@ void ShaderCompilerUtil::Output::reset()
m_extraRequestForReflection = nullptr;
}
-/* static */ SlangResult ShaderCompilerUtil::_compileProgramImpl(slang::ISession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out)
+/* static */ SlangResult ShaderCompilerUtil::_compileProgramImpl(slang::IGlobalSession* globalSession, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out)
{
out.reset();
+ slang::SessionDesc sessionDesc = {};
+ List<slang::PreprocessorMacroDesc> macros;
+ sessionDesc.preprocessorMacroCount = (SlangInt)macros.getCount();
+ sessionDesc.preprocessorMacros = macros.getBuffer();
+
ComPtr<SlangCompileRequest> slangRequest = nullptr;
- session->createCompileRequest(slangRequest.writeRef());
+ globalSession->createCompileRequest(slangRequest.writeRef());
out.m_requestForKernels = slangRequest;
- out.session = session->getGlobalSession();
+ out.session = globalSession;
// Parse all the extra args
{
@@ -104,7 +109,6 @@ void ShaderCompilerUtil::Output::reset()
}
}
}
-
spSetCodeGenTarget(slangRequest, input.target);
spSetTargetProfile(slangRequest, 0, spFindProfile(out.session, input.profile.getBuffer()));
if (options.generateSPIRVDirectly)
@@ -283,11 +287,11 @@ void ShaderCompilerUtil::Output::reset()
return SLANG_OK;
}
-/* static */ SlangResult ShaderCompilerUtil::compileProgram(slang::ISession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out)
+/* static */ SlangResult ShaderCompilerUtil::compileProgram(slang::IGlobalSession* globalSession, 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);
+ return _compileProgramImpl(globalSession, options, input, request, out);
}
else
{
@@ -317,7 +321,7 @@ void ShaderCompilerUtil::Output::reset()
// TODO: we want to pass along a flag to skip codegen...
- SLANG_RETURN_ON_FAIL(_compileProgramImpl(session, options, slangInput, request, slangOutput));
+ SLANG_RETURN_ON_FAIL(_compileProgramImpl(globalSession, options, slangInput, request, slangOutput));
}
// Now we have what we need to be able to do the downstream compile better.
@@ -326,7 +330,7 @@ void ShaderCompilerUtil::Output::reset()
// 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));
+ SLANG_RETURN_ON_FAIL(_compileProgramImpl(globalSession, options, input, request, out));
out.m_extraRequestForReflection = slangOutput.getRequestForReflection();
out.desc.slangGlobalScope = slangOutput.desc.slangGlobalScope;
@@ -361,7 +365,11 @@ void ShaderCompilerUtil::Output::reset()
return SLANG_OK;
}
-/* static */SlangResult ShaderCompilerUtil::compileWithLayout(slang::ISession* session, const Options& options, const ShaderCompilerUtil::Input& input, OutputAndLayout& output)
+/* static */SlangResult ShaderCompilerUtil::compileWithLayout(
+ slang::IGlobalSession* globalSession,
+ const Options& options,
+ const ShaderCompilerUtil::Input& input,
+ OutputAndLayout& output)
{
String sourcePath = options.sourcePath;
auto shaderType = options.shaderType;
@@ -373,7 +381,7 @@ void ShaderCompilerUtil::Output::reset()
{
// Add an include of the prelude
ComPtr<ISlangBlob> prelude;
- session->getGlobalSession()->getLanguagePrelude(input.sourceLanguage, prelude.writeRef());
+ globalSession->getLanguagePrelude(input.sourceLanguage, prelude.writeRef());
String preludeString = StringUtil::getString(prelude);
@@ -498,7 +506,7 @@ void ShaderCompilerUtil::Output::reset()
c.idOverride = conformance.idOverride;
compileRequest.typeConformances.add(c);
}
- return ShaderCompilerUtil::compileProgram(session, options, input, compileRequest, output.output);
+ return ShaderCompilerUtil::compileProgram(globalSession, options, input, compileRequest, output.output);
}
} // renderer_test
diff --git a/tools/render-test/slang-support.h b/tools/render-test/slang-support.h
index 9e06ef77c..6eef93edc 100644
--- a/tools/render-test/slang-support.h
+++ b/tools/render-test/slang-support.h
@@ -93,12 +93,12 @@ struct ShaderCompilerUtil
Slang::String sourcePath;
};
- static SlangResult compileWithLayout(slang::ISession* session, const Options& options, const ShaderCompilerUtil::Input& input, OutputAndLayout& output);
+ static SlangResult compileWithLayout(slang::IGlobalSession* globalSession, const Options& options, const ShaderCompilerUtil::Input& input, OutputAndLayout& output);
static SlangResult readSource(const Slang::String& inSourcePath, Slang::List<char>& outSourceText);
- static SlangResult _compileProgramImpl(slang::ISession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out);
- static SlangResult compileProgram(slang::ISession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out);
+ static SlangResult _compileProgramImpl(slang::IGlobalSession* globalSession, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out);
+ static SlangResult compileProgram(slang::IGlobalSession* globalSession, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out);
};