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