Skip to content

Commit e17caad

Browse files
committed
almost done with the compilerSet
1 parent ffccf14 commit e17caad

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

include/nbl/asset/utils/CCompilerSet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace nbl::asset
1919
, m_GLSLCompiler(core::make_smart_refctd_ptr<CGLSLCompiler>(core::smart_refctd_ptr(sys)))
2020
{}
2121

22-
core::smart_refctd_ptr<ICPUBuffer> compileToSPIRV(core::smart_refctd_ptr<asset::ICPUShader> shader, const IShaderCompiler::SOptions& options);
22+
core::smart_refctd_ptr<ICPUBuffer> compileToSPIRV(const asset::ICPUShader* shader, const IShaderCompiler::SOptions& options);
2323

2424
inline core::smart_refctd_ptr<IShaderCompiler> getShaderCompiler(IShader::E_CONTENT_TYPE contentType) const
2525
{

src/nbl/asset/utils/CCompilerSet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using namespace nbl;
77
using namespace nbl::asset;
88

9-
core::smart_refctd_ptr<ICPUBuffer> CCompilerSet::compileToSPIRV(core::smart_refctd_ptr<asset::ICPUShader> shader, const IShaderCompiler::SOptions& options)
9+
core::smart_refctd_ptr<ICPUBuffer> CCompilerSet::compileToSPIRV(const asset::ICPUShader* shader, const IShaderCompiler::SOptions& options)
1010
{
1111
core::smart_refctd_ptr<ICPUBuffer> outSpirvShader;
1212
if (shader)

src/nbl/asset/utils/CShaderIntrospector.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,29 @@ const CIntrospectionData* CShaderIntrospector::introspect(const ICPUShader* _sha
101101
return m_introspectionCache[std::move(key)].insert({core::smart_refctd_ptr<const ICPUShader>(_shader),std::move(introspection)}).first->second.get();
102102
};
103103

104-
// TODO: Use the compilerSet here to also take care of HLSL
105-
if (_shader->getContentType() == ICPUShader::E_CONTENT_TYPE::ECT_GLSL)
104+
auto begin = reinterpret_cast<const char*>(_shader->getContent()->getPointer());
105+
auto end = begin + _shader->getContent()->getSize();
106+
std::string code(begin, end);
107+
if (_shader->getContentType() != ICPUShader::E_CONTENT_TYPE::ECT_SPIRV)
108+
ICPUShader::insertDefines(code, _params.extraDefines);
109+
110+
// TODO:
111+
core::smart_refctd_ptr<asset::CCompilerSet> compilerSet;
112+
113+
auto compiler = compilerSet->getShaderCompiler(_shader->getContentType());
114+
asset::IShaderCompiler::SOptions commonCompileOptions = {};
115+
commonCompileOptions.logger = nullptr;
116+
commonCompileOptions.includeFinder = compiler->getDefaultIncludeFinder(); // to resolve includes before compilation
117+
commonCompileOptions.stage = _shader->getStage();
118+
commonCompileOptions.sourceIdentifier = _shader->getFilepathHint().c_str();
119+
commonCompileOptions.entryPoint = _params.entryPoint;
120+
commonCompileOptions.genDebugInfo = true;
121+
commonCompileOptions.spirvOptimizer = nullptr; // No need of optimizing for introspection
122+
123+
if (_shader->getContentType() == ICPUShader::E_CONTENT_TYPE::ECT_GLSL || _shader->getContentType() == ICPUShader::E_CONTENT_TYPE::ECT_HLSL)
106124
{
107-
auto begin = reinterpret_cast<const char*>(_shader->getContent()->getPointer());
108-
auto end = begin+_shader->getContent()->getSize();
109-
std::string glsl(begin,end);
110-
ICPUShader::insertDefines(glsl,_params.extraDefines);
111-
auto glslShader_woIncludes = m_glslCompiler->resolveIncludeDirectives(glsl.c_str(), _shader->getStage(), _shader->getFilepathHint().c_str());
112-
auto spvShader = m_glslCompiler->createSPIRVFromGLSL(
113-
reinterpret_cast<const char*>(glslShader_woIncludes->getContent()->getPointer()),
114-
glslShader_woIncludes->getStage(),
115-
_params.entryPoint,
116-
glslShader_woIncludes->getFilepathHint().c_str()
117-
);
118-
if (!spvShader)
119-
return nullptr;
120-
121-
return introspectSPV(spvShader.get());
125+
// TODO: actually use code to create a ICPUShader or change the function signature for "compilerSet"
126+
compilerSet->compileToSPIRV(_shader, commonCompileOptions);
122127
}
123128
else if (_shader->getContentType() == ICPUShader::E_CONTENT_TYPE::ECT_SPIRV)
124129
return introspectSPV(_shader);

src/nbl/video/CVulkanLogicalDevice.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,12 +539,13 @@ class CVulkanLogicalDevice final : public ILogicalDevice
539539

540540
if (cpushader->getContentType() == asset::ICPUShader::E_CONTENT_TYPE::ECT_HLSL)
541541
{
542+
// TODO: actually use code to create a ICPUShader (via non allocating CPUBuffer) or change the function signature for "compilerSet"
542543
// TODO: add specific HLSLCompiler::SOption params
543-
spirv = compilerSet->compileToSPIRV(cpushader, commonCompileOptions);
544+
spirv = compilerSet->compileToSPIRV(cpushader.get(), commonCompileOptions);
544545
}
545546
else if (cpushader->getContentType() == asset::ICPUShader::E_CONTENT_TYPE::ECT_GLSL)
546547
{
547-
spirv = compilerSet->compileToSPIRV(cpushader, commonCompileOptions);
548+
spirv = compilerSet->compileToSPIRV(cpushader.get(), commonCompileOptions);
548549
}
549550
else if (cpushader->getContentType() == asset::ICPUShader::E_CONTENT_TYPE::ECT_SPIRV)
550551
{

0 commit comments

Comments
 (0)