@@ -1109,26 +1109,101 @@ Result ShaderProgramBase::compileShaders(RendererBase* device)
1109
1109
SlangInt entryPointIndex)
1110
1110
{
1111
1111
auto stage = entryPointInfo->getStage ();
1112
+
1113
+ List<ComPtr<ISlangBlob> > kernelCodes;
1112
1114
ComPtr<ISlangBlob> kernelCode;
1113
- ComPtr<ISlangBlob> diagnostics;
1114
- auto compileResult = device->getEntryPointCodeFromShaderCache (
1115
- entryPointComponent,
1116
- entryPointIndex,
1117
- 0 ,
1118
- kernelCode.writeRef (),
1119
- diagnostics.writeRef ());
1120
- if (diagnostics)
1121
1115
{
1122
- DebugMessageType msgType = DebugMessageType::Warning;
1123
- if (compileResult != SLANG_OK)
1124
- msgType = DebugMessageType::Error;
1125
- getDebugCallback ()->handleMessage (
1126
- msgType,
1127
- DebugMessageSource::Slang,
1128
- (char *)diagnostics->getBufferPointer ());
1116
+ ComPtr<ISlangBlob> diagnostics;
1117
+ auto compileResult = device->getEntryPointCodeFromShaderCache (
1118
+ entryPointComponent,
1119
+ entryPointIndex,
1120
+ 0 ,
1121
+ kernelCode.writeRef (),
1122
+ diagnostics.writeRef ());
1123
+ if (diagnostics)
1124
+ {
1125
+ DebugMessageType msgType = DebugMessageType::Warning;
1126
+ if (compileResult != SLANG_OK)
1127
+ msgType = DebugMessageType::Error;
1128
+ getDebugCallback ()->handleMessage (
1129
+ msgType,
1130
+ DebugMessageSource::Slang,
1131
+ (char *)diagnostics->getBufferPointer ());
1132
+ }
1133
+ SLANG_RETURN_ON_FAIL (compileResult);
1134
+ kernelCodes.add (kernelCode);
1135
+ }
1136
+
1137
+ // If target precompilation was used, kernelCode may only represent the
1138
+ // glue code holding together the bits of precompiled target IR.
1139
+ // Collect those dependency target IRs too.
1140
+ ComPtr<slang::IModulePrecompileService_Experimental> componentPrecompileService;
1141
+ if (entryPointComponent->queryInterface (
1142
+ slang::IModulePrecompileService_Experimental::getTypeGuid (),
1143
+ (void **)componentPrecompileService.writeRef ()) == SLANG_OK)
1144
+ {
1145
+ SlangInt dependencyCount = componentPrecompileService->getModuleDependencyCount ();
1146
+ if (dependencyCount > 0 )
1147
+ {
1148
+ for (int dependencyIndex = 0 ; dependencyIndex < dependencyCount; dependencyIndex++)
1149
+ {
1150
+ ComPtr<slang::IModule> dependencyModule;
1151
+ {
1152
+ ComPtr<slang::IBlob> diagnosticsBlob;
1153
+ auto result = componentPrecompileService->getModuleDependency (
1154
+ dependencyIndex,
1155
+ dependencyModule.writeRef (),
1156
+ diagnosticsBlob.writeRef ());
1157
+ if (diagnosticsBlob)
1158
+ {
1159
+ DebugMessageType msgType = DebugMessageType::Warning;
1160
+ if (result != SLANG_OK)
1161
+ msgType = DebugMessageType::Error;
1162
+ getDebugCallback ()->handleMessage (
1163
+ msgType,
1164
+ DebugMessageSource::Slang,
1165
+ (char *)diagnosticsBlob->getBufferPointer ());
1166
+ }
1167
+ SLANG_RETURN_ON_FAIL (result);
1168
+ }
1169
+
1170
+ ComPtr<slang::IBlob> spirv;
1171
+ {
1172
+ ComPtr<slang::IBlob> diagnosticsBlob;
1173
+ SlangResult result = SLANG_OK;
1174
+ ComPtr<slang::IModulePrecompileService_Experimental> precompileService;
1175
+ result = dependencyModule->queryInterface (
1176
+ slang::IModulePrecompileService_Experimental::getTypeGuid (),
1177
+ (void **)precompileService.writeRef ());
1178
+ if (result == SLANG_OK)
1179
+ {
1180
+ ComPtr<slang::IBlob> diagnosticsBlob;
1181
+ auto result = precompileService->getPrecompiledTargetCode (
1182
+ SLANG_SPIRV,
1183
+ spirv.writeRef (),
1184
+ diagnosticsBlob.writeRef ());
1185
+ if (result == SLANG_OK)
1186
+ {
1187
+ kernelCodes.add (spirv);
1188
+ }
1189
+ if (diagnosticsBlob)
1190
+ {
1191
+ DebugMessageType msgType = DebugMessageType::Warning;
1192
+ if (result != SLANG_OK)
1193
+ msgType = DebugMessageType::Error;
1194
+ getDebugCallback ()->handleMessage (
1195
+ msgType,
1196
+ DebugMessageSource::Slang,
1197
+ (char *)diagnosticsBlob->getBufferPointer ());
1198
+ }
1199
+ }
1200
+ SLANG_RETURN_ON_FAIL (result);
1201
+ }
1202
+ }
1203
+ }
1129
1204
}
1130
- SLANG_RETURN_ON_FAIL (compileResult);
1131
- SLANG_RETURN_ON_FAIL (createShaderModule (entryPointInfo, kernelCode ));
1205
+
1206
+ SLANG_RETURN_ON_FAIL (createShaderModule (entryPointInfo, kernelCodes ));
1132
1207
return SLANG_OK;
1133
1208
};
1134
1209
@@ -1160,10 +1235,10 @@ Result ShaderProgramBase::compileShaders(RendererBase* device)
1160
1235
1161
1236
Result ShaderProgramBase::createShaderModule (
1162
1237
slang::EntryPointReflection* entryPointInfo,
1163
- ComPtr<ISlangBlob> kernelCode )
1238
+ Slang::List< ComPtr<ISlangBlob> > kernelCodes )
1164
1239
{
1165
1240
SLANG_UNUSED (entryPointInfo);
1166
- SLANG_UNUSED (kernelCode );
1241
+ SLANG_UNUSED (kernelCodes );
1167
1242
return SLANG_OK;
1168
1243
}
1169
1244
0 commit comments