36 #ifndef SPIRVREMAPPER_H 37 #define SPIRVREMAPPER_H 48 #if __cplusplus >= 201103L || _MSC_VER >= 1700 77 #if !defined (use_cpp11) 87 void remap(std::vector<std::uint32_t>& ,
unsigned int )
89 printf(
"Tool not compiled for C++11, which is required for SPIR-V remapping.\n");
96 #else // defined (use_cpp11) 100 #include <unordered_map> 101 #include <unordered_set> 112 class spirvbin_t :
public spirvbin_base_t
128 static void registerErrorHandler(errorfn_t
handler) { errorHandler =
handler; }
129 static void registerLogHandler(logfn_t
handler) { logHandler =
handler; }
133 virtual void msg(
int minVerbosity,
int indent,
const std::string& txt)
const;
137 typedef std::unordered_map<spv::Id, spv::Id> idmap_t;
138 typedef std::unordered_set<spv::Id> idset_t;
139 typedef std::unordered_map<spv::Id, int> blockmap_t;
144 typedef std::unordered_map<std::string, spv::Id> namemap_t;
148 typedef std::pair<unsigned, unsigned> range_t;
155 static const int header_size;
160 typedef std::vector<spirword_t> typeentry_t;
161 typedef std::map<spv::Id, typeentry_t> globaltypes_t;
164 typedef std::set<int> posmap_t;
165 typedef std::unordered_map<spv::Id, int> posmap_rev_t;
168 typedef std::unordered_map<spv::Id, unsigned> typesize_map_t;
171 void error(
const std::string& txt)
const { errorLatch =
true; errorHandler(txt); }
173 bool isConstOp(
spv::Op opCode)
const;
174 bool isTypeOp(
spv::Op opCode)
const;
175 bool isStripOp(
spv::Op opCode)
const;
176 bool isFlowCtrl(
spv::Op opCode)
const;
177 range_t literalRange(
spv::Op opCode)
const;
178 range_t typeRange(
spv::Op opCode)
const;
179 range_t constRange(
spv::Op opCode)
const;
180 unsigned typeSizeInWords(
spv::Id id)
const;
181 unsigned idTypeSizeInWords(
spv::Id id)
const;
183 spv::Id& asId(
unsigned word) {
return spv[word]; }
184 const spv::Id& asId(
unsigned word)
const {
return spv[word]; }
185 spv::Op asOpCode(
unsigned word)
const {
return opOpCode(
spv[word]); }
188 unsigned asWordCount(
unsigned word)
const {
return opWordCount(
spv[word]); }
189 spv::Id asTypeConstId(
unsigned word)
const {
return asId(word + (isTypeOp(asOpCode(word)) ? 1 : 2)); }
190 unsigned idPos(
spv::Id id)
const;
196 spirword_t magic()
const {
return spv[0]; }
197 spirword_t bound()
const {
return spv[3]; }
198 spirword_t bound(spirword_t
b) {
return spv[3] =
b; };
199 spirword_t genmagic()
const {
return spv[2]; }
200 spirword_t genmagic(spirword_t
m) {
return spv[2] =
m; }
201 spirword_t schemaNum()
const {
return spv[4]; }
215 void buildLocalMaps();
217 int literalStringWords(
const std::string&
str)
const {
return (
int(
str.size())+4)/4; }
219 bool isNewIdMapped(
spv::Id newId)
const {
return isMapped(newId); }
220 bool isOldIdUnmapped(
spv::Id oldId)
const {
return localId(oldId) == unmapped; }
221 bool isOldIdUnused(
spv::Id oldId)
const {
return localId(oldId) == unused; }
222 bool isOldIdMapped(
spv::Id oldId)
const {
return !isOldIdUnused(oldId) && !isOldIdUnmapped(oldId); }
223 bool isFunction(
spv::Id oldId)
const {
return fnPos.find(oldId) != fnPos.end(); }
229 spirvbin_t& process(instfn_t, idfn_t,
unsigned begin = 0,
unsigned end = 0);
230 int processInstruction(
unsigned word, instfn_t, idfn_t);
232 void validate()
const;
241 void forwardLoadStores();
247 void stripDeadRefs();
250 std::vector<spirword_t>
spv;
257 std::vector<bits_t> mapped;
258 static const int mBits =
sizeof(bits_t) * 4;
260 bool isMapped(
spv::Id id)
const {
return id < maxMappedId() && ((mapped[
id/mBits] & (1
LL<<(
id%mBits))) != 0); }
261 void setMapped(
spv::Id id) { resizeMapped(
id); mapped[
id/mBits] |= (1
LL<<(
id%mBits)); }
262 void resizeMapped(
spv::Id id) {
if (
id >= maxMappedId()) mapped.resize(
id/mBits+1, 0); }
263 size_t maxMappedId()
const {
return mapped.size() * mBits; }
267 void stripInst(
unsigned start) { stripRange.push_back(range_t(
start,
start + asWordCount(
start))); }
271 std::unordered_map<spv::Id, range_t> fnPos;
274 std::unordered_map<spv::Id, int> fnCalls;
276 posmap_t typeConstPos;
278 typesize_map_t idTypeSizeMap;
280 std::vector<spv::Id> idMapL;
286 std::vector<range_t> stripRange;
295 mutable bool errorLatch;
297 static errorfn_t errorHandler;
298 static logfn_t logHandler;
303 #endif // defined (use_cpp11) 304 #endif // SPIRVREMAPPER_H Definition: SPVRemapper.h:65
Definition: SPVRemapper.h:52
Definition: SPVRemapper.h:63
Options
Definition: SPVRemapper.h:55
Definition: SPVRemapper.h:64
Definition: disassemble.cpp:50
unsigned int Id
Definition: spirv.hpp:47
spirvbin_t(int)
Definition: SPVRemapper.h:85
GLuint start
Definition: glext.h:6292
Definition: SPVRemapper.h:60
GLenum GLuint id
Definition: glext.h:6233
GLsizei const GLchar *const * string
Definition: glext.h:6699
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
Definition: SPVRemapper.h:70
const char * entryPoint
Definition: Hlsl.FromFile.cpp:45
Definition: SPVRemapper.h:62
GLboolean GLboolean GLboolean b
Definition: glext.h:6844
Definition: SPVRemapper.h:58
typedef bool(RETRO_CALLCONV *retro_replace_image_index_t)(unsigned index
Definition: SPVRemapper.h:61
Decoration
Definition: spirv.hpp:344
static const unsigned int WordCountShift
Definition: spirv.hpp:56
static const unsigned int OpCodeMask
Definition: spirv.hpp:55
Op
Definition: spirv.hpp:714
static const unsigned char msg[]
Definition: ccm.c:375
static l_noret error(LoadState *S, const char *why)
Definition: lundump.c:39
Definition: SPVRemapper.h:66
const Id NoResult
Definition: spvIR.h:64
Definition: SPVRemapper.h:56
Definition: SPVRemapper.h:57
Definition: SPVRemapper.h:59
JSON_Parser_EncodingDetectedHandler handler
Definition: jsonsax_full.h:561
void remap(std::vector< std::uint32_t > &, unsigned int)
Definition: SPVRemapper.h:87
#define LL(x)
Definition: lobject.c:479
GLuint GLuint end
Definition: glext.h:6292
#define false
Definition: ordinals.h:83
Definition: SPVRemapper.h:82
Definition: SPVRemapper.h:71
unsigned __int64 uint64_t
Definition: stdint.h:136
unsigned int uint32_t
Definition: stdint.h:126
bf_uint8_t options
Definition: connect_ps4.c:78
const GLfloat * m
Definition: glext.h:11755
const char *const str
Definition: portlistingparse.c:18
Definition: SPVRemapper.h:67
Definition: SPVRemapper.h:68