Add a helper for changing/wrapping an entry point in another function

This commit is contained in:
baldurk
2025-02-10 17:52:29 +00:00
parent 4ad2deb049
commit aae58c765a
2 changed files with 53 additions and 0 deletions
@@ -442,6 +442,58 @@ void Editor::AddEntryGlobals(Id entry, const rdcarray<Id> &newGlobals)
}
}
void Editor::ChangeEntry(Id from, Id to)
{
rdcspv::Iter it = GetEntry(from);
// this copies into the helper struct
rdcspv::OpEntryPoint e(it);
RDCASSERT(e.entryPoint == from);
e.entryPoint = to;
UnregisterOp(it);
it = e;
RegisterOp(it);
// update any execution modes to apply to the new function
it = rdcspv::Iter(m_SPIRV, m_Sections[Section::ExecutionMode].startOffset);
rdcspv::Iter end(m_SPIRV, m_Sections[Section::ExecutionMode].endOffset);
while(it && it < end)
{
if(it.opcode() == Op::ExecutionMode)
{
OpExecutionMode execMode(it);
if(execMode.entryPoint == from)
{
execMode.entryPoint = to;
UnregisterOp(it);
it = execMode;
RegisterOp(it);
}
}
else if(it.opcode() == Op::ExecutionModeId)
{
OpExecutionModeId execMode(it);
if(execMode.entryPoint == from)
{
execMode.entryPoint = to;
UnregisterOp(it);
it = execMode;
RegisterOp(it);
}
}
it++;
}
}
rdcpair<Id, Id> Editor::AddBuiltinInputLoad(OperationList &ops, ShaderStage stage, BuiltIn builtin,
Id type)
{
@@ -108,6 +108,7 @@ public:
Id FindEntryID(ShaderEntryPoint entry);
void AddEntryGlobals(Id entry, const rdcarray<Id> &newGlobals);
void ChangeEntry(Id from, Id to);
rdcpair<Id, Id> AddBuiltinInputLoad(OperationList &ops, ShaderStage stage, BuiltIn builtin,
Id type);