{"id":1277,"date":"2017-12-15T11:17:09","date_gmt":"2017-12-15T18:17:09","guid":{"rendered":"https:\/\/www.lunarg.com\/?p=1277"},"modified":"2025-01-15T18:17:55","modified_gmt":"2025-01-16T01:17:55","slug":"simplify-spir-v-size-reduction-with-os-option","status":"publish","type":"post","link":"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/","title":{"rendered":"A Simpler Way to Reduce Vulkan SPIR-V Size with New spirv-opt -Os"},"content":{"rendered":"<p><a href=\"https:\/\/www.lunarg.com\/\">LunarG<\/a> is pleased to announce the release of a new option\u00a0in <a href=\"http:\/\/github.com\/KhronosGroup\/SPIRV-Tools\">spirv-opt,<\/a>\u00a0which 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.<\/p>\n<p><!--more--><\/p>\n<h2>Background<\/h2>\n<p><span style=\"font-weight: 400;\">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 <\/span><a href=\"https:\/\/github.com\/KhronosGroup\/glslang\"><span style=\"font-weight: 400;\">glslangValidator<\/span><\/a><span style=\"font-weight: 400;\"> 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.\u00a0<\/span><\/p>\n<p>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.<\/p>\n<p>A white paper is available. See the link below.<\/p>\n<h2>SPIRV-opt Overview<\/h2>\n<p><span style=\"font-weight: 400;\">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.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">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.<\/span><\/p>\n<h2>The New -Os option<\/h2>\n<p><span style=\"font-weight: 400;\">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 \u201clatest and greatest\u201d passes and recipe. Another advantage is that developers will not need to continually update their build scripts as new passes and recipes become available. <\/span><\/p>\n<h2>White Paper Available<\/h2>\n<p>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 <a href=\"https:\/\/www.lunarg.com\/\">LunarG<\/a>, titled <a href=\"https:\/\/www.lunarg.com\/wp-content\/uploads\/2017\/12\/SPIR-V-Shader-Size-Reduction-Using-spirv-opt_v1.1-1.pdf\">SPIR-V Shader Size Reduction Using spirv-opt_v1.1<\/a><a href=\"https:\/\/www.lunarg.com\/shader-compiler-technologies\/white-paper-spirv-opt\/\"><b><i>. <\/i><\/b><\/a>\u00a0Learn about the specific passes and how they can be used so you can best decide how to reduce the size of SPIR-V shaders.<\/p>\n<p>There are several other features which these passes do not support: please refer to the <b>Limitations <\/b>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.<\/p>\n<h2><\/h2>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LunarG is pleased to announce the release of a new option\u00a0in spirv-opt,\u00a0which 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.<\/p>\n","protected":false},"author":14,"featured_media":1959,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","footnotes":"","_links_to":"","_links_to_target":""},"categories":[130],"tags":[17,9],"class_list":["post-1277","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-spir","tag-spir-v"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>A Simpler Way to Reduce Vulkan SPIR-V Size with New spirv-opt -Os - LunarG<\/title>\n<meta name=\"description\" content=\"Vulkan shader developers, simplify the reduction of your SPIR-V size, by using glslang validator and this new spirv-opt option, -Os..\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A Simpler Way to Reduce Vulkan SPIR-V Size with New spirv-opt -Os - LunarG\" \/>\n<meta property=\"og:description\" content=\"Vulkan shader developers, simplify the reduction of your SPIR-V size, by using glslang validator and this new spirv-opt option, -Os..\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/\" \/>\n<meta property=\"og:site_name\" content=\"LunarG\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-15T18:17:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-16T01:17:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.lunarg.com\/wp-content\/uploads\/2019\/09\/iStock-1155410378-2.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"755\" \/>\n\t<meta property=\"og:image:height\" content=\"395\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Dave Desormeaux\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dave Desormeaux\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/\"},\"author\":{\"name\":\"Dave Desormeaux\",\"@id\":\"https:\/\/www.lunarg.com\/#\/schema\/person\/493f4ece901c822208cfda3feb80420a\"},\"headline\":\"A Simpler Way to Reduce Vulkan SPIR-V Size with New spirv-opt -Os\",\"datePublished\":\"2017-12-15T18:17:09+00:00\",\"dateModified\":\"2025-01-16T01:17:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/\"},\"wordCount\":487,\"publisher\":{\"@id\":\"https:\/\/www.lunarg.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.lunarg.com\/wp-content\/uploads\/2019\/09\/iStock-1155410378-2.jpg\",\"keywords\":[\"SPIR\",\"spir-v\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/\",\"url\":\"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/\",\"name\":\"A Simpler Way to Reduce Vulkan SPIR-V Size with New spirv-opt -Os - LunarG\",\"isPartOf\":{\"@id\":\"https:\/\/www.lunarg.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.lunarg.com\/wp-content\/uploads\/2019\/09\/iStock-1155410378-2.jpg\",\"datePublished\":\"2017-12-15T18:17:09+00:00\",\"dateModified\":\"2025-01-16T01:17:55+00:00\",\"description\":\"Vulkan shader developers, simplify the reduction of your SPIR-V size, by using glslang validator and this new spirv-opt option, -Os..\",\"breadcrumb\":{\"@id\":\"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/#primaryimage\",\"url\":\"https:\/\/www.lunarg.com\/wp-content\/uploads\/2019\/09\/iStock-1155410378-2.jpg\",\"contentUrl\":\"https:\/\/www.lunarg.com\/wp-content\/uploads\/2019\/09\/iStock-1155410378-2.jpg\",\"width\":755,\"height\":395,\"caption\":\"Creative concept of shape fluid mixed blue, red and green paints\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.lunarg.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A Simpler Way to Reduce Vulkan SPIR-V Size with New spirv-opt -Os\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.lunarg.com\/#website\",\"url\":\"https:\/\/www.lunarg.com\/\",\"name\":\"LunarG\",\"description\":\"3D Graphics Software Solutions\",\"publisher\":{\"@id\":\"https:\/\/www.lunarg.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.lunarg.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.lunarg.com\/#organization\",\"name\":\"LunarG\",\"url\":\"https:\/\/www.lunarg.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.lunarg.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.lunarg.com\/wp-content\/uploads\/2020\/05\/logo.png\",\"contentUrl\":\"https:\/\/www.lunarg.com\/wp-content\/uploads\/2020\/05\/logo.png\",\"width\":767,\"height\":304,\"caption\":\"LunarG\"},\"image\":{\"@id\":\"https:\/\/www.lunarg.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.lunarg.com\/#\/schema\/person\/493f4ece901c822208cfda3feb80420a\",\"name\":\"Dave Desormeaux\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.lunarg.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/89944424b10c09db4e6c6e62b6ef1722?s=96&d=retro&r=pg\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/89944424b10c09db4e6c6e62b6ef1722?s=96&d=retro&r=pg\",\"caption\":\"Dave Desormeaux\"},\"sameAs\":[\"http:\/\/www.lunarg.com\"],\"url\":\"https:\/\/www.lunarg.com\/author\/dave-d\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A Simpler Way to Reduce Vulkan SPIR-V Size with New spirv-opt -Os - LunarG","description":"Vulkan shader developers, simplify the reduction of your SPIR-V size, by using glslang validator and this new spirv-opt option, -Os..","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/","og_locale":"en_US","og_type":"article","og_title":"A Simpler Way to Reduce Vulkan SPIR-V Size with New spirv-opt -Os - LunarG","og_description":"Vulkan shader developers, simplify the reduction of your SPIR-V size, by using glslang validator and this new spirv-opt option, -Os..","og_url":"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/","og_site_name":"LunarG","article_published_time":"2017-12-15T18:17:09+00:00","article_modified_time":"2025-01-16T01:17:55+00:00","og_image":[{"width":755,"height":395,"url":"https:\/\/www.lunarg.com\/wp-content\/uploads\/2019\/09\/iStock-1155410378-2.jpg","type":"image\/jpeg"}],"author":"Dave Desormeaux","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Dave Desormeaux","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/#article","isPartOf":{"@id":"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/"},"author":{"name":"Dave Desormeaux","@id":"https:\/\/www.lunarg.com\/#\/schema\/person\/493f4ece901c822208cfda3feb80420a"},"headline":"A Simpler Way to Reduce Vulkan SPIR-V Size with New spirv-opt -Os","datePublished":"2017-12-15T18:17:09+00:00","dateModified":"2025-01-16T01:17:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/"},"wordCount":487,"publisher":{"@id":"https:\/\/www.lunarg.com\/#organization"},"image":{"@id":"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/#primaryimage"},"thumbnailUrl":"https:\/\/www.lunarg.com\/wp-content\/uploads\/2019\/09\/iStock-1155410378-2.jpg","keywords":["SPIR","spir-v"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/","url":"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/","name":"A Simpler Way to Reduce Vulkan SPIR-V Size with New spirv-opt -Os - LunarG","isPartOf":{"@id":"https:\/\/www.lunarg.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/#primaryimage"},"image":{"@id":"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/#primaryimage"},"thumbnailUrl":"https:\/\/www.lunarg.com\/wp-content\/uploads\/2019\/09\/iStock-1155410378-2.jpg","datePublished":"2017-12-15T18:17:09+00:00","dateModified":"2025-01-16T01:17:55+00:00","description":"Vulkan shader developers, simplify the reduction of your SPIR-V size, by using glslang validator and this new spirv-opt option, -Os..","breadcrumb":{"@id":"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/#primaryimage","url":"https:\/\/www.lunarg.com\/wp-content\/uploads\/2019\/09\/iStock-1155410378-2.jpg","contentUrl":"https:\/\/www.lunarg.com\/wp-content\/uploads\/2019\/09\/iStock-1155410378-2.jpg","width":755,"height":395,"caption":"Creative concept of shape fluid mixed blue, red and green paints"},{"@type":"BreadcrumbList","@id":"https:\/\/www.lunarg.com\/simplify-spir-v-size-reduction-with-os-option\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.lunarg.com\/"},{"@type":"ListItem","position":2,"name":"A Simpler Way to Reduce Vulkan SPIR-V Size with New spirv-opt -Os"}]},{"@type":"WebSite","@id":"https:\/\/www.lunarg.com\/#website","url":"https:\/\/www.lunarg.com\/","name":"LunarG","description":"3D Graphics Software Solutions","publisher":{"@id":"https:\/\/www.lunarg.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.lunarg.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.lunarg.com\/#organization","name":"LunarG","url":"https:\/\/www.lunarg.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lunarg.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.lunarg.com\/wp-content\/uploads\/2020\/05\/logo.png","contentUrl":"https:\/\/www.lunarg.com\/wp-content\/uploads\/2020\/05\/logo.png","width":767,"height":304,"caption":"LunarG"},"image":{"@id":"https:\/\/www.lunarg.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.lunarg.com\/#\/schema\/person\/493f4ece901c822208cfda3feb80420a","name":"Dave Desormeaux","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lunarg.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/89944424b10c09db4e6c6e62b6ef1722?s=96&d=retro&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/89944424b10c09db4e6c6e62b6ef1722?s=96&d=retro&r=pg","caption":"Dave Desormeaux"},"sameAs":["http:\/\/www.lunarg.com"],"url":"https:\/\/www.lunarg.com\/author\/dave-d\/"}]}},"_links":{"self":[{"href":"https:\/\/www.lunarg.com\/wp-json\/wp\/v2\/posts\/1277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lunarg.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lunarg.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lunarg.com\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lunarg.com\/wp-json\/wp\/v2\/comments?post=1277"}],"version-history":[{"count":0,"href":"https:\/\/www.lunarg.com\/wp-json\/wp\/v2\/posts\/1277\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lunarg.com\/wp-json\/wp\/v2\/media\/1959"}],"wp:attachment":[{"href":"https:\/\/www.lunarg.com\/wp-json\/wp\/v2\/media?parent=1277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lunarg.com\/wp-json\/wp\/v2\/categories?post=1277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lunarg.com\/wp-json\/wp\/v2\/tags?post=1277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}