Skip to content

Commit e4b9600

Browse files
authored
Prepare for render test api migration (#6498)
* Remove tests/compute/dump-repro The -load-repro option is no longer maintained. This helps to address issue #4760. * Rename ShaderCompilerUtil::Output::session to globalSession * Remove the load-repro codepath * Lifetime bugfix
1 parent ceb3af5 commit e4b9600

File tree

3 files changed

+108
-126
lines changed

3 files changed

+108
-126
lines changed

tests/compute/dump-repro.slang

-16
This file was deleted.

tools/render-test/slang-support.cpp

+107-109
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void ShaderCompilerUtil::Output::reset()
3535
desc.slangGlobalScope = nullptr;
3636
}
3737

38-
session = nullptr;
38+
globalSession = nullptr;
3939
m_requestDEPRECATED = nullptr;
4040
}
4141

@@ -58,18 +58,17 @@ static SlangResult _compileProgramImpl(
5858
globalSession->createCompileRequest(slangRequest.writeRef());
5959
SLANG_ALLOW_DEPRECATED_END
6060
out.m_requestDEPRECATED = slangRequest;
61-
out.session = globalSession;
62-
63-
bool hasRepro = false;
61+
out.globalSession = globalSession;
6462

6563
// Parse all the extra args
6664
{
6765
List<const char*> args;
6866
for (const auto& arg : options.downstreamArgs.getArgsByName("slang"))
6967
{
7068
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");
7372
}
7473

7574
// If there are additional args parse them
@@ -89,126 +88,122 @@ static SlangResult _compileProgramImpl(
8988
}
9089
}
9190

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);
105101

106-
slangRequest->setAllowGLSLInput(options.allowGLSL);
102+
slangRequest->setAllowGLSLInput(options.allowGLSL);
107103

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;
116112

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;
135131

136-
default:
137-
assert(!"unexpected");
138-
break;
139-
}
132+
default:
133+
assert(!"unexpected");
134+
break;
135+
}
140136

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+
}
149145

150146

151-
const auto sourceLanguage = input.sourceLanguage;
147+
const auto sourceLanguage = input.sourceLanguage;
152148

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+
}
162167

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)
165173
{
166-
spSetTypeNameForGlobalExistentialTypeParam(
174+
spSetTypeNameForEntryPointExistentialTypeParam(
167175
slangRequest,
176+
entryPoint,
168177
ii,
169-
request.globalSpecializationArgs[ii].getBuffer());
178+
request.entryPointSpecializationArgs[ii].getBuffer());
170179
}
180+
};
171181

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)
188186
{
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);
207192
}
208193

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);
210203
}
211204

205+
spSetLineDirectiveMode(slangRequest, SLANG_LINE_DIRECTIVE_MODE_NONE);
206+
212207
if (options.generateSPIRVDirectly)
213208
{
214209
if (options.disableDebugInfo)
@@ -354,9 +349,12 @@ static SlangResult compileProgram(
354349
SLANG_RETURN_ON_FAIL(_compileProgramImpl(globalSession, options, input, request, out));
355350

356351
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();
358357
slangOutput.m_requestDEPRECATED = nullptr;
359-
360358
return SLANG_OK;
361359
}
362360
}

tools/render-test/slang-support.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct ShaderCompilerUtil
6969

7070
ComPtr<SlangCompileRequest> m_requestDEPRECATED = nullptr;
7171

72-
SlangSession* session = nullptr;
72+
slang::IGlobalSession* globalSession = nullptr;
7373
};
7474

7575
struct OutputAndLayout

0 commit comments

Comments
 (0)