learn-wgpu/assets/js/28.a3ac06e2.js
2020-12-13 03:05:43 +00:00

1 line
5.8 KiB
JavaScript

(window.webpackJsonp=window.webpackJsonp||[]).push([[28],{269:function(t,e,r){"use strict";r.r(e);var v=r(10),a=Object(v.a)({},(function(){var t=this,e=t.$createElement,r=t._self._c||e;return r("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[r("h1",{attrs:{id:"memory-layout-in-glsl"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#memory-layout-in-glsl"}},[t._v("#")]),t._v(" Memory Layout in GLSL")]),t._v(" "),r("h2",{attrs:{id:"alignments"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#alignments"}},[t._v("#")]),t._v(" Alignments")]),t._v(" "),r("p",[t._v("The address of the position of an instance in memory has to a multiple of its alignment.")]),t._v(" "),r("p",[t._v("Normally alignment is the same as size. Exceptions are vec3, structs and arrays.")]),t._v(" "),r("p",[t._v("A vec3 is padded to be a vec4 which means it behaves as if it was a vec4 just that the last entry is not used.")]),t._v(" "),r("p",[r("code",[t._v("{i,u,b}vec")]),t._v(" is shorthand for "),r("code",[t._v("ivec")]),t._v(", "),r("code",[t._v("uvec")]),t._v(", "),r("code",[t._v("bvec")]),t._v(" so a vector of "),r("code",[t._v("int")]),t._v(" or "),r("code",[t._v("uint")]),t._v(" or "),r("code",[t._v("bool")]),t._v(". A "),r("code",[t._v("vec")]),t._v(" is a vec of "),r("code",[t._v("float")]),t._v(".")]),t._v(" "),r("table",[r("thead",[r("tr",[r("th",[t._v("type")]),t._v(" "),r("th",[t._v("Alignment in bytes")]),t._v(" "),r("th",[t._v("size in bytes")])])]),t._v(" "),r("tbody",[r("tr",[r("td",[t._v("int, uint, float, bool")]),t._v(" "),r("td",[t._v("4")]),t._v(" "),r("td",[t._v("4")])]),t._v(" "),r("tr",[r("td",[t._v("double")]),t._v(" "),r("td",[t._v("8")]),t._v(" "),r("td",[t._v("8")])]),t._v(" "),r("tr",[r("td",[t._v("{i,u,b}vec2")]),t._v(" "),r("td",[t._v("8")]),t._v(" "),r("td",[t._v("8")])]),t._v(" "),r("tr",[r("td",[t._v("dvec2")]),t._v(" "),r("td",[t._v("16")]),t._v(" "),r("td",[t._v("16")])]),t._v(" "),r("tr",[r("td",[t._v("{i,u,b}vec3")]),t._v(" "),r("td",[r("strong",[t._v("16")])]),t._v(" "),r("td",[t._v("12")])]),t._v(" "),r("tr",[r("td",[t._v("{i,u,b}vec4")]),t._v(" "),r("td",[t._v("16")]),t._v(" "),r("td",[t._v("16")])]),t._v(" "),r("tr",[r("td",[t._v("dvec3")]),t._v(" "),r("td",[r("strong",[t._v("32")])]),t._v(" "),r("td",[t._v("24")])]),t._v(" "),r("tr",[r("td",[t._v("dvec4")]),t._v(" "),r("td",[t._v("32")]),t._v(" "),r("td",[t._v("32")])]),t._v(" "),r("tr",[r("td",[t._v("mat3 (like array of 3 vec3)")]),t._v(" "),r("td",[r("strong",[t._v("16")])]),t._v(" "),r("td",[t._v("3*16")])]),t._v(" "),r("tr",[r("td",[t._v("mat4 (like array of 4 vec4)")]),t._v(" "),r("td",[t._v("16")]),t._v(" "),r("td",[t._v("4*16")])])])]),t._v(" "),r("p",[r("a",{attrs:{href:"https://www.khronos.org/registry/OpenGL/specs/gl/glspec45.core.pdf#page=159",target:"_blank",rel:"noopener noreferrer"}},[t._v("Reference"),r("OutboundLink")],1),t._v(" section 7.6.2.2")]),t._v(" "),r("h2",{attrs:{id:"in-wgpu"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#in-wgpu"}},[t._v("#")]),t._v(" In WGPU")]),t._v(" "),r("p",[t._v("To make "),r("em",[t._v("uniform buffers")]),t._v(" portable they have to be std140 and not std430.\n"),r("em",[t._v("Uniform structs")]),t._v(" have to be std140.\n"),r("em",[t._v("Storage structs")]),t._v(" have to be std430.")]),t._v(" "),r("p",[r("em",[t._v("Storage buffers")]),t._v(" for compute shaders can be std140 or std430.")]),t._v(" "),r("h2",{attrs:{id:"std140-since-glsl-1-4-opengl-3-1"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#std140-since-glsl-1-4-opengl-3-1"}},[t._v("#")]),t._v(" std140 (since GLSL 1.4, OpenGL 3.1)")]),t._v(" "),r("p",[t._v("Array:")]),t._v(" "),r("ul",[r("li",[t._v("determine the alignment of the member type and lets name it "),r("code",[t._v("align_member")])]),t._v(" "),r("li",[t._v("the alignment of the array is maximum("),r("code",[t._v("align_member")]),t._v(", 16)")])]),t._v(" "),r("p",[t._v("Struct:")]),t._v(" "),r("ul",[r("li",[t._v("determine the member with the largest alignment and lets name it "),r("code",[t._v("max_member_align")])]),t._v(" "),r("li",[t._v("the alignment of the array is maximum("),r("code",[t._v("max_member_align")]),t._v(", 16)")])]),t._v(" "),r("h3",{attrs:{id:"crates-to-make-your-struct-compatible-with-std140"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#crates-to-make-your-struct-compatible-with-std140"}},[t._v("#")]),t._v(" crates to make your struct compatible with std140")]),t._v(" "),r("p",[r("a",{attrs:{href:"https://github.com/rustgd/glsl-layout",target:"_blank",rel:"noopener noreferrer"}},[t._v("glsl_layout"),r("OutboundLink")],1),t._v(" "),r("a",{attrs:{href:"https://github.com/LPGhatguy/crevice",target:"_blank",rel:"noopener noreferrer"}},[t._v("crevice"),r("OutboundLink")],1)]),t._v(" "),r("h2",{attrs:{id:"std430-since-glsl-4-3-opengl-4-3"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#std430-since-glsl-4-3-opengl-4-3"}},[t._v("#")]),t._v(" std430 (since GLSL 4.3, OpenGL 4.3)")]),t._v(" "),r("p",[t._v("more space efficient for structs and arrays")]),t._v(" "),r("p",[t._v("Array")]),t._v(" "),r("ul",[r("li",[t._v("alignment is the alignment of the element type")])]),t._v(" "),r("p",[t._v("Struct")]),t._v(" "),r("ul",[r("li",[t._v("alignment is the alignment of the member with the largest alignment")])]),t._v(" "),r("h3",{attrs:{id:"crates-to-make-yuor-struct-compatible-with-std430"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#crates-to-make-yuor-struct-compatible-with-std430"}},[t._v("#")]),t._v(" crates to make yuor struct compatible with std430")]),t._v(" "),r("p",[r("a",{attrs:{href:"https://github.com/rustgd/glsl-layout/issues/9",target:"_blank",rel:"noopener noreferrer"}},[t._v("glsl_layout issue"),r("OutboundLink")],1),t._v(" "),r("a",{attrs:{href:"https://github.com/LPGhatguy/crevice/issues/1",target:"_blank",rel:"noopener noreferrer"}},[t._v("crevice issue"),r("OutboundLink")],1)]),t._v(" "),r("hr")])}),[],!1,null,null,null);e.default=a.exports}}]);