README-spirv-remap.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. VERSION
  2. --------------------------------------------------------------------------------
  3. spirv-remap 0.97
  4. INTRO:
  5. --------------------------------------------------------------------------------
  6. spirv-remap is a utility to improve compression of SPIR-V binary files via
  7. entropy reduction, plus optional stripping of debug information and
  8. load/store optimization. It transforms SPIR-V to SPIR-V, remapping IDs. The
  9. resulting modules have an increased ID range (IDs are not as tightly packed
  10. around zero), but will compress better when multiple modules are compressed
  11. together, since compressor's dictionary can find better cross module
  12. commonality.
  13. Remapping is accomplished via canonicalization. Thus, modules can be
  14. compressed one at a time with no loss of quality relative to operating on
  15. many modules at once. The command line tool operates on multiple modules
  16. only in the trivial repetition sense, for ease of use. The remapper API
  17. only accepts a single module at a time.
  18. There are two modes of use: command line, and a C++11 API. Both are
  19. described below.
  20. spirv-remap is currently in an alpha state. Although there are no known
  21. remapping defects, it has only been exercised on one real world game shader
  22. workload.
  23. FEEDBACK
  24. --------------------------------------------------------------------------------
  25. Report defects, enhancements requests, code improvements, etc to:
  26. spvremapper@lunarg.com
  27. COMMAND LINE USAGE:
  28. --------------------------------------------------------------------------------
  29. Examples are given with a verbosity of one (-v), but more verbosity can be
  30. had via -vv, -vvv, etc, or an integer parameter to --verbose, such as
  31. "--verbose 4". With no verbosity, the command is silent and returns 0 on
  32. success, and a positive integer error on failure.
  33. Pre-built binaries for several OSs are available. Examples presented are
  34. for Linux. Command line arguments can be provided in any order.
  35. 1. Basic ID remapping
  36. Perform ID remapping on all shaders in "*.spv", writing new files with
  37. the same basenames to /tmp/out_dir.
  38. spirv-remap -v --map all --input *.spv --output /tmp/out_dir
  39. 2. Perform all possible size reductions
  40. spirv-remap-linux-64 -v --do-everything --input *.spv --output /tmp/out_dir
  41. Note that --do-everything is a synonym for:
  42. --map all --dce all --opt all --strip all
  43. API USAGE:
  44. --------------------------------------------------------------------------------
  45. The public interface to the remapper is defined in SPIRV/SPVRemapper.h as follows:
  46. namespace spv {
  47. class spirvbin_t
  48. {
  49. public:
  50. enum Options { ... };
  51. spirvbin_t(int verbose = 0); // construct
  52. // remap an existing binary in memory
  53. void remap(std::vector<std::uint32_t>& spv, std::uint32_t opts = DO_EVERYTHING);
  54. // Type for error/log handler functions
  55. typedef std::function<void(const std::string&)> errorfn_t;
  56. typedef std::function<void(const std::string&)> logfn_t;
  57. // Register error/log handling functions (can be c/c++ fn, lambda fn, or functor)
  58. static void registerErrorHandler(errorfn_t handler) { errorHandler = handler; }
  59. static void registerLogHandler(logfn_t handler) { logHandler = handler; }
  60. };
  61. } // namespace spv
  62. The class definition is in SPVRemapper.cpp.
  63. remap() accepts an std::vector of SPIR-V words, modifies them per the
  64. request given in 'opts', and leaves the 'spv' container with the result.
  65. It is safe to instantiate one spirvbin_t per thread and process a different
  66. SPIR-V in each.
  67. The "opts" parameter to remap() accepts a bit mask of desired remapping
  68. options. See REMAPPING AND OPTIMIZATION OPTIONS.
  69. On error, the function supplied to registerErrorHandler() will be invoked.
  70. This can be a standard C/C++ function, a lambda function, or a functor.
  71. The default handler simply calls exit(5); The error handler is a static
  72. member, so need only be set up once, not once per spirvbin_t instance.
  73. Log messages are supplied to registerLogHandler(). By default, log
  74. messages are eaten silently. The log handler is also a static member.
  75. BUILD DEPENDENCIES:
  76. --------------------------------------------------------------------------------
  77. 1. C++11 compatible compiler
  78. 2. cmake
  79. 3. glslang
  80. BUILDING
  81. --------------------------------------------------------------------------------
  82. The standalone remapper is built along side glslangValidator through its
  83. normal build process.
  84. REMAPPING AND OPTIMIZATION OPTIONS
  85. --------------------------------------------------------------------------------
  86. API:
  87. These are bits defined under spv::spirvbin_t::, and can be
  88. bitwise or-ed together as desired.
  89. MAP_TYPES = canonicalize type IDs
  90. MAP_NAMES = canonicalize named data
  91. MAP_FUNCS = canonicalize function bodies
  92. DCE_FUNCS = remove dead functions
  93. DCE_VARS = remove dead variables
  94. DCE_TYPES = remove dead types
  95. OPT_LOADSTORE = optimize unneeded load/stores
  96. MAP_ALL = (MAP_TYPES | MAP_NAMES | MAP_FUNCS)
  97. DCE_ALL = (DCE_FUNCS | DCE_VARS | DCE_TYPES)
  98. OPT_ALL = (OPT_LOADSTORE)
  99. ALL_BUT_STRIP = (MAP_ALL | DCE_ALL | OPT_ALL)
  100. DO_EVERYTHING = (STRIP | ALL_BUT_STRIP)