diff --git a/renderdoc/driver/shaders/spirv/spirv_editor.cpp b/renderdoc/driver/shaders/spirv/spirv_editor.cpp index 44e2cdfd4..27709bcd0 100644 --- a/renderdoc/driver/shaders/spirv/spirv_editor.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_editor.cpp @@ -442,6 +442,58 @@ void Editor::AddEntryGlobals(Id entry, const rdcarray &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 Editor::AddBuiltinInputLoad(OperationList &ops, ShaderStage stage, BuiltIn builtin, Id type) { diff --git a/renderdoc/driver/shaders/spirv/spirv_editor.h b/renderdoc/driver/shaders/spirv/spirv_editor.h index 8a93005ad..6c70cdec5 100644 --- a/renderdoc/driver/shaders/spirv/spirv_editor.h +++ b/renderdoc/driver/shaders/spirv/spirv_editor.h @@ -108,6 +108,7 @@ public: Id FindEntryID(ShaderEntryPoint entry); void AddEntryGlobals(Id entry, const rdcarray &newGlobals); + void ChangeEntry(Id from, Id to); rdcpair AddBuiltinInputLoad(OperationList &ops, ShaderStage stage, BuiltIn builtin, Id type);