A Simpler Way to Reduce Vulkan SPIR-V Size with New spirv-opt -Os

LunarG is pleased to announce the release of a new option in spirv-opt, which was designed to reduce SPIR-V size. This new option, -Os, allows developers to reduce SPIR-V size without specifying individual passes of spirv-opt.


Since the inception of SPIR-V, there has been an interest in optimizing its code, particularly with the goal of reducing its size. Understandably, the raw SPIR-V emitted from the frontend glslangValidator is verbose, particularly with regard to function scope variables and their loads and stores. Significant opportunities for size reduction come from 1) eliminating these loads and stores, 2) eliminating dead code due to branches with constant conditionals and 3) eliminating replicated accesses to uniform variables, including images and samplers. 

Earlier this year we introduced passes to spirv-opt that use classic code optimization techniques to address these inefficiencies in a SPIR-V module. Today we are introducing the -OS option to spirv-opt for those developers who wish derive the benefits of SPIR-V size reduction without specifying individual passes.

A white paper is available. See the link below.

SPIRV-opt Overview

Using spirv-opt combined with spirv-remap, which we use to remove module-level dead types and functions, can reduce raw SPIR-V size by over 60%, and bring SPIR-V sizes within 40% of DX Byte Code.

These passes have been initially designed to work with SPIR-V modules for graphics APIs such as Vulkan and OpenGL. Such shaders use logical addressing. Modules with physical addressing, such as those for the OpenCL API will regrettably not derive much benefit at this time. The scope of these passes was restricted to speed implementation and delivery of their benefits to the graphics community. The structured control flow of shaders and the simplified memory accesses of logical addressing simplify these passes. Optimization of kernels is left for future work.

The New -Os option

For those developers who wish derive the benefits of SPIR-V size reduction without specifying individual passes, the -Os option is available. It invokes a recommended set of passes for size reduction. One advantage of this option is that developers will always get the “latest and greatest” passes and recipe. Another advantage is that developers will not need to continually update their build scripts as new passes and recipes become available.

White Paper Available

For those developers who wish to have finer control over which passes are invoked, read more details about the available SPIR-V optimization options in the white paper by Greg Fischer of LunarG, titled SPIR-V Shader Size Reduction Using spirv-opt_v1.1.  Learn about the specific passes and how they can be used so you can best decide how to reduce the size of SPIR-V shaders.

There are several other features which these passes do not support: please refer to the Limitations section of this document for more information. Running these passes on modules with unsupported features will cause the pass to return silently without changing the module.


  • Need Help with
    3D Graphics Software?

    Let’s talk about your project and how our industry leading team of 3D software engineers can help you build something amazing.