Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanups for render-api #6360

Merged
merged 4 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 14 additions & 29 deletions tools/render-test/render-test-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,28 +154,28 @@ class RenderTestApp
struct AssignValsFromLayoutContext
{
IDevice* device;
slang::ISession* slangSession;
slang::IComponentType* slangComponent;
ShaderOutputPlan& outputPlan;
TestResourceContext& resourceContext;
slang::ProgramLayout* slangReflection;
IAccelerationStructure* accelerationStructure;

AssignValsFromLayoutContext(
IDevice* device,
slang::ISession* slangSession,
slang::IComponentType* slangComponent,
ShaderOutputPlan& outputPlan,
TestResourceContext& resourceContext,
slang::ProgramLayout* slangReflection,
IAccelerationStructure* accelerationStructure)
: device(device)
, slangSession(slangSession)
, slangComponent(slangComponent)
, outputPlan(outputPlan)
, resourceContext(resourceContext)
, slangReflection(slangReflection)
, accelerationStructure(accelerationStructure)
{
}

slang::ProgramLayout* slangReflection() { return slangComponent->getLayout(); }
slang::ISession* slangSession() { return slangComponent->getSession(); }

void maybeAddOutput(
ShaderCursor const& dstCursor,
ShaderInputLayout::Val* srcVal,
Expand Down Expand Up @@ -389,7 +389,7 @@ struct AssignValsFromLayoutContext
// If the input line specified the name of the type
// to allocate, then we use it directly.
//
slangType = slangReflection->findTypeByName(typeName.getBuffer());
slangType = slangReflection()->findTypeByName(typeName.getBuffer());
}
else
{
Expand Down Expand Up @@ -418,7 +418,7 @@ struct AssignValsFromLayoutContext

ComPtr<IShaderObject> shaderObject;
device->createShaderObject(
slangSession,
slangSession(),
slangType,
ShaderObjectContainerType::None,
shaderObject.writeRef());
Expand All @@ -437,7 +437,7 @@ struct AssignValsFromLayoutContext
List<slang::SpecializationArg> args;
for (auto& typeName : srcVal->typeArgs)
{
auto slangType = slangReflection->findTypeByName(typeName.getBuffer());
auto slangType = slangReflection()->findTypeByName(typeName.getBuffer());
if (!slangType)
{
StdWriters::getError().print(
Expand Down Expand Up @@ -516,42 +516,30 @@ struct AssignValsFromLayoutContext
}
};

SlangResult _assignVarsFromLayout(
static SlangResult _assignVarsFromLayout(
IDevice* device,
slang::ISession* slangSession,
slang::IComponentType* slangComponent,
IShaderObject* shaderObject,
ShaderInputLayout const& layout,
ShaderOutputPlan& ioOutputPlan,
TestResourceContext& ioResourceContext,
slang::ProgramLayout* slangReflection,
IAccelerationStructure* accelerationStructure)
{
AssignValsFromLayoutContext context(
device,
slangSession,
ioOutputPlan,
ioResourceContext,
slangReflection,
accelerationStructure);
AssignValsFromLayoutContext
context(device, slangComponent, ioOutputPlan, ioResourceContext, accelerationStructure);
ShaderCursor rootCursor = ShaderCursor(shaderObject);
return context.assign(rootCursor, layout.rootVal);
}

Result RenderTestApp::applyBinding(IShaderObject* rootObject)
{
auto slangReflection = (slang::ProgramLayout*)spGetReflection(
m_compilationOutput.output.getRequestForReflection());
ComPtr<slang::ISession> slangSession;
m_compilationOutput.output.m_requestForKernels->getSession(slangSession.writeRef());

return _assignVarsFromLayout(
m_device,
slangSession,
m_compilationOutput.output.slangProgram,
rootObject,
m_compilationOutput.layout,
m_outputPlan,
m_resourceContext,
slangReflection,
m_topLevelAccelerationStructure);
}

Expand Down Expand Up @@ -1086,9 +1074,6 @@ Result RenderTestApp::update()
m_options.shaderType == Options::ShaderProgramType::GraphicsMeshCompute ||
m_options.shaderType == Options::ShaderProgramType::GraphicsTaskMeshCompute)
{
auto request = m_compilationOutput.output.getRequestForReflection();
auto slangReflection = (slang::ShaderReflection*)spGetReflection(request);

SLANG_RETURN_ON_FAIL(writeBindingOutput(m_options.outputPath));
}
else
Expand Down
39 changes: 16 additions & 23 deletions tools/render-test/slang-support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@ void ShaderCompilerUtil::Output::reset()
}

session = nullptr;
m_requestForKernels = nullptr;
m_extraRequestForReflection = nullptr;
m_requestDEPRECATED = nullptr;
}

/* static */ SlangResult ShaderCompilerUtil::_compileProgramImpl(
static SlangResult _compileProgramImpl(
slang::IGlobalSession* globalSession,
const Options& options,
const Input& input,
const ShaderCompilerUtil::Input& input,
const ShaderCompileRequest& request,
Output& out)
ShaderCompilerUtil::Output& out)
{
out.reset();

Expand All @@ -58,7 +57,7 @@ void ShaderCompilerUtil::Output::reset()
SLANG_ALLOW_DEPRECATED_BEGIN
globalSession->createCompileRequest(slangRequest.writeRef());
SLANG_ALLOW_DEPRECATED_END
out.m_requestForKernels = slangRequest;
out.m_requestDEPRECATED = slangRequest;
out.session = globalSession;

bool hasRepro = false;
Expand Down Expand Up @@ -303,12 +302,12 @@ void ShaderCompilerUtil::Output::reset()
return SLANG_OK;
}

/* static */ SlangResult ShaderCompilerUtil::compileProgram(
static SlangResult compileProgram(
slang::IGlobalSession* globalSession,
const Options& options,
const Input& input,
const ShaderCompilerUtil::Input& input,
const ShaderCompileRequest& request,
Output& out)
ShaderCompilerUtil::Output& out)
{
if (input.passThrough == SLANG_PASS_THROUGH_NONE)
{
Expand All @@ -333,7 +332,7 @@ void ShaderCompilerUtil::Output::reset()
// compile in another pass using the desired downstream compiler
// so that we can get the refleciton information we need.
//
Output slangOutput;
ShaderCompilerUtil::Output slangOutput;
if (canUseSlangForPrecompile)
{
ShaderCompilerUtil::Input slangInput = input;
Expand All @@ -354,17 +353,16 @@ void ShaderCompilerUtil::Output::reset()
//
SLANG_RETURN_ON_FAIL(_compileProgramImpl(globalSession, options, input, request, out));

out.m_extraRequestForReflection = slangOutput.getRequestForReflection();
out.m_requestDEPRECATED = slangOutput.m_requestDEPRECATED;
out.desc.slangGlobalScope = slangOutput.desc.slangGlobalScope;
slangOutput.m_requestForKernels = nullptr;
slangOutput.m_requestDEPRECATED = nullptr;

return SLANG_OK;
}
}

/* static */ SlangResult ShaderCompilerUtil::readSource(
const String& inSourcePath,
List<char>& outSourceText)
// Helper for compileWithLayout
/* static */ SlangResult readSource(const String& inSourcePath, List<char>& outSourceText)
{
// Read in the source code
FILE* sourceFile = fopen(inSourcePath.getBuffer(), "rb");
Expand Down Expand Up @@ -392,8 +390,8 @@ void ShaderCompilerUtil::Output::reset()
/* static */ SlangResult ShaderCompilerUtil::compileWithLayout(
slang::IGlobalSession* globalSession,
const Options& options,
const ShaderCompilerUtil::Input& input,
OutputAndLayout& output)
const Input& input,
ShaderCompilerUtil::OutputAndLayout& output)
{
String sourcePath = options.sourcePath;
auto shaderType = options.shaderType;
Expand Down Expand Up @@ -531,12 +529,7 @@ void ShaderCompilerUtil::Output::reset()
c.idOverride = conformance.idOverride;
compileRequest.typeConformances.add(c);
}
return ShaderCompilerUtil::compileProgram(
globalSession,
options,
input,
compileRequest,
output.output);
return compileProgram(globalSession, options, input, compileRequest, output.output);
}

} // namespace renderer_test
30 changes: 2 additions & 28 deletions tools/render-test/slang-support.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,7 @@ struct ShaderCompilerUtil
ComPtr<slang::IComponentType> slangProgram;
ShaderProgramDesc desc = {};

/// Compile request that owns the lifetime of compiled kernel code.
ComPtr<SlangCompileRequest> m_requestForKernels = nullptr;

/// Compile request that owns the lifetime of reflection information.
ComPtr<SlangCompileRequest> m_extraRequestForReflection = nullptr;

SlangCompileRequest* getRequestForKernels() const { return m_requestForKernels; }
SlangCompileRequest* getRequestForReflection() const
{
return m_extraRequestForReflection ? m_extraRequestForReflection : m_requestForKernels;
}
ComPtr<SlangCompileRequest> m_requestDEPRECATED = nullptr;

SlangSession* session = nullptr;
};
Expand All @@ -89,28 +79,12 @@ struct ShaderCompilerUtil
Slang::String sourcePath;
};

// Wrapper for compileProgram
static SlangResult compileWithLayout(
slang::IGlobalSession* globalSession,
const Options& options,
const ShaderCompilerUtil::Input& input,
OutputAndLayout& output);

static SlangResult readSource(
const Slang::String& inSourcePath,
Slang::List<char>& outSourceText);

static SlangResult _compileProgramImpl(
slang::IGlobalSession* globalSession,
const Options& options,
const Input& input,
const ShaderCompileRequest& request,
Output& out);
static SlangResult compileProgram(
slang::IGlobalSession* globalSession,
const Options& options,
const Input& input,
const ShaderCompileRequest& request,
Output& out);
};


Expand Down
Loading