1617a3babSopenharmony_ci
2617a3babSopenharmony_ciVERSION
3617a3babSopenharmony_ci--------------------------------------------------------------------------------
4617a3babSopenharmony_cispirv-remap 0.97
5617a3babSopenharmony_ci
6617a3babSopenharmony_ciINTRO:
7617a3babSopenharmony_ci--------------------------------------------------------------------------------
8617a3babSopenharmony_cispirv-remap is a utility to improve compression of SPIR-V binary files via
9617a3babSopenharmony_cientropy reduction, plus optional stripping of debug information and
10617a3babSopenharmony_ciload/store optimization.  It transforms SPIR-V to SPIR-V, remapping IDs.  The
11617a3babSopenharmony_ciresulting modules have an increased ID range (IDs are not as tightly packed
12617a3babSopenharmony_ciaround zero), but will compress better when multiple modules are compressed
13617a3babSopenharmony_citogether, since compressor's dictionary can find better cross module
14617a3babSopenharmony_cicommonality.
15617a3babSopenharmony_ci
16617a3babSopenharmony_ciRemapping is accomplished via canonicalization.  Thus, modules can be
17617a3babSopenharmony_cicompressed one at a time with no loss of quality relative to operating on
18617a3babSopenharmony_cimany modules at once.  The command line tool operates on multiple modules
19617a3babSopenharmony_cionly in the trivial repetition sense, for ease of use.  The remapper API
20617a3babSopenharmony_cionly accepts a single module at a time.
21617a3babSopenharmony_ci
22617a3babSopenharmony_ciThere are two modes of use: command line, and a C++11 API.  Both are
23617a3babSopenharmony_cidescribed below.
24617a3babSopenharmony_ci
25617a3babSopenharmony_cispirv-remap is currently in an alpha state.  Although there are no known
26617a3babSopenharmony_ciremapping defects, it has only been exercised on one real world game shader
27617a3babSopenharmony_ciworkload.
28617a3babSopenharmony_ci
29617a3babSopenharmony_ci
30617a3babSopenharmony_ciFEEDBACK
31617a3babSopenharmony_ci--------------------------------------------------------------------------------
32617a3babSopenharmony_ciReport defects, enhancements requests, code improvements, etc to:
33617a3babSopenharmony_ci   spvremapper@lunarg.com
34617a3babSopenharmony_ci
35617a3babSopenharmony_ci
36617a3babSopenharmony_ciCOMMAND LINE USAGE:
37617a3babSopenharmony_ci--------------------------------------------------------------------------------
38617a3babSopenharmony_ciExamples are given with a verbosity of one (-v), but more verbosity can be
39617a3babSopenharmony_cihad via -vv, -vvv, etc, or an integer parameter to --verbose, such as
40617a3babSopenharmony_ci"--verbose 4".  With no verbosity, the command is silent and returns 0 on
41617a3babSopenharmony_cisuccess, and a positive integer error on failure.
42617a3babSopenharmony_ci
43617a3babSopenharmony_ciPre-built binaries for several OSs are available.  Examples presented are
44617a3babSopenharmony_cifor Linux.  Command line arguments can be provided in any order.
45617a3babSopenharmony_ci
46617a3babSopenharmony_ci1. Basic ID remapping
47617a3babSopenharmony_ci
48617a3babSopenharmony_ciPerform ID remapping on all shaders in "*.spv", writing new files with
49617a3babSopenharmony_cithe same basenames to /tmp/out_dir.
50617a3babSopenharmony_ci
51617a3babSopenharmony_ci  spirv-remap -v --map all --input *.spv --output /tmp/out_dir
52617a3babSopenharmony_ci
53617a3babSopenharmony_ci2. Perform all possible size reductions
54617a3babSopenharmony_ci
55617a3babSopenharmony_ci  spirv-remap-linux-64 -v --do-everything --input *.spv --output /tmp/out_dir
56617a3babSopenharmony_ci
57617a3babSopenharmony_ciNote that --do-everything is a synonym for:
58617a3babSopenharmony_ci
59617a3babSopenharmony_ci  --map all --dce all --opt all --strip all
60617a3babSopenharmony_ci
61617a3babSopenharmony_ciAPI USAGE:
62617a3babSopenharmony_ci--------------------------------------------------------------------------------
63617a3babSopenharmony_ci
64617a3babSopenharmony_ciThe public interface to the remapper is defined in SPIRV/SPVRemapper.h as follows:
65617a3babSopenharmony_ci
66617a3babSopenharmony_cinamespace spv {
67617a3babSopenharmony_ci
68617a3babSopenharmony_ciclass spirvbin_t
69617a3babSopenharmony_ci{
70617a3babSopenharmony_cipublic:
71617a3babSopenharmony_ci   enum Options { ... };
72617a3babSopenharmony_ci   spirvbin_t(int verbose = 0);  // construct
73617a3babSopenharmony_ci
74617a3babSopenharmony_ci   // remap an existing binary in memory
75617a3babSopenharmony_ci   void remap(std::vector<std::uint32_t>& spv, std::uint32_t opts = DO_EVERYTHING);
76617a3babSopenharmony_ci
77617a3babSopenharmony_ci   // Type for error/log handler functions
78617a3babSopenharmony_ci   typedef std::function<void(const std::string&)> errorfn_t;
79617a3babSopenharmony_ci   typedef std::function<void(const std::string&)> logfn_t;
80617a3babSopenharmony_ci
81617a3babSopenharmony_ci   // Register error/log handling functions (can be c/c++ fn, lambda fn, or functor)
82617a3babSopenharmony_ci   static void registerErrorHandler(errorfn_t handler) { errorHandler = handler; }
83617a3babSopenharmony_ci   static void registerLogHandler(logfn_t handler)     { logHandler   = handler; }
84617a3babSopenharmony_ci};
85617a3babSopenharmony_ci
86617a3babSopenharmony_ci} // namespace spv
87617a3babSopenharmony_ci
88617a3babSopenharmony_ciThe class definition is in SPVRemapper.cpp.
89617a3babSopenharmony_ci
90617a3babSopenharmony_ciremap() accepts an std::vector of SPIR-V words, modifies them per the
91617a3babSopenharmony_cirequest given in 'opts', and leaves the 'spv' container with the result.
92617a3babSopenharmony_ciIt is safe to instantiate one spirvbin_t per thread and process a different
93617a3babSopenharmony_ciSPIR-V in each.
94617a3babSopenharmony_ci
95617a3babSopenharmony_ciThe "opts" parameter to remap() accepts a bit mask of desired remapping
96617a3babSopenharmony_cioptions.  See REMAPPING AND OPTIMIZATION OPTIONS.
97617a3babSopenharmony_ci
98617a3babSopenharmony_ciOn error, the function supplied to registerErrorHandler() will be invoked.
99617a3babSopenharmony_ciThis can be a standard C/C++ function, a lambda function, or a functor.
100617a3babSopenharmony_ciThe default handler simply calls exit(5); The error handler is a static
101617a3babSopenharmony_cimember, so need only be set up once, not once per spirvbin_t instance.
102617a3babSopenharmony_ci
103617a3babSopenharmony_ciLog messages are supplied to registerLogHandler().  By default, log
104617a3babSopenharmony_cimessages are eaten silently.  The log handler is also a static member.
105617a3babSopenharmony_ci
106617a3babSopenharmony_ciBUILD DEPENDENCIES:
107617a3babSopenharmony_ci--------------------------------------------------------------------------------
108617a3babSopenharmony_ci 1. C++11 compatible compiler
109617a3babSopenharmony_ci 2. cmake
110617a3babSopenharmony_ci 3. glslang
111617a3babSopenharmony_ci
112617a3babSopenharmony_ci
113617a3babSopenharmony_ciBUILDING
114617a3babSopenharmony_ci--------------------------------------------------------------------------------
115617a3babSopenharmony_ciThe standalone remapper is built along side glslang through its
116617a3babSopenharmony_cinormal build process.
117617a3babSopenharmony_ci
118617a3babSopenharmony_ci
119617a3babSopenharmony_ciREMAPPING AND OPTIMIZATION OPTIONS
120617a3babSopenharmony_ci--------------------------------------------------------------------------------
121617a3babSopenharmony_ciAPI:
122617a3babSopenharmony_ci   These are bits defined under spv::spirvbin_t::, and can be
123617a3babSopenharmony_ci   bitwise or-ed together as desired.
124617a3babSopenharmony_ci
125617a3babSopenharmony_ci   MAP_TYPES      = canonicalize type IDs
126617a3babSopenharmony_ci   MAP_NAMES      = canonicalize named data
127617a3babSopenharmony_ci   MAP_FUNCS      = canonicalize function bodies
128617a3babSopenharmony_ci   DCE_FUNCS      = remove dead functions
129617a3babSopenharmony_ci   DCE_VARS       = remove dead variables
130617a3babSopenharmony_ci   DCE_TYPES      = remove dead types
131617a3babSopenharmony_ci   OPT_LOADSTORE  = optimize unneeded load/stores
132617a3babSopenharmony_ci   MAP_ALL        = (MAP_TYPES | MAP_NAMES | MAP_FUNCS)
133617a3babSopenharmony_ci   DCE_ALL        = (DCE_FUNCS | DCE_VARS | DCE_TYPES)
134617a3babSopenharmony_ci   OPT_ALL        = (OPT_LOADSTORE)
135617a3babSopenharmony_ci   ALL_BUT_STRIP  = (MAP_ALL | DCE_ALL | OPT_ALL)
136617a3babSopenharmony_ci   DO_EVERYTHING  = (STRIP | ALL_BUT_STRIP)
137617a3babSopenharmony_ci
138