1313#include < regex>
1414#include < iterator>
1515#include < codecvt>
16+ #include < wrl.h>
17+ #include < combaseapi.h>
18+ #include < sstream>
19+ #include < dxc/dxcapi.h>
1620
1721
1822using namespace nbl ;
@@ -31,6 +35,19 @@ struct DXC
3135};
3236}
3337
38+ struct DxcCompilationResult
39+ {
40+ Microsoft::WRL::ComPtr<IDxcBlobEncoding> errorMessages;
41+ Microsoft::WRL::ComPtr<IDxcBlob> objectBlob;
42+ Microsoft::WRL::ComPtr<IDxcResult> compileResult;
43+
44+ std::string GetErrorMessagesString ()
45+ {
46+ return std::string (reinterpret_cast <char *>(errorMessages->GetBufferPointer ()), errorMessages->GetBufferSize ());
47+ }
48+ };
49+
50+
3451CHLSLCompiler::CHLSLCompiler (core::smart_refctd_ptr<system::ISystem>&& system)
3552 : IShaderCompiler(std::move(system))
3653{
@@ -53,7 +70,7 @@ CHLSLCompiler::~CHLSLCompiler()
5370 delete m_dxcCompilerTypes;
5471}
5572
56- CHLSLCompiler::DxcCompilationResult CHLSLCompiler::dxcCompile (std::string& source, LPCWSTR* args, uint32_t argCount, const CHLSLCompiler::SOptions& options) const
73+ CHLSLCompiler::SdxcCompileResult CHLSLCompiler::dxcCompile (std::string& source, LPCWSTR* args, uint32_t argCount, const CHLSLCompiler::SOptions& options) const
5774{
5875 // Append Commandline options into source only if debugInfoFlags will emit source
5976 auto sourceEmittingFlags =
@@ -63,7 +80,7 @@ CHLSLCompiler::DxcCompilationResult CHLSLCompiler::dxcCompile(std::string& sourc
6380 if ((options.debugInfoFlags .value & sourceEmittingFlags) != CHLSLCompiler::E_DEBUG_INFO_FLAGS::EDIF_NONE)
6481 {
6582 std::ostringstream insertion;
66- insertion << " #pragma compile_flags " ;
83+ insertion << " #pragma wave dxc_compile_flags( " ;
6784
6885 std::wstring_convert<std::codecvt_utf8<wchar_t >, wchar_t > conv;
6986 for (uint32_t arg = 0 ; arg < argCount; arg ++)
@@ -72,7 +89,7 @@ CHLSLCompiler::DxcCompilationResult CHLSLCompiler::dxcCompile(std::string& sourc
7289 insertion << str.c_str () << " " ;
7390 }
7491
75- insertion << " \n " ;
92+ insertion << " ) \n " ;
7693 insertIntoStart (source, std::move (insertion));
7794 }
7895 nbl::asset::impl::DXC* dxc = m_dxcCompilerTypes;
@@ -114,7 +131,7 @@ CHLSLCompiler::DxcCompilationResult CHLSLCompiler::dxcCompile(std::string& sourc
114131 else
115132 {
116133 options.preprocessorOptions .logger .log (" DXC Compilation Failed:\n %s" , system::ILogger::ELL_ERROR, errorMessagesString.c_str ());
117- return result;
134+ return { ( uint8_t *) result. objectBlob -> GetBufferPointer (), result. objectBlob -> GetBufferSize () } ;
118135 }
119136
120137 ComPtr<IDxcBlob> resultingBlob;
@@ -123,7 +140,7 @@ CHLSLCompiler::DxcCompilationResult CHLSLCompiler::dxcCompile(std::string& sourc
123140
124141 result.objectBlob = resultingBlob;
125142
126- return result;
143+ return { ( uint8_t *) result. objectBlob -> GetBufferPointer (), result. objectBlob -> GetBufferSize () } ;
127144}
128145
129146
@@ -135,7 +152,7 @@ std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADE
135152 nbl::wave::context context (code.begin (),code.end (),preprocessOptions.sourceIdentifier .data (),{preprocessOptions});
136153 context.add_macro_definition (" __HLSL_VERSION" );
137154
138- // instead of defining extraDefines as "NBL_GLSL_LIMIT_MAX_IMAGE_DIMENSION_1D 32768",
155+ // instead of defining extraDefines as "NBL_GLSL_LIMIT_MAX_IMAGE_DIMENSION_1D 32768",
139156 // now define them as "NBL_GLSL_LIMIT_MAX_IMAGE_DIMENSION_1D=32768"
140157 // to match boost wave syntax
141158 // https://www.boost.org/doc/libs/1_82_0/libs/wave/doc/class_reference_context.html#:~:text=Maintain%20defined%20macros-,add_macro_definition,-bool%20add_macro_definition
@@ -307,13 +324,13 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* cod
307324 if (arg_storage)
308325 delete[] arg_storage;
309326
310- if (!compileResult.objectBlob )
327+ if (!compileResult.begin )
311328 {
312329 return nullptr ;
313330 }
314331
315- auto outSpirv = core::make_smart_refctd_ptr<ICPUBuffer>(compileResult.objectBlob -> GetBufferSize () );
316- memcpy (outSpirv->getPointer (), compileResult.objectBlob -> GetBufferPointer () , compileResult.objectBlob -> GetBufferSize () );
332+ auto outSpirv = core::make_smart_refctd_ptr<ICPUBuffer>(compileResult.size );
333+ memcpy (outSpirv->getPointer (), compileResult.begin , compileResult.size );
317334
318335 // Optimizer step
319336 if (hlslOptions.spirvOptimizer )
0 commit comments