Skip to content

Commit 42beae3

Browse files
committed
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla
2 parents 0af8baf + 577f3a2 commit 42beae3

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

include/nbl/asset/utils/CHLSLCompiler.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
#include "nbl/asset/utils/ISPIRVOptimizer.h"
99
#include "nbl/asset/utils/IShaderCompiler.h"
1010

11-
class IDxcUtils;
12-
class IDxcCompiler3;
13-
class DxcCompilationResult;
14-
15-
#include <wrl.h>
16-
#include <combaseapi.h>
11+
namespace nbl::asset::hlsl::impl
12+
{
13+
class DXC;
14+
}
1715

1816
namespace nbl::asset
1917
{
@@ -50,13 +48,7 @@ class NBL_API2 CHLSLCompiler final : public IShaderCompiler
5048
void insertIntoStart(std::string& code, std::ostringstream&& ins) const override;
5149
protected:
5250

53-
Microsoft::WRL::ComPtr<IDxcUtils> m_dxcUtils;
54-
Microsoft::WRL::ComPtr<IDxcCompiler3> m_dxcCompiler;
55-
56-
DxcCompilationResult dxcCompile(std::string& source, LPCWSTR* args, uint32_t argCount, const CHLSLCompiler::SOptions& options) const;
57-
58-
IDxcUtils* getDxcUtils() const { return m_dxcUtils.Get(); }
59-
IDxcCompiler3* getDxcCompiler() const { return m_dxcCompiler.Get(); }
51+
std::unique_ptr<nbl::asset::hlsl::impl::DXC> m_dxcCompilerTypes;
6052

6153
static CHLSLCompiler::SOptions option_cast(const IShaderCompiler::SCompilerOptions& options)
6254
{

src/nbl/asset/utils/CHLSLCompiler.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include "nbl/asset/utils/CHLSLCompiler.h"
55
#include "nbl/asset/utils/shadercUtils.h"
66

7+
#include <wrl.h>
8+
#include <combaseapi.h>
9+
710
#include <dxc/dxcapi.h>
811

912
#include <sstream>
@@ -18,6 +21,14 @@ using namespace nbl;
1821
using namespace nbl::asset;
1922
using Microsoft::WRL::ComPtr;
2023

24+
namespace nbl::asset::hlsl::impl
25+
{
26+
struct DXC {
27+
Microsoft::WRL::ComPtr<IDxcUtils> m_dxcUtils;
28+
Microsoft::WRL::ComPtr<IDxcCompiler3> m_dxcCompiler;
29+
};
30+
}
31+
2132
CHLSLCompiler::CHLSLCompiler(core::smart_refctd_ptr<system::ISystem>&& system)
2233
: IShaderCompiler(std::move(system))
2334
{
@@ -29,8 +40,10 @@ CHLSLCompiler::CHLSLCompiler(core::smart_refctd_ptr<system::ISystem>&& system)
2940
res = DxcCreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(compiler.GetAddressOf()));
3041
assert(SUCCEEDED(res));
3142

32-
m_dxcUtils = utils;
33-
m_dxcCompiler = compiler;
43+
m_dxcCompilerTypes = std::unique_ptr<nbl::asset::hlsl::impl::DXC>(new nbl::asset::hlsl::impl::DXC{
44+
utils,
45+
compiler
46+
});
3447
}
3548

3649
static tcpp::IInputStream* getInputStreamInclude(
@@ -88,9 +101,8 @@ class DxcCompilationResult
88101
}
89102
};
90103

91-
DxcCompilationResult CHLSLCompiler::dxcCompile(std::string& source, LPCWSTR* args, uint32_t argCount, const CHLSLCompiler::SOptions& options) const
104+
DxcCompilationResult dxcCompile(const CHLSLCompiler* compiler, nbl::asset::hlsl::impl::DXC* dxc, std::string& source, LPCWSTR* args, uint32_t argCount, const CHLSLCompiler::SOptions& options)
92105
{
93-
auto compiler = this;
94106
if (options.genDebugInfo)
95107
{
96108
std::ostringstream insertion;
@@ -108,7 +120,7 @@ DxcCompilationResult CHLSLCompiler::dxcCompile(std::string& source, LPCWSTR* arg
108120
}
109121

110122
ComPtr<IDxcBlobEncoding> src;
111-
auto res = compiler->getDxcUtils()->CreateBlob(reinterpret_cast<const void*>(source.data()), source.size(), CP_UTF8, &src);
123+
auto res = dxc->m_dxcUtils->CreateBlob(reinterpret_cast<const void*>(source.data()), source.size(), CP_UTF8, &src);
112124
assert(SUCCEEDED(res));
113125

114126
DxcBuffer sourceBuffer;
@@ -117,7 +129,7 @@ DxcCompilationResult CHLSLCompiler::dxcCompile(std::string& source, LPCWSTR* arg
117129
sourceBuffer.Encoding = 0;
118130

119131
ComPtr<IDxcResult> compileResult;
120-
res = compiler->getDxcCompiler()->Compile(&sourceBuffer, args, argCount, nullptr, IID_PPV_ARGS(compileResult.GetAddressOf()));
132+
res = dxc->m_dxcCompiler->Compile(&sourceBuffer, args, argCount, nullptr, IID_PPV_ARGS(compileResult.GetAddressOf()));
121133
// If the compilation failed, this should still be a successful result
122134
assert(SUCCEEDED(res));
123135

@@ -288,7 +300,15 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* cod
288300
const uint32_t nonDebugArgs = 5;
289301
const uint32_t allArgs = nonDebugArgs + 4;
290302

291-
auto compileResult = dxcCompile(newCode, &arguments[0], hlslOptions.genDebugInfo ? allArgs : nonDebugArgs, hlslOptions);
303+
// const CHLSLCompiler* compiler, nbl::asset::hlsl::impl::DXC* compilerTypes, std::string& source, LPCWSTR* args, uint32_t argCount, const CHLSLCompiler::SOptions& options
304+
auto compileResult = dxcCompile(
305+
this,
306+
m_dxcCompilerTypes.get(),
307+
newCode,
308+
&arguments[0],
309+
hlslOptions.genDebugInfo ? allArgs : nonDebugArgs,
310+
hlslOptions
311+
);
292312

293313
if (!compileResult.objectBlob)
294314
{

0 commit comments

Comments
 (0)