{"id":1199,"date":"2017-08-18T15:18:15","date_gmt":"2017-08-18T21:18:15","guid":{"rendered":"https:\/\/www.lunarg.com\/?p=1199"},"modified":"2025-01-15T18:20:40","modified_gmt":"2025-01-16T01:20:40","slug":"reduce-spir-v-binary-file-sizes","status":"publish","type":"post","link":"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/","title":{"rendered":"Reduce SPIR-V size with spirv-opt enhancements"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">LunarG is pleased to announce the release of new options\u00a0in <a href=\"http:\/\/github.com\/KhronosGroup\/SPIRV-Tools\">spirv-opt<\/a><\/span><span style=\"font-weight: 400;\">\u00a0designed to reduce SPIR-V size.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We have introduced passes to spirv-opt that use classic code optimization techniques to address code inefficiencies in a SPIR-V module. Combined with <\/span><a href=\"https:\/\/github.com\/KhronosGroup\/glslang\"><span style=\"font-weight: 400;\">spirv-remap <\/span><\/a><span style=\"font-weight: 400;\">, 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.<\/span><\/p>\n<p><!--more--><\/p>\n<p>&nbsp;<\/p>\n<h2><b>Overview<\/b><\/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=\"http:\/\/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.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">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.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To achieve ultimate size reduction, these passes should be followed by applying spirv-remap with the &#8211;dce all and &#8211;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.<\/span><\/p>\n<h2><b>Expected Benefits in SPIR-V<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Over a small, random sample set of HLSL shaders (vertex and fragment), the following size reductions were achieved:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">glslang &#8211; 188K<\/span><\/p>\n<p><span style=\"font-weight: 400;\">glslang + spirv-opt + spirv-remap &#8211; 77K<\/span><\/p>\n<p><span style=\"font-weight: 400;\">DX Byte Code &#8211; 56K<\/span><\/p>\n<h2><b>Restrictions<\/b><\/h2>\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, 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.<\/span><\/p>\n<h2><b>More information<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Read the white paper, by Greg Fischer of <\/span><a href=\"https:\/\/www.lunarg.com\/\"><span style=\"font-weight: 400;\">LunarG<\/span><\/a><span style=\"font-weight: 400;\">, 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><\/span><span style=\"font-weight: 400;\">\u00a0for more details about how to use these optimizations. \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.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LunarG is pleased to announce the release of new options\u00a0in spirv-opt\u00a0designed 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 [&hellip;]<\/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":[8,9,6],"class_list":["post-1199","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-spir_v","tag-spir-v","tag-vulkan"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Reduce SPIR-V size with spirv-opt enhancements - LunarG<\/title>\n<meta name=\"description\" content=\"LunarG announces the release of spirv-opt enhancements to help reduce SPIR-V file size. Read the white paper for more information.\" \/>\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\/reduce-spir-v-binary-file-sizes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Reduce SPIR-V size with spirv-opt enhancements - LunarG\" \/>\n<meta property=\"og:description\" content=\"LunarG announces the release of spirv-opt enhancements to help reduce SPIR-V file size. Read the white paper for more information.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/\" \/>\n<meta property=\"og:site_name\" content=\"LunarG\" \/>\n<meta property=\"article:published_time\" content=\"2017-08-18T21:18:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-16T01:20:40+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\/reduce-spir-v-binary-file-sizes\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/\"},\"author\":{\"name\":\"Dave Desormeaux\",\"@id\":\"https:\/\/www.lunarg.com\/#\/schema\/person\/493f4ece901c822208cfda3feb80420a\"},\"headline\":\"Reduce SPIR-V size with spirv-opt enhancements\",\"datePublished\":\"2017-08-18T21:18:15+00:00\",\"dateModified\":\"2025-01-16T01:20:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/\"},\"wordCount\":402,\"publisher\":{\"@id\":\"https:\/\/www.lunarg.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.lunarg.com\/wp-content\/uploads\/2019\/09\/iStock-1155410378-2.jpg\",\"keywords\":[\"SPIR_V\",\"spir-v\",\"Vulkan\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/\",\"url\":\"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/\",\"name\":\"Reduce SPIR-V size with spirv-opt enhancements - LunarG\",\"isPartOf\":{\"@id\":\"https:\/\/www.lunarg.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.lunarg.com\/wp-content\/uploads\/2019\/09\/iStock-1155410378-2.jpg\",\"datePublished\":\"2017-08-18T21:18:15+00:00\",\"dateModified\":\"2025-01-16T01:20:40+00:00\",\"description\":\"LunarG announces the release of spirv-opt enhancements to help reduce SPIR-V file size. Read the white paper for more information.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/#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\/reduce-spir-v-binary-file-sizes\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.lunarg.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Reduce SPIR-V size with spirv-opt enhancements\"}]},{\"@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":"Reduce SPIR-V size with spirv-opt enhancements - LunarG","description":"LunarG announces the release of spirv-opt enhancements to help reduce SPIR-V file size. Read the white paper for more information.","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\/reduce-spir-v-binary-file-sizes\/","og_locale":"en_US","og_type":"article","og_title":"Reduce SPIR-V size with spirv-opt enhancements - LunarG","og_description":"LunarG announces the release of spirv-opt enhancements to help reduce SPIR-V file size. Read the white paper for more information.","og_url":"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/","og_site_name":"LunarG","article_published_time":"2017-08-18T21:18:15+00:00","article_modified_time":"2025-01-16T01:20:40+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\/reduce-spir-v-binary-file-sizes\/#article","isPartOf":{"@id":"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/"},"author":{"name":"Dave Desormeaux","@id":"https:\/\/www.lunarg.com\/#\/schema\/person\/493f4ece901c822208cfda3feb80420a"},"headline":"Reduce SPIR-V size with spirv-opt enhancements","datePublished":"2017-08-18T21:18:15+00:00","dateModified":"2025-01-16T01:20:40+00:00","mainEntityOfPage":{"@id":"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/"},"wordCount":402,"publisher":{"@id":"https:\/\/www.lunarg.com\/#organization"},"image":{"@id":"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/#primaryimage"},"thumbnailUrl":"https:\/\/www.lunarg.com\/wp-content\/uploads\/2019\/09\/iStock-1155410378-2.jpg","keywords":["SPIR_V","spir-v","Vulkan"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/","url":"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/","name":"Reduce SPIR-V size with spirv-opt enhancements - LunarG","isPartOf":{"@id":"https:\/\/www.lunarg.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/#primaryimage"},"image":{"@id":"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/#primaryimage"},"thumbnailUrl":"https:\/\/www.lunarg.com\/wp-content\/uploads\/2019\/09\/iStock-1155410378-2.jpg","datePublished":"2017-08-18T21:18:15+00:00","dateModified":"2025-01-16T01:20:40+00:00","description":"LunarG announces the release of spirv-opt enhancements to help reduce SPIR-V file size. Read the white paper for more information.","breadcrumb":{"@id":"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lunarg.com\/reduce-spir-v-binary-file-sizes\/#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\/reduce-spir-v-binary-file-sizes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.lunarg.com\/"},{"@type":"ListItem","position":2,"name":"Reduce SPIR-V size with spirv-opt enhancements"}]},{"@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\/1199","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=1199"}],"version-history":[{"count":0,"href":"https:\/\/www.lunarg.com\/wp-json\/wp\/v2\/posts\/1199\/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=1199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lunarg.com\/wp-json\/wp\/v2\/categories?post=1199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lunarg.com\/wp-json\/wp\/v2\/tags?post=1199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}