@@ -35,7 +35,7 @@ void ShaderCompilerUtil::Output::reset()
35
35
desc.slangGlobalScope = nullptr ;
36
36
}
37
37
38
- session = nullptr ;
38
+ globalSession = nullptr ;
39
39
m_requestDEPRECATED = nullptr ;
40
40
}
41
41
@@ -58,18 +58,17 @@ static SlangResult _compileProgramImpl(
58
58
globalSession->createCompileRequest (slangRequest.writeRef ());
59
59
SLANG_ALLOW_DEPRECATED_END
60
60
out.m_requestDEPRECATED = slangRequest;
61
- out.session = globalSession;
62
-
63
- bool hasRepro = false ;
61
+ out.globalSession = globalSession;
64
62
65
63
// Parse all the extra args
66
64
{
67
65
List<const char *> args;
68
66
for (const auto & arg : options.downstreamArgs .getArgsByName (" slang" ))
69
67
{
70
68
args.add (arg.value .getBuffer ());
71
- if (arg.value == " -load-repro" )
72
- hasRepro = true ;
69
+ // The -load-repro feature is not maintained, and not supported by the new compile API.
70
+ // TODO: Remove this when the feature has been deprecated.
71
+ SLANG_ASSERT (arg.value != " -load-repro" );
73
72
}
74
73
75
74
// If there are additional args parse them
@@ -89,126 +88,122 @@ static SlangResult _compileProgramImpl(
89
88
}
90
89
}
91
90
92
- // Only proceed if the command line arguments are not loading a repro.
93
- if (!hasRepro)
94
- {
95
- spSetCodeGenTarget (slangRequest, input.target );
96
- if (input.profile .getLength ()) // do not set profile unless requested
97
- spSetTargetProfile (
98
- slangRequest,
99
- 0 ,
100
- spFindProfile (out.session , input.profile .getBuffer ()));
101
- if (options.generateSPIRVDirectly )
102
- spSetTargetFlags (slangRequest, 0 , SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY);
103
- else
104
- spSetTargetFlags (slangRequest, 0 , 0 );
91
+ spSetCodeGenTarget (slangRequest, input.target );
92
+ if (input.profile .getLength ()) // do not set profile unless requested
93
+ spSetTargetProfile (
94
+ slangRequest,
95
+ 0 ,
96
+ spFindProfile (out.globalSession , input.profile .getBuffer ()));
97
+ if (options.generateSPIRVDirectly )
98
+ spSetTargetFlags (slangRequest, 0 , SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY);
99
+ else
100
+ spSetTargetFlags (slangRequest, 0 , 0 );
105
101
106
- slangRequest->setAllowGLSLInput (options.allowGLSL );
102
+ slangRequest->setAllowGLSLInput (options.allowGLSL );
107
103
108
- // Define a macro so that shader code in a test can detect what language we
109
- // are nominally working with.
110
- char const * langDefine = nullptr ;
111
- switch (input.sourceLanguage )
112
- {
113
- case SLANG_SOURCE_LANGUAGE_GLSL:
114
- spAddPreprocessorDefine (slangRequest, " __GLSL__" , " 1" );
115
- break ;
104
+ // Define a macro so that shader code in a test can detect what language we
105
+ // are nominally working with.
106
+ char const * langDefine = nullptr ;
107
+ switch (input.sourceLanguage )
108
+ {
109
+ case SLANG_SOURCE_LANGUAGE_GLSL:
110
+ spAddPreprocessorDefine (slangRequest, " __GLSL__" , " 1" );
111
+ break ;
116
112
117
- case SLANG_SOURCE_LANGUAGE_SLANG:
118
- spAddPreprocessorDefine (slangRequest, " __SLANG__" , " 1" );
119
- // fall through
120
- case SLANG_SOURCE_LANGUAGE_HLSL:
121
- spAddPreprocessorDefine (slangRequest, " __HLSL__" , " 1" );
122
- break ;
123
- case SLANG_SOURCE_LANGUAGE_C:
124
- spAddPreprocessorDefine (slangRequest, " __C__" , " 1" );
125
- break ;
126
- case SLANG_SOURCE_LANGUAGE_CPP:
127
- spAddPreprocessorDefine (slangRequest, " __CPP__" , " 1" );
128
- break ;
129
- case SLANG_SOURCE_LANGUAGE_CUDA:
130
- spAddPreprocessorDefine (slangRequest, " __CUDA__" , " 1" );
131
- break ;
132
- case SLANG_SOURCE_LANGUAGE_WGSL:
133
- spAddPreprocessorDefine (slangRequest, " __WGSL__" , " 1" );
134
- break ;
113
+ case SLANG_SOURCE_LANGUAGE_SLANG:
114
+ spAddPreprocessorDefine (slangRequest, " __SLANG__" , " 1" );
115
+ // fall through
116
+ case SLANG_SOURCE_LANGUAGE_HLSL:
117
+ spAddPreprocessorDefine (slangRequest, " __HLSL__" , " 1" );
118
+ break ;
119
+ case SLANG_SOURCE_LANGUAGE_C:
120
+ spAddPreprocessorDefine (slangRequest, " __C__" , " 1" );
121
+ break ;
122
+ case SLANG_SOURCE_LANGUAGE_CPP:
123
+ spAddPreprocessorDefine (slangRequest, " __CPP__" , " 1" );
124
+ break ;
125
+ case SLANG_SOURCE_LANGUAGE_CUDA:
126
+ spAddPreprocessorDefine (slangRequest, " __CUDA__" , " 1" );
127
+ break ;
128
+ case SLANG_SOURCE_LANGUAGE_WGSL:
129
+ spAddPreprocessorDefine (slangRequest, " __WGSL__" , " 1" );
130
+ break ;
135
131
136
- default :
137
- assert (!" unexpected" );
138
- break ;
139
- }
132
+ default :
133
+ assert (!" unexpected" );
134
+ break ;
135
+ }
140
136
141
- if (input.passThrough != SLANG_PASS_THROUGH_NONE)
142
- {
143
- spSetPassThrough (slangRequest, input.passThrough );
144
- }
145
- else
146
- {
147
- spSetCompileFlags (slangRequest, SLANG_COMPILE_FLAG_NO_CODEGEN);
148
- }
137
+ if (input.passThrough != SLANG_PASS_THROUGH_NONE)
138
+ {
139
+ spSetPassThrough (slangRequest, input.passThrough );
140
+ }
141
+ else
142
+ {
143
+ spSetCompileFlags (slangRequest, SLANG_COMPILE_FLAG_NO_CODEGEN);
144
+ }
149
145
150
146
151
- const auto sourceLanguage = input.sourceLanguage ;
147
+ const auto sourceLanguage = input.sourceLanguage ;
152
148
153
- int translationUnitIndex = 0 ;
154
- {
155
- translationUnitIndex = spAddTranslationUnit (slangRequest, sourceLanguage, nullptr );
156
- spAddTranslationUnitSourceString (
157
- slangRequest,
158
- translationUnitIndex,
159
- request.source .path ,
160
- request.source .dataBegin );
161
- }
149
+ int translationUnitIndex = 0 ;
150
+ {
151
+ translationUnitIndex = spAddTranslationUnit (slangRequest, sourceLanguage, nullptr );
152
+ spAddTranslationUnitSourceString (
153
+ slangRequest,
154
+ translationUnitIndex,
155
+ request.source .path ,
156
+ request.source .dataBegin );
157
+ }
158
+
159
+ const int globalSpecializationArgCount = int (request.globalSpecializationArgs .getCount ());
160
+ for (int ii = 0 ; ii < globalSpecializationArgCount; ++ii)
161
+ {
162
+ spSetTypeNameForGlobalExistentialTypeParam (
163
+ slangRequest,
164
+ ii,
165
+ request.globalSpecializationArgs [ii].getBuffer ());
166
+ }
162
167
163
- const int globalSpecializationArgCount = int (request.globalSpecializationArgs .getCount ());
164
- for (int ii = 0 ; ii < globalSpecializationArgCount; ++ii)
168
+ const int entryPointSpecializationArgCount =
169
+ int (request.entryPointSpecializationArgs .getCount ());
170
+ auto setEntryPointSpecializationArgs = [&](int entryPoint)
171
+ {
172
+ for (int ii = 0 ; ii < entryPointSpecializationArgCount; ++ii)
165
173
{
166
- spSetTypeNameForGlobalExistentialTypeParam (
174
+ spSetTypeNameForEntryPointExistentialTypeParam (
167
175
slangRequest,
176
+ entryPoint,
168
177
ii,
169
- request.globalSpecializationArgs [ii].getBuffer ());
178
+ request.entryPointSpecializationArgs [ii].getBuffer ());
170
179
}
180
+ };
171
181
172
- const int entryPointSpecializationArgCount =
173
- int (request.entryPointSpecializationArgs .getCount ());
174
- auto setEntryPointSpecializationArgs = [&](int entryPoint)
175
- {
176
- for (int ii = 0 ; ii < entryPointSpecializationArgCount; ++ii)
177
- {
178
- spSetTypeNameForEntryPointExistentialTypeParam (
179
- slangRequest,
180
- entryPoint,
181
- ii,
182
- request.entryPointSpecializationArgs [ii].getBuffer ());
183
- }
184
- };
185
-
186
- Index explicitEntryPointCount = request.entryPoints .getCount ();
187
- for (Index ee = 0 ; ee < explicitEntryPointCount; ++ee)
182
+ Index explicitEntryPointCount = request.entryPoints .getCount ();
183
+ for (Index ee = 0 ; ee < explicitEntryPointCount; ++ee)
184
+ {
185
+ if (options.dontAddDefaultEntryPoints )
188
186
{
189
- if (options.dontAddDefaultEntryPoints )
190
- {
191
- // If default entry points are not to be added, then
192
- // the `request.entryPoints` array should have been
193
- // left empty.
194
- //
195
- SLANG_ASSERT (false );
196
- }
197
-
198
- auto & entryPointInfo = request.entryPoints [ee];
199
- int entryPointIndex = spAddEntryPoint (
200
- slangRequest,
201
- translationUnitIndex,
202
- entryPointInfo.name ,
203
- entryPointInfo.slangStage );
204
- SLANG_ASSERT (entryPointIndex == ee);
205
-
206
- setEntryPointSpecializationArgs (entryPointIndex);
187
+ // If default entry points are not to be added, then
188
+ // the `request.entryPoints` array should have been
189
+ // left empty.
190
+ //
191
+ SLANG_ASSERT (false );
207
192
}
208
193
209
- spSetLineDirectiveMode (slangRequest, SLANG_LINE_DIRECTIVE_MODE_NONE);
194
+ auto & entryPointInfo = request.entryPoints [ee];
195
+ int entryPointIndex = spAddEntryPoint (
196
+ slangRequest,
197
+ translationUnitIndex,
198
+ entryPointInfo.name ,
199
+ entryPointInfo.slangStage );
200
+ SLANG_ASSERT (entryPointIndex == ee);
201
+
202
+ setEntryPointSpecializationArgs (entryPointIndex);
210
203
}
211
204
205
+ spSetLineDirectiveMode (slangRequest, SLANG_LINE_DIRECTIVE_MODE_NONE);
206
+
212
207
if (options.generateSPIRVDirectly )
213
208
{
214
209
if (options.disableDebugInfo )
@@ -354,9 +349,12 @@ static SlangResult compileProgram(
354
349
SLANG_RETURN_ON_FAIL (_compileProgramImpl (globalSession, options, input, request, out));
355
350
356
351
out.m_requestDEPRECATED = slangOutput.m_requestDEPRECATED ;
357
- out.desc .slangGlobalScope = slangOutput.desc .slangGlobalScope ;
352
+ // slangOutput.desc.slangGlobalScope and slangOutput.slangProgram are the same object, but
353
+ // the latter is a ComPtr while the former isn't. Therefore we need to detach so that the
354
+ // object doesn't get destroyed.
355
+ SLANG_ASSERT (slangOutput.desc .slangGlobalScope == slangOutput.slangProgram .get ());
356
+ out.desc .slangGlobalScope = slangOutput.slangProgram .detach ();
358
357
slangOutput.m_requestDEPRECATED = nullptr ;
359
-
360
358
return SLANG_OK;
361
359
}
362
360
}
0 commit comments