<metaproperty="article:modified_time"content="2020-11-21T20:16:07.000Z"><metaproperty="og:site_name"content="Learn Wgpu"><metaproperty="og:title"content="Memory Layout in GLSL"><metaproperty="og:type"content="website"><metaproperty="og:url"content="/showcase/alignment/"><metaname="twitter:title"content="Memory Layout in GLSL"><metaname="twitter:url"content="/showcase/alignment/"><metaname="twitter:card"content="summary_large_image"><metaname="twitter:label1"content="Written by"><metaname="twitter:data2"content="Benjamin R Hansen"><metaname="twitter:creator"content="https://twitter.com/sotrh760">
<em>Storage structs</em> have to be std430.</p><p><em>Storage buffers</em> for compute shaders can be std140 or std430.</p><h2id="std140-since-glsl-1-4-opengl-3-1"><ahref="#std140-since-glsl-1-4-opengl-3-1"class="header-anchor">#</a> std140 (since GLSL 1.4, OpenGL 3.1)</h2><p>Array:</p><ul><li>determine the alignment of the member type and lets name it <code>align_member</code></li><li>the alignment of the array is maximum(<code>align_member</code>, 16)</li></ul><p>Struct:</p><ul><li>determine the member with the largest alignment and lets name it <code>max_member_align</code></li><li>the alignment of the array is maximum(<code>max_member_align</code>, 16)</li></ul><h3id="crates-to-make-your-struct-compatible-with-std140"><ahref="#crates-to-make-your-struct-compatible-with-std140"class="header-anchor">#</a> crates to make your struct compatible with std140</h3><p><ahref="https://github.com/rustgd/glsl-layout"target="_blank"rel="noopener noreferrer">glsl_layout<svgxmlns="http://www.w3.org/2000/svg"aria-hidden="true"x="0px"y="0px"viewBox="0 0 100 100"width="15"height="15"class="icon outbound"><pathfill="currentColor"d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygonfill="currentColor"points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a><ahref="https://github.com/LPGhatguy/crevice"target="_blank"rel="noopener noreferrer">crevice<svgxmlns="http://www.w3.org/2000/svg"aria-hidden="true"x="0px"y="0px"viewBox="0 0 100 100"width="15"height="15"class="icon outbound"><pathfill="currentColor"d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygonfill="currentColor"points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p><h2id="std430-since-glsl-4-3-opengl-4-3"><ahref="#std430-since-glsl-4-3-opengl-4-3"class="header-anchor">#</a> std430 (since GLSL 4.3, OpenGL 4.3)</h2><p>more space efficient for structs and arrays</p><p>Array</p><ul><li>alignment is the alignment of the element type</li></ul><p>Struct</p><ul><li>alignment is the alignment of the member with the largest alignment</li></ul><h3id="crates-to-make-yuor-struct-compatible-with-std430"><ahref="#crates-to-make-yuor-struct-compatible-with-std430"class="header-anchor">#</a> crates to make yuor struct compatible with std430</h3><p><ahref="https://github.com/rustgd/glsl-layout/issues/9"target="_blank"rel="noopener noreferrer">glsl_layout issue<svgxmlns="http://www.w3.org/2000/svg"aria-hidden="true"x="0px"y="0px"viewBox="0 0 100 100"width="15"height="15"class="icon outbound"><pathfill="currentColor"d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygonfill="currentColor"points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a><ahref="https://github.com/LPGhatguy/crevice/issues/1"target="_blank"rel="noopener noreferrer">crevice issue<svgxmlns="http://www.w3.org/2000/svg"aria-hidden="true"x="0px"y="0px"viewBox="0 0 100 100"width="15"height="15"class="icon outbound"><pathfill="currentColor"d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygonfill="currentColor"points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p><hr></div><footerclass="page-edit"><!----><divclass="last-updated"><spanclass="prefix">Last Updated: </span><spanclass="time">11/21/2020, 8:16:07 PM</span></div></footer><divclass="page-nav"><pclass="inner"><spanclass="prev">