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