Skip to content

Commit e04afc1

Browse files
authored
Merge pull request #463 from Devsh-Graphics-Programming/dxc-ptr
Go back from using unique ptr for DXC
2 parents 8148213 + 10797c9 commit e04afc1

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

include/nbl/asset/utils/CHLSLCompiler.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class NBL_API2 CHLSLCompiler final : public IShaderCompiler
2222
IShader::E_CONTENT_TYPE getCodeContentType() const override { return IShader::E_CONTENT_TYPE::ECT_HLSL; };
2323

2424
CHLSLCompiler(core::smart_refctd_ptr<system::ISystem>&& system);
25+
~CHLSLCompiler();
2526

2627
struct SOptions : IShaderCompiler::SCompilerOptions
2728
{
@@ -48,7 +49,9 @@ class NBL_API2 CHLSLCompiler final : public IShaderCompiler
4849
void insertIntoStart(std::string& code, std::ostringstream&& ins) const override;
4950
protected:
5051

51-
std::unique_ptr<nbl::asset::hlsl::impl::DXC> m_dxcCompilerTypes;
52+
// This can't be a unique_ptr due to it being an undefined type
53+
// when Nabla is used as a lib
54+
nbl::asset::hlsl::impl::DXC* m_dxcCompilerTypes;
5255

5356
static CHLSLCompiler::SOptions option_cast(const IShaderCompiler::SCompilerOptions& options)
5457
{

src/nbl/asset/utils/CHLSLCompiler.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ using Microsoft::WRL::ComPtr;
2424
namespace nbl::asset::hlsl::impl
2525
{
2626
struct DXC {
27-
Microsoft::WRL::ComPtr<IDxcUtils> m_dxcUtils;
28-
Microsoft::WRL::ComPtr<IDxcCompiler3> m_dxcCompiler;
27+
ComPtr<IDxcUtils> m_dxcUtils;
28+
ComPtr<IDxcCompiler3> m_dxcCompiler;
2929
};
3030
}
3131

@@ -40,10 +40,15 @@ CHLSLCompiler::CHLSLCompiler(core::smart_refctd_ptr<system::ISystem>&& system)
4040
res = DxcCreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(compiler.GetAddressOf()));
4141
assert(SUCCEEDED(res));
4242

43-
m_dxcCompilerTypes = std::unique_ptr<nbl::asset::hlsl::impl::DXC>(new nbl::asset::hlsl::impl::DXC{
43+
m_dxcCompilerTypes = new nbl::asset::hlsl::impl::DXC{
4444
utils,
4545
compiler
46-
});
46+
};
47+
}
48+
49+
CHLSLCompiler::~CHLSLCompiler()
50+
{
51+
delete m_dxcCompilerTypes;
4752
}
4853

4954
static tcpp::IInputStream* getInputStreamInclude(
@@ -303,7 +308,7 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* cod
303308
// const CHLSLCompiler* compiler, nbl::asset::hlsl::impl::DXC* compilerTypes, std::string& source, LPCWSTR* args, uint32_t argCount, const CHLSLCompiler::SOptions& options
304309
auto compileResult = dxcCompile(
305310
this,
306-
m_dxcCompilerTypes.get(),
311+
m_dxcCompilerTypes,
307312
newCode,
308313
&arguments[0],
309314
hlslOptions.genDebugInfo ? allArgs : nonDebugArgs,

0 commit comments

Comments
 (0)