Skip to content

Commit e9a63b2

Browse files
aleino-nvcsyonghe
andauthored
Cleanups for render-api (#6360)
* Clean up unused code * Clean up support interface * Rename the compile output requests to mark them DEPRECATED --------- Co-authored-by: Yong He <yonghe@outlook.com>
1 parent 5ceef13 commit e9a63b2

File tree

3 files changed

+32
-80
lines changed

3 files changed

+32
-80
lines changed

tools/render-test/render-test-main.cpp

+14-29
Original file line numberDiff line numberDiff line change
@@ -154,28 +154,28 @@ class RenderTestApp
154154
struct AssignValsFromLayoutContext
155155
{
156156
IDevice* device;
157-
slang::ISession* slangSession;
157+
slang::IComponentType* slangComponent;
158158
ShaderOutputPlan& outputPlan;
159159
TestResourceContext& resourceContext;
160-
slang::ProgramLayout* slangReflection;
161160
IAccelerationStructure* accelerationStructure;
162161

163162
AssignValsFromLayoutContext(
164163
IDevice* device,
165-
slang::ISession* slangSession,
164+
slang::IComponentType* slangComponent,
166165
ShaderOutputPlan& outputPlan,
167166
TestResourceContext& resourceContext,
168-
slang::ProgramLayout* slangReflection,
169167
IAccelerationStructure* accelerationStructure)
170168
: device(device)
171-
, slangSession(slangSession)
169+
, slangComponent(slangComponent)
172170
, outputPlan(outputPlan)
173171
, resourceContext(resourceContext)
174-
, slangReflection(slangReflection)
175172
, accelerationStructure(accelerationStructure)
176173
{
177174
}
178175

176+
slang::ProgramLayout* slangReflection() { return slangComponent->getLayout(); }
177+
slang::ISession* slangSession() { return slangComponent->getSession(); }
178+
179179
void maybeAddOutput(
180180
ShaderCursor const& dstCursor,
181181
ShaderInputLayout::Val* srcVal,
@@ -389,7 +389,7 @@ struct AssignValsFromLayoutContext
389389
// If the input line specified the name of the type
390390
// to allocate, then we use it directly.
391391
//
392-
slangType = slangReflection->findTypeByName(typeName.getBuffer());
392+
slangType = slangReflection()->findTypeByName(typeName.getBuffer());
393393
}
394394
else
395395
{
@@ -418,7 +418,7 @@ struct AssignValsFromLayoutContext
418418

419419
ComPtr<IShaderObject> shaderObject;
420420
device->createShaderObject(
421-
slangSession,
421+
slangSession(),
422422
slangType,
423423
ShaderObjectContainerType::None,
424424
shaderObject.writeRef());
@@ -437,7 +437,7 @@ struct AssignValsFromLayoutContext
437437
List<slang::SpecializationArg> args;
438438
for (auto& typeName : srcVal->typeArgs)
439439
{
440-
auto slangType = slangReflection->findTypeByName(typeName.getBuffer());
440+
auto slangType = slangReflection()->findTypeByName(typeName.getBuffer());
441441
if (!slangType)
442442
{
443443
StdWriters::getError().print(
@@ -516,42 +516,30 @@ struct AssignValsFromLayoutContext
516516
}
517517
};
518518

519-
SlangResult _assignVarsFromLayout(
519+
static SlangResult _assignVarsFromLayout(
520520
IDevice* device,
521-
slang::ISession* slangSession,
521+
slang::IComponentType* slangComponent,
522522
IShaderObject* shaderObject,
523523
ShaderInputLayout const& layout,
524524
ShaderOutputPlan& ioOutputPlan,
525525
TestResourceContext& ioResourceContext,
526-
slang::ProgramLayout* slangReflection,
527526
IAccelerationStructure* accelerationStructure)
528527
{
529-
AssignValsFromLayoutContext context(
530-
device,
531-
slangSession,
532-
ioOutputPlan,
533-
ioResourceContext,
534-
slangReflection,
535-
accelerationStructure);
528+
AssignValsFromLayoutContext
529+
context(device, slangComponent, ioOutputPlan, ioResourceContext, accelerationStructure);
536530
ShaderCursor rootCursor = ShaderCursor(shaderObject);
537531
return context.assign(rootCursor, layout.rootVal);
538532
}
539533

540534
Result RenderTestApp::applyBinding(IShaderObject* rootObject)
541535
{
542-
auto slangReflection = (slang::ProgramLayout*)spGetReflection(
543-
m_compilationOutput.output.getRequestForReflection());
544-
ComPtr<slang::ISession> slangSession;
545-
m_compilationOutput.output.m_requestForKernels->getSession(slangSession.writeRef());
546-
547536
return _assignVarsFromLayout(
548537
m_device,
549-
slangSession,
538+
m_compilationOutput.output.slangProgram,
550539
rootObject,
551540
m_compilationOutput.layout,
552541
m_outputPlan,
553542
m_resourceContext,
554-
slangReflection,
555543
m_topLevelAccelerationStructure);
556544
}
557545

@@ -1086,9 +1074,6 @@ Result RenderTestApp::update()
10861074
m_options.shaderType == Options::ShaderProgramType::GraphicsMeshCompute ||
10871075
m_options.shaderType == Options::ShaderProgramType::GraphicsTaskMeshCompute)
10881076
{
1089-
auto request = m_compilationOutput.output.getRequestForReflection();
1090-
auto slangReflection = (slang::ShaderReflection*)spGetReflection(request);
1091-
10921077
SLANG_RETURN_ON_FAIL(writeBindingOutput(m_options.outputPath));
10931078
}
10941079
else

tools/render-test/slang-support.cpp

+16-23
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,15 @@ void ShaderCompilerUtil::Output::reset()
3636
}
3737

3838
session = nullptr;
39-
m_requestForKernels = nullptr;
40-
m_extraRequestForReflection = nullptr;
39+
m_requestDEPRECATED = nullptr;
4140
}
4241

43-
/* static */ SlangResult ShaderCompilerUtil::_compileProgramImpl(
42+
static SlangResult _compileProgramImpl(
4443
slang::IGlobalSession* globalSession,
4544
const Options& options,
46-
const Input& input,
45+
const ShaderCompilerUtil::Input& input,
4746
const ShaderCompileRequest& request,
48-
Output& out)
47+
ShaderCompilerUtil::Output& out)
4948
{
5049
out.reset();
5150

@@ -58,7 +57,7 @@ void ShaderCompilerUtil::Output::reset()
5857
SLANG_ALLOW_DEPRECATED_BEGIN
5958
globalSession->createCompileRequest(slangRequest.writeRef());
6059
SLANG_ALLOW_DEPRECATED_END
61-
out.m_requestForKernels = slangRequest;
60+
out.m_requestDEPRECATED = slangRequest;
6261
out.session = globalSession;
6362

6463
bool hasRepro = false;
@@ -303,12 +302,12 @@ void ShaderCompilerUtil::Output::reset()
303302
return SLANG_OK;
304303
}
305304

306-
/* static */ SlangResult ShaderCompilerUtil::compileProgram(
305+
static SlangResult compileProgram(
307306
slang::IGlobalSession* globalSession,
308307
const Options& options,
309-
const Input& input,
308+
const ShaderCompilerUtil::Input& input,
310309
const ShaderCompileRequest& request,
311-
Output& out)
310+
ShaderCompilerUtil::Output& out)
312311
{
313312
if (input.passThrough == SLANG_PASS_THROUGH_NONE)
314313
{
@@ -333,7 +332,7 @@ void ShaderCompilerUtil::Output::reset()
333332
// compile in another pass using the desired downstream compiler
334333
// so that we can get the refleciton information we need.
335334
//
336-
Output slangOutput;
335+
ShaderCompilerUtil::Output slangOutput;
337336
if (canUseSlangForPrecompile)
338337
{
339338
ShaderCompilerUtil::Input slangInput = input;
@@ -354,17 +353,16 @@ void ShaderCompilerUtil::Output::reset()
354353
//
355354
SLANG_RETURN_ON_FAIL(_compileProgramImpl(globalSession, options, input, request, out));
356355

357-
out.m_extraRequestForReflection = slangOutput.getRequestForReflection();
356+
out.m_requestDEPRECATED = slangOutput.m_requestDEPRECATED;
358357
out.desc.slangGlobalScope = slangOutput.desc.slangGlobalScope;
359-
slangOutput.m_requestForKernels = nullptr;
358+
slangOutput.m_requestDEPRECATED = nullptr;
360359

361360
return SLANG_OK;
362361
}
363362
}
364363

365-
/* static */ SlangResult ShaderCompilerUtil::readSource(
366-
const String& inSourcePath,
367-
List<char>& outSourceText)
364+
// Helper for compileWithLayout
365+
/* static */ SlangResult readSource(const String& inSourcePath, List<char>& outSourceText)
368366
{
369367
// Read in the source code
370368
FILE* sourceFile = fopen(inSourcePath.getBuffer(), "rb");
@@ -392,8 +390,8 @@ void ShaderCompilerUtil::Output::reset()
392390
/* static */ SlangResult ShaderCompilerUtil::compileWithLayout(
393391
slang::IGlobalSession* globalSession,
394392
const Options& options,
395-
const ShaderCompilerUtil::Input& input,
396-
OutputAndLayout& output)
393+
const Input& input,
394+
ShaderCompilerUtil::OutputAndLayout& output)
397395
{
398396
String sourcePath = options.sourcePath;
399397
auto shaderType = options.shaderType;
@@ -531,12 +529,7 @@ void ShaderCompilerUtil::Output::reset()
531529
c.idOverride = conformance.idOverride;
532530
compileRequest.typeConformances.add(c);
533531
}
534-
return ShaderCompilerUtil::compileProgram(
535-
globalSession,
536-
options,
537-
input,
538-
compileRequest,
539-
output.output);
532+
return compileProgram(globalSession, options, input, compileRequest, output.output);
540533
}
541534

542535
} // namespace renderer_test

tools/render-test/slang-support.h

+2-28
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,7 @@ struct ShaderCompilerUtil
6767
ComPtr<slang::IComponentType> slangProgram;
6868
ShaderProgramDesc desc = {};
6969

70-
/// Compile request that owns the lifetime of compiled kernel code.
71-
ComPtr<SlangCompileRequest> m_requestForKernels = nullptr;
72-
73-
/// Compile request that owns the lifetime of reflection information.
74-
ComPtr<SlangCompileRequest> m_extraRequestForReflection = nullptr;
75-
76-
SlangCompileRequest* getRequestForKernels() const { return m_requestForKernels; }
77-
SlangCompileRequest* getRequestForReflection() const
78-
{
79-
return m_extraRequestForReflection ? m_extraRequestForReflection : m_requestForKernels;
80-
}
70+
ComPtr<SlangCompileRequest> m_requestDEPRECATED = nullptr;
8171

8272
SlangSession* session = nullptr;
8373
};
@@ -89,28 +79,12 @@ struct ShaderCompilerUtil
8979
Slang::String sourcePath;
9080
};
9181

82+
// Wrapper for compileProgram
9283
static SlangResult compileWithLayout(
9384
slang::IGlobalSession* globalSession,
9485
const Options& options,
9586
const ShaderCompilerUtil::Input& input,
9687
OutputAndLayout& output);
97-
98-
static SlangResult readSource(
99-
const Slang::String& inSourcePath,
100-
Slang::List<char>& outSourceText);
101-
102-
static SlangResult _compileProgramImpl(
103-
slang::IGlobalSession* globalSession,
104-
const Options& options,
105-
const Input& input,
106-
const ShaderCompileRequest& request,
107-
Output& out);
108-
static SlangResult compileProgram(
109-
slang::IGlobalSession* globalSession,
110-
const Options& options,
111-
const Input& input,
112-
const ShaderCompileRequest& request,
113-
Output& out);
11488
};
11589

11690

0 commit comments

Comments
 (0)