4
4
#include " nbl/asset/utils/CHLSLCompiler.h"
5
5
#include " nbl/asset/utils/shadercUtils.h"
6
6
7
+ #include < wrl.h>
8
+ #include < combaseapi.h>
9
+
7
10
#include < dxc/dxcapi.h>
8
11
9
12
#include < sstream>
@@ -18,6 +21,14 @@ using namespace nbl;
18
21
using namespace nbl ::asset;
19
22
using Microsoft::WRL::ComPtr;
20
23
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
+
21
32
CHLSLCompiler::CHLSLCompiler (core::smart_refctd_ptr<system::ISystem>&& system)
22
33
: IShaderCompiler(std::move(system))
23
34
{
@@ -29,8 +40,10 @@ CHLSLCompiler::CHLSLCompiler(core::smart_refctd_ptr<system::ISystem>&& system)
29
40
res = DxcCreateInstance (CLSID_DxcCompiler, IID_PPV_ARGS (compiler.GetAddressOf ()));
30
41
assert (SUCCEEDED (res));
31
42
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
+ });
34
47
}
35
48
36
49
static tcpp::IInputStream* getInputStreamInclude (
@@ -88,9 +101,8 @@ class DxcCompilationResult
88
101
}
89
102
};
90
103
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)
92
105
{
93
- auto compiler = this ;
94
106
if (options.genDebugInfo )
95
107
{
96
108
std::ostringstream insertion;
@@ -108,7 +120,7 @@ DxcCompilationResult CHLSLCompiler::dxcCompile(std::string& source, LPCWSTR* arg
108
120
}
109
121
110
122
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);
112
124
assert (SUCCEEDED (res));
113
125
114
126
DxcBuffer sourceBuffer;
@@ -117,7 +129,7 @@ DxcCompilationResult CHLSLCompiler::dxcCompile(std::string& source, LPCWSTR* arg
117
129
sourceBuffer.Encoding = 0 ;
118
130
119
131
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 ()));
121
133
// If the compilation failed, this should still be a successful result
122
134
assert (SUCCEEDED (res));
123
135
@@ -288,7 +300,15 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* cod
288
300
const uint32_t nonDebugArgs = 5 ;
289
301
const uint32_t allArgs = nonDebugArgs + 4 ;
290
302
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
+ );
292
312
293
313
if (!compileResult.objectBlob )
294
314
{
0 commit comments