From fb9c673bdb45ef0f651214f88111d3e8b503d584 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 28 Jul 2015 18:44:49 +0200 Subject: [PATCH] Add a struct for a SPIR-V file, and for an operation --- .../shaders/spirv/spirv_disassemble.cpp | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp b/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp index 26d613954..4b9eb2460 100644 --- a/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp @@ -47,6 +47,103 @@ static string OptionalFlagString(EnumType e) return (int)e ? "[" + ToStr::Get(e) + "]" : ""; } +struct SPVOperation +{ + spv::Op opcode; + + ~SPVOperation() + { + } + + int indentChange() + { + return 0; + } + + bool useIndent() + { + return opcode != spv::OpLabel; + } + + string str; + vector arguments; +}; + +struct SPVExtInstSet; +struct SPVOperation; +struct SPVTypeData; +struct SPVFunction; +struct SPVBlock; +struct SPVConstant; +struct SPVVariable; + +struct SPVModule +{ + ~SPVModule() + { + for(size_t i=0; i < operations.size(); i++) + delete operations[i]; + operations.clear(); + } + + // base set of all operations + vector operations; + + uint32_t moduleVersion; + string generator; + string sourceLang; uint32_t sourceVer; + spv::AddressingModel addrModel; spv::MemoryModel memModel; + SPVFunction *entryPoint; + + vector globals; // IDs of global variables + vector funcs; // IDs of functions + + union IDData + { + SPVExtInstSet *ext; // this ID is an extended instruction set + SPVOperation *op; // this ID is the result of an operation + SPVTypeData *type; // this ID names a type + SPVFunction *func; // this ID names a function + SPVBlock *block; // this is the ID of a label + SPVConstant *constant; // this ID is a constant value + SPVVariable *var; // this ID is a variable + }; + + vector ids; // data pointers that depend on what the ID is + + string Disassemble() + { + // add global props + // + // add global variables + // + // add func pre-declares(?) + // + // for each func: + // declare instructino list + // push variable declares + // + // for each block: + // for each instruction: + // add to list + // if instruction takes params: + // if params instructions complexity are low enough + // take param instructions out of list + // incr. this instruction's complexity + // mark params to be melded + // aggressively meld function call parameters, remove variable declares + // + // do magic secret sauce to analyse ifs and loops + // + // for instructions in list: + // mark line num to all 'child' instructions, for stepping + // output combined line + // if instruction pair is goto then label, skip + // + // + } +}; + void DisassembleSPIRV(SPIRVShaderStage shadType, const vector &spirv, string &disasm) { #if defined(RELEASE)