@@ -36,11 +36,11 @@ CHLSLCompiler::~CHLSLCompiler()
36
36
m_dxcCompiler->Release ();
37
37
}
38
38
39
- CHLSLCompiler::DxcCompilationResult CHLSLCompiler::dxcCompile (asset::ICPUShader* source, LPCWSTR* args, uint32_t argCount, const SOptions& options) const
39
+ CHLSLCompiler::DxcCompilationResult CHLSLCompiler::dxcCompile (const std::string& source, LPCWSTR* args, uint32_t argCount, const SOptions& options) const
40
40
{
41
41
DxcBuffer sourceBuffer;
42
- sourceBuffer.Ptr = source-> getContent ()-> getPointer ();
43
- sourceBuffer.Size = source-> getContent ()-> getSize ();
42
+ sourceBuffer.Ptr = source. data ();
43
+ sourceBuffer.Size = source. size ();
44
44
sourceBuffer.Encoding = 0 ;
45
45
46
46
IDxcResult* compileResult;
@@ -63,7 +63,7 @@ CHLSLCompiler::DxcCompilationResult CHLSLCompiler::dxcCompile(asset::ICPUShader*
63
63
64
64
if (!SUCCEEDED (compilationStatus))
65
65
{
66
- options.logger .log (result.GetErrorMessagesString (), system::ILogger::ELL_ERROR);
66
+ options.preprocessorOptions . logger .log (result.GetErrorMessagesString (), system::ILogger::ELL_ERROR);
67
67
return result;
68
68
}
69
69
@@ -82,33 +82,40 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* cod
82
82
83
83
if (!code)
84
84
{
85
- options .preprocessorOptions .logger .log (" code is nullptr" , system::ILogger::ELL_ERROR);
85
+ hlslOptions .preprocessorOptions .logger .log (" code is nullptr" , system::ILogger::ELL_ERROR);
86
86
return nullptr ;
87
87
}
88
88
89
- core::smart_refctd_ptr<asset::ICPUShader> includesResolved;
90
- if (hlslOptions.includeFinder != nullptr )
91
- {
92
- includesResolved = resolveIncludeDirectives (code, hlslOptions.stage , hlslOptions.sourceIdentifier .data (), hlslOptions.maxSelfInclusionCount , hlslOptions.logger );
93
- if (includesResolved)
94
- {
95
- code = reinterpret_cast <const char *>(includesResolved->getContent ()->getPointer ());
96
- }
97
- }
89
+ auto newCode = preprocessShader (code, hlslOptions.stage , hlslOptions.preprocessorOptions );
98
90
99
91
LPCWSTR arguments[] = {
100
92
// These will always be present
101
93
L" -spirv" ,
102
94
L" -HLSL2021" ,
103
95
104
96
// These are debug only
105
- L" -DPARTI" ,
106
- L" -DBOY"
97
+ L" -Qembed_debug"
107
98
};
99
+ if (hlslOptions.genDebugInfo )
100
+ {
101
+ std::ostringstream insertion;
102
+ insertion << " // commandline compiler options : " ;
103
+
104
+ std::wstring_convert<std::codecvt_utf8<wchar_t >, wchar_t > conv;
105
+ for (auto arg : arguments)
106
+ {
107
+ auto str = conv.to_bytes (arg);
108
+ insertion << str.c_str () << " " ;
109
+ }
110
+
111
+ insertion << " \n " ;
112
+ insertIntoStart (newCode, std::move (insertion));
113
+ }
114
+
108
115
const uint32_t nonDebugArgs = 2 ;
109
- const uint32_t allArgs = nonDebugArgs + 2 ;
116
+ const uint32_t allArgs = nonDebugArgs + 0 ;
110
117
111
- DxcCompilationResult compileResult = dxcCompile (includesResolved. get () , &arguments[0 ], hlslOptions.genDebugInfo ? allArgs : nonDebugArgs, hlslOptions);
118
+ DxcCompilationResult compileResult = dxcCompile (newCode , &arguments[0 ], hlslOptions.genDebugInfo ? allArgs : nonDebugArgs, hlslOptions);
112
119
113
120
if (!compileResult.objectBlob )
114
121
{
@@ -118,18 +125,10 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* cod
118
125
auto outSpirv = core::make_smart_refctd_ptr<ICPUBuffer>(compileResult.objectBlob ->GetBufferSize ());
119
126
memcpy (outSpirv->getPointer (), compileResult.objectBlob ->GetBufferPointer (), compileResult.objectBlob ->GetBufferSize ());
120
127
121
- return core::make_smart_refctd_ptr<asset::ICPUShader>(std::move (outSpirv), hlslOptions.stage , IShader::E_CONTENT_TYPE::ECT_SPIRV, hlslOptions.sourceIdentifier .data ());
128
+ return core::make_smart_refctd_ptr<asset::ICPUShader>(std::move (outSpirv), hlslOptions.stage , IShader::E_CONTENT_TYPE::ECT_SPIRV, hlslOptions.preprocessorOptions . sourceIdentifier .data ());
122
129
}
123
130
124
- void CHLSLCompiler::insertExtraDefines (std::string& code, const core::SRange< const char * const >& defines ) const
131
+ void CHLSLCompiler::insertIntoStart (std::string& code, std::ostringstream&& ins ) const
125
132
{
126
- if (defines.empty ())
127
- return ;
128
-
129
- std::ostringstream insertion;
130
- for (auto def : defines)
131
- {
132
- insertion << " #define " << def << " \n " ;
133
- }
134
- code.insert (0u , insertion.str ());
135
- }
133
+ code.insert (0u , ins.str ());
134
+ }
0 commit comments