Reduce SPIR-V size with spirv-opt enhancements

LunarG is pleased to announce the release of new options in spirv-opt designed to reduce SPIR-V size.

We have introduced passes to spirv-opt that use classic code optimization techniques to address code inefficiencies in a SPIR-V module. Combined with spirv-remap , which we use to remove module-level dead types and functions, these passes can reduce raw SPIR-V size by over 60%, and bring SPIR-V sizes within 40% of DX Byte Code.

 

Overview

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.

New spirv-opt passes added by LunarG use standard code optimization techniques (Inlining, Store-Load Elimination, Dead Code Elimination, Dead Branch Elimination, etc.) to remove functionally unnecessary instructions at the function level.

To achieve ultimate size reduction, these passes should be followed by applying spirv-remap with the –dce all and –strip all options to remove module level dead and debug instructions. Moving this capability from spirv-remap to spirv-opt is left for future work.

Expected Benefits in SPIR-V

Over a small, random sample set of HLSL shaders (vertex and fragment), the following size reductions were achieved:

glslang – 188K

glslang + spirv-opt + spirv-remap – 77K

DX Byte Code – 56K

Restrictions

These passes have been initially designed to work with SPIR-V modules for graphics APIs such as Vulkan and OpenGL, which 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.

More information

Read the white paper, by Greg Fischer of LunarG, titled SPIR-V Shader Size Reduction Using spirv-opt_v1.1 for more details about how to use these optimizations.  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.

 

 

 

Featured Post

  • All Posts
  • Announcements
  • Blog
  • Presentations
  • White Papers

Latest Posts

  • All Posts
  • Announcements
  • Blog
  • Presentations
  • White Papers

LunarG Email List

Join our email list to receive important news about Vulkan SDK releases, ecosystem surveys, and more.

You have been successfully subscribed! Oops! Something went wrong, please try again.
Edit Template

Partner with LunarG to do impossible things.

The complexity of GPU software development is relentless, but every “unsolvable” problem that comes up is really an opportunity to create a stronger product.

We believe collaboration is one of the great benefits and opportunities of being part of the visual computing community, and our strength is in our shared expertise. While we focus on your GPU coding issues, you can focus on creating unforgettable visual experiences.

Together, we’ll unlock the full power and potential of today’s GPU’s to surpass your customers’ expectations. 
Successful Software Project
Edit Template

GPU software development teams often run into roadblocks they can’t move on their own. LunarG is the industry’s leading problem-solving partner for GPU programming. We provide the tools, expertise, and passion you need to keep moving forward and deliver innovative, quality products. Let us know how we can help your next project succeed.

LunarG Email List

Join our email list to receive important news about Vulkan SDK releases, ecosystem surveys, and more.

You have been successfully subscribed! Oops! Something went wrong, please try again.

© 2025 LunarG, Inc. All Rights Reserved.   |   Privacy   |   Terms   |    Follow LunarG