1<!DOCTYPE html>
2<html lang="en">
3<head>
4<meta charset="UTF-8">
5<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
6<meta name="viewport" content="width=device-width, initial-scale=1.0">
7<meta name="generator" content="Asciidoctor 1.5.7.1">
8<meta name="author" content="John Kessenich, Google (Editor and Author) ; Dave Baldwin and Randi Rost (Version 1.1 Authors)">
9<title>The OpenGL&#174; Shading Language, Version 4.60.7</title>
10<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
11<style>
12/* Asciidoctor default stylesheet | MIT License | http://asciidoctor.org */
13/* Uncomment @import statement below to use as custom stylesheet */
14/*@import "https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700";*/
15article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}
16audio,canvas,video{display:inline-block}
17audio:not([controls]){display:none;height:0}
18script{display:none!important}
19html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}
20a{background:transparent}
21a:focus{outline:thin dotted}
22a:active,a:hover{outline:0}
23h1{font-size:2em;margin:.67em 0}
24abbr[title]{border-bottom:1px dotted}
25b,strong{font-weight:bold}
26dfn{font-style:italic}
27hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}
28mark{background:#ff0;color:#000}
29code,kbd,pre,samp{font-family:monospace;font-size:1em}
30pre{white-space:pre-wrap}
31q{quotes:"\201C" "\201D" "\2018" "\2019"}
32small{font-size:80%}
33sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}
34sup{top:-.5em}
35sub{bottom:-.25em}
36img{border:0}
37svg:not(:root){overflow:hidden}
38figure{margin:0}
39fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}
40legend{border:0;padding:0}
41button,input,select,textarea{font-family:inherit;font-size:100%;margin:0}
42button,input{line-height:normal}
43button,select{text-transform:none}
44button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}
45button[disabled],html input[disabled]{cursor:default}
46input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}
47button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}
48textarea{overflow:auto;vertical-align:top}
49table{border-collapse:collapse;border-spacing:0}
50*,*::before,*::after{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}
51html,body{font-size:100%}
52body{background:#fff;color:rgba(0,0,0,.8);padding:0;margin:0;font-family:"Noto Serif","DejaVu Serif",serif;font-weight:400;font-style:normal;line-height:1;position:relative;cursor:auto;tab-size:4;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}
53a:hover{cursor:pointer}
54img,object,embed{max-width:100%;height:auto}
55object,embed{height:100%}
56img{-ms-interpolation-mode:bicubic}
57.left{float:left!important}
58.right{float:right!important}
59.text-left{text-align:left!important}
60.text-right{text-align:right!important}
61.text-center{text-align:center!important}
62.text-justify{text-align:justify!important}
63.hide{display:none}
64img,object,svg{display:inline-block;vertical-align:middle}
65textarea{height:auto;min-height:50px}
66select{width:100%}
67.center{margin-left:auto;margin-right:auto}
68.stretch{width:100%}
69.subheader,.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{line-height:1.45;color:#7a2518;font-weight:400;margin-top:0;margin-bottom:.25em}
70div,dl,dt,dd,ul,ol,li,h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6,pre,form,p,blockquote,th,td{margin:0;padding:0;direction:ltr}
71a{color:#2156a5;text-decoration:underline;line-height:inherit}
72a:hover,a:focus{color:#1d4b8f}
73a img{border:none}
74p{font-family:inherit;font-weight:400;font-size:1em;line-height:1.6;margin-bottom:1.25em;text-rendering:optimizeLegibility}
75p aside{font-size:.875em;line-height:1.35;font-style:italic}
76h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{font-family:"Open Sans","DejaVu Sans",sans-serif;font-weight:300;font-style:normal;color:#ba3925;text-rendering:optimizeLegibility;margin-top:1em;margin-bottom:.5em;line-height:1.0125em}
77h1 small,h2 small,h3 small,#toctitle small,.sidebarblock>.content>.title small,h4 small,h5 small,h6 small{font-size:60%;color:#e99b8f;line-height:0}
78h1{font-size:2.125em}
79h2{font-size:1.6875em}
80h3,#toctitle,.sidebarblock>.content>.title{font-size:1.375em}
81h4,h5{font-size:1.125em}
82h6{font-size:1em}
83hr{border:solid #ddddd8;border-width:1px 0 0;clear:both;margin:1.25em 0 1.1875em;height:0}
84em,i{font-style:italic;line-height:inherit}
85strong,b{font-weight:bold;line-height:inherit}
86small{font-size:60%;line-height:inherit}
87code{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;color:rgba(0,0,0,.9)}
88ul,ol,dl{font-size:1em;line-height:1.6;margin-bottom:1.25em;list-style-position:outside;font-family:inherit}
89ul,ol{margin-left:1.5em}
90ul li ul,ul li ol{margin-left:1.25em;margin-bottom:0;font-size:1em}
91ul.square li ul,ul.circle li ul,ul.disc li ul{list-style:inherit}
92ul.square{list-style-type:square}
93ul.circle{list-style-type:circle}
94ul.disc{list-style-type:disc}
95ol li ul,ol li ol{margin-left:1.25em;margin-bottom:0}
96dl dt{margin-bottom:.3125em;font-weight:bold}
97dl dd{margin-bottom:1.25em}
98abbr,acronym{text-transform:uppercase;font-size:90%;color:rgba(0,0,0,.8);border-bottom:1px dotted #ddd;cursor:help}
99abbr{text-transform:none}
100blockquote{margin:0 0 1.25em;padding:.5625em 1.25em 0 1.1875em;border-left:1px solid #ddd}
101blockquote cite{display:block;font-size:.9375em;color:rgba(0,0,0,.6)}
102blockquote cite::before{content:"\2014 \0020"}
103blockquote cite a,blockquote cite a:visited{color:rgba(0,0,0,.6)}
104blockquote,blockquote p{line-height:1.6;color:rgba(0,0,0,.85)}
105@media screen and (min-width:768px){h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2}
106h1{font-size:2.75em}
107h2{font-size:2.3125em}
108h3,#toctitle,.sidebarblock>.content>.title{font-size:1.6875em}
109h4{font-size:1.4375em}}
110table{background:#fff;margin-bottom:1.25em;border:solid 1px #dedede}
111table thead,table tfoot{background:#f7f8f7}
112table thead tr th,table thead tr td,table tfoot tr th,table tfoot tr td{padding:.5em .625em .625em;font-size:inherit;color:rgba(0,0,0,.8);text-align:left}
113table tr th,table tr td{padding:.5625em .625em;font-size:inherit;color:rgba(0,0,0,.8)}
114table tr.even,table tr.alt,table tr:nth-of-type(even){background:#f8f8f7}
115table thead tr th,table tfoot tr th,table tbody tr td,table tr td,table tfoot tr td{display:table-cell;line-height:1.6}
116h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2;word-spacing:-.05em}
117h1 strong,h2 strong,h3 strong,#toctitle strong,.sidebarblock>.content>.title strong,h4 strong,h5 strong,h6 strong{font-weight:400}
118.clearfix::before,.clearfix::after,.float-group::before,.float-group::after{content:" ";display:table}
119.clearfix::after,.float-group::after{clear:both}
120*:not(pre)>code{font-size:.9375em;font-style:normal!important;letter-spacing:0;padding:.1em .5ex;word-spacing:-.15em;background-color:#f7f7f8;-webkit-border-radius:4px;border-radius:4px;line-height:1.45;text-rendering:optimizeSpeed;word-wrap:break-word}
121*:not(pre)>code.nobreak{word-wrap:normal}
122*:not(pre)>code.nowrap{white-space:nowrap}
123pre,pre>code{line-height:1.45;color:rgba(0,0,0,.9);font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;text-rendering:optimizeSpeed}
124em em{font-style:normal}
125strong strong{font-weight:400}
126.keyseq{color:rgba(51,51,51,.8)}
127kbd{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;display:inline-block;color:rgba(0,0,0,.8);font-size:.65em;line-height:1.45;background-color:#f7f7f7;border:1px solid #ccc;-webkit-border-radius:3px;border-radius:3px;-webkit-box-shadow:0 1px 0 rgba(0,0,0,.2),0 0 0 .1em white inset;box-shadow:0 1px 0 rgba(0,0,0,.2),0 0 0 .1em #fff inset;margin:0 .15em;padding:.2em .5em;vertical-align:middle;position:relative;top:-.1em;white-space:nowrap}
128.keyseq kbd:first-child{margin-left:0}
129.keyseq kbd:last-child{margin-right:0}
130.menuseq,.menuref{color:#000}
131.menuseq b:not(.caret),.menuref{font-weight:inherit}
132.menuseq{word-spacing:-.02em}
133.menuseq b.caret{font-size:1.25em;line-height:.8}
134.menuseq i.caret{font-weight:bold;text-align:center;width:.45em}
135b.button::before,b.button::after{position:relative;top:-1px;font-weight:400}
136b.button::before{content:"[";padding:0 3px 0 2px}
137b.button::after{content:"]";padding:0 2px 0 3px}
138p a>code:hover{color:rgba(0,0,0,.9)}
139#header,#content,#footnotes,#footer{width:100%;margin-left:auto;margin-right:auto;margin-top:0;margin-bottom:0;max-width:62.5em;*zoom:1;position:relative;padding-left:.9375em;padding-right:.9375em}
140#header::before,#header::after,#content::before,#content::after,#footnotes::before,#footnotes::after,#footer::before,#footer::after{content:" ";display:table}
141#header::after,#content::after,#footnotes::after,#footer::after{clear:both}
142#content{margin-top:1.25em}
143#content::before{content:none}
144#header>h1:first-child{color:rgba(0,0,0,.85);margin-top:2.25rem;margin-bottom:0}
145#header>h1:first-child+#toc{margin-top:8px;border-top:1px solid #ddddd8}
146#header>h1:only-child,body.toc2 #header>h1:nth-last-child(2){border-bottom:1px solid #ddddd8;padding-bottom:8px}
147#header .details{border-bottom:1px solid #ddddd8;line-height:1.45;padding-top:.25em;padding-bottom:.25em;padding-left:.25em;color:rgba(0,0,0,.6);display:-ms-flexbox;display:-webkit-flex;display:flex;-ms-flex-flow:row wrap;-webkit-flex-flow:row wrap;flex-flow:row wrap}
148#header .details span:first-child{margin-left:-.125em}
149#header .details span.email a{color:rgba(0,0,0,.85)}
150#header .details br{display:none}
151#header .details br+span::before{content:"\00a0\2013\00a0"}
152#header .details br+span.author::before{content:"\00a0\22c5\00a0";color:rgba(0,0,0,.85)}
153#header .details br+span#revremark::before{content:"\00a0|\00a0"}
154#header #revnumber{text-transform:capitalize}
155#header #revnumber::after{content:"\00a0"}
156#content>h1:first-child:not([class]){color:rgba(0,0,0,.85);border-bottom:1px solid #ddddd8;padding-bottom:8px;margin-top:0;padding-top:1rem;margin-bottom:1.25rem}
157#toc{border-bottom:1px solid #efefed;padding-bottom:.5em}
158#toc>ul{margin-left:.125em}
159#toc ul.sectlevel0>li>a{font-style:italic}
160#toc ul.sectlevel0 ul.sectlevel1{margin:.5em 0}
161#toc ul{font-family:"Open Sans","DejaVu Sans",sans-serif;list-style-type:none}
162#toc li{line-height:1.3334;margin-top:.3334em}
163#toc a{text-decoration:none}
164#toc a:active{text-decoration:underline}
165#toctitle{color:#7a2518;font-size:1.2em}
166@media screen and (min-width:768px){#toctitle{font-size:1.375em}
167body.toc2{padding-left:15em;padding-right:0}
168#toc.toc2{margin-top:0!important;background-color:#f8f8f7;position:fixed;width:15em;left:0;top:0;border-right:1px solid #efefed;border-top-width:0!important;border-bottom-width:0!important;z-index:1000;padding:1.25em 1em;height:100%;overflow:auto}
169#toc.toc2 #toctitle{margin-top:0;margin-bottom:.8rem;font-size:1.2em}
170#toc.toc2>ul{font-size:.9em;margin-bottom:0}
171#toc.toc2 ul ul{margin-left:0;padding-left:1em}
172#toc.toc2 ul.sectlevel0 ul.sectlevel1{padding-left:0;margin-top:.5em;margin-bottom:.5em}
173body.toc2.toc-right{padding-left:0;padding-right:15em}
174body.toc2.toc-right #toc.toc2{border-right-width:0;border-left:1px solid #efefed;left:auto;right:0}}
175@media screen and (min-width:1280px){body.toc2{padding-left:20em;padding-right:0}
176#toc.toc2{width:20em}
177#toc.toc2 #toctitle{font-size:1.375em}
178#toc.toc2>ul{font-size:.95em}
179#toc.toc2 ul ul{padding-left:1.25em}
180body.toc2.toc-right{padding-left:0;padding-right:20em}}
181#content #toc{border-style:solid;border-width:1px;border-color:#e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;-webkit-border-radius:4px;border-radius:4px}
182#content #toc>:first-child{margin-top:0}
183#content #toc>:last-child{margin-bottom:0}
184#footer{max-width:100%;background-color:rgba(0,0,0,.8);padding:1.25em}
185#footer-text{color:rgba(255,255,255,.8);line-height:1.44}
186#content{margin-bottom:.625em}
187.sect1{padding-bottom:.625em}
188@media screen and (min-width:768px){#content{margin-bottom:1.25em}
189.sect1{padding-bottom:1.25em}}
190.sect1:last-child{padding-bottom:0}
191.sect1+.sect1{border-top:1px solid #efefed}
192#content h1>a.anchor,h2>a.anchor,h3>a.anchor,#toctitle>a.anchor,.sidebarblock>.content>.title>a.anchor,h4>a.anchor,h5>a.anchor,h6>a.anchor{position:absolute;z-index:1001;width:1.5ex;margin-left:-1.5ex;display:block;text-decoration:none!important;visibility:hidden;text-align:center;font-weight:400}
193#content h1>a.anchor::before,h2>a.anchor::before,h3>a.anchor::before,#toctitle>a.anchor::before,.sidebarblock>.content>.title>a.anchor::before,h4>a.anchor::before,h5>a.anchor::before,h6>a.anchor::before{content:"\00A7";font-size:.85em;display:block;padding-top:.1em}
194#content h1:hover>a.anchor,#content h1>a.anchor:hover,h2:hover>a.anchor,h2>a.anchor:hover,h3:hover>a.anchor,#toctitle:hover>a.anchor,.sidebarblock>.content>.title:hover>a.anchor,h3>a.anchor:hover,#toctitle>a.anchor:hover,.sidebarblock>.content>.title>a.anchor:hover,h4:hover>a.anchor,h4>a.anchor:hover,h5:hover>a.anchor,h5>a.anchor:hover,h6:hover>a.anchor,h6>a.anchor:hover{visibility:visible}
195#content h1>a.link,h2>a.link,h3>a.link,#toctitle>a.link,.sidebarblock>.content>.title>a.link,h4>a.link,h5>a.link,h6>a.link{color:#ba3925;text-decoration:none}
196#content h1>a.link:hover,h2>a.link:hover,h3>a.link:hover,#toctitle>a.link:hover,.sidebarblock>.content>.title>a.link:hover,h4>a.link:hover,h5>a.link:hover,h6>a.link:hover{color:#a53221}
197.audioblock,.imageblock,.literalblock,.listingblock,.stemblock,.videoblock{margin-bottom:1.25em}
198.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{text-rendering:optimizeLegibility;text-align:left;font-family:"Noto Serif","DejaVu Serif",serif;font-size:1rem;font-style:italic}
199table.tableblock.fit-content>caption.title{white-space:nowrap;width:0}
200.paragraph.lead>p,#preamble>.sectionbody>[class="paragraph"]:first-of-type p{font-size:1.21875em;line-height:1.6;color:rgba(0,0,0,.85)}
201table.tableblock #preamble>.sectionbody>[class="paragraph"]:first-of-type p{font-size:inherit}
202.admonitionblock>table{border-collapse:separate;border:0;background:none;width:100%}
203.admonitionblock>table td.icon{text-align:center;width:80px}
204.admonitionblock>table td.icon img{max-width:none}
205.admonitionblock>table td.icon .title{font-weight:bold;font-family:"Open Sans","DejaVu Sans",sans-serif;text-transform:uppercase}
206.admonitionblock>table td.content{padding-left:1.125em;padding-right:1.25em;border-left:1px solid #ddddd8;color:rgba(0,0,0,.6)}
207.admonitionblock>table td.content>:last-child>:last-child{margin-bottom:0}
208.exampleblock>.content{border-style:solid;border-width:1px;border-color:#e6e6e6;margin-bottom:1.25em;padding:1.25em;background:#fff;-webkit-border-radius:4px;border-radius:4px}
209.exampleblock>.content>:first-child{margin-top:0}
210.exampleblock>.content>:last-child{margin-bottom:0}
211.sidebarblock{border-style:solid;border-width:1px;border-color:#e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;-webkit-border-radius:4px;border-radius:4px}
212.sidebarblock>:first-child{margin-top:0}
213.sidebarblock>:last-child{margin-bottom:0}
214.sidebarblock>.content>.title{color:#7a2518;margin-top:0;text-align:center}
215.exampleblock>.content>:last-child>:last-child,.exampleblock>.content .olist>ol>li:last-child>:last-child,.exampleblock>.content .ulist>ul>li:last-child>:last-child,.exampleblock>.content .qlist>ol>li:last-child>:last-child,.sidebarblock>.content>:last-child>:last-child,.sidebarblock>.content .olist>ol>li:last-child>:last-child,.sidebarblock>.content .ulist>ul>li:last-child>:last-child,.sidebarblock>.content .qlist>ol>li:last-child>:last-child{margin-bottom:0}
216.literalblock pre,.listingblock pre:not(.highlight),.listingblock pre[class="highlight"],.listingblock pre[class^="highlight "],.listingblock pre.CodeRay,.listingblock pre.prettyprint{background:#f7f7f8}
217.sidebarblock .literalblock pre,.sidebarblock .listingblock pre:not(.highlight),.sidebarblock .listingblock pre[class="highlight"],.sidebarblock .listingblock pre[class^="highlight "],.sidebarblock .listingblock pre.CodeRay,.sidebarblock .listingblock pre.prettyprint{background:#f2f1f1}
218.literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{-webkit-border-radius:4px;border-radius:4px;word-wrap:break-word;padding:1em;font-size:.8125em}
219.literalblock pre.nowrap,.literalblock pre[class].nowrap,.listingblock pre.nowrap,.listingblock pre[class].nowrap{overflow-x:auto;white-space:pre;word-wrap:normal}
220@media screen and (min-width:768px){.literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{font-size:.90625em}}
221@media screen and (min-width:1280px){.literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{font-size:1em}}
222.literalblock.output pre{color:#f7f7f8;background-color:rgba(0,0,0,.9)}
223.listingblock pre.highlightjs{padding:0}
224.listingblock pre.highlightjs>code{padding:1em;-webkit-border-radius:4px;border-radius:4px}
225.listingblock pre.prettyprint{border-width:0}
226.listingblock>.content{position:relative}
227.listingblock code[data-lang]::before{display:none;content:attr(data-lang);position:absolute;font-size:.75em;top:.425rem;right:.5rem;line-height:1;text-transform:uppercase;color:#999}
228.listingblock:hover code[data-lang]::before{display:block}
229.listingblock.terminal pre .command::before{content:attr(data-prompt);padding-right:.5em;color:#999}
230.listingblock.terminal pre .command:not([data-prompt])::before{content:"$"}
231table.pyhltable{border-collapse:separate;border:0;margin-bottom:0;background:none}
232table.pyhltable td{vertical-align:top;padding-top:0;padding-bottom:0;line-height:1.45}
233table.pyhltable td.code{padding-left:.75em;padding-right:0}
234pre.pygments .lineno,table.pyhltable td:not(.code){color:#999;padding-left:0;padding-right:.5em;border-right:1px solid #ddddd8}
235pre.pygments .lineno{display:inline-block;margin-right:.25em}
236table.pyhltable .linenodiv{background:none!important;padding-right:0!important}
237.quoteblock{margin:0 1em 1.25em 1.5em;display:table}
238.quoteblock>.title{margin-left:-1.5em;margin-bottom:.75em}
239.quoteblock blockquote,.quoteblock blockquote p{color:rgba(0,0,0,.85);font-size:1.15rem;line-height:1.75;word-spacing:.1em;letter-spacing:0;font-style:italic;text-align:justify}
240.quoteblock blockquote{margin:0;padding:0;border:0}
241.quoteblock blockquote::before{content:"\201c";float:left;font-size:2.75em;font-weight:bold;line-height:.6em;margin-left:-.6em;color:#7a2518;text-shadow:0 1px 2px rgba(0,0,0,.1)}
242.quoteblock blockquote>.paragraph:last-child p{margin-bottom:0}
243.quoteblock .attribution{margin-top:.5em;margin-right:.5ex;text-align:right}
244.quoteblock .quoteblock{margin-left:0;margin-right:0;padding:.5em 0;border-left:3px solid rgba(0,0,0,.6)}
245.quoteblock .quoteblock blockquote{padding:0 0 0 .75em}
246.quoteblock .quoteblock blockquote::before{display:none}
247.verseblock{margin:0 1em 1.25em}
248.verseblock pre{font-family:"Open Sans","DejaVu Sans",sans;font-size:1.15rem;color:rgba(0,0,0,.85);font-weight:300;text-rendering:optimizeLegibility}
249.verseblock pre strong{font-weight:400}
250.verseblock .attribution{margin-top:1.25rem;margin-left:.5ex}
251.quoteblock .attribution,.verseblock .attribution{font-size:.9375em;line-height:1.45;font-style:italic}
252.quoteblock .attribution br,.verseblock .attribution br{display:none}
253.quoteblock .attribution cite,.verseblock .attribution cite{display:block;letter-spacing:-.025em;color:rgba(0,0,0,.6)}
254.quoteblock.abstract{margin:0 1em 1.25em;display:block}
255.quoteblock.abstract>.title{margin:0 0 .375em;font-size:1.15em;text-align:center}
256.quoteblock.abstract blockquote,.quoteblock.abstract blockquote p{word-spacing:0;line-height:1.6}
257.quoteblock.abstract blockquote::before,.quoteblock.abstract p::before{display:none}
258table.tableblock{max-width:100%;border-collapse:separate}
259p.tableblock:last-child{margin-bottom:0}
260td.tableblock>.content{margin-bottom:-1.25em}
261table.tableblock,th.tableblock,td.tableblock{border:0 solid #dedede}
262table.grid-all>thead>tr>.tableblock,table.grid-all>tbody>tr>.tableblock{border-width:0 1px 1px 0}
263table.grid-all>tfoot>tr>.tableblock{border-width:1px 1px 0 0}
264table.grid-cols>*>tr>.tableblock{border-width:0 1px 0 0}
265table.grid-rows>thead>tr>.tableblock,table.grid-rows>tbody>tr>.tableblock{border-width:0 0 1px}
266table.grid-rows>tfoot>tr>.tableblock{border-width:1px 0 0}
267table.grid-all>*>tr>.tableblock:last-child,table.grid-cols>*>tr>.tableblock:last-child{border-right-width:0}
268table.grid-all>tbody>tr:last-child>.tableblock,table.grid-all>thead:last-child>tr>.tableblock,table.grid-rows>tbody>tr:last-child>.tableblock,table.grid-rows>thead:last-child>tr>.tableblock{border-bottom-width:0}
269table.frame-all{border-width:1px}
270table.frame-sides{border-width:0 1px}
271table.frame-topbot,table.frame-ends{border-width:1px 0}
272table.stripes-all tr,table.stripes-odd tr:nth-of-type(odd){background:#f8f8f7}
273table.stripes-none tr,table.stripes-odd tr:nth-of-type(even){background:none}
274th.halign-left,td.halign-left{text-align:left}
275th.halign-right,td.halign-right{text-align:right}
276th.halign-center,td.halign-center{text-align:center}
277th.valign-top,td.valign-top{vertical-align:top}
278th.valign-bottom,td.valign-bottom{vertical-align:bottom}
279th.valign-middle,td.valign-middle{vertical-align:middle}
280table thead th,table tfoot th{font-weight:bold}
281tbody tr th{display:table-cell;line-height:1.6;background:#f7f8f7}
282tbody tr th,tbody tr th p,tfoot tr th,tfoot tr th p{color:rgba(0,0,0,.8);font-weight:bold}
283p.tableblock>code:only-child{background:none;padding:0}
284p.tableblock{font-size:1em}
285td>div.verse{white-space:pre}
286ol{margin-left:1.75em}
287ul li ol{margin-left:1.5em}
288dl dd{margin-left:1.125em}
289dl dd:last-child,dl dd:last-child>:last-child{margin-bottom:0}
290ol>li p,ul>li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em}
291ul.checklist,ul.none,ol.none,ul.no-bullet,ol.no-bullet,ol.unnumbered,ul.unstyled,ol.unstyled{list-style-type:none}
292ul.no-bullet,ol.no-bullet,ol.unnumbered{margin-left:.625em}
293ul.unstyled,ol.unstyled{margin-left:0}
294ul.checklist{margin-left:.625em}
295ul.checklist li>p:first-child>.fa-square-o:first-child,ul.checklist li>p:first-child>.fa-check-square-o:first-child{width:1.25em;font-size:.8em;position:relative;bottom:.125em}
296ul.checklist li>p:first-child>input[type="checkbox"]:first-child{margin-right:.25em}
297ul.inline{display:-ms-flexbox;display:-webkit-box;display:flex;-ms-flex-flow:row wrap;-webkit-flex-flow:row wrap;flex-flow:row wrap;list-style:none;margin:0 0 .625em -1.25em}
298ul.inline>li{margin-left:1.25em}
299.unstyled dl dt{font-weight:400;font-style:normal}
300ol.arabic{list-style-type:decimal}
301ol.decimal{list-style-type:decimal-leading-zero}
302ol.loweralpha{list-style-type:lower-alpha}
303ol.upperalpha{list-style-type:upper-alpha}
304ol.lowerroman{list-style-type:lower-roman}
305ol.upperroman{list-style-type:upper-roman}
306ol.lowergreek{list-style-type:lower-greek}
307.hdlist>table,.colist>table{border:0;background:none}
308.hdlist>table>tbody>tr,.colist>table>tbody>tr{background:none}
309td.hdlist1,td.hdlist2{vertical-align:top;padding:0 .625em}
310td.hdlist1{font-weight:bold;padding-bottom:1.25em}
311.literalblock+.colist,.listingblock+.colist{margin-top:-.5em}
312.colist td:not([class]):first-child{padding:.4em .75em 0;line-height:1;vertical-align:top}
313.colist td:not([class]):first-child img{max-width:none}
314.colist td:not([class]):last-child{padding:.25em 0}
315.thumb,.th{line-height:0;display:inline-block;border:solid 4px #fff;-webkit-box-shadow:0 0 0 1px #ddd;box-shadow:0 0 0 1px #ddd}
316.imageblock.left,.imageblock[style*="float: left"]{margin:.25em .625em 1.25em 0}
317.imageblock.right,.imageblock[style*="float: right"]{margin:.25em 0 1.25em .625em}
318.imageblock>.title{margin-bottom:0}
319.imageblock.thumb,.imageblock.th{border-width:6px}
320.imageblock.thumb>.title,.imageblock.th>.title{padding:0 .125em}
321.image.left,.image.right{margin-top:.25em;margin-bottom:.25em;display:inline-block;line-height:0}
322.image.left{margin-right:.625em}
323.image.right{margin-left:.625em}
324a.image{text-decoration:none;display:inline-block}
325a.image object{pointer-events:none}
326sup.footnote,sup.footnoteref{font-size:.875em;position:static;vertical-align:super}
327sup.footnote a,sup.footnoteref a{text-decoration:none}
328sup.footnote a:active,sup.footnoteref a:active{text-decoration:underline}
329#footnotes{padding-top:.75em;padding-bottom:.75em;margin-bottom:.625em}
330#footnotes hr{width:20%;min-width:6.25em;margin:-.25em 0 .75em;border-width:1px 0 0}
331#footnotes .footnote{padding:0 .375em 0 .225em;line-height:1.3334;font-size:.875em;margin-left:1.2em;margin-bottom:.2em}
332#footnotes .footnote a:first-of-type{font-weight:bold;text-decoration:none;margin-left:-1.05em}
333#footnotes .footnote:last-of-type{margin-bottom:0}
334#content #footnotes{margin-top:-.625em;margin-bottom:0;padding:.75em 0}
335.gist .file-data>table{border:0;background:#fff;width:100%;margin-bottom:0}
336.gist .file-data>table td.line-data{width:99%}
337div.unbreakable{page-break-inside:avoid}
338.big{font-size:larger}
339.small{font-size:smaller}
340.underline{text-decoration:underline}
341.overline{text-decoration:overline}
342.line-through{text-decoration:line-through}
343.aqua{color:#00bfbf}
344.aqua-background{background-color:#00fafa}
345.black{color:#000}
346.black-background{background-color:#000}
347.blue{color:#0000bf}
348.blue-background{background-color:#0000fa}
349.fuchsia{color:#bf00bf}
350.fuchsia-background{background-color:#fa00fa}
351.gray{color:#606060}
352.gray-background{background-color:#7d7d7d}
353.green{color:#006000}
354.green-background{background-color:#007d00}
355.lime{color:#00bf00}
356.lime-background{background-color:#00fa00}
357.maroon{color:#600000}
358.maroon-background{background-color:#7d0000}
359.navy{color:#000060}
360.navy-background{background-color:#00007d}
361.olive{color:#606000}
362.olive-background{background-color:#7d7d00}
363.purple{color:#600060}
364.purple-background{background-color:#7d007d}
365.red{color:#bf0000}
366.red-background{background-color:#fa0000}
367.silver{color:#909090}
368.silver-background{background-color:#bcbcbc}
369.teal{color:#006060}
370.teal-background{background-color:#007d7d}
371.white{color:#bfbfbf}
372.white-background{background-color:#fafafa}
373.yellow{color:#bfbf00}
374.yellow-background{background-color:#fafa00}
375span.icon>.fa{cursor:default}
376a span.icon>.fa{cursor:inherit}
377.admonitionblock td.icon [class^="fa icon-"]{font-size:2.5em;text-shadow:1px 1px 2px rgba(0,0,0,.5);cursor:default}
378.admonitionblock td.icon .icon-note::before{content:"\f05a";color:#19407c}
379.admonitionblock td.icon .icon-tip::before{content:"\f0eb";text-shadow:1px 1px 2px rgba(155,155,0,.8);color:#111}
380.admonitionblock td.icon .icon-warning::before{content:"\f071";color:#bf6900}
381.admonitionblock td.icon .icon-caution::before{content:"\f06d";color:#bf3400}
382.admonitionblock td.icon .icon-important::before{content:"\f06a";color:#bf0000}
383.conum[data-value]{display:inline-block;color:#fff!important;background-color:rgba(0,0,0,.8);-webkit-border-radius:100px;border-radius:100px;text-align:center;font-size:.75em;width:1.67em;height:1.67em;line-height:1.67em;font-family:"Open Sans","DejaVu Sans",sans-serif;font-style:normal;font-weight:bold}
384.conum[data-value] *{color:#fff!important}
385.conum[data-value]+b{display:none}
386.conum[data-value]::after{content:attr(data-value)}
387pre .conum[data-value]{position:relative;top:-.125em}
388b.conum *{color:inherit!important}
389.conum:not([data-value]):empty{display:none}
390dt,th.tableblock,td.content,div.footnote{text-rendering:optimizeLegibility}
391h1,h2,p,td.content,span.alt{letter-spacing:-.01em}
392p strong,td.content strong,div.footnote strong{letter-spacing:-.005em}
393p,blockquote,dt,td.content,span.alt{font-size:1.0625rem}
394p{margin-bottom:1.25rem}
395.sidebarblock p,.sidebarblock dt,.sidebarblock td.content,p.tableblock{font-size:1em}
396.exampleblock>.content{background-color:#fffef7;border-color:#e0e0dc;-webkit-box-shadow:0 1px 4px #e0e0dc;box-shadow:0 1px 4px #e0e0dc}
397.print-only{display:none!important}
398@page{margin:1.25cm .75cm}
399@media print{*{-webkit-box-shadow:none!important;box-shadow:none!important;text-shadow:none!important}
400html{font-size:80%}
401a{color:inherit!important;text-decoration:underline!important}
402a.bare,a[href^="#"],a[href^="mailto:"]{text-decoration:none!important}
403a[href^="http:"]:not(.bare)::after,a[href^="https:"]:not(.bare)::after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em}
404abbr[title]::after{content:" (" attr(title) ")"}
405pre,blockquote,tr,img,object,svg{page-break-inside:avoid}
406thead{display:table-header-group}
407svg{max-width:100%}
408p,blockquote,dt,td.content{font-size:1em;orphans:3;widows:3}
409h2,h3,#toctitle,.sidebarblock>.content>.title{page-break-after:avoid}
410#toc,.sidebarblock,.exampleblock>.content{background:none!important}
411#toc{border-bottom:1px solid #ddddd8!important;padding-bottom:0!important}
412body.book #header{text-align:center}
413body.book #header>h1:first-child{border:0!important;margin:2.5em 0 1em}
414body.book #header .details{border:0!important;display:block;padding:0!important}
415body.book #header .details span:first-child{margin-left:0!important}
416body.book #header .details br{display:block}
417body.book #header .details br+span::before{content:none!important}
418body.book #toc{border:0!important;text-align:left!important;padding:0!important;margin:0!important}
419body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-break-before:always}
420.listingblock code[data-lang]::before{display:block}
421#footer{padding:0 .9375em}
422.hide-on-print{display:none!important}
423.print-only{display:block!important}
424.hide-for-print{display:none!important}
425.show-for-print{display:inherit!important}}
426@media print,amzn-kf8{#header>h1:first-child{margin-top:1.25rem}
427.sect1{padding:0!important}
428.sect1+.sect1{border:0}
429#footer{background:none}
430#footer-text{color:rgba(0,0,0,.6);font-size:.9em}}
431@media amzn-kf8{#header,#content,#footnotes,#footer{padding:0}}
432</style>
433<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
434<style>
435/* Stylesheet for CodeRay to match GitHub theme | MIT License | http://foundation.zurb.com */
436/*pre.CodeRay {background-color:#f7f7f8;}*/
437.CodeRay .line-numbers{border-right:1px solid #d8d8d8;padding:0 0.5em 0 .25em}
438.CodeRay span.line-numbers{display:inline-block;margin-right:.5em;color:rgba(0,0,0,.3)}
439.CodeRay .line-numbers strong{color:rgba(0,0,0,.4)}
440table.CodeRay{border-collapse:separate;border-spacing:0;margin-bottom:0;border:0;background:none}
441table.CodeRay td{vertical-align: top;line-height:1.45}
442table.CodeRay td.line-numbers{text-align:right}
443table.CodeRay td.line-numbers>pre{padding:0;color:rgba(0,0,0,.3)}
444table.CodeRay td.code{padding:0 0 0 .5em}
445table.CodeRay td.code>pre{padding:0}
446.CodeRay .debug{color:#fff !important;background:#000080 !important}
447.CodeRay .annotation{color:#007}
448.CodeRay .attribute-name{color:#000080}
449.CodeRay .attribute-value{color:#700}
450.CodeRay .binary{color:#509}
451.CodeRay .comment{color:#998;font-style:italic}
452.CodeRay .char{color:#04d}
453.CodeRay .char .content{color:#04d}
454.CodeRay .char .delimiter{color:#039}
455.CodeRay .class{color:#458;font-weight:bold}
456.CodeRay .complex{color:#a08}
457.CodeRay .constant,.CodeRay .predefined-constant{color:#008080}
458.CodeRay .color{color:#099}
459.CodeRay .class-variable{color:#369}
460.CodeRay .decorator{color:#b0b}
461.CodeRay .definition{color:#099}
462.CodeRay .delimiter{color:#000}
463.CodeRay .doc{color:#970}
464.CodeRay .doctype{color:#34b}
465.CodeRay .doc-string{color:#d42}
466.CodeRay .escape{color:#666}
467.CodeRay .entity{color:#800}
468.CodeRay .error{color:#808}
469.CodeRay .exception{color:inherit}
470.CodeRay .filename{color:#099}
471.CodeRay .function{color:#900;font-weight:bold}
472.CodeRay .global-variable{color:#008080}
473.CodeRay .hex{color:#058}
474.CodeRay .integer,.CodeRay .float{color:#099}
475.CodeRay .include{color:#555}
476.CodeRay .inline{color:#000}
477.CodeRay .inline .inline{background:#ccc}
478.CodeRay .inline .inline .inline{background:#bbb}
479.CodeRay .inline .inline-delimiter{color:#d14}
480.CodeRay .inline-delimiter{color:#d14}
481.CodeRay .important{color:#555;font-weight:bold}
482.CodeRay .interpreted{color:#b2b}
483.CodeRay .instance-variable{color:#008080}
484.CodeRay .label{color:#970}
485.CodeRay .local-variable{color:#963}
486.CodeRay .octal{color:#40e}
487.CodeRay .predefined{color:#369}
488.CodeRay .preprocessor{color:#579}
489.CodeRay .pseudo-class{color:#555}
490.CodeRay .directive{font-weight:bold}
491.CodeRay .type{font-weight:bold}
492.CodeRay .predefined-type{color:inherit}
493.CodeRay .reserved,.CodeRay .keyword {color:#000;font-weight:bold}
494.CodeRay .key{color:#808}
495.CodeRay .key .delimiter{color:#606}
496.CodeRay .key .char{color:#80f}
497.CodeRay .value{color:#088}
498.CodeRay .regexp .delimiter{color:#808}
499.CodeRay .regexp .content{color:#808}
500.CodeRay .regexp .modifier{color:#808}
501.CodeRay .regexp .char{color:#d14}
502.CodeRay .regexp .function{color:#404;font-weight:bold}
503.CodeRay .string{color:#d20}
504.CodeRay .string .string .string{background:#ffd0d0}
505.CodeRay .string .content{color:#d14}
506.CodeRay .string .char{color:#d14}
507.CodeRay .string .delimiter{color:#d14}
508.CodeRay .shell{color:#d14}
509.CodeRay .shell .delimiter{color:#d14}
510.CodeRay .symbol{color:#990073}
511.CodeRay .symbol .content{color:#a60}
512.CodeRay .symbol .delimiter{color:#630}
513.CodeRay .tag{color:#008080}
514.CodeRay .tag-special{color:#d70}
515.CodeRay .variable{color:#036}
516.CodeRay .insert{background:#afa}
517.CodeRay .delete{background:#faa}
518.CodeRay .change{color:#aaf;background:#007}
519.CodeRay .head{color:#f8f;background:#505}
520.CodeRay .insert .insert{color:#080}
521.CodeRay .delete .delete{color:#800}
522.CodeRay .change .change{color:#66f}
523.CodeRay .head .head{color:#f4f}
524</style>
525<link rel="stylesheet" href="../katex/katex.min.css">
526<script src="../katex/katex.min.js"></script>
527<script src="../katex/contrib/auto-render.min.js"></script>
528    <!-- Use KaTeX to render math once document is loaded, see
529         https://github.com/Khan/KaTeX/tree/master/contrib/auto-render -->
530<script>
531    document.addEventListener("DOMContentLoaded", function () {
532        renderMathInElement(
533            document.body,
534            {
535                delimiters: [
536                    { left: "$$", right: "$$", display: true},
537                    { left: "\\[", right: "\\]", display: true},
538                    { left: "$", right: "$", display: false},
539                    { left: "\\(", right: "\\)", display: false}
540                ]
541            }
542        );
543    });
544</script></head>
545<body class="book toc2 toc-left" style="max-width: 100;">
546<div id="header">
547<h1>The OpenGL<sup>&#174;</sup> Shading Language, Version 4.60.7</h1>
548<div class="details">
549<span id="author" class="author">John Kessenich, Google (Editor and Author) ; Dave Baldwin and Randi Rost (Version 1.1 Authors)</span><br>
550<span id="revnumber">version 4.60.7,</span>
551<span id="revdate">Wed, 10 Jul 2019 20:42:58 +0000</span>
552<br><span id="revremark">Git branch information not available</span>
553</div>
554<div id="toc" class="toc2">
555<div id="toctitle">Table of Contents</div>
556<ul class="sectlevel1">
557<li><a href="#introduction">1. Introduction</a>
558<ul class="sectlevel2">
559<li><a href="#changes">1.1. Changes</a></li>
560<li><a href="#overview">1.2. Overview</a></li>
561<li><a href="#error-handling">1.3. Error Handling</a></li>
562<li><a href="#typographical-conventions">1.4. Typographical Conventions</a></li>
563<li><a href="#deprecation">1.5. Deprecation</a></li>
564</ul>
565</li>
566<li><a href="#overview-of-opengl-shading">2. Overview of Shading</a>
567<ul class="sectlevel2">
568<li><a href="#vertex-processor">2.1. Vertex Processor</a></li>
569<li><a href="#tessellation-control-processor">2.2. Tessellation Control Processor</a></li>
570<li><a href="#tessellation-evaluation-processor">2.3. Tessellation Evaluation Processor</a></li>
571<li><a href="#geometry-processor">2.4. Geometry Processor</a></li>
572<li><a href="#fragment-processor">2.5. Fragment Processor</a></li>
573<li><a href="#compute-processor">2.6. Compute Processor</a></li>
574</ul>
575</li>
576<li><a href="#basics">3. Basics</a>
577<ul class="sectlevel2">
578<li><a href="#character-set">3.1. Character Set and Phases of Compilation</a></li>
579<li><a href="#source-strings">3.2. Source Strings</a></li>
580<li><a href="#preprocessor">3.3. Preprocessor</a></li>
581<li><a href="#comments">3.4. Comments</a></li>
582<li><a href="#tokens">3.5. Tokens</a></li>
583<li><a href="#keywords">3.6. Keywords</a></li>
584<li><a href="#identifiers">3.7. Identifiers</a></li>
585<li><a href="#definitions">3.8. Definitions</a></li>
586</ul>
587</li>
588<li><a href="#variables-and-types">4. Variables and Types</a>
589<ul class="sectlevel2">
590<li><a href="#basic-types">4.1. Basic Types</a></li>
591<li><a href="#scoping">4.2. Scoping</a></li>
592<li><a href="#storage-qualifiers">4.3. Storage Qualifiers</a></li>
593<li><a href="#layout-qualifiers">4.4. Layout Qualifiers</a></li>
594<li><a href="#interpolation-qualifiers">4.5. Interpolation Qualifiers</a></li>
595<li><a href="#parameter-qualifiers">4.6. Parameter Qualifiers</a></li>
596<li><a href="#precision-and-precision-qualifiers">4.7. Precision and Precision Qualifiers</a></li>
597<li><a href="#variance-and-the-invariant-qualifier">4.8. Variance and the Invariant Qualifier</a></li>
598<li><a href="#the-precise-qualifier">4.9. The Precise Qualifier</a></li>
599<li><a href="#memory-qualifiers">4.10. Memory Qualifiers</a></li>
600<li><a href="#specialization-constant-qualifier">4.11. Specialization-Constant Qualifier</a></li>
601<li><a href="#order-of-qualification">4.12. Order and Repetition of Qualification</a></li>
602<li><a href="#empty-declarations">4.13. Empty Declarations</a></li>
603</ul>
604</li>
605<li><a href="#operators-and-expressions">5. Operators and Expressions</a>
606<ul class="sectlevel2">
607<li><a href="#operators">5.1. Operators</a></li>
608<li><a href="#array-operations">5.2. Array Operations</a></li>
609<li><a href="#function-calls">5.3. Function Calls</a></li>
610<li><a href="#constructors">5.4. Constructors</a></li>
611<li><a href="#vector-components">5.5. Vector and Scalar Components and Length</a></li>
612<li><a href="#matrix-components">5.6. Matrix Components</a></li>
613<li><a href="#structure-and-array-operations">5.7. Structure and Array Operations</a></li>
614<li><a href="#assignments">5.8. Assignments</a></li>
615<li><a href="#expressions">5.9. Expressions</a></li>
616<li><a href="#vector-and-matrix-operations">5.10. Vector and Matrix Operations</a></li>
617<li><a href="#out-of-bounds-accesses">5.11. Out-of-Bounds Accesses</a></li>
618<li><a href="#specialization-constant-operations">5.12. Specialization-Constant Operations</a></li>
619</ul>
620</li>
621<li><a href="#statements-and-structure">6. Statements and Structure</a>
622<ul class="sectlevel2">
623<li><a href="#function-definitions">6.1. Function Definitions</a></li>
624<li><a href="#selection">6.2. Selection</a></li>
625<li><a href="#iteration">6.3. Iteration</a></li>
626<li><a href="#jumps">6.4. Jumps</a></li>
627</ul>
628</li>
629<li><a href="#built-in-variables">7. Built-In Variables</a>
630<ul class="sectlevel2">
631<li><a href="#built-in-language-variables">7.1. Built-In Language Variables</a></li>
632<li><a href="#compatibility-profile-vertex-shader-built-in-inputs">7.2. Compatibility Profile Vertex Shader Built-In Inputs</a></li>
633<li><a href="#built-in-constants">7.3. Built-In Constants</a></li>
634<li><a href="#built-in-uniform-state">7.4. Built-In Uniform State</a></li>
635<li><a href="#redeclaring-built-in-blocks">7.5. Redeclaring Built-In Blocks</a></li>
636</ul>
637</li>
638<li><a href="#built-in-functions">8. Built-In Functions</a>
639<ul class="sectlevel2">
640<li><a href="#angle-and-trigonometry-functions">8.1. Angle and Trigonometry Functions</a></li>
641<li><a href="#exponential-functions">8.2. Exponential Functions</a></li>
642<li><a href="#common-functions">8.3. Common Functions</a></li>
643<li><a href="#floating-point-pack-and-unpack-functions">8.4. Floating-Point Pack and Unpack Functions</a></li>
644<li><a href="#geometric-functions">8.5. Geometric Functions</a></li>
645<li><a href="#matrix-functions">8.6. Matrix Functions</a></li>
646<li><a href="#vector-relational-functions">8.7. Vector Relational Functions</a></li>
647<li><a href="#integer-functions">8.8. Integer Functions</a></li>
648<li><a href="#texture-functions">8.9. Texture Functions</a></li>
649<li><a href="#atomic-counter-functions">8.10. Atomic Counter Functions</a></li>
650<li><a href="#atomic-memory-functions">8.11. Atomic Memory Functions</a></li>
651<li><a href="#image-functions">8.12. Image Functions</a></li>
652<li><a href="#geometry-shader-functions">8.13. Geometry Shader Functions</a></li>
653<li><a href="#fragment-processing-functions">8.14. Fragment Processing Functions</a></li>
654<li><a href="#noise-functions">8.15. Noise Functions</a></li>
655<li><a href="#shader-invocation-control-functions">8.16. Shader Invocation Control Functions</a></li>
656<li><a href="#shader-memory-control-functions">8.17. Shader Memory Control Functions</a></li>
657<li><a href="#_subpass_input_functions">8.18. Subpass-Input Functions</a></li>
658<li><a href="#shader-invocation-group-functions">8.19. Shader Invocation Group Functions</a></li>
659</ul>
660</li>
661<li><a href="#shading-language-grammar">9. Shading Language Grammar</a></li>
662<li><a href="#acknowledgments">10. Acknowledgments</a></li>
663<li><a href="#references">11. Normative References</a></li>
664<li><a href="#_non_normative_spir_v_mappings">12. Non-Normative SPIR-V Mappings</a>
665<ul class="sectlevel2">
666<li><a href="#_feature_comparisons">12.1. Feature Comparisons</a></li>
667<li><a href="#_mapping_from_glsl_to_spir_v">12.2. Mapping from GLSL to SPIR-V</a></li>
668</ul>
669</li>
670</ul>
671</div>
672</div>
673<div id="content">
674<div id="preamble">
675<div class="sectionbody">
676<div style="page-break-after: always;"></div>
677<div class="paragraph">
678<p>Copyright &#169; 2008-2018 The Khronos Group Inc. All Rights Reserved.</p>
679</div>
680<div class="paragraph">
681<p>This specification is protected by copyright laws and contains material
682proprietary to the Khronos Group, Inc. It or any components may not be
683reproduced, republished, distributed, transmitted, displayed, broadcast,
684or otherwise exploited in any manner without the express prior written
685permission of Khronos Group. You may use this specification for
686implementing the functionality therein, without altering or removing any
687trademark, copyright or other notice from the specification, but the
688receipt or possession of this specification does not convey any rights
689to reproduce, disclose, or distribute its contents, or to manufacture,
690use, or sell anything that it may describe, in whole or in part.</p>
691</div>
692<div class="paragraph">
693<p>Khronos Group grants express permission to any current Promoter,
694Contributor or Adopter member of Khronos to copy and redistribute
695UNMODIFIED versions of this specification in any fashion, provided that
696NO CHARGE is made for the specification and the latest available update
697of the specification for any version of the API is used whenever
698possible. Such distributed specification may be reformatted AS LONG AS
699the contents of the specification are not changed in any way. The
700specification may be incorporated into a product that is sold as long as
701such product includes significant independent work developed by the
702seller. A link to the current version of this specification on the
703Khronos Group website should be included whenever possible with
704specification distributions.</p>
705</div>
706<div class="paragraph">
707<p>Khronos Group makes no, and expressly disclaims any, representations or
708warranties, express or implied, regarding this specification, including,
709without limitation, any implied warranties of merchantability or fitness
710for a particular purpose or noninfringement of any intellectual
711property. Khronos Group makes no, and expressly disclaims any,
712warranties, express or implied, regarding the correctness, accuracy,
713completeness, timeliness, and reliability of the specification. Under no
714circumstances will the Khronos Group, or any of its Promoters,
715Contributors or Members or their respective partners, officers,
716directors, employees, agents, or representatives be liable for any
717damages, whether direct, indirect, special or consequential damages for
718lost revenues, lost profits, or otherwise, arising from or in connection
719with these materials.</p>
720</div>
721<div class="paragraph">
722<p>Khronos, Vulkan, SYCL, SPIR, WebGL, EGL, COLLADA, StreamInput, OpenVX,
723OpenKCam, glTF, OpenKODE, OpenVG, OpenWF, OpenSL ES, OpenMAX, OpenMAX
724AL, OpenMAX IL and OpenMAX DL are trademarks and WebCL is a
725certification mark of the Khronos Group Inc. OpenCL is a trademark of
726Apple Inc. and OpenGL and OpenML are registered trademarks and the
727OpenGL ES and OpenGL SC logos are trademarks of Silicon Graphics
728International used under license by Khronos. All other product names,
729trademarks, and/or company names are used solely for identification and
730belong to their respective owners.</p>
731</div>
732<div style="page-break-after: always;"></div>
733<!-- toc disabled -->
734</div>
735</div>
736<div class="sect1">
737<h2 id="introduction">1. Introduction</h2>
738<div class="sectionbody">
739<div class="paragraph">
740<p>This document specifies only version 4.60 of the OpenGL Shading Language (GLSL).
741It requires __VERSION__ to substitute 460, and requires
742<strong>#version</strong> to accept only
743<code>460</code>.
744If <strong>#version</strong> is declared with a smaller number, the language accepted is a
745previous version of the shading language, which will be supported depending
746on the version and type of context in the API.
747See the <a href="#references">normative references</a> for details on what language
748versions are supported.</p>
749</div>
750<div class="paragraph">
751<p>Previous versions of the OpenGL Shading Language, as well as the OpenGL ES Shading Language,
752are not strict subsets of the version specified here, particularly with
753respect to precision, name-hiding rules, and treatment of interface
754variables.
755See the specification corresponding to a particular language version for
756details specific to that version of the language.</p>
757</div>
758<div class="paragraph">
759<p>Throughout, when generating SPIR-V for consumption by the Vulkan API
760(see <a href="#references">normative references</a>), this will be said to be
761<em>targeting Vulkan</em>.</p>
762</div>
763<div class="paragraph">
764<p>While this specification and the OpenGL Specification are normative for OpenGL Shading Language, for
765SPIR-V generation it is still the SPIR-V specification and the SPIR-V client
766API specification that are normative for the generated SPIR-V.
767See the <a href="#references">normative references</a> for further detail.</p>
768</div>
769<div class="paragraph">
770<p>For SPIR-V generation, the SPIR-V client API specifies the commands used to
771manipulate SPIR-V shaders.</p>
772</div>
773<div class="paragraph">
774<p>Independent offline tool chains will compile GLSL down to the SPIR-V
775intermediate language.
776SPIR-V generation is not enabled with a <strong>#extension</strong>, <strong>#version</strong>, or a
777profile.
778Instead, use of GLSL for SPIR-V is determined by offline tool-chain use.
779See the documentation of such tools to see how to request generation of
780SPIR-V for its client API.</p>
781</div>
782<div class="paragraph">
783<p>GLSL &#8594; SPIR-V compilers must be directed as to what SPIR-V <strong>Capabilities</strong>
784are legal at run-time and give errors for GLSL feature use outside those
785capabilities.
786This is also true for implementation-dependent limits that can be error
787checked by the front-end against built-in constants present in the GLSL
788source: the front-end can be informed of such limits, and report errors when
789they are exceeded.</p>
790</div>
791<div class="paragraph">
792<p>SPIR-V features that are not controlled by a SPIR-V capability, but do have an
793equivalent GLSL counterpart (stages, built-in functions, types, limits, etc.)
794are only expected to work on OpenGL drivers that support the GLSL counterpart.</p>
795</div>
796<div class="paragraph">
797<p>All references in this specification to the <a href="#references">OpenGL Specification</a> are to
798the Core profile of version 4.6, unless a different profile is
799specified.</p>
800</div>
801<div class="sect2">
802<h3 id="changes">1.1. Changes</h3>
803<div class="sect3">
804<h4 id="_changes_from_revision_6_of_glsl_4_6">1.1.1. Changes from Revision 6 of GLSL 4.6</h4>
805<div class="ulist">
806<ul>
807<li>
808<p>Incorporated the GL_KHR_vulkan_glsl specification.</p>
809</li>
810<li>
811<p>Add note in the introduction about presence in drivers of SPIR-V features,
812as they relate to GLSL features.</p>
813</li>
814<li>
815<p>Clarify it is same location that triggers default-uniform block matching
816rules.
817See <a href="#uniform-variable-layout-qualifiers">Uniform Variable Layout Qualifiers</a>.</p>
818</li>
819</ul>
820</div>
821</div>
822<div class="sect3">
823<h4 id="_changes_from_revision_5_of_glsl_4_6">1.1.2. Changes from Revision 5 of GLSL 4.6</h4>
824<div class="ulist">
825<ul>
826<li>
827<p>Private GLSL issue #34: Clarify/consolidate implicit conversion rules from int &#8594; uint
828to be the same as explicit construction.</p>
829</li>
830<li>
831<p>Private GLSL issue #24: Clarify that <strong>barrier</strong>() by itself is enough to synchronize
832both control flow and memory accesses to <strong>shared</strong> variables and tessellation
833control output variables. For other memory accesses an additional memory
834barrier is still required.</p>
835</li>
836<li>
837<p>Normatively reference IEEE-754 for definitions of floating-point formats.</p>
838</li>
839<li>
840<p>Private GLSL issue 36: <strong>refract</strong> function on <strong>double</strong> types requires eta
841argument to have type <strong>double</strong>.</p>
842</li>
843<li>
844<p>Clarify restrictions on input variables in tessellation and geometry stages.</p>
845</li>
846<li>
847<p>Private GLSL issue 15: Clarify the ordering of bindings for arrays of arrays.</p>
848</li>
849<li>
850<p>Private GLSL issue 14: Uniform variables need only match at link time if they
851are statically used.</p>
852</li>
853<li>
854<p>For <strong>precise</strong> computations, the controlling expressions for
855control flow and ternary operators (<strong>?:</strong>) are not included.</p>
856</li>
857</ul>
858</div>
859</div>
860<div class="sect3">
861<h4 id="_changes_from_revision_4_of_glsl_4_6">1.1.3. Changes from Revision 4 of GLSL 4.6</h4>
862<div class="ulist">
863<ul>
864<li>
865<p>Private bug 13012: Clarified that builtin uniform variables might only
866be available in the fragment stage.</p>
867</li>
868<li>
869<p>Private bug 13837: Ternary and sequence operators may operate on <strong>void</strong> types.</p>
870</li>
871<li>
872<p>Clarified that errors arising from preprocessing must be returned at compile time.</p>
873</li>
874<li>
875<p>Clarified that access to any part of a variable constitutes a static use.</p>
876</li>
877<li>
878<p>Private GLSL issue 19: A statement is required following any label at the end of a <strong>switch</strong>.</p>
879</li>
880<li>
881<p>Private GLSL issue 26: <strong>noise</strong> is not valid when compiling for SPIR-V.</p>
882</li>
883<li>
884<p>Private GLSL issue 20: <strong>length</strong>() expressions returning a constant value may not
885contain side effects.</p>
886</li>
887<li>
888<p>Public OpenGL-API issue 7: Variables can be declared as both <strong>readonly</strong>
889and <strong>writeonly</strong>.</p>
890</li>
891<li>
892<p>Private GLSL issue 16: Use of constant expressions within <strong>#line</strong> directives is undefined.</p>
893</li>
894<li>
895<p>Corrected return type of <strong>imageAtomicExchange</strong> on <strong>float</strong> images.</p>
896</li>
897<li>
898<p>Private GLSL issue 32: Remove <strong>length</strong>() method contradiction:
899Non runtime-sized arrays only support <strong>length</strong>() on explicitly
900sized arrays.</p>
901</li>
902<li>
903<p>Private GLSL issue 21: Clarified the l-value restriction on <strong>interpolateAt</strong>.</p>
904</li>
905<li>
906<p>Private OpenGL-API issue 53: Clarified bit-width requirements for location aliasing.</p>
907</li>
908<li>
909<p>Public GLSL issue 15: <strong>gl_in</strong> can be redeclared using unsized-array syntax.</p>
910</li>
911<li>
912<p>Clarification of the formats needed for DEPTH_COMPONENT and
913STENCIL_COMPONENT for depth/stencil textures.</p>
914</li>
915<li>
916<p>Added image formats to the layout-qualifier table in the
917<a href="#layout-qualifiers">Layout Qualifiers</a> section.</p>
918</li>
919</ul>
920</div>
921</div>
922<div class="sect3">
923<h4 id="_changes_from_revision_3_of_glsl_4_6">1.1.4. Changes from Revision 3 of GLSL 4.6</h4>
924<div class="ulist">
925<ul>
926<li>
927<p>Private GLSL issue 13: Fix misspelling of <strong>allInvocationsEqual</strong>().
928(The one in the table was incorrectly listed as <strong>anyInvocationsEqual</strong>(),
929other spellings were correct.)</p>
930</li>
931</ul>
932</div>
933</div>
934<div class="sect3">
935<h4 id="_summary_of_changes_from_revision_7_of_glsl_version_4_50">1.1.5. Summary of Changes from Revision 7 of GLSL Version 4.50</h4>
936<div class="ulist">
937<ul>
938<li>
939<p>Incorporated the GL_ARB_shader_atomic_counter_ops extension.</p>
940</li>
941<li>
942<p>Incorporated the GL_ARB_shader_draw_parameters extension.</p>
943</li>
944<li>
945<p>Incorporated the GL_ARB_shader_group_vote extension.</p>
946</li>
947<li>
948<p>Incorporated the GL_ARB_gl_spirv extension.</p>
949</li>
950<li>
951<p>Private Bug 16070: Allow extra semi-colons at global scope.</p>
952</li>
953<li>
954<p>Private GLSL Issue 5: Be explicit that &#8220;fail to link&#8221; is really
955&#8220;compile-time or link-time error&#8221;, for some forms of error.</p>
956</li>
957<li>
958<p>Private GLSL Issue 7: Change <em>gl_MaxComputeUniformComponents</em> to 1024.</p>
959</li>
960<li>
961<p>Private OpenGL API Issue 35: Require location on transparent individual
962uniform variables for SPIR-V.</p>
963</li>
964<li>
965<p>Private GLSL Issue 8: Be more clear an <strong>interpolateAt</strong>() interpolant can
966be a structure member.</p>
967</li>
968<li>
969<p>Private GLSL Issue 9: Specify how <strong>xfb_buffer</strong> interacts with a block
970array: the capturing buffer increments for each block array element.</p>
971</li>
972</ul>
973</div>
974</div>
975</div>
976<div class="sect2">
977<h3 id="overview">1.2. Overview</h3>
978<div class="paragraph">
979<p>This document describes <em>The OpenGL Shading Language, version 4.60</em>.</p>
980</div>
981<div class="paragraph">
982<p>Independent compilation units written in this language are called <em>shaders</em>.
983A <em>program</em> is a set of shaders that are compiled and linked
984together,
985completely creating one or more of the programmable stages of the
986API pipeline.
987All the shaders for a single programmable stage must be within the same
988program.
989A complete set of programmable stages can be put into a single program or
990the stages can be partitioned across multiple programs.
991The aim of this document is to thoroughly specify the programming language.
992The <a href="#references">normative references</a> will specify the API entry points
993used to manipulate and communicate with programs and shaders.</p>
994</div>
995</div>
996<div class="sect2">
997<h3 id="error-handling">1.3. Error Handling</h3>
998<div class="paragraph">
999<p>Compilers, in general, accept programs that are ill-formed, due to the
1000impossibility of detecting all ill-formed programs.
1001Portability is only ensured for well-formed programs, which this
1002specification describes.
1003Compilers are encouraged to detect ill-formed programs and issue diagnostic
1004messages, but are not required to do so for all cases.
1005Compile-time errors must be returned for lexically or grammatically
1006incorrect shaders.
1007Other errors are reported at compile time or link time as indicated.
1008Code that is &#8220;dead&#8221; must still be error checked.
1009For example:</p>
1010</div>
1011<div class="listingblock">
1012<div class="content">
1013<pre class="CodeRay highlight"><code data-lang="c++"><span class="keyword">if</span> (<span class="predefined-constant">false</span>)     <span class="comment">// changing false to true cannot uncover additional errors</span>
1014    statement; <span class="comment">// statement must be error checked regardless</span></code></pre>
1015</div>
1016</div>
1017</div>
1018<div class="sect2">
1019<h3 id="typographical-conventions">1.4. Typographical Conventions</h3>
1020<div class="paragraph">
1021<p>Italic, bold, and font choices have been used in this specification
1022primarily to improve readability.
1023Code fragments use a fixed width font.
1024Identifiers embedded in text are italicized.
1025Keywords embedded in text are bold.
1026Operators are called by their name, followed by their symbol in bold in
1027parentheses.
1028The clarifying grammar fragments in the text use bold for literals and
1029italics for non-terminals.
1030The official grammar in &#8220;<a href="#shading-language-grammar">Shading Language
1031Grammar</a>&#8221; uses all capitals for terminals and lower case for
1032non-terminals.</p>
1033</div>
1034</div>
1035<div class="sect2">
1036<h3 id="deprecation">1.5. Deprecation</h3>
1037<div class="paragraph">
1038<p>The OpenGL Shading Language has deprecated some features.
1039These are clearly called out in this specification as &#8220;deprecated&#8221;.
1040They are still present in this version of the language, but are targeted for
1041potential removal in a future version of the shading language.
1042The OpenGL API has a forward compatibility mode that will disallow use of
1043deprecated features.
1044If compiling in a mode where use of deprecated features is disallowed, their
1045use causes compile-time or link-time errors.
1046See the <a href="#references">OpenGL Specification</a> for details on what causes deprecated
1047language features to be accepted or to return an error.</p>
1048</div>
1049</div>
1050</div>
1051</div>
1052<div class="sect1">
1053<h2 id="overview-of-opengl-shading">2. Overview of Shading</h2>
1054<div class="sectionbody">
1055<div class="paragraph">
1056<p>The OpenGL Shading Language is actually several closely related languages.
1057These languages are used to create shaders for each of the programmable
1058processors contained in the API&#8217;s processing pipeline.
1059Currently, these processors are the vertex, tessellation control,
1060tessellation evaluation, geometry, fragment, and compute processors.</p>
1061</div>
1062<div class="paragraph">
1063<p>Unless otherwise noted in this paper, a language feature applies to all
1064languages, and common usage will refer to these languages as a single
1065language.
1066The specific languages will be referred to by the name of the processor they
1067target: vertex, tessellation control, tessellation evaluation, geometry,
1068fragment, or compute.</p>
1069</div>
1070<div class="paragraph">
1071<p>Most API state is not tracked or made available to shaders.
1072Typically, user-defined variables will be used for communicating between
1073different stages of the API pipeline.
1074However, a small amount of state is still tracked and automatically made
1075available to shaders, and there are a few built-in variables for interfaces
1076between different stages of the API pipeline.</p>
1077</div>
1078<div class="sect2">
1079<h3 id="vertex-processor">2.1. Vertex Processor</h3>
1080<div class="paragraph">
1081<p>The <em>vertex processor</em> is a programmable unit that operates on incoming
1082vertices and their associated data.
1083Compilation units written in the OpenGL Shading Language to run on this processor are called
1084<em>vertex shaders</em>.
1085When a set of vertex shaders are successfully compiled and linked, they
1086result in a <em>vertex shader executable</em> that runs on the vertex processor.</p>
1087</div>
1088<div class="paragraph">
1089<p>The vertex processor operates on one vertex at a time.
1090It does not replace graphics operations that require knowledge of several
1091vertices at a time.</p>
1092</div>
1093</div>
1094<div class="sect2">
1095<h3 id="tessellation-control-processor">2.2. Tessellation Control Processor</h3>
1096<div class="paragraph">
1097<p>The <em>tessellation control processor</em> is a programmable unit that operates on
1098a patch of incoming vertices and their associated data, emitting a new
1099output patch.
1100Compilation units written in the OpenGL Shading Language to run on this processor are called
1101tessellation control shaders.
1102When a set of tessellation control shaders are successfully compiled and
1103linked, they result in a <em>tessellation control shader executable</em> that runs
1104on the tessellation control processor.</p>
1105</div>
1106<div class="paragraph">
1107<p>The tessellation control shader is invoked for each vertex of the output
1108patch.
1109Each invocation can read the attributes of any vertex in the input or output
1110patches, but can only write per-vertex attributes for the corresponding
1111output patch vertex.
1112The shader invocations collectively produce a set of per-patch attributes
1113for the output patch.</p>
1114</div>
1115<div class="paragraph">
1116<p>After all tessellation control shader invocations have completed, the output
1117vertices and per-patch attributes are assembled to form a patch to be used
1118by subsequent pipeline stages.</p>
1119</div>
1120<div class="paragraph">
1121<p>Tessellation control shader invocations run mostly independently, with
1122undefined relative execution order.
1123However, the built-in function <strong>barrier</strong>() can be used to control execution
1124order by synchronizing invocations, effectively dividing tessellation
1125control shader execution into a set of phases.
1126Tessellation control shaders will get undefined results if one invocation
1127reads from a per-vertex or per-patch attribute written by another invocation
1128at any point during the same phase, or if two invocations attempt to write
1129different values to the same per-patch output
113032-bit component
1131in a single phase.</p>
1132</div>
1133</div>
1134<div class="sect2">
1135<h3 id="tessellation-evaluation-processor">2.3. Tessellation Evaluation Processor</h3>
1136<div class="paragraph">
1137<p>The <em>tessellation evaluation processor</em> is a programmable unit that
1138evaluates the position and other attributes of a vertex generated by the
1139tessellation primitive generator, using a patch of incoming vertices and
1140their associated data.
1141Compilation units written in the OpenGL Shading Language to run on this processor are called
1142tessellation evaluation shaders.
1143When a set of tessellation evaluation shaders are successfully compiled and
1144linked, they result in a <em>tessellation evaluation shader executable</em> that
1145runs on the tessellation evaluation processor.</p>
1146</div>
1147<div class="paragraph">
1148<p>Each invocation of the tessellation evaluation executable computes the
1149position and attributes of a single vertex generated by the tessellation
1150primitive generator.
1151The executable can read the attributes of any vertex in the input patch,
1152plus the tessellation coordinate, which is the relative location of the
1153vertex in the primitive being tessellated.
1154The executable writes the position and other attributes of the vertex.</p>
1155</div>
1156</div>
1157<div class="sect2">
1158<h3 id="geometry-processor">2.4. Geometry Processor</h3>
1159<div class="paragraph">
1160<p>The <em>geometry processor</em> is a programmable unit that operates on data for
1161incoming vertices for a primitive assembled after vertex processing and
1162outputs a sequence of vertices forming output primitives.
1163Compilation units written in the OpenGL Shading Language to run on this processor are called
1164<em>geometry shaders</em>.
1165When a set of geometry shaders are successfully compiled and linked, they
1166result in a <em>geometry shader executable</em> that runs on the geometry
1167processor.</p>
1168</div>
1169<div class="paragraph">
1170<p>A single invocation of the geometry shader executable on the geometry
1171processor will operate on a declared input primitive with a fixed number of
1172vertices.
1173This single invocation can emit a variable number of vertices that are
1174assembled into primitives of a declared output primitive type and passed to
1175subsequent pipeline stages.</p>
1176</div>
1177</div>
1178<div class="sect2">
1179<h3 id="fragment-processor">2.5. Fragment Processor</h3>
1180<div class="paragraph">
1181<p>The <em>fragment processor</em> is a programmable unit that operates on fragment
1182values and their associated data.
1183Compilation units written in the OpenGL Shading Language to run on this processor are called
1184<em>fragment shaders</em>.
1185When a set of fragment shaders are successfully compiled and linked, they
1186result in a <em>fragment shader executable</em> that runs on the fragment
1187processor.</p>
1188</div>
1189<div class="paragraph">
1190<p>A fragment shader cannot change a fragment&#8217;s (<em>x</em>, <em>y</em>) position.
1191Access to neighboring fragments is not allowed.
1192The values computed by the fragment shader are ultimately used to update
1193framebuffer memory or texture memory, depending on the current API
1194state and the API command that caused the fragments to be generated.</p>
1195</div>
1196</div>
1197<div class="sect2">
1198<h3 id="compute-processor">2.6. Compute Processor</h3>
1199<div class="paragraph">
1200<p>The <em>compute processor</em> is a programmable unit that operates independently
1201from the other shader processors.
1202Compilation units written in the OpenGL Shading Language to run on this processor are called
1203<em>compute shaders</em>.
1204When a set of compute shaders are successfully compiled and linked, they
1205result in a <em>compute shader executable</em> that runs on the compute processor.</p>
1206</div>
1207<div class="paragraph">
1208<p>A compute shader has access to many of the same resources as fragment and
1209other shader processors, such as textures, buffers, image variables, and
1210atomic counters.
1211It does not have fixed-function outputs.
1212It is not part of the graphics pipeline and its visible side effects are
1213through changes to images, storage buffers, and atomic counters.</p>
1214</div>
1215<div class="paragraph">
1216<p>A compute shader operates on a group of work items called a <em>workgroup</em>.
1217A workgroup is a collection of shader invocations that execute the same
1218code, potentially in parallel.
1219An invocation within a workgroup may share data with other members of the
1220same workgroup through shared variables and issue memory and control flow
1221barriers to synchronize with other members of the same workgroup.</p>
1222</div>
1223</div>
1224</div>
1225</div>
1226<div class="sect1">
1227<h2 id="basics">3. Basics</h2>
1228<div class="sectionbody">
1229<div class="sect2">
1230<h3 id="character-set">3.1. Character Set and Phases of Compilation</h3>
1231<div class="paragraph">
1232<p>The source character set used for the OpenGL Shading Language is Unicode in the UTF-8
1233encoding scheme.</p>
1234</div>
1235<div class="paragraph">
1236<p>After preprocessing, only the following characters are allowed in the
1237resulting stream of GLSL tokens:</p>
1238</div>
1239<div class="ulist">
1240<ul>
1241<li>
1242<p>The letters <strong>a-z</strong>, <strong>A-Z</strong>, and the underscore (<strong>_</strong>).</p>
1243</li>
1244<li>
1245<p>The numbers <strong>0-9</strong>.</p>
1246</li>
1247<li>
1248<p>The symbols period (<strong>.</strong>), plus (<strong>+</strong>), dash (<strong>-</strong>), slash (<strong>/</strong>), asterisk
1249(<strong>*</strong>), percent (<strong>%</strong>), angled brackets (<strong>&lt;</strong> and <strong>&gt;</strong>), square brackets
1250(<strong>[</strong> and <strong>]</strong>), parentheses (<strong>(</strong> and <strong>)</strong>), braces (<strong>{</strong> and <strong>}</strong>), caret
1251(<strong>^</strong>), vertical bar (<strong>|</strong>), ampersand (<strong>&amp;</strong>), tilde (<strong>~</strong>), equals (<strong>=</strong>),
1252exclamation point (<strong>!</strong>), colon (<strong>:</strong>), semicolon (<strong>;</strong>), comma (<strong>,</strong>), and
1253question mark (<strong>?</strong>).</p>
1254</li>
1255</ul>
1256</div>
1257<div class="paragraph">
1258<p>A compile-time error will be given if any other character is used in a GLSL
1259token.</p>
1260</div>
1261<div class="paragraph">
1262<p>There are no digraphs or trigraphs.
1263There are no escape sequences or other uses of the backslash beyond use as
1264the line-continuation character.</p>
1265</div>
1266<div class="paragraph">
1267<p>Lines are relevant for compiler diagnostic messages and the preprocessor.
1268They are terminated by carriage-return or line-feed.
1269If both are used together, it will count as only a single line termination.
1270For the remainder of this document, any of these combinations is simply
1271referred to as a new-line.
1272Lines may be of arbitrary length.</p>
1273</div>
1274<div class="paragraph">
1275<p>In general, the language&#8217;s use of this character set is case sensitive.</p>
1276</div>
1277<div class="paragraph">
1278<p>There are no character or string data types, so no quoting characters are
1279included.</p>
1280</div>
1281<div class="paragraph">
1282<p>There is no end-of-file character.</p>
1283</div>
1284<div class="paragraph">
1285<p>More formally, compilation happens as if the following logical phases were
1286executed in order:</p>
1287</div>
1288<div class="olist arabic">
1289<ol class="arabic">
1290<li>
1291<p>Source strings are concatenated to form a single input.
1292All provided new-lines are retained.</p>
1293</li>
1294<li>
1295<p>Line numbering is noted, based on all present new-lines, and does not
1296change when new-lines are later eliminated.</p>
1297</li>
1298<li>
1299<p>Wherever a backslash ('\') occurs immediately before a new-line, both
1300are eliminated.
1301(Note no white space is substituted, allowing a single token to span a
1302new-line.) Any newly formed backslash followed by a new-line is not
1303eliminated; only those pairs originally occurring after phase 1 are
1304eliminated.</p>
1305</li>
1306<li>
1307<p>All comments are replaced with a single space.
1308(Note that '//' style comments end before their terminating new-lines
1309and white space is generally relevant to preprocessing.)</p>
1310</li>
1311<li>
1312<p>Preprocessing is done, resulting in a sequence of GLSL tokens, formed
1313from the character set stated above.</p>
1314</li>
1315<li>
1316<p>GLSL processing is done on the sequence of GLSL tokens.</p>
1317</li>
1318</ol>
1319</div>
1320<div class="paragraph">
1321<p>Details that fully define source strings, comments, line numbering, new-line
1322elimination, and preprocessing are all discussed in upcoming sections.
1323Sections beyond those describe GLSL processing.</p>
1324</div>
1325</div>
1326<div class="sect2">
1327<h3 id="source-strings">3.2. Source Strings</h3>
1328<div class="paragraph">
1329<p>The source for a single shader is an array of strings of characters from the
1330character set.
1331A single shader is made from the concatenation of these strings.
1332Each string can contain multiple lines, separated by new-lines.
1333No new-lines need be present in a string; a single line can be formed from
1334multiple strings.
1335No new-lines or other characters are inserted by the implementation when it
1336concatenates the strings to form a single shader.
1337Multiple shaders can be linked together to form a single program.</p>
1338</div>
1339<div class="paragraph">
1340<p>Diagnostic messages returned from compiling a shader must identify both the
1341line number within a string and which source string the message applies to.
1342Source strings are counted sequentially with the first string being string
13430.
1344Line numbers are one more than the number of new-lines that have been
1345processed, including counting the new-lines that will be removed by the
1346line-continuation character (<strong>\</strong>).</p>
1347</div>
1348<div class="paragraph">
1349<p>Lines separated by the line-continuation character preceding a new-line are
1350concatenated together before either comment processing or preprocessing.
1351This means that no white space is substituted for the line-continuation
1352character.
1353That is, a single token could be formed by the concatenation by taking the
1354characters at the end of one line concatenating them with the characters at
1355the beginning of the next line.</p>
1356</div>
1357<div class="listingblock">
1358<div class="content">
1359<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span> f\
1360oo;
1361<span class="comment">// forms a single line equivalent to &quot;float foo;&quot;</span>
1362<span class="comment">// (assuming '\' is the last character before the new-line and &quot;oo&quot; are</span>
1363<span class="comment">// the first two characters of the next line)</span></code></pre>
1364</div>
1365</div>
1366</div>
1367<div class="sect2">
1368<h3 id="preprocessor">3.3. Preprocessor</h3>
1369<div class="paragraph">
1370<p>There is a preprocessor that processes the source strings as part of the
1371compilation process.
1372Except as noted below, it behaves as the C++ standard preprocessor (see
1373&#8220;<a href="#references">Normative References</a>&#8221;).</p>
1374</div>
1375<div class="paragraph">
1376<p>The complete list of preprocessor directives is as follows.</p>
1377</div>
1378<div class="dlist">
1379<dl>
1380<dt class="hdlist1"></dt>
1381<dd>
1382<p>#<br>
1383#define<br>
1384#undef<br></p>
1385</dd>
1386<dt class="hdlist1"></dt>
1387<dd>
1388<p>#if<br>
1389#ifdef<br>
1390#ifndef<br>
1391#else<br>
1392#elif<br>
1393#endif<br></p>
1394</dd>
1395<dt class="hdlist1"></dt>
1396<dd>
1397<p>#error<br>
1398#pragma<br></p>
1399</dd>
1400<dt class="hdlist1"></dt>
1401<dd>
1402<p>#extension<br>
1403#version<br></p>
1404</dd>
1405<dt class="hdlist1"></dt>
1406<dd>
1407<p>#line</p>
1408</dd>
1409</dl>
1410</div>
1411<div class="paragraph">
1412<p>The following
1413operators are
1414also available:</p>
1415</div>
1416<div class="dlist">
1417<dl>
1418<dt class="hdlist1"></dt>
1419<dd>
1420<p>defined<br>
1421##</p>
1422</dd>
1423</dl>
1424</div>
1425<div class="paragraph">
1426<p>Each number sign (<strong>#</strong>) can be preceded in its line only by spaces or
1427horizontal tabs.
1428It may also be followed by spaces and horizontal tabs, preceding the
1429directive.
1430Each directive is terminated by a new-line.
1431Preprocessing does not change the number or relative location of new-lines
1432in a source string.
1433Preprocessing takes places after new-lines have been removed by the
1434line-continuation character.</p>
1435</div>
1436<div class="paragraph">
1437<p>The number sign (<strong>#</strong>) on a line by itself is ignored.
1438Any directive not listed above will cause a compile-time error.</p>
1439</div>
1440<div class="paragraph">
1441<p><strong>#define</strong> and <strong>#undef</strong> functionality are defined as is standard for C++
1442preprocessors for macro definitions both with and without macro parameters.</p>
1443</div>
1444<div class="paragraph">
1445<p>The following predefined macros are available:</p>
1446</div>
1447<div class="dlist">
1448<dl>
1449<dt class="hdlist1"></dt>
1450<dd>
1451<p>__LINE__<br>
1452__FILE__<br>
1453__VERSION__<br></p>
1454</dd>
1455</dl>
1456</div>
1457<div class="paragraph">
1458<p>__LINE__ will substitute a decimal integer constant that is one more than
1459the number of preceding new-lines in the current source string.</p>
1460</div>
1461<div class="paragraph">
1462<p>__FILE__ will substitute a decimal integer constant that says which source
1463string number is currently being processed.</p>
1464</div>
1465<div class="paragraph">
1466<p>__VERSION__ will substitute a decimal integer reflecting the version
1467number of the OpenGL Shading Language.
1468The version of the shading language described in this document will have
1469__VERSION__ substitute the decimal integer 460.</p>
1470</div>
1471<div class="paragraph">
1472<p>By convention, all macro names containing two consecutive underscores (__)
1473are reserved for use by underlying software layers.
1474Defining
1475or undefining
1476such a name in a shader does not itself result in an error, but may
1477result in unintended behaviors that stem from having multiple definitions of
1478the same name.
1479All macro names prefixed with &#8220;GL_&#8221; (&#8220;GL&#8221; followed by a single
1480underscore) are also reserved, and defining
1481or undefining
1482such a name results in a compile-time error.</p>
1483</div>
1484<div class="paragraph">
1485<p>Implementations must support macro-name lengths of up to 1024 characters.
1486Implementations are allowed to generate an error for a macro name of length
1487greater than 1024 characters, but are also allowed to support lengths
1488greater than 1024.</p>
1489</div>
1490<div class="paragraph">
1491<p><strong>#if</strong>, <strong>#ifdef</strong>, <strong>#ifndef</strong>, <strong>#else</strong>, <strong>#elif</strong>, and <strong>#endif</strong> are defined to
1492operate as is standard for C++ preprocessors except for the following:</p>
1493</div>
1494<div class="ulist">
1495<ul>
1496<li>
1497<p>Expressions following <strong>#if</strong> and <strong>#elif</strong> are
1498further restricted to
1499expressions operating on literal integer constants, plus identifiers
1500consumed by the <strong>defined</strong> operator.</p>
1501</li>
1502<li>
1503<p>Character constants are not supported.</p>
1504</li>
1505</ul>
1506</div>
1507<div class="paragraph">
1508<p>The operators available are as follows.</p>
1509</div>
1510<table class="tableblock frame-all grid-all stretch">
1511<colgroup>
1512<col style="width: 25%;">
1513<col style="width: 25%;">
1514<col style="width: 25%;">
1515<col style="width: 25%;">
1516</colgroup>
1517<thead>
1518<tr>
1519<th class="tableblock halign-left valign-top">Precedence</th>
1520<th class="tableblock halign-left valign-top">Operator class</th>
1521<th class="tableblock halign-left valign-top">Operators</th>
1522<th class="tableblock halign-left valign-top">Associativity</th>
1523</tr>
1524</thead>
1525<tbody>
1526<tr>
1527<td class="tableblock halign-left valign-top"><p class="tableblock">1 (highest)</p></td>
1528<td class="tableblock halign-left valign-top"><p class="tableblock">parenthetical grouping</p></td>
1529<td class="tableblock halign-left valign-top"><p class="tableblock">( )</p></td>
1530<td class="tableblock halign-left valign-top"><p class="tableblock">NA</p></td>
1531</tr>
1532<tr>
1533<td class="tableblock halign-left valign-top"><p class="tableblock">2</p></td>
1534<td class="tableblock halign-left valign-top"><p class="tableblock">unary</p></td>
1535<td class="tableblock halign-left valign-top"><p class="tableblock">defined<br>
1536                                         + - ~ !</p></td>
1537<td class="tableblock halign-left valign-top"><p class="tableblock">Right to Left</p></td>
1538</tr>
1539<tr>
1540<td class="tableblock halign-left valign-top"><p class="tableblock">3</p></td>
1541<td class="tableblock halign-left valign-top"><p class="tableblock">multiplicative</p></td>
1542<td class="tableblock halign-left valign-top"><p class="tableblock">* / %</p></td>
1543<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
1544</tr>
1545<tr>
1546<td class="tableblock halign-left valign-top"><p class="tableblock">4</p></td>
1547<td class="tableblock halign-left valign-top"><p class="tableblock">additive</p></td>
1548<td class="tableblock halign-left valign-top"><p class="tableblock">+ -</p></td>
1549<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
1550</tr>
1551<tr>
1552<td class="tableblock halign-left valign-top"><p class="tableblock">5</p></td>
1553<td class="tableblock halign-left valign-top"><p class="tableblock">bit-wise shift</p></td>
1554<td class="tableblock halign-left valign-top"><p class="tableblock">&lt;&lt; &gt;&gt;</p></td>
1555<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
1556</tr>
1557<tr>
1558<td class="tableblock halign-left valign-top"><p class="tableblock">6</p></td>
1559<td class="tableblock halign-left valign-top"><p class="tableblock">relational</p></td>
1560<td class="tableblock halign-left valign-top"><p class="tableblock">&lt; &gt; &lt;= &gt;=</p></td>
1561<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
1562</tr>
1563<tr>
1564<td class="tableblock halign-left valign-top"><p class="tableblock">7</p></td>
1565<td class="tableblock halign-left valign-top"><p class="tableblock">equality</p></td>
1566<td class="tableblock halign-left valign-top"><p class="tableblock">== !=</p></td>
1567<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
1568</tr>
1569<tr>
1570<td class="tableblock halign-left valign-top"><p class="tableblock">8</p></td>
1571<td class="tableblock halign-left valign-top"><p class="tableblock">bit-wise and</p></td>
1572<td class="tableblock halign-left valign-top"><p class="tableblock">&amp;</p></td>
1573<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
1574</tr>
1575<tr>
1576<td class="tableblock halign-left valign-top"><p class="tableblock">9</p></td>
1577<td class="tableblock halign-left valign-top"><p class="tableblock">bit-wise exclusive or</p></td>
1578<td class="tableblock halign-left valign-top"><p class="tableblock">^</p></td>
1579<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
1580</tr>
1581<tr>
1582<td class="tableblock halign-left valign-top"><p class="tableblock">10</p></td>
1583<td class="tableblock halign-left valign-top"><p class="tableblock">bit-wise inclusive or</p></td>
1584<td class="tableblock halign-left valign-top"><p class="tableblock">|</p></td>
1585<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
1586</tr>
1587<tr>
1588<td class="tableblock halign-left valign-top"><p class="tableblock">11</p></td>
1589<td class="tableblock halign-left valign-top"><p class="tableblock">logical and</p></td>
1590<td class="tableblock halign-left valign-top"><p class="tableblock">&amp;&amp;</p></td>
1591<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
1592</tr>
1593<tr>
1594<td class="tableblock halign-left valign-top"><p class="tableblock">12 (lowest)</p></td>
1595<td class="tableblock halign-left valign-top"><p class="tableblock">logical inclusive or</p></td>
1596<td class="tableblock halign-left valign-top"><p class="tableblock">||</p></td>
1597<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
1598</tr>
1599</tbody>
1600</table>
1601<div class="paragraph">
1602<p>The <strong>defined</strong> operator can be used in either of the following ways:</p>
1603</div>
1604<div class="listingblock">
1605<div class="content">
1606<pre class="CodeRay highlight"><code data-lang="c++">defined identifier
1607defined ( identifier )</code></pre>
1608</div>
1609</div>
1610<div class="paragraph">
1611<p>Two tokens in a macro can be concatenated into one token using the token
1612pasting (<strong>##</strong>) operator, as is standard for C++ preprocessors.
1613The result must be a valid single token, which will then be subject to macro
1614expansion.
1615That is, macro expansion happens only after token pasting.
1616There are no other number sign based operators (e.g. no <strong>#</strong> or <strong>#@</strong>), nor is
1617there a <strong>sizeof</strong> operator.</p>
1618</div>
1619<div class="paragraph">
1620<p>The semantics of applying operators to integer literals in the preprocessor
1621match those standard in the C++ preprocessor, not those in the OpenGL Shading Language.</p>
1622</div>
1623<div class="paragraph">
1624<p>Preprocessor expressions will be evaluated according to the behavior of the
1625host processor, not the processor targeted by the shader.</p>
1626</div>
1627<div class="paragraph">
1628<p><strong>#error</strong> will cause the implementation to put a compile-time diagnostic message
1629into the shader object&#8217;s information log (see section 7.12 &#8220;Shader, Program
1630and Program Pipeline Queries&#8221; of the <a href="#references">OpenGL Specification</a> for how to
1631access a shader object&#8217;s information log).
1632The message will be the tokens following the <strong>#error</strong> directive, up to the
1633first new-line.
1634The implementation must treat the presence of a <strong>#error</strong> directive as a
1635compile-time error.</p>
1636</div>
1637<div class="paragraph">
1638<p><strong>#pragma</strong> allows implementation-dependent compiler control.
1639Tokens following <strong>#pragma</strong> are not subject to preprocessor macro expansion.
1640If an implementation does not recognize the tokens following <strong>#pragma</strong>, then
1641it will ignore that pragma.
1642The following pragmas are defined as part of the language.</p>
1643</div>
1644<div class="listingblock">
1645<div class="content">
1646<pre class="CodeRay highlight"><code data-lang="c++"><span class="preprocessor">#pragma</span> STDGL</code></pre>
1647</div>
1648</div>
1649<div class="paragraph">
1650<p>The <strong>STDGL</strong> pragma is used to reserve pragmas for use by future revisions of
1651this language.
1652No implementation may use a pragma whose first token is <strong>STDGL</strong>.</p>
1653</div>
1654<div class="listingblock">
1655<div class="content">
1656<pre class="CodeRay highlight"><code data-lang="c++"><span class="preprocessor">#pragma</span> optimize(on)
1657<span class="preprocessor">#pragma</span> optimize(off)</code></pre>
1658</div>
1659</div>
1660<div class="paragraph">
1661<p>can be used to turn off optimizations as an aid in developing and debugging
1662shaders.
1663It can only be used outside function definitions.
1664By default, optimization is turned on for all shaders.
1665The debug pragma</p>
1666</div>
1667<div class="listingblock">
1668<div class="content">
1669<pre class="CodeRay highlight"><code data-lang="c++"><span class="preprocessor">#pragma</span> debug(on)
1670<span class="preprocessor">#pragma</span> debug(off)</code></pre>
1671</div>
1672</div>
1673<div class="paragraph">
1674<p>can be used to enable compiling and annotating a shader with debug
1675information, so that it can be used with a debugger.
1676It can only be used outside function definitions.
1677By default, debug is turned off.</p>
1678</div>
1679<div class="paragraph">
1680<p>Shaders should declare the version of the language they are written to.
1681The language version a shader is written to is specified by</p>
1682</div>
1683<div class="listingblock">
1684<div class="content">
1685<pre class="CodeRay highlight"><code data-lang="c++"><span class="preprocessor">#version</span> number profile_opt</code></pre>
1686</div>
1687</div>
1688<div class="paragraph">
1689<p>where <em>number</em> must be a version of the language, following the same
1690convention as __VERSION__ above.
1691The directive &#8220;<strong>#version 460</strong>&#8221; is required in any shader that
1692uses version 4.60 of the language.
1693Any <em>number</em> representing a version of the language a compiler does not
1694support will cause a compile-time error to be generated.
1695Version 1.10 of the language does not require shaders to include this
1696directive, and shaders that do not include a <strong>#version</strong> directive will be
1697treated as targeting version 1.10.
1698Shaders that specify <strong>#version</strong> 100 will be treated as targeting version
16991.00 of the OpenGL ES Shading Language.
1700Shaders that specify <strong>#version</strong> 300 will be treated as targeting version
17013.00 of the OpenGL ES Shading Language.
1702Shaders that specify <strong>#version</strong> 310 will be treated as targeting version
17033.10 of the OpenGL ES Shading Language.</p>
1704</div>
1705<div class="paragraph">
1706<p>If the optional <em>profile</em> argument is provided, it must be the name of an
1707OpenGL profile.
1708Currently, there are three choices:</p>
1709</div>
1710<div class="listingblock">
1711<div class="content">
1712<pre class="CodeRay highlight"><code data-lang="c++">core
1713compatibility
1714es</code></pre>
1715</div>
1716</div>
1717<div class="paragraph">
1718<p>A <em>profile</em> argument can only be used with version 150 or greater.
1719If no profile argument is provided and the version is 150 or greater, the
1720default is <strong>core</strong>.
1721If version 300 or 310 is specified, the profile argument is not optional and
1722must be <strong>es</strong>, or a compile-time error results.
1723The Language Specification for the <strong>es</strong> profile is specified in The OpenGL
1724ES Shading Language specification.</p>
1725</div>
1726<div class="paragraph">
1727<p>Shaders for the <strong>core</strong> or <strong>compatibility</strong> profiles that declare different
1728versions can be linked together.
1729However, <strong>es</strong> profile shaders cannot be linked with non-<strong>es</strong> profile shaders
1730or with <strong>es</strong> profile shaders of a different version, or a link-time error
1731will result.
1732When linking shaders of versions allowed by these rules, remaining link-time
1733errors will be given as per the linking rules in the GLSL version
1734corresponding to the version of the context the shaders are linked under.
1735Shader compile-time errors must still be given strictly based on the version
1736declared (or defaulted to) within each shader.</p>
1737</div>
1738<div class="paragraph">
1739<p>Unless otherwise specified, this specification is documenting the core
1740profile, and everything specified for the core profile is also available in
1741the compatibility profile.
1742Features specified as belonging specifically to the compatibility profile
1743are not available in the core profile.
1744Compatibility-profile features are not available when generating SPIR-V.</p>
1745</div>
1746<div class="paragraph">
1747<p>There is a built-in macro definition for each profile the implementation
1748supports.
1749All implementations provide the following macro:</p>
1750</div>
1751<div class="listingblock">
1752<div class="content">
1753<pre class="CodeRay highlight"><code data-lang="c++"><span class="preprocessor">#define</span> GL_core_profile <span class="integer">1</span></code></pre>
1754</div>
1755</div>
1756<div class="paragraph">
1757<p>Implementations providing the <strong>compatibility</strong> profile provide the following
1758macro:</p>
1759</div>
1760<div class="listingblock">
1761<div class="content">
1762<pre class="CodeRay highlight"><code data-lang="c++"><span class="preprocessor">#define</span> GL_compatibility_profile <span class="integer">1</span></code></pre>
1763</div>
1764</div>
1765<div class="paragraph">
1766<p>Implementations providing the <strong>es</strong> profile provide the following macro:</p>
1767</div>
1768<div class="listingblock">
1769<div class="content">
1770<pre class="CodeRay highlight"><code data-lang="c++"><span class="preprocessor">#define</span> GL_es_profile <span class="integer">1</span></code></pre>
1771</div>
1772</div>
1773<div class="paragraph">
1774<p>The <strong>#version</strong> directive must occur in a shader before anything else, except
1775for comments and white space.</p>
1776</div>
1777<div class="paragraph">
1778<p>By default, compilers of this language must issue compile-time
1779lexical
1780and
1781grammatical errors for shaders that do not conform to this specification.
1782Any extended behavior must first be enabled.
1783Directives to control the behavior of the compiler with respect to
1784extensions are declared with the <strong>#extension</strong> directive</p>
1785</div>
1786<div class="listingblock">
1787<div class="content">
1788<pre class="CodeRay highlight"><code data-lang="c++"><span class="preprocessor">#extension</span> extension_name : behavior
1789<span class="preprocessor">#extension</span> all : behavior</code></pre>
1790</div>
1791</div>
1792<div class="paragraph">
1793<p>where <em>extension_name</em> is the name of an extension.
1794Extension names are not documented in this specification.
1795The token <strong>all</strong> means the behavior applies to all extensions supported by
1796the compiler.
1797The <em>behavior</em> can be one of the following:</p>
1798</div>
1799<table class="tableblock frame-all grid-all stretch">
1800<colgroup>
1801<col style="width: 50%;">
1802<col style="width: 50%;">
1803</colgroup>
1804<thead>
1805<tr>
1806<th class="tableblock halign-left valign-top">Behavior</th>
1807<th class="tableblock halign-left valign-top">Effect</th>
1808</tr>
1809</thead>
1810<tbody>
1811<tr>
1812<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>require</strong></p></td>
1813<td class="tableblock halign-left valign-top"><p class="tableblock">Behave as specified by the extension <em>extension_name</em>.<br>
1814              Give a compile-time error on the <strong>#extension</strong> if the extension
1815              <em>extension_name</em> is not supported, or if <strong>all</strong> is specified.</p></td>
1816</tr>
1817<tr>
1818<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>enable</strong></p></td>
1819<td class="tableblock halign-left valign-top"><p class="tableblock">Behave as specified by the extension <em>extension_name</em>.<br>
1820              Warn on the <strong>#extension</strong> if the extension <em>extension_name</em> is
1821              not supported.<br>
1822              Give a compile-time error on the <strong>#extension</strong> if <strong>all</strong> is
1823              specified.</p></td>
1824</tr>
1825<tr>
1826<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>warn</strong></p></td>
1827<td class="tableblock halign-left valign-top"><p class="tableblock">Behave as specified by the extension <em>extension_name</em>,
1828              except issue warnings on any detectable use of that extension,
1829              unless such use is supported by other enabled or required
1830              extensions.<br>
1831              If <strong>all</strong> is specified, then warn on all detectable uses of any
1832              extension used.<br>
1833              Warn on the <strong>#extension</strong> if the extension <em>extension_name</em> is
1834              not supported.</p></td>
1835</tr>
1836<tr>
1837<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>disable</strong></p></td>
1838<td class="tableblock halign-left valign-top"><p class="tableblock">Behave (including issuing errors and warnings) as if the
1839              extension <em>extension_name</em> is not part of the language
1840              definition.<br>
1841              If <strong>all</strong> is specified, then behavior must revert back to that
1842              of the non-extended core version of the language being
1843              compiled to.<br>
1844              Warn on the <strong>#extension</strong> if the extension <em>extension_name</em> is
1845              not supported.</p></td>
1846</tr>
1847</tbody>
1848</table>
1849<div class="paragraph">
1850<p>The <strong>extension</strong> directive is a simple, low-level mechanism to set the
1851behavior for each extension.
1852It does not define policies such as which combinations are appropriate,
1853those must be defined elsewhere.
1854Order of directives matters in setting the behavior for each extension:
1855Directives that occur later override those seen earlier.
1856The <strong>all</strong> variant sets the behavior for all extensions, overriding all
1857previously issued <strong>extension</strong> directives, but only for the <em>behaviors</em>
1858<strong>warn</strong> and <strong>disable</strong>.</p>
1859</div>
1860<div class="paragraph">
1861<p>The initial state of the compiler is as if the directive</p>
1862</div>
1863<div class="listingblock">
1864<div class="content">
1865<pre class="CodeRay highlight"><code data-lang="c++"><span class="preprocessor">#extension</span> all : disable</code></pre>
1866</div>
1867</div>
1868<div class="paragraph">
1869<p>was issued, telling the compiler that all error and warning reporting must
1870be done according to this specification, ignoring any extensions.</p>
1871</div>
1872<div class="paragraph">
1873<p>Each extension can define its allowed granularity of scope.
1874If nothing is said, the granularity is a shader (that is, a single
1875compilation unit), and the extension directives must occur before any
1876non-preprocessor tokens.
1877If necessary, the linker can enforce granularities larger than a single
1878compilation unit, in which case each involved shader will have to contain
1879the necessary extension directive.</p>
1880</div>
1881<div class="paragraph">
1882<p>Macro expansion is not done on lines containing <strong>#extension</strong> and <strong>#version</strong>
1883directives.</p>
1884</div>
1885<div class="paragraph">
1886<p><strong>#line</strong> must have, after macro substitution, one of the following forms:</p>
1887</div>
1888<div class="listingblock">
1889<div class="content">
1890<pre class="CodeRay highlight"><code data-lang="c++"><span class="preprocessor">#line</span> line
1891<span class="preprocessor">#line</span> line source-<span class="predefined-type">string</span>-number</code></pre>
1892</div>
1893</div>
1894<div class="paragraph">
1895<p>where <em>line</em> and <em>source-string-number</em> are
1896constant integer expressions.
1897If these constant expressions are not integer literals then behavior is undefined.
1898After processing this directive (including its new-line), the implementation
1899will behave as if it is compiling at line number <em>line</em> and source string
1900number <em>source-string-number</em>.
1901Subsequent source strings will be numbered sequentially, until another
1902<strong>#line</strong> directive overrides that numbering.</p>
1903</div>
1904<div class="admonitionblock note">
1905<table>
1906<tr>
1907<td class="icon">
1908<i class="fa icon-note" title="Note"></i>
1909</td>
1910<td class="content">
1911<div class="title">Note</div>
1912<div class="paragraph">
1913<p>Some implementations have allowed constant expressions in #line directives and
1914some have not. Even where expressions are supported the grammar is ambiguous and so
1915results are implementation dependent. For example,
1916+ #line +2 +2               // Line number set to 4, or file to 2 and line to 2</p>
1917</div>
1918</td>
1919</tr>
1920</table>
1921</div>
1922<div class="paragraph">
1923<p>When shaders are compiled for OpenGL SPIR-V, the following predefined
1924macro is available:</p>
1925</div>
1926<div class="listingblock">
1927<div class="content">
1928<pre class="CodeRay highlight"><code data-lang="c++"><span class="preprocessor">#define</span> GL_SPIRV <span class="integer">100</span></code></pre>
1929</div>
1930</div>
1931<div class="paragraph">
1932<p>When targeting Vulkan, the following predefined macro is available:</p>
1933</div>
1934<div class="listingblock">
1935<div class="content">
1936<pre class="CodeRay highlight"><code data-lang="c++"><span class="preprocessor">#define</span> VULKAN <span class="integer">100</span></code></pre>
1937</div>
1938</div>
1939</div>
1940<div class="sect2">
1941<h3 id="comments">3.4. Comments</h3>
1942<div class="paragraph">
1943<p>Comments are delimited by <strong>/*</strong> and <strong>*/</strong>, or by <strong>//</strong> and a new-line.
1944The begin comment delimiters (/* or //) are not recognized as comment
1945delimiters inside of a comment, hence comments cannot be nested.
1946A <strong>/*</strong> comment includes its terminating delimiter (*/).
1947However, a <strong>//</strong> comment does not include (or eliminate) its terminating new
1948line.</p>
1949</div>
1950<div class="paragraph">
1951<p>Inside comments, any byte values may be used, except a byte whose value is
19520.
1953No errors will be given for the content of comments and no validation on the
1954content of comments need be done.</p>
1955</div>
1956<div class="paragraph">
1957<p>Removal of new-lines by the line-continuation character (<strong>\</strong>) logically
1958occurs before comments are processed.
1959That is, a single-line comment ending in the line-continuation character
1960(<strong>\</strong>) includes the next line in the comment.</p>
1961</div>
1962<div class="listingblock">
1963<div class="content">
1964<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">// a single-line comment containing the next line \
1965a = b; // this is still in the first comment</span></code></pre>
1966</div>
1967</div>
1968</div>
1969<div class="sect2">
1970<h3 id="tokens">3.5. Tokens</h3>
1971<div class="paragraph">
1972<p>The language, after preprocessing, is a sequence of tokens.
1973A token can be</p>
1974</div>
1975<div class="openblock bnf">
1976<div class="content">
1977<div class="dlist">
1978<dl>
1979<dt class="hdlist1"><em>token</em> : </dt>
1980<dd>
1981<p><em>keyword</em><br>
1982<em>identifier</em><br>
1983<em>integer-constant</em><br>
1984<em>floating-constant</em><br>
1985<em>operator</em><br>
1986<strong>;</strong> <strong>{</strong> <strong>}</strong></p>
1987</dd>
1988</dl>
1989</div>
1990</div>
1991</div>
1992</div>
1993<div class="sect2">
1994<h3 id="keywords">3.6. Keywords</h3>
1995<div class="paragraph">
1996<p>The following are the keywords in the language and (after
1997preprocessing) can only be used as described in this specification,
1998or a compile-time error results:</p>
1999</div>
2000<div class="dlist">
2001<dl>
2002<dt class="hdlist1"></dt>
2003<dd>
2004<p><strong>const</strong> <strong>uniform</strong> <strong>buffer</strong> <strong>shared</strong>
2005<strong>attribute</strong> <strong>varying</strong></p>
2006</dd>
2007<dt class="hdlist1"></dt>
2008<dd>
2009<p><strong>coherent</strong> <strong>volatile</strong> <strong>restrict</strong> <strong>readonly</strong> <strong>writeonly</strong></p>
2010</dd>
2011<dt class="hdlist1"></dt>
2012<dd>
2013<p><strong>atomic_uint</strong></p>
2014</dd>
2015<dt class="hdlist1"></dt>
2016<dd>
2017<p><strong>layout</strong></p>
2018</dd>
2019<dt class="hdlist1"></dt>
2020<dd>
2021<p><strong>centroid</strong> <strong>flat</strong> <strong>smooth</strong>
2022<strong>noperspective</strong></p>
2023</dd>
2024<dt class="hdlist1"></dt>
2025<dd>
2026<p><strong>patch</strong> <strong>sample</strong></p>
2027</dd>
2028<dt class="hdlist1"></dt>
2029<dd>
2030<p><strong>invariant</strong> <strong>precise</strong></p>
2031</dd>
2032<dt class="hdlist1"></dt>
2033<dd>
2034<p><strong>break</strong> <strong>continue</strong> <strong>do</strong> <strong>for</strong> <strong>while</strong> <strong>switch</strong> <strong>case</strong> <strong>default</strong></p>
2035</dd>
2036<dt class="hdlist1"></dt>
2037<dd>
2038<p><strong>if</strong> <strong>else</strong></p>
2039</dd>
2040<dt class="hdlist1"></dt>
2041<dd>
2042<p><strong>subroutine</strong></p>
2043</dd>
2044<dt class="hdlist1"></dt>
2045<dd>
2046<p><strong>in</strong> <strong>out</strong> <strong>inout</strong></p>
2047</dd>
2048<dt class="hdlist1"></dt>
2049<dd>
2050<p><strong>int</strong> <strong>void</strong> <strong>bool</strong> <strong>true</strong> <strong>false</strong> <strong>float</strong>
2051<strong>double</strong></p>
2052</dd>
2053<dt class="hdlist1"></dt>
2054<dd>
2055<p><strong>discard</strong> <strong>return</strong></p>
2056</dd>
2057<dt class="hdlist1"></dt>
2058<dd>
2059<p><strong>vec2</strong> <strong>vec3</strong> <strong>vec4</strong> <strong>ivec2</strong> <strong>ivec3</strong> <strong>ivec4</strong> <strong>bvec2</strong> <strong>bvec3</strong> <strong>bvec4</strong></p>
2060</dd>
2061<dt class="hdlist1"></dt>
2062<dd>
2063<p><strong>uint</strong> <strong>uvec2</strong> <strong>uvec3</strong> <strong>uvec4</strong></p>
2064</dd>
2065<dt class="hdlist1"></dt>
2066<dd>
2067<p><strong>dvec2</strong> <strong>dvec3</strong> <strong>dvec4</strong></p>
2068</dd>
2069<dt class="hdlist1"></dt>
2070<dd>
2071<p><strong>mat2</strong> <strong>mat3</strong> <strong>mat4</strong></p>
2072</dd>
2073<dt class="hdlist1"></dt>
2074<dd>
2075<p><strong>mat2x2</strong> <strong>mat2x3</strong> <strong>mat2x4</strong></p>
2076</dd>
2077<dt class="hdlist1"></dt>
2078<dd>
2079<p><strong>mat3x2</strong> <strong>mat3x3</strong> <strong>mat3x4</strong></p>
2080</dd>
2081<dt class="hdlist1"></dt>
2082<dd>
2083<p><strong>mat4x2</strong> <strong>mat4x3</strong> <strong>mat4x4</strong></p>
2084</dd>
2085<dt class="hdlist1"></dt>
2086<dd>
2087<p><strong>dmat2</strong> <strong>dmat3</strong> <strong>dmat4</strong></p>
2088</dd>
2089<dt class="hdlist1"></dt>
2090<dd>
2091<p><strong>dmat2x2</strong> <strong>dmat2x3</strong> <strong>dmat2x4</strong></p>
2092</dd>
2093<dt class="hdlist1"></dt>
2094<dd>
2095<p><strong>dmat3x2</strong> <strong>dmat3x3</strong> <strong>dmat3x4</strong></p>
2096</dd>
2097<dt class="hdlist1"></dt>
2098<dd>
2099<p><strong>dmat4x2</strong> <strong>dmat4x3</strong> <strong>dmat4x4</strong></p>
2100</dd>
2101<dt class="hdlist1"></dt>
2102<dd>
2103<p><strong>lowp</strong> <strong>mediump</strong> <strong>highp</strong> <strong>precision</strong></p>
2104</dd>
2105<dt class="hdlist1"></dt>
2106<dd>
2107<p><strong>sampler1D</strong> <strong>sampler1DShadow</strong> <strong>sampler1DArray</strong> <strong>sampler1DArrayShadow</strong></p>
2108</dd>
2109<dt class="hdlist1"></dt>
2110<dd>
2111<p><strong>isampler1D</strong> <strong>isampler1DArray</strong> <strong>usampler1D</strong> <strong>usampler1DArray</strong></p>
2112</dd>
2113<dt class="hdlist1"></dt>
2114<dd>
2115<p><strong>sampler2D</strong> <strong>sampler2DShadow</strong> <strong>sampler2DArray</strong> <strong>sampler2DArrayShadow</strong></p>
2116</dd>
2117<dt class="hdlist1"></dt>
2118<dd>
2119<p><strong>isampler2D</strong> <strong>isampler2DArray</strong> <strong>usampler2D</strong> <strong>usampler2DArray</strong></p>
2120</dd>
2121<dt class="hdlist1"></dt>
2122<dd>
2123<p><strong>sampler2DRect</strong> <strong>sampler2DRectShadow</strong> <strong>isampler2DRect</strong> <strong>usampler2DRect</strong></p>
2124</dd>
2125<dt class="hdlist1"></dt>
2126<dd>
2127<p><strong>sampler2DMS</strong> <strong>isampler2DMS</strong> <strong>usampler2DMS</strong></p>
2128</dd>
2129<dt class="hdlist1"></dt>
2130<dd>
2131<p><strong>sampler2DMSArray</strong> <strong>isampler2DMSArray</strong> <strong>usampler2DMSArray</strong></p>
2132</dd>
2133<dt class="hdlist1"></dt>
2134<dd>
2135<p><strong>sampler3D</strong> <strong>isampler3D</strong> <strong>usampler3D</strong></p>
2136</dd>
2137<dt class="hdlist1"></dt>
2138<dd>
2139<p><strong>samplerCube</strong> <strong>samplerCubeShadow</strong> <strong>isamplerCube</strong> <strong>usamplerCube</strong></p>
2140</dd>
2141<dt class="hdlist1"></dt>
2142<dd>
2143<p><strong>samplerCubeArray</strong> <strong>samplerCubeArrayShadow</strong></p>
2144</dd>
2145<dt class="hdlist1"></dt>
2146<dd>
2147<p><strong>isamplerCubeArray</strong> <strong>usamplerCubeArray</strong></p>
2148</dd>
2149<dt class="hdlist1"></dt>
2150<dd>
2151<p><strong>samplerBuffer</strong> <strong>isamplerBuffer</strong> <strong>usamplerBuffer</strong></p>
2152</dd>
2153<dt class="hdlist1"></dt>
2154<dd>
2155<p><strong>image1D</strong> <strong>iimage1D</strong> <strong>uimage1D</strong></p>
2156</dd>
2157<dt class="hdlist1"></dt>
2158<dd>
2159<p><strong>image1DArray</strong> <strong>iimage1DArray</strong> <strong>uimage1DArray</strong></p>
2160</dd>
2161<dt class="hdlist1"></dt>
2162<dd>
2163<p><strong>image2D</strong> <strong>iimage2D</strong> <strong>uimage2D</strong></p>
2164</dd>
2165<dt class="hdlist1"></dt>
2166<dd>
2167<p><strong>image2DArray</strong> <strong>iimage2DArray</strong> <strong>uimage2DArray</strong></p>
2168</dd>
2169<dt class="hdlist1"></dt>
2170<dd>
2171<p><strong>image2DRect</strong> <strong>iimage2DRect</strong> <strong>uimage2DRect</strong></p>
2172</dd>
2173<dt class="hdlist1"></dt>
2174<dd>
2175<p><strong>image2DMS</strong> <strong>iimage2DMS</strong> <strong>uimage2DMS</strong></p>
2176</dd>
2177<dt class="hdlist1"></dt>
2178<dd>
2179<p><strong>image2DMSArray</strong> <strong>iimage2DMSArray</strong> <strong>uimage2DMSArray</strong></p>
2180</dd>
2181<dt class="hdlist1"></dt>
2182<dd>
2183<p><strong>image3D</strong> <strong>iimage3D</strong> <strong>uimage3D</strong></p>
2184</dd>
2185<dt class="hdlist1"></dt>
2186<dd>
2187<p><strong>imageCube</strong> <strong>iimageCube</strong> <strong>uimageCube</strong></p>
2188</dd>
2189<dt class="hdlist1"></dt>
2190<dd>
2191<p><strong>imageCubeArray</strong> <strong>iimageCubeArray</strong> <strong>uimageCubeArray</strong></p>
2192</dd>
2193<dt class="hdlist1"></dt>
2194<dd>
2195<p><strong>imageBuffer</strong> <strong>iimageBuffer</strong> <strong>uimageBuffer</strong></p>
2196</dd>
2197<dt class="hdlist1"></dt>
2198<dd>
2199<p><strong>struct</strong></p>
2200</dd>
2201</dl>
2202</div>
2203<div class="paragraph">
2204<p>In addition, when targeting Vulkan, the following keywords also exist:</p>
2205</div>
2206<div class="dlist">
2207<dl>
2208<dt class="hdlist1"></dt>
2209<dd>
2210<p><strong>texture1D</strong> <strong>texture1DArray</strong></p>
2211</dd>
2212<dt class="hdlist1"></dt>
2213<dd>
2214<p><strong>itexture1D</strong> <strong>itexture1DArray</strong> <strong>utexture1D</strong> <strong>utexture1DArray</strong></p>
2215</dd>
2216<dt class="hdlist1"></dt>
2217<dd>
2218<p><strong>texture2D</strong> <strong>texture2DArray</strong></p>
2219</dd>
2220<dt class="hdlist1"></dt>
2221<dd>
2222<p><strong>itexture2D</strong> <strong>itexture2DArray</strong> <strong>utexture2D</strong> <strong>utexture2DArray</strong></p>
2223</dd>
2224<dt class="hdlist1"></dt>
2225<dd>
2226<p><strong>texture2DRect</strong> <strong>itexture2DRect</strong> <strong>utexture2DRect</strong></p>
2227</dd>
2228<dt class="hdlist1"></dt>
2229<dd>
2230<p><strong>texture2DMS</strong> <strong>itexture2DMS</strong> <strong>utexture2DMS</strong></p>
2231</dd>
2232<dt class="hdlist1"></dt>
2233<dd>
2234<p><strong>texture2DMSArray</strong> <strong>itexture2DMSArray</strong> <strong>utexture2DMSArray</strong></p>
2235</dd>
2236<dt class="hdlist1"></dt>
2237<dd>
2238<p><strong>texture3D</strong> <strong>itexture3D</strong> <strong>utexture3D</strong></p>
2239</dd>
2240<dt class="hdlist1"></dt>
2241<dd>
2242<p><strong>textureCube</strong> <strong>itextureCube</strong> <strong>utextureCube</strong></p>
2243</dd>
2244<dt class="hdlist1"></dt>
2245<dd>
2246<p><strong>textureCubeArray</strong> <strong>itextureCubeArray</strong> <strong>utextureCubeArray</strong></p>
2247</dd>
2248<dt class="hdlist1"></dt>
2249<dd>
2250<p><strong>textureBuffer</strong> <strong>itextureBuffer</strong> <strong>utextureBuffer</strong></p>
2251</dd>
2252<dt class="hdlist1"></dt>
2253<dd>
2254<p><strong>sampler</strong> <strong>samplerShadow</strong></p>
2255</dd>
2256<dt class="hdlist1"></dt>
2257<dd>
2258<p><strong>subpassInput</strong> <strong>isubpassInput</strong> <strong>usubpassInput</strong></p>
2259</dd>
2260<dt class="hdlist1"></dt>
2261<dd>
2262<p><strong>subpassInputMS</strong> <strong>isubpassInputMS</strong> <strong>usubpassInputMS</strong></p>
2263</dd>
2264</dl>
2265</div>
2266<div class="paragraph">
2267<p>The following are the keywords reserved for future use.
2268Using them will result in a compile-time error:</p>
2269</div>
2270<div class="dlist">
2271<dl>
2272<dt class="hdlist1"></dt>
2273<dd>
2274<p><strong>common</strong> <strong>partition</strong> <strong>active</strong></p>
2275</dd>
2276<dt class="hdlist1"></dt>
2277<dd>
2278<p><strong>asm</strong></p>
2279</dd>
2280<dt class="hdlist1"></dt>
2281<dd>
2282<p><strong>class</strong> <strong>union</strong> <strong>enum</strong> <strong>typedef</strong> <strong>template</strong> <strong>this</strong></p>
2283</dd>
2284<dt class="hdlist1"></dt>
2285<dd>
2286<p><strong>resource</strong></p>
2287</dd>
2288<dt class="hdlist1"></dt>
2289<dd>
2290<p><strong>goto</strong></p>
2291</dd>
2292<dt class="hdlist1"></dt>
2293<dd>
2294<p><strong>inline</strong> <strong>noinline</strong> <strong>public</strong> <strong>static</strong> <strong>extern</strong> <strong>external</strong> <strong>interface</strong></p>
2295</dd>
2296<dt class="hdlist1"></dt>
2297<dd>
2298<p><strong>long</strong> <strong>short</strong> <strong>half</strong> <strong>fixed</strong> <strong>unsigned</strong> <strong>superp</strong></p>
2299</dd>
2300<dt class="hdlist1"></dt>
2301<dd>
2302<p><strong>input</strong> <strong>output</strong></p>
2303</dd>
2304<dt class="hdlist1"></dt>
2305<dd>
2306<p><strong>hvec2</strong> <strong>hvec3</strong> <strong>hvec4</strong> <strong>fvec2</strong> <strong>fvec3</strong> <strong>fvec4</strong></p>
2307</dd>
2308<dt class="hdlist1"></dt>
2309<dd>
2310<p><strong>filter</strong></p>
2311</dd>
2312<dt class="hdlist1"></dt>
2313<dd>
2314<p><strong>sizeof</strong> <strong>cast</strong></p>
2315</dd>
2316<dt class="hdlist1"></dt>
2317<dd>
2318<p><strong>namespace</strong> <strong>using</strong></p>
2319</dd>
2320<dt class="hdlist1"></dt>
2321<dd>
2322<p><strong>sampler3DRect</strong></p>
2323</dd>
2324</dl>
2325</div>
2326<div class="paragraph">
2327<p>In addition, all identifiers containing two consecutive underscores (__)
2328are reserved for use by underlying software layers.
2329Defining such a name in a shader does not itself result in an error, but may
2330result in unintended behaviors that stem from having multiple definitions of
2331the same name.</p>
2332</div>
2333</div>
2334<div class="sect2">
2335<h3 id="identifiers">3.7. Identifiers</h3>
2336<div class="paragraph">
2337<p>Identifiers are used for variable names, function names, structure names,
2338and field selectors (field selectors select components of
2339<code><a href="#vector-components">vectors</a></code> and <code><a href="#matrix-components">matrices</a></code>,
2340similarly to structure members).
2341Identifiers have the form:</p>
2342</div>
2343<div class="openblock bnf">
2344<div class="content">
2345<div class="dlist">
2346<dl>
2347<dt class="hdlist1"><em>identifier</em> : </dt>
2348<dd>
2349<p><em>nondigit</em><br>
2350<em>identifier</em> <em>nondigit</em><br>
2351<em>identifier</em> <em>digit</em></p>
2352</dd>
2353<dt class="hdlist1"><em>nondigit</em> : one of </dt>
2354<dd>
2355<p><strong>_</strong> <strong>a b c d e f g h i j k l m n o p q r s t u v w x y z</strong><br>
2356<strong>A B C D E F G H I J K L M N O P Q R S T U V W X Y Z</strong></p>
2357</dd>
2358<dt class="hdlist1"><em>digit</em> : one of </dt>
2359<dd>
2360<p><strong>0 1 2 3 4 5 6 7 8 9</strong></p>
2361</dd>
2362</dl>
2363</div>
2364</div>
2365</div>
2366<div class="paragraph">
2367<p>Identifiers starting with &#8220;gl_&#8221; are reserved, and
2368in general, may not be declared in a shader;
2369this results in a compile-time error.
2370However, as noted in the specification, there are some cases where
2371previously declared variables can be redeclared, and predeclared &#8220;gl_&#8221;
2372names are allowed to be redeclared in a shader only for these specific
2373purposes.</p>
2374</div>
2375<div class="paragraph">
2376<p>Implementations must support identifier lengths of up to 1024 characters.
2377Implementations are allowed to generate an error for an identifier of length
2378greater than 1024 characters, but are also allowed to support lengths
2379greater than 1024.</p>
2380</div>
2381</div>
2382<div class="sect2">
2383<h3 id="definitions">3.8. Definitions</h3>
2384<div class="paragraph">
2385<p>Some language rules described below depend on the following definitions.</p>
2386</div>
2387<div class="sect3">
2388<h4 id="static-use">3.8.1. Static Use</h4>
2389<div class="paragraph">
2390<p>A shader contains a <em>static use</em> of a variable <em>x</em> if, after preprocessing,
2391the shader contains a statement that would access any part of <em>x</em>,
2392whether or not flow of control will cause that statement to be executed.
2393Such a variable is referred to as being <em>statically used</em>. If the access is a
2394write then <em>x</em> is further said to be <em>statically assigned</em>.</p>
2395</div>
2396</div>
2397<div class="sect3">
2398<h4 id="dynamically-uniform-expressions-and-uniform-control-flow">3.8.2. Dynamically Uniform Expressions and Uniform Control Flow</h4>
2399<div class="paragraph">
2400<p>Some operations require an expression to be <em>dynamically uniform</em>, or that
2401it be located in <em>uniform control flow</em>.
2402These requirements are defined by the following set of definitions.</p>
2403</div>
2404<div class="paragraph">
2405<p>An <em>invocation</em> is a single execution of <em>main()</em> for a particular stage,
2406operating only on the amount of data explicitly exposed within that stage&#8217;s
2407shaders.
2408(Any implicit operation on additional instances of data would comprise
2409additional invocations.) For example, in compute execution models, a single
2410invocation operates only on a single work item, or, in a vertex execution
2411model, a single invocation operates only on a single vertex.</p>
2412</div>
2413<div class="paragraph">
2414<p>An <em>invocation group</em> is the complete set of invocations collectively
2415processing a particular compute workgroup or graphical operation, where the
2416scope of a "graphical operation" is implementation-dependent, but at least
2417as large as a single triangle or patch, and at most as large as a single
2418rendering command, as defined by the client API.</p>
2419</div>
2420<div class="paragraph">
2421<p>Within a single invocation, a single shader statement can be executed
2422multiple times, giving multiple <em>dynamic instances</em> of that instruction.
2423This can happen when the instruction is executed in a loop, or in a function
2424called from multiple call sites, or combinations of multiple of these.
2425Different loop iterations and different dynamic function-call-site chains
2426yield different dynamic instances of such an instruction.
2427Dynamic instances are distinguished by their control-flow path within an
2428invocation, not by which invocation executed it.
2429That is, different invocations of <em>main()</em> execute the same dynamic
2430instances of an instruction when they follow the same control-flow path.</p>
2431</div>
2432<div class="paragraph">
2433<p>An expression is <em>dynamically uniform</em> for a dynamic instance consuming it
2434when its value is the same for all invocations (in the invocation group)
2435that execute that dynamic instance.</p>
2436</div>
2437<div class="paragraph">
2438<p><em>Uniform control flow</em> (or converged control flow) occurs when all
2439invocations in the invocation group execute the same control-flow path (and
2440hence the same sequence of dynamic instances of instructions).
2441Uniform control flow is the initial state at the entry into <em>main()</em>, and
2442lasts until a conditional branch takes different control paths for different
2443invocations (non-uniform or divergent control flow).
2444Such divergence can reconverge, with all the invocations once again
2445executing the same control-flow path, and this re-establishes the existence
2446of uniform control flow.
2447If control flow is uniform upon entry into a selection or loop, and all
2448invocations in the invocation group subsequently leave that selection or
2449loop, then control flow reconverges to be uniform.</p>
2450</div>
2451<div class="paragraph">
2452<p>For example:</p>
2453</div>
2454<div class="listingblock">
2455<div class="content">
2456<pre class="CodeRay highlight"><code data-lang="c++">main()
2457{
2458    <span class="predefined-type">float</span> a = ...; <span class="comment">// this is uniform control flow</span>
2459    <span class="keyword">if</span> (a &lt; b) {   <span class="comment">// this expression is true for some fragments, not all</span>
2460        ...;       <span class="comment">// non-uniform control flow</span>
2461    } <span class="keyword">else</span> {
2462        ...;       <span class="comment">// non-uniform control flow</span>
2463    }
2464    ...;           <span class="comment">// uniform control flow again</span>
2465}</code></pre>
2466</div>
2467</div>
2468<div class="paragraph">
2469<p>Note that constant expressions are trivially dynamically uniform.
2470It follows that typical loop counters based on these are also dynamically
2471uniform.</p>
2472</div>
2473</div>
2474</div>
2475</div>
2476</div>
2477<div class="sect1">
2478<h2 id="variables-and-types">4. Variables and Types</h2>
2479<div class="sectionbody">
2480<div class="paragraph">
2481<p>All variables and functions must be declared before being used.
2482Variable and function names are identifiers.</p>
2483</div>
2484<div class="paragraph">
2485<p>There are no default types.
2486All variable and function declarations must have a declared type, and
2487optionally qualifiers.
2488A variable is declared by specifying its type followed by one or more names
2489separated by commas.
2490In many cases, a variable can be initialized as part of its declaration by
2491using the assignment operator (<strong>=</strong>).</p>
2492</div>
2493<div class="paragraph">
2494<p>User-defined types may be defined using <strong>struct</strong> to aggregate a list of
2495existing types into a single name.</p>
2496</div>
2497<div class="paragraph">
2498<p>The OpenGL Shading Language is type safe.
2499There are some implicit conversions between types.
2500Exactly how and when this can occur is described in section
2501&#8220;<a href="#implicit-conversions">Implicit Conversions</a>&#8221; and as referenced by other
2502sections in this specification.</p>
2503</div>
2504<div class="sect2">
2505<h3 id="basic-types">4.1. Basic Types</h3>
2506<div class="dlist">
2507<dl>
2508<dt class="hdlist1">Definition</dt>
2509<dd>
2510<p>A <em>basic type</em> is a type defined by a keyword in the language.</p>
2511</dd>
2512</dl>
2513</div>
2514<div class="paragraph">
2515<p>The OpenGL Shading Language supports the following basic data types, grouped as follows.</p>
2516</div>
2517<div class="paragraph">
2518<p><strong>Transparent Types</strong></p>
2519</div>
2520<table class="tableblock frame-all grid-all stretch">
2521<colgroup>
2522<col style="width: 50%;">
2523<col style="width: 50%;">
2524</colgroup>
2525<thead>
2526<tr>
2527<th class="tableblock halign-left valign-top">Type</th>
2528<th class="tableblock halign-left valign-top">Meaning</th>
2529</tr>
2530</thead>
2531<tbody>
2532<tr>
2533<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>void</strong></p></td>
2534<td class="tableblock halign-left valign-top"><p class="tableblock">for functions that do not return a value</p></td>
2535</tr>
2536<tr>
2537<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>bool</strong></p></td>
2538<td class="tableblock halign-left valign-top"><p class="tableblock">a conditional type, taking on values of true or false</p></td>
2539</tr>
2540<tr>
2541<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>int</strong></p></td>
2542<td class="tableblock halign-left valign-top"><p class="tableblock">a signed integer</p></td>
2543</tr>
2544<tr>
2545<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>uint</strong></p></td>
2546<td class="tableblock halign-left valign-top"><p class="tableblock">an unsigned integer</p></td>
2547</tr>
2548<tr>
2549<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>float</strong></p></td>
2550<td class="tableblock halign-left valign-top"><p class="tableblock">a single-precision floating-point scalar</p></td>
2551</tr>
2552<tr>
2553<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>double</strong></p></td>
2554<td class="tableblock halign-left valign-top"><p class="tableblock">a double-precision floating-point scalar</p></td>
2555</tr>
2556<tr>
2557<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>vec2</strong></p></td>
2558<td class="tableblock halign-left valign-top"><p class="tableblock">a two-component single-precision floating-point vector</p></td>
2559</tr>
2560<tr>
2561<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>vec3</strong></p></td>
2562<td class="tableblock halign-left valign-top"><p class="tableblock">a three-component single-precision floating-point vector</p></td>
2563</tr>
2564<tr>
2565<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>vec4</strong></p></td>
2566<td class="tableblock halign-left valign-top"><p class="tableblock">a four-component single-precision floating-point vector</p></td>
2567</tr>
2568<tr>
2569<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dvec2</strong></p></td>
2570<td class="tableblock halign-left valign-top"><p class="tableblock">a two-component double-precision floating-point vector</p></td>
2571</tr>
2572<tr>
2573<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dvec3</strong></p></td>
2574<td class="tableblock halign-left valign-top"><p class="tableblock">a three-component double-precision floating-point vector</p></td>
2575</tr>
2576<tr>
2577<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dvec4</strong></p></td>
2578<td class="tableblock halign-left valign-top"><p class="tableblock">a four-component double-precision floating-point vector</p></td>
2579</tr>
2580<tr>
2581<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>bvec2</strong></p></td>
2582<td class="tableblock halign-left valign-top"><p class="tableblock">a two-component Boolean vector</p></td>
2583</tr>
2584<tr>
2585<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>bvec3</strong></p></td>
2586<td class="tableblock halign-left valign-top"><p class="tableblock">a three-component Boolean vector</p></td>
2587</tr>
2588<tr>
2589<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>bvec4</strong></p></td>
2590<td class="tableblock halign-left valign-top"><p class="tableblock">a four-component Boolean vector</p></td>
2591</tr>
2592<tr>
2593<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>ivec2</strong></p></td>
2594<td class="tableblock halign-left valign-top"><p class="tableblock">a two-component signed integer vector</p></td>
2595</tr>
2596<tr>
2597<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>ivec3</strong></p></td>
2598<td class="tableblock halign-left valign-top"><p class="tableblock">a three-component signed integer vector</p></td>
2599</tr>
2600<tr>
2601<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>ivec4</strong></p></td>
2602<td class="tableblock halign-left valign-top"><p class="tableblock">a four-component signed integer vector</p></td>
2603</tr>
2604<tr>
2605<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>uvec2</strong></p></td>
2606<td class="tableblock halign-left valign-top"><p class="tableblock">a two-component unsigned integer vector</p></td>
2607</tr>
2608<tr>
2609<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>uvec3</strong></p></td>
2610<td class="tableblock halign-left valign-top"><p class="tableblock">a three-component unsigned integer vector</p></td>
2611</tr>
2612<tr>
2613<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>uvec4</strong></p></td>
2614<td class="tableblock halign-left valign-top"><p class="tableblock">a four-component unsigned integer vector</p></td>
2615</tr>
2616<tr>
2617<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat2</strong></p></td>
2618<td class="tableblock halign-left valign-top"><p class="tableblock">a 2 × 2 single-precision floating-point matrix</p></td>
2619</tr>
2620<tr>
2621<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat3</strong></p></td>
2622<td class="tableblock halign-left valign-top"><p class="tableblock">a 3 × 3 single-precision floating-point matrix</p></td>
2623</tr>
2624<tr>
2625<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat4</strong></p></td>
2626<td class="tableblock halign-left valign-top"><p class="tableblock">a 4 × 4 single-precision floating-point matrix</p></td>
2627</tr>
2628<tr>
2629<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat2x2</strong></p></td>
2630<td class="tableblock halign-left valign-top"><p class="tableblock">same as a <strong>mat2</strong></p></td>
2631</tr>
2632<tr>
2633<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat2x3</strong></p></td>
2634<td class="tableblock halign-left valign-top"><p class="tableblock">a single-precision floating-point matrix with 2 columns and 3 rows</p></td>
2635</tr>
2636<tr>
2637<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat2x4</strong></p></td>
2638<td class="tableblock halign-left valign-top"><p class="tableblock">a single-precision floating-point matrix with 2 columns and 4 rows</p></td>
2639</tr>
2640<tr>
2641<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat3x2</strong></p></td>
2642<td class="tableblock halign-left valign-top"><p class="tableblock">a single-precision floating-point matrix with 3 columns and 2 rows</p></td>
2643</tr>
2644<tr>
2645<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat3x3</strong></p></td>
2646<td class="tableblock halign-left valign-top"><p class="tableblock">same as a <strong>mat3</strong></p></td>
2647</tr>
2648<tr>
2649<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat3x4</strong></p></td>
2650<td class="tableblock halign-left valign-top"><p class="tableblock">a single-precision floating-point matrix with 3 columns and 4 rows</p></td>
2651</tr>
2652<tr>
2653<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat4x2</strong></p></td>
2654<td class="tableblock halign-left valign-top"><p class="tableblock">a single-precision floating-point matrix with 4 columns and 2 rows</p></td>
2655</tr>
2656<tr>
2657<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat4x3</strong></p></td>
2658<td class="tableblock halign-left valign-top"><p class="tableblock">a single-precision floating-point matrix with 4 columns and 3 rows</p></td>
2659</tr>
2660<tr>
2661<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat4x4</strong></p></td>
2662<td class="tableblock halign-left valign-top"><p class="tableblock">same as a <strong>mat4</strong></p></td>
2663</tr>
2664<tr>
2665<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat2</strong></p></td>
2666<td class="tableblock halign-left valign-top"><p class="tableblock">a 2 × 2 double-precision floating-point matrix</p></td>
2667</tr>
2668<tr>
2669<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat3</strong></p></td>
2670<td class="tableblock halign-left valign-top"><p class="tableblock">a 3 × 3 double-precision floating-point matrix</p></td>
2671</tr>
2672<tr>
2673<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat4</strong></p></td>
2674<td class="tableblock halign-left valign-top"><p class="tableblock">a 4 × 4 double-precision floating-point matrix</p></td>
2675</tr>
2676<tr>
2677<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat2x2</strong></p></td>
2678<td class="tableblock halign-left valign-top"><p class="tableblock">same as a <strong>dmat2</strong></p></td>
2679</tr>
2680<tr>
2681<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat2x3</strong></p></td>
2682<td class="tableblock halign-left valign-top"><p class="tableblock">a double-precision floating-point matrix with 2 columns and 3 rows</p></td>
2683</tr>
2684<tr>
2685<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat2x4</strong></p></td>
2686<td class="tableblock halign-left valign-top"><p class="tableblock">a double-precision floating-point matrix with 2 columns and 4 rows</p></td>
2687</tr>
2688<tr>
2689<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat3x2</strong></p></td>
2690<td class="tableblock halign-left valign-top"><p class="tableblock">a double-precision floating-point matrix with 3 columns and 2 rows</p></td>
2691</tr>
2692<tr>
2693<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat3x3</strong></p></td>
2694<td class="tableblock halign-left valign-top"><p class="tableblock">same as a <strong>dmat3</strong></p></td>
2695</tr>
2696<tr>
2697<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat3x4</strong></p></td>
2698<td class="tableblock halign-left valign-top"><p class="tableblock">a double-precision floating-point matrix with 3 columns and 4 rows</p></td>
2699</tr>
2700<tr>
2701<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat4x2</strong></p></td>
2702<td class="tableblock halign-left valign-top"><p class="tableblock">a double-precision floating-point matrix with 4 columns and 2 rows</p></td>
2703</tr>
2704<tr>
2705<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat4x3</strong></p></td>
2706<td class="tableblock halign-left valign-top"><p class="tableblock">a double-precision floating-point matrix with 4 columns and 3 rows</p></td>
2707</tr>
2708<tr>
2709<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat4x4</strong></p></td>
2710<td class="tableblock halign-left valign-top"><p class="tableblock">same as a <strong>dmat4</strong></p></td>
2711</tr>
2712</tbody>
2713</table>
2714<div class="paragraph">
2715<p>Note that where the following tables say &#8220;accessing a texture&#8221;, the
2716<strong>sampler*</strong> opaque types access textures, and the <strong>image*</strong> opaque types
2717access images, of a specified type.</p>
2718</div>
2719<div class="paragraph">
2720<p><strong>Floating-Point Opaque Types</strong></p>
2721</div>
2722<table class="tableblock frame-all grid-all stretch">
2723<colgroup>
2724<col style="width: 50%;">
2725<col style="width: 50%;">
2726</colgroup>
2727<thead>
2728<tr>
2729<th class="tableblock halign-left valign-top">Type</th>
2730<th class="tableblock halign-left valign-top">Meaning</th>
2731</tr>
2732</thead>
2733<tbody>
2734<tr>
2735<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sampler1D</strong><br>
2736  <strong>texture1D</strong><br>
2737  <strong>image1D</strong></p></td>
2738<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a 1D texture</p></td>
2739</tr>
2740<tr>
2741<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sampler1DShadow</strong></p></td>
2742<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a 1D depth texture with comparison</p></td>
2743</tr>
2744<tr>
2745<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sampler1DArray</strong><br>
2746  <strong>texture1DArray</strong><br>
2747  <strong>image1DArray</strong></p></td>
2748<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a 1D array texture</p></td>
2749</tr>
2750<tr>
2751<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sampler1DArrayShadow</strong></p></td>
2752<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a 1D array depth texture with comparison</p></td>
2753</tr>
2754<tr>
2755<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sampler2D</strong><br>
2756  <strong>texture2D</strong><br>
2757  <strong>image2D</strong></p></td>
2758<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a 2D texture</p></td>
2759</tr>
2760<tr>
2761<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sampler2DShadow</strong></p></td>
2762<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a 2D depth texture with comparison</p></td>
2763</tr>
2764<tr>
2765<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sampler2DArray</strong><br>
2766  <strong>texture2DArray</strong><br>
2767  <strong>image2DArray</strong></p></td>
2768<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a 2D array texture</p></td>
2769</tr>
2770<tr>
2771<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sampler2DArrayShadow</strong></p></td>
2772<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a 2D array depth texture with comparison</p></td>
2773</tr>
2774<tr>
2775<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sampler2DMS</strong><br>
2776  <strong>texture2DMS</strong><br>
2777  <strong>image2DMS</strong></p></td>
2778<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a 2D multisample texture</p></td>
2779</tr>
2780<tr>
2781<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sampler2DMSArray</strong><br>
2782  <strong>texture2DMSArray</strong><br>
2783  <strong>image2DMSArray</strong></p></td>
2784<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a 2D multisample array texture</p></td>
2785</tr>
2786<tr>
2787<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sampler2DRect</strong><br>
2788  <strong>texture2DRect</strong><br>
2789  <strong>image2DRect</strong></p></td>
2790<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a rectangle texture</p></td>
2791</tr>
2792<tr>
2793<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sampler2DRectShadow</strong></p></td>
2794<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a rectangle texture with comparison</p></td>
2795</tr>
2796<tr>
2797<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sampler3D</strong><br>
2798  <strong>texture3D</strong><br>
2799  <strong>image3D</strong></p></td>
2800<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a 3D texture</p></td>
2801</tr>
2802<tr>
2803<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>samplerCube</strong><br>
2804  <strong>textureCube</strong><br>
2805  <strong>imageCube</strong></p></td>
2806<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a cube mapped texture</p></td>
2807</tr>
2808<tr>
2809<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>samplerCubeShadow</strong></p></td>
2810<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a cube map depth texture with comparison</p></td>
2811</tr>
2812<tr>
2813<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>samplerCubeArray</strong><br>
2814  <strong>textureCubeArray</strong><br>
2815  <strong>imageCubeArray</strong></p></td>
2816<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a cube map array texture</p></td>
2817</tr>
2818<tr>
2819<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>samplerCubeArrayShadow</strong></p></td>
2820<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a cube map array depth texture with comparison</p></td>
2821</tr>
2822<tr>
2823<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>samplerBuffer</strong><br>
2824  <strong>textureBuffer</strong><br>
2825  <strong>imageBuffer</strong></p></td>
2826<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a buffer texture</p></td>
2827</tr>
2828<tr>
2829<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>subpassInput</strong></p></td>
2830<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a floating-point subpass input</p></td>
2831</tr>
2832<tr>
2833<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>subpassInputMS</strong></p></td>
2834<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a multi-sampled floating-point subpass input</p></td>
2835</tr>
2836</tbody>
2837</table>
2838<div class="paragraph">
2839<p><strong>Signed Integer Opaque Types</strong></p>
2840</div>
2841<table class="tableblock frame-all grid-all stretch">
2842<colgroup>
2843<col style="width: 50%;">
2844<col style="width: 50%;">
2845</colgroup>
2846<thead>
2847<tr>
2848<th class="tableblock halign-left valign-top">Type</th>
2849<th class="tableblock halign-left valign-top">Meaning</th>
2850</tr>
2851</thead>
2852<tbody>
2853<tr>
2854<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>isampler1D</strong><br>
2855  <strong>itexture1D</strong><br>
2856  <strong>iimage1D</strong></p></td>
2857<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an integer 1D texture</p></td>
2858</tr>
2859<tr>
2860<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>isampler1DArray</strong><br>
2861  <strong>itexture1DArray</strong><br>
2862  <strong>iimage1DArray</strong></p></td>
2863<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an integer 1D array texture</p></td>
2864</tr>
2865<tr>
2866<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>isampler2D</strong><br>
2867  <strong>itexture2D</strong><br>
2868  <strong>iimage2D</strong></p></td>
2869<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an integer 2D texture</p></td>
2870</tr>
2871<tr>
2872<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>isampler2DArray</strong><br>
2873  <strong>itexture2DArray</strong><br>
2874  <strong>iimage2DArray</strong></p></td>
2875<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an integer 2D array texture</p></td>
2876</tr>
2877<tr>
2878<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>isampler2DMS</strong><br>
2879  <strong>itexture2DMS</strong><br>
2880  <strong>iimage2DMS</strong></p></td>
2881<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an integer 2D multisample texture</p></td>
2882</tr>
2883<tr>
2884<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>isampler2DMSArray</strong><br>
2885  <strong>itexture2DMSArray</strong><br>
2886  <strong>iimage2DMSArray</strong></p></td>
2887<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an integer 2D multisample array texture</p></td>
2888</tr>
2889<tr>
2890<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>isampler2DRect</strong><br>
2891  <strong>itexture2DRect</strong><br>
2892  <strong>iimage2DRect</strong></p></td>
2893<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an integer 2D rectangle texture</p></td>
2894</tr>
2895<tr>
2896<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>isampler3D</strong><br>
2897  <strong>itexture3D</strong><br>
2898  <strong>iimage3D</strong></p></td>
2899<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an integer 3D texture</p></td>
2900</tr>
2901<tr>
2902<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>isamplerCube</strong><br>
2903  <strong>itextureCube</strong><br>
2904  <strong>iimageCube</strong></p></td>
2905<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an integer cube mapped texture</p></td>
2906</tr>
2907<tr>
2908<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>isamplerCubeArray</strong><br>
2909  <strong>itextureCubeArray</strong><br>
2910  <strong>iimageCubeArray</strong></p></td>
2911<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an integer cube map array texture</p></td>
2912</tr>
2913<tr>
2914<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>isamplerBuffer</strong><br>
2915  <strong>itextureBuffer</strong><br>
2916  <strong>iimageBuffer</strong></p></td>
2917<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an integer buffer texture</p></td>
2918</tr>
2919<tr>
2920<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>isubpassInput</strong></p></td>
2921<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an integer subpass input</p></td>
2922</tr>
2923<tr>
2924<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>isubpassInputMS</strong></p></td>
2925<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a multi-sampled integer subpass input</p></td>
2926</tr>
2927</tbody>
2928</table>
2929<div class="paragraph">
2930<p><strong>Unsigned Integer Opaque Types</strong></p>
2931</div>
2932<table class="tableblock frame-all grid-all stretch">
2933<colgroup>
2934<col style="width: 50%;">
2935<col style="width: 50%;">
2936</colgroup>
2937<thead>
2938<tr>
2939<th class="tableblock halign-left valign-top">Type</th>
2940<th class="tableblock halign-left valign-top">Meaning</th>
2941</tr>
2942</thead>
2943<tbody>
2944<tr>
2945<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>usampler1D</strong><br>
2946  <strong>utexture1D</strong><br>
2947  <strong>uimage1D</strong></p></td>
2948<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an unsigned integer 1D texture</p></td>
2949</tr>
2950<tr>
2951<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>usampler1DArray</strong><br>
2952  <strong>utexture1DArray</strong><br>
2953  <strong>uimage1DArray</strong></p></td>
2954<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an unsigned integer 1D array texture</p></td>
2955</tr>
2956<tr>
2957<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>usampler2D</strong><br>
2958  <strong>utexture2D</strong><br>
2959  <strong>uimage2D</strong></p></td>
2960<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an unsigned integer 2D texture</p></td>
2961</tr>
2962<tr>
2963<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>usampler2DArray</strong><br>
2964  <strong>utexture1DArray</strong><br>
2965  <strong>uimage2DArray</strong></p></td>
2966<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an unsigned integer 2D array texture</p></td>
2967</tr>
2968<tr>
2969<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>usampler2DMS</strong><br>
2970  <strong>utexture2DMS</strong><br>
2971  <strong>uimage2DMS</strong></p></td>
2972<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an unsigned integer 2D multisample texture</p></td>
2973</tr>
2974<tr>
2975<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>usampler2DMSArray</strong><br>
2976  <strong>utexture2DMSArray</strong><br>
2977  <strong>uimage2DMSArray</strong></p></td>
2978<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an unsigned integer 2D multisample array texture</p></td>
2979</tr>
2980<tr>
2981<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>usampler2DRect</strong><br>
2982  <strong>utexture2DRect</strong><br>
2983  <strong>uimage2DRect</strong></p></td>
2984<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an unsigned integer rectangle texture</p></td>
2985</tr>
2986<tr>
2987<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>usampler3D</strong><br>
2988  <strong>utexture3D</strong><br>
2989  <strong>uimage3D</strong></p></td>
2990<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an unsigned integer 3D texture</p></td>
2991</tr>
2992<tr>
2993<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>usamplerCube</strong><br>
2994  <strong>utextureCube</strong><br>
2995  <strong>uimageCube</strong></p></td>
2996<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an unsigned integer cube mapped texture</p></td>
2997</tr>
2998<tr>
2999<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>usamplerCubeArray</strong><br>
3000  <strong>utextureCubeArray</strong><br>
3001  <strong>uimageCubeArray</strong></p></td>
3002<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an unsigned integer cube map array texture</p></td>
3003</tr>
3004<tr>
3005<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>usamplerBuffer</strong><br>
3006  <strong>utextureBuffer</strong><br>
3007  <strong>uimageBuffer</strong></p></td>
3008<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an unsigned integer buffer texture</p></td>
3009</tr>
3010<tr>
3011<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>atomic_uint</strong></p></td>
3012<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an unsigned integer atomic counter</p></td>
3013</tr>
3014<tr>
3015<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>usubpassInput</strong></p></td>
3016<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing an unsigned-integer subpass input</p></td>
3017</tr>
3018<tr>
3019<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>usubpassInputMS</strong></p></td>
3020<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing a multi-sampled unsigned-integer subpass input</p></td>
3021</tr>
3022</tbody>
3023</table>
3024<div class="paragraph">
3025<p><strong>Sampler Opaque Types</strong></p>
3026</div>
3027<table class="tableblock frame-all grid-all stretch">
3028<colgroup>
3029<col style="width: 50%;">
3030<col style="width: 50%;">
3031</colgroup>
3032<thead>
3033<tr>
3034<th class="tableblock halign-left valign-top">Type</th>
3035<th class="tableblock halign-left valign-top">Meaning</th>
3036</tr>
3037</thead>
3038<tbody>
3039<tr>
3040<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sampler</strong></p></td>
3041<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing state describing how to sample a texture</p></td>
3042</tr>
3043<tr>
3044<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>samplerShadow</strong></p></td>
3045<td class="tableblock halign-left valign-top"><p class="tableblock">a handle for accessing state describing how to sample a depth
3046                            texture with comparison</p></td>
3047</tr>
3048</tbody>
3049</table>
3050<div class="paragraph">
3051<p>In addition, a shader can aggregate these basic types using arrays and
3052structures to build more complex types.</p>
3053</div>
3054<div class="paragraph">
3055<p>There are no pointer types.</p>
3056</div>
3057<div class="paragraph">
3058<p>In this specification, an <em>aggregate</em> will mean a structure or array.
3059(Matrices and vectors are not by themselves aggregates.) Aggregates,
3060matrices, and vectors will collectively be referred to as <em>composites</em>.</p>
3061</div>
3062<div class="sect3">
3063<h4 id="void">4.1.1. Void</h4>
3064<div class="paragraph">
3065<p>Functions that do not return a value must be declared as <strong>void</strong>.
3066There is no default function return type.
3067The keyword <strong>void</strong> cannot be used in any other declarations (except for
3068empty formal or actual parameter lists), or a compile-time error results.</p>
3069</div>
3070</div>
3071<div class="sect3">
3072<h4 id="booleans">4.1.2. Booleans</h4>
3073<div class="dlist">
3074<dl>
3075<dt class="hdlist1">Definition</dt>
3076<dd>
3077<p>A <em>boolean type</em> is any boolean scalar or vector type (<strong>bool</strong>, <strong>bvec2</strong>,
3078<strong>bvec3</strong>, <strong>bvec4</strong>)</p>
3079</dd>
3080</dl>
3081</div>
3082<div class="paragraph">
3083<p>To make conditional execution of code easier to express, the type <strong>bool</strong> is
3084supported.
3085There is no expectation that hardware directly supports variables of this
3086type.
3087It is a genuine Boolean type, holding only one of two values meaning either
3088true or false.
3089Two keywords <strong>true</strong> and <strong>false</strong> can be used as literal Boolean constants.
3090Booleans are declared and optionally initialized as in the follow example:</p>
3091</div>
3092<div class="listingblock">
3093<div class="content">
3094<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">bool</span> success;      <span class="comment">// declare &quot;success&quot; to be a Boolean</span>
3095<span class="predefined-type">bool</span> done = <span class="predefined-constant">false</span>; <span class="comment">// declare and initialize &quot;done&quot;</span></code></pre>
3096</div>
3097</div>
3098<div class="paragraph">
3099<p>Expressions used for conditional jumps (<strong>if</strong>, <strong>for</strong>, <strong>?:</strong>, <strong>while</strong>,
3100<strong>do</strong>-<strong>while</strong>) must evaluate to the type <strong>bool</strong>.</p>
3101</div>
3102</div>
3103<div class="sect3">
3104<h4 id="integers">4.1.3. Integers</h4>
3105<div class="dlist">
3106<dl>
3107<dt class="hdlist1">Definitions</dt>
3108<dd>
3109<p>An <em>integral type</em> is any signed or unsigned, scalar or vector integer type.
3110It excludes arrays and structures.</p>
3111</dd>
3112<dt class="hdlist1"></dt>
3113<dd>
3114<p>A <em>scalar integral type</em> is a scalar signed or unsigned integer type:</p>
3115</dd>
3116<dt class="hdlist1"></dt>
3117<dd>
3118<p>A <em>vector integral type</em> is a vector of signed or unsigned integers:</p>
3119</dd>
3120</dl>
3121</div>
3122<div class="paragraph">
3123<p>Signed and unsigned integer variables are fully supported.
3124In this document, the term <em>integer</em> is meant to generally include both
3125signed and unsigned integers.</p>
3126</div>
3127<div class="paragraph">
3128<p>For OpenGL, unsigned integers have exactly 32 bits of precision.
3129When targeting Vulkan, <strong>highp</strong>
3130unsigned integers have exactly 32 bits of precision.</p>
3131</div>
3132<div class="paragraph">
3133<p>For OpenGL, signed integers use 32 bits, including a sign bit, in two&#8217;s complement form.
3134When targeting Vulkan, <strong>highp</strong>
3135signed integers use 32 bits, including a sign bit, in two&#8217;s complement form.</p>
3136</div>
3137<div class="paragraph">
3138<p>When targeting Vulkan, <strong>mediump</strong> and <strong>lowp</strong> integers are as defined by the
3139SPIR-V <strong>RelaxedPrecision</strong> decoration.</p>
3140</div>
3141<div class="paragraph">
3142<p>Addition,
3143subtraction and multiplication resulting in overflow or
3144underflow will result in the low-order
314532
3146bits of the correct result R, where
3147R is computed with enough precision to avoid overflow or underflow.
3148Division resulting in overflow will result in an undefined value.</p>
3149</div>
3150<div class="paragraph">
3151<p>Integers are declared and optionally initialized with integer expressions,
3152as in the following example:</p>
3153</div>
3154<div class="listingblock">
3155<div class="content">
3156<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">int</span> i, j = <span class="integer">42</span>; <span class="comment">// default integer literal type is int</span>
3157uint k = <span class="integer">3</span>u;   <span class="comment">// &quot;u&quot; establishes the type as uint</span></code></pre>
3158</div>
3159</div>
3160<div class="paragraph">
3161<p>Literal integer constants can be expressed in decimal (base 10), octal (base
31628), or hexadecimal (base 16) as follows.</p>
3163</div>
3164<div class="openblock bnf">
3165<div class="content">
3166<div class="dlist">
3167<dl>
3168<dt class="hdlist1"><em>integer-constant</em> : </dt>
3169<dd>
3170<p><em>decimal-constant</em> <em>integer-suffix<sub>opt</sub></em><br>
3171<em>octal-constant</em> <em>integer-suffix<sub>opt</sub></em><br>
3172<em>hexadecimal-constant</em> <em>integer-suffix<sub>opt</sub></em></p>
3173</dd>
3174<dt class="hdlist1"><em>integer-suffix</em> : one of </dt>
3175<dd>
3176<p><strong>u</strong> <strong>U</strong></p>
3177</dd>
3178<dt class="hdlist1"><em>decimal-constant</em> : </dt>
3179<dd>
3180<p><em>nonzero-digit</em><br>
3181<em>decimal-constant</em> <em>digit</em></p>
3182</dd>
3183<dt class="hdlist1"><em>octal-constant</em> : </dt>
3184<dd>
3185<p><strong>0</strong><br>
3186<em>octal-constant</em> <em>octal-digit</em></p>
3187</dd>
3188<dt class="hdlist1"><em>hexadecimal-constant</em> : </dt>
3189<dd>
3190<p><strong>0x</strong> <em>hexadecimal-digit</em><br>
3191<strong>0X</strong> <em>hexadecimal-digit</em><br>
3192<em>hexadecimal-constant</em> <em>hexadecimal-digit</em></p>
3193</dd>
3194<dt class="hdlist1"><em>digit</em> : </dt>
3195<dd>
3196<p><strong>0</strong><br>
3197<em>nonzero-digit</em></p>
3198</dd>
3199<dt class="hdlist1"><em>nonzero-digit</em> : one of </dt>
3200<dd>
3201<p><strong>1 2 3 4 5 6 7 8 9</strong></p>
3202</dd>
3203<dt class="hdlist1"><em>octal-digit</em> : one of </dt>
3204<dd>
3205<p><strong>0 1 2 3 4 5 6 7</strong></p>
3206</dd>
3207<dt class="hdlist1"><em>hexadecimal-digit</em> : one of </dt>
3208<dd>
3209<p><strong>0 1 2 3 4 5 6 7 8 9<br>
3210a b c d e f<br>
3211A B C D E F</strong></p>
3212</dd>
3213</dl>
3214</div>
3215</div>
3216</div>
3217<div class="paragraph">
3218<p>No white space is allowed between the digits of an integer constant,
3219including after the leading <strong>0</strong> or after the leading <strong>0x</strong> or <strong>0X</strong> of a
3220constant, or before the suffix <strong>u</strong> or <strong>U</strong>.
3221When tokenizing, the maximal token matching the above will be recognized
3222before a new token is started.
3223When the suffix <strong>u</strong> or <strong>U</strong> is present, the literal has type <strong>uint</strong>,
3224otherwise the type is <strong>int</strong>.
3225A leading unary minus sign (-) is interpreted as an arithmetic unary
3226negation, not as part of the constant.
3227Hence, literals themselves are always expressed with non-negative syntax,
3228though they could result in a negative value.</p>
3229</div>
3230<div class="paragraph">
3231<p>It is a compile-time error to provide a literal integer whose bit pattern
3232cannot fit in 32 bits.
3233The bit pattern of the literal is always used unmodified.
3234So a signed literal whose bit pattern includes a set sign bit creates a
3235negative value.</p>
3236</div>
3237<div class="paragraph">
3238<p>For example,</p>
3239</div>
3240<div class="listingblock">
3241<div class="content">
3242<pre class="CodeRay highlight"><code data-lang="c++"><span class="integer">1</span>             <span class="comment">// OK. Signed integer, value 1</span>
3243<span class="integer">1</span>u            <span class="comment">// OK. Unsigned integer, value 1</span>
3244-<span class="integer">1</span>            <span class="comment">// OK. Unary minus applied to signed integer.</span>
3245              <span class="comment">// result is a signed integer, value -1</span>
3246-<span class="integer">1</span>u           <span class="comment">// OK. Unary minus applies to unsigned integer.</span>
3247              <span class="comment">// Result is an unsigned integer, value 0xffffffff</span>
3248<span class="hex">0xA0000000</span>    <span class="comment">// OK. 32-bit signed hexadecimal</span>
3249<span class="hex">0xABcdEF00</span>u   <span class="comment">// OK. 32-bit unsigned hexadecimal</span>
3250<span class="hex">0xffffffff</span>    <span class="comment">// OK. Signed integer, value -1</span>
3251<span class="hex">0x80000000</span>    <span class="comment">// OK. Evaluates to -2147483648</span>
3252<span class="hex">0xffffffff</span>u   <span class="comment">// OK. Unsigned integer, value 0xffffffff</span>
3253<span class="hex">0xfffffffff</span>   <span class="comment">// Error: needs more than 32 bits</span>
3254<span class="integer">3000000000</span>    <span class="comment">// OK. A signed decimal literal taking 32 bits.</span>
3255              <span class="comment">// It evaluates to -1294967296</span>
3256<span class="integer">2147483648</span>    <span class="comment">// OK. Evaluates to -2147483648 (the literal set the sign bit)</span>
3257<span class="integer">5000000000</span>    <span class="comment">// Error: needs more than 32 bits</span></code></pre>
3258</div>
3259</div>
3260</div>
3261<div class="sect3">
3262<h4 id="floats">4.1.4. Floats</h4>
3263<div class="paragraph">
3264<p>Single-precision and double-precision floating-point variables are available
3265for use in a variety of scalar calculations.
3266Generally, the term <em>floating-point</em> will refer to both single- and
3267double-precision floating-point.
3268Floating-point variables are defined as in the following examples:</p>
3269</div>
3270<div class="listingblock">
3271<div class="content">
3272<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span> a, b = <span class="float">1</span><span class="float">.5</span>;    <span class="comment">// single-precision floating-point</span>
3273<span class="predefined-type">double</span> c, d = <span class="float">2</span><span class="float">.0</span>LF; <span class="comment">// double-precision floating-point</span></code></pre>
3274</div>
3275</div>
3276<div class="paragraph">
3277<p>As an input value to one of the processing units, a single-precision or
3278double-precision floating-point variable is expected to match the
3279corresponding IEEE 754 floating-point definition for precision and dynamic
3280range.
3281Floating-point variables within a shader are also encoded according to the
3282IEEE 754 specification for single-precision floating-point values</p>
3283</div>
3284<div class="paragraph">
3285<p>(logically, not necessarily physically).
3286While encodings are logically IEEE 754, operations (addition,
3287multiplication, etc.) are not necessarily performed as required by IEEE 754.
3288See &#8220;<a href="#range-and-precision">Range and Precision</a>&#8221; for more details on
3289precision and usage of NaNs (Not a Number) and Infs (positive or negative
3290infinities).</p>
3291</div>
3292<div class="paragraph">
3293<p>Floating-point constants are defined as follows.</p>
3294</div>
3295<div class="openblock bnf">
3296<div class="content">
3297<div class="dlist">
3298<dl>
3299<dt class="hdlist1"><em>floating-constant</em> : </dt>
3300<dd>
3301<p><em>fractional-constant</em> <em>exponent-part<sub>opt</sub></em> <em>floating-suffix<sub>opt</sub></em><br>
3302<em>digit-sequence</em> <em>exponent-part</em> <em>floating-suffix<sub>opt</sub></em></p>
3303</dd>
3304<dt class="hdlist1"><em>fractional-constant</em> : </dt>
3305<dd>
3306<p><em>digit-sequence</em> <strong>.</strong> <em>digit-sequence</em><br>
3307<em>digit-sequence</em> <strong>.</strong><br>
3308<strong>.</strong> <em>digit-sequence</em></p>
3309</dd>
3310<dt class="hdlist1"><em>exponent-part</em> : </dt>
3311<dd>
3312<p><strong>e</strong> <em>sign<sub>opt</sub></em> <em>digit-sequence</em><br>
3313<strong>E</strong> <em>sign<sub>opt</sub></em> <em>digit-sequence</em></p>
3314</dd>
3315<dt class="hdlist1"><em>sign</em> : one of </dt>
3316<dd>
3317<p><strong>+</strong> <strong>-</strong></p>
3318</dd>
3319<dt class="hdlist1"><em>digit-sequence</em> : </dt>
3320<dd>
3321<p><em>digit</em><br>
3322<em>digit-sequence</em> <em>digit</em></p>
3323</dd>
3324<dt class="hdlist1"><em>floating-suffix</em> : one of </dt>
3325<dd>
3326<p>    <strong>f</strong> <strong>F</strong>
3327<strong>lf</strong> <strong>LF</strong></p>
3328</dd>
3329</dl>
3330</div>
3331</div>
3332</div>
3333<div class="paragraph">
3334<p>A decimal point (<strong>.</strong>) is not needed if the exponent part is present.
3335No white space may appear anywhere within a floating-point constant,
3336including before a suffix.
3337When tokenizing, the maximal token matching the above will be recognized
3338before a new token is started.
3339When the suffix "lf" or "LF" is present, the literal has type <strong>double</strong>.
3340Otherwise, the literal has type <strong>float</strong>.
3341A leading unary minus sign (<strong>-</strong>) is interpreted as a unary operator and is
3342not part of the floating-point constant.</p>
3343</div>
3344</div>
3345<div class="sect3">
3346<h4 id="vectors">4.1.5. Vectors</h4>
3347<div class="paragraph">
3348<p>The OpenGL Shading Language includes data types for generic 2-, 3-, and 4-component vectors
3349of floating-point values, integers, and Booleans.
3350Floating-point vector variables can be used to store colors, normals,
3351positions, texture coordinates, texture lookup results and the like.
3352Boolean vectors can be used for component-wise comparisons of numeric
3353vectors.
3354Some examples of vector declarations are:</p>
3355</div>
3356<div class="listingblock">
3357<div class="content">
3358<pre class="CodeRay highlight"><code data-lang="c++">vec2 texcoord1, texcoord2;
3359vec3 position;
3360vec4 myRGBA;
3361ivec2 textureLookup;
3362bvec3 less;</code></pre>
3363</div>
3364</div>
3365<div class="paragraph">
3366<p>Initialization of vectors can be done with constructors.
3367See &#8220;<a href="#vector-and-matrix-constructors">Vector and Matrix Constructors</a>&#8221;.</p>
3368</div>
3369</div>
3370<div class="sect3">
3371<h4 id="matrices">4.1.6. Matrices</h4>
3372<div class="paragraph">
3373<p>The OpenGL Shading Language has built-in types for 2 × 2, 2 × 3, 2 × 4, 3
3374× 2, 3 × 3, 3 × 4, 4 × 2, 4 × 3, and 4 ×
33754 matrices of floating-point numbers.
3376Matrix types beginning with "<strong>mat</strong>" have single-precision components while
3377matrix types beginning with "<strong>dmat</strong>" have double-precision components.
3378The first number in the type is the number of columns, the second is the
3379number of rows.
3380If there is only one number, the matrix is square.
3381Example matrix declarations:</p>
3382</div>
3383<div class="listingblock">
3384<div class="content">
3385<pre class="CodeRay highlight"><code data-lang="c++">mat2 mat2D;
3386mat3 optMatrix;
3387mat4 view, projection;
3388mat4x4 view; <span class="comment">// an alternate way of declaring a mat4</span>
3389mat3x2 m;    <span class="comment">// a matrix with 3 columns and 2 rows</span>
3390dmat4 highPrecisionMVP;
3391dmat2x4 dm;</code></pre>
3392</div>
3393</div>
3394<div class="paragraph">
3395<p>Initialization of matrix values is done with constructors (described in
3396&#8220;<a href="#vector-and-matrix-constructors">Vector and Matrix Constructors</a>&#8221;) in
3397column-major order.</p>
3398</div>
3399</div>
3400<div class="sect3">
3401<h4 id="opaque-types">4.1.7. Opaque Types</h4>
3402<div class="dlist">
3403<dl>
3404<dt class="hdlist1">Definition</dt>
3405<dd>
3406<p>An <em>opaque type</em> is a type where the internal structure of the type is
3407hidden from the language.</p>
3408</dd>
3409</dl>
3410</div>
3411<div class="paragraph">
3412<p>The opaque types, as listed in the following sections, declare variables
3413that are effectively opaque handles to other objects.
3414These objects are accessed through built-in functions, not through direct
3415reading or writing of the declared variable.
3416They can only be declared as function parameters or in <strong>uniform</strong>-qualified
3417variables (see &#8220;<a href="#uniform-variables">Uniform Variables</a>&#8221;).
3418The only opaque types that take memory qualifiers are the image types.
3419Except for array indexing, structure member selection, and parentheses,
3420opaque variables are not allowed to be operands in expressions; such use
3421results in a compile-time error.</p>
3422</div>
3423<div class="paragraph">
3424<p>Opaque variables cannot be treated as l-values; hence cannot be used as
3425<strong>out</strong> or <strong>inout</strong> function parameters, nor can they be assigned into.
3426Any such use results in a compile-time error.
3427However, they can be passed as <strong>in</strong> parameters with matching types and
3428memory qualifiers.
3429They cannot be declared with an initializer.</p>
3430</div>
3431<div class="paragraph">
3432<p>Because a single opaque type declaration effectively declares two objects,
3433the opaque handle itself and the object it is a handle to, there is room for
3434both a storage qualifier and a memory qualifier.
3435The storage qualifier will qualify the opaque handle, while the memory
3436qualifier will qualify the object it is a handle to.</p>
3437</div>
3438<div class="sect4">
3439<h5 id="samplers">Texture-Combined Samplers</h5>
3440<div class="paragraph">
3441<p>Texture-combined sampler types (e.g. <strong>sampler2D</strong>) are the sampler types
3442described in the Basic Types tables as handles for accessing textures.
3443(They do not include <strong>sampler</strong> and <strong>samplerShadow</strong>.)
3444There are distinct texture-combined sampler types for each texture target,
3445and for each of float, integer, and unsigned integer data types.
3446Texture accesses are done through built-in texture functions (described in
3447&#8220;<a href="#texture-functions">Texture Functions</a>&#8221;) and texture-combined samplers
3448are used to specify which texture to access and how it is to be filtered.</p>
3449</div>
3450<div class="paragraph">
3451<p>Texture-combined sampler types are opaque types,
3452declared and behaving as described above for opaque types.
3453When aggregated into arrays within a shader, they can only be indexed
3454with a dynamically uniform integral expression, otherwise results are
3455undefined.</p>
3456</div>
3457</div>
3458<div class="sect4">
3459<h5 id="images">Images</h5>
3460<div class="paragraph">
3461<p>Image types are opaque types, declared and behaving as described above for
3462opaque types.
3463They can be further qualified with memory qualifiers.
3464When aggregated into arrays within a shader, images can only be indexed with
3465a dynamically uniform integral expression, otherwise results are undefined.</p>
3466</div>
3467<div class="paragraph">
3468<p>Image variables are handles to
3469one-,
3470two-, or three-dimensional images
3471corresponding to all or a portion of a single level of a texture image bound
3472to an image unit.
3473There are distinct image variable types for each texture target, and for
3474each of float, integer, and unsigned integer data types.
3475Image accesses should use an image type that matches the target of the
3476texture whose level is bound to the image unit, or for non-layered bindings
3477of 3D or array images should use the image type that matches the
3478dimensionality of the layer of the image (i.e., a layer of 3D, 2DArray,
3479Cube, or CubeArray should use
3480<strong>image2D</strong>, a layer of 1DArray should use <strong>image1D</strong>, and a layer of 2DMSArray
3481should use <strong>image2DMS</strong>).
3482If the image target type does not match the bound image in this manner, if
3483the data type does not match the bound image, or if the format layout
3484qualifier does not match the image unit format as described in section
34858.25
3486&#8220;Texture Image Loads and Stores&#8221; of the <a href="#references">OpenGL Specification</a>, the
3487results of image accesses are undefined but cannot include program
3488termination.</p>
3489</div>
3490<div class="paragraph">
3491<p>Image variables are used in the image load, store, and atomic functions
3492described in &#8220;<a href="#image-functions">Image Functions</a>&#8221; to specify an image to
3493access.</p>
3494</div>
3495</div>
3496<div class="sect4">
3497<h5 id="atomic-counters">Atomic Counters</h5>
3498<div class="paragraph">
3499<p>Atomic counter types (e.g. <strong>atomic_uint</strong>) are opaque handles to counters,
3500declared and behaving as described above for opaque types.
3501The variables they declare specify which counter to access when using the
3502built-in atomic counter functions as described in
3503&#8220;<a href="#atomic-counter-functions">Atomic Counter Functions</a>&#8221;.
3504They are bound to buffers as described in
3505&#8220;<a href="#atomic-counter-layout-qualifiers">Atomic Counter Layout Qualifiers</a>&#8221;.</p>
3506</div>
3507<div class="paragraph">
3508<p>Atomic counters aggregated into arrays within a shader can only be indexed
3509with dynamically uniform integral expressions, otherwise results are
3510undefined.</p>
3511</div>
3512<div class="paragraph">
3513<p>Members of structures cannot be declared as atomic counter types.</p>
3514</div>
3515<div class="paragraph">
3516<p>Atomic counter types are not available when targeting Vulkan.</p>
3517</div>
3518</div>
3519<div class="sect4">
3520<h5 id="_texture_sampler_and_samplershadow_types">Texture, <strong>sampler</strong>, and <strong>samplerShadow</strong> Types</h5>
3521<div class="paragraph">
3522<p>Texture (e.g., <strong>texture2D</strong>), <strong>sampler</strong>, and <strong>samplerShadow</strong> types are opaque
3523types, declared and behaving as described above for opaque types.
3524These types are only available when targeting Vulkan.
3525When aggregated into arrays within a shader, these types can only be indexed
3526with a dynamically uniform expression, or texture lookup will result in
3527undefined values.
3528Texture variables are handles to one-, two-, and three-dimensional textures,
3529cube maps, etc., as enumerated in the basic types tables.
3530There are distinct texture types for each texture target, and for each of
3531float, integer, and unsigned integer data types.
3532Textures can be combined with a variable of type <strong>sampler</strong> or <strong>samplerShadow</strong>
3533to create a texture-combined sampler type (e.g., sampler2D, or sampler2DShadow).
3534This is done with a constructor, e.g., <code>sampler2D(texture2D, sampler)</code>,
3535<code>sampler2DShadow(texture2D, sampler)</code>, <code>sampler2DShadow(texture2D, samplerShadow)</code>,
3536or <code>sampler2D(texture2D, samplerShadow)</code> and is described in more detail
3537in section 5.4 "Constructors".</p>
3538</div>
3539</div>
3540<div class="sect4">
3541<h5 id="_subpass_inputs">Subpass Inputs</h5>
3542<div class="paragraph">
3543<p>Subpass-input types are only available when targeting Vulkan.</p>
3544</div>
3545<div class="paragraph">
3546<p>Subpass-input types (e.g., <strong>subpassInput</strong>) are opaque types, declared
3547and behaving as described above for opaque types.
3548When aggregated into arrays within a shader, they can only be indexed with a
3549dynamically uniform integral expression, otherwise results are undefined.</p>
3550</div>
3551<div class="paragraph">
3552<p>Subpass-input types are handles to two-dimensional single sampled or
3553multi-sampled images, with distinct types for each of float, integer,
3554and unsigned integer data types.</p>
3555</div>
3556<div class="paragraph">
3557<p>Subpass-input types are only available in fragment shaders.  It is
3558a compile-time error to use them in any other stage.</p>
3559</div>
3560</div>
3561</div>
3562<div class="sect3">
3563<h4 id="structures">4.1.8. Structures</h4>
3564<div class="paragraph">
3565<p>User-defined types can be created by aggregating other already defined types
3566into a structure using the <strong>struct</strong> keyword.
3567For example,</p>
3568</div>
3569<div class="listingblock">
3570<div class="content">
3571<pre class="CodeRay highlight"><code data-lang="c++"><span class="keyword">struct</span> light {
3572    <span class="predefined-type">float</span> intensity;
3573    vec3 position;
3574} lightVar;</code></pre>
3575</div>
3576</div>
3577<div class="paragraph">
3578<p>In this example, <em>light</em> becomes the name of the new type, and <em>lightVar</em>
3579becomes a variable of type <em>light</em>.
3580To declare variables of the new type, use its name (without the keyword
3581<strong>struct</strong>).</p>
3582</div>
3583<div class="listingblock">
3584<div class="content">
3585<pre class="CodeRay highlight"><code data-lang="c++">light lightVar2;</code></pre>
3586</div>
3587</div>
3588<div class="paragraph">
3589<p>More formally, structures are declared as follows.
3590However, the definitive grammar is as given in
3591&#8220;<a href="#shading-language-grammar">Shading Language Grammar</a>&#8221;.</p>
3592</div>
3593<div class="openblock bnf">
3594<div class="content">
3595<div class="dlist">
3596<dl>
3597<dt class="hdlist1"><em>struct-definition</em> : </dt>
3598<dd>
3599<p><em>qualifier<sub>opt</sub></em> <strong>struct</strong> name<sub>opt</sub>_ <strong>{</strong> <em>member-list</em> <strong>}</strong>
3600<em>declarators<sub>opt</sub></em> <strong>;</strong></p>
3601</dd>
3602<dt class="hdlist1"><em>member-list</em> : </dt>
3603<dd>
3604<p><em>member-declaration</em> <strong>;</strong><br>
3605<em>member-declaration</em> <em>member-list</em> <strong>;</strong></p>
3606</dd>
3607<dt class="hdlist1"><em>member-declaration</em> : </dt>
3608<dd>
3609<p><em>basic-type</em> <em>declarators</em> <strong>;</strong></p>
3610</dd>
3611</dl>
3612</div>
3613</div>
3614</div>
3615<div class="paragraph">
3616<p>where <em>name</em> becomes the user-defined type, and can be used to declare
3617variables to be of this new type.
3618The <em>name</em> shares the same name space as other variables, types, and
3619functions.
3620All previously visible variables, types, constructors, or functions with
3621that name are hidden.
3622The optional <em>qualifier</em> only applies to any <em>declarators</em>, and is not part
3623of the type being defined for <em>name</em>.</p>
3624</div>
3625<div class="paragraph">
3626<p>Structures must have at least one member declaration.
3627Member declarators may contain precision qualifiers, but use of any other
3628qualifier results in a compile-time error.
3629Bit fields are not supported.
3630Member types must be already defined (there are no forward references).
3631A compile-time error results if a member declaration contains an
3632initializer.
3633Member declarators can contain arrays.
3634Such arrays must have a size specified, and the size must be a constant
3635integral expression that&#8217;s greater than zero (see
3636&#8220;<a href="#constant-expressions">Constant Expressions</a>&#8221;).
3637Each level of structure has its own name space for names given in member
3638declarators; such names need only be unique within that name space.</p>
3639</div>
3640<div class="paragraph">
3641<p>Anonymous structures are not supported.
3642Embedded structure definitions are not supported.
3643These result in compile-time errors.</p>
3644</div>
3645<div class="listingblock">
3646<div class="content">
3647<pre class="CodeRay highlight"><code data-lang="c++"><span class="keyword">struct</span> S { <span class="predefined-type">float</span> f; }; <span class="comment">// Allowed: S is defined as a structure.</span>
3648
3649<span class="keyword">struct</span> T {
3650    S;              <span class="comment">// Error: anonymous structures disallowed</span>
3651    <span class="keyword">struct</span> { ... }; <span class="comment">// Error: embedded structures disallowed</span>
3652    S s;            <span class="comment">// Allowed: nested structure with a name.</span>
3653};</code></pre>
3654</div>
3655</div>
3656<div class="paragraph">
3657<p>Structures can be initialized at declaration time using constructors, as
3658discussed in &#8220;<a href="#structure-constructors">Structure Constructors</a>&#8221;.</p>
3659</div>
3660<div class="paragraph">
3661<p>Any restrictions on the usage of a type or qualifier also apply to any
3662structure that contains a member of that type or qualifier.
3663This also applies to structure members that are structures, recursively.</p>
3664</div>
3665</div>
3666<div class="sect3">
3667<h4 id="arrays">4.1.9. Arrays</h4>
3668<div class="paragraph">
3669<p>Variables of the same type can be aggregated into arrays by declaring a name
3670followed by brackets (<strong>[ ]</strong>) enclosing an optional size.
3671When an array size is specified in a declaration, it must be an integral
3672constant expression (see &#8220;<a href="#constant-expressions">Constant Expressions</a>&#8221;)
3673greater than zero.
3674Except for the last declared member of a shader storage block (see section
3675&#8220;<a href="#interface-blocks">Interface Blocks</a>&#8221;), the size of an array must be
3676declared (<em>explicitly sized</em>) before it is indexed with anything other than
3677a constant integral expression.
3678The size of any array must be declared before passing it as an argument to a
3679function.
3680Violation of any of these rules result in compile-time errors.
3681It is legal to declare an array without a size (<em>unsized</em>) and then later
3682redeclare the same name as an array of the same type and specify a size, or
3683index it only with constant integral expressions (<em>implicitly sized</em>).
3684However, unless noted otherwise, blocks cannot be redeclared; an unsized
3685array member in a user-declared block cannot be sized by a block redeclaration.
3686It is a compile-time error to declare an array with a size, and then later
3687(in the same shader) index the same array with a constant integral
3688expression greater than or equal to the declared size.
3689It is a compile-time error to redeclare an unsized array with a size equal
3690to or smaller than any index used earlier in the shader to index the array.
3691It is also a compile-time error to index an array with a negative constant
3692expression.
3693Arrays declared as formal parameters in a function declaration must specify
3694a size.
3695Undefined behavior results from indexing an array with a non-constant
3696expression that&#8217;s greater than or equal to the array&#8217;s size or less than 0.
3697Arrays only have a single dimension (a single entry within "[ ]"), however,
3698arrays of arrays can be declared.
3699All types (basic types, structures, arrays) can be formed into an array.</p>
3700</div>
3701<div class="paragraph">
3702<p>All arrays are inherently homogeneous; made of elements all having the same
3703type and size, with one exception.
3704The exception is a shader storage block having an unsized array as its last
3705member (<em>run-time sized</em>); an array can be formed from such a shader storage
3706block, even if the storage blocks have differing lengths for their last
3707member.</p>
3708</div>
3709<div class="paragraph">
3710<p>Some examples are:</p>
3711</div>
3712<div class="listingblock">
3713<div class="content">
3714<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span> frequencies[<span class="integer">3</span>];
3715uniform vec4 lightPosition[<span class="integer">4</span>];
3716light lights[];
3717<span class="directive">const</span> <span class="predefined-type">int</span> numLights = <span class="integer">2</span>;
3718light lights[numLights];
3719
3720<span class="comment">// a shader storage block, introduced in section 4.3.7 &quot;Buffer Variables&quot;</span>
3721buffer b {
3722    <span class="predefined-type">float</span> u[]; <span class="comment">// an error, unless u gets statically sized by link time</span>
3723    vec4 v[];  <span class="comment">// okay, v will be sized dynamically, if not statically</span>
3724} name[<span class="integer">3</span>];     <span class="comment">// when the block is arrayed, all u will be the same size,</span>
3725               <span class="comment">// but not necessarily all v, if sized dynamically</span></code></pre>
3726</div>
3727</div>
3728<div class="paragraph">
3729<p>An array type can be formed by specifying non-array type followed by an
3730array specifier.
3731All dimensions of such an array specifier must include a size.</p>
3732</div>
3733<div class="listingblock">
3734<div class="content">
3735<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span>[<span class="integer">5</span>]    <span class="comment">// an array of size [5] of float</span>
3736<span class="predefined-type">float</span>[<span class="integer">2</span>][<span class="integer">3</span>] <span class="comment">// an array of size [2][3] of float, not size [3] of float[2]</span></code></pre>
3737</div>
3738</div>
3739<div class="paragraph">
3740<p>This type can be used anywhere any other type can be used, including as the
3741return value from a function</p>
3742</div>
3743<div class="listingblock">
3744<div class="content">
3745<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span>[<span class="integer">5</span>] foo() { }</code></pre>
3746</div>
3747</div>
3748<div class="paragraph">
3749<p>as a constructor of an array:</p>
3750</div>
3751<div class="listingblock">
3752<div class="content">
3753<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span>[<span class="integer">5</span>](<span class="float">3</span><span class="float">.4</span>, <span class="float">4</span><span class="float">.2</span>, <span class="float">5</span><span class="float">.0</span>, <span class="float">5</span><span class="float">.2</span>, <span class="float">1</span><span class="float">.1</span>)</code></pre>
3754</div>
3755</div>
3756<div class="paragraph">
3757<p>as an unnamed parameter:</p>
3758</div>
3759<div class="listingblock">
3760<div class="content">
3761<pre class="CodeRay highlight"><code data-lang="c++"><span class="directive">void</span> foo(<span class="predefined-type">float</span>[<span class="integer">5</span>])</code></pre>
3762</div>
3763</div>
3764<div class="paragraph">
3765<p>and as an alternate way of declaring a variable or function parameter:</p>
3766</div>
3767<div class="listingblock">
3768<div class="content">
3769<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span>[<span class="integer">5</span>] a;</code></pre>
3770</div>
3771</div>
3772<div class="paragraph">
3773<p>Arrays can have initializers formed from array constructors:</p>
3774</div>
3775<div class="listingblock">
3776<div class="content">
3777<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span> a[<span class="integer">5</span>] = <span class="predefined-type">float</span>[<span class="integer">5</span>](<span class="float">3</span><span class="float">.4</span>, <span class="float">4</span><span class="float">.2</span>, <span class="float">5</span><span class="float">.0</span>, <span class="float">5</span><span class="float">.2</span>, <span class="float">1</span><span class="float">.1</span>);
3778<span class="predefined-type">float</span> a[<span class="integer">5</span>] = <span class="predefined-type">float</span>[](<span class="float">3</span><span class="float">.4</span>, <span class="float">4</span><span class="float">.2</span>, <span class="float">5</span><span class="float">.0</span>, <span class="float">5</span><span class="float">.2</span>, <span class="float">1</span><span class="float">.1</span>);  <span class="comment">// same thing</span></code></pre>
3779</div>
3780</div>
3781<div class="paragraph">
3782<p>An array of arrays can be declared as:</p>
3783</div>
3784<div class="listingblock">
3785<div class="content">
3786<pre class="CodeRay highlight"><code data-lang="c++">vec4 a[<span class="integer">3</span>][<span class="integer">2</span>]; <span class="comment">// size-3 array of size-2 array of vec4</span></code></pre>
3787</div>
3788</div>
3789<div class="paragraph">
3790<p>which declares a one-dimensional array of size 3 of one-dimensional arrays
3791of size 2 of <strong>vec4</strong>.
3792The following declarations do the same thing:</p>
3793</div>
3794<div class="listingblock">
3795<div class="content">
3796<pre class="CodeRay highlight"><code data-lang="c++">vec4[<span class="integer">2</span>] a[<span class="integer">3</span>]; <span class="comment">// size-3 array of size-2 array of vec4</span>
3797vec4[<span class="integer">3</span>][<span class="integer">2</span>] a; <span class="comment">// size-3 array of size-2 array of vec4</span></code></pre>
3798</div>
3799</div>
3800<div class="paragraph">
3801<p>When in transparent memory (like in a uniform block), the layout is that the
3802inner-most (right-most in declaration) dimensions iterate faster than the
3803outer dimensions.
3804That is, for the above, the order in memory would be:</p>
3805</div>
3806<div class="dlist">
3807<dl>
3808<dt class="hdlist1"></dt>
3809<dd>
3810<p>Low address : a[0][0] : a[0][1] : a[1][0] : a[1][1] : a[2][0] : a[2][1]
3811: High address</p>
3812</dd>
3813</dl>
3814</div>
3815<div class="paragraph">
3816<p>The type of <em>a</em> needed for both constructors and nameless parameters is
3817&#8220;vec4[3][2]&#8221;:</p>
3818</div>
3819<div class="listingblock">
3820<div class="content">
3821<pre class="CodeRay highlight"><code data-lang="c++">vec4 b[<span class="integer">2</span>] = vec4[<span class="integer">2</span>](vec4(<span class="float">0</span><span class="float">.0</span>), vec4(<span class="float">0</span><span class="float">.1</span>));
3822vec4[<span class="integer">3</span>][<span class="integer">2</span>] a = vec4[<span class="integer">3</span>][<span class="integer">2</span>](b, b, b);        <span class="comment">// constructor</span>
3823<span class="directive">void</span> foo(vec4[<span class="integer">3</span>][<span class="integer">2</span>]); <span class="comment">// prototype with unnamed parameter</span></code></pre>
3824</div>
3825</div>
3826<div class="paragraph">
3827<p>Alternatively, the initializer-list syntax can be used to initialize an
3828array of arrays:</p>
3829</div>
3830<div class="listingblock">
3831<div class="content">
3832<pre class="CodeRay highlight"><code data-lang="c++">vec4 a[<span class="integer">3</span>][<span class="integer">2</span>] = { vec4[<span class="integer">2</span>](vec4(<span class="float">0</span><span class="float">.0</span>), vec4(<span class="float">1</span><span class="float">.0</span>)),
3833                 vec4[<span class="integer">2</span>](vec4(<span class="float">0</span><span class="float">.0</span>), vec4(<span class="float">1</span><span class="float">.0</span>)),
3834                 vec4[<span class="integer">2</span>](vec4(<span class="float">0</span><span class="float">.0</span>), vec4(<span class="float">1</span><span class="float">.0</span>)) };</code></pre>
3835</div>
3836</div>
3837<div class="paragraph">
3838<p>Unsized arrays can be explicitly sized by an initializer at declaration
3839time:</p>
3840</div>
3841<div class="listingblock">
3842<div class="content">
3843<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span> a[<span class="integer">5</span>];
3844...
3845<span class="predefined-type">float</span> b[] = a;  <span class="comment">// b is explicitly size 5</span>
3846<span class="predefined-type">float</span> b[<span class="integer">5</span>] = a; <span class="comment">// means the same thing</span>
3847<span class="predefined-type">float</span> b[] = <span class="predefined-type">float</span>[](<span class="integer">1</span>,<span class="integer">2</span>,<span class="integer">3</span>,<span class="integer">4</span>,<span class="integer">5</span>); <span class="comment">// also explicitly sizes to 5</span></code></pre>
3848</div>
3849</div>
3850<div class="paragraph">
3851<p>However, it is a compile-time error to assign to an unsized array.
3852Note, this is a rare case that initializers and assignments appear to have
3853different semantics.
3854For arrays of arrays, any unsized dimension is explicitly sized by the
3855initializer:</p>
3856</div>
3857<div class="listingblock">
3858<div class="content">
3859<pre class="CodeRay highlight"><code data-lang="c++">vec4 a[][] = { vec4[<span class="integer">2</span>](vec4(<span class="float">0</span><span class="float">.0</span>), vec4(<span class="float">1</span><span class="float">.0</span>)), <span class="comment">// okay, size to a[3][2]</span>
3860               vec4[<span class="integer">2</span>](vec4(<span class="float">0</span><span class="float">.0</span>), vec4(<span class="float">1</span><span class="float">.0</span>)),
3861               vec4[<span class="integer">2</span>](vec4(<span class="float">0</span><span class="float">.0</span>), vec4(<span class="float">1</span><span class="float">.0</span>)) };</code></pre>
3862</div>
3863</div>
3864<div class="paragraph">
3865<p>Arrays know the number of elements they contain.
3866This can be obtained by using the <strong>length</strong>() method:</p>
3867</div>
3868<div class="listingblock">
3869<div class="content">
3870<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span> a[<span class="integer">5</span>];
3871a.length(); <span class="comment">// returns 5</span></code></pre>
3872</div>
3873</div>
3874<div class="paragraph">
3875<p>This returns a type <strong>int</strong>.
3876If an array has been explicitly sized, the value returned by the <strong>length</strong>()
3877method is a constant expression.
3878If an array has not been explicitly sized and is the last declared member of
3879a shader storage block, the value returned will not be a constant expression
3880and will be determined at runtime based on the size of the buffer object
3881providing storage for the block.
3882Such arrays are runtime sized.
3883For runtime-sized arrays, the value returned by the <strong>length</strong>() method will be
3884undefined if the array is contained in an array of shader storage blocks
3885that is indexed with a non-constant expression less than zero or greater
3886than or equal to the number of blocks in the array.</p>
3887</div>
3888<div class="paragraph">
3889<p>The <strong>length</strong>() method cannot be called on an array that is not runtime sized
3890and also has not yet been explicitly sized;
3891this results in a compile-time error.</p>
3892</div>
3893<div class="paragraph">
3894<p>When the <strong>length</strong>() method returns a compile-time constant, the expression the
3895<strong>length</strong>() method is applied to cannot contain any side effects, such as writes
3896to l-values within the expression, or function calls that themselves have side
3897effects: only the compile-time constant length itself need be computed.
3898Behavior and results, including any compile-time error reporting,
3899are undefined if the expression contains other effects.</p>
3900</div>
3901<div class="listingblock">
3902<div class="content">
3903<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span> a, b;
3904<span class="directive">const</span> <span class="predefined-type">int</span> s = <span class="predefined-type">float</span>[<span class="integer">2</span>](a=<span class="float">3</span><span class="float">.0</span>, ++b).length(); <span class="comment">// illegal side effects</span></code></pre>
3905</div>
3906</div>
3907<div class="paragraph">
3908<p>The <strong>length</strong>() method works equally well for arrays of arrays:</p>
3909</div>
3910<div class="listingblock">
3911<div class="content">
3912<pre class="CodeRay highlight"><code data-lang="c++">vec4 a[<span class="integer">3</span>][<span class="integer">2</span>];
3913a.length()    <span class="comment">// this is 3</span>
3914a[x].length() <span class="comment">// this is 2</span></code></pre>
3915</div>
3916</div>
3917<div class="paragraph">
3918<p>When the <strong>length</strong>() method returns a compile-time constant, the expression
3919in brackets (<em>x</em> above) will be parsed and subjected to the rules required for
3920array indices, but the array will not be dereferenced.
3921Thus, behavior is well defined even if the run-time value of the expression
3922is out of bounds, as long as the expression contains no side effects.</p>
3923</div>
3924<div class="paragraph">
3925<p>When the <strong>length</strong>() method returns a run-time value
3926(not a compile-time constant), the array will be
3927dereferenced.
3928E.g., if <em>x</em> is not a compile-time constant and is out of range, an undefined
3929value results.
3930More generally, all involved expressions are fully evaluated and executed.</p>
3931</div>
3932<div class="listingblock">
3933<div class="content">
3934<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">// for a compile time-sized array b containing a member array a:</span>
3935b[x+<span class="integer">3</span>].a.length(); <span class="comment">// b is never dereferenced, x+3 is evaluated and checked</span>
3936b[++x].a.length(); <span class="comment">// not allowed; results are undefined</span>
3937
3938<span class="comment">// for an array s of a shader storage object (run-time sized) containing a member array a:</span>
3939s[++x].a.length(); <span class="comment">// s is dereferenced; ++x needs to be a valid index</span></code></pre>
3940</div>
3941</div>
3942<div class="paragraph">
3943<p>For implicitly-sized or run-time-sized arrays, only the outer-most dimension
3944can be lacking a size.
3945A type that includes an unknown array size cannot be formed into an array
3946until it gets an explicit size, except for shader storage blocks where the
3947only unsized array member is the last member of the block.</p>
3948</div>
3949<div class="paragraph">
3950<p>In a shader storage block, the last member may be declared without an
3951explicit size.
3952In this case, the effective array size is inferred at run-time from the size
3953of the data store backing the interface block.
3954Such run-time-sized arrays may be indexed with general integer expressions.
3955However, it is a compile-time error to pass them as an argument to a
3956function or index them with a negative constant expression.</p>
3957</div>
3958</div>
3959<div class="sect3">
3960<h4 id="implicit-conversions">4.1.10. Implicit Conversions</h4>
3961<div class="paragraph">
3962<p>In some situations, an expression and its type will be implicitly converted
3963to a different type.
3964The following table shows all allowed implicit conversions:</p>
3965</div>
3966<table class="tableblock frame-all grid-all stretch">
3967<colgroup>
3968<col style="width: 50%;">
3969<col style="width: 50%;">
3970</colgroup>
3971<thead>
3972<tr>
3973<th class="tableblock halign-left valign-top">Type of expression</th>
3974<th class="tableblock halign-left valign-top">Can be implicitly converted to</th>
3975</tr>
3976</thead>
3977<tbody>
3978<tr>
3979<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>int</strong></p></td>
3980<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>uint</strong></p></td>
3981</tr>
3982<tr>
3983<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>int</strong><br>
3984  <strong>uint</strong></p></td>
3985<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>float</strong></p></td>
3986</tr>
3987<tr>
3988<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>int</strong><br>
3989  <strong>uint</strong><br>
3990  <strong>float</strong></p></td>
3991<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>double</strong></p></td>
3992</tr>
3993<tr>
3994<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>ivec2</strong></p></td>
3995<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>uvec2</strong></p></td>
3996</tr>
3997<tr>
3998<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>ivec3</strong></p></td>
3999<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>uvec3</strong></p></td>
4000</tr>
4001<tr>
4002<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>ivec4</strong></p></td>
4003<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>uvec4</strong></p></td>
4004</tr>
4005<tr>
4006<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>ivec2</strong><br>
4007  <strong>uvec2</strong></p></td>
4008<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>vec2</strong></p></td>
4009</tr>
4010<tr>
4011<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>ivec3</strong><br>
4012  <strong>uvec3</strong></p></td>
4013<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>vec3</strong></p></td>
4014</tr>
4015<tr>
4016<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>ivec4</strong><br>
4017  <strong>uvec4</strong></p></td>
4018<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>vec4</strong></p></td>
4019</tr>
4020<tr>
4021<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>ivec2</strong><br>
4022  <strong>uvec2</strong><br>
4023  <strong>vec2</strong></p></td>
4024<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dvec2</strong></p></td>
4025</tr>
4026<tr>
4027<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>ivec3</strong><br>
4028  <strong>uvec3</strong><br>
4029  <strong>vec3</strong></p></td>
4030<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dvec3</strong></p></td>
4031</tr>
4032<tr>
4033<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>ivec4</strong><br>
4034  <strong>uvec4</strong><br>
4035  <strong>vec4</strong></p></td>
4036<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dvec4</strong></p></td>
4037</tr>
4038<tr>
4039<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat2</strong></p></td>
4040<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat2</strong></p></td>
4041</tr>
4042<tr>
4043<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat3</strong></p></td>
4044<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat3</strong></p></td>
4045</tr>
4046<tr>
4047<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat4</strong></p></td>
4048<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat4</strong></p></td>
4049</tr>
4050<tr>
4051<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat2x3</strong></p></td>
4052<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat2x3</strong></p></td>
4053</tr>
4054<tr>
4055<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat2x4</strong></p></td>
4056<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat2x4</strong></p></td>
4057</tr>
4058<tr>
4059<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat3x2</strong></p></td>
4060<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat3x2</strong></p></td>
4061</tr>
4062<tr>
4063<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat3x4</strong></p></td>
4064<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat3x4</strong></p></td>
4065</tr>
4066<tr>
4067<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat4x2</strong></p></td>
4068<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat4x2</strong></p></td>
4069</tr>
4070<tr>
4071<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mat4x3</strong></p></td>
4072<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dmat4x3</strong></p></td>
4073</tr>
4074</tbody>
4075</table>
4076<div class="paragraph">
4077<p>There are no implicit array or structure conversions.
4078For example, an array of <strong>int</strong> cannot be implicitly converted to an array of
4079<strong>float</strong>.</p>
4080</div>
4081<div class="paragraph">
4082<p>When an implicit conversion is done, it is the same conversion that would be
4083done under explicit conversion, using a constructor.
4084The explicit conversions via constructors are described in
4085<a href="#conversion-and-scalar-constructors">Conversion and Scalar Constructors</a>.</p>
4086</div>
4087<div class="paragraph">
4088<p>When performing implicit conversion for binary operators, there may be
4089multiple data types to which the two operands can be converted.
4090For example, when adding an <strong>int</strong> value to a <strong>uint</strong> value, both values can
4091be implicitly converted to <strong>uint</strong>, <strong>float</strong>, and <strong>double</strong>.
4092In such cases, a floating-point type is chosen if either operand has a
4093floating-point type.
4094Otherwise, an unsigned integer type is chosen if either operand has an
4095unsigned integer type.
4096Otherwise, a signed integer type is chosen.
4097If operands can be implicitly converted to multiple data types deriving from
4098the same base data type, the type with the smallest component size is used.</p>
4099</div>
4100<div class="paragraph">
4101<p>The conversions in the table above are done only as indicated by other
4102sections of this specification.</p>
4103</div>
4104</div>
4105<div class="sect3">
4106<h4 id="initializers">4.1.11. Initializers</h4>
4107<div class="paragraph">
4108<p>At declaration, an initial value for a variable may be provided, specified
4109as an equals (=) followed by an initializer.
4110The initializer is either an <em>assignment-expression</em> or a list of
4111initializers enclosed in curly braces.
4112The grammar for the initializer is:</p>
4113</div>
4114<div class="openblock bnf">
4115<div class="content">
4116<div class="dlist">
4117<dl>
4118<dt class="hdlist1"><em>initializer</em> : </dt>
4119<dd>
4120<p><em>assignment-expression</em><br>
4121<strong>{</strong> <em>initializer-list</em> <strong>}</strong><br>
4122<strong>{</strong> <em>initializer-list</em> <strong>,</strong> <strong>}</strong></p>
4123</dd>
4124<dt class="hdlist1"><em>initializer-list</em> : </dt>
4125<dd>
4126<p><em>initializer</em><br>
4127<em>initializer-list</em> , <em>initializer</em></p>
4128</dd>
4129</dl>
4130</div>
4131</div>
4132</div>
4133<div class="paragraph">
4134<p>The <em>assignment-expression</em> is a normal expression except that a comma (<strong>,</strong>)
4135outside parentheses is interpreted as the end of the initializer, not as the
4136sequence operator.
4137As explained in more detail below, this allows creation of nested
4138initializers: The variable type and its initializer must exactly match in
4139terms of nesting, number of components/elements/members present at each
4140level, and types of components/elements/members.
4141An <em>assignment-expression</em> at global scope can include calls to user-defined
4142functions.</p>
4143</div>
4144<div class="paragraph">
4145<p>An <em>assignment-expression</em> in an initializer must be either the same type as
4146the object it initializes or be a type that can be converted to the object&#8217;s
4147type according to &#8220;<a href="#implicit-conversions">Implicit Conversions</a>&#8221;.
4148Since these include constructors, a composite variable can be initialized by
4149either a constructor or an initializer list; and an element in an
4150initializer list can be a constructor.</p>
4151</div>
4152<div class="paragraph">
4153<p>If an initializer is a list of initializers enclosed in curly braces, the
4154variable being declared must be a vector, a matrix, an array, or a
4155structure.</p>
4156</div>
4157<div class="listingblock">
4158<div class="content">
4159<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">int</span> i = { <span class="integer">1</span> }; <span class="comment">// illegal, i is not a composite</span></code></pre>
4160</div>
4161</div>
4162<div class="paragraph">
4163<p>A list of initializers enclosed in a matching set of curly braces is applied
4164to one composite.
4165This may be the variable being declared or a composite contained in the
4166variable being declared.
4167Individual initializers from the initializer list are applied to the
4168elements/members of the composite, in order.</p>
4169</div>
4170<div class="paragraph">
4171<p>If the composite has a vector type, initializers from the list are applied
4172to the components of the vector, in order, starting with component 0.
4173The number of initializers must match the number of components.</p>
4174</div>
4175<div class="paragraph">
4176<p>If the composite has a matrix type, initializers from the list must be
4177vector initializers and are applied to the columns of the matrix, in order,
4178starting with column 0.
4179The number of initializers must match the number of columns.</p>
4180</div>
4181<div class="paragraph">
4182<p>If the composite has a structure type, initializers from the list are
4183applied to the members of the structure, in the order declared in the
4184structure, starting with the first member.
4185The number of initializers must match the number of members.</p>
4186</div>
4187<div class="paragraph">
4188<p>Applying these rules, the following matrix declarations are equivalent:</p>
4189</div>
4190<div class="listingblock">
4191<div class="content">
4192<pre class="CodeRay highlight"><code data-lang="c++">mat2x2 a = mat2(  vec2( <span class="float">1</span><span class="float">.0</span>, <span class="float">0</span><span class="float">.0</span> ), vec2( <span class="float">0</span><span class="float">.0</span>, <span class="float">1</span><span class="float">.0</span> ) );
4193mat2x2 b =      { vec2( <span class="float">1</span><span class="float">.0</span>, <span class="float">0</span><span class="float">.0</span> ), vec2( <span class="float">0</span><span class="float">.0</span>, <span class="float">1</span><span class="float">.0</span> ) };
4194mat2x2 c =      {     { <span class="float">1</span><span class="float">.0</span>, <span class="float">0</span><span class="float">.0</span> },     { <span class="float">0</span><span class="float">.0</span>, <span class="float">1</span><span class="float">.0</span> } };</code></pre>
4195</div>
4196</div>
4197<div class="paragraph">
4198<p>All of the following declarations result in a compile-time error.</p>
4199</div>
4200<div class="listingblock">
4201<div class="content">
4202<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span> a[<span class="integer">2</span>] = { <span class="float">3</span><span class="float">.4</span>, <span class="float">4</span><span class="float">.2</span>, <span class="float">5</span><span class="float">.0</span> };         <span class="comment">// illegal</span>
4203vec2 b = { <span class="float">1</span><span class="float">.0</span>, <span class="float">2</span><span class="float">.0</span>, <span class="float">3</span><span class="float">.0</span> };             <span class="comment">// illegal</span>
4204mat3x3 c = { vec3(<span class="float">0</span><span class="float">.0</span>), vec3(<span class="float">1</span><span class="float">.0</span>), vec3(<span class="float">2</span><span class="float">.0</span>), vec3(<span class="float">3</span><span class="float">.0</span>) }; <span class="comment">// illegal</span>
4205mat2x2 d = { <span class="float">1</span><span class="float">.0</span>, <span class="float">0</span><span class="float">.0</span>, <span class="float">0</span><span class="float">.0</span>, <span class="float">1</span><span class="float">.0</span> };      <span class="comment">// illegal, can't flatten nesting</span>
4206<span class="keyword">struct</span> {
4207    <span class="predefined-type">float</span> a;
4208    <span class="predefined-type">int</span> b;
4209} e = { <span class="float">1</span><span class="float">.2</span>, <span class="integer">2</span>, <span class="integer">3</span> };                    <span class="comment">// illegal</span></code></pre>
4210</div>
4211</div>
4212<div class="paragraph">
4213<p>In all cases, the inner-most initializer (i.e., not a list of initializers
4214enclosed in curly braces) applied to an object must have the same type as
4215the object being initialized or be a type that can be converted to the
4216object&#8217;s type according to &#8220;<a href="#implicit-conversions">Implicit
4217Conversions</a>&#8221;.
4218In the latter case, an implicit conversion will be done on the initializer
4219before the assignment is done.</p>
4220</div>
4221<div class="listingblock">
4222<div class="content">
4223<pre class="CodeRay highlight"><code data-lang="c++"><span class="keyword">struct</span> {
4224    <span class="predefined-type">float</span> a;
4225    <span class="predefined-type">int</span> b;
4226} e = { <span class="float">1</span><span class="float">.2</span>, <span class="integer">2</span> }; <span class="comment">// legal, all types match</span>
4227<span class="keyword">struct</span> {
4228    <span class="predefined-type">float</span> a;
4229    <span class="predefined-type">int</span> b;
4230} e = { <span class="integer">1</span>, <span class="integer">3</span> };   <span class="comment">// legal, first initializer is converted</span></code></pre>
4231</div>
4232</div>
4233<div class="paragraph">
4234<p>All of the following declarations result in a compile-time error.</p>
4235</div>
4236<div class="listingblock">
4237<div class="content">
4238<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">int</span> a = <span class="predefined-constant">true</span>;                         <span class="comment">// illegal</span>
4239vec4 b[<span class="integer">2</span>] = { vec4(<span class="float">0</span><span class="float">.0</span>), <span class="float">1</span><span class="float">.0</span> };       <span class="comment">// illegal</span>
4240mat4x2 c = { vec3(<span class="float">0</span><span class="float">.0</span>), vec3(<span class="float">1</span><span class="float">.0</span>) };  <span class="comment">// illegal</span>
4241
4242<span class="keyword">struct</span> S1 {
4243    vec4 a;
4244    vec4 b;
4245};
4246
4247<span class="keyword">struct</span> {
4248    <span class="predefined-type">float</span> s;
4249    <span class="predefined-type">float</span> t;
4250} d[] = { S1(vec4(<span class="float">0</span><span class="float">.0</span>), vec4(<span class="float">1</span><span class="float">.1</span>)) }; <span class="comment">// illegal</span></code></pre>
4251</div>
4252</div>
4253<div class="paragraph">
4254<p>If an initializer (of either form) is provided for an unsized array, the
4255size of the array is determined by the number of top-level (non-nested)
4256initializers within the initializer.
4257All of the following declarations create arrays explicitly sized with five
4258elements:</p>
4259</div>
4260<div class="listingblock">
4261<div class="content">
4262<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span> a[] = <span class="predefined-type">float</span>[](<span class="float">3</span><span class="float">.4</span>, <span class="float">4</span><span class="float">.2</span>, <span class="float">5</span><span class="float">.0</span>, <span class="float">5</span><span class="float">.2</span>, <span class="float">1</span><span class="float">.1</span>);
4263<span class="predefined-type">float</span> b[] = { <span class="float">3</span><span class="float">.4</span>, <span class="float">4</span><span class="float">.2</span>, <span class="float">5</span><span class="float">.0</span>, <span class="float">5</span><span class="float">.2</span>, <span class="float">1</span><span class="float">.1</span> };
4264<span class="predefined-type">float</span> c[] = a;                          <span class="comment">// c is explicitly size 5</span>
4265<span class="predefined-type">float</span> d[<span class="integer">5</span>] = b;                         <span class="comment">// means the same thing</span></code></pre>
4266</div>
4267</div>
4268<div class="paragraph">
4269<p>It is a compile-time error to have too few or too many initializers in an
4270initializer list for the composite being initialized.
4271That is, all elements of an array, all members of a structure, all columns
4272of a matrix, and all components of a vector must have exactly one
4273initializer expression present, with no unconsumed initializers.</p>
4274</div>
4275</div>
4276</div>
4277<div class="sect2">
4278<h3 id="scoping">4.2. Scoping</h3>
4279<div class="paragraph">
4280<p>The scope of a variable is determined by where it is declared.
4281If it is declared outside all function definitions, it has global scope,
4282which starts from where it is declared and persists to the end of the shader
4283it is declared in.
4284If it is declared in a <strong>while</strong> test or a <strong>for</strong> statement, then it is scoped
4285to the end of the following sub-statement.
4286If it is declared in an <strong>if</strong> or <strong>else</strong> statement, it is scoped to the end of
4287that statement.
4288(See &#8220;<a href="#selection">Selection</a>&#8221; and &#8220;<a href="#iteration">Iteration</a>&#8221; for the
4289location of statements and sub-statements.) Otherwise, if it is declared as
4290a statement within a compound statement, it is scoped to the end of that
4291compound statement.
4292If it is declared as a parameter in a function definition, it is scoped
4293until the end of that function definition.
4294A function&#8217;s parameter declarations and body together form a single scope
4295nested in the global scope.
4296The <strong>if</strong> statement&#8217;s expression does not allow new variables to be declared,
4297hence does not form a new scope.</p>
4298</div>
4299<div class="paragraph">
4300<p>Within a declaration, the scope of a name starts immediately after the
4301initializer if present or immediately after the name being declared if not.
4302Several examples:</p>
4303</div>
4304<div class="listingblock">
4305<div class="content">
4306<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">int</span> x = <span class="integer">1</span>;
4307{
4308    <span class="predefined-type">int</span> x = <span class="integer">2</span>, y = x; <span class="comment">// y is initialized to 2</span>
4309}
4310
4311<span class="keyword">struct</span> S
4312{
4313    <span class="predefined-type">int</span> x;
4314};
4315
4316{
4317    S S = S(<span class="integer">0</span>); <span class="comment">// 'S' is only visible as a struct and constructor</span>
4318    S;          <span class="comment">// 'S' is now visible as a variable</span>
4319}
4320
4321<span class="predefined-type">int</span> x = x; <span class="comment">// Error if x has not been previously defined.</span>
4322           <span class="comment">// If the previous definition of x was in this</span>
4323           <span class="comment">// same scope, this causes a redeclaration error.</span>
4324
4325<span class="predefined-type">int</span> f( <span class="comment">/* nested scope begins here */</span> <span class="predefined-type">int</span> k)
4326{
4327    <span class="predefined-type">int</span> k = k + <span class="integer">3</span>; <span class="comment">// redeclaration error of the name k</span>
4328    ...
4329}
4330
4331<span class="predefined-type">int</span> f(<span class="predefined-type">int</span> k)
4332{
4333    {
4334        <span class="predefined-type">int</span> k = k + <span class="integer">3</span>; <span class="comment">// 2nd k is parameter, initializing nested first k</span>
4335        <span class="predefined-type">int</span> m = k;     <span class="comment">// use of new k, which is hiding the parameter</span>
4336    }
4337}</code></pre>
4338</div>
4339</div>
4340<div class="paragraph">
4341<p>For both <strong>for</strong> and <strong>while</strong> loops, the sub-statement itself does not
4342introduce a new scope for variable names, so the following has a
4343redeclaration compile-time error:</p>
4344</div>
4345<div class="listingblock">
4346<div class="content">
4347<pre class="CodeRay highlight"><code data-lang="c++"><span class="keyword">for</span> ( <span class="comment">/* nested scope begins here */</span> <span class="predefined-type">int</span> i = <span class="integer">0</span>; i &lt; <span class="integer">10</span>; i++) {
4348    <span class="predefined-type">int</span> i; <span class="comment">// redeclaration error</span>
4349}</code></pre>
4350</div>
4351</div>
4352<div class="paragraph">
4353<p>The body of a <strong>do</strong>-<strong>while</strong> loop introduces a new scope lasting only between
4354the <strong>do</strong> and <strong>while</strong> (not including the while test expression), whether or
4355not the body is simple or compound:</p>
4356</div>
4357<div class="listingblock">
4358<div class="content">
4359<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">int</span> i = <span class="integer">17</span>;
4360<span class="keyword">do</span>
4361    <span class="predefined-type">int</span> i = <span class="integer">4</span>;  <span class="comment">// okay, in nested scope_</span>
4362<span class="keyword">while</span> (i == <span class="integer">0</span>); <span class="comment">// i is 17, scoped outside the do-while body</span></code></pre>
4363</div>
4364</div>
4365<div class="paragraph">
4366<p>The statement following a <strong>switch</strong> (&#8230;&#8203;) forms a nested scope.</p>
4367</div>
4368<div class="paragraph">
4369<p>All variable names, structure type names, and function names in a given
4370scope share the same name space.
4371Function names can be redeclared in the same scope, with the same or
4372different parameters, without error.
4373An implicitly-sized array can be redeclared in the same scope as an array of
4374the same base type.
4375Otherwise, within one compilation unit, a declared name cannot be redeclared
4376in the same scope; doing so results in a redeclaration compile-time error.
4377If a nested scope redeclares a name used in an outer scope, it hides all
4378existing uses of that name.
4379There is no way to access the hidden name or make it unhidden, without
4380exiting the scope that hid it.</p>
4381</div>
4382<div class="paragraph">
4383<p>The built-in functions are scoped in a scope outside the global scope that
4384users declare global variables in.
4385That is, a shader&#8217;s global scope, available for user-defined functions and
4386global variables, is nested inside the scope containing the built-in
4387functions.
4388When a function name is redeclared in a nested scope, it hides all functions
4389declared with that name in the outer scope.
4390Function declarations (prototypes) cannot occur inside of functions; they
4391must be at global scope, or for the built-in functions, outside the global
4392scope, otherwise a compile-time error results.</p>
4393</div>
4394<div class="paragraph">
4395<p>Shared globals are global variables declared with the same name in
4396independently compiled units (shaders) within the same language (i.e., same
4397stage, e.g. vertex) that are linked together when making a single program.
4398(Globals forming the interface between two different shader languages are
4399discussed in other sections.) Shared globals share the same name space, and
4400must be declared with the same type.
4401They will share the same storage.</p>
4402</div>
4403<div class="paragraph">
4404<p>Shared global arrays must have the same base type and the same explicit
4405size.
4406An array implicitly sized in one shader can be explicitly sized by another
4407shader in the same stage.
4408If no shader in a stage has an explicit size for the array, the largest
4409implicit size (one more than the largest index used) in that stage is used.
4410There is no cross-stage array sizing.
4411If there is no static access to an implicitly sized array within the stage
4412declaring it, then the array is given a size of 1, which is relevant when
4413the array is declared within an interface block that is shared with other
4414stages or the application (other unused arrays might be eliminated by the
4415optimizer).</p>
4416</div>
4417<div class="paragraph">
4418<p>Shared global scalars must have exactly the same type name and type
4419definition.
4420Structures must have the same name, sequence of type names, and type
4421definitions, and member names to be considered the same type.
4422This rule applies recursively for nested or embedded types.
4423If a shared global has multiple initializers, the initializers must all be
4424constant expressions, and they must all have the same value.
4425Otherwise, a link-time error will result.
4426(A shared global having only one initializer does not require that
4427initializer to be a constant expression.)</p>
4428</div>
4429</div>
4430<div class="sect2">
4431<h3 id="storage-qualifiers">4.3. Storage Qualifiers</h3>
4432<div class="paragraph">
4433<p>Variable declarations may have at most one storage qualifier specified in
4434front of the type.
4435These are summarized as</p>
4436</div>
4437<table class="tableblock frame-all grid-all stretch">
4438<colgroup>
4439<col style="width: 50%;">
4440<col style="width: 50%;">
4441</colgroup>
4442<thead>
4443<tr>
4444<th class="tableblock halign-left valign-top">Storage Qualifier</th>
4445<th class="tableblock halign-left valign-top">Meaning</th>
4446</tr>
4447</thead>
4448<tbody>
4449<tr>
4450<td class="tableblock halign-left valign-top"><p class="tableblock">&lt;none: default&gt;</p></td>
4451<td class="tableblock halign-left valign-top"><p class="tableblock">local read/write memory, or an input parameter to a
4452                      function</p></td>
4453</tr>
4454<tr>
4455<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>const</strong></p></td>
4456<td class="tableblock halign-left valign-top"><p class="tableblock">a variable whose value cannot be changed</p></td>
4457</tr>
4458<tr>
4459<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>in</strong></p></td>
4460<td class="tableblock halign-left valign-top"><p class="tableblock">linkage into a shader from a previous stage, variable
4461                      is copied in</p></td>
4462</tr>
4463<tr>
4464<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>out</strong></p></td>
4465<td class="tableblock halign-left valign-top"><p class="tableblock">linkage out of a shader to a subsequent stage,
4466                      variable is copied out</p></td>
4467</tr>
4468<tr>
4469<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>attribute</strong></p></td>
4470<td class="tableblock halign-left valign-top"><p class="tableblock">compatibility profile only and vertex language only;
4471                      same as <strong>in</strong> when in a vertex shader</p></td>
4472</tr>
4473<tr>
4474<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>uniform</strong></p></td>
4475<td class="tableblock halign-left valign-top"><p class="tableblock">value does not change across the primitive being
4476                      processed, uniforms form the linkage between a shader,
4477                      API, and the application</p></td>
4478</tr>
4479<tr>
4480<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>varying</strong></p></td>
4481<td class="tableblock halign-left valign-top"><p class="tableblock">compatibility profile only and vertex and fragment
4482                      languages only; same as <strong>out</strong> when in a vertex shader
4483                      and same as <strong>in</strong> when in a fragment shader</p></td>
4484</tr>
4485<tr>
4486<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>buffer</strong></p></td>
4487<td class="tableblock halign-left valign-top"><p class="tableblock">value is stored in a buffer object, and can be read or
4488                      written both by shader invocations and the API</p></td>
4489</tr>
4490<tr>
4491<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>shared</strong></p></td>
4492<td class="tableblock halign-left valign-top"><p class="tableblock">compute shader only; variable storage is shared across
4493                      all work items in a workgroup</p></td>
4494</tr>
4495</tbody>
4496</table>
4497<div class="paragraph">
4498<p>Some input and output qualified variables can be qualified with at most one
4499additional auxiliary storage qualifier:</p>
4500</div>
4501<table class="tableblock frame-all grid-all stretch">
4502<colgroup>
4503<col style="width: 50%;">
4504<col style="width: 50%;">
4505</colgroup>
4506<thead>
4507<tr>
4508<th class="tableblock halign-left valign-top">Auxiliary Storage Qualifier</th>
4509<th class="tableblock halign-left valign-top">Meaning</th>
4510</tr>
4511</thead>
4512<tbody>
4513<tr>
4514<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>centroid</strong></p></td>
4515<td class="tableblock halign-left valign-top"><p class="tableblock">centroid-based interpolation</p></td>
4516</tr>
4517<tr>
4518<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sample</strong></p></td>
4519<td class="tableblock halign-left valign-top"><p class="tableblock">per-sample interpolation</p></td>
4520</tr>
4521<tr>
4522<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>patch</strong></p></td>
4523<td class="tableblock halign-left valign-top"><p class="tableblock">per-tessellation-patch attributes</p></td>
4524</tr>
4525</tbody>
4526</table>
4527<div class="paragraph">
4528<p>Not all combinations of qualification are allowed.
4529Auxiliary storage qualifiers can only be used with the <strong>in</strong> or <strong>out</strong> storage
4530qualifiers.
4531Additional qualifier rules are defined in upcoming sections.</p>
4532</div>
4533<div class="paragraph">
4534<p>Local variables can only use the <strong>const</strong> storage qualifier (or use no
4535storage qualifier).</p>
4536</div>
4537<div class="paragraph">
4538<p>Note that function parameters can use <strong>const</strong>, <strong>in</strong>, and <strong>out</strong> qualifiers,
4539but as <em>parameter qualifiers</em>.
4540Parameter qualifiers are discussed in
4541&#8220;<a href="#function-calling-conventions">Function Calling Conventions</a>&#8221;.</p>
4542</div>
4543<div class="paragraph">
4544<p>Function return types and structure members do not use storage qualifiers.</p>
4545</div>
4546<div class="paragraph">
4547<p>Initializers in global declarations may only be used in declarations of
4548global variables with no storage qualifier, with a <strong>const</strong> qualifier, or
4549with a <strong>uniform</strong> qualifier.</p>
4550</div>
4551<div class="paragraph">
4552<p>Global variables without storage qualifiers that are not initialized in
4553their declaration or by the application will not be initialized,
4554but rather will enter <em>main()</em> with undefined values.</p>
4555</div>
4556<div class="paragraph">
4557<p>When comparing an output from one shader stage to an input of a subsequent
4558shader stage, the input and output don&#8217;t match if their auxiliary qualifiers
4559(or lack thereof) are not the same.</p>
4560</div>
4561<div class="sect3">
4562<h4 id="default-storage-qualifier">4.3.1. Default Storage Qualifier</h4>
4563<div class="paragraph">
4564<p>If no qualifier is present on a global variable, then the variable has no
4565linkage to the application or shaders running on other pipeline stages.
4566For either global or local unqualified variables, the declaration will
4567appear to allocate memory associated with the processor it targets.
4568This variable will provide read/write access to this allocated memory.</p>
4569</div>
4570</div>
4571<div class="sect3">
4572<h4 id="constant-qualifier">4.3.2. Constant Qualifier</h4>
4573<div class="paragraph">
4574<p>Named compile-time constants
4575or read-only variables
4576can be declared using
4577the <strong>const</strong> qualifier.
4578The <strong>const</strong> qualifier can be used with any of the non-void transparent basic
4579data types, as well as with structures and arrays of these.
4580It is a compile-time error to write to a <strong>const</strong> variable outside of its
4581declaration, so they must be initialized when declared.
4582For example,</p>
4583</div>
4584<div class="listingblock">
4585<div class="content">
4586<pre class="CodeRay highlight"><code data-lang="c++"><span class="directive">const</span> vec3 zAxis = vec3 (<span class="float">0</span><span class="float">.0</span>, <span class="float">0</span><span class="float">.0</span>, <span class="float">1</span><span class="float">.0</span>);
4587<span class="directive">const</span> <span class="predefined-type">float</span> ceiling = a + b; <span class="comment">// a and b not necessarily constants</span></code></pre>
4588</div>
4589</div>
4590<div class="paragraph">
4591<p>Structure members may not be qualified with <strong>const</strong>.
4592Structure variables can be declared as <strong>const</strong>, and initialized with a
4593structure
4594constructor or initializer.</p>
4595</div>
4596<div class="paragraph">
4597<p>Initializers for <strong>const</strong> declarations
4598at global scope
4599must be constant expressions, as defined in
4600&#8220;<a href="#constant-expressions">Constant Expressions</a>&#8221;.</p>
4601</div>
4602</div>
4603<div class="sect3">
4604<h4 id="constant-expressions">4.3.3. Constant Expressions</h4>
4605<div class="paragraph">
4606<p>SPIR-V specialization constants are expressed in GLSL as <strong>const</strong> with the
4607layout qualifier <strong>constant_id</strong>, as described in
4608&#8220;<a href="#specialization-constant-qualifier">Specialization-Constant
4609Qualifier.</a>&#8221;</p>
4610</div>
4611<div class="paragraph">
4612<p>A <em>constant expression</em> is one of</p>
4613</div>
4614<div class="ulist">
4615<ul>
4616<li>
4617<p>A literal value (e.g. <strong>5</strong> or <strong>true</strong>).</p>
4618</li>
4619<li>
4620<p>A variable declared with the <strong>const</strong> qualifier and an initializer, where
4621the initializer is a constant expression.
4622This includes both <strong>const</strong> declared with a specialization-constant
4623layout qualifier, e.g. <strong>layout</strong>(<strong>constant_id</strong> = &#8230;&#8203;), and those declared
4624without a specialization-constant layout qualifier.</p>
4625</li>
4626<li>
4627<p>Built-in variables qualified as <strong>const</strong>.</p>
4628</li>
4629<li>
4630<p>An expression formed by an operator on operands that are all constant
4631expressions, including getting an element of a constant array, or a
4632member of a constant structure, or components of a constant vector.
4633However, the lowest precedence operators of the sequence operator (<strong>,</strong>)
4634and the assignment operators (<strong>=</strong>, <strong>+=</strong>, <strong>&#8230;&#8203;</strong>) are not included in the
4635operators that can create a constant expression.
4636Also, an array access with a specialization constant as an index does
4637not result in a constant expression.</p>
4638</li>
4639<li>
4640<p>Valid use of the <strong>length</strong>() method on an explicitly sized object,
4641whether or not the object itself is constant (implicitly sized or
4642run-time sized arrays do not return a constant expression).</p>
4643</li>
4644<li>
4645<p>A constructor whose arguments are all constant expressions.</p>
4646</li>
4647<li>
4648<p>For non-specialization constants only: The value returned by certain
4649built-in function calls whose arguments are all constant expressions,
4650including at least the list below.
4651Any other built-in function that does not access memory (not the texture
4652lookup functions, image access, atomic counter, etc.), that has a
4653non-<strong>void</strong> return type, that has no <strong>out</strong> parameter, and is not a noise
4654function might also be considered a constant.
4655When a function is called with an argument that is a specialization
4656constant, the result is not a constant expression.</p>
4657<div class="ulist">
4658<ul>
4659<li>
4660<p>Angle and Trigonometric Functions</p>
4661<div class="ulist">
4662<ul>
4663<li>
4664<p><strong>radians</strong></p>
4665</li>
4666<li>
4667<p><strong>degrees</strong></p>
4668</li>
4669<li>
4670<p><strong>sin</strong></p>
4671</li>
4672<li>
4673<p><strong>cos</strong></p>
4674</li>
4675<li>
4676<p><strong>asin</strong></p>
4677</li>
4678<li>
4679<p><strong>acos</strong></p>
4680</li>
4681</ul>
4682</div>
4683</li>
4684<li>
4685<p>Exponential Functions</p>
4686<div class="ulist">
4687<ul>
4688<li>
4689<p><strong>pow</strong></p>
4690</li>
4691<li>
4692<p><strong>exp</strong></p>
4693</li>
4694<li>
4695<p><strong>log</strong></p>
4696</li>
4697<li>
4698<p><strong>exp2</strong></p>
4699</li>
4700<li>
4701<p><strong>log2</strong></p>
4702</li>
4703<li>
4704<p><strong>sqrt</strong></p>
4705</li>
4706<li>
4707<p><strong>inversesqrt</strong></p>
4708</li>
4709</ul>
4710</div>
4711</li>
4712<li>
4713<p>Common Functions</p>
4714<div class="ulist">
4715<ul>
4716<li>
4717<p><strong>abs</strong></p>
4718</li>
4719<li>
4720<p><strong>sign</strong></p>
4721</li>
4722<li>
4723<p><strong>floor</strong></p>
4724</li>
4725<li>
4726<p><strong>trunc</strong></p>
4727</li>
4728<li>
4729<p><strong>round</strong></p>
4730</li>
4731<li>
4732<p><strong>ceil</strong></p>
4733</li>
4734<li>
4735<p><strong>mod</strong></p>
4736</li>
4737<li>
4738<p><strong>min</strong></p>
4739</li>
4740<li>
4741<p><strong>max</strong></p>
4742</li>
4743<li>
4744<p><strong>clamp</strong></p>
4745</li>
4746</ul>
4747</div>
4748</li>
4749<li>
4750<p>Geometric Functions</p>
4751<div class="ulist">
4752<ul>
4753<li>
4754<p><strong>length</strong></p>
4755</li>
4756<li>
4757<p><strong>dot</strong></p>
4758</li>
4759<li>
4760<p><strong>normalize</strong></p>
4761</li>
4762</ul>
4763</div>
4764</li>
4765</ul>
4766</div>
4767</li>
4768<li>
4769<p>Function calls to user-defined functions (non-built-in functions) cannot
4770be used to form constant expressions.</p>
4771</li>
4772</ul>
4773</div>
4774<div class="paragraph">
4775<p>A <em>constant integral expression</em> is a constant expression that evaluates to
4776a scalar signed or unsigned integer.</p>
4777</div>
4778<div class="paragraph">
4779<p>Constant expressions will be evaluated in an invariant way so as to create
4780the same value in multiple shaders when the same constant expressions appear
4781in those shaders.
4782See &#8220;<a href="#the-invariant-qualifier">The Invariant Qualifier</a>&#8221; for more details
4783on how to create invariant expressions and
4784&#8220;<a href="#precision-qualifiers">Precision Qualifiers</a>&#8221; for detail on how
4785expressions are evaluated.</p>
4786</div>
4787<div class="paragraph">
4788<p>Constant expressions respect the <strong>precise</strong> and <strong>invariant</strong> qualifiers but
4789will be always be evaluated in an invariant way, independent of the use of
4790such qualification, so as to create the same value in multiple shaders when
4791the same constant expressions appear in those shaders.
4792See &#8220;<a href="#the-invariant-qualifier">The Invariant Qualifier</a>&#8221; and
4793&#8220;<a href="#the-precise-qualifier">The Precise Qualifier</a>&#8221; for more details on how
4794to create invariant expressions.</p>
4795</div>
4796<div class="paragraph">
4797<p>Constant-expressions may be evaluated by a
4798host platform, and are therefore not required to compute the same value that
4799the same expression would evaluate to on the shader execution target.
4800However, the host must use the same or greater precision than the target
4801would use.
4802When the precision qualification cannot be determined, the expression is
4803evaluated at <strong>highp</strong>.
4804See &#8220;<a href="#default-precision-qualifiers">Default Precision Qualifiers</a>&#8221;.</p>
4805</div>
4806<div class="paragraph">
4807<p>Specialization-constant expressions are never evaluated by the compiler
4808front end, but instead retain the expression&#8217;s operations needed to evaluate
4809them later on the host.</p>
4810</div>
4811</div>
4812<div class="sect3">
4813<h4 id="input-variables">4.3.4. Input Variables</h4>
4814<div class="paragraph">
4815<p>Shader input variables are declared with the <strong>in</strong> storage qualifier.
4816They form the input interface between previous stages of the API
4817pipeline and the declaring shader.
4818Input variables must be declared at global scope.
4819Values from the previous pipeline stage are copied into input variables at
4820the beginning of shader execution.
4821It is a compile-time error to write to a variable declared as an input.</p>
4822</div>
4823<div class="paragraph">
4824<p>Only the input variables that are
4825statically
4826read need to be written by the
4827previous stage; it is allowed to have superfluous declarations of input
4828variables.
4829This is shown in the following table.</p>
4830</div>
4831<table class="tableblock frame-all grid-all fit-content">
4832<colgroup>
4833<col>
4834<col>
4835<col>
4836<col>
4837<col>
4838</colgroup>
4839<tbody>
4840<tr>
4841<td class="tableblock halign-left valign-top" colspan="2" rowspan="2"><p class="tableblock">Treatment of Mismatched Input Variables</p></td>
4842<td class="tableblock halign-left valign-top" colspan="3"><p class="tableblock">Consuming Shader (input variables)</p></td>
4843</tr>
4844<tr>
4845<td class="tableblock halign-left valign-top"><p class="tableblock">No Declaration</p></td>
4846<td class="tableblock halign-left valign-top"><p class="tableblock">Declared but no Static Use</p></td>
4847<td class="tableblock halign-left valign-top"><p class="tableblock">Declared and Static Use</p></td>
4848</tr>
4849<tr>
4850<td class="tableblock halign-left valign-top" rowspan="3"><p class="tableblock">Generating Shader (output variables)</p></td>
4851<td class="tableblock halign-left valign-top"><p class="tableblock">No Declaration</p></td>
4852<td class="tableblock halign-left valign-top"><p class="tableblock">Allowed</p></td>
4853<td class="tableblock halign-left valign-top"><p class="tableblock">Allowed</p></td>
4854<td class="tableblock halign-left valign-top"><p class="tableblock">Link-Time Error</p></td>
4855</tr>
4856<tr>
4857<td class="tableblock halign-left valign-top"><p class="tableblock">Declared but no Static Use</p></td>
4858<td class="tableblock halign-left valign-top"><p class="tableblock">Allowed</p></td>
4859<td class="tableblock halign-left valign-top"><p class="tableblock">Allowed</p></td>
4860<td class="tableblock halign-left valign-top"><p class="tableblock">Allowed (values are undefined)</p></td>
4861</tr>
4862<tr>
4863<td class="tableblock halign-left valign-top"><p class="tableblock">Declared and Static Use</p></td>
4864<td class="tableblock halign-left valign-top"><p class="tableblock">Allowed</p></td>
4865<td class="tableblock halign-left valign-top"><p class="tableblock">Allowed</p></td>
4866<td class="tableblock halign-left valign-top"><p class="tableblock">Allowed (values are potentially undefined)</p></td>
4867</tr>
4868</tbody>
4869</table>
4870<div class="paragraph">
4871<p>Consumption errors are based on static use only.
4872Compilation may generate a warning, but not an error, for any dynamic use
4873the compiler can deduce that might cause consumption of undefined values.</p>
4874</div>
4875<div class="paragraph">
4876<p>See &#8220;<a href="#built-in-variables">Built-In Variables</a>&#8221; for a list of the built-in
4877input names.</p>
4878</div>
4879<div class="paragraph">
4880<p>Vertex shader input variables (or attributes) receive per-vertex data.
4881It is a compile-time error to use auxiliary storage or interpolation qualifiers
4882on a vertex shader input.
4883The values copied in are established by the API or through the use
4884of the layout identifier <strong>location</strong>.</p>
4885</div>
4886<div class="paragraph">
4887<p>It is a compile-time error to declare a vertex shader input with, or that
4888contains, any of the following types:</p>
4889</div>
4890<div class="ulist">
4891<ul>
4892<li>
4893<p>A <a href="#booleans">boolean type</a></p>
4894</li>
4895<li>
4896<p>An <a href="#opaque-types">opaque type</a></p>
4897</li>
4898<li>
4899<p>A structure</p>
4900</li>
4901</ul>
4902</div>
4903<div class="paragraph">
4904<p>Example declarations in a vertex shader:</p>
4905</div>
4906<div class="listingblock">
4907<div class="content">
4908<pre class="CodeRay highlight"><code data-lang="c++">in vec4 position;
4909in vec3 normal;
4910in vec2 texCoord[<span class="integer">4</span>];</code></pre>
4911</div>
4912</div>
4913<div class="paragraph">
4914<p>It is expected that graphics hardware will have a small number of fixed
4915vector locations for passing vertex inputs.
4916Therefore, the OpenGL Shading Language defines each non-matrix input variable as taking up
4917one such vector location.
4918There is an implementation-dependent limit on the number of locations that
4919can be used, and if this is exceeded it will cause a link-time error.
4920(Declared input variables that are not statically used do not count against
4921this limit.) A scalar input counts the same amount against this limit as a
4922<strong>vec4</strong>, so applications may want to consider packing groups of four
4923unrelated float inputs together into a vector to better utilize the
4924capabilities of the underlying hardware.
4925A matrix input will use up multiple locations.
4926The number of locations used will equal the number of columns in the matrix.</p>
4927</div>
4928<div class="paragraph">
4929<p>Tessellation control, evaluation, and geometry shader input variables get
4930the per-vertex values written out by output variables of the same names in
4931the previous active shader stage.
4932For these inputs, <strong>centroid</strong> and interpolation qualifiers are allowed, but
4933have no effect.
4934Since tessellation control, tessellation evaluation, and geometry shaders
4935operate on a set of vertices, each input variable (or input block, see
4936interface blocks below) needs to be declared as an array.
4937For example,</p>
4938</div>
4939<div class="listingblock">
4940<div class="content">
4941<pre class="CodeRay highlight"><code data-lang="c++">in <span class="predefined-type">float</span> foo[]; <span class="comment">// geometry shader input for vertex &quot;out float foo&quot;</span></code></pre>
4942</div>
4943</div>
4944<div class="paragraph">
4945<p>Each element of such an array corresponds to one vertex of the primitive
4946being processed.
4947Each array can optionally have a size declared.
4948For geometry shaders, the array size will be set by, (or if provided must be
4949consistent with) the input <strong>layout</strong> declaration(s) establishing the type of
4950input primitive, as described later in &#8220;<a href="#input-layout-qualifiers">Input
4951Layout Qualifiers</a>&#8221;.</p>
4952</div>
4953<div class="paragraph">
4954<p>Some inputs and outputs are <em>arrayed</em>, meaning that for an interface between
4955two shader stages either the input or output declaration requires an extra
4956level of array indexing for the declarations to match.
4957For example, with the interface between a vertex shader and a geometry
4958shader, vertex shader output variables and geometry shader input variables
4959of the same name must have matching types, except that the geometry shader
4960will have one more array dimension than the vertex shader, to allow for
4961vertex indexing.
4962If such an arrayed interface variable is not declared with the necessary
4963additional input or output array dimension, a link-time error will result.
4964Geometry shader inputs, tessellation control shader inputs and outputs, and
4965tessellation evaluation inputs all have an additional level of arrayness
4966relative to other shader inputs and outputs.
4967These inputs and outputs are known as <em>per-vertex-arrayed</em> inputs and
4968outputs.
4969Component limits for arrayed interfaces (e.g.
4970<em>gl_MaxTessControlInputComponents</em>) are limits per vertex, not limits for
4971the entire interface.</p>
4972</div>
4973<div class="paragraph">
4974<p>For non-arrayed interfaces (meaning array dimensionally stays the same
4975between stages), it is a link-time error if the input variable is not
4976declared with the same type, including array dimensionality, as the matching
4977output variable.</p>
4978</div>
4979<div class="paragraph">
4980<p>The link-time type-matching rules apply to all declared input and output
4981variables, whether or not they are used.</p>
4982</div>
4983<div class="paragraph">
4984<p>Additionally, tessellation evaluation shaders support per-patch input
4985variables declared with the <strong>patch</strong> and <strong>in</strong> qualifiers.
4986Per-patch input variables are filled with the values of per-patch output
4987variables written by the tessellation control shader.
4988Per-patch inputs may be declared as one-dimensional arrays, but are not
4989indexed by vertex number.
4990Applying the <strong>patch</strong> qualifier to inputs can only be done in tessellation
4991evaluation shaders.
4992As with other input variables, per-patch inputs must be declared using the
4993same type and qualification as per-patch outputs from the previous
4994(tessellation control) shader stage.
4995It is a compile-time error to use <strong>patch</strong> with inputs in any other stage.</p>
4996</div>
4997<div class="paragraph">
4998<p>It is a compile-time error to declare a tessellation control, tessellation
4999evaluation or geometry shader input with, or that contains, any of the
5000following types:</p>
5001</div>
5002<div class="ulist">
5003<ul>
5004<li>
5005<p>A <a href="#booleans">boolean type</a></p>
5006</li>
5007<li>
5008<p>An <a href="#opaque-types">opaque type</a></p>
5009</li>
5010</ul>
5011</div>
5012<div class="paragraph">
5013<p>Fragment shader inputs get per-fragment values, typically interpolated from
5014a previous stage&#8217;s outputs.
5015The auxiliary storage qualifiers <strong>centroid</strong> and <strong>sample</strong> can also be
5016applied, as well as the interpolation qualifiers <strong>flat</strong>, <strong>noperspective</strong>,
5017and <strong>smooth.</strong></p>
5018</div>
5019<div class="paragraph">
5020<p>It is a compile-time error to declare a fragment shader input with, or that
5021contains, any of the following types:</p>
5022</div>
5023<div class="ulist">
5024<ul>
5025<li>
5026<p>A <a href="#booleans">boolean type</a></p>
5027</li>
5028<li>
5029<p>An <a href="#opaque-types">opaque type</a></p>
5030</li>
5031</ul>
5032</div>
5033<div class="paragraph">
5034<p>Fragment shader inputs that are, or contain, integral
5035or double-precision floating-point
5036types must be
5037qualified with the interpolation qualifier <strong>flat</strong>.</p>
5038</div>
5039<div class="paragraph">
5040<p>Fragment inputs are declared as in the following examples:</p>
5041</div>
5042<div class="listingblock">
5043<div class="content">
5044<pre class="CodeRay highlight"><code data-lang="c++">in vec3 normal;
5045centroid in vec2 TexCoord;
5046invariant centroid in vec4 Color;
5047noperspective in <span class="predefined-type">float</span> temperature;
5048flat in vec3 myColor;
5049noperspective centroid in vec2 myTexCoord;</code></pre>
5050</div>
5051</div>
5052<div class="paragraph">
5053<p>The fragment shader inputs form an interface with the last active shader in
5054the vertex processing pipeline.
5055For this interface, the last active shader stage output variables and
5056fragment shader input variables of the same name must match in type and
5057qualification, with a few exceptions: The storage qualifiers must, of
5058course, differ (one is <strong>in</strong> and one is <strong>out</strong>).
5059Also,
5060interpolation qualification (e.g. <strong>flat</strong>) and
5061auxiliary qualification (e.g. <strong>centroid</strong>) may differ.
5062These mismatches are allowed between any pair of stages.
5063When
5064interpolation or
5065auxiliary qualifiers do not match, those provided in
5066the fragment shader supersede those provided in previous stages.
5067If any such qualifiers are completely missing in the fragment shaders, then
5068the default is used, rather than any qualifiers that may have been declared
5069in previous stages.
5070That is, what matters is what is declared in the fragment shaders, not what
5071is declared in shaders in previous stages.</p>
5072</div>
5073<div class="paragraph">
5074<p>When an interface between shader stages is formed using shaders from two
5075separate program objects, it is not possible to detect mismatches between
5076inputs and outputs when the programs are linked.
5077When there are mismatches between inputs and outputs on such interfaces,
5078the values passed across the interface will be partially or completely
5079undefined.</p>
5080</div>
5081<div class="paragraph">
5082<p>Shaders can ensure matches across such interfaces either by using input and
5083output layout qualifiers (sections &#8220;<a href="#input-layout-qualifiers">Input Layout
5084Qualifiers</a>&#8221; and &#8220;<a href="#output-layout-qualifiers">Output Layout
5085Qualifiers</a>&#8221;) or by using identical input and output declarations of
5086blocks or variables.
5087Complete rules for interface matching are found in section 7.4.1 &#8220;Shader
5088Interface Matching&#8221; of the <a href="#references">OpenGL Specification</a>.</p>
5089</div>
5090<div class="paragraph">
5091<p>Compute shaders do not permit user-defined input variables and do not form a
5092formal interface with any other shader stage.
5093See &#8220;<a href="#compute-shader-special-variables">Compute Shader Special
5094Variables</a>&#8221; for a description of built-in compute shader input variables.
5095All other input to a compute shader is retrieved explicitly through image
5096loads, texture fetches, loads from uniforms or uniform buffers, or other
5097user supplied code.
5098Redeclaration of built-in input variables in compute shaders is not
5099permitted.</p>
5100</div>
5101</div>
5102<div class="sect3">
5103<h4 id="uniform-variables">4.3.5. Uniform Variables</h4>
5104<div class="paragraph">
5105<p>The <strong>uniform</strong> qualifier is used to declare global variables whose values are
5106the same across the entire primitive being processed.
5107All <strong>uniform</strong> variables are read-only and are initialized externally either
5108at link time or through the API.
5109The link-time initial value is either the value of the variable&#8217;s
5110initializer, if present, or 0 if no initializer is present.
5111Opaque types cannot have initializers, or a compile-time error results.
5112When targeting Vulkan, it is a compile-time error to declare <strong>uniform</strong>
5113variables outside a block.</p>
5114</div>
5115<div class="paragraph">
5116<p>Example declarations are:</p>
5117</div>
5118<div class="listingblock">
5119<div class="content">
5120<pre class="CodeRay highlight"><code data-lang="c++">uniform vec4 lightPosition;
5121uniform vec3 color = vec3(<span class="float">0</span><span class="float">.7</span>, <span class="float">0</span><span class="float">.7</span>, <span class="float">0</span><span class="float">.2</span>); <span class="comment">// value assigned at link time</span></code></pre>
5122</div>
5123</div>
5124<div class="paragraph">
5125<p>The <strong>uniform</strong> qualifier can be used with any of the basic data types, or
5126when declaring a variable whose type is a structure, or an array of any of
5127these.</p>
5128</div>
5129<div class="paragraph">
5130<p>There is an implementation-dependent limit on the amount of storage for
5131uniforms that can be used for each type of shader and if this is exceeded it
5132will cause a compile-time or link-time error.
5133Uniform variables that are declared but not
5134used do not count against this limit.
5135The number of user-defined uniform variables and the number of built-in
5136uniform variables that are used within a shader are added together to
5137determine whether available uniform storage has been exceeded.</p>
5138</div>
5139<div class="paragraph">
5140<p>Uniforms in shaders all share a single global name space when linked into a
5141program or separable program.
5142Hence, the types,
5143initializers,
5144and any location specifiers of all statically used uniform variables with the
5145same name must match across all shaders that are linked into a single program.
5146However it is not required to repeat the
5147initializer or
5148location specifier in all the linked shaders.
5149While this single uniform name space is cross stage, a uniform variable
5150name&#8217;s scope is per stage: If a uniform variable name is declared in one
5151stage (e.g. a vertex shader) but not in another (e.g. a fragment shader),
5152then that name is still available in the other stage for a different use.</p>
5153</div>
5154</div>
5155<div class="sect3">
5156<h4 id="output-variables">4.3.6. Output Variables</h4>
5157<div class="paragraph">
5158<p>Shader output variables are declared with the <strong>out</strong> storage qualifier.
5159They form the output interface between the declaring shader and the
5160subsequent stages of the API pipeline.
5161Output variables must be declared at global scope.
5162During shader execution they will behave as normal unqualified global
5163variables.
5164Their values are copied out to the subsequent pipeline stage on shader exit.
5165Only output variables that are read by the subsequent pipeline stage need to
5166be written; it is allowed to have superfluous declarations of output
5167variables.</p>
5168</div>
5169<div class="paragraph">
5170<p>There is <em>not</em> an <strong>inout</strong> storage qualifier for declaring a single variable
5171name as both input and output to a shader.
5172Also, a variable cannot be declared with both the <strong>in</strong> and the <strong>out</strong>
5173qualifiers, this will result in a compile-time or link-time error.
5174Output variables must be declared with different names than input variables.
5175However, nesting an input or output inside an interface block with an
5176instance name allows the same names with one referenced through a block
5177instance name.</p>
5178</div>
5179<div class="paragraph">
5180<p>Vertex, tessellation evaluation, and geometry output variables output
5181per-vertex data and are declared using the <strong>out</strong> storage qualifier.
5182Applying <strong>patch</strong> to an output can only be done in a tessellation control
5183shader.
5184It is a compile-time error to use <strong>patch</strong> on outputs in any other stage.</p>
5185</div>
5186<div class="paragraph">
5187<p>It is a compile-time error to declare a vertex, tessellation evaluation,
5188tessellation control, or geometry shader output with, or that contains, any
5189of the following types:</p>
5190</div>
5191<div class="ulist">
5192<ul>
5193<li>
5194<p>A <a href="#booleans">boolean type</a></p>
5195</li>
5196<li>
5197<p>An <a href="#opaque-types">opaque type</a></p>
5198</li>
5199</ul>
5200</div>
5201<div class="paragraph">
5202<p>Individual outputs are declared as in the following examples:</p>
5203</div>
5204<div class="listingblock">
5205<div class="content">
5206<pre class="CodeRay highlight"><code data-lang="c++">out vec3 normal;
5207centroid out vec2 TexCoord;
5208invariant centroid out vec4 Color;
5209flat out vec3 myColor;
5210sample out vec4 perSampleColor;</code></pre>
5211</div>
5212</div>
5213<div class="paragraph">
5214<p>These can also appear in interface blocks, as described in
5215&#8220;<a href="#interface-blocks">Interface Blocks</a>&#8221;.
5216Interface blocks allow simpler addition of arrays to the interface from
5217vertex to geometry shader.
5218They also allow a fragment shader to have the same input interface as a
5219geometry shader for a given vertex shader.</p>
5220</div>
5221<div class="paragraph">
5222<p>Tessellation control shader output variables are used to output
5223per-vertex and per-patch data.
5224Per-vertex output variables are arrayed (see <em>arrayed</em> under
5225&#8220;<a href="#input-variables">Input Variables</a>&#8221;) and declared using the <strong>out</strong>
5226qualifier without the <strong>patch</strong> qualifier.
5227Per-patch output variables are declared using the <strong>patch</strong> and <strong>out</strong>
5228qualifiers.</p>
5229</div>
5230<div class="paragraph">
5231<p>Since tessellation control shaders produce an arrayed primitive comprising
5232multiple vertices, each per-vertex output variable (or output block, see
5233interface blocks below) needs to be declared as an array.
5234For example,</p>
5235</div>
5236<div class="listingblock">
5237<div class="content">
5238<pre class="CodeRay highlight"><code data-lang="c++">out <span class="predefined-type">float</span> foo[]; <span class="comment">// feeds next stage input &quot;in float foo[]&quot;</span></code></pre>
5239</div>
5240</div>
5241<div class="paragraph">
5242<p>Each element of such an array corresponds to one vertex of the primitive
5243being produced.
5244Each array can optionally have a size declared.
5245The array size will be set by (or if provided must be consistent with) the
5246output layout declaration(s) establishing the number of vertices in the
5247output patch, as described later in
5248&#8220;<a href="#tessellation-control-outputs">Tessellation Control Outputs</a>&#8221;.</p>
5249</div>
5250<div class="paragraph">
5251<p>Each tessellation control shader invocation has a corresponding output patch
5252vertex, and may assign values to per-vertex outputs only if they belong to
5253that corresponding vertex.
5254If a per-vertex output variable is used as an l-value, it is a compile-time
5255or link-time error if the expression indicating the vertex index is not the
5256identifier <em>gl_InvocationID</em>.</p>
5257</div>
5258<div class="paragraph">
5259<p>The order of execution of a tessellation control shader invocation relative
5260to the other invocations for the same input patch is undefined unless the
5261built-in function <strong>barrier</strong>() is used.
5262This provides some control over relative execution order.
5263When a shader invocation calls <strong>barrier</strong>(), its execution pauses until all
5264other invocations have reached the same point of execution.
5265Output variable assignments performed by any invocation executed prior to
5266calling <strong>barrier</strong>() will be visible to any other invocation after the call
5267to <strong>barrier</strong>() returns.</p>
5268</div>
5269<div class="paragraph">
5270<p>Because tessellation control shader invocations execute in undefined order
5271between barriers, the values of per-vertex or per-patch output variables
5272will sometimes be undefined.
5273Consider the beginning and end of shader execution and each call to
5274<strong>barrier</strong>() as synchronization points.
5275The value of an output variable will be undefined in any of the three
5276following cases:</p>
5277</div>
5278<div class="olist arabic">
5279<ol class="arabic">
5280<li>
5281<p>At the beginning of execution.</p>
5282</li>
5283<li>
5284<p>At each synchronization point, unless</p>
5285<div class="openblock">
5286<div class="content">
5287<div class="ulist">
5288<ul>
5289<li>
5290<p>the value was well-defined after the previous synchronization point and
5291was not written by any invocation since, or</p>
5292</li>
5293<li>
5294<p>the value was written by exactly one shader invocation since the previous
5295synchronization point, or</p>
5296</li>
5297<li>
5298<p>the value was written by multiple shader invocations since the previous
5299synchronization point, and the last write performed by all such
5300invocations wrote the same value.</p>
5301</li>
5302</ul>
5303</div>
5304</div>
5305</div>
5306</li>
5307<li>
5308<p>When read by a shader invocation, if</p>
5309<div class="openblock">
5310<div class="content">
5311<div class="ulist">
5312<ul>
5313<li>
5314<p>the value was undefined at the previous synchronization point and has not
5315been written by the same shader invocation since, or</p>
5316</li>
5317<li>
5318<p>the output variable is written to by any other shader invocation between
5319the previous and next synchronization points, even if that assignment
5320occurs in code following the read.</p>
5321</li>
5322</ul>
5323</div>
5324</div>
5325</div>
5326</li>
5327</ol>
5328</div>
5329<div class="paragraph">
5330<p>Fragment outputs output per-fragment data and are declared using the <strong>out</strong>
5331storage qualifier.
5332It is a compile-time error to use auxiliary storage qualifiers or
5333interpolation qualifiers in a fragment shader output declaration.
5334It is a compile-time error to declare a fragment shader output with, or that
5335contains, any of the following types:</p>
5336</div>
5337<div class="ulist">
5338<ul>
5339<li>
5340<p>A <a href="#booleans">boolean type</a></p>
5341</li>
5342<li>
5343<p>A double-precision scalar or vector (<strong>double</strong>, <strong>dvec2</strong>, <strong>dvec3</strong>,
5344<strong>dvec4</strong>)</p>
5345</li>
5346<li>
5347<p>An <a href="#opaque-types">opaque type</a></p>
5348</li>
5349<li>
5350<p>A matrix type</p>
5351</li>
5352<li>
5353<p>A structure</p>
5354</li>
5355</ul>
5356</div>
5357<div class="paragraph">
5358<p>Fragment outputs are declared as in the following examples:</p>
5359</div>
5360<div class="listingblock">
5361<div class="content">
5362<pre class="CodeRay highlight"><code data-lang="c++">out vec4 FragmentColor;
5363out uint Luminosity;</code></pre>
5364</div>
5365</div>
5366<div class="paragraph">
5367<p>Compute shaders have no built-in output variables, do not support
5368user-defined output variables and do not form a formal interface with any
5369other shader stage.
5370All outputs from a compute shader take the form of the side effects such as
5371image stores and operations on atomic counters.</p>
5372</div>
5373</div>
5374<div class="sect3">
5375<h4 id="buffer-variables">4.3.7. Buffer Variables</h4>
5376<div class="paragraph">
5377<p>The <strong>buffer</strong> qualifier is used to declare global variables whose values are
5378stored in the data store of a buffer object bound through the API.
5379Buffer variables can be read and written, with the underlying storage shared
5380among all active shader invocations.
5381Buffer variable memory reads and writes within a single shader invocation
5382are processed in order.
5383However, the order of reads and writes performed in one invocation relative
5384to those performed by another invocation is largely undefined.
5385Buffer variables may be qualified with memory qualifiers affecting how the
5386underlying memory is accessed, as described in &#8220;<a href="#memory-qualifiers">Memory
5387Qualifiers</a>&#8221;.</p>
5388</div>
5389<div class="paragraph">
5390<p>The <strong>buffer</strong> qualifier can be used to declare interface blocks (see
5391&#8220;<a href="#interface-blocks">Interface Blocks</a>&#8221;), which are then referred to as
5392shader storage blocks.
5393It is a compile-time error to declare buffer variables outside a block.</p>
5394</div>
5395<div class="listingblock">
5396<div class="content">
5397<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">// use buffer to create a buffer block (shader storage block)</span>
5398buffer BufferName { <span class="comment">// externally visible name of buffer</span>
5399    <span class="predefined-type">int</span> count;      <span class="comment">// typed, shared memory...</span>
5400    ...             <span class="comment">// ...</span>
5401    vec4 v[];       <span class="comment">// last member may be an array that is not sized</span>
5402                    <span class="comment">// until after link time (dynamically sized)</span>
5403} Name;             <span class="comment">// name of block within the shader</span></code></pre>
5404</div>
5405</div>
5406<div class="paragraph">
5407<p>There are implementation-dependent limits on the number of shader storage
5408blocks used for each type of shader, the combined number of shader storage
5409blocks used for a program, and the amount of storage required by each
5410individual shader storage block.
5411If any of these limits are exceeded, it will cause a compile-time or
5412link-time error.</p>
5413</div>
5414<div class="paragraph">
5415<p>If multiple shaders are linked together, then they will share a single
5416global buffer variable name space.
5417Hence, the types of all declared buffer variables with the same name must
5418match across all shaders that are linked into a single program.</p>
5419</div>
5420</div>
5421<div class="sect3">
5422<h4 id="shared-variables">4.3.8. Shared Variables</h4>
5423<div class="paragraph">
5424<p>The <strong>shared</strong> qualifier is used to declare global variables that have storage
5425shared between all work items in a compute shader workgroup.
5426Variables declared as <strong>shared</strong> may only be used in compute shaders (see
5427&#8220;<a href="#compute-processor">Compute Processor</a>&#8221;).
5428Any other declaration of a <strong>shared</strong> variable is a compile-time error.
5429Shared variables are implicitly coherent (see
5430&#8220;<a href="#memory-qualifiers">Memory Qualifiers</a>&#8221;).</p>
5431</div>
5432<div class="paragraph">
5433<p>Variables declared as <strong>shared</strong> may not have initializers and their contents
5434are undefined at the beginning of shader execution.
5435Any data written to <strong>shared</strong> variables will be visible to other work items
5436(executing the same shader) within the same workgroup.</p>
5437</div>
5438<div class="paragraph">
5439<p>In the absence of synchronization, the order of reads and writes to the same
5440<strong>shared</strong> variable by different invocations of a shader is not defined.</p>
5441</div>
5442<div class="paragraph">
5443<p>In order to achieve ordering with respect to reads and writes to <strong>shared</strong>
5444variables, control flow barriers must be employed using the <strong>barrier</strong>() function
5445(see &#8220;<a href="#shader-invocation-control-functions">Shader Invocation Control
5446Functions</a>&#8221;).</p>
5447</div>
5448<div class="paragraph">
5449<p>There is a limit to the total size of all variables declared as <strong>shared</strong> in a
5450single program.
5451This limit, expressed in units of basic machine units may be determined by
5452using the OpenGL API to query the value of
5453MAX_COMPUTE_SHARED_MEMORY_SIZE.</p>
5454</div>
5455</div>
5456<div class="sect3">
5457<h4 id="interface-blocks">4.3.9. Interface Blocks</h4>
5458<div class="paragraph">
5459<p>Input, output, uniform, and buffer variable declarations can be grouped into
5460named interface blocks to provide coarser granularity backing than is
5461achievable with individual declarations.
5462They can have an optional instance name, used in the shader to reference
5463their members.
5464An output block of one programmable stage is backed by a corresponding input
5465block in the subsequent programmable stage.
5466A <em>uniform block</em> is backed by the application with a buffer object.
5467A block of buffer variables, called a <em>shader storage block</em>, is also backed
5468by the application with a buffer object.
5469It is a compile-time error to have an input block in a vertex shader or an
5470output block in a fragment shader.
5471These uses are reserved for future use.</p>
5472</div>
5473<div class="paragraph">
5474<p>An interface block is started by an <strong>in</strong>, <strong>out</strong>, <strong>uniform</strong>, or <strong>buffer</strong>
5475keyword, followed by a block name, followed by an open curly brace (<strong>{</strong>) as
5476follows:</p>
5477</div>
5478<div class="openblock bnf">
5479<div class="content">
5480<div class="dlist">
5481<dl>
5482<dt class="hdlist1"><em>interface-block</em> : </dt>
5483<dd>
5484<p><em>layout-qualifier<sub>opt</sub></em> <em>interface-qualifier</em> <em>block-name</em> <strong>{</strong>
5485<em>member-list</em> <strong>}</strong> <em>instance-name<sub>opt</sub></em> <strong>;</strong></p>
5486</dd>
5487</dl>
5488</div>
5489<div class="dlist">
5490<dl>
5491<dt class="hdlist1"><em>interface-qualifier</em> : </dt>
5492<dd>
5493<p><strong>in</strong><br>
5494<strong>out</strong><br>
5495<strong>patch</strong> <strong>in</strong> // Note: Qualifiers can be in any order.<br>
5496<strong>patch</strong> <strong>out</strong><br>
5497<strong>uniform</strong><br>
5498<strong>buffer</strong></p>
5499</dd>
5500</dl>
5501</div>
5502<div class="dlist">
5503<dl>
5504<dt class="hdlist1"><em>member-list</em> : </dt>
5505<dd>
5506<p><em>member-declaration</em><br>
5507<em>member-declaration</em> <em>member-list</em></p>
5508</dd>
5509<dt class="hdlist1"><em>member-declaration</em> : </dt>
5510<dd>
5511<p><em>layout-qualifier<sub>opt</sub></em> <em>qualifiers<sub>opt</sub></em> <em>type</em> <em>declarators</em> <strong>;</strong></p>
5512</dd>
5513</dl>
5514</div>
5515<div class="dlist">
5516<dl>
5517<dt class="hdlist1"><em>instance-name</em> : </dt>
5518<dd>
5519<p><em>identifier</em><br>
5520<em>identifier</em> <strong>[</strong> <strong>]</strong><br>
5521<em>identifier</em> <strong>[</strong> <em>constant-integral-expression</em> <strong>]</strong></p>
5522</dd>
5523</dl>
5524</div>
5525</div>
5526</div>
5527<div class="paragraph">
5528<p>Each of the above elements is discussed below, with the exception of layout
5529qualifiers (<em>layout-qualifier</em>), which are defined in the next section.</p>
5530</div>
5531<div class="paragraph">
5532<p>First, an example,</p>
5533</div>
5534<div class="listingblock">
5535<div class="content">
5536<pre class="CodeRay highlight"><code data-lang="c++">uniform Transform {
5537    mat4 ModelViewMatrix;
5538    mat4 ModelViewProjectionMatrix;
5539    uniform mat3 NormalMatrix;      <span class="comment">// allowed restatement of qualifier</span>
5540    <span class="predefined-type">float</span> Deformation;
5541};</code></pre>
5542</div>
5543</div>
5544<div class="paragraph">
5545<p>The above establishes a uniform block named &#8220;Transform&#8221; with four uniforms
5546grouped inside it.</p>
5547</div>
5548<div class="paragraph">
5549<p>Types and declarators are the same as for other input, output, uniform, and
5550buffer variable declarations outside blocks, with these exceptions:</p>
5551</div>
5552<div class="ulist">
5553<ul>
5554<li>
5555<p>Initializers are not allowed</p>
5556</li>
5557<li>
5558<p>Opaque types are not allowed</p>
5559</li>
5560<li>
5561<p>Structure definitions cannot be nested inside a block</p>
5562</li>
5563</ul>
5564</div>
5565<div class="paragraph">
5566<p>Any of these would result in a compile-time error.</p>
5567</div>
5568<div class="paragraph">
5569<p>If no optional qualifier is used in a member-declaration, the qualification
5570of the member includes all <strong>in</strong>, <strong>out</strong>, <strong>patch</strong>, <strong>uniform</strong>, or <strong>buffer</strong> as
5571determined by <em>interface-qualifier</em>.
5572If optional qualifiers are used, they can include interpolation qualifiers,
5573auxiliary storage qualifiers,
5574and storage qualifiers and they must declare
5575an input, output, or uniform member consistent with the interface qualifier
5576of the block: Input variables, output variables, uniform variables, and
5577<strong>buffer</strong> members can only be in <strong>in</strong> blocks, <strong>out</strong> blocks, <strong>uniform</strong> blocks,
5578and shader storage blocks, respectively.</p>
5579</div>
5580<div class="paragraph">
5581<p>Repeating the <strong>in</strong>, <strong>out</strong>, <strong>patch</strong>, <strong>uniform</strong>, or <strong>buffer</strong> interface
5582qualifier for a member&#8217;s storage qualifier is optional.
5583For example,</p>
5584</div>
5585<div class="listingblock">
5586<div class="content">
5587<pre class="CodeRay highlight"><code data-lang="c++">in Material {
5588    smooth in vec4 Color1; <span class="comment">// legal, input inside in block</span>
5589    smooth vec4 Color2;    <span class="comment">// legal, 'in' inherited from 'in Material'</span>
5590    vec2 TexCoord;         <span class="comment">// legal, TexCoord is an input</span>
5591    uniform <span class="predefined-type">float</span> Atten;   <span class="comment">// illegal, mismatched storage qualifier</span>
5592};</code></pre>
5593</div>
5594</div>
5595<div class="paragraph">
5596<p>A <em>shader interface</em> is defined to be one of these:</p>
5597</div>
5598<div class="ulist">
5599<ul>
5600<li>
5601<p>All the uniform variables and uniform blocks declared in a program.
5602This spans all compilation units linked together within one program.</p>
5603</li>
5604<li>
5605<p>All the <strong>buffer</strong> blocks declared in a program.</p>
5606</li>
5607<li>
5608<p>The boundary between adjacent programmable pipeline stages: This spans
5609all the outputs declared in all compilation units of the first stage and
5610all the inputs declared in all compilation units of the second stage.
5611Note that for the purposes of this definition, the fragment shader and
5612the preceding shader are considered to have a shared boundary even
5613though in practice, all values passed to the fragment shader first pass
5614through the rasterizer and interpolator.</p>
5615</li>
5616</ul>
5617</div>
5618<div class="paragraph">
5619<p>The block name (<em>block-name</em>) is used to match within shader interfaces: an
5620output block of one pipeline stage will be matched to an input block with
5621the same name in the subsequent pipeline stage.
5622For uniform or shader storage blocks, the application uses the block name to
5623identify the block.
5624Block names have no other use within a shader beyond interface matching; it
5625is a compile-time error
5626to use a block name at global scope for anything other than as a
5627block name (e.g. use of a block name for a global variable name or function
5628name is currently reserved).
5629It is a compile-time error to use the same block name for more than one
5630block declaration in the same shader interface (as defined above) within one
5631shader, even if the block contents are identical.</p>
5632</div>
5633<div class="paragraph">
5634<p>Matched block names within a shader interface (as defined above) must match
5635in terms of having the same number of declarations with the same sequence of
5636types and the same sequence of member names, as well as having matching
5637member-wise layout qualification
5638(see next section).
5639Matched uniform or shader storage block names (but not input or output block
5640names) must also either all be lacking an instance name or all having an
5641instance name, putting their members at the same scoping level.
5642When instance names are present on matched block names, it is allowed for
5643the instance names to differ; they need not match for the blocks to match.
5644Furthermore, if a matching block is declared as an array, then the array
5645sizes must also match (or follow array matching rules for the shader
5646interface between consecutive shader stages).
5647Any mismatch will generate a link-time error.
5648A block name is allowed to have different definitions in different shader
5649interfaces within the same shader, allowing, for example, an input block and
5650output block to have the same name.</p>
5651</div>
5652<div class="paragraph">
5653<p>If an instance name (<em>instance-name</em>) is not used, the names declared inside
5654the block are scoped at the global level and accessed as if they were
5655declared outside the block.
5656If an instance name (<em>instance-name</em>) is used, then it puts all the members
5657inside a scope within its own name space, accessed with the field selector
5658(<strong>.</strong>) operator (analogously to structures).
5659For example,</p>
5660</div>
5661<div class="listingblock">
5662<div class="content">
5663<pre class="CodeRay highlight"><code data-lang="c++">in Light {
5664    vec4 LightPos;
5665    vec3 LightColor;
5666};
5667in ColoredTexture {
5668    vec4 Color;
5669    vec2 TexCoord;
5670} Material;           <span class="comment">// instance name</span>
5671vec3 Color;           <span class="comment">// different Color than Material.Color</span>
5672vec4 LightPos;        <span class="comment">// illegal, already defined</span>
5673...
5674... = LightPos;       <span class="comment">// accessing LightPos</span>
5675... = Material.Color; <span class="comment">// accessing Color in ColoredTexture block</span></code></pre>
5676</div>
5677</div>
5678<div class="paragraph">
5679<p>Outside the shading language (i.e., in the API), members are similarly
5680identified except the block name is always used in place of the instance
5681name (API accesses are to shader interfaces, not to shaders).
5682If there is no instance name, then the API does not use the block name to
5683access a member, just the member name.</p>
5684</div>
5685<div class="paragraph">
5686<p>Within a shader interface, all declarations of the same global name must be
5687for the same object and must match in type and in whether they declare a
5688variable or member of a block with no instance name.
5689The API also needs this name to uniquely identify an object in the shader
5690interface.
5691It is a link-time error if any particular shader interface contains</p>
5692</div>
5693<div class="ulist">
5694<ul>
5695<li>
5696<p>two different blocks, each having no instance name, and each having a
5697member of the same name, or</p>
5698</li>
5699<li>
5700<p>a variable outside a block, and a block with no instance name, where the
5701variable has the same name as a member in the block.</p>
5702</li>
5703</ul>
5704</div>
5705<div class="listingblock">
5706<div class="content">
5707<pre class="CodeRay highlight"><code data-lang="c++">out Vertex {
5708    vec4 Position;  <span class="comment">// API transform/feedback will use &quot;Vertex.Position&quot;</span>
5709    vec2 Texture;
5710} Coords;           <span class="comment">// shader will use &quot;Coords.Position&quot;</span>
5711out Vertex2 {
5712    vec4 Color;     <span class="comment">// API will use &quot;Color&quot;</span>
5713    <span class="predefined-type">float</span> Color2;
5714};
5715
5716<span class="comment">// in same program as Vertex2 above:</span>
5717out Vertex3 {
5718    <span class="predefined-type">float</span> Intensity;
5719    vec4 Color;     <span class="comment">// ERROR, name collision with Color in Vertex2</span>
5720};
5721<span class="predefined-type">float</span> Color2;       <span class="comment">// ERROR, collides with Color2 in Vertex2</span></code></pre>
5722</div>
5723</div>
5724<div class="paragraph">
5725<p>For blocks declared as arrays, the array index must also be included when
5726accessing members, as in this example</p>
5727</div>
5728<div class="listingblock">
5729<div class="content">
5730<pre class="CodeRay highlight"><code data-lang="c++">uniform Transform { <span class="comment">// API uses &quot;Transform[2]&quot; to refer to instance 2</span>
5731    mat4 ModelViewMatrix;
5732    mat4 ModelViewProjectionMatrix;
5733    vec4 a[]; <span class="comment">// array will get implicitly sized</span>
5734    <span class="predefined-type">float</span> Deformation;
5735} transforms[<span class="integer">4</span>];
5736...
5737... = transforms[<span class="integer">2</span>].ModelViewMatrix; <span class="comment">// shader access of instance 2</span>
5738<span class="comment">// API uses &quot;Transform.ModelViewMatrix&quot; to query an offset or other query</span>
5739transforms[x].a.length(); <span class="comment">// same length for 'a' for all x</span>
5740Transform[x];             <span class="comment">// illegal, must use 'transforms'</span>
5741Transform.a.length();     <span class="comment">// illegal, must use 'transforms'</span>
5742...transforms[<span class="integer">2</span>].a[<span class="integer">3</span>]...  <span class="comment">// if these are the only two dereferences of 'a',</span>
5743...transforms[<span class="integer">3</span>].a[<span class="integer">7</span>]...  <span class="comment">// then 'a' must be size 8, for all</span>
5744transforms[x]</code></pre>
5745</div>
5746</div>
5747<div class="paragraph">
5748<p>For uniform or shader storage blocks declared as an array, each individual
5749array element corresponds to a separate buffer object bind range, backing
5750one instance of the block.
5751As the array size indicates the number of buffer objects needed, uniform and
5752shader storage block array declarations must specify an array size.
5753A uniform or shader storage block array can only be indexed with a
5754dynamically uniform integral expression, otherwise results are undefined.</p>
5755</div>
5756<div class="paragraph">
5757<p>When using OpenGL API entry points to identify the name of an individual
5758block in an array of blocks, the name string may include an array index
5759(e.g. <em>Transform[2]</em>).
5760When using OpenGL API entry points to refer to offsets or other
5761characteristics of a block member, an array index must not be specified
5762(e.g. <em>Transform.ModelViewMatrix</em>).</p>
5763</div>
5764<div class="paragraph">
5765<p>Tessellation control, tessellation evaluation and geometry shader input
5766blocks must be declared as arrays and follow the array declaration and
5767linking rules for all shader inputs for the respective stages.
5768All other input and output block arrays must specify an array size.</p>
5769</div>
5770<div class="paragraph">
5771<p>There are implementation-dependent limits on the number of uniform blocks
5772and the number of shader storage blocks that can be used per stage.
5773If either limit is exceeded, it will cause a link-time error.</p>
5774</div>
5775</div>
5776</div>
5777<div class="sect2">
5778<h3 id="layout-qualifiers">4.4. Layout Qualifiers</h3>
5779<div class="paragraph">
5780<p>Layout qualifiers can appear in several forms of declaration.
5781They can appear as part of an interface block definition or block member, as
5782shown in the grammar in the previous section.
5783They can also appear with just an <em>interface-qualifier</em> to establish layouts
5784of other declarations made with that qualifier:</p>
5785</div>
5786<div class="openblock bnf">
5787<div class="content">
5788<div class="paragraph">
5789<p><em>layout-qualifier</em> <em>interface-qualifier</em> <strong>;</strong></p>
5790</div>
5791</div>
5792</div>
5793<div class="paragraph">
5794<p>Or, they can appear with an individual variable declared with an interface
5795qualifier:</p>
5796</div>
5797<div class="openblock bnf">
5798<div class="content">
5799<div class="paragraph">
5800<p><em>layout-qualifier</em> <em>interface-qualifier</em> <em>declaration</em> <strong>;</strong></p>
5801</div>
5802</div>
5803</div>
5804<div class="paragraph">
5805<p>Declarations of layouts can only be made at global scope or block members,
5806and only where indicated in the following subsections; their details are
5807specific to what the interface qualifier is, and are discussed individually.</p>
5808</div>
5809<div class="paragraph">
5810<p>The <em>layout-qualifier</em> expands to:</p>
5811</div>
5812<div class="openblock bnf">
5813<div class="content">
5814<div class="dlist">
5815<dl>
5816<dt class="hdlist1"><em>layout-qualifier</em> : </dt>
5817<dd>
5818<p><strong>layout</strong> <strong>(</strong> <em>layout-qualifier-id-list</em> <strong>)</strong></p>
5819</dd>
5820<dt class="hdlist1"><em>layout-qualifier-id-list</em> : </dt>
5821<dd>
5822<p><em>layout-qualifier-id</em><br>
5823<em>layout-qualifier-id</em> <strong>,</strong> <em>layout-qualifier-id-list</em></p>
5824</dd>
5825<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
5826<dd>
5827<p><em>layout-qualifier-name</em><br>
5828<em>layout-qualifier-name</em> <strong>=</strong> <em>layout-qualifier-value</em><br>
5829<strong>shared</strong></p>
5830</dd>
5831</dl>
5832</div>
5833</div>
5834</div>
5835<div class="openblock bnf">
5836<div class="content">
5837<div class="dlist">
5838<dl>
5839<dt class="hdlist1"><em>layout-qualifier-value</em> : </dt>
5840<dd>
5841<p><em>integer-constant-expression</em></p>
5842</dd>
5843</dl>
5844</div>
5845</div>
5846</div>
5847<div class="paragraph">
5848<p>The tokens used for <em>layout-qualifier-name</em> are identifiers, not keywords,
5849however, the <strong>shared</strong> keyword is allowed as a <em>layout-qualifier-id</em>.
5850Generally, they can be listed in any order.
5851Order-dependent meanings exist only if explicitly called out below.
5852Similarly, these identifiers are not case sensitive, unless explicitly noted
5853otherwise.</p>
5854</div>
5855<div class="paragraph">
5856<p>More than one layout qualifier may appear in a single declaration.
5857Additionally, the same <em>layout-qualifier-name</em> can occur multiple times
5858within a layout qualifier or across multiple layout qualifiers in the same
5859declaration.
5860When the same <em>layout-qualifier-name</em> occurs multiple times, in a single
5861declaration, the last occurrence overrides the former occurrence(s).
5862Further, if such a <em>layout-qualifier-name</em> will affect subsequent
5863declarations or other observable behavior, it is only the last occurrence
5864that will have any effect, behaving as if the earlier occurrence(s) within
5865the declaration are not present.
5866This is also true for overriding <em>layout-qualifier-name</em>, where one
5867overrides the other (e.g. <strong>row_major</strong> vs.
5868<strong>column_major</strong>); only the last occurrence has any effect.</p>
5869</div>
5870<div class="paragraph">
5871<p><em>integer-constant-expression</em> is defined in
5872&#8220;<a href="#constant-expressions">Constant Expressions</a>&#8221; as <em>constant integral
5873expression</em>, with it being a compile-time error for
5874<em>integer-constant-expression</em> to be a specialization constant.</p>
5875</div>
5876<div class="paragraph">
5877<p>The following table summarizes the use of layout qualifiers.
5878It shows for each one what kinds of declarations it may be applied to.
5879These are all discussed in detail in the following sections.</p>
5880</div>
5881<table class="tableblock frame-all grid-all stretch">
5882<colgroup>
5883<col style="width: 16.6666%;">
5884<col style="width: 16.6666%;">
5885<col style="width: 16.6666%;">
5886<col style="width: 16.6666%;">
5887<col style="width: 16.6666%;">
5888<col style="width: 16.667%;">
5889</colgroup>
5890<thead>
5891<tr>
5892<th class="tableblock halign-left valign-middle">Layout Qualifier</th>
5893<th class="tableblock halign-center valign-middle">Qualifier Only</th>
5894<th class="tableblock halign-center valign-middle">Individual Variable</th>
5895<th class="tableblock halign-center valign-middle">Block</th>
5896<th class="tableblock halign-center valign-middle">Block Member</th>
5897<th class="tableblock halign-left valign-middle">Allowed Interfaces</th>
5898</tr>
5899</thead>
5900<tbody>
5901<tr>
5902<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>shared</strong><br>
5903  <strong>packed</strong><br>
5904  <strong>std140</strong><br>
5905  <strong>std430</strong></p></td>
5906<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5907<td class="tableblock halign-center valign-middle"></td>
5908<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5909<td class="tableblock halign-center valign-middle"></td>
5910<td class="tableblock halign-left valign-middle" rowspan="5"><p class="tableblock"><strong>uniform</strong> / <strong>buffer</strong></p></td>
5911</tr>
5912<tr>
5913<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>row_major</strong><br>
5914  <strong>column_major</strong></p></td>
5915<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5916<td class="tableblock halign-center valign-middle"></td>
5917<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5918<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5919</tr>
5920<tr>
5921<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>binding</strong> =</p></td>
5922<td class="tableblock halign-center valign-middle"></td>
5923<td class="tableblock halign-center valign-middle"><p class="tableblock">opaque types only</p></td>
5924<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5925<td class="tableblock halign-center valign-middle"></td>
5926</tr>
5927<tr>
5928<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>offset</strong> =</p></td>
5929<td class="tableblock halign-center valign-middle"></td>
5930<td class="tableblock halign-center valign-middle"><p class="tableblock">atomic counters only</p></td>
5931<td class="tableblock halign-center valign-middle"></td>
5932<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5933</tr>
5934<tr>
5935<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>align</strong> =</p></td>
5936<td class="tableblock halign-center valign-middle"></td>
5937<td class="tableblock halign-center valign-middle"></td>
5938<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5939<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5940</tr>
5941<tr>
5942<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>set</strong> =</p></td>
5943<td class="tableblock halign-center valign-middle"></td>
5944<td class="tableblock halign-center valign-middle"><p class="tableblock">opaque types only</p></td>
5945<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5946<td class="tableblock halign-center valign-middle"></td>
5947<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>uniform</strong> / <strong>buffer</strong> (Vulkan only)</p></td>
5948</tr>
5949<tr>
5950<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>push_constant</strong></p></td>
5951<td class="tableblock halign-center valign-middle"></td>
5952<td class="tableblock halign-center valign-middle"></td>
5953<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5954<td class="tableblock halign-center valign-middle"></td>
5955<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>uniform</strong> (Vulkan only)</p></td>
5956</tr>
5957<tr>
5958<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>input_attachment_index</strong> =</p></td>
5959<td class="tableblock halign-center valign-middle"></td>
5960<td class="tableblock halign-center valign-middle"><p class="tableblock">subpass types only</p></td>
5961<td class="tableblock halign-center valign-middle"></td>
5962<td class="tableblock halign-center valign-middle"></td>
5963<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>uniform</strong> (Vulkan only)</p></td>
5964</tr>
5965<tr>
5966<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>location</strong> =</p></td>
5967<td class="tableblock halign-center valign-middle"></td>
5968<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5969<td class="tableblock halign-center valign-middle"></td>
5970<td class="tableblock halign-center valign-middle"></td>
5971<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>uniform</strong> / <strong>buffer</strong> and subroutine variables</p></td>
5972</tr>
5973<tr>
5974<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>location</strong> =</p></td>
5975<td class="tableblock halign-center valign-middle"></td>
5976<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5977<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5978<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5979<td class="tableblock halign-left valign-middle" rowspan="2"><p class="tableblock">all <strong>in</strong> / <strong>out</strong>, except for compute</p></td>
5980</tr>
5981<tr>
5982<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>component</strong> =</p></td>
5983<td class="tableblock halign-center valign-middle"></td>
5984<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5985<td class="tableblock halign-center valign-middle"></td>
5986<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5987</tr>
5988<tr>
5989<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>index</strong> =</p></td>
5990<td class="tableblock halign-center valign-middle"></td>
5991<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
5992<td class="tableblock halign-center valign-middle"></td>
5993<td class="tableblock halign-center valign-middle"></td>
5994<td class="tableblock halign-left valign-middle"><p class="tableblock">fragment <strong>out</strong> and subroutine functions</p></td>
5995</tr>
5996<tr>
5997<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>triangles</strong><br>
5998  <strong>quads</strong><br>
5999  <strong>isolines</strong></p></td>
6000<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6001<td class="tableblock halign-center valign-middle"></td>
6002<td class="tableblock halign-center valign-middle"></td>
6003<td class="tableblock halign-center valign-middle"></td>
6004<td class="tableblock halign-left valign-middle"><p class="tableblock">tessellation evaluation <strong>in</strong></p></td>
6005</tr>
6006<tr>
6007<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>equal_spacing</strong><br>
6008  <strong>fractional_even_spacing</strong><br>
6009  <strong>fractional_odd_spacing</strong></p></td>
6010<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6011<td class="tableblock halign-center valign-middle"></td>
6012<td class="tableblock halign-center valign-middle"></td>
6013<td class="tableblock halign-center valign-middle"></td>
6014<td class="tableblock halign-left valign-middle"><p class="tableblock">tessellation evaluation <strong>in</strong></p></td>
6015</tr>
6016<tr>
6017<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>cw</strong><br>
6018  <strong>ccw</strong></p></td>
6019<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6020<td class="tableblock halign-center valign-middle"></td>
6021<td class="tableblock halign-center valign-middle"></td>
6022<td class="tableblock halign-center valign-middle"></td>
6023<td class="tableblock halign-left valign-middle"><p class="tableblock">tessellation evaluation <strong>in</strong></p></td>
6024</tr>
6025<tr>
6026<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>point_mode</strong></p></td>
6027<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6028<td class="tableblock halign-center valign-middle"></td>
6029<td class="tableblock halign-center valign-middle"></td>
6030<td class="tableblock halign-center valign-middle"></td>
6031<td class="tableblock halign-left valign-middle"><p class="tableblock">tessellation evaluation <strong>in</strong></p></td>
6032</tr>
6033<tr>
6034<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>points</strong></p></td>
6035<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6036<td class="tableblock halign-center valign-middle"></td>
6037<td class="tableblock halign-center valign-middle"></td>
6038<td class="tableblock halign-center valign-middle"></td>
6039<td class="tableblock halign-left valign-middle"><p class="tableblock">geometry <strong>in</strong>/<strong>out</strong></p></td>
6040</tr>
6041<tr>
6042<td class="tableblock halign-left valign-middle"><p class="tableblock">[ <strong>points</strong> ]<br>
6043  <strong>lines</strong><br>
6044  <strong>lines_adjacency</strong><br>
6045  <strong>triangles</strong><br>
6046  <strong>triangles_adjacency</strong></p></td>
6047<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6048<td class="tableblock halign-center valign-middle"></td>
6049<td class="tableblock halign-center valign-middle"></td>
6050<td class="tableblock halign-center valign-middle"></td>
6051<td class="tableblock halign-left valign-middle"><p class="tableblock">geometry <strong>in</strong></p></td>
6052</tr>
6053<tr>
6054<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>invocations</strong> =</p></td>
6055<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6056<td class="tableblock halign-center valign-middle"></td>
6057<td class="tableblock halign-center valign-middle"></td>
6058<td class="tableblock halign-center valign-middle"></td>
6059<td class="tableblock halign-left valign-middle"><p class="tableblock">geometry <strong>in</strong></p></td>
6060</tr>
6061<tr>
6062<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>origin_upper_left</strong><br>
6063  <strong>pixel_center_integer</strong></p></td>
6064<td class="tableblock halign-center valign-middle"></td>
6065<td class="tableblock halign-center valign-middle"><p class="tableblock"><em>gl_FragCoord</em> only</p></td>
6066<td class="tableblock halign-center valign-middle"></td>
6067<td class="tableblock halign-center valign-middle"></td>
6068<td class="tableblock halign-left valign-middle" rowspan="2"><p class="tableblock">fragment <strong>in</strong></p></td>
6069</tr>
6070<tr>
6071<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>early_fragment_tests</strong></p></td>
6072<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6073<td class="tableblock halign-center valign-middle"></td>
6074<td class="tableblock halign-center valign-middle"></td>
6075<td class="tableblock halign-center valign-middle"></td>
6076</tr>
6077<tr>
6078<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>local_size_x</strong> =<br>
6079  <strong>local_size_y</strong> =<br>
6080  <strong>local_size_z</strong> =</p></td>
6081<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6082<td class="tableblock halign-center valign-middle"></td>
6083<td class="tableblock halign-center valign-middle"></td>
6084<td class="tableblock halign-center valign-middle"></td>
6085<td class="tableblock halign-left valign-middle"><p class="tableblock">compute <strong>in</strong></p></td>
6086</tr>
6087<tr>
6088<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>local_size_x_id</strong> =<br>
6089  <strong>local_size_y_id</strong> =<br>
6090  <strong>local_size_z_id</strong> =</p></td>
6091<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6092<td class="tableblock halign-center valign-middle"></td>
6093<td class="tableblock halign-center valign-middle"></td>
6094<td class="tableblock halign-center valign-middle"></td>
6095<td class="tableblock halign-left valign-middle"><p class="tableblock">compute <strong>in</strong> (SPIR-V only)</p></td>
6096</tr>
6097<tr>
6098<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>xfb_buffer</strong> =<br>
6099  <strong>xfb_stride</strong> =</p></td>
6100<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6101<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6102<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6103<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6104<td class="tableblock halign-left valign-middle" rowspan="2"><p class="tableblock">vertex, tessellation, and geometry <strong>out</strong></p></td>
6105</tr>
6106<tr>
6107<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>xfb_offset</strong> =</p></td>
6108<td class="tableblock halign-center valign-middle"></td>
6109<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6110<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6111<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6112</tr>
6113<tr>
6114<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>vertices</strong> =</p></td>
6115<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6116<td class="tableblock halign-center valign-middle"></td>
6117<td class="tableblock halign-center valign-middle"></td>
6118<td class="tableblock halign-center valign-middle"></td>
6119<td class="tableblock halign-left valign-middle"><p class="tableblock">tessellation control <strong>out</strong></p></td>
6120</tr>
6121<tr>
6122<td class="tableblock halign-left valign-middle"><p class="tableblock">[ <strong>points</strong> ]<br>
6123  <strong>line_strip</strong><br>
6124  <strong>triangle_strip</strong></p></td>
6125<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6126<td class="tableblock halign-center valign-middle"></td>
6127<td class="tableblock halign-center valign-middle"></td>
6128<td class="tableblock halign-center valign-middle"></td>
6129<td class="tableblock halign-left valign-middle" rowspan="3"><p class="tableblock">geometry <strong>out</strong></p></td>
6130</tr>
6131<tr>
6132<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>max_vertices</strong> =</p></td>
6133<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6134<td class="tableblock halign-center valign-middle"></td>
6135<td class="tableblock halign-center valign-middle"></td>
6136<td class="tableblock halign-center valign-middle"></td>
6137</tr>
6138<tr>
6139<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>stream</strong> =</p></td>
6140<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6141<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6142<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6143<td class="tableblock halign-center valign-middle"><p class="tableblock">X</p></td>
6144</tr>
6145<tr>
6146<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>depth_any</strong><br>
6147  <strong>depth_greater</strong><br>
6148  <strong>depth_less</strong><br>
6149  <strong>depth_unchanged</strong></p></td>
6150<td class="tableblock halign-center valign-middle"></td>
6151<td class="tableblock halign-center valign-middle"><p class="tableblock"><em>gl_FragDepth</em> only</p></td>
6152<td class="tableblock halign-center valign-middle"></td>
6153<td class="tableblock halign-center valign-middle"></td>
6154<td class="tableblock halign-left valign-middle"><p class="tableblock">fragment <strong>out</strong></p></td>
6155</tr>
6156<tr>
6157<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>constant_id</strong> =</p></td>
6158<td class="tableblock halign-center valign-middle"></td>
6159<td class="tableblock halign-center valign-middle"><p class="tableblock">scalar only</p></td>
6160<td class="tableblock halign-center valign-middle"></td>
6161<td class="tableblock halign-center valign-middle"></td>
6162<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>const</strong> (SPIR-V only)</p></td>
6163</tr>
6164<tr>
6165<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>rgba32f</strong><br>
6166  <strong>rgba16f</strong><br>
6167  <strong>rg32f</strong><br>
6168  <strong>rg16f</strong><br>
6169  <strong>r11f_g11f_b10f</strong><br>
6170  <strong>r32f</strong><br>
6171  <strong>r16f</strong><br>
6172  <strong>rgba16</strong><br>
6173  <strong>rgb10_a2</strong><br>
6174  <strong>rgba8</strong><br>
6175  <strong>rg16</strong><br>
6176  <strong>rg8</strong><br>
6177  <strong>r16</strong><br>
6178  <strong>r8</strong><br>
6179  <strong>rgba16_snorm</strong><br>
6180  <strong>rgba8_snorm</strong><br>
6181  <strong>rg16_snorm</strong><br>
6182  <strong>rg8_snorm</strong><br>
6183  <strong>r16_snorm</strong><br>
6184  <strong>r8_snorm</strong><br>
6185  <strong>rgba32i</strong><br>
6186  <strong>rgba16i</strong><br>
6187  <strong>rgba8i</strong><br>
6188  <strong>rg32i</strong><br>
6189  <strong>rg16i</strong><br>
6190  <strong>rg8i</strong><br>
6191  <strong>r32i</strong><br>
6192  <strong>r16i</strong><br>
6193  <strong>r8i</strong><br>
6194  <strong>rgba32ui</strong><br>
6195  <strong>rgba16ui</strong><br>
6196<strong>rgb10_a2ui</strong><br>
6197  <strong>rgba8ui</strong><br>
6198  <strong>rg32ui</strong><br>
6199  <strong>rg16ui</strong><br>
6200  <strong>rg8ui</strong><br>
6201  <strong>r32ui</strong><br>
6202  <strong>r16ui</strong><br>
6203  <strong>r8ui</strong></p></td>
6204<td class="tableblock halign-center valign-middle"></td>
6205<td class="tableblock halign-center valign-middle"><p class="tableblock">image types only</p></td>
6206<td class="tableblock halign-center valign-middle"></td>
6207<td class="tableblock halign-center valign-middle"></td>
6208<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>uniform</strong></p></td>
6209</tr>
6210</tbody>
6211</table>
6212<div class="sect3">
6213<h4 id="input-layout-qualifiers">4.4.1. Input Layout Qualifiers</h4>
6214<div class="paragraph">
6215<p>Layout qualifiers specific to a particular shader language are discussed in
6216separate sections below.</p>
6217</div>
6218<div class="paragraph">
6219<p>All shaders except compute shaders allow <strong>location</strong> layout qualifiers on
6220input variable declarations, input block declarations, and input block
6221member declarations.
6222Of these, variables and block members (but not blocks) additionally allow
6223the <strong>component</strong> layout qualifier.</p>
6224</div>
6225<div class="openblock bnf">
6226<div class="content">
6227<div class="dlist">
6228<dl>
6229<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
6230<dd>
6231<p><strong>location</strong> <strong>=</strong> <em>layout-qualifier-value</em><br>
6232<strong>component</strong> <strong>=</strong> <em>layout-qualifier-value</em></p>
6233</dd>
6234</dl>
6235</div>
6236</div>
6237</div>
6238<div class="paragraph">
6239<p>For example,</p>
6240</div>
6241<div class="listingblock">
6242<div class="content">
6243<pre class="CodeRay highlight"><code data-lang="c++">layout(location = <span class="integer">3</span>) in vec4 normal;
6244<span class="directive">const</span> <span class="predefined-type">int</span> start = <span class="integer">6</span>;
6245layout(location = start + <span class="integer">2</span>) <span class="predefined-type">int</span> vec4 v;</code></pre>
6246</div>
6247</div>
6248<div class="paragraph">
6249<p>will establish that the shader input <em>normal</em> is assigned to vector location
6250number
62513 and <em>v</em> is assigned location number 8.
6252For vertex shader inputs, the location specifies the number of the
6253vertex attribute from which input values are taken.
6254For inputs of all other shader types, the location specifies a vector number
6255that can be used to match against outputs from a previous shader stage, even
6256if that shader is in a different program object.</p>
6257</div>
6258<div class="paragraph">
6259<p>The following language describes how many locations are consumed by a given
6260type.
6261However, geometry shader inputs, tessellation control shader inputs and
6262outputs, and tessellation evaluation inputs all have an additional level of
6263arrayness relative to other shader inputs and outputs.
6264This outer array level is removed from the type before considering how many
6265locations the type consumes.</p>
6266</div>
6267<div class="paragraph">
6268<p>Except when targeting Vulkan,
6269if a vertex shader input is any scalar or vector type, it will consume a
6270single location.
6271If a non-vertex shader input, or any stage input when targeting Vulkan,
6272is a scalar or vector type other than <strong>dvec3</strong>
6273or <strong>dvec4</strong>, it will consume a single location, while types <strong>dvec3</strong> or
6274<strong>dvec4</strong> will consume two consecutive locations.
6275Inputs of type <strong>double</strong> and <strong>dvec2</strong> will consume only a single location, in
6276all stages.</p>
6277</div>
6278<div class="paragraph">
6279<p>If the declared input (after potentially removing an outer array level as
6280just described above) is an array of size <em>n</em> and each of the elements takes
6281<em>m</em> locations, it will be assigned <em>m</em> * <em>n</em> consecutive locations starting
6282with the location specified.
6283For example,</p>
6284</div>
6285<div class="listingblock">
6286<div class="content">
6287<pre class="CodeRay highlight"><code data-lang="c++">layout(location = <span class="integer">6</span>) in vec4 colors[<span class="integer">3</span>];</code></pre>
6288</div>
6289</div>
6290<div class="paragraph">
6291<p>will establish that the shader input <em>colors</em> is assigned to vector location
6292numbers 6, 7, and 8.</p>
6293</div>
6294<div class="paragraph">
6295<p>If the declared input is an <em>n</em> × <em>m</em>
6296matrix, it will be assigned multiple locations starting with the location
6297specified.
6298The number of locations assigned for each matrix will be the same as for an
6299<em>n</em>-element array of <em>m</em>-component vectors.
6300For example,</p>
6301</div>
6302<div class="listingblock">
6303<div class="content">
6304<pre class="CodeRay highlight"><code data-lang="c++">layout(location = <span class="integer">9</span>) in mat4 transforms[<span class="integer">2</span>];</code></pre>
6305</div>
6306</div>
6307<div class="paragraph">
6308<p>will establish that shader input <em>transforms</em> is assigned to vector
6309locations 9-16, with <em>transforms[0]</em> being assigned to locations 9-12, and
6310<em>transforms[1]</em> being assigned to locations 13-16.</p>
6311</div>
6312<div class="paragraph">
6313<p>If the declared input is a structure or block, its members will be assigned
6314consecutive locations in their order of declaration, with the first member
6315assigned the location provided in the layout qualifier.
6316For a structure, this process applies to the entire structure.
6317It is a compile-time error to use a <strong>location</strong> qualifier on a member of a
6318structure.
6319For a block, this process applies to the entire block, or until the first
6320member is reached that has a <strong>location</strong> layout qualifier.</p>
6321</div>
6322<div class="paragraph">
6323<p>When a block member is declared with a <strong>location</strong> qualifier, its location
6324comes from that qualifier; the member&#8217;s <strong>location</strong> qualifier overrides the
6325block-level declaration.
6326Subsequent members are again assigned consecutive locations, based on the
6327newest location, until the next member declared with a <strong>location</strong> qualifier.
6328The values used for locations do not have to be declared in increasing
6329order.</p>
6330</div>
6331<div class="paragraph">
6332<p>If a block has no block-level <strong>location</strong> layout qualifier, it is required
6333that either all or none of its members have a <strong>location</strong> layout qualifier,
6334or a compile-time error results.
6335For some blocks declared as arrays, the <strong>location</strong> can only be applied at
6336the block level: When a block is declared as an array where additional
6337locations are needed for each member for each block array element, it is a
6338compile-time error to specify locations on the block members.
6339That is, when locations would be under specified by applying them on block
6340members, they are not allowed on block members.
6341For <em>arrayed</em> interfaces (those generally having an extra level of arrayness
6342due to interface expansion), the outer array is stripped before applying
6343this rule.</p>
6344</div>
6345<div class="paragraph">
6346<p>When generating SPIR-V, all <strong>in</strong> and <strong>out</strong> qualified user-declared (non
6347built-in) variables and blocks (or all their members) must have a
6348shader-specified <strong>location</strong>.
6349Otherwise, a compile-time error is generated.</p>
6350</div>
6351<div class="paragraph">
6352<p>The locations consumed by block and structure members are determined by
6353applying the rules above recursively as though the structure member were
6354declared as an input variable of the same type.
6355For example:</p>
6356</div>
6357<div class="listingblock">
6358<div class="content">
6359<pre class="CodeRay highlight"><code data-lang="c++">layout(location = <span class="integer">3</span>) in <span class="keyword">struct</span> S
6360{
6361    vec3 a;                      <span class="comment">// gets location 3</span>
6362    mat2 b;                      <span class="comment">// gets locations 4 and 5</span>
6363    vec4 c[<span class="integer">2</span>];                   <span class="comment">// gets locations 6 and 7</span>
6364    layout(location = <span class="integer">8</span>) vec2 A; <span class="comment">// ERROR, can't use on struct member</span>
6365} s;
6366layout(location = <span class="integer">4</span>) in block
6367{
6368    vec4 d;                      <span class="comment">// gets location 4</span>
6369    vec4 e;                      <span class="comment">// gets location 5</span>
6370    layout(location = <span class="integer">7</span>) vec4 f; <span class="comment">// gets location 7</span>
6371    vec4 g;                      <span class="comment">// gets location 8</span>
6372    layout(location = <span class="integer">1</span>) vec4 h; <span class="comment">// gets location 1</span>
6373    vec4 i;                      <span class="comment">// gets location 2</span>
6374    vec4 j;                      <span class="comment">// gets location 3</span>
6375    vec4 k;                      <span class="comment">// ERROR, location 4 already used</span>
6376};</code></pre>
6377</div>
6378</div>
6379<div class="paragraph">
6380<p>The number of input locations available to a shader is limited.
6381For vertex shaders, the limit is the advertised number of vertex attributes.
6382For all other shaders, the limit is implementation-dependent and must be no
6383less than one fourth of the advertised maximum input component count.</p>
6384</div>
6385<div class="paragraph">
6386<p>A program will fail to link if any attached shader uses a location greater
6387than or equal to the number of supported locations, unless device-dependent
6388optimizations are able to make the program fit within available hardware
6389resources.</p>
6390</div>
6391<div class="paragraph">
6392<p>A program will fail to link if explicit location assignments leave the
6393linker unable to find space for other variables without explicit
6394assignments.</p>
6395</div>
6396<div class="paragraph">
6397<p>For the purposes of determining if a non-vertex input matches an output from
6398a previous shader stage, the <strong>location</strong> layout qualifier (if any) must
6399match.</p>
6400</div>
6401<div class="paragraph">
6402<p>If a vertex shader input variable with no location assigned in the shader
6403text has a location specified through the OpenGL API, the API-assigned
6404location will be used.
6405Otherwise, such variables will be assigned a location by the linker.
6406See section 11.1.1 &#8220;Vertex Attributes&#8221; of the <a href="#references">OpenGL Specification</a> for
6407more details.
6408A link-time error will occur if an input variable is declared in multiple
6409shaders of the same language with conflicting locations.</p>
6410</div>
6411<div class="paragraph">
6412<p>The <strong>component</strong> qualifier allows the location to be more finely specified
6413for scalars and vectors, down to the individual components within a location
6414that are consumed.
6415It is a compile-time error to use <strong>component</strong> without also specifying the
6416<strong>location</strong> qualifier (order does not matter).
6417The components within a location are 0, 1, 2, and 3.
6418A variable or block member starting at component <em>N</em> will consume components
6419<em>N</em>, <em>N+1</em>, <em>N+2</em>, &#8230;&#8203;
6420up through its size.
6421It is a compile-time error if this sequence of components gets larger than
64223.
6423A scalar <strong>double</strong> will consume two of these components, and a <strong>dvec2</strong> will
6424consume all four components available within a location.
6425A <strong>dvec3</strong> or <strong>dvec4</strong> can only be declared without specifying a <strong>component</strong>.
6426A <strong>dvec3</strong> will consume all four components of the first location and
6427components 0 and 1 of the second location.
6428This leaves components 2 and 3 available for other component-qualified
6429declarations.</p>
6430</div>
6431<div class="paragraph">
6432<p>For example:</p>
6433</div>
6434<div class="listingblock">
6435<div class="content">
6436<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">// a consumes components 2 and 3 of location 4</span>
6437layout(location = <span class="integer">4</span>, component = <span class="integer">2</span>) in vec2 a;
6438
6439<span class="comment">// b consumes component 1 of location 4</span>
6440layout(location = <span class="integer">4</span>, component = <span class="integer">1</span>) in <span class="predefined-type">float</span> b;
6441
6442<span class="comment">// ERROR: c overflows component 3</span>
6443layout(location = <span class="integer">3</span>, component = <span class="integer">2</span>) in vec3 c;
6444
6445<span class="comment">// d consumes components 2 and 3 of location 5</span>
6446layout(location = <span class="integer">5</span>, component = <span class="integer">2</span>) in <span class="predefined-type">double</span> d;
6447
6448<span class="comment">// ERROR: e overflows component 3 of location 6</span>
6449layout(location = <span class="integer">6</span>, component = <span class="integer">2</span>) in dvec2 e;
6450
6451<span class="comment">// ERROR: f overlaps with g</span>
6452layout(location = <span class="integer">7</span>, component = <span class="integer">0</span>) <span class="predefined-type">double</span> f;
6453layout(location = <span class="integer">7</span>, component = <span class="integer">1</span>) <span class="predefined-type">float</span> g;
6454
6455layout(location = <span class="integer">8</span>) in dvec3 h; <span class="comment">// components 0,1,2 and 3 of location 8</span>
6456                                 <span class="comment">// and components 0 and 1 of location 9</span>
6457layout(location = <span class="integer">9</span>, component = <span class="integer">2</span>) in <span class="predefined-type">float</span> i; <span class="comment">// okay, compts 2 and 3</span></code></pre>
6458</div>
6459</div>
6460<div class="paragraph">
6461<p>If the variable is an array, each element of the array, in order, is
6462assigned to consecutive locations, but all at the same specified component
6463within each location.
6464For example:</p>
6465</div>
6466<div class="listingblock">
6467<div class="content">
6468<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">// component 3 in 6 locations are consumed</span>
6469layout(location = <span class="integer">2</span>, component = <span class="integer">3</span>) in <span class="predefined-type">float</span> d[<span class="integer">6</span>];</code></pre>
6470</div>
6471</div>
6472<div class="paragraph">
6473<p>That is, location 2 component 3 will hold <em>d[0]</em>, location 3 component 3
6474will hold <em>d[1]</em>, &#8230;&#8203;, up through location 7 component 3 holding <em>d[5]</em>.</p>
6475</div>
6476<div class="paragraph">
6477<p>This allows packing of two arrays into the same set of locations:</p>
6478</div>
6479<div class="listingblock">
6480<div class="content">
6481<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">// e consumes beginning (components 0, 1 and 2) of each of 6 slots</span>
6482layout(location = <span class="integer">0</span>, component = <span class="integer">0</span>) in vec3 e[<span class="integer">6</span>];
6483
6484<span class="comment">// f consumes last component of the same 6 slots</span>
6485layout(location = <span class="integer">0</span>, component = <span class="integer">3</span>) in <span class="predefined-type">float</span> f[<span class="integer">6</span>];</code></pre>
6486</div>
6487</div>
6488<div class="paragraph">
6489<p>If applying this to an array of arrays, all levels of arrayness are removed
6490to get to the elements that are assigned per location to the specified
6491component.
6492These non-arrayed elements will fill the locations in the order specified
6493for arrays of arrays in &#8220;<a href="#arrays">Arrays</a>&#8221;.</p>
6494</div>
6495<div class="paragraph">
6496<p>It is a compile-time error to apply the <strong>component</strong> qualifier to a matrix, a
6497structure, a block, or an array containing any of these.
6498It is a compile-time error to use <strong>component</strong> 1 or 3 as the beginning of a
6499<strong>double</strong> or <strong>dvec2</strong>.
6500It is a link-time error to specify different components for the same
6501variable within a program.</p>
6502</div>
6503<div class="paragraph">
6504<p><em>Location aliasing</em> is causing two variables or block members to have the
6505same location number.
6506<em>Component aliasing</em> is assigning the same (or overlapping) component
6507numbers for two location aliases.
6508(Recall if <strong>component</strong> is not used, components are assigned starting with
65090.)
6510With one exception, location aliasing is allowed only if it does not
6511cause component aliasing; it is a compile-time or link-time error to cause
6512component aliasing.
6513Further, when location aliasing, the aliases sharing the location must have
6514the same underlying numerical type and bit width  (floating-point or integer,
651532-bit versus 64-bit, etc.) and the same
6516auxiliary storage and interpolation qualification.
6517The one exception where component aliasing is permitted is
6518when targeting OpenGL for two input
6519variables (not block members) to a vertex shader, which are allowed to have
6520component aliasing.
6521This vertex-variable component aliasing is intended only to support vertex
6522shaders where each execution path accesses at most one input per each
6523aliased component.
6524Implementations are permitted, but not required, to generate link-time
6525errors if they detect that every path through the vertex shader executable
6526accesses multiple inputs aliased to any single component.</p>
6527</div>
6528<div class="sect4">
6529<h5 id="tessellation-evaluation-inputs">Tessellation Evaluation Inputs</h5>
6530<div class="paragraph">
6531<p>Additional input layout qualifier identifiers allowed for tessellation
6532evaluation shaders are described below.</p>
6533</div>
6534<div class="openblock bnf">
6535<div class="content">
6536<div class="dlist">
6537<dl>
6538<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
6539<dd>
6540<p><em>primitive_mode</em><br>
6541<em>vertex_spacing</em><br>
6542<em>ordering</em><br>
6543<em>point_mode</em></p>
6544</dd>
6545</dl>
6546</div>
6547</div>
6548</div>
6549<div class="paragraph">
6550<p>The <strong>primitive-mode</strong> is used to specify a tessellation primitive mode to be
6551used by the tessellation primitive generator.</p>
6552</div>
6553<div class="openblock bnf">
6554<div class="content">
6555<div class="dlist">
6556<dl>
6557<dt class="hdlist1"><em>primitive-mode</em>: </dt>
6558<dd>
6559<p><strong>triangles</strong><br>
6560<strong>quads</strong><br>
6561<strong>isolines</strong></p>
6562</dd>
6563</dl>
6564</div>
6565</div>
6566</div>
6567<div class="paragraph">
6568<p>If present, the <em>primitive-mode</em> specifies that the tessellation primitive
6569generator should subdivide a triangle into smaller triangles, a quad into
6570triangles, or a quad into a collection of lines, respectively.</p>
6571</div>
6572<div class="paragraph">
6573<p>A second group of layout identifiers, <em>vertex spacing</em>, is used to specify
6574the spacing used by the tessellation primitive generator when subdividing an
6575edge.</p>
6576</div>
6577<div class="openblock bnf">
6578<div class="content">
6579<div class="dlist">
6580<dl>
6581<dt class="hdlist1"><em>vertex-spacing</em>: </dt>
6582<dd>
6583<p><strong>equal_spacing</strong><br>
6584<strong>fractional_even_spacing</strong><br>
6585<strong>fractional_odd_spacing</strong></p>
6586</dd>
6587</dl>
6588</div>
6589</div>
6590</div>
6591<div class="paragraph">
6592<p><strong>equal_spacing</strong> specifies that edges should be divided into a collection of
6593equal-sized segments;</p>
6594</div>
6595<div class="paragraph">
6596<p><strong>fractional_even_spacing</strong> specifies that edges should be divided into an
6597even number of equal-length segments plus two additional shorter
6598&#8220;fractional&#8221; segments; or</p>
6599</div>
6600<div class="paragraph">
6601<p><strong>fractional_odd_spacing</strong> specifies that edges should be divided into an odd
6602number of equal-length segments plus two additional shorter &#8220;fractional&#8221;
6603segments.</p>
6604</div>
6605<div class="paragraph">
6606<p>A third group of layout identifiers, <em>ordering</em>, specifies whether the
6607tessellation primitive generator produces triangles in clockwise or
6608counter-clockwise order, according to the coordinate system depicted in the
6609<a href="#references">OpenGL Specification</a>.</p>
6610</div>
6611<div class="openblock bnf">
6612<div class="content">
6613<div class="dlist">
6614<dl>
6615<dt class="hdlist1"><em>ordering</em>: </dt>
6616<dd>
6617<p><strong>cw</strong><br>
6618<strong>ccw</strong></p>
6619</dd>
6620</dl>
6621</div>
6622</div>
6623</div>
6624<div class="paragraph">
6625<p>The identifiers <strong>cw</strong> and <strong>ccw</strong> indicate clockwise and counter-clockwise
6626triangles, respectively.
6627If the tessellation primitive generator does not produce triangles, the
6628order is ignored.</p>
6629</div>
6630<div class="paragraph">
6631<p>Finally, <em>point mode</em> indicates that the tessellation primitive generator
6632should produce one point for each distinct vertex in the subdivided
6633primitive, rather than generating lines or triangles.</p>
6634</div>
6635<div class="openblock bnf">
6636<div class="content">
6637<div class="dlist">
6638<dl>
6639<dt class="hdlist1"><em>point-mode</em>: </dt>
6640<dd>
6641<p><strong>point_mode</strong></p>
6642</dd>
6643</dl>
6644</div>
6645</div>
6646</div>
6647<div class="paragraph">
6648<p>Any or all of these identifiers may be specified one or more times in a
6649single input layout declaration.
6650If primitive mode, vertex spacing, or ordering is declared more than once in
6651the tessellation evaluation shaders of a program, all such declarations must
6652use the same identifier.</p>
6653</div>
6654<div class="paragraph">
6655<p>At least one tessellation evaluation shader (compilation unit) in a program
6656must declare a primitive mode in its input layout.
6657Declaring vertex spacing, ordering, or point mode identifiers is optional.
6658It is not required that all tessellation evaluation shaders in a program
6659declare a primitive mode.
6660If spacing or vertex ordering declarations are omitted, the tessellation
6661primitive generator will use equal spacing or counter-clockwise vertex
6662ordering, respectively.
6663If a point mode declaration is omitted, the tessellation primitive generator
6664will produce lines or triangles according to the primitive mode.</p>
6665</div>
6666</div>
6667<div class="sect4">
6668<h5 id="geometry-shader-inputs">Geometry Shader Inputs</h5>
6669<div class="paragraph">
6670<p>Additional layout qualifier identifiers for geometry shader inputs include
6671<em>primitive</em> identifiers and an <em>invocation count</em> identifier:</p>
6672</div>
6673<div class="openblock bnf">
6674<div class="content">
6675<div class="dlist">
6676<dl>
6677<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
6678<dd>
6679<p><strong>points</strong><br>
6680<strong>lines</strong><br>
6681<strong>lines_adjacency</strong><br>
6682<strong>triangles</strong><br>
6683<strong>triangles_adjacency</strong><br>
6684<strong>invocations</strong> <strong>=</strong> <em>layout-qualifier-value</em></p>
6685</dd>
6686</dl>
6687</div>
6688</div>
6689</div>
6690<div class="paragraph">
6691<p>The identifiers <strong>points</strong>, <strong>lines</strong>, <strong>lines_adjacency</strong>, <strong>triangles</strong>, and
6692<strong>triangles_adjacency</strong> are used to specify the type of input primitive
6693accepted by the geometry shader, and only one of these is accepted.
6694At least one geometry shader (compilation unit) in a program must declare
6695this input primitive layout, and all geometry shader input layout
6696declarations in a program must declare the same layout.
6697It is not required that all geometry shaders in a program declare an input
6698primitive layout.</p>
6699</div>
6700<div class="paragraph">
6701<p>The identifier <strong>invocations</strong> is used to specify the number of times the
6702geometry shader executable is invoked for each input primitive received.
6703Invocation count declarations are optional.
6704If no invocation count is declared in any geometry shader in a program, the
6705geometry shader will be run once for each input primitive.
6706If an invocation count is declared, all such declarations must specify the
6707same count.
6708If a shader specifies an invocation count greater than the
6709implementation-dependent maximum, or less than or equal to zero,
6710a compile-time error results.</p>
6711</div>
6712<div class="paragraph">
6713<p>For example,</p>
6714</div>
6715<div class="listingblock">
6716<div class="content">
6717<pre class="CodeRay highlight"><code data-lang="c++">layout(triangles, invocations = <span class="integer">6</span>) in;</code></pre>
6718</div>
6719</div>
6720<div class="paragraph">
6721<p>will establish that all inputs to the geometry shader are triangles and that
6722the geometry shader executable is run six times for each triangle processed.</p>
6723</div>
6724<div class="paragraph">
6725<p>All geometry shader input unsized array declarations will be sized by an
6726earlier input primitive layout qualifier, when present, as per the following
6727table.</p>
6728</div>
6729<table class="tableblock frame-all grid-all stretch">
6730<colgroup>
6731<col style="width: 50%;">
6732<col style="width: 50%;">
6733</colgroup>
6734<thead>
6735<tr>
6736<th class="tableblock halign-left valign-top">Layout</th>
6737<th class="tableblock halign-left valign-top">Size of Input Arrays</th>
6738</tr>
6739</thead>
6740<tbody>
6741<tr>
6742<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>points</strong></p></td>
6743<td class="tableblock halign-left valign-top"><p class="tableblock">1</p></td>
6744</tr>
6745<tr>
6746<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>lines</strong></p></td>
6747<td class="tableblock halign-left valign-top"><p class="tableblock">2</p></td>
6748</tr>
6749<tr>
6750<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>lines_adjacency</strong></p></td>
6751<td class="tableblock halign-left valign-top"><p class="tableblock">4</p></td>
6752</tr>
6753<tr>
6754<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>triangles</strong></p></td>
6755<td class="tableblock halign-left valign-top"><p class="tableblock">3</p></td>
6756</tr>
6757<tr>
6758<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>triangles_adjacency</strong></p></td>
6759<td class="tableblock halign-left valign-top"><p class="tableblock">6</p></td>
6760</tr>
6761</tbody>
6762</table>
6763<div class="paragraph">
6764<p>The intrinsically declared input array <em>gl_in[]</em> will also be sized by any
6765input primitive-layout declaration.
6766Hence, the expression</p>
6767</div>
6768<div class="listingblock">
6769<div class="content">
6770<pre class="CodeRay highlight"><code data-lang="c++">gl_in.length()</code></pre>
6771</div>
6772</div>
6773<div class="paragraph">
6774<p>will return the value from the table above.</p>
6775</div>
6776<div class="paragraph">
6777<p>For inputs declared without an array size, including intrinsically declared
6778inputs (i.e., <em>gl_in</em>), a layout must be declared before any use of the
6779method <strong>length</strong>() or other any array use that requires the array size to be
6780known.</p>
6781</div>
6782<div class="paragraph">
6783<p>It is a compile-time error if a layout declaration&#8217;s array size (from the
6784table above) does not match all the explicit array sizes specified in
6785declarations of an input variables in the same shader.
6786The following includes examples of compile-time errors:</p>
6787</div>
6788<div class="listingblock">
6789<div class="content">
6790<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">// code sequence within one shader...</span>
6791in vec4 Color1[];     <span class="comment">// legal, size still unknown</span>
6792in vec4 Color2[<span class="integer">2</span>];    <span class="comment">// legal, size is 2</span>
6793in vec4 Color3[<span class="integer">3</span>];    <span class="comment">// illegal, input sizes are inconsistent</span>
6794layout(lines) in;     <span class="comment">// legal for Color2, input size is 2, matching Color2</span>
6795in vec4 Color4[<span class="integer">3</span>];    <span class="comment">// illegal, contradicts layout of lines</span>
6796layout(lines) in;     <span class="comment">// legal, matches other layout() declaration</span>
6797layout(triangles) in; <span class="comment">// illegal, does not match earlier layout() declaration</span></code></pre>
6798</div>
6799</div>
6800<div class="paragraph">
6801<p>It is a link-time error if not all provided sizes (sized input arrays and
6802layout size) match across all geometry shaders in a program.</p>
6803</div>
6804</div>
6805<div class="sect4">
6806<h5 id="fragment-shader-inputs">Fragment Shader Inputs</h5>
6807<div class="paragraph">
6808<p>Additional fragment layout qualifier identifiers include the following for
6809<em>gl_FragCoord</em> :</p>
6810</div>
6811<div class="openblock bnf">
6812<div class="content">
6813<div class="dlist">
6814<dl>
6815<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
6816<dd>
6817<p><strong>origin_upper_left</strong><br>
6818<strong>pixel_center_integer</strong></p>
6819</dd>
6820</dl>
6821</div>
6822</div>
6823</div>
6824<div class="paragraph">
6825<p>By default, <em>gl_FragCoord</em> in OpenGL assumes a lower-left origin for window
6826coordinates and assumes pixel centers are located at half-pixel coordinates.
6827For example, the (<em>x, y</em>) location (0.5, 0.5) is returned for the
6828lower-left-most pixel in a window.
6829The origin can be changed by redeclaring <em>gl_FragCoord</em> with the
6830<strong>origin_upper_left</strong> qualifier, moving the origin of <em>gl_FragCoord</em> to the
6831upper left of the window, with <em>y</em> increasing in value toward the bottom of
6832the window.
6833The values returned can also be shifted by half a pixel in both <em>x</em> and <em>y</em>
6834by <strong>pixel_center_integer</strong> so it appears the pixels are centered at whole
6835number pixel offsets.
6836This moves the (<em>x</em>, <em>y</em>) value returned by <em>gl_FragCoord</em> of (0.5, 0.5) by
6837default, to (0.0, 0.0) with <strong>pixel_center_integer</strong>.</p>
6838</div>
6839<div class="paragraph">
6840<p>Targeting Vulkan will assume and require an upper-left origin for <em>gl_FragCoord</em>
6841with pixel centers located at half-pixel coordinates.
6842This origin can be explicitly set by redeclaring <em>gl_FragCoord</em> with the
6843<strong>origin_upper_left</strong> identifier.</p>
6844</div>
6845<div class="paragraph">
6846<p>Redeclarations are done as follows</p>
6847</div>
6848<div class="listingblock">
6849<div class="content">
6850<pre class="CodeRay highlight"><code data-lang="c++">in vec4 gl_FragCoord; <span class="comment">// redeclaration that changes nothing is allowed</span>
6851
6852<span class="comment">// All the following are allowed redeclaration that change behavior</span>
6853layout(origin_upper_left) in vec4 gl_FragCoord;
6854layout(pixel_center_integer) in vec4 gl_FragCoord;
6855layout(origin_upper_left, pixel_center_integer) in vec4 gl_FragCoord;</code></pre>
6856</div>
6857</div>
6858<div class="paragraph">
6859<p>If <em>gl_FragCoord</em> is redeclared in any fragment shader in a program, it must
6860be redeclared in all the fragment shaders in that program that have a static
6861use <em>gl_FragCoord</em>.
6862All redeclarations of <em>gl_FragCoord in all fragment shaders in a single
6863program must have the same set of qualifiers.
6864Within any shader, the first redeclarations of _glFragCoord</em> must appear
6865before any use of <em>gl_FragCoord</em>.
6866The built-in <em>gl_FragCoord</em> is only predeclared in fragment shaders, so
6867redeclaring it in any other shader language results in a compile-time error.</p>
6868</div>
6869<div class="paragraph">
6870<p>Redeclaring <em>glFragCoord</em> with <strong>origin_upper_left</strong> and/or
6871<strong>pixel_center_integer</strong> qualifiers only affects <em>gl_FragCoord.x</em> and
6872<em>gl_FragCoord.y</em>.
6873It has no effect on rasterization, transformation, or any other part of the
6874API pipeline or language features.</p>
6875</div>
6876<div class="paragraph">
6877<p>Fragment shaders allow the following layout qualifier on <strong>in</strong> only (not with
6878variable declarations):</p>
6879</div>
6880<div class="openblock bnf">
6881<div class="content">
6882<div class="dlist">
6883<dl>
6884<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
6885<dd>
6886<p><strong>early_fragment_tests</strong></p>
6887</dd>
6888</dl>
6889</div>
6890</div>
6891</div>
6892<div class="paragraph">
6893<p>to request that fragment tests be performed before fragment shader
6894execution, as described in section 15.2.4 &#8220;Early Fragment Tests&#8221; of the
6895<a href="#references">OpenGL Specification</a>.</p>
6896</div>
6897<div class="paragraph">
6898<p>For example,</p>
6899</div>
6900<div class="listingblock">
6901<div class="content">
6902<pre class="CodeRay highlight"><code data-lang="c++">layout(early_fragment_tests) in;</code></pre>
6903</div>
6904</div>
6905<div class="paragraph">
6906<p>Specifying this will make per-fragment tests be performed before fragment
6907shader execution.
6908If this is not declared, per-fragment tests will be performed after fragment
6909shader execution.
6910Only one fragment shader (compilation unit) need declare this, though more
6911than one can.
6912If at least one declares this, then it is enabled.</p>
6913</div>
6914</div>
6915<div class="sect4">
6916<h5 id="compute-shader-inputs">Compute Shader Inputs</h5>
6917<div class="paragraph">
6918<p>There are no layout location qualifiers for compute shader inputs.</p>
6919</div>
6920<div class="paragraph">
6921<p>Layout qualifier identifiers for compute shader inputs are the workgroup
6922size qualifiers:</p>
6923</div>
6924<div class="openblock bnf">
6925<div class="content">
6926<div class="dlist">
6927<dl>
6928<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
6929<dd>
6930<p><strong>local_size_x</strong> <strong>=</strong> <em>layout-qualifier-value</em><br>
6931<strong>local_size_y</strong> <strong>=</strong> <em>layout-qualifier-value</em><br>
6932<strong>local_size_z</strong> <strong>=</strong> <em>layout-qualifier-value</em></p>
6933</dd>
6934</dl>
6935</div>
6936</div>
6937</div>
6938<div class="paragraph">
6939<p>The <strong>local_size_x</strong>, <strong>local_size_y</strong>, and <strong>local_size_z</strong> qualifiers are used
6940to declare a fixed workgroup size by the compute shader in the first,
6941second, and third dimension, respectively.
6942If a shader does not specify a size for one of the dimensions, that
6943dimension will have a size of 1.</p>
6944</div>
6945<div class="paragraph">
6946<p>For example, the following declaration in a compute shader</p>
6947</div>
6948<div class="listingblock">
6949<div class="content">
6950<pre class="CodeRay highlight"><code data-lang="c++">layout(local_size_x = <span class="integer">32</span>, local_size_y = <span class="integer">32</span>) in;</code></pre>
6951</div>
6952</div>
6953<div class="paragraph">
6954<p>is used to declare a two-dimensional compute shader with a workgroup size of 32
6955X 32 elements, which is equivalent to a three-dimensional compute shader
6956where the third dimension has size one.</p>
6957</div>
6958<div class="paragraph">
6959<p>As another example, the declaration</p>
6960</div>
6961<div class="listingblock">
6962<div class="content">
6963<pre class="CodeRay highlight"><code data-lang="c++">layout(local_size_x = <span class="integer">8</span>) in;</code></pre>
6964</div>
6965</div>
6966<div class="paragraph">
6967<p>effectively specifies that a one-dimensional compute shader is being
6968compiled, and its size is 8 elements.</p>
6969</div>
6970<div class="paragraph">
6971<p>If the fixed workgroup size of the shader in any dimension is less than
6972or equal to zero or greater than the maximum size supported by the
6973implementation for that dimension, a compile-time error results.
6974Also, if such a layout qualifier is declared more than once in the same
6975shader, all those declarations must set the same set of workgroup
6976sizes and set them to the same values; otherwise a compile-time error
6977results.
6978If multiple compute shaders attached to a single program object declare a
6979fixed workgroup size, the declarations must be identical; otherwise a
6980link-time error results.</p>
6981</div>
6982<div class="paragraph">
6983<p>Furthermore, if a program object contains any compute shaders, at least one
6984must contain an input layout qualifier specifying a fixed workgroup size
6985for the program, or a link-time error will occur.</p>
6986</div>
6987</div>
6988</div>
6989<div class="sect3">
6990<h4 id="output-layout-qualifiers">4.4.2. Output Layout Qualifiers</h4>
6991<div class="paragraph">
6992<p>Some output layout qualifiers apply to all shader stages and some apply only
6993to specific stages.
6994The latter are discussed in separate sections below.</p>
6995</div>
6996<div class="paragraph">
6997<p>As with input layout qualifiers, all shaders except compute shaders allow
6998<strong>location</strong> layout qualifiers on output variable declarations, output block
6999declarations, and output block member declarations.
7000Of these, variables and block members (but not blocks) additionally allow
7001the <strong>component</strong> layout qualifier.</p>
7002</div>
7003<div class="openblock bnf">
7004<div class="content">
7005<div class="dlist">
7006<dl>
7007<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
7008<dd>
7009<p><strong>location</strong> <strong>=</strong> <em>layout-qualifier-value</em><br>
7010<strong>component</strong> <strong>=</strong> <em>layout-qualifier-value</em></p>
7011</dd>
7012</dl>
7013</div>
7014</div>
7015</div>
7016<div class="paragraph">
7017<p>The usage and rules for applying the <strong>location</strong> qualifier
7018and the <strong>component</strong> qualifier
7019to blocks and structures are exactly as described in
7020&#8220;<a href="#input-layout-qualifiers">Input Layout Qualifiers</a>&#8221;.
7021Additionally, for fragment shader outputs, if two variables are placed
7022within the same location, they must have the same underlying type
7023(floating-point or integer).
7024No component aliasing of output variables or members is allowed.</p>
7025</div>
7026<div class="paragraph">
7027<p>Fragment shaders allow an additional <strong>index</strong> output layout qualifier:</p>
7028</div>
7029<div class="openblock bnf">
7030<div class="content">
7031<div class="dlist">
7032<dl>
7033<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
7034<dd>
7035<p><strong>index</strong> <strong>=</strong> <em>layout-qualifier-value</em></p>
7036</dd>
7037</dl>
7038</div>
7039</div>
7040</div>
7041<div class="paragraph">
7042<p>Each of these qualifiers may appear at most once.
7043If <strong>index</strong> is specified, <strong>location</strong> must also be specified.
7044If <strong>index</strong> is not specified, the value 0 is used.
7045For example, in a fragment shader,</p>
7046</div>
7047<div class="listingblock">
7048<div class="content">
7049<pre class="CodeRay highlight"><code data-lang="c++">layout(location = <span class="integer">3</span>) out vec4 color;</code></pre>
7050</div>
7051</div>
7052<div class="paragraph">
7053<p>will establish that the fragment shader output <em>color</em> is assigned to
7054fragment color 3 as the first (index zero) input to the blend equation.
7055And,</p>
7056</div>
7057<div class="listingblock">
7058<div class="content">
7059<pre class="CodeRay highlight"><code data-lang="c++">layout(location = <span class="integer">3</span>, index = <span class="integer">1</span>) out vec4 factor;</code></pre>
7060</div>
7061</div>
7062<div class="paragraph">
7063<p>will establish that the fragment shader output <em>factor</em> is assigned to
7064fragment color 3 as the second (index one) input to the blend equation.</p>
7065</div>
7066<div class="paragraph">
7067<p>For fragment shader outputs, the location
7068and index specify
7069the color output number
7070and index
7071receiving the values of the output.
7072For outputs of all other shader stages, the location specifies a vector
7073number that can be used to match against inputs in a subsequent shader
7074stage, even if that shader is in a different program object.</p>
7075</div>
7076<div class="paragraph">
7077<p>If a declared output is a scalar or vector type other than <strong>dvec3</strong> or
7078<strong>dvec4</strong>, it will consume a single location.
7079Outputs of type <strong>dvec3</strong> or <strong>dvec4</strong> will consume two consecutive locations.
7080Outputs of type <strong>double</strong> and <strong>dvec2</strong> will consume only a single location, in
7081all stages.</p>
7082</div>
7083<div class="paragraph">
7084<p>If the declared output is an array, it will be assigned consecutive
7085locations starting with the location specified.
7086For example,</p>
7087</div>
7088<div class="listingblock">
7089<div class="content">
7090<pre class="CodeRay highlight"><code data-lang="c++">layout(location = <span class="integer">2</span>) out vec4 colors[<span class="integer">3</span>];</code></pre>
7091</div>
7092</div>
7093<div class="paragraph">
7094<p>will establish that <em>colors</em> is assigned to vector location numbers 2, 3,
7095and 4.</p>
7096</div>
7097<div class="paragraph">
7098<p>If the declared output is an <em>n</em> × <em>m</em>
7099matrix, it will be assigned multiple locations starting with the location
7100specified.
7101The number of locations assigned will be the same as for an <em>n</em>-element
7102array of <em>m</em>-component vectors.</p>
7103</div>
7104<div class="paragraph">
7105<p>If the declared output is a structure, its members will be assigned
7106consecutive locations in the order of declaration, with the first member
7107assigned the location specified for the structure.
7108The number of locations consumed by a structure member is determined by
7109applying the rules above recursively as though the structure member were
7110declared as an output variable of the same type.</p>
7111</div>
7112<div class="paragraph">
7113<p><strong>location</strong> layout qualifiers may be used on output variables declared as
7114structures.
7115However, it is a compile-time error to use a <strong>location</strong> qualifier on a
7116structure member.
7117Location layout qualifiers may be used on output blocks and output block
7118members.</p>
7119</div>
7120<div class="paragraph">
7121<p>The number of output locations available to a shader is limited.
7122For fragment shaders, the limit is the advertised number of draw buffers.</p>
7123</div>
7124<div class="paragraph">
7125<p>For all other shaders, the limit is implementation-dependent and must be no
7126less than one fourth of the advertised maximum output component count
7127(compute shaders have no outputs).
7128A program will fail to link if any attached shader uses a location greater
7129than or equal to the number of supported locations, unless device-dependent
7130optimizations are able to make the program fit within available hardware
7131resources.</p>
7132</div>
7133<div class="paragraph">
7134<p>Compile-time errors may also be given if at compile time it is known the
7135link will fail.
7136A negative output location will result in a compile-time error.
7137It is also a compile-time error if a fragment shader sets a layout index to
7138less than 0 or greater than 1.</p>
7139</div>
7140<div class="paragraph">
7141<p>It is a compile-time or link-time error if any of the following occur:</p>
7142</div>
7143<div class="ulist">
7144<ul>
7145<li>
7146<p>any two fragment shader output variables are assigned to the same
7147location and index.</p>
7148</li>
7149<li>
7150<p>if any two output variables from the same vertex, tessellation or
7151geometry shader stage are assigned to the same location.</p>
7152</li>
7153</ul>
7154</div>
7155<div class="paragraph">
7156<p>For fragment shader outputs, locations can be assigned using either a
7157<strong>layout</strong> qualifier or via the OpenGL API.</p>
7158</div>
7159<div class="paragraph">
7160<p>For all shader types, a program will fail to link if explicit location
7161assignments leave the linker unable to find space for other variables
7162without explicit assignments.</p>
7163</div>
7164<div class="paragraph">
7165<p>If an output variable with no location or index assigned in the shader text
7166has a location specified through the OpenGL API, the API-assigned
7167location will be used.
7168Otherwise, such variables will be assigned a location by the linker.
7169All such assignments will have a color index of zero.
7170See section 15.2 &#8220;Shader Execution&#8221; of the <a href="#references">OpenGL Specification</a> for
7171more details.
7172A link-time error will occur if an output variable is declared in multiple
7173shaders of the same language with conflicting location or index values.</p>
7174</div>
7175<div class="paragraph">
7176<p>For the purposes of determining if a non-fragment output matches an input
7177from a subsequent shader stage, the <strong>location</strong> layout qualifier (if any)
7178must match.</p>
7179</div>
7180<div class="sect4">
7181<h5 id="transform-feedback-layout-qualifiers">Transform Feedback Layout Qualifiers</h5>
7182<div class="paragraph">
7183<p>The vertex, tessellation, and geometry stages allow shaders to control
7184transform feedback.
7185When doing this, shaders will dictate which transform feedback buffers are
7186in use, which output variables will be written to which buffers, and how
7187each buffer is laid out.
7188To accomplish this, shaders allow the following layout qualifier identifiers
7189on output declarations:</p>
7190</div>
7191<div class="openblock bnf">
7192<div class="content">
7193<div class="dlist">
7194<dl>
7195<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
7196<dd>
7197<p><strong>xfb_buffer</strong> <strong>=</strong> <em>layout-qualifier-value</em><br>
7198<strong>xfb_offset</strong> <strong>=</strong> <em>layout-qualifier-value</em><br>
7199<strong>xfb_stride</strong> <strong>=</strong> <em>layout-qualifier-value</em></p>
7200</dd>
7201</dl>
7202</div>
7203</div>
7204</div>
7205<div class="paragraph">
7206<p>Any shader making any static use (after preprocessing) of any of these
7207<strong>xfb_</strong> qualifiers will cause the shader to be in a transform feedback
7208capturing mode and hence responsible for describing the transform feedback
7209setup.
7210This mode will capture any output selected by <strong>xfb_offset</strong>, directly or
7211indirectly, to a transform feedback buffer.</p>
7212</div>
7213<div class="paragraph">
7214<p>The <strong>xfb_buffer</strong> qualifier specifies which transform feedback buffer will
7215capture outputs selected with <strong>xfb_offset</strong>.
7216The <strong>xfb_buffer</strong> qualifier can be applied to the qualifier <strong>out</strong>, to output
7217variables, to output blocks, and to output block members.
7218Shaders in the transform feedback capturing mode have an initial global
7219default of</p>
7220</div>
7221<div class="listingblock">
7222<div class="content">
7223<pre class="CodeRay highlight"><code data-lang="c++">layout(xfb_buffer = <span class="integer">0</span>) out;</code></pre>
7224</div>
7225</div>
7226<div class="paragraph">
7227<p>This default can be changed by declaring a different buffer with
7228<strong>xfb_buffer</strong> on the interface qualifier <strong>out</strong>.
7229This is the only way the global default can be changed.
7230When a variable or output block is declared without an <strong>xfb_buffer</strong>
7231qualifier, it inherits the global default buffer.
7232When a variable or output block is declared with an <strong>xfb_buffer</strong> qualifier,
7233it has that declared buffer.
7234All members of a block inherit the block&#8217;s buffer.
7235A member is allowed to declare an <strong>xfb_buffer</strong>, but it must match the buffer
7236inherited from its block, or a compile-time error results.</p>
7237</div>
7238<div class="listingblock">
7239<div class="content">
7240<pre class="CodeRay highlight"><code data-lang="c++">layout(xfb_buffer=<span class="integer">2</span>, xfb_offset=<span class="integer">0</span>) out block { <span class="comment">// block's buffer is 2</span>
7241    layout(xfb_buffer = <span class="integer">2</span>) vec4 v; <span class="comment">// okay, matches the inherited 2</span>
7242    layout(xfb_buffer = <span class="integer">3</span>) vec4 u; <span class="comment">// ERROR, mismatched buffer</span>
7243    vec4 w; <span class="comment">// inherited</span>
7244};
7245layout(xfb_offset=<span class="integer">16</span>) out vec4 t;  <span class="comment">// initial default is buffer 0</span>
7246layout(xfb_buffer=<span class="integer">1</span>) out;          <span class="comment">// new global default of 1</span>
7247out block {                        <span class="comment">// block has buffer 1</span>
7248    vec4 x;                        <span class="comment">// x has buffer 1 (not captured)</span>
7249    layout(xfb_buffer = <span class="integer">1</span>) vec4 y; <span class="comment">// okay (not captured)</span>
7250    layout(xfb_buffer = <span class="integer">0</span>) vec4 z; <span class="comment">// ERROR, mismatched buffer</span>
7251};
7252layout(xfb_offset=<span class="integer">0</span>) out vec4 g;   <span class="comment">// g has buffer 1</span>
7253layout(xfb_buffer=<span class="integer">2</span>) out vec4 h;   <span class="comment">// does not change global default</span>
7254layout(xfb_offset=<span class="integer">16</span>) out vec4 j;  <span class="comment">// j has buffer 1</span></code></pre>
7255</div>
7256</div>
7257<div class="paragraph">
7258<p>Note this means all members of a block that go to a transform feedback
7259buffer will go to the same buffer.</p>
7260</div>
7261<div class="paragraph">
7262<p>When a block is declared as an array, all members of block array-element 0
7263are captured, as previously described, by the declared or inherited
7264<strong>xfb_buffer</strong>.
7265Generally, an array of size <em>N</em> of blocks is captured by <em>N</em> consecutive
7266buffers, with all members of block array-element <em>E</em> captured by buffer <em>B</em>,
7267where <em>B</em> equals the declared or inherited <strong>xfb_buffer</strong> plus <em>E</em>.</p>
7268</div>
7269<div class="paragraph">
7270<p>It is a compile-time or link-time error to specify an <strong>xfb_buffer</strong>,
7271including any additional buffers needed to capture an arrays of blocks, that
7272is less than zero or greater than or equal to the implementation-dependent
7273constant <em>gl_MaxTransformFeedbackBuffers</em>.</p>
7274</div>
7275<div class="paragraph">
7276<p>The <strong>xfb_offset</strong> qualifier assigns a byte offset within a transform feedback
7277buffer.
7278Only variables, block members, or blocks can be qualified with <strong>xfb_offset</strong>.
7279If a block is qualified with <strong>xfb_offset</strong>, all its members are assigned
7280transform feedback buffer offsets.
7281If a block is not qualified with <strong>xfb_offset</strong>, any members of that block not
7282qualified with an <strong>xfb_offset</strong> will not be assigned transform feedback
7283buffer offsets.
7284Only variables and block members that are assigned offsets will be captured
7285(thus, a proper subset of a block can be captured).
7286Each time such a variable or block member is written in a shader, the
7287written value is captured at the assigned offset.
7288If such a block member or variable is not written during a shader
7289invocation, the buffer contents at the assigned offset will be undefined.
7290Even if there are no static writes to a variable or member that is assigned
7291a transform feedback offset, the space is still allocated in the buffer and
7292still affects the stride.</p>
7293</div>
7294<div class="paragraph">
7295<p>Variables and block members qualified with <strong>xfb_offset</strong> can be scalars,
7296vectors, matrices, structures, and (sized) arrays of these.
7297The offset must be a multiple of the size of the first component of the
7298first qualified variable or block member, or a compile-time error results.
7299Further, if applied to an aggregate containing a <strong>double</strong>, the offset must
7300also be a multiple of 8, and the space taken in the buffer will be a
7301multiple of 8.
7302The given offset applies to the first component of the first member of the
7303qualified entity.
7304Then, within the qualified entity, subsequent components are each assigned,
7305in order, to the next available offset aligned to a multiple of that
7306component&#8217;s size.
7307Aggregate types are flattened down to the component level to get this
7308sequence of components.
7309It is a compile-time error to apply <strong>xfb_offset</strong> to the declaration of an
7310unsized array.</p>
7311</div>
7312<div class="paragraph">
7313<p>No aliasing in output buffers is allowed: It is a compile-time or link-time
7314error to specify variables with overlapping transform feedback offsets.</p>
7315</div>
7316<div class="paragraph">
7317<p>The <strong>xfb_stride</strong> qualifier specifies how many bytes are consumed by each
7318captured vertex.
7319It applies to the transform feedback buffer for that declaration, whether it
7320is inherited or explicitly declared.
7321It can be applied to variables, blocks, block members, or just the qualifier
7322<strong>out</strong>.
7323If the buffer is capturing any outputs with double-precision components, the
7324stride must be a multiple of 8, otherwise it must be a multiple of 4, or a
7325compile-time or link-time error results.
7326It is a compile-time or link-time error to have any <strong>xfb_offset</strong> that
7327overflows <strong>xfb_stride</strong>, whether stated on declarations before or after the
7328<strong>xfb_stride</strong>, or in different compilation units.
7329While <strong>xfb_stride</strong> can be declared multiple times for the same buffer, it is
7330a compile-time or link-time error to have different values specified for the
7331stride for the same buffer.</p>
7332</div>
7333<div class="paragraph">
7334<p>For example:</p>
7335</div>
7336<div class="listingblock">
7337<div class="content">
7338<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">// buffer 1 has 32-byte stride</span>
7339layout(xfb_buffer = <span class="integer">1</span>, xfb_stride = <span class="integer">32</span>) out;
7340
7341<span class="comment">// same as previous example; order within layout does not matter</span>
7342layout(xfb_stride = <span class="integer">32</span>, xfb_buffer = <span class="integer">1</span>) out;
7343
7344<span class="comment">// everything in this block goes to buffer 0</span>
7345layout(xfb_buffer = <span class="integer">0</span>, xfb_stride = <span class="integer">32</span>) out block1 {
7346    layout(xfb_offset = <span class="integer">0</span>) vec4 a;  <span class="comment">// a goes to byte offset 0 of buffer 0</span>
7347    layout(xfb_offset = <span class="integer">16</span>) vec4 b; <span class="comment">// b goes to offset 16 of buffer 0</span>
7348};
7349
7350layout(xfb_buffer = <span class="integer">3</span>, xfb_offset = <span class="integer">12</span>) out block2 {
7351    vec4 v;  <span class="comment">// v will be written to byte offsets 12 through 27 of buffer</span>
7352    <span class="predefined-type">float</span> u; <span class="comment">// u will be written to offset 28</span>
7353    layout(xfb_offset = <span class="integer">40</span>) vec4 w;
7354    vec4 x;  <span class="comment">// x will be written to offset 56, the next available offset</span>
7355};
7356
7357layout(xfb_buffer = <span class="integer">2</span>, xfb_stride = <span class="integer">32</span>) out block3 {
7358    layout(xfb_offset = <span class="integer">12</span>) vec3 c;
7359    layout(xfb_offset = <span class="integer">24</span>) vec3 d; <span class="comment">// ERROR, requires stride of 36</span>
7360    layout(xfb_offset = <span class="integer">0</span>) vec3 g;  <span class="comment">// okay, increasing order not required</span>
7361};</code></pre>
7362</div>
7363</div>
7364<div class="paragraph">
7365<p>When no <strong>xfb_stride</strong> is specified for a buffer, the stride of the buffer
7366will be the smallest needed to hold the variable placed at the highest
7367offset, including any required padding.
7368For example:</p>
7369</div>
7370<div class="listingblock">
7371<div class="content">
7372<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">// if there no other declarations for buffer 3, it has stride 32</span>
7373layout(xfb_buffer = <span class="integer">3</span>) out block4 {
7374    layout(xfb_offset = <span class="integer">0</span>) vec4 e;
7375    layout(xfb_offset = <span class="integer">16</span>) vec4 f;
7376};</code></pre>
7377</div>
7378</div>
7379<div class="paragraph">
7380<p>The resulting stride (implicit or explicit), when divided by 4, must be less
7381than or equal to the implementation-dependent constant
7382<em>gl_MaxTransformFeedbackInterleavedComponents</em>.</p>
7383</div>
7384</div>
7385<div class="sect4">
7386<h5 id="tessellation-control-outputs">Tessellation Control Outputs</h5>
7387<div class="paragraph">
7388<p>Other than for the transform feedback layout qualifiers, tessellation
7389control shaders allow output layout qualifiers only on the interface
7390qualifier <strong>out</strong>, not on an output block, block member, or variable
7391declaration.
7392The output layout qualifier identifiers allowed for tessellation control
7393shaders are:</p>
7394</div>
7395<div class="openblock bnf">
7396<div class="content">
7397<div class="dlist">
7398<dl>
7399<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
7400<dd>
7401<p><strong>vertices</strong> <strong>=</strong> <em>layout-qualifier-value</em></p>
7402</dd>
7403</dl>
7404</div>
7405</div>
7406</div>
7407<div class="paragraph">
7408<p>The identifier <strong>vertices</strong> specifies the number of vertices in the output
7409patch produced by the tessellation control shader, which also specifies the
7410number of times the tessellation control shader is invoked.
7411It is a compile- or link-time error for the output vertex count to be less
7412than or equal to zero, or greater than the implementation-dependent maximum
7413patch size.</p>
7414</div>
7415<div class="paragraph">
7416<p>The intrinsically declared tessellation control output array <em>gl_out[]</em> will
7417also be sized by any output layout declaration.
7418Hence, the expression</p>
7419</div>
7420<div class="listingblock">
7421<div class="content">
7422<pre class="CodeRay highlight"><code data-lang="c++">gl_out.length()</code></pre>
7423</div>
7424</div>
7425<div class="paragraph">
7426<p>will return the output patch vertex count specified in a previous output
7427layout qualifier.
7428For outputs declared without an array size, including intrinsically declared
7429outputs (i.e., <em>gl_out</em>), a layout must be declared before any use of the
7430method <strong>length</strong>() or other array use that requires its size to be known.</p>
7431</div>
7432<div class="paragraph">
7433<p>It is a compile-time error if the output patch vertex count specified in an
7434output layout qualifier does not match the array size specified in any
7435output variable declaration in the same shader.</p>
7436</div>
7437<div class="paragraph">
7438<p>All tessellation control shader layout declarations in a program must
7439specify the same output patch vertex count.
7440There must be at least one layout qualifier specifying an output patch
7441vertex count in any program containing tessellation control shaders;
7442however, such a declaration is not required in all tessellation control
7443shaders.</p>
7444</div>
7445</div>
7446<div class="sect4">
7447<h5 id="geometry-outputs">Geometry Outputs</h5>
7448<div class="paragraph">
7449<p>Geometry shaders can have three additional types of output layout
7450identifiers: an output <em>primitive type</em>, a maximum output <em>vertex count</em>,
7451and per-output <em>stream</em> numbers.
7452The primitive type and vertex count identifiers are allowed only on the
7453interface qualifier <strong>out</strong>, not on an output block, block member, or variable
7454declaration.
7455The stream identifier is allowed on the interface qualifier <strong>out</strong>, on output
7456blocks, and on variable declarations.</p>
7457</div>
7458<div class="paragraph">
7459<p>The layout qualifier identifiers for geometry shader outputs are</p>
7460</div>
7461<div class="openblock bnf">
7462<div class="content">
7463<div class="dlist">
7464<dl>
7465<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
7466<dd>
7467<p><strong>points</strong><br>
7468<strong>line_strip</strong><br>
7469<strong>triangle_strip</strong><br>
7470<strong>max_vertices</strong> <strong>=</strong> <em>layout-qualifier-value</em><br>
7471<strong>stream</strong> <strong>=</strong> <em>layout-qualifier-value</em></p>
7472</dd>
7473</dl>
7474</div>
7475</div>
7476</div>
7477<div class="paragraph">
7478<p>The primitive type identifiers <strong>points</strong>, <strong>line_strip</strong>, and <strong>triangle_strip</strong>
7479are used to specify the type of output primitive produced by the geometry
7480shader, and only one of these is accepted.
7481At least one geometry shader (compilation unit) in a program must declare an
7482output primitive type, and all geometry shader output primitive type
7483declarations in a program must declare the same primitive type.
7484It is not required that all geometry shaders in a program declare an output
7485primitive type.</p>
7486</div>
7487<div class="paragraph">
7488<p>The vertex count identifier <strong>max_vertices</strong> is used to specify the maximum
7489number of vertices the shader will ever emit in a single invocation.
7490At least one geometry shader (compilation unit) in a program must declare a
7491maximum output vertex count, and all geometry shader output vertex count
7492declarations in a program must declare the same count.
7493It is not required that all geometry shaders in a program declare a count.</p>
7494</div>
7495<div class="paragraph">
7496<p>In this example,</p>
7497</div>
7498<div class="listingblock">
7499<div class="content">
7500<pre class="CodeRay highlight"><code data-lang="c++">layout(triangle_strip, max_vertices = <span class="integer">60</span>) out; <span class="comment">// order does not matter</span>
7501layout(max_vertices = <span class="integer">60</span>) out;  <span class="comment">// redeclaration okay</span>
7502layout(triangle_strip) out;     <span class="comment">// redeclaration okay</span>
7503layout(points) out;             <span class="comment">// error, contradicts triangle_strip</span>
7504layout(max_vertices = <span class="integer">30</span>) out;  <span class="comment">// error, contradicts 60</span></code></pre>
7505</div>
7506</div>
7507<div class="paragraph">
7508<p>all outputs from the geometry shader are triangles and at most 60 vertices
7509will be emitted by the shader.
7510It is an error for the maximum number of vertices to be greater than
7511<em>gl_MaxGeometryOutputVertices</em>.</p>
7512</div>
7513<div class="paragraph">
7514<p>The identifier <strong>stream</strong> is used to specify that a geometry shader output
7515variable or block is associated with a particular vertex stream (numbered
7516beginning with zero).
7517A default stream number may be declared at global scope by qualifying
7518interface qualifier <strong>out</strong> as in this example:</p>
7519</div>
7520<div class="listingblock">
7521<div class="content">
7522<pre class="CodeRay highlight"><code data-lang="c++">layout(stream = <span class="integer">1</span>) out;</code></pre>
7523</div>
7524</div>
7525<div class="paragraph">
7526<p>The stream number specified in such a declaration replaces any previous
7527default and applies to all subsequent block and variable declarations until
7528a new default is established.
7529The initial default stream number is zero.</p>
7530</div>
7531<div class="paragraph">
7532<p>Each output block or non-block output variable is associated with a vertex
7533stream.
7534If the block or variable is declared with the stream identifier, it is
7535associated with the specified stream; otherwise, it is associated with the
7536current default stream.
7537A block member may be declared with a stream identifier, but the specified
7538stream must match the stream associated with the containing block.
7539One example:</p>
7540</div>
7541<div class="listingblock">
7542<div class="content">
7543<pre class="CodeRay highlight"><code data-lang="c++">layout(stream=<span class="integer">1</span>) out;           <span class="comment">// default is now stream 1</span>
7544out vec4 var1;                  <span class="comment">// var1 gets default stream (1)</span>
7545layout(stream=<span class="integer">2</span>) out Block1 {   <span class="comment">// &quot;Block1&quot; belongs to stream 2</span>
7546    layout(stream=<span class="integer">2</span>) vec4 var2; <span class="comment">// redundant block member stream decl</span>
7547    layout(stream=<span class="integer">3</span>) vec2 var3; <span class="comment">// ILLEGAL (must match block stream)</span>
7548    vec3 var4;                  <span class="comment">// belongs to stream 2</span>
7549};
7550layout(stream=<span class="integer">0</span>) out;           <span class="comment">// default is now stream 0</span>
7551out vec4 var5;                  <span class="comment">// var5 gets default stream (0)</span>
7552out Block2 {                    <span class="comment">// &quot;Block2&quot; gets default stream (0)</span>
7553    vec4 var6;
7554};
7555layout(stream=<span class="integer">3</span>) out vec4 var7; <span class="comment">// var7 belongs to stream 3</span></code></pre>
7556</div>
7557</div>
7558<div class="paragraph">
7559<p>Each vertex emitted by the geometry shader is assigned to a specific stream,
7560and the attributes of the emitted vertex are taken from the set of output
7561blocks and variables assigned to the targeted stream.
7562After each vertex is emitted, the values of all output variables become
7563undefined.
7564Additionally, the output variables associated with each vertex stream may
7565share storage.
7566Writing to an output variable associated with one stream may overwrite
7567output variables associated with any other stream.
7568When emitting each vertex, a geometry shader should write to all outputs
7569associated with the stream to which the vertex will be emitted and to no
7570outputs associated with any other stream.</p>
7571</div>
7572<div class="paragraph">
7573<p>If a geometry shader output block or variable is declared more than once,
7574all such declarations must associate the variable with the same vertex
7575stream.
7576If any stream declaration specifies a non-existent stream number, the shader
7577will fail to compile.</p>
7578</div>
7579<div class="paragraph">
7580<p>Built-in geometry shader outputs are always associated with vertex stream
7581zero.</p>
7582</div>
7583<div class="paragraph">
7584<p>All geometry shader output layout declarations in a program must declare the
7585same layout and same value for <strong>max_vertices</strong>.
7586If geometry shaders are in a program, there must be at least one geometry
7587output layout declaration somewhere in that
7588program, but not all geometry
7589shaders (compilation units) are required to declare it.</p>
7590</div>
7591</div>
7592<div class="sect4">
7593<h5 id="fragment-outputs">Fragment Outputs</h5>
7594<div class="paragraph">
7595<p>The built-in fragment shader variable <em>gl_FragDepth</em> may be redeclared using
7596one of the following layout qualifiers.</p>
7597</div>
7598<div class="openblock bnf">
7599<div class="content">
7600<div class="dlist">
7601<dl>
7602<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
7603<dd>
7604<p><strong>depth_any</strong><br>
7605<strong>depth_greater</strong><br>
7606<strong>depth_less</strong><br>
7607<strong>depth_unchanged</strong></p>
7608</dd>
7609</dl>
7610</div>
7611</div>
7612</div>
7613<div class="paragraph">
7614<p>The layout qualifier for <em>gl_FragDepth</em> constrains intentions of the final
7615value of <em>gl_FragDepth</em> written by any shader invocation.
7616GL implementations are allowed to perform optimizations assuming that the
7617depth test fails (or passes) for a given fragment if all values of
7618<em>gl_FragDepth</em> consistent with the layout qualifier would fail (or pass).
7619This potentially includes skipping shader execution if the fragment is
7620discarded because it is occluded and the shader has no side effects.
7621If the final value of <em>gl_FragDepth</em> is inconsistent with its layout
7622qualifier, the result of the depth test for the corresponding fragment is
7623undefined.
7624However, no error will be generated in this case.
7625If the depth test passes and depth writes are enabled, the value written to
7626the depth buffer is always the value of <em>gl_FragDepth</em>, whether or not it is
7627consistent with the layout qualifier.</p>
7628</div>
7629<div class="paragraph">
7630<p>By default, <em>gl_FragDepth</em> is qualified as <em>depth_any</em>.
7631When the layout qualifier for <em>gl_FragDepth</em> is <em>depth_any</em>, the shader
7632compiler will note any assignment to <em>gl_FragDepth</em> modifying it in an
7633unknown way, and depth testing will always be performed after the shader has
7634executed.
7635When the layout qualifier is <em>depth_greater</em>, the GL can assume that the
7636final value of <em>gl_FragDepth</em> is greater than or equal to the fragment&#8217;s
7637interpolated depth value, as given by the <em>z</em> component of <em>gl_FragCoord</em>.
7638When the layout qualifier is <em>depth_less</em>, the GL can assume that any
7639modification of <em>gl_FragDepth</em> will only decrease its value.
7640When the layout qualifier is <em>depth_unchanged</em>, the shader compiler will
7641honor any modification to <em>gl_FragDepth</em>, but the rest of the GL can assume
7642that <em>gl_FragDepth</em> is not assigned a new value.</p>
7643</div>
7644<div class="paragraph">
7645<p>Redeclarations of <em>gl_FragDepth</em> are performed as follows:</p>
7646</div>
7647<div class="listingblock">
7648<div class="content">
7649<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">// redeclaration that changes nothing is allowed +</span>
7650out <span class="predefined-type">float</span> gl_FragDepth;
7651
7652<span class="comment">// assume it may be modified in any way</span>
7653layout(depth_any) out <span class="predefined-type">float</span> gl_FragDepth;
7654
7655<span class="comment">// assume it may be modified such that its value will only increase</span>
7656layout(depth_greater) out <span class="predefined-type">float</span> gl_FragDepth;
7657
7658<span class="comment">// assume it may be modified such that its value will only decrease</span>
7659layout(depth_less) out <span class="predefined-type">float</span> gl_FragDepth;
7660
7661<span class="comment">// assume it will not be modified</span>
7662layout(depth_unchanged) out <span class="predefined-type">float</span> gl_FragDepth;</code></pre>
7663</div>
7664</div>
7665<div class="paragraph">
7666<p>If <em>gl_FragDepth</em> is redeclared in any fragment shader in a program, it must
7667be redeclared in all fragment shaders in that program that have static
7668assignments to <em>gl_FragDepth</em>.
7669All redeclarations of <em>gl_FragDepth</em> in all fragment shaders in a single
7670program must have the same set of qualifiers.
7671Within any shader, the first redeclarations of <em>gl_FragDepth</em> must appear
7672before any use of <em>gl_FragDepth</em>.
7673The built-in <em>gl_FragDepth</em> is only predeclared in fragment shaders, so
7674redeclaring it in any other shader language results in a compile-time error.</p>
7675</div>
7676</div>
7677</div>
7678<div class="sect3">
7679<h4 id="uniform-variable-layout-qualifiers">4.4.3. Uniform Variable Layout Qualifiers</h4>
7680<div class="paragraph">
7681<p>Layout qualifiers can be used for uniform variables and subroutine uniforms.
7682The layout qualifier identifiers for uniform variables and subroutine
7683uniforms are:</p>
7684</div>
7685<div class="openblock bnf">
7686<div class="content">
7687<div class="dlist">
7688<dl>
7689<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
7690<dd>
7691<p><strong>location</strong> <strong>=</strong> <em>layout-qualifier-value</em></p>
7692</dd>
7693</dl>
7694</div>
7695</div>
7696</div>
7697<div class="paragraph">
7698<p>The location identifier can be used with default-block uniform variables and
7699subroutine uniforms.
7700The location specifies the location by which the API can reference
7701the uniform and update its value.
7702Individual elements of a uniform array are assigned consecutive locations
7703with the first element taking location <strong>location</strong>.
7704Default-block uniform variable declarations sharing the same location
7705linked in the program have to match by name, type, qualifiers and arrayness.
7706For arrays their array dimensionality and array sizes must match.
7707For structs this rule applies recursively to all members.
7708No two subroutine uniform variables can have the same location in the same
7709shader stage, otherwise a compile-time or link-time error will be generated.
7710Valid locations for default-block uniform variable locations are in the
7711range of 0 to the implementation-defined maximum number of uniform locations
7712minus one.
7713Valid locations for subroutine uniforms are in the range of 0 to the
7714implementation-defined per-stage maximum number of subroutine uniform
7715locations minus one.</p>
7716</div>
7717<div class="paragraph">
7718<p>Locations can be assigned to default-block uniform arrays and structures.
7719The first inner-most scalar, vector or matrix member or element takes the
7720specified <strong>location</strong> and the compiler assigns the next inner-most member or
7721element the next incremental location value.
7722Each subsequent inner-most member or element gets incremental locations for
7723the entire structure or array.
7724This rule applies to nested structures and arrays and gives each inner-most
7725scalar, vector, or matrix member a unique location.
7726For arrays without an explicit size, the size is calculated based on its
7727static usage.
7728When the linker generates locations for uniforms without an explicit
7729location, it assumes for all uniforms with an explicit location all their
7730array elements and structure members are used and the linker will not
7731generate a conflicting location, even if that element or member is deemed
7732unused.</p>
7733</div>
7734<div class="paragraph">
7735<p>When generating SPIR-V for API&#8217;s that accept individual (default block)
7736non-opaque uniform variables, it is a compile-time error to not
7737include a location when declaring them.</p>
7738</div>
7739<div class="paragraph">
7740<p>When targeting Vulkan, the <strong>push_constant</strong> qualifier is used to
7741declare an entire block, and represents a set of <em>push constants</em>, as defined
7742by the Vulkan API.
7743It is a compile-time error to apply this to anything other than a uniform block
7744declaration, or when not targeting Vulkan.
7745The values in the block will be initialized as per the Vulkan API specification.
7746A block declared with <code>layout(push_constant)</code> may optionally include an
7747<em>instance-name</em>.
7748There can be only one <strong>push_constant</strong> block per stage, or a compile-time or
7749link-time error will result.
7750A push-constant array can only be indexed with dynamically uniform indices.
7751Uniform blocks declared with <strong>push_constant</strong> use different resources
7752than those without; and are accounted for separately.</p>
7753</div>
7754</div>
7755<div class="sect3">
7756<h4 id="subroutine-function-layout-qualifiers">4.4.4. Subroutine Function Layout Qualifiers</h4>
7757<div class="paragraph">
7758<p>Layout qualifiers can be used for subroutine functions.
7759The layout qualifier identifiers for subroutine functions are:</p>
7760</div>
7761<div class="openblock bnf">
7762<div class="content">
7763<div class="dlist">
7764<dl>
7765<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
7766<dd>
7767<p><strong>index</strong> <strong>=</strong> <em>layout-qualifier-value</em></p>
7768</dd>
7769</dl>
7770</div>
7771</div>
7772</div>
7773<div class="paragraph">
7774<p>Each subroutine with an index qualifier in the shader must be given a unique
7775index, otherwise a compile- or link-time error will be generated.
7776The indices must be in the range of 0 to the implementation defined maximum
7777number of subroutines minus one.
7778It is recommended, but not required, that the shader assigns a range of
7779tightly packed <em>index</em> values starting from zero so that the OpenGL
7780subroutine function enumeration API returns a non-empty name for all active
7781indices.</p>
7782</div>
7783</div>
7784<div class="sect3">
7785<h4 id="uniform-and-shader-storage-block-layout-qualifiers">4.4.5. Uniform and Shader Storage Block Layout Qualifiers</h4>
7786<div class="paragraph">
7787<p>Layout qualifiers can be used for uniform and shader storage blocks, but not
7788for non-block uniform declarations.
7789The layout qualifier identifiers (and <strong>shared</strong> keyword) for uniform and
7790shader storage blocks are:</p>
7791</div>
7792<div class="openblock bnf">
7793<div class="content">
7794<div class="dlist">
7795<dl>
7796<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
7797<dd>
7798<p><strong>shared</strong><br>
7799<strong>packed</strong><br>
7800<strong>std140</strong><br>
7801<strong>std430</strong><br>
7802<strong>row_major</strong><br>
7803<strong>column_major</strong><br>
7804<strong>binding</strong> <strong>=</strong> <em>layout-qualifier-value</em><br>
7805<strong>offset</strong> <strong>=</strong> <em>layout-qualifier-value</em><br>
7806<strong>align</strong> <strong>=</strong> <em>layout-qualifier-value</em></p>
7807</dd>
7808</dl>
7809</div>
7810</div>
7811</div>
7812<div class="paragraph">
7813<p>None of these have any semantic effect at all on the usage of the variables
7814being declared; they only describe how data is laid out in memory.
7815For example, matrix semantics are always column-based, as described in the
7816rest of this specification, no matter what layout qualifiers are being used.</p>
7817</div>
7818<div class="paragraph">
7819<p>Uniform and shader storage block layout qualifiers can be declared for
7820global scope, on a single uniform or shader storage block, or on a single
7821block member declaration.</p>
7822</div>
7823<div class="paragraph">
7824<p>Default layouts are established at global scope for uniform blocks as:</p>
7825</div>
7826<div class="listingblock">
7827<div class="content">
7828<pre class="CodeRay highlight"><code data-lang="c++">layout(layout-qualifier-id-list) uniform;</code></pre>
7829</div>
7830</div>
7831<div class="paragraph">
7832<p>and for shader storage blocks as:</p>
7833</div>
7834<div class="listingblock">
7835<div class="content">
7836<pre class="CodeRay highlight"><code data-lang="c++">layout(layout-qualifier-id-list) buffer;</code></pre>
7837</div>
7838</div>
7839<div class="paragraph">
7840<p>When this is done, the previous default qualification is first inherited and
7841then overridden as per the override rules listed below for each qualifier
7842listed in the declaration.
7843The result becomes the new default qualification scoped to subsequent
7844uniform or shader storage block definitions.</p>
7845</div>
7846<div class="paragraph">
7847<p>The initial state of compilation when generating SPIR-V is as if the
7848following were declared:</p>
7849</div>
7850<div class="listingblock">
7851<div class="content">
7852<pre class="CodeRay highlight"><code data-lang="c++">layout(std140, column_major) uniform;
7853layout(std430, column_major) buffer;</code></pre>
7854</div>
7855</div>
7856<div class="paragraph">
7857<p>However, when <strong>push_constant</strong> is declared, the default layout of the
7858buffer will be <strong>std430</strong>. There is no method to globally set this default.</p>
7859</div>
7860<div class="paragraph">
7861<p>The initial state of compilation when not generating SPIR-V is as if the
7862following were declared:</p>
7863</div>
7864<div class="listingblock">
7865<div class="content">
7866<pre class="CodeRay highlight"><code data-lang="c++">layout(shared, column_major) uniform;
7867layout(shared, column_major) buffer;</code></pre>
7868</div>
7869</div>
7870<div class="paragraph">
7871<p>Uniform and shader storage blocks can be declared with optional layout
7872qualifiers, and so can their individual member declarations.
7873Such block layout qualification is scoped only to the content of the block.
7874As with global layout declarations, block layout qualification first
7875inherits from the current default qualification and then overrides it.
7876Similarly, individual member layout qualification is scoped just to the
7877member declaration, and inherits from and overrides the block&#8217;s
7878qualification.</p>
7879</div>
7880<div class="paragraph">
7881<p>The <strong>shared</strong> qualifier overrides only the <strong>std140</strong>, <strong>std430</strong>, and <strong>packed</strong>
7882qualifiers; other qualifiers are inherited.
7883The compiler/linker will ensure that multiple programs and programmable
7884stages containing this definition will share the same memory layout for this
7885block, as long as all arrays are declared with explicit sizes and all
7886matrices have matching <strong>row_major</strong> and/or <strong>column_major</strong> qualifications
7887(which may come from a declaration outside the block definition).
7888This allows use of the same buffer to back the same block definition across
7889different programs.
7890It is a compile-time error to use the <strong>shared</strong> qualifier when generating
7891SPIR-V.</p>
7892</div>
7893<div class="paragraph">
7894<p>The <strong>packed</strong> qualifier overrides only <strong>std140</strong>, <strong>std430</strong>, and <strong>shared</strong>;
7895other qualifiers are inherited.
7896When <strong>packed</strong> is used, no shareable layout is guaranteed.
7897The compiler and linker can optimize memory use based on what variables
7898actively get used and on other criteria.
7899Offsets must be queried, as there is no other way of guaranteeing where (and
7900which) variables reside within the block.</p>
7901</div>
7902<div class="paragraph">
7903<p>It is a link-time error to access the same packed uniform or shader storage
7904block in multiple stages within a program.
7905Attempts to access the same packed uniform or shader storage block across
7906programs can result in conflicting member offsets and in undefined values
7907being read.
7908However, implementations may aid application management of packed blocks by
7909using canonical layouts for packed blocks.
7910It is a compile-time error to use the <strong>packed</strong> qualifier when generating
7911SPIR-V.</p>
7912</div>
7913<div class="paragraph">
7914<p>The <strong>std140</strong> and <strong>std430</strong> qualifiers override only the <strong>packed</strong>, <strong>shared</strong>,
7915<strong>std140</strong>, and <strong>std430</strong> qualifiers; other qualifiers are inherited.
7916The <strong>std430</strong> qualifier is supported only for shader storage blocks; a shader
7917using the <strong>std430</strong> qualifier on a uniform block will result in
7918a compile-time error, unless it is also declared with <strong>push_constant</strong>.</p>
7919</div>
7920<div class="paragraph">
7921<p>The layout is explicitly determined by this, as described in section 7.6.2.2
7922&#8220;Standard Uniform Block Layout&#8221; of the <a href="#references">OpenGL Specification</a>.
7923Hence, as in <strong>shared</strong> above, the resulting layout is shareable across
7924programs.</p>
7925</div>
7926<div class="paragraph">
7927<p>Layout qualifiers on member declarations cannot use the <strong>shared</strong>, <strong>packed</strong>,
7928<strong>std140</strong>, or <strong>std430</strong> qualifiers.
7929These can only be used at global scope (without an object) or on a block
7930declaration, or a compile-time error results.</p>
7931</div>
7932<div class="paragraph">
7933<p>The <strong>row_major</strong> and <strong>column_major</strong> qualifiers only affect the layout of
7934matrices, including all matrices contained in structures and arrays they are
7935applied to, to all depths of nesting.
7936These qualifiers can be applied to other types, but will have no effect.</p>
7937</div>
7938<div class="paragraph">
7939<p>The <strong>row_major</strong> qualifier overrides only the <strong>column_major</strong> qualifier; other
7940qualifiers are inherited.
7941Elements within a matrix row will be contiguous in memory.</p>
7942</div>
7943<div class="paragraph">
7944<p>The <strong>column_major</strong> qualifier overrides only the <strong>row_major</strong> qualifier; other
7945qualifiers are inherited.
7946Elements within a matrix column will be contiguous in memory.</p>
7947</div>
7948<div class="paragraph">
7949<p>The <strong>binding</strong> qualifier specifies the uniform buffer binding point
7950corresponding to the uniform or shader storage block, which will be used to
7951obtain the values of the member variables of the block.
7952It is a compile-time error to specify the <strong>binding</strong> qualifier for the global
7953scope or for block member declarations.
7954Any uniform or shader storage block declared without a <strong>binding</strong> qualifier
7955is initially assigned to block binding point zero.
7956After a program is linked, the binding points used for uniform
7957and shader storage blocks
7958declared with or without a <strong>binding</strong> qualifier can be updated
7959by the API.</p>
7960</div>
7961<div class="paragraph">
7962<p>When used with OpenGL,
7963if the <strong>binding</strong> qualifier is used with a uniform block or shader storage
7964block instanced as an array, the first element of the array takes the
7965specified block binding and each subsequent element takes the next
7966consecutive binding point.
7967For an array of arrays, each element (e.g. 6 elements for a[2][3]) gets a
7968binding point, and they are ordered per the array of array ordering
7969described in &#8220;<a href="#arrays">Arrays.</a>&#8221;</p>
7970</div>
7971<div class="paragraph">
7972<p>When targeting Vulkan,
7973if the <strong>binding</strong> qualifier is used with a uniform block or buffer block
7974instanced as an array, the entire array takes only the provided binding
7975number.
7976The next consecutive binding number is available for a different
7977object.
7978For an array of arrays, descriptor set array element numbers used
7979in descriptor set accesses are ordered per the array-of-array ordering
7980described in &#8220;<a href="#arrays">Arrays.</a>&#8221;</p>
7981</div>
7982<div class="paragraph">
7983<p>If the binding point for any uniform or shader storage block instance is
7984less than zero, or greater than or equal to the corresponding
7985implementation-dependent maximum number of buffer bindings, a compile-time
7986error will occur.
7987When the <strong>binding</strong> qualifier is used with a uniform or shader storage block
7988instanced as an array of size <em>N</em>, all elements of the array from <strong>binding</strong>
7989through <em>binding + N - 1</em> must be within this range.
7990It is a compile-time or link-time error to use the same binding number for
7991more than one uniform block or for more than one buffer block.</p>
7992</div>
7993<div class="paragraph">
7994<p>The <strong>set</strong> qualifier is only available when targeting Vulkan.
7995It specifies the descriptor set this object belongs to.
7996It is a compile-time error to apply <strong>set</strong> to a standalone qualifier, to
7997a member of a block, or when not targeting an API that supports descriptor sets.
7998It is a compile-time error to apply <strong>set</strong> to a block qualified as <strong>push_constant</strong>.
7999By default, any non-push-constant uniform or shader storage block declared
8000without a <strong>set</strong> identifier is assigned to descriptor set 0.
8001Similarly, any sampler, texture, or subpass-input type declared as a uniform
8002without a <strong>set</strong> identifier is also assigned to descriptor set 0.</p>
8003</div>
8004<div class="paragraph">
8005<p>If applied to an object declared as an array, all elements of the array
8006belong to the specified <strong>set</strong>.</p>
8007</div>
8008<div class="paragraph">
8009<p>When generating SPIR-V, it is a compile-time error for either the <strong>set</strong> or
8010<strong>binding</strong> value to exceed a front-end-configuration supplied maximum value.</p>
8011</div>
8012<div class="paragraph">
8013<p>When multiple arguments are listed in a <strong>layout</strong> declaration, the effect
8014will be the same as if they were declared one at a time, in order from left
8015to right, each in turn inheriting from and overriding the result from the
8016previous qualification.</p>
8017</div>
8018<div class="paragraph">
8019<p>For example</p>
8020</div>
8021<div class="listingblock">
8022<div class="content">
8023<pre class="CodeRay highlight"><code data-lang="c++">layout(row_major, column_major)</code></pre>
8024</div>
8025</div>
8026<div class="paragraph">
8027<p>results in the qualification being <strong>column_major</strong>.
8028Other examples:</p>
8029</div>
8030<div class="listingblock">
8031<div class="content">
8032<pre class="CodeRay highlight"><code data-lang="c++">layout(shared, row_major) uniform; <span class="comment">// default is now shared and row_major</span>
8033
8034layout(std140) uniform Transform { <span class="comment">// layout of this block is std140</span>
8035    mat4 M1;                       <span class="comment">// row major</span>
8036    layout(column_major) mat4 M2;  <span class="comment">// column major</span>
8037    mat3 N1;                       <span class="comment">// row major</span>
8038};
8039
8040uniform T2 {                       <span class="comment">// layout of this block is shared</span>
8041    ...
8042};
8043
8044layout(column_major) uniform T3 {  <span class="comment">// shared and column major</span>
8045    mat4 M3;                       <span class="comment">// column major</span>
8046    layout(row_major) mat4 m4;     <span class="comment">// row major</span>
8047    mat3 N2;                       <span class="comment">// column major</span>
8048};</code></pre>
8049</div>
8050</div>
8051<div class="paragraph">
8052<p>When targeting Vulkan, the <strong>offset</strong> and <strong>align</strong> qualifiers for blocks and
8053block members can only be used with <strong>uniform</strong> and <strong>buffer</strong> blocks.
8054When not targeting Vulkan, they can only be used with blocks declared with
8055<strong>std140</strong> or <strong>std430</strong> layouts.</p>
8056</div>
8057<div class="paragraph">
8058<p>The <strong>offset</strong> qualifier can only be used on block members.
8059The <strong>offset</strong> qualifier forces the qualified member to start at or after the
8060specified <em>layout-qualifier-value</em>, which will be its byte offset from
8061the beginning of the buffer.
8062It is a compile-time error to have any offset, explicit or assigned, that
8063lies within another member of the block.
8064When not generating SPIR-V, it is a compile-time error to specify an offset
8065that is smaller than the offset of the previous member in the block.
8066Two blocks linked together in the same program with the same block name must
8067have the exact same set of members qualified with <strong>offset</strong> and their
8068<em>layout-qualifier-value</em> values must be the same, or a link-time error
8069results.
8070The specified offset must be a multiple of the base alignment of the type of
8071the block member it qualifies, or a compile-time error results.</p>
8072</div>
8073<div class="paragraph">
8074<p>The <strong>align</strong> qualifier makes the start of each block member have a minimum
8075byte alignment.
8076It does not affect the internal layout within each member, which will still
8077follow the <strong>std140</strong> or <strong>std430</strong> rules.
8078The specified alignment must be greater than 0 and a power of 2, or a
8079compile-time error results.</p>
8080</div>
8081<div class="paragraph">
8082<p>The <em>actual alignment</em> of a member will be the greater of the specified
8083<strong>align</strong> alignment and the standard (e.g. <strong>std140</strong>) base alignment for the
8084member&#8217;s type.
8085The <em>actual offset</em> of a member is computed as follows: If <strong>offset</strong> was
8086declared, start with that offset, otherwise start with the offset immediately
8087following the preceding member (in declaration order).
8088If the resulting offset is not a multiple of the <em>actual alignment</em>,
8089increase it to the first offset that is a multiple of the <em>actual
8090alignment</em>.
8091This results in the <em>actual offset</em> the member will have.</p>
8092</div>
8093<div class="paragraph">
8094<p>When <strong>align</strong> is applied to an array, it affects only the start of the array,
8095not the array&#8217;s internal stride.
8096Both an <strong>offset</strong> and an <strong>align</strong> qualifier can be specified on a declaration.</p>
8097</div>
8098<div class="paragraph">
8099<p>The <strong>align</strong> qualifier, when used on a block, has the same effect as
8100qualifying each member with the same <strong>align</strong> value as declared on the block,
8101and gets the same compile-time results and errors as if this had been done.
8102As described in general earlier, an individual member can specify its own
8103<strong>align</strong>, which overrides the block-level <strong>align</strong>, but just for that member.</p>
8104</div>
8105<div class="paragraph">
8106<p>Examples:</p>
8107</div>
8108<div class="listingblock">
8109<div class="content">
8110<pre class="CodeRay highlight"><code data-lang="c++">layout(std140) uniform block {
8111 vec4 a;                         <span class="comment">// a takes offsets 0-15</span>
8112 layout(offset = <span class="integer">32</span>) vec3 b;     <span class="comment">// b takes offsets 32-43</span>
8113 layout(offset = <span class="integer">40</span>) vec2 c;     <span class="comment">// ERROR, lies within previous member</span>
8114 layout(offset = <span class="integer">48</span>) vec2 d;     <span class="comment">// d takes offsets 48-55</span>
8115 layout(align = <span class="integer">16</span>) <span class="predefined-type">float</span> e;     <span class="comment">// e takes offsets 64-67</span>
8116 layout(align = <span class="integer">2</span>) <span class="predefined-type">double</span> f;     <span class="comment">// f takes offsets 72-79</span>
8117 layout(align = <span class="integer">6</span>) <span class="predefined-type">double</span> g;     <span class="comment">// ERROR, 6 is not a power of 2</span>
8118 layout(offset = <span class="integer">80</span>) <span class="predefined-type">float</span> h;    <span class="comment">// h takes offsets 80-83</span>
8119 layout(align = <span class="integer">64</span>) dvec3 i;     <span class="comment">// i takes offsets 128-151</span>
8120 layout(offset = <span class="integer">164</span>, align = <span class="integer">8</span>)
8121 <span class="predefined-type">float</span> j;                        <span class="comment">// j takes offsets 168-171</span>
8122};</code></pre>
8123</div>
8124</div>
8125</div>
8126<div class="sect3">
8127<h4 id="opaque-uniform-layout-qualifiers">4.4.6. Opaque Uniform Layout Qualifiers</h4>
8128<div class="paragraph">
8129<p>Opaque uniform variables can take the uniform layout qualifier for binding:</p>
8130</div>
8131<div class="openblock bnf">
8132<div class="content">
8133<div class="dlist">
8134<dl>
8135<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
8136<dd>
8137<p><strong>binding</strong> <strong>=</strong> <em>layout-qualifier-value</em></p>
8138</dd>
8139</dl>
8140</div>
8141</div>
8142</div>
8143<div class="paragraph">
8144<p>The <strong>binding</strong> qualifier specifies the point where the variable will be bound.
8145Any opaque variable declared without a binding qualifier has a default binding
8146of zero.</p>
8147</div>
8148<div class="paragraph">
8149<p>When used with OpenGL,
8150if the <strong>binding</strong> qualifier is used with an array, the first element of the
8151array takes the specified binding point and each subsequent element takes the
8152next consecutive binding point.
8153For an array of arrays, each element (e.g. 6 elements for a[2][3]) gets a
8154binding point, and they are ordered per the array of array ordering
8155described in &#8220;<a href="#arrays">Arrays.</a>&#8221;</p>
8156</div>
8157<div class="paragraph">
8158<p>When targeting Vulkan,
8159if the <strong>binding</strong> qualifier is used with an array, the entire array
8160takes only the provided binding number. The next consecutive binding
8161number is available for a different object.</p>
8162</div>
8163<div class="paragraph">
8164<p>If the <strong>binding</strong> is less than zero, or greater than or equal to the
8165implementation-dependent maximum supported number of binding points,
8166a compile-time error will occur.
8167When the <strong>binding</strong> qualifier is used with an array of size <em>N</em>, all elements
8168of the array from <strong>binding</strong> through <em>binding + N - 1</em> must be within this
8169range.
8170It is a compile-time or link-time error to use the same <strong>binding</strong> number for
8171more than one atomic counter, unless the <em>offset</em> for the atomic counters
8172sharing the same binding are all different.</p>
8173</div>
8174<div class="paragraph">
8175<p>A link-time error will result if two shaders in a program specify different
8176<em>layout-qualifier-value</em> bindings for the same opaque-uniform name.
8177However, it is not an error to specify a binding on some but not all
8178declarations for the same name, as shown in the examples below.</p>
8179</div>
8180<div class="listingblock">
8181<div class="content">
8182<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">// in one shader...</span>
8183layout(binding=<span class="integer">3</span>) uniform sampler2D s; <span class="comment">// s bound to point 3</span>
8184
8185<span class="comment">// in another shader...</span>
8186uniform sampler2D s;                   <span class="comment">// okay, s still bound at 3</span>
8187
8188<span class="comment">// in another shader...</span>
8189layout(binding=<span class="integer">4</span>) uniform sampler2D s; <span class="comment">// ERROR: contradictory bindings</span></code></pre>
8190</div>
8191</div>
8192</div>
8193<div class="sect3">
8194<h4 id="atomic-counter-layout-qualifiers">4.4.7. Atomic Counter Layout Qualifiers</h4>
8195<div class="paragraph">
8196<p>Atomic counters are not available when targeting Vulkan.</p>
8197</div>
8198<div class="paragraph">
8199<p>Atomic counter layout qualifiers can be used on atomic counter declarations.
8200The atomic counter qualifiers are:</p>
8201</div>
8202<div class="openblock bnf">
8203<div class="content">
8204<div class="dlist">
8205<dl>
8206<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
8207<dd>
8208<p><strong>binding</strong> <strong>=</strong> <em>layout-qualifier-value</em><br>
8209<strong>offset</strong> <strong>=</strong> <em>layout-qualifier-value</em></p>
8210</dd>
8211</dl>
8212</div>
8213</div>
8214</div>
8215<div class="paragraph">
8216<p>For example,</p>
8217</div>
8218<div class="listingblock">
8219<div class="content">
8220<pre class="CodeRay highlight"><code data-lang="c++">layout(binding = <span class="integer">2</span>, offset = <span class="integer">4</span>) uniform atomic_uint a;</code></pre>
8221</div>
8222</div>
8223<div class="paragraph">
8224<p>will establish that the opaque handle to the atomic counter <em>a</em> will be
8225bound to atomic counter buffer binding point 2 at an offset of 4 basic
8226machine units into that buffer.
8227The default <em>offset</em> for binding point 2 will be post incremented by 4 (the
8228size of an atomic counter).</p>
8229</div>
8230<div class="paragraph">
8231<p>A subsequent atomic counter declaration will inherit the previous (post
8232incremented) offset.
8233For example, a subsequent declaration of</p>
8234</div>
8235<div class="listingblock">
8236<div class="content">
8237<pre class="CodeRay highlight"><code data-lang="c++">layout(binding = <span class="integer">2</span>) uniform atomic_uint bar;</code></pre>
8238</div>
8239</div>
8240<div class="paragraph">
8241<p>will establish that the atomic counter <em>bar</em> has a binding to buffer binding
8242point 2 at an offset of 8 basic machine units into that buffer.
8243The offset for binding point 2 will again be post-incremented by 4 (the size
8244of an atomic counter).</p>
8245</div>
8246<div class="paragraph">
8247<p>When multiple variables are listed in a layout declaration, the effect will
8248be the same as if they were declared one at a time, in order from left to
8249right.</p>
8250</div>
8251<div class="paragraph">
8252<p>Binding points are not inherited, only offsets.
8253Each binding point tracks its own current default <em>offset</em> for inheritance
8254of subsequent variables using the same <strong>binding</strong>.
8255The initial state of compilation is that all <strong>binding</strong> points have an
8256<em>offset</em> of 0.
8257The <em>offset</em> can be set per binding point at global scope (without declaring
8258a variable).
8259For example,</p>
8260</div>
8261<div class="listingblock">
8262<div class="content">
8263<pre class="CodeRay highlight"><code data-lang="c++">layout(binding = <span class="integer">2</span>, offset = <span class="integer">4</span>) uniform atomic_uint;</code></pre>
8264</div>
8265</div>
8266<div class="paragraph">
8267<p>Establishes that the next <strong>atomic_uint</strong> declaration for binding point 2 will
8268inherit <em>offset</em> 4 (but does not establish a default <strong>binding</strong>):</p>
8269</div>
8270<div class="listingblock">
8271<div class="content">
8272<pre class="CodeRay highlight"><code data-lang="c++">layout(binding = <span class="integer">2</span>) uniform atomic_uint bar; <span class="comment">// offset is 4</span>
8273layout(offset = <span class="integer">8</span>) uniform atomic_uint bar;  <span class="comment">// error, no default binding</span></code></pre>
8274</div>
8275</div>
8276<div class="paragraph">
8277<p>Atomic counters may share the same binding point, but if a binding is
8278shared, their offsets must be either explicitly or implicitly (from
8279inheritance) unique and non overlapping.</p>
8280</div>
8281<div class="paragraph">
8282<p>Example valid uniform declarations, assuming top of shader:</p>
8283</div>
8284<div class="listingblock">
8285<div class="content">
8286<pre class="CodeRay highlight"><code data-lang="c++">layout(binding=<span class="integer">3</span>, offset=<span class="integer">4</span>) uniform atomic_uint a; <span class="comment">// offset = 4</span>
8287layout(binding=<span class="integer">2</span>) uniform atomic_uint b;           <span class="comment">// offset = 0</span>
8288layout(binding=<span class="integer">3</span>) uniform atomic_uint c;           <span class="comment">// offset = 8</span>
8289layout(binding=<span class="integer">2</span>) uniform atomic_uint d;           <span class="comment">// offset = 4</span></code></pre>
8290</div>
8291</div>
8292<div class="paragraph">
8293<p>Example of an invalid uniform declaration:</p>
8294</div>
8295<div class="listingblock">
8296<div class="content">
8297<pre class="CodeRay highlight"><code data-lang="c++">layout(offset=<span class="integer">4</span>) ...               <span class="comment">// error, must include binding</span>
8298layout(binding=<span class="integer">1</span>, offset=<span class="integer">0</span>) ... a; <span class="comment">// okay</span>
8299layout(binding=<span class="integer">2</span>, offset=<span class="integer">0</span>) ... b; <span class="comment">// okay</span>
8300layout(binding=<span class="integer">1</span>, offset=<span class="integer">0</span>) ... c; <span class="comment">// error, offsets must not be shared</span>
8301                                   <span class="comment">// between a and c</span>
8302layout(binding=<span class="integer">1</span>, offset=<span class="integer">2</span>) ... d; <span class="comment">// error, overlaps offset 0 of a</span></code></pre>
8303</div>
8304</div>
8305<div class="paragraph">
8306<p>It is a compile-time error to bind an atomic counter with a binding value
8307greater than or equal to <em>gl_MaxAtomicCounterBindings</em>.
8308It is a compile-time error to declare an unsized array of <strong>atomic_uint</strong>.</p>
8309</div>
8310</div>
8311<div class="sect3">
8312<h4 id="format-layout-qualifiers">4.4.8. Format Layout Qualifiers</h4>
8313<div class="paragraph">
8314<p>Format layout qualifiers can be used on image variable declarations (those
8315declared with a basic type having &#8220;<strong>image</strong>&#8221; in its keyword).
8316The format layout qualifier identifiers for image variable declarations are:</p>
8317</div>
8318<div class="openblock bnf">
8319<div class="content">
8320<div class="dlist">
8321<dl>
8322<dt class="hdlist1"><em>layout-qualifier-id</em> : </dt>
8323<dd>
8324<p><em>float-image-format-qualifier</em><br>
8325<em>int-image-format-qualifier</em><br>
8326<em>uint-image-format-qualifier</em><br>
8327<strong>binding</strong> <strong>=</strong> <em>layout-qualifier-value</em></p>
8328</dd>
8329</dl>
8330</div>
8331</div>
8332</div>
8333<div class="openblock bnf">
8334<div class="content">
8335<div class="dlist">
8336<dl>
8337<dt class="hdlist1"><em>float-image-format-qualifier</em> : </dt>
8338<dd>
8339<p><strong>rgba32f</strong><br>
8340<strong>rgba16f</strong><br>
8341<strong>rg32f</strong><br>
8342<strong>rg16f</strong><br>
8343<strong>r11f_g11f_b10f</strong><br>
8344<strong>r32f</strong><br>
8345<strong>r16f</strong><br>
8346<strong>rgba16</strong><br>
8347<strong>rgb10_a2</strong><br>
8348<strong>rgba8</strong><br>
8349<strong>rg16</strong><br>
8350<strong>rg8</strong><br>
8351<strong>r16</strong><br>
8352<strong>r8</strong><br>
8353<strong>rgba16_snorm</strong><br>
8354<strong>rgba8_snorm</strong><br>
8355<strong>rg16_snorm</strong><br>
8356<strong>rg8_snorm</strong><br>
8357<strong>r16_snorm</strong><br>
8358<strong>r8_snorm</strong></p>
8359</dd>
8360<dt class="hdlist1"><em>int-image-format-qualifier</em> : </dt>
8361<dd>
8362<p><strong>rgba32i</strong><br>
8363<strong>rgba16i</strong><br>
8364<strong>rgba8i</strong><br>
8365<strong>rg32i</strong><br>
8366<strong>rg16i</strong><br>
8367<strong>rg8i</strong><br>
8368<strong>r32i</strong><br>
8369<strong>r16i</strong><br>
8370<strong>r8i</strong></p>
8371</dd>
8372<dt class="hdlist1"><em>uint-image-format-qualifier</em> : </dt>
8373<dd>
8374<p><strong>rgba32ui</strong><br>
8375<strong>rgba16ui</strong><br>
8376<strong>rgb10_a2ui</strong><br>
8377<strong>rgba8ui</strong><br>
8378<strong>rg32ui</strong><br>
8379<strong>rg16ui</strong><br>
8380<strong>rg8ui</strong><br>
8381<strong>r32ui</strong><br>
8382<strong>r16ui</strong><br>
8383<strong>r8ui</strong></p>
8384</dd>
8385</dl>
8386</div>
8387</div>
8388</div>
8389<div class="paragraph">
8390<p>A format layout qualifier specifies the image format associated with a
8391declared image variable.
8392Only one format qualifier may be specified for any image variable
8393declaration.
8394For image variables with floating-point component types (keywords starting
8395with &#8220;<strong>image</strong>&#8221;), signed integer component types (keywords starting with
8396&#8220;<strong>iimage</strong>&#8221;), or unsigned integer component types (keywords starting with
8397&#8220;<strong>uimage</strong>&#8221;), the format qualifier used must match the
8398<em>float-image-format-qualifier</em>, <em>int-image-format-qualifier</em>, or
8399<em>uint-image-format-qualifier</em> grammar rules, respectively.
8400It is a compile-time error to declare an image variable where the format
8401qualifier does not match the image variable type.</p>
8402</div>
8403<div class="paragraph">
8404<p>Any image variable used for image loads or atomic operations must specify a
8405format layout qualifier; it is a compile-time error to pass an image uniform
8406variable or function parameter declared without a format layout qualifier to
8407an image load or atomic function.</p>
8408</div>
8409<div class="paragraph">
8410<p>Uniforms not qualified with <strong>writeonly</strong> must have a format layout qualifier.
8411Note that an image variable passed to a function for read access cannot be
8412declared as <strong>writeonly</strong> and hence must have been declared with a format
8413layout qualifier.</p>
8414</div>
8415<div class="paragraph">
8416<p>The <strong>binding</strong> qualifier was described in
8417&#8220;<a href="#opaque-uniform-layout-qualifiers">Opaque Uniform Layout Qualifiers</a>&#8221;.</p>
8418</div>
8419</div>
8420<div class="sect3">
8421<h4 id="_subpass_input_qualifier">4.4.9. Subpass Input Qualifier</h4>
8422<div class="paragraph">
8423<p>Subpass inputs are only available when targeting Vulkan.</p>
8424</div>
8425<div class="paragraph">
8426<p>Subpass inputs are declared with the basic <strong>subpassInput</strong> types.
8427They must be declared with the layout qualifier
8428<strong>input_attachment_index</strong>, or a compile-time error results.
8429For example:</p>
8430</div>
8431<div class="listingblock">
8432<div class="content">
8433<pre class="CodeRay highlight"><code data-lang="c++">layout(input_attachment_index = <span class="integer">2</span>) uniform subpassInput t;</code></pre>
8434</div>
8435</div>
8436<div class="paragraph">
8437<p>This selects which subpass input is being read from. The value assigned
8438to <strong>input_attachment_index</strong>, say <em>i</em> (<code>input_attachment_index = i</code>), selects
8439that entry (<em>i</em> th entry) in the input list for the pass.  See the API
8440documentation for more detail about passes and the input list.</p>
8441</div>
8442<div class="paragraph">
8443<p>If an array of size <em>N</em> is declared, it consumes <em>N</em> consecutive
8444<strong>input_attachment_index</strong> values, starting with the one provided.</p>
8445</div>
8446<div class="paragraph">
8447<p>It is a compile-time or link-time error to have different variables
8448declared with the same <strong>input_attachment_index</strong>.
8449This includes any overlap in the implicit <strong>input_attachment_index</strong> consumed by
8450array declarations.</p>
8451</div>
8452<div class="paragraph">
8453<p>It is a compile-time error if the value assigned to an <strong>input_attachment_index</strong>
8454is greater than or equal to <em>gl_MaxInputAttachments</em>.</p>
8455</div>
8456</div>
8457</div>
8458<div class="sect2">
8459<h3 id="interpolation-qualifiers">4.5. Interpolation Qualifiers</h3>
8460<div class="paragraph">
8461<p>Inputs and outputs that could be interpolated can be further qualified by at
8462most one of the following interpolation qualifiers:</p>
8463</div>
8464<table class="tableblock frame-all grid-all stretch">
8465<colgroup>
8466<col style="width: 50%;">
8467<col style="width: 50%;">
8468</colgroup>
8469<thead>
8470<tr>
8471<th class="tableblock halign-left valign-top">Qualifier</th>
8472<th class="tableblock halign-left valign-top">Meaning</th>
8473</tr>
8474</thead>
8475<tbody>
8476<tr>
8477<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>smooth</strong></p></td>
8478<td class="tableblock halign-left valign-top"><p class="tableblock">perspective correct interpolation</p></td>
8479</tr>
8480<tr>
8481<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>flat</strong></p></td>
8482<td class="tableblock halign-left valign-top"><p class="tableblock">no interpolation</p></td>
8483</tr>
8484<tr>
8485<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>noperspective</strong></p></td>
8486<td class="tableblock halign-left valign-top"><p class="tableblock">linear interpolation</p></td>
8487</tr>
8488</tbody>
8489</table>
8490<div class="paragraph">
8491<p>The presence of and type of interpolation is controlled by the above
8492interpolation qualifiers as well as the auxiliary storage qualifiers
8493<strong>centroid</strong> and <strong>sample</strong>.
8494When no interpolation qualifier is present, smooth interpolation is used.
8495It is a compile-time error to use more than one interpolation qualifier.
8496The auxiliary storage qualifier <strong>patch</strong> is not used for interpolation; it is
8497a compile-time error to use interpolation qualifiers with <strong>patch</strong>.</p>
8498</div>
8499<div class="paragraph">
8500<p>A variable qualified as <strong>flat</strong> will not be interpolated.
8501Instead, it will have the same value for every fragment within a primitive.
8502This value will come from a single provoking vertex, as described by the
8503<a href="#references">API</a>.
8504A variable qualified as <strong>flat</strong> may also be qualified as <strong>centroid</strong> or
8505<strong>sample</strong>, which will mean the same thing as qualifying it only as <strong>flat</strong>.</p>
8506</div>
8507<div class="paragraph">
8508<p>A variable qualified as <strong>smooth</strong> will be interpolated in a
8509perspective-correct manner over the primitive being rendered.
8510Interpolation in a perspective correct manner is specified in equation 14.7
8511of the <a href="#references">OpenGL Specification</a>, section 14.5 &#8220;Line Segments&#8221;.</p>
8512</div>
8513<div class="paragraph">
8514<p>A variable qualified as <strong>noperspective</strong> must be interpolated linearly in
8515screen space, as described in equation 3.7 of the <a href="#references">OpenGL Specification</a>,
8516section 3.5 &#8220;Line Segments&#8221;.</p>
8517</div>
8518<div class="paragraph">
8519<p>When multisample rasterization is disabled, or for fragment shader input
8520variables qualified with neither <strong>centroid</strong> nor <strong>sample</strong>, the value of the
8521assigned variable may be interpolated anywhere within the pixel and a single
8522value may be assigned to each sample within the pixel, to the extent
8523permitted by the <a href="#references">OpenGL Specification</a>.</p>
8524</div>
8525<div class="paragraph">
8526<p>When multisample rasterization is enabled, <strong>centroid</strong> and <strong>sample</strong> may be
8527used to control the location and frequency of the sampling of the qualified
8528fragment shader input.
8529If a fragment shader input is qualified with <strong>centroid</strong>, a single value may
8530be assigned to that variable for all samples in the pixel, but that value
8531must be interpolated at a location that lies in both the pixel and in the
8532primitive being rendered, including any of the pixel&#8217;s samples covered by
8533the primitive.
8534Because the location at which the variable is interpolated may be different
8535in neighboring pixels, and derivatives may be computed by computing
8536differences between neighboring pixels, derivatives of centroid-sampled
8537inputs may be less accurate than those for non-centroid interpolated
8538variables.
8539If a fragment shader input is qualified with <strong>sample</strong>, a separate value must
8540be assigned to that variable for each covered sample in the pixel, and that
8541value must be sampled at the location of the individual sample.</p>
8542</div>
8543<div class="paragraph">
8544<p>It is a link-time error if, within the same stage, the interpolation
8545qualifiers of variables of the same name do not match.</p>
8546</div>
8547<div class="sect3">
8548<h4 id="redeclaring-built-in-interpolation-variables-in-the-compatibility-profile">4.5.1. Redeclaring Built-In Interpolation Variables in the Compatibility Profile</h4>
8549<div class="paragraph">
8550<p>The following predeclared variables can be redeclared with an interpolation
8551qualifier when using the compatibility profile:</p>
8552</div>
8553<div class="paragraph">
8554<p>Vertex, tessellation control, tessellation evaluation, and geometry
8555languages:</p>
8556</div>
8557<div class="listingblock">
8558<div class="content">
8559<pre class="CodeRay highlight"><code data-lang="c++">gl_FrontColor
8560gl_BackColor
8561gl_FrontSecondaryColor
8562gl_BackSecondaryColor</code></pre>
8563</div>
8564</div>
8565<div class="paragraph">
8566<p>Fragment language:</p>
8567</div>
8568<div class="listingblock">
8569<div class="content">
8570<pre class="CodeRay highlight"><code data-lang="c++">gl_Color
8571gl_SecondaryColor</code></pre>
8572</div>
8573</div>
8574<div class="paragraph">
8575<p>For example,</p>
8576</div>
8577<div class="listingblock">
8578<div class="content">
8579<pre class="CodeRay highlight"><code data-lang="c++">in vec4 gl_Color;            <span class="comment">// predeclared by the fragment language</span>
8580flat in vec4 gl_Color;       <span class="comment">// redeclared by user to be flat</span>
8581flat in vec4 gl_FrontColor;  <span class="comment">// input to geometry shader, no &quot;gl_in[]&quot;</span>
8582flat out vec4 gl_FrontColor; <span class="comment">// output from geometry shader</span></code></pre>
8583</div>
8584</div>
8585<div class="paragraph">
8586<p>Ideally, these are redeclared as part of the redeclaration of an interface
8587block, as described in
8588&#8220;<a href="#compatibility-profile-built-in-language-variables">Compatibility Profile
8589Built-In Language Variables</a>&#8221;.
8590However, for the above purpose, they can be redeclared as individual
8591variables at global scope, outside an interface block.
8592Such redeclarations also allow adding the transform-feedback qualifiers
8593<strong>xfb_buffer</strong>, <strong>xfb_stride</strong>, and <strong>xfb_offset</strong> to output variables.
8594(Using <strong>xfb_buffer</strong> on a variable does not change the global default
8595buffer.) A compile-time error will result if a shader has both an interface
8596block redeclaration and a separate redeclaration of a member of that
8597interface block outside the interface block redeclaration.</p>
8598</div>
8599<div class="paragraph">
8600<p>If <em>gl_Color</em> is redeclared with an interpolation qualifier, then
8601<em>gl_FrontColor</em> and <em>gl_BackColor</em> (if they are written to) must also be
8602redeclared with the same interpolation qualifier, and vice versa.
8603If <em>gl_SecondaryColor</em> is redeclared with an interpolation qualifier, then
8604<em>gl_FrontSecondaryColor</em> and _gl_BackSecondaryColor _(if they are written
8605to) must also be redeclared with the same interpolation qualifier, and vice
8606versa.
8607This qualifier matching on predeclared variables is only required for
8608variables that are statically used within the shaders in a program.</p>
8609</div>
8610</div>
8611</div>
8612<div class="sect2">
8613<h3 id="parameter-qualifiers">4.6. Parameter Qualifiers</h3>
8614<div class="paragraph">
8615<p>In addition to precision qualifiers and memory qualifiers, parameters can
8616have these parameter qualifiers.</p>
8617</div>
8618<table class="tableblock frame-all grid-all stretch">
8619<colgroup>
8620<col style="width: 50%;">
8621<col style="width: 50%;">
8622</colgroup>
8623<thead>
8624<tr>
8625<th class="tableblock halign-left valign-top">Qualifier</th>
8626<th class="tableblock halign-left valign-top">Meaning</th>
8627</tr>
8628</thead>
8629<tbody>
8630<tr>
8631<td class="tableblock halign-left valign-top"><p class="tableblock">&lt;none: default&gt;</p></td>
8632<td class="tableblock halign-left valign-top"><p class="tableblock">same as <strong>in</strong></p></td>
8633</tr>
8634<tr>
8635<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>const</strong></p></td>
8636<td class="tableblock halign-left valign-top"><p class="tableblock">for function parameters that cannot be written to</p></td>
8637</tr>
8638<tr>
8639<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>in</strong></p></td>
8640<td class="tableblock halign-left valign-top"><p class="tableblock">for function parameters passed into a function</p></td>
8641</tr>
8642<tr>
8643<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>out</strong></p></td>
8644<td class="tableblock halign-left valign-top"><p class="tableblock">for function parameters passed back out of a function,
8645                   but not initialized for use when passed in</p></td>
8646</tr>
8647<tr>
8648<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>inout</strong></p></td>
8649<td class="tableblock halign-left valign-top"><p class="tableblock">for function parameters passed both into and out of a
8650                   function</p></td>
8651</tr>
8652</tbody>
8653</table>
8654<div class="paragraph">
8655<p>Parameter qualifiers are discussed in more detail in
8656&#8220;<a href="#function-calling-conventions">Function Calling Conventions</a>&#8221;.</p>
8657</div>
8658</div>
8659<div class="sect2">
8660<h3 id="precision-and-precision-qualifiers">4.7. Precision and Precision Qualifiers</h3>
8661<div class="paragraph">
8662<p>When not targeting Vulkan:
8663Precision qualifiers are added for code portability with OpenGL ES, not for
8664functionality.
8665They have the same syntax as in OpenGL ES, as described below, but they have
8666no semantic meaning, which includes no effect on the precision used to store
8667or operate on variables.
8668If an extension adds in the same semantics and functionality in the OpenGL
8669ES 2.0 specification for precision qualifiers, then the extension is allowed
8670to reuse the keywords below for that purpose.</p>
8671</div>
8672<div class="paragraph">
8673<p>When targeting Vulkan:
8674For interface matching, uniform variables and uniform and buffer block
8675members must have the same precision qualification.
8676Global variables declared in different compilation units linked into the
8677same shader stage must be declared with the same precision qualification.</p>
8678</div>
8679<div class="paragraph">
8680<p>For the purposes of determining if an output from one shader stage matches
8681an input of the next stage, the precision qualifier need not match.</p>
8682</div>
8683<div class="sect3">
8684<h4 id="range-and-precision">4.7.1. Range and Precision</h4>
8685<div class="paragraph">
8686<p>The precision of <strong>highp</strong>
8687single- and double-precision
8688floating-point variables is defined by the IEEE 754 standard for
868932-bit
8690and 64-bit
8691floating-point numbers.</p>
8692</div>
8693<div class="paragraph">
8694<p>This includes support for NaNs (Not a Number) and Infs (positive or negative
8695infinities) and positive and negative zeros.</p>
8696</div>
8697<div class="paragraph">
8698<p>The following rules apply to <strong>highp</strong>
8699for both single and double-precision
8700operations:
8701Signed infinities and zeros are generated as dictated by IEEE, but subject
8702to the precisions allowed in the following table.
8703Any subnormal (denormalized) value input into a shader or potentially
8704generated by any operation in a shader can be flushed to 0.
8705The rounding mode cannot be set and is undefined but must not affect the
8706result by more than 1 ULP.
8707NaNs are not required to be generated.
8708Support for signaling NaNs is not required and exceptions are never raised.
8709Operations including built-in functions that operate on a NaN are not
8710required to return a NaN as the result.
8711However if NaNs are generated, <strong>isnan</strong>() must return the correct value.</p>
8712</div>
8713<div class="paragraph">
8714<p>Precisions are expressed in terms of maximum relative error in units of ULP
8715(units in the last place), unless otherwise noted.</p>
8716</div>
8717<div class="paragraph">
8718<p>For single precision operations, precisions are required as follows:</p>
8719</div>
8720<table class="tableblock frame-all grid-all stretch">
8721<colgroup>
8722<col style="width: 50%;">
8723<col style="width: 50%;">
8724</colgroup>
8725<thead>
8726<tr>
8727<th class="tableblock halign-left valign-top">Operation</th>
8728<th class="tableblock halign-left valign-top">Precision</th>
8729</tr>
8730</thead>
8731<tbody>
8732<tr>
8733<td class="tableblock halign-left valign-top"><p class="tableblock"><em>a</em> + <em>b</em>, <em>a</em> - <em>b</em>, <em>a</em> * <em>b</em></p></td>
8734<td class="tableblock halign-left valign-top"><p class="tableblock">Correctly rounded.</p></td>
8735</tr>
8736<tr>
8737<td class="tableblock halign-left valign-top"><p class="tableblock">&lt;, &lt;=, ==, &gt;, &gt;=</p></td>
8738<td class="tableblock halign-left valign-top"><p class="tableblock">Correct result.</p></td>
8739</tr>
8740<tr>
8741<td class="tableblock halign-left valign-top"><p class="tableblock"><em>a</em> / <em>b</em>, 1.0 / <em>b</em></p></td>
8742<td class="tableblock halign-left valign-top"><p class="tableblock">2.5 ULP for <span class="eq">|b|</span> in the range <span class="eq">[2<sup>-126</sup>, 2<sup>126</sup>]</span>.</p></td>
8743</tr>
8744<tr>
8745<td class="tableblock halign-left valign-top"><p class="tableblock"><em>a</em> * <em>b</em> + <em>c</em></p></td>
8746<td class="tableblock halign-left valign-top"><p class="tableblock">Correctly rounded single operation or
8747                                    sequence of two correctly rounded operations.</p></td>
8748</tr>
8749<tr>
8750<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>fma</strong>()</p></td>
8751<td class="tableblock halign-left valign-top"><p class="tableblock">Inherited from <em>a</em> * <em>b</em> + <em>c</em>.</p></td>
8752</tr>
8753<tr>
8754<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>pow</strong>(<em>x</em>, <em>y</em>)</p></td>
8755<td class="tableblock halign-left valign-top"><p class="tableblock">Inherited from <strong>exp2</strong>(<em>y</em> * <strong>log2</strong>(<em>x</em>)).</p></td>
8756</tr>
8757<tr>
8758<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>exp</strong>(<em>x</em>), <strong>exp2</strong>(<em>x</em>)</p></td>
8759<td class="tableblock halign-left valign-top"><p class="tableblock"><span class="eq">(3 + 2 · |x|)</span> ULP.</p></td>
8760</tr>
8761<tr>
8762<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>log</strong>(), <strong>log2</strong>()</p></td>
8763<td class="tableblock halign-left valign-top"><p class="tableblock">3 ULP outside the range <span class="eq">[0.5,2.0]</span>.<br>
8764                                    Absolute error &lt; 2<sup>-21</sup> inside the range
8765                                    <span class="eq">[0.5,2.0]</span>.</p></td>
8766</tr>
8767<tr>
8768<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sqrt</strong>()</p></td>
8769<td class="tableblock halign-left valign-top"><p class="tableblock">Inherited from 1.0 / <strong>inversesqrt</strong>().</p></td>
8770</tr>
8771<tr>
8772<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>inversesqrt</strong>()</p></td>
8773<td class="tableblock halign-left valign-top"><p class="tableblock">2 ULP.</p></td>
8774</tr>
8775<tr>
8776<td class="tableblock halign-left valign-top"><p class="tableblock">implicit and explicit
8777  conversions between types</p></td>
8778<td class="tableblock halign-left valign-top"><p class="tableblock">Correctly rounded.</p></td>
8779</tr>
8780</tbody>
8781</table>
8782<div class="paragraph">
8783<p>Built-in functions defined in the specification with an equation built from
8784the above operations inherit the above errors.
8785These include, for example, the geometric functions, the common functions,
8786and many of the matrix functions.
8787Built-in functions not listed above and not defined as equations of the
8788above have undefined precision.
8789These include, for example, the trigonometric functions and determinant.</p>
8790</div>
8791<div class="paragraph">
8792<p>The precision of double-precision operations is at least that of single
8793precision.</p>
8794</div>
8795</div>
8796<div class="sect3">
8797<h4 id="precision-qualifiers">4.7.2. Precision Qualifiers</h4>
8798<div class="paragraph">
8799<p>Any
8800single-precision
8801floating-point, integer, or opaque-type declaration can have the type
8802preceded by one of these precision qualifiers:</p>
8803</div>
8804<table class="tableblock frame-all grid-all stretch">
8805<colgroup>
8806<col style="width: 50%;">
8807<col style="width: 50%;">
8808</colgroup>
8809<thead>
8810<tr>
8811<th class="tableblock halign-left valign-top">Qualifier</th>
8812<th class="tableblock halign-left valign-top">Meaning</th>
8813</tr>
8814</thead>
8815<tbody>
8816<tr>
8817<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>highp</strong></p></td>
8818<td class="tableblock halign-left valign-top"><p class="tableblock">32-bit two&#8217;s complement for integers,
8819              32-bit IEEE 754 floating-point for <strong>float</strong></p></td>
8820</tr>
8821<tr>
8822<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>mediump</strong></p></td>
8823<td class="tableblock halign-left valign-top"><p class="tableblock">SPIR-V <strong>RelaxedPrecision</strong> when targeting Vulkan, otherwise none.</p></td>
8824</tr>
8825<tr>
8826<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>lowp</strong></p></td>
8827<td class="tableblock halign-left valign-top"><p class="tableblock">SPIR-V <strong>RelaxedPrecision</strong> when targeting Vulkan, otherwise none.</p></td>
8828</tr>
8829</tbody>
8830</table>
8831<div class="paragraph">
8832<p>For example:</p>
8833</div>
8834<div class="listingblock">
8835<div class="content">
8836<pre class="CodeRay highlight"><code data-lang="c++">lowp <span class="predefined-type">float</span> color;
8837out mediump vec2 P;
8838lowp ivec2 foo(lowp mat3);
8839highp mat4 m;</code></pre>
8840</div>
8841</div>
8842<div class="paragraph">
8843<p>Literal constants do not have precision qualifiers.
8844Neither do Boolean variables.
8845Neither do constructors.</p>
8846</div>
8847<div class="paragraph">
8848<p>For this paragraph, &#8220;operation&#8221; includes operators, built-in functions,
8849and constructors, and &#8220;operand&#8221; includes function arguments and
8850constructor arguments.
8851The precision used to internally evaluate an operation, and the precision
8852qualification subsequently associated with any resulting intermediate
8853values, must be at least as high as the highest precision qualification of
8854the operands consumed by the operation.</p>
8855</div>
8856<div class="paragraph">
8857<p>In cases where operands do not have a precision qualifier, the precision
8858qualification will come from the other operands.
8859If no operands have a precision qualifier, then the precision qualifications
8860of the operands of the next consuming operation in the expression will be
8861used.
8862This rule can be applied recursively until a precision qualified operand is
8863found.
8864If necessary, it will also include the precision qualification of l-values
8865for assignments, of the declared variable for initializers, of formal
8866parameters for function call arguments, or of function return types for
8867function return values.
8868If the precision cannot be determined by this method e.g. if an entire
8869expression is composed only of operands with no precision qualifier, and the
8870result is not assigned or passed as an argument, then it is evaluated at the
8871default precision of the type or greater.
8872When this occurs in the fragment shader, the default precision must be
8873defined.</p>
8874</div>
8875<div class="paragraph">
8876<p>For example, consider the statements:</p>
8877</div>
8878<div class="listingblock">
8879<div class="content">
8880<pre class="CodeRay highlight"><code data-lang="c++">uniform highp <span class="predefined-type">float</span> h1;
8881highp <span class="predefined-type">float</span> h2 = <span class="float">2</span><span class="float">.3</span> * <span class="float">4</span><span class="float">.7</span>; <span class="comment">// operation and result are highp</span>
8882precision
8883mediump <span class="predefined-type">float</span> m;
8884m = <span class="float">3</span><span class="float">.7</span> * h1 * h2; <span class="comment">// all operations are highp precision</span>
8885h2 = m * h1; <span class="comment">// operation is highp precision</span>
8886m = h2 - h1; <span class="comment">// operation is highp precision</span>
8887h2 = m + m; <span class="comment">// addition and result at mediump precision</span>
8888<span class="directive">void</span> f(highp <span class="predefined-type">float</span> p);
8889f(<span class="float">3</span><span class="float">.3</span>); <span class="comment">// 3.3 will be passed in at highp precision</span></code></pre>
8890</div>
8891</div>
8892<div class="paragraph">
8893<p>Precision qualifiers, as with other qualifiers, do not affect the basic type
8894of the variable.
8895In particular, there are no constructors for precision conversions;
8896constructors only convert types.
8897Similarly, precision qualifiers, as with other qualifiers, do not contribute
8898to function overloading based on parameter types.
8899As discussed in &#8220;<a href="#function-calling-conventions">Function Calling
8900Conventions</a>&#8221;, function input and output is done through copies, and
8901therefore qualifiers do not have to match.</p>
8902</div>
8903<div class="paragraph">
8904<p>The precision of a variable is determined when the variable is declared and
8905cannot be subsequently changed.</p>
8906</div>
8907<div class="paragraph">
8908<p>Where the precision of a constant integral or constant floating-point
8909expression is not specified, evaluation is performed at <strong>highp</strong>.
8910This rule does not affect the precision qualification of the expression.</p>
8911</div>
8912<div class="paragraph">
8913<p>The evaluation of constant expressions must be invariant and will usually be
8914performed at compile time.</p>
8915</div>
8916</div>
8917<div class="sect3">
8918<h4 id="default-precision-qualifiers">4.7.3. Default Precision Qualifiers</h4>
8919<div class="paragraph">
8920<p>The precision statement</p>
8921</div>
8922<div class="listingblock">
8923<div class="content">
8924<pre class="CodeRay highlight"><code data-lang="c++">precision precision-qualifier type;</code></pre>
8925</div>
8926</div>
8927<div class="paragraph">
8928<p>can be used to establish a default precision qualifier.
8929The <em>type</em> field can be either <strong>int</strong>, <strong>float</strong>, or any of the opaque types,
8930and the <em>precision-qualifier</em> can be <strong>lowp</strong>, <strong>mediump</strong>, or <strong>highp</strong>.</p>
8931</div>
8932<div class="paragraph">
8933<p>Any other types or qualifiers will result in a compile-time error.
8934If <em>type</em> is <strong>float</strong>, the directive applies to non-precision-qualified
8935single-precision
8936floating-point type (scalar, vector, and matrix) declarations.
8937If <em>type</em> is <strong>int</strong>, the directive applies to all non-precision-qualified
8938integer type (scalar, vector, signed, and unsigned) declarations.
8939This includes global variable declarations, function return declarations,
8940function parameter declarations, and local variable declarations.</p>
8941</div>
8942<div class="paragraph">
8943<p>Non-precision qualified declarations will use the precision qualifier
8944specified in the most recent <strong>precision</strong> statement that is still in scope.
8945The <strong>precision</strong> statement has the same scoping rules as variable
8946declarations.
8947If it is declared inside a compound statement, its effect stops at the end
8948of the inner-most statement it was declared in.
8949Precision statements in nested scopes override precision statements in outer
8950scopes.
8951Multiple precision statements for the same basic type can appear inside the
8952same scope, with later statements overriding earlier statements within that
8953scope.</p>
8954</div>
8955<div class="paragraph">
8956<p>For any type that accepts a precision qualifier,
8957the default precision qualification will be <strong>highp</strong>.
8958Because all types requiring a precision qualifier have a default precision,
8959there are no errors for omission of a precision qualifier.</p>
8960</div>
8961</div>
8962<div class="sect3">
8963<h4 id="available-precision-qualifiers">4.7.4. Available Precision Qualifiers</h4>
8964<div class="paragraph">
8965<p>The built-in macro GL_FRAGMENT_PRECISION_HIGH is defined to one:</p>
8966</div>
8967<div class="listingblock">
8968<div class="content">
8969<pre class="CodeRay highlight"><code data-lang="c++"><span class="preprocessor">#define</span> GL_FRAGMENT_PRECISION_HIGH <span class="integer">1</span></code></pre>
8970</div>
8971</div>
8972<div class="paragraph">
8973<p>This macro is available in all languages except compute.</p>
8974</div>
8975</div>
8976</div>
8977<div class="sect2">
8978<h3 id="variance-and-the-invariant-qualifier">4.8. Variance and the Invariant Qualifier</h3>
8979<div class="paragraph">
8980<p>In this section, <em>variance</em> refers to the possibility of getting different
8981values from the same expression in different programs.
8982For example, consider the situation where two vertex shaders, in different
8983programs, each set <em>gl_Position</em> with the same expression, and the input
8984values into that expression are the same when both shaders run.
8985It is possible, due to independent compilation of the two shaders, that the
8986values assigned to <em>gl_Position</em> are not exactly the same when the two
8987shaders run.
8988In this example, this can cause problems with alignment of geometry in a
8989multi-pass algorithm.</p>
8990</div>
8991<div class="paragraph">
8992<p>In general, such variance between shaders is allowed.
8993When such variance does not exist for a particular output variable, that
8994variable is said to be <em>invariant</em>.</p>
8995</div>
8996<div class="sect3">
8997<h4 id="the-invariant-qualifier">4.8.1. The Invariant Qualifier</h4>
8998<div class="paragraph">
8999<p>To ensure that a particular output variable is invariant, it is necessary to
9000use the <strong>invariant</strong> qualifier.
9001It can either be used to qualify a previously declared variable as being
9002invariant:</p>
9003</div>
9004<div class="listingblock">
9005<div class="content">
9006<pre class="CodeRay highlight"><code data-lang="c++">invariant gl_Position; <span class="comment">// make existing gl_Position be invariant</span>
9007out vec3 Color;
9008invariant Color;       <span class="comment">// make existing Color be invariant</span></code></pre>
9009</div>
9010</div>
9011<div class="paragraph">
9012<p>or as part of a declaration when a variable is declared:</p>
9013</div>
9014<div class="listingblock">
9015<div class="content">
9016<pre class="CodeRay highlight"><code data-lang="c++">invariant centroid out vec3 Color;</code></pre>
9017</div>
9018</div>
9019<div class="paragraph">
9020<p>Only variables output from a shader can be candidates for invariance.
9021This includes user-defined output variables and the built-in output
9022variables.
9023As only outputs can be declared as invariant, an output from one shader
9024stage will still match an input of a subsequent stage without the input
9025being declared as invariant.</p>
9026</div>
9027<div class="paragraph">
9028<p>Input or output instance names on blocks are not used when redeclaring
9029built-in variables.</p>
9030</div>
9031<div class="paragraph">
9032<p>The <strong>invariant</strong> keyword can be followed by a comma separated list of
9033previously declared identifiers.
9034All uses of <strong>invariant</strong> must be at global scope or on block
9035members, and before any use of the variables being declared as invariant.</p>
9036</div>
9037<div class="paragraph">
9038<p>To guarantee invariance of a particular output variable across two programs,
9039the following must also be true:</p>
9040</div>
9041<div class="ulist">
9042<ul>
9043<li>
9044<p>The output variable is declared as invariant in both programs.</p>
9045</li>
9046<li>
9047<p>The same values must be input to all shader input variables consumed by
9048expressions and control flow contributing to the value assigned to the
9049output variable.</p>
9050</li>
9051<li>
9052<p>The texture formats, texel values, and texture filtering are set the
9053same way for any texture function calls contributing to the value of the
9054output variable.</p>
9055</li>
9056<li>
9057<p>All input values are all operated on in the same way.
9058    All operations in the consuming expressions and any intermediate
9059    expressions must be the same, with the same order of operands and same
9060    associativity, to give the same order of evaluation.
9061    Intermediate variables and functions must be declared as the same type
9062    with the same explicit or implicit precision
9063qualifiers.
9064    Any control flow affecting the output value must be the same, and any
9065    expressions consumed to determine this control flow must also follow
9066    these invariance rules.</p>
9067</li>
9068<li>
9069<p>All the data flow and control flow leading to setting the invariant
9070output variable reside in a single compilation unit.</p>
9071</li>
9072</ul>
9073</div>
9074<div class="paragraph">
9075<p>Essentially, all the data flow and control flow leading to an invariant
9076output must match.</p>
9077</div>
9078<div class="paragraph">
9079<p>Initially, by default, all output variables are allowed to be variant.
9080To force all output variables to be invariant, use the pragma</p>
9081</div>
9082<div class="listingblock">
9083<div class="content">
9084<pre class="CodeRay highlight"><code data-lang="c++"><span class="preprocessor">#pragma</span> STDGL invariant(all)</code></pre>
9085</div>
9086</div>
9087<div class="paragraph">
9088<p>before all declarations in a shader.
9089If this pragma is used after the declaration of any variables or functions,
9090then the set of outputs that behave as invariant is undefined.</p>
9091</div>
9092<div class="paragraph">
9093<p>Generally, invariance is ensured at the cost of flexibility in optimization,
9094so performance can be degraded by use of invariance.
9095Hence, use of this pragma is intended as a debug aid, to avoid individually
9096declaring all output variables as invariant.</p>
9097</div>
9098</div>
9099<div class="sect3">
9100<h4 id="invariance-of-constant-expressions">4.8.2. Invariance of Constant Expressions</h4>
9101<div class="paragraph">
9102<p>Invariance must be guaranteed for constant expressions.
9103A particular constant expression must evaluate to the same result if it
9104appears again in the same shader or a different shader.
9105This includes the same expression appearing in two shaders of the same
9106language or shaders of two different languages.</p>
9107</div>
9108<div class="paragraph">
9109<p>Constant expressions must evaluate to the same result when operated on as
9110already described above for invariant variables.</p>
9111</div>
9112</div>
9113</div>
9114<div class="sect2">
9115<h3 id="the-precise-qualifier">4.9. The Precise Qualifier</h3>
9116<div class="paragraph">
9117<p>Some algorithms require floating-point computations to exactly follow the
9118order of operations specified in the source code and to treat all operations
9119consistently, even if the implementation supports optimizations that could
9120produce nearly equivalent results with higher performance.
9121For example, many GL implementations support a &#8220;multiply-add&#8221; instruction
9122that can compute a floating-point expression such as</p>
9123</div>
9124<div class="listingblock">
9125<div class="content">
9126<pre class="CodeRay highlight"><code data-lang="c++">result = (a * b) + (c * d);</code></pre>
9127</div>
9128</div>
9129<div class="paragraph">
9130<p>in two operations instead of three operations; one multiply and one
9131multiply-add instead of two multiplies and one add.
9132The result of a floating-point multiply-add might not always be identical to
9133first doing a multiply yielding a floating-point result and then doing a
9134floating-point add.
9135Hence, in this example, the two multiply operations would not be treated
9136consistently; the two multiplies could effectively appear to have differing
9137precisions.</p>
9138</div>
9139<div class="paragraph">
9140<p>The key computation that needs to be made consistent appears when
9141tessellating, where intermediate points for subdivision are synthesized in
9142different directions, yet need to yield the same result, as shown in the
9143diagram below.</p>
9144</div>
9145<div id="img-precise" class="imageblock">
9146<div class="content">
9147<img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KCjxzdmcgdmVyc2lvbj0iMS4yIiBiYXNlUHJvZmlsZT0idGlueSIgd2lkdGg9IjIxMG1tIiBoZWlnaHQ9IjI5N21tIiB2aWV3Qm94PSIwIDAgMjEwMDAgMjk3MDAiIHByZXNlcnZlQXNwZWN0UmF0aW89InhNaWRZTWlkIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcGF0aD0idXJsKCNwcmVzZW50YXRpb25fY2xpcF9wYXRoKSIgc3Ryb2tlLXdpZHRoPSIyOC4yMjIiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6b29vPSJodHRwOi8veG1sLm9wZW5vZmZpY2Uub3JnL3N2Zy9leHBvcnQiIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4bWw6c3BhY2U9InByZXNlcnZlIj4KIDxkZWZzIGNsYXNzPSJDbGlwUGF0aEdyb3VwIj4KICA8Y2xpcFBhdGggaWQ9InByZXNlbnRhdGlvbl9jbGlwX3BhdGgiIGNsaXBQYXRoVW5pdHM9InVzZXJTcGFjZU9uVXNlIj4KICAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjIxMDAwIiBoZWlnaHQ9IjI5NzAwIi8+CiAgPC9jbGlwUGF0aD4KIDwvZGVmcz4KIDxkZWZzPgogIDxmb250IGlkPSJFbWJlZGRlZEZvbnRfMSIgaG9yaXotYWR2LXg9IjIwNDgiPgogICA8Zm9udC1mYWNlIGZvbnQtZmFtaWx5PSJMaWJlcmF0aW9uIFNhbnMgZW1iZWRkZWQiIHVuaXRzLXBlci1lbT0iMjA0OCIgZm9udC13ZWlnaHQ9Im5vcm1hbCIgZm9udC1zdHlsZT0ibm9ybWFsIiBhc2NlbnQ9IjE4NTIiIGRlc2NlbnQ9IjQyMyIvPgogICA8bWlzc2luZy1nbHlwaCBob3Jpei1hZHYteD0iMjA0OCIgZD0iTSAwLDAgTCAyMDQ3LDAgMjA0NywyMDQ3IDAsMjA0NyAwLDAgWiIvPgogICA8Z2x5cGggdW5pY29kZT0idyIgaG9yaXotYWR2LXg9IjE1MDkiIGQ9Ik0gMTE3NCwwIEwgOTY1LDAgNzkyLDY5OCBDIDc4Nyw3MTYgNzgxLDczOCA3NzYsNzY1IDc3MCw3OTIgNzY0LDgxOCA3NTksODQzIDc1Miw4NzIgNzQ2LDkwMyA3NDAsOTM0IDczNCw5MDQgNzI4LDg3NCA3MjEsODQ1IDcxNiw4MjAgNzEwLDc5MyA3MDQsNzY2IDY5Nyw3MzkgNjkxLDcxNSA2ODYsNjk0IEwgNTA4LDAgMzAwLDAgLTMsMTA4MiAxNzUsMTA4MiAzNTgsMzQ3IEMgMzYzLDMzMiAzNjcsMzEzIDM3MiwyOTEgMzc3LDI2OCAzODEsMjQ2IDM4NiwyMjUgMzkxLDIwMCAzOTYsMTc1IDQwMSwxNDkgNDA2LDE3NCA0MTIsMTk5IDQxOCwyMjMgNDIzLDI0NCA0MjksMjY1IDQzNCwyODYgNDM5LDMwNyA0NDQsMzI1IDQ0OCwzMzkgTCA2NDQsMTA4MiA4MzcsMTA4MiAxMDI2LDMzOSBDIDEwMzEsMzIyIDEwMzYsMzAyIDEwNDEsMjgwIDEwNDYsMjU4IDEwNTEsMjM3IDEwNTYsMjE4IDEwNjEsMTk1IDEwNjcsMTcyIDEwNzIsMTQ5IDEwNzcsMTc0IDEwODMsMTk5IDEwODgsMjIzIDEwOTMsMjQ0IDEwOTgsMjY1IDExMDMsMjg4IDExMDgsMzEwIDExMTIsMzMwIDExMTcsMzQ3IEwgMTMwOCwxMDgyIDE0ODQsMTA4MiAxMTc0LDAgWiIvPgogICA8Z2x5cGggdW5pY29kZT0idiIgaG9yaXotYWR2LXg9IjEwMzMiIGQ9Ik0gNjEzLDAgTCA0MDAsMCA3LDEwODIgMTk5LDEwODIgNDM3LDM3OCBDIDQ0MiwzNjMgNDQ3LDM0NiA0NTQsMzI1IDQ2MCwzMDQgNDY2LDI4MiA0NzMsMjU5IDQ4MCwyMzYgNDg2LDIxNSA0OTIsMTk0IDQ5NywxNzMgNTAyLDE1NSA1MDYsMTQxIDUxMCwxNTUgNTE1LDE3MyA1MjIsMTk0IDUyOCwyMTUgNTM0LDIzNiA1NDEsMjU4IDU0OCwyODAgNTU1LDMwMiA1NjIsMzIzIDU2OSwzNDQgNTc1LDM2MSA1ODAsMzc2IEwgODI2LDEwODIgMTAxNywxMDgyIDYxMywwIFoiLz4KICAgPGdseXBoIHVuaWNvZGU9InUiIGhvcml6LWFkdi14PSI4NzQiIGQ9Ik0gMzE0LDEwODIgTCAzMTQsMzk2IEMgMzE0LDM0MyAzMTgsMjk5IDMyNiwyNjQgMzMzLDIyOSAzNDYsMjAwIDM2MywxNzkgMzgwLDE1NyA0MDMsMTQyIDQzMiwxMzMgNDYwLDEyNCA0OTUsMTE5IDUzNywxMTkgNTgwLDExOSA2MTgsMTI3IDY1MywxNDIgNjg3LDE1NyA3MTYsMTc4IDc0MSwyMDcgNzY1LDIzNSA3ODQsMjcwIDc5NywzMTIgODEwLDM1MyA4MTcsNDAxIDgxNyw0NTUgTCA4MTcsMTA4MiA5OTcsMTA4MiA5OTcsMjMxIEMgOTk3LDIwOCA5OTcsMTg1IDk5OCwxNjAgOTk4LDEzNSA5OTgsMTExIDk5OSw4OSAxMDAwLDY2IDEwMDAsNDcgMTAwMSwzMSAxMDAyLDE1IDEwMDIsNSAxMDAzLDAgTCA4MzMsMCBDIDgzMiwzIDgzMiwxMiA4MzEsMjcgODMwLDQyIDgzMCw1OSA4MjksNzggODI4LDk3IDgyNywxMTYgODI2LDEzNiA4MjUsMTU1IDgyNSwxNzIgODI1LDE4NSBMIDgyMiwxODUgQyA4MDUsMTU0IDc4NiwxMjUgNzY1LDEwMCA3NDQsNzUgNzIwLDUzIDY5MywzNiA2NjYsMTggNjM0LDQgNTk5LC02IDU2NCwtMTUgNTIzLC0yMCA0NzYsLTIwIDQxNiwtMjAgMzY0LC0xMyAzMjEsMiAyNzgsMTcgMjQyLDM5IDIxNCw3MCAxODYsMTAxIDE2NiwxNDAgMTUzLDE4OCAxNDAsMjM2IDEzMywyOTQgMTMzLDM2MSBMIDEzMywxMDgyIDMxNCwxMDgyIFoiLz4KICAgPGdseXBoIHVuaWNvZGU9InQiIGhvcml6LWFkdi14PSI1MzEiIGQ9Ik0gNTU0LDggQyA1MjcsMSA0OTksLTUgNDcxLC0xMCA0NDIsLTE0IDQwOSwtMTYgMzcyLC0xNiAyMjgsLTE2IDE1Niw2NiAxNTYsMjI5IEwgMTU2LDk1MSAzMSw5NTEgMzEsMTA4MiAxNjMsMTA4MiAyMTYsMTMyNCAzMzYsMTMyNCAzMzYsMTA4MiA1MzYsMTA4MiA1MzYsOTUxIDMzNiw5NTEgMzM2LDI2OCBDIDMzNiwyMTYgMzQ1LDE4MCAzNjIsMTU5IDM3OSwxMzggNDA4LDEyNyA0NTAsMTI3IDQ2NywxMjcgNDg0LDEyOCA1MDEsMTMxIDUxNywxMzQgNTM1LDEzNyA1NTQsMTQxIEwgNTU0LDggWiIvPgogICA8Z2x5cGggdW5pY29kZT0icyIgaG9yaXotYWR2LXg9IjkwMSIgZD0iTSA5NTAsMjk5IEMgOTUwLDI0OCA5NDAsMjAzIDkyMSwxNjQgOTAxLDEyNCA4NzIsOTEgODM1LDY0IDc5OCwzNyA3NTIsMTYgNjk4LDIgNjQzLC0xMyA1ODEsLTIwIDUxMSwtMjAgNDQ4LC0yMCAzOTIsLTE1IDM0MiwtNiAyOTEsNCAyNDcsMjAgMjA5LDQxIDE3MSw2MiAxMzksOTEgMTE0LDEyNiA4OCwxNjEgNjksMjAzIDU3LDI1NCBMIDIxNiwyODUgQyAyMzEsMjI3IDI2MywxODUgMzExLDE1OCAzNTksMTMxIDQyNiwxMTcgNTExLDExNyA1NTAsMTE3IDU4NSwxMjAgNjE4LDEyNSA2NTAsMTMwIDY3OCwxNDAgNzAxLDE1MyA3MjQsMTY2IDc0MywxODMgNzU2LDIwNSA3NjksMjI2IDc3NSwyNTMgNzc1LDI4NSA3NzUsMzE4IDc2NywzNDUgNzUyLDM2NiA3MzcsMzg3IDcxNSw0MDQgNjg4LDQxOCA2NjEsNDMyIDYyOCw0NDQgNTg5LDQ1NSA1NTAsNDY1IDUwNyw0NzYgNDYwLDQ4OSA0MTcsNTAwIDM3NCw1MTMgMzMxLDUyNyAyODgsNTQxIDI1MCw1NjAgMjE2LDU4MyAxODEsNjA2IDE1Myw2MzQgMTMyLDY2OCAxMTEsNzAyIDEwMCw3NDUgMTAwLDc5NiAxMDAsODk1IDEzNSw5NzAgMjA2LDEwMjIgMjc2LDEwNzMgMzc4LDEwOTkgNTEzLDEwOTkgNjMyLDEwOTkgNzI3LDEwNzggNzk4LDEwMzYgODY4LDk5NCA5MTIsOTI3IDkzMSw4MzQgTCA3NjksODE0IEMgNzYzLDg0MiA3NTIsODY2IDczNiw4ODUgNzIwLDkwNCA3MDEsOTE5IDY3OCw5MzEgNjU1LDk0MiA2MzAsOTUxIDYwMiw5NTYgNTczLDk2MSA1NDQsOTYzIDUxMyw5NjMgNDMyLDk2MyAzNzIsOTUxIDMzMyw5MjYgMjk0LDkwMSAyNzUsODY0IDI3NSw4MTQgMjc1LDc4NSAyODIsNzYxIDI5Nyw3NDIgMzExLDcyMyAzMzEsNzA3IDM1Nyw2OTQgMzgyLDY4MSA0MTMsNjY5IDQ0OSw2NjAgNDg1LDY1MCA1MjUsNjQwIDU2OCw2MjkgNTk3LDYyMiA2MjYsNjE0IDY1Niw2MDYgNjg2LDU5NyA3MTUsNTg3IDc0NCw1NzYgNzcyLDU2NCA3OTksNTUwIDgyNCw1MzUgODQ5LDUxOSA4NzAsNTAwIDg4OSw0NzggOTA4LDQ1NiA5MjMsNDMwIDkzNCw0MDEgOTQ1LDM3MiA5NTAsMzM4IDk1MCwyOTkgWiIvPgogICA8Z2x5cGggdW5pY29kZT0iciIgaG9yaXotYWR2LXg9IjUzMCIgZD0iTSAxNDIsMCBMIDE0Miw4MzAgQyAxNDIsODUzIDE0Miw4NzYgMTQyLDkwMCAxNDEsOTIzIDE0MSw5NDYgMTQwLDk2OCAxMzksOTkwIDEzOSwxMDExIDEzOCwxMDMwIDEzNywxMDQ5IDEzNywxMDY3IDEzNiwxMDgyIEwgMzA2LDEwODIgQyAzMDcsMTA2NyAzMDgsMTA0OSAzMDksMTAzMCAzMTAsMTAxMCAzMTEsOTkwIDMxMiw5NjkgMzEzLDk0OCAzMTMsOTI5IDMxNCw5MTAgMzE0LDg5MSAzMTQsODc0IDMxNCw4NjEgTCAzMTgsODYxIEMgMzMxLDkwMiAzNDQsOTM4IDM1OSw5NjkgMzczLDk5OSAzOTAsMTAyNCA0MDksMTA0NCA0MjgsMTA2MyA0NTEsMTA3OCA0NzgsMTA4OCA1MDUsMTA5NyA1MzcsMTEwMiA1NzUsMTEwMiA1OTAsMTEwMiA2MDQsMTEwMSA2MTcsMTA5OSA2MzAsMTA5NiA2NDEsMTA5NCA2NDgsMTA5MiBMIDY0OCw5MjcgQyA2MzYsOTMwIDYyMiw5MzMgNjA2LDkzNSA1OTAsOTM2IDU3Miw5MzcgNTUyLDkzNyA1MTEsOTM3IDQ3Niw5MjggNDQ3LDkwOSA0MTgsODkwIDM5NCw4NjUgMzc2LDgzMiAzNTcsNzk5IDM0NCw3NTkgMzM1LDcxNCAzMjYsNjY4IDMyMiw2MTggMzIyLDU2NCBMIDMyMiwwIDE0MiwwIFoiLz4KICAgPGdseXBoIHVuaWNvZGU9InAiIGhvcml6LWFkdi14PSI5NTMiIGQ9Ik0gMTA1Myw1NDYgQyAxMDUzLDQ2NCAxMDQ2LDM4OCAxMDMzLDMxOSAxMDIwLDI1MCA5OTgsMTkwIDk2NywxNDAgOTM2LDkwIDg5NSw1MSA4NDQsMjMgNzkzLC02IDczMCwtMjAgNjU1LC0yMCA1NzgsLTIwIDUxMCwtNSA0NTIsMjQgMzk0LDUzIDM1MCwxMDEgMzE5LDE2OCBMIDMxNCwxNjggQyAzMTUsMTY3IDMxNSwxNjEgMzE2LDE1MCAzMTYsMTM5IDMxNiwxMjYgMzE3LDExMCAzMTcsOTQgMzE3LDc2IDMxOCw1NyAzMTgsMzcgMzE4LDE3IDMxOCwtMiBMIDMxOCwtNDI1IDEzOCwtNDI1IDEzOCw4NjEgQyAxMzgsODg3IDEzOCw5MTIgMTM4LDkzNiAxMzcsOTYwIDEzNyw5ODIgMTM2LDEwMDIgMTM1LDEwMjEgMTM1LDEwMzggMTM0LDEwNTIgMTMzLDEwNjYgMTMzLDEwNzYgMTMyLDEwODIgTCAzMDYsMTA4MiBDIDMwNywxMDgwIDMwOCwxMDczIDMwOSwxMDYxIDMxMCwxMDQ5IDMxMSwxMDM1IDMxMiwxMDE4IDMxMywxMDAxIDMxNCw5ODIgMzE1LDk2MyAzMTYsOTQ0IDMxNiw5MjUgMzE2LDkwOCBMIDMyMCw5MDggQyAzMzcsOTQzIDM1Niw5NzIgMzc3LDk5NyAzOTgsMTAyMSA0MjMsMTA0MSA0NTAsMTA1NyA0NzcsMTA3MiA1MDgsMTA4NCA1NDIsMTA5MSA1NzUsMTA5OCA2MTMsMTEwMSA2NTUsMTEwMSA3MzAsMTEwMSA3OTMsMTA4OCA4NDQsMTA2MSA4OTUsMTAzNCA5MzYsOTk3IDk2Nyw5NDkgOTk4LDkwMCAxMDIwLDg0MiAxMDMzLDc3NCAxMDQ2LDcwNSAxMDUzLDYyOSAxMDUzLDU0NiBaIE0gODY0LDU0MiBDIDg2NCw2MDkgODYwLDY2OCA4NTIsNzIwIDg0NCw3NzIgODMwLDgxNiA4MTEsODUyIDc5MSw4ODggNzY1LDkxNSA3MzIsOTM0IDY5OSw5NTMgNjU4LDk2MiA2MDksOTYyIDU2OSw5NjIgNTMxLDk1NiA0OTYsOTQ1IDQ2MSw5MzQgNDMwLDkxMiA0MDQsODgwIDM3Nyw4NDggMzU2LDgwNCAzNDEsNzQ4IDMyNiw2OTEgMzE4LDYxOCAzMTgsNTI4IDMxOCw0NTEgMzI0LDM4NyAzMzcsMzM0IDM1MCwyODEgMzY4LDIzOCAzOTMsMjA1IDQxNywxNzIgNDQ3LDE0OSA0ODMsMTM1IDUxOSwxMjAgNTYwLDExMyA2MDcsMTEzIDY1NywxMTMgNjk5LDEyMyA3MzIsMTQyIDc2NSwxNjEgNzkxLDE4OSA4MTEsMjI2IDgzMCwyNjMgODQ0LDMwOCA4NTIsMzYxIDg2MCw0MTQgODY0LDQ3NCA4NjQsNTQyIFoiLz4KICAgPGdseXBoIHVuaWNvZGU9Im8iIGhvcml6LWFkdi14PSI5ODAiIGQ9Ik0gMTA1Myw1NDIgQyAxMDUzLDM1MyAxMDExLDIxMiA5MjgsMTE5IDg0NSwyNiA3MjQsLTIwIDU2NSwtMjAgNDkwLC0yMCA0MjIsLTkgMzYzLDE0IDMwNCwzNyAyNTQsNzEgMjEzLDExOCAxNzIsMTY1IDE0MCwyMjMgMTE5LDI5NCA5NywzNjQgODYsNDQ3IDg2LDU0MiA4Niw5MTUgMjQ4LDExMDIgNTcxLDExMDIgNjU1LDExMDIgNzI4LDEwOTAgNzg5LDEwNjcgODUwLDEwNDQgOTAwLDEwMDkgOTM5LDk2MiA5NzgsOTE1IDEwMDYsODU3IDEwMjUsNzg3IDEwNDQsNzE3IDEwNTMsNjM1IDEwNTMsNTQyIFogTSA4NjQsNTQyIEMgODY0LDYyNiA4NTgsNjk1IDg0NSw3NTAgODMyLDgwNSA4MTMsODQ4IDc4OCw4ODEgNzYzLDkxNCA3MzIsOTM3IDY5Niw5NTAgNjYwLDk2MyA2MTksOTY5IDU3NCw5NjkgNTI4LDk2OSA0ODcsOTYyIDQ1MCw5NDkgNDEzLDkzNSAzODEsOTEyIDM1NSw4NzkgMzI5LDg0NiAzMDksODAyIDI5Niw3NDcgMjgyLDY5MiAyNzUsNjI0IDI3NSw1NDIgMjc1LDQ1OCAyODIsMzg5IDI5NywzMzQgMzEyLDI3OSAzMzIsMjM1IDM1OCwyMDIgMzgzLDE2OSA0MTQsMTQ2IDQ0OSwxMzMgNDg0LDEyMCA1MjIsMTEzIDU2MywxMTMgNjA5LDExMyA2NTEsMTIwIDY4OCwxMzMgNzI1LDE0NiA3NTcsMTY4IDc4MywyMDEgODA5LDIzNCA4MjksMjc4IDg0MywzMzMgODU3LDM4OCA4NjQsNDU4IDg2NCw1NDIgWiIvPgogICA8Z2x5cGggdW5pY29kZT0ibiIgaG9yaXotYWR2LXg9Ijg3NCIgZD0iTSA4MjUsMCBMIDgyNSw2ODYgQyA4MjUsNzM5IDgyMSw3ODMgODE0LDgxOCA4MDYsODUzIDc5Myw4ODIgNzc2LDkwNCA3NTksOTI1IDczNiw5NDEgNzA4LDk1MCA2NzksOTU5IDY0NCw5NjMgNjAyLDk2MyA1NTksOTYzIDUyMSw5NTYgNDg3LDk0MSA0NTIsOTI2IDQyMyw5MDQgMzk5LDg3NiAzNzQsODQ3IDM1NSw4MTIgMzQyLDc3MSAzMjksNzI5IDMyMiw2ODEgMzIyLDYyNyBMIDMyMiwwIDE0MiwwIDE0Miw4NTEgQyAxNDIsODc0IDE0Miw4OTggMTQyLDkyMyAxNDEsOTQ4IDE0MSw5NzEgMTQwLDk5NCAxMzksMTAxNiAxMzksMTAzNSAxMzgsMTA1MSAxMzcsMTA2NyAxMzcsMTA3NyAxMzYsMTA4MiBMIDMwNiwxMDgyIEMgMzA3LDEwNzkgMzA3LDEwNzAgMzA4LDEwNTUgMzA5LDEwNDAgMzEwLDEwMjQgMzExLDEwMDUgMzEyLDk4NiAzMTIsOTY2IDMxMyw5NDcgMzE0LDkyNyAzMTQsOTEwIDMxNCw4OTcgTCAzMTcsODk3IEMgMzM0LDkyOCAzNTMsOTU3IDM3NCw5ODIgMzk1LDEwMDcgNDE5LDEwMjkgNDQ2LDEwNDcgNDczLDEwNjQgNTA1LDEwNzggNTQwLDEwODggNTc1LDEwOTcgNjE2LDExMDIgNjYzLDExMDIgNzIzLDExMDIgNzc1LDEwOTUgODE4LDEwODAgODYxLDEwNjUgODk3LDEwNDMgOTI1LDEwMTIgOTUzLDk4MSA5NzQsOTQyIDk4Nyw4OTQgMTAwMCw4NDUgMTAwNiw3ODggMTAwNiw3MjEgTCAxMDA2LDAgODI1LDAgWiIvPgogICA8Z2x5cGggdW5pY29kZT0ibSIgaG9yaXotYWR2LXg9IjE0NTciIGQ9Ik0gNzY4LDAgTCA3NjgsNjg2IEMgNzY4LDczOSA3NjUsNzgzIDc1OCw4MTggNzUxLDg1MyA3NDAsODgyIDcyNSw5MDQgNzA5LDkyNSA2ODgsOTQxIDY2Myw5NTAgNjM4LDk1OSA2MDcsOTYzIDU3MCw5NjMgNTMyLDk2MyA0OTgsOTU2IDQ2Nyw5NDEgNDM2LDkyNiA0MTAsOTA0IDM4OSw4NzYgMzY3LDg0NyAzNTAsODEyIDMzOSw3NzEgMzI3LDcyOSAzMjEsNjgxIDMyMSw2MjcgTCAzMjEsMCAxNDIsMCAxNDIsODUxIEMgMTQyLDg3NCAxNDIsODk4IDE0Miw5MjMgMTQxLDk0OCAxNDEsOTcxIDE0MCw5OTQgMTM5LDEwMTYgMTM5LDEwMzUgMTM4LDEwNTEgMTM3LDEwNjcgMTM3LDEwNzcgMTM2LDEwODIgTCAzMDYsMTA4MiBDIDMwNywxMDc5IDMwNywxMDcwIDMwOCwxMDU1IDMwOSwxMDQwIDMxMCwxMDI0IDMxMSwxMDA1IDMxMiw5ODYgMzEyLDk2NiAzMTMsOTQ3IDMxNCw5MjcgMzE0LDkxMCAzMTQsODk3IEwgMzE3LDg5NyBDIDMzMyw5MjggMzUwLDk1NyAzNjksOTgyIDM4OCwxMDA3IDQxMCwxMDI5IDQzNSwxMDQ3IDQ2MCwxMDY0IDQ4OCwxMDc4IDUyMSwxMDg4IDU1MywxMDk3IDU5MCwxMTAyIDYzMywxMTAyIDcxNSwxMTAyIDc4MCwxMDg2IDgyOCwxMDUzIDg3NSwxMDIwIDkwOCw5NjggOTI3LDg5NyBMIDkzMCw4OTcgQyA5NDYsOTI4IDk2NCw5NTcgOTg0LDk4MiAxMDA0LDEwMDcgMTAyNywxMDI5IDEwNTQsMTA0NyAxMDgxLDEwNjQgMTExMSwxMDc4IDExNDQsMTA4OCAxMTc3LDEwOTcgMTIxNSwxMTAyIDEyNTgsMTEwMiAxMzEzLDExMDIgMTM2MCwxMDk1IDE0MDAsMTA4MCAxNDM5LDEwNjUgMTQ3MiwxMDQzIDE0OTcsMTAxMiAxNTIyLDk4MSAxNTQxLDk0MiAxNTUzLDg5NCAxNTY1LDg0NSAxNTcxLDc4OCAxNTcxLDcyMSBMIDE1NzEsMCAxMzkzLDAgMTM5Myw2ODYgQyAxMzkzLDczOSAxMzkwLDc4MyAxMzgzLDgxOCAxMzc2LDg1MyAxMzY1LDg4MiAxMzUwLDkwNCAxMzM0LDkyNSAxMzEzLDk0MSAxMjg4LDk1MCAxMjYzLDk1OSAxMjMyLDk2MyAxMTk1LDk2MyAxMTU3LDk2MyAxMTIzLDk1NiAxMDkyLDk0MiAxMDYxLDkyNyAxMDM1LDkwNiAxMDE0LDg3OCA5OTIsODUwIDk3NSw4MTUgOTY0LDc3MyA5NTIsNzMxIDk0Niw2ODIgOTQ2LDYyNyBMIDk0NiwwIDc2OCwwIFoiLz4KICAgPGdseXBoIHVuaWNvZGU9ImwiIGhvcml6LWFkdi14PSIxODciIGQ9Ik0gMTM4LDAgTCAxMzgsMTQ4NCAzMTgsMTQ4NCAzMTgsMCAxMzgsMCBaIi8+CiAgIDxnbHlwaCB1bmljb2RlPSJrIiBob3Jpei1hZHYteD0iOTAxIiBkPSJNIDgxNiwwIEwgNDUwLDQ5NCAzMTgsMzg1IDMxOCwwIDEzOCwwIDEzOCwxNDg0IDMxOCwxNDg0IDMxOCw1NTcgNzkzLDEwODIgMTAwNCwxMDgyIDU2NSw2MTcgMTAyNywwIDgxNiwwIFoiLz4KICAgPGdseXBoIHVuaWNvZGU9ImkiIGhvcml6LWFkdi14PSIxODciIGQ9Ik0gMTM3LDEzMTIgTCAxMzcsMTQ4NCAzMTcsMTQ4NCAzMTcsMTMxMiAxMzcsMTMxMiBaIE0gMTM3LDAgTCAxMzcsMTA4MiAzMTcsMTA4MiAzMTcsMCAxMzcsMCBaIi8+CiAgIDxnbHlwaCB1bmljb2RlPSJoIiBob3Jpei1hZHYteD0iODc0IiBkPSJNIDMxNyw4OTcgQyAzMzcsOTM0IDM1OSw5NjUgMzgyLDk5MSA0MDUsMTAxNiA0MzEsMTAzNyA0NTksMTA1NCA0ODcsMTA3MSA1MTgsMTA4MyA1NTEsMTA5MSA1ODQsMTA5OCA2MjIsMTEwMiA2NjMsMTEwMiA3MzIsMTEwMiA3ODksMTA5MyA4MzQsMTA3NCA4NzgsMTA1NSA5MTMsMTAyOSA5MzksOTk2IDk2NCw5NjIgOTgyLDkyMiA5OTIsODc1IDEwMDEsODI4IDEwMDYsNzc3IDEwMDYsNzIxIEwgMTAwNiwwIDgyNSwwIDgyNSw2ODYgQyA4MjUsNzMyIDgyMiw3NzIgODE3LDgwNyA4MTEsODQyIDgwMCw4NzEgNzg0LDg5NCA3NjgsOTE3IDc0NSw5MzQgNzE2LDk0NiA2ODcsOTU3IDY0OSw5NjMgNjAyLDk2MyA1NTksOTYzIDUyMSw5NTUgNDg3LDk0MCA0NTIsOTI1IDQyMyw5MDMgMzk5LDg3NSAzNzQsODQ3IDM1NSw4MTMgMzQyLDc3MyAzMjksNzMzIDMyMiw2ODggMzIyLDYzOCBMIDMyMiwwIDE0MiwwIDE0MiwxNDg0IDMyMiwxNDg0IDMyMiwxMDk4IEMgMzIyLDEwNzYgMzIyLDEwNTQgMzIxLDEwMzIgMzIwLDEwMTAgMzIwLDk5MCAzMTksOTcxIDMxOCw5NTIgMzE3LDkzNyAzMTYsOTI0IDMxNSw5MTEgMzE1LDkwMiAzMTQsODk3IEwgMzE3LDg5NyBaIi8+CiAgIDxnbHlwaCB1bmljb2RlPSJnIiBob3Jpei1hZHYteD0iOTI3IiBkPSJNIDU0OCwtNDI1IEMgNDg2LC00MjUgNDMxLC00MTkgMzgzLC00MDYgMzM1LC0zOTMgMjk0LC0zNzUgMjYwLC0zNTIgMjI2LC0zMjggMTk4LC0zMDAgMTc3LC0yNjcgMTU2LC0yMzQgMTQwLC0xOTggMTMxLC0xNTggTCAzMTIsLTEzMiBDIDMyNCwtMTgyIDM1MSwtMjIwIDM5MiwtMjQ4IDQzMywtMjc0IDQ4NiwtMjg4IDU1MywtMjg4IDU5NCwtMjg4IDYzMSwtMjgyIDY2NCwtMjcxIDY5NywtMjYwIDcyNiwtMjQxIDc0OSwtMjE3IDc3MiwtMTkxIDc5MCwtMTU5IDgwMywtMTE5IDgxNiwtNzkgODIyLC0zMCA4MjIsMjcgTCA4MjIsMjAxIDgyMCwyMDEgQyA4MDcsMTc0IDc5MCwxNDggNzcxLDEyMyA3NTEsOTggNzI3LDc1IDY5OSw1NiA2NzAsMzcgNjM3LDIxIDYwMCwxMCA1NjMsLTIgNTIwLC04IDQ3MiwtOCA0MDMsLTggMzQ1LDQgMjk2LDI3IDI0Nyw1MCAyMDcsODQgMTc2LDEzMCAxNDUsMTc2IDEyMiwyMzMgMTA4LDMwMiA5MywzNzAgODYsNDQ5IDg2LDUzOSA4Niw2MjYgOTMsNzA0IDEwOCw3NzMgMTIyLDg0MiAxNDUsOTAxIDE3OCw5NTAgMjEwLDk5OCAyNTIsMTAzNSAzMDQsMTA2MSAzNTUsMTA4NiA0MTgsMTA5OSA0OTIsMTA5OSA1NjksMTA5OSA2MzUsMTA4MiA2OTIsMTA0NyA3NDgsMTAxMiA3OTEsOTYyIDgyMiw4OTcgTCA4MjQsODk3IEMgODI0LDkxNCA4MjUsOTMyIDgyNiw5NTMgODI3LDk3NCA4MjgsOTkzIDgyOSwxMDEyIDgzMCwxMDMwIDgzMSwxMDQ2IDgzMiwxMDU5IDgzMywxMDcyIDgzNSwxMDgwIDgzNiwxMDgyIEwgMTAwNywxMDgyIEMgMTAwNiwxMDc2IDEwMDYsMTA2NiAxMDA1LDEwNTIgMTAwNCwxMDM3IDEwMDQsMTAyMCAxMDAzLDEwMDAgMTAwMiw5ODAgMTAwMiw5NTggMTAwMiw5MzQgMTAwMSw5MDkgMTAwMSw4ODQgMTAwMSw4NTggTCAxMDAxLDMxIEMgMTAwMSwtMTIwIDk2NCwtMjM0IDg5MCwtMzExIDgxNSwtMzg3IDcwMSwtNDI1IDU0OCwtNDI1IFogTSA4MjIsNTQxIEMgODIyLDYxNiA4MTQsNjgxIDc5OCw3MzUgNzgxLDc4OCA3NjAsODMyIDczMyw4NjYgNzA2LDkwMCA2NzYsOTI1IDY0Miw5NDEgNjA3LDk1NyA1NzIsOTY1IDUzNiw5NjUgNDkwLDk2NSA0NTEsOTU3IDQxOCw5NDEgMzg1LDkyNSAzNTcsOTAwIDMzNiw4NjYgMzE0LDgzMSAyOTgsNzg3IDI4OCw3MzQgMjc3LDY4MCAyNzIsNjE2IDI3Miw1NDEgMjcyLDQ2MyAyNzcsMzk4IDI4OCwzNDUgMjk4LDI5MiAzMTQsMjQ5IDMzNSwyMTYgMzU2LDE4MyAzODMsMTYwIDQxNiwxNDYgNDQ5LDEzMiA0ODgsMTI1IDUzMywxMjUgNTY5LDEyNSA2MDQsMTMzIDYzOSwxNDggNjczLDE2MyA3MDQsMTg4IDczMSwyMjEgNzU4LDI1NCA3ODAsMjk3IDc5NywzNTAgODE0LDQwMyA4MjIsNDY2IDgyMiw1NDEgWiIvPgogICA8Z2x5cGggdW5pY29kZT0iZiIgaG9yaXotYWR2LXg9IjU1NyIgZD0iTSAzNjEsOTUxIEwgMzYxLDAgMTgxLDAgMTgxLDk1MSAyOSw5NTEgMjksMTA4MiAxODEsMTA4MiAxODEsMTIwNCBDIDE4MSwxMjQzIDE4NSwxMjgwIDE5MiwxMzE0IDE5OSwxMzQ3IDIxMywxMzc3IDIzMywxNDAyIDI1MiwxNDI3IDI3OSwxNDQ2IDMxMywxNDYxIDM0NywxNDc1IDM5MSwxNDgyIDQ0NSwxNDgyIDQ2NiwxNDgyIDQ4OSwxNDgxIDUxMiwxNDc5IDUzNSwxNDc3IDU1NSwxNDc0IDU3MiwxNDcwIEwgNTcyLDEzMzMgQyA1NjEsMTMzNSA1NDgsMTMzNyA1MzMsMTMzOSA1MTgsMTM0MCA1MDQsMTM0MSA0OTIsMTM0MSA0NjUsMTM0MSA0NDQsMTMzNyA0MjcsMTMzMCA0MTAsMTMyMyAzOTYsMTMxMiAzODcsMTI5OSAzNzcsMTI4NSAzNzAsMTI2OCAzNjcsMTI0OCAzNjMsMTIyOCAzNjEsMTIwNSAzNjEsMTE3OSBMIDM2MSwxMDgyIDU3MiwxMDgyIDU3Miw5NTEgMzYxLDk1MSBaIi8+CiAgIDxnbHlwaCB1bmljb2RlPSJlIiBob3Jpei1hZHYteD0iOTgwIiBkPSJNIDI3Niw1MDMgQyAyNzYsNDQ2IDI4MiwzOTQgMjk0LDM0NyAzMDUsMjk5IDMyMywyNTggMzQ4LDIyNCAzNzIsMTg5IDQwMywxNjMgNDQxLDE0NCA0NzksMTI1IDUyNSwxMTUgNTc4LDExNSA2NTYsMTE1IDcxOSwxMzEgNzY2LDE2MiA4MTMsMTkzIDg0NCwyMzMgODYxLDI4MSBMIDEwMTksMjM2IEMgMTAwOCwyMDYgOTkyLDE3NiA5NzIsMTQ2IDk1MSwxMTUgOTI0LDg4IDg5MCw2NCA4NTYsMzkgODE0LDE5IDc2Myw0IDcxMiwtMTIgNjUwLC0yMCA1NzgsLTIwIDQxOCwtMjAgMjk2LDI4IDIxMywxMjMgMTI5LDIxOCA4NywzNjAgODcsNTQ4IDg3LDY0OSAxMDAsNzM1IDEyNSw4MDYgMTUwLDg3NiAxODUsOTMzIDIyOSw5NzcgMjczLDEwMjEgMzI0LDEwNTMgMzgzLDEwNzMgNDQyLDEwOTIgNTA0LDExMDIgNTcxLDExMDIgNjYyLDExMDIgNzM4LDEwODcgNzk5LDEwNTggODYwLDEwMjkgOTA5LDk4OCA5NDYsOTM3IDk4Myw4ODUgMTAwOSw4MjQgMTAyNSw3NTQgMTA0MCw2ODQgMTA0OCw2MDggMTA0OCw1MjcgTCAxMDQ4LDUwMyAyNzYsNTAzIFogTSA4NjIsNjQxIEMgODUyLDc1NSA4MjMsODM4IDc3NSw4OTEgNzI3LDk0MyA2NTgsOTY5IDU2OCw5NjkgNTM4LDk2OSA1MDcsOTY0IDQ3NCw5NTUgNDQxLDk0NSA0MTAsOTI4IDM4Miw5MDMgMzU0LDg3OCAzMzAsODQ1IDMxMSw4MDMgMjkyLDc2MCAyODEsNzA2IDI3OCw2NDEgTCA4NjIsNjQxIFoiLz4KICAgPGdseXBoIHVuaWNvZGU9ImQiIGhvcml6LWFkdi14PSI5MjciIGQ9Ik0gODIxLDE3NCBDIDc4OCwxMDUgNzQ0LDU1IDY4OSwyNSA2MzQsLTUgNTY1LC0yMCA0ODQsLTIwIDM0NywtMjAgMjQ3LDI2IDE4MywxMTggMTE4LDIxMCA4NiwzNDkgODYsNTM2IDg2LDkxMyAyMTksMTEwMiA0ODQsMTEwMiA1NjYsMTEwMiA2MzQsMTA4NyA2ODksMTA1NyA3NDQsMTAyNyA3ODgsOTc5IDgyMSw5MTQgTCA4MjMsOTE0IEMgODIzLDkyMSA4MjMsOTMxIDgyMyw5NDYgODIyLDk2MCA4MjIsOTc1IDgyMiw5OTEgODIxLDEwMDYgODIxLDEwMjEgODIxLDEwMzUgODIxLDEwNDkgODIxLDEwNTkgODIxLDEwNjUgTCA4MjEsMTQ4NCAxMDAxLDE0ODQgMTAwMSwyMjMgQyAxMDAxLDE5NyAxMDAxLDE3MiAxMDAyLDE0OCAxMDAyLDEyNCAxMDAyLDEwMiAxMDAzLDgyIDEwMDQsNjIgMTAwNCw0NSAxMDA1LDMxIDEwMDYsMTYgMTAwNiw2IDEwMDcsMCBMIDgzNSwwIEMgODM0LDcgODMzLDE2IDgzMiwyOSA4MzEsNDEgODMwLDU1IDgyOSw3MSA4MjgsODcgODI3LDEwNCA4MjYsMTIyIDgyNSwxMzkgODI1LDE1NyA4MjUsMTc0IEwgODIxLDE3NCBaIE0gMjc1LDU0MiBDIDI3NSw0NjcgMjgwLDQwMyAyODksMzUwIDI5OCwyOTcgMzEzLDI1MyAzMzQsMjE5IDM1NSwxODQgMzgxLDE1OSA0MTMsMTQzIDQ0NSwxMjcgNDg0LDExOSA1MzAsMTE5IDU3NywxMTkgNjE5LDEyNyA2NTYsMTQyIDY5MiwxNTcgNzIyLDE4MiA3NDcsMjE3IDc3MSwyNTEgNzg5LDI5NiA4MDIsMzUxIDgxNSw0MDYgODIxLDQ3NCA4MjEsNTU0IDgyMSw2MzEgODE1LDY5NiA4MDIsNzQ5IDc4OSw4MDIgNzcxLDg0NCA3NDYsODc3IDcyMSw5MTAgNjkxLDkzMyA2NTYsOTQ4IDYyMCw5NjIgNTc5LDk2OSA1MzIsOTY5IDQ4OCw5NjkgNDUwLDk2MSA0MTgsOTQ2IDM4Niw5MzEgMzU5LDkwNiAzMzgsODcyIDMxNyw4MzggMzAxLDc5NCAyOTEsNzQwIDI4MCw2ODUgMjc1LDYxOSAyNzUsNTQyIFoiLz4KICAgPGdseXBoIHVuaWNvZGU9ImMiIGhvcml6LWFkdi14PSI5MDEiIGQ9Ik0gMjc1LDU0NiBDIDI3NSw0ODQgMjgwLDQyNyAyODksMzc1IDI5OCwzMjMgMzEzLDI3OCAzMzQsMjQxIDM1NSwyMDMgMzg0LDE3NCA0MTksMTUzIDQ1NCwxMzIgNDk3LDEyMiA1NDgsMTIyIDYxMiwxMjIgNjY2LDEzOSA3MDksMTczIDc1MiwyMDYgNzc4LDI1OCA3ODgsMzI4IEwgOTcwLDMyOCBDIDk2NCwyODMgOTUxLDIzOSA5MzEsMTk3IDkxMSwxNTUgODg0LDExOCA4NTAsODYgODE1LDU0IDc3MywyOCA3MjQsOSA2NzUsLTEwIDYxOCwtMjAgNTUzLC0yMCA0NjgsLTIwIDM5NiwtNiAzMzcsMjMgMjc4LDUyIDIzMCw5MSAxOTMsMTQyIDE1NiwxOTIgMTI5LDI1MSAxMTIsMzIwIDk1LDM4OCA4Nyw0NjIgODcsNTQyIDg3LDYxNSA5Myw2NzkgMTA1LDczNSAxMTcsNzkwIDEzNCw4MzkgMTU2LDg4MSAxNzcsOTIyIDIwMyw5NTcgMjMyLDk4NiAyNjEsMTAxNCAyOTMsMTAzNyAzMjgsMTA1NCAzNjIsMTA3MSAzOTgsMTA4MyA0MzYsMTA5MSA0NzQsMTA5OCA1MTIsMTEwMiA1NTEsMTEwMiA2MTIsMTEwMiA2NjYsMTA5NCA3MTMsMTA3NyA3NjAsMTA2MCA4MDEsMTAzOCA4MzYsMTAwOSA4NzAsOTgwIDg5OCw5NDUgOTE5LDkwNiA5NDAsODY3IDk1NSw4MjQgOTY0LDc3OSBMIDc3OSw3NjUgQyA3NzAsODI1IDc0Niw4NzMgNzA4LDkwOCA2NzAsOTQzIDYxNiw5NjEgNTQ2LDk2MSA0OTUsOTYxIDQ1Miw5NTMgNDE4LDkzNiAzODMsOTE5IDM1NSw4OTMgMzM0LDg1OSAzMTMsODI0IDI5OCw3ODEgMjg5LDcyOSAyODAsNjc3IDI3NSw2MTYgMjc1LDU0NiBaIi8+CiAgIDxnbHlwaCB1bmljb2RlPSJiIiBob3Jpei1hZHYteD0iOTUzIiBkPSJNIDEwNTMsNTQ2IEMgMTA1MywxNjkgOTIwLC0yMCA2NTUsLTIwIDU3MywtMjAgNTA1LC01IDQ1MSwyNSAzOTYsNTQgMzUyLDEwMiAzMTgsMTY4IEwgMzE2LDE2OCBDIDMxNiwxNTEgMzE2LDEzMyAzMTUsMTE0IDMxNCw5NSAzMTMsNzggMzEyLDYyIDMxMSw0NiAzMTAsMzIgMzA5LDIxIDMwOCwxMCAzMDcsMyAzMDYsMCBMIDEzMiwwIEMgMTMzLDYgMTMzLDE2IDEzNCwzMSAxMzUsNDUgMTM1LDYyIDEzNiw4MiAxMzcsMTAyIDEzNywxMjQgMTM4LDE0OCAxMzgsMTcyIDEzOCwxOTcgMTM4LDIyMyBMIDEzOCwxNDg0IDMxOCwxNDg0IDMxOCwxMDYxIEMgMzE4LDEwNDEgMzE4LDEwMjIgMzE4LDEwMDQgMzE3LDk4NSAzMTcsOTY5IDMxNiw5NTUgMzE1LDkzOCAzMTUsOTIzIDMxNCw5MDggTCAzMTgsOTA4IEMgMzUxLDk3NyAzOTYsMTAyNyA0NTEsMTA1NyA1MDYsMTA4NyA1NzQsMTEwMiA2NTUsMTEwMiA3OTIsMTEwMiA4OTIsMTA1NiA5NTcsOTY0IDEwMjEsODcyIDEwNTMsNzMzIDEwNTMsNTQ2IFogTSA4NjQsNTQwIEMgODY0LDYxNSA4NTksNjc5IDg1MCw3MzIgODQxLDc4NSA4MjYsODI5IDgwNSw4NjQgNzg0LDg5OCA3NTgsOTIzIDcyNiw5MzkgNjk0LDk1NSA2NTUsOTYzIDYwOSw5NjMgNTYyLDk2MyA1MjAsOTU1IDQ4NCw5NDAgNDQ3LDkyNSA0MTcsOTAwIDM5Myw4NjYgMzY4LDgzMiAzNTAsNzg3IDMzNyw3MzIgMzI0LDY3NyAzMTgsNjA5IDMxOCw1MjkgMzE4LDQ1MiAzMjQsMzg3IDMzNywzMzQgMzUwLDI4MSAzNjgsMjM5IDM5MywyMDYgNDE3LDE3MyA0NDcsMTQ5IDQ4MywxMzUgNTE5LDEyMCA1NjAsMTEzIDYwNywxMTMgNjUxLDExMyA2ODksMTIxIDcyMSwxMzYgNzUzLDE1MSA3ODAsMTc2IDgwMSwyMTAgODIyLDI0NCA4MzgsMjg4IDg0OSwzNDMgODU5LDM5NyA4NjQsNDYzIDg2NCw1NDAgWiIvPgogICA8Z2x5cGggdW5pY29kZT0iYSIgaG9yaXotYWR2LXg9IjEwNjAiIGQ9Ik0gNDE0LC0yMCBDIDMwNSwtMjAgMjI0LDkgMTY5LDY2IDExNCwxMjQgODcsMjAzIDg3LDMwMyA4NywzNzUgMTAxLDQzNCAxMjgsNDgwIDE1NSw1MjYgMTkwLDU2MiAyMzQsNTg4IDI3Nyw2MTQgMzI3LDYzMiAzODMsNjQyIDQzOSw2NTIgNDk2LDY1NyA1NTQsNjU3IEwgNzk3LDY1NyA3OTcsNzE3IEMgNzk3LDc2MiA3OTIsODAwIDc4Myw4MzIgNzc0LDg2MyA3NTksODg5IDc0MCw5MDggNzIxLDkyOCA2OTcsOTQyIDY2OCw5NTEgNjM5LDk2MCA2MDQsOTY1IDU2NSw5NjUgNTMwLDk2NSA0OTksOTYzIDQ3MSw5NTggNDQzLDk1MyA0MTksOTQ0IDM5OCw5MzEgMzc3LDkxOCAzNjEsOTAwIDM0OCw4NzggMzM1LDg1NSAzMjcsODI3IDMyMyw3OTMgTCAxMzUsODEwIEMgMTQyLDg1MyAxNTQsODkyIDE3Myw5MjggMTkyLDk2MyAyMTgsOTk0IDI1MywxMDIwIDI4NywxMDQ2IDMzMCwxMDY2IDM4MiwxMDgxIDQzMywxMDk1IDQ5NiwxMTAyIDU2OSwxMTAyIDcwNSwxMTAyIDgwNywxMDcxIDg3NiwxMDA5IDk0NSw5NDYgOTc5LDg1NiA5NzksNzM4IEwgOTc5LDI3MiBDIDk3OSwyMTkgOTg2LDE3OSAxMDAwLDE1MiAxMDE0LDEyNSAxMDQxLDExMSAxMDgwLDExMSAxMDkwLDExMSAxMTAwLDExMiAxMTEwLDExMyAxMTIwLDExNCAxMTMwLDExNiAxMTM5LDExOCBMIDExMzksNiBDIDExMTYsMSAxMDk0LC0zIDEwNzIsLTYgMTA0OSwtOSAxMDI1LC0xMCAxMDAwLC0xMCA5NjYsLTEwIDkzNywtNSA5MTMsNCA4ODgsMTMgODY4LDI2IDg1Myw0NSA4MzgsNjMgODI2LDg2IDgxOCwxMTMgODEwLDE0MCA4MDUsMTcxIDgwMywyMDcgTCA3OTcsMjA3IEMgNzc4LDE3MiA3NTcsMTQxIDczNCwxMTMgNzExLDg1IDY4NCw2MSA2NTMsNDIgNjIyLDIyIDU4OCw3IDU0OSwtNCA1MTAsLTE1IDQ2NSwtMjAgNDE0LC0yMCBaIE0gNDU1LDExNSBDIDUxMiwxMTUgNTYzLDEyNSA2MDYsMTQ2IDY0OSwxNjcgNjg0LDE5NCA3MTMsMjI2IDc0MSwyNTkgNzYyLDI5NCA3NzYsMzMyIDc5MCwzNzEgNzk3LDQwOCA3OTcsNDQzIEwgNzk3LDUzMSA2MDAsNTMxIEMgNTU2LDUzMSA1MTQsNTI4IDQ3NSw1MjIgNDM1LDUxNyA0MDAsNTA2IDM3MCw0ODkgMzQwLDQ3MiAzMTYsNDQ5IDI5OSw0MTggMjgxLDM4OCAyNzIsMzQ5IDI3MiwzMDAgMjcyLDI0MSAyODgsMTk1IDMyMCwxNjMgMzUxLDEzMSAzOTYsMTE1IDQ1NSwxMTUgWiIvPgogICA8Z2x5cGggdW5pY29kZT0iUyIgaG9yaXotYWR2LXg9IjExOTIiIGQ9Ik0gMTI3MiwzODkgQyAxMjcyLDMzMCAxMjYxLDI3NSAxMjM4LDIyNSAxMjE1LDE3NSAxMTc5LDEzMiAxMTMxLDk2IDEwODMsNTkgMTAyMywzMSA5NTAsMTEgODc3LC0xMCA3OTAsLTIwIDY5MCwtMjAgNTE1LC0yMCAzNzgsMTEgMjgwLDcyIDE4MiwxMzMgMTIwLDIyMiA5MywzMzggTCAyNzgsMzc1IEMgMjg3LDMzOCAzMDIsMzA1IDMyMSwyNzUgMzQwLDI0NSAzNjcsMjE5IDQwMCwxOTggNDMzLDE3NiA0NzMsMTU5IDUyMiwxNDcgNTcxLDEzNSA2MjksMTI5IDY5NywxMjkgNzU0LDEyOSA4MDYsMTM0IDg1MywxNDQgOTAwLDE1MyA5NDEsMTY4IDk3NSwxODggMTAwOSwyMDggMTAzNiwyMzQgMTA1NSwyNjYgMTA3NCwyOTcgMTA4MywzMzUgMTA4MywzNzkgMTA4Myw0MjUgMTA3Myw0NjIgMTA1Miw0OTEgMTAzMSw1MjAgMTAwMSw1NDMgOTYzLDU2MiA5MjUsNTgxIDg4MCw1OTYgODI3LDYwOSA3NzQsNjIyIDcxNiw2MzUgNjUyLDY1MCA2MTMsNjU5IDU3Myw2NjggNTM0LDY3OSA0OTQsNjg5IDQ1Niw3MDEgNDIwLDcxNiAzODMsNzMwIDM0OSw3NDcgMzE3LDc2NiAyODUsNzg1IDI1Nyw4MDkgMjM0LDgzNiAyMTEsODYzIDE5Miw4OTQgMTc5LDkzMCAxNjYsOTY1IDE1OSwxMDA2IDE1OSwxMDUzIDE1OSwxMTIwIDE3MywxMTc3IDIwMCwxMjI1IDIyNywxMjcyIDI2NCwxMzExIDMxMiwxMzQyIDM2MCwxMzczIDQxNywxMzk1IDQ4MiwxNDA5IDU0NywxNDIzIDYxOCwxNDMwIDY5NCwxNDMwIDc4MSwxNDMwIDg1NiwxNDIzIDkxOCwxNDEwIDk4MCwxMzk2IDEwMzIsMTM3NSAxMDc1LDEzNDggMTExOCwxMzIxIDExNTIsMTI4NyAxMTc4LDEyNDcgMTIwMywxMjA2IDEyMjQsMTE1OSAxMjM5LDExMDYgTCAxMDUxLDEwNzMgQyAxMDQyLDExMDcgMTAyOCwxMTM3IDEwMTEsMTE2NCA5OTMsMTE5MSA5NzAsMTIxMyA5NDEsMTIzMSA5MTIsMTI0OSA4NzgsMTI2MyA4MzcsMTI3MiA3OTYsMTI4MSA3NDcsMTI4NiA2OTIsMTI4NiA2MjcsMTI4NiA1NzIsMTI4MCA1MjgsMTI2OSA0ODMsMTI1NyA0NDgsMTI0MSA0MjEsMTIyMSAzOTQsMTIwMSAzNzQsMTE3OCAzNjMsMTE1MSAzNTEsMTEyNCAzNDUsMTA5NCAzNDUsMTA2MyAzNDUsMTAyMSAzNTYsOTg3IDM3Nyw5NjAgMzk4LDkzMyA0MjYsOTEwIDQ2Miw4OTIgNDk4LDg3NCA1NDAsODU5IDU4Nyw4NDcgNjM0LDgzNSA2ODUsODIzIDczOCw4MTEgNzgxLDgwMSA4MjUsNzkxIDg2OCw3ODEgOTExLDc3MCA5NTIsNzU4IDk5MSw3NDQgMTAzMCw3MjkgMTA2Nyw3MTIgMTEwMiw2OTMgMTEzNiw2NzQgMTE2Niw2NTAgMTE5MSw2MjIgMTIxNiw1OTQgMTIzNiw1NjEgMTI1MSw1MjMgMTI2NSw0ODUgMTI3Miw0NDAgMTI3MiwzODkgWiIvPgogICA8Z2x5cGggdW5pY29kZT0iTyIgaG9yaXotYWR2LXg9IjE0MzAiIGQ9Ik0gMTQ5NSw3MTEgQyAxNDk1LDYwMSAxNDc5LDUwMSAxNDQ4LDQxMSAxNDE2LDMyMSAxMzcwLDI0NCAxMzEwLDE4MCAxMjUwLDExNiAxMTc3LDY3IDEwOTAsMzIgMTAwMywtMyA5MDUsLTIwIDc5NSwtMjAgNjc5LC0yMCA1NzcsLTIgNDkwLDM1IDQwMyw3MSAzMzAsMTIyIDI3MiwxODcgMjE0LDI1MiAxNzAsMzI5IDE0MSw0MTggMTEyLDUwNyA5Nyw2MDUgOTcsNzExIDk3LDgyMSAxMTIsOTIwIDE0MywxMDA5IDE3NCwxMDk4IDIxOSwxMTczIDI3OCwxMjM2IDMzNywxMjk4IDQxMSwxMzQ2IDQ5OCwxMzgwIDU4NSwxNDEzIDY4NCwxNDMwIDc5NywxNDMwIDkwOSwxNDMwIDEwMDksMTQxMyAxMDk2LDEzNzkgMTE4MywxMzQ1IDEyNTYsMTI5NyAxMzE1LDEyMzQgMTM3NCwxMTcxIDE0MTgsMTA5NiAxNDQ5LDEwMDcgMTQ4MCw5MTggMTQ5NSw4MjAgMTQ5NSw3MTEgWiBNIDEzMDAsNzExIEMgMTMwMCw3OTYgMTI4OSw4NzMgMTI2OCw5NDIgMTI0NiwxMDExIDEyMTQsMTA3MSAxMTcyLDExMjAgMTEyOSwxMTY5IDEwNzcsMTIwNyAxMDE0LDEyMzQgOTUxLDEyNjEgODc5LDEyNzQgNzk3LDEyNzQgNzEzLDEyNzQgNjM5LDEyNjEgNTc2LDEyMzQgNTEzLDEyMDcgNDYwLDExNjkgNDE4LDExMjAgMzc1LDEwNzEgMzQ0LDEwMTEgMzIzLDk0MiAzMDIsODczIDI5MSw3OTYgMjkxLDcxMSAyOTEsNjI2IDMwMiw1NDkgMzI0LDQ3OSAzNDUsNDA4IDM3NywzNDggNDIwLDI5NyA0NjIsMjQ2IDUxNSwyMDYgNTc4LDE3OCA2NDEsMTQ5IDcxMywxMzUgNzk1LDEzNSA4ODMsMTM1IDk1OSwxNDkgMTAyMywxNzggMTA4NiwyMDcgMTEzOSwyNDcgMTE4MCwyOTggMTIyMSwzNDkgMTI1MSw0MDkgMTI3MSw0ODAgMTI5MCw1NTEgMTMwMCw2MjggMTMwMCw3MTEgWiIvPgogICA8Z2x5cGggdW5pY29kZT0iQyIgaG9yaXotYWR2LXg9IjEzMjQiIGQ9Ik0gNzkyLDEyNzQgQyA3MTIsMTI3NCA2NDEsMTI2MSA1ODAsMTIzNCA1MTgsMTIwNyA0NjYsMTE2OSA0MjUsMTEyMCAzODMsMTA3MSAzNTEsMTAxMSAzMzAsOTQyIDMwOSw4NzMgMjk4LDc5NiAyOTgsNzExIDI5OCw2MjYgMzEwLDU0OSAzMzMsNDc5IDM1Niw0MDggMzg5LDM0OCA0MzIsMjk3IDQ3NSwyNDYgNTI3LDIwNyA1OTAsMTc5IDY1MiwxNTEgNzIyLDEzNyA4MDAsMTM3IDg1NSwxMzcgOTA1LDE0NCA5NTAsMTU5IDk5NSwxNzMgMTAzNSwxOTMgMTA3MiwyMTkgMTEwOCwyNDUgMTE0MCwyNzYgMTE2OSwzMTIgMTE5OCwzNDcgMTIyMywzODcgMTI0NSw0MzAgTCAxNDAxLDM1MiBDIDEzNzYsMjk5IDEzNDQsMjUwIDEzMDcsMjA1IDEyNzAsMTYwIDEyMjYsMTIwIDExNzYsODcgMTEyNSw1NCAxMDY4LDI4IDEwMDUsOSA5NDEsLTEwIDg3MCwtMjAgNzkxLC0yMCA2NzcsLTIwIDU3NywtMiA0OTIsMzUgNDA2LDcxIDMzNCwxMjIgMjc3LDE4NyAyMTksMjUyIDE3NiwzMjkgMTQ3LDQxOCAxMTgsNTA3IDEwNCw2MDUgMTA0LDcxMSAxMDQsODIxIDExOSw5MjAgMTUwLDEwMDkgMTgwLDEwOTggMjI0LDExNzMgMjgzLDEyMzYgMzQxLDEyOTggNDEzLDEzNDYgNDk4LDEzODAgNTgzLDE0MTMgNjgxLDE0MzAgNzkwLDE0MzAgOTQwLDE0MzAgMTA2NSwxNDAxIDExNjYsMTM0MiAxMjY3LDEyODMgMTM0MSwxMTk2IDEzODgsMTA4MSBMIDEyMDcsMTAyMSBDIDExOTQsMTA1NCAxMTc2LDEwODYgMTE1MywxMTE3IDExMzAsMTE0NyAxMTAyLDExNzQgMTA2OCwxMTk3IDEwMzQsMTIyMCA5OTQsMTIzOSA5NDksMTI1MyA5MDMsMTI2NyA4NTEsMTI3NCA3OTIsMTI3NCBaIi8+CiAgIDxnbHlwaCB1bmljb2RlPSIgIiBob3Jpei1hZHYteD0iNTU2Ii8+CiAgPC9mb250PgogPC9kZWZzPgogPGRlZnMgY2xhc3M9IlRleHRTaGFwZUluZGV4Ij4KICA8ZyBvb286c2xpZGU9ImlkMSIgb29vOmlkLWxpc3Q9ImlkMyBpZDQgaWQ1IGlkNiBpZDcgaWQ4IGlkOSBpZDEwIGlkMTEgaWQxMiBpZDEzIGlkMTQgaWQxNSBpZDE2IGlkMTcgaWQxOCBpZDE5Ii8+CiA8L2RlZnM+CiA8ZGVmcyBjbGFzcz0iRW1iZWRkZWRCdWxsZXRDaGFycyI+CiAgPGcgaWQ9ImJ1bGxldC1jaGFyLXRlbXBsYXRlKDU3MzU2KSIgdHJhbnNmb3JtPSJzY2FsZSgwLjAwMDQ4ODI4MTI1LC0wLjAwMDQ4ODI4MTI1KSI+CiAgIDxwYXRoIGQ9Ik0gNTgwLDExNDEgTCAxMTYzLDU3MSA1ODAsMCAtNCw1NzEgNTgwLDExNDEgWiIvPgogIDwvZz4KICA8ZyBpZD0iYnVsbGV0LWNoYXItdGVtcGxhdGUoNTczNTQpIiB0cmFuc2Zvcm09InNjYWxlKDAuMDAwNDg4MjgxMjUsLTAuMDAwNDg4MjgxMjUpIj4KICAgPHBhdGggZD0iTSA4LDExMjggTCAxMTM3LDExMjggMTEzNywwIDgsMCA4LDExMjggWiIvPgogIDwvZz4KICA8ZyBpZD0iYnVsbGV0LWNoYXItdGVtcGxhdGUoMTAxNDYpIiB0cmFuc2Zvcm09InNjYWxlKDAuMDAwNDg4MjgxMjUsLTAuMDAwNDg4MjgxMjUpIj4KICAgPHBhdGggZD0iTSAxNzQsMCBMIDYwMiw3MzkgMTc0LDE0ODEgMTQ1Niw3MzkgMTc0LDAgWiBNIDEzNTgsNzM5IEwgMzA5LDEzNDYgNjU5LDczOSAxMzU4LDczOSBaIi8+CiAgPC9nPgogIDxnIGlkPSJidWxsZXQtY2hhci10ZW1wbGF0ZSgxMDEzMikiIHRyYW5zZm9ybT0ic2NhbGUoMC4wMDA0ODgyODEyNSwtMC4wMDA0ODgyODEyNSkiPgogICA8cGF0aCBkPSJNIDIwMTUsNzM5IEwgMTI3NiwwIDcxNywwIDEyNjAsNTQzIDE3NCw1NDMgMTc0LDkzNiAxMjYwLDkzNiA3MTcsMTQ4MSAxMjc0LDE0ODEgMjAxNSw3MzkgWiIvPgogIDwvZz4KICA8ZyBpZD0iYnVsbGV0LWNoYXItdGVtcGxhdGUoMTAwMDcpIiB0cmFuc2Zvcm09InNjYWxlKDAuMDAwNDg4MjgxMjUsLTAuMDAwNDg4MjgxMjUpIj4KICAgPHBhdGggZD0iTSAwLC0yIEMgLTcsMTQgLTE2LDI3IC0yNSwzNyBMIDM1Niw1NjcgQyAyNjIsODIzIDIxNSw5NTIgMjE1LDk1NCAyMTUsOTc5IDIyOCw5OTIgMjU1LDk5MiAyNjQsOTkyIDI3Niw5OTAgMjg5LDk4NyAzMTAsOTkxIDMzMSw5OTkgMzU0LDEwMTIgTCAzODEsOTk5IDQ5Miw3NDggNzcyLDEwNDkgODM2LDEwMjQgODYwLDEwNDkgQyA4ODEsMTAzOSA5MDEsMTAyNSA5MjIsMTAwNiA4ODYsOTM3IDgzNSw4NjMgNzcwLDc4NCA3NjksNzgzIDcxMCw3MTYgNTk0LDU4NCBMIDc3NCwyMjMgQyA3NzQsMTk2IDc1MywxNjggNzExLDEzOSBMIDcyNywxMTkgQyA3MTcsOTAgNjk5LDc2IDY3Miw3NiA2NDEsNzYgNTcwLDE3OCA0NTcsMzgxIEwgMTY0LC03NiBDIDE0MiwtMTEwIDExMSwtMTI3IDcyLC0xMjcgMzAsLTEyNyA5LC0xMTAgOCwtNzYgMSwtNjcgLTIsLTUyIC0yLC0zMiAtMiwtMjMgLTEsLTEzIDAsLTIgWiIvPgogIDwvZz4KICA8ZyBpZD0iYnVsbGV0LWNoYXItdGVtcGxhdGUoMTAwMDQpIiB0cmFuc2Zvcm09InNjYWxlKDAuMDAwNDg4MjgxMjUsLTAuMDAwNDg4MjgxMjUpIj4KICAgPHBhdGggZD0iTSAyODUsLTMzIEMgMTgyLC0zMyAxMTEsMzAgNzQsMTU2IDUyLDIyOCA0MSwzMzMgNDEsNDcxIDQxLDU0OSA1NSw2MTYgODIsNjcyIDExNiw3NDMgMTY5LDc3OCAyNDAsNzc4IDI5Myw3NzggMzI4LDc0NyAzNDYsNjg0IEwgMzY5LDUwOCBDIDM3Nyw0NDQgMzk3LDQxMSA0MjgsNDEwIEwgMTE2MywxMTE2IEMgMTE3NCwxMTI3IDExOTYsMTEzMyAxMjI5LDExMzMgMTI3MSwxMTMzIDEyOTIsMTExOCAxMjkyLDEwODcgTCAxMjkyLDk2NSBDIDEyOTIsOTI5IDEyODIsOTAxIDEyNjIsODgxIEwgNDQyLDQ3IEMgMzkwLC02IDMzOCwtMzMgMjg1LC0zMyBaIi8+CiAgPC9nPgogIDxnIGlkPSJidWxsZXQtY2hhci10ZW1wbGF0ZSg5Njc5KSIgdHJhbnNmb3JtPSJzY2FsZSgwLjAwMDQ4ODI4MTI1LC0wLjAwMDQ4ODI4MTI1KSI+CiAgIDxwYXRoIGQ9Ik0gODEzLDAgQyA2MzIsMCA0ODksNTQgMzgzLDE2MSAyNzYsMjY4IDIyMyw0MTEgMjIzLDU5MiAyMjMsNzczIDI3Niw5MTYgMzgzLDEwMjMgNDg5LDExMzAgNjMyLDExODQgODEzLDExODQgOTkyLDExODQgMTEzNiwxMTMwIDEyNDUsMTAyMyAxMzUzLDkxNiAxNDA3LDc3MiAxNDA3LDU5MiAxNDA3LDQxMiAxMzUzLDI2OCAxMjQ1LDE2MSAxMTM2LDU0IDk5MiwwIDgxMywwIFoiLz4KICA8L2c+CiAgPGcgaWQ9ImJ1bGxldC1jaGFyLXRlbXBsYXRlKDgyMjYpIiB0cmFuc2Zvcm09InNjYWxlKDAuMDAwNDg4MjgxMjUsLTAuMDAwNDg4MjgxMjUpIj4KICAgPHBhdGggZD0iTSAzNDYsNDU3IEMgMjczLDQ1NyAyMDksNDgzIDE1NSw1MzUgMTAxLDU4NiA3NCw2NDkgNzQsNzIzIDc0LDc5NiAxMDEsODU5IDE1NSw5MTEgMjA5LDk2MyAyNzMsOTg5IDM0Niw5ODkgNDE5LDk4OSA0ODAsOTYzIDUzMSw5MTAgNTgyLDg1OSA2MDgsNzk2IDYwOCw3MjMgNjA4LDY0OCA1ODMsNTg2IDUzMiw1MzUgNDgyLDQ4MyA0MjAsNDU3IDM0Niw0NTcgWiIvPgogIDwvZz4KICA8ZyBpZD0iYnVsbGV0LWNoYXItdGVtcGxhdGUoODIxMSkiIHRyYW5zZm9ybT0ic2NhbGUoMC4wMDA0ODgyODEyNSwtMC4wMDA0ODgyODEyNSkiPgogICA8cGF0aCBkPSJNIC00LDQ1OSBMIDExMzUsNDU5IDExMzUsNjA2IC00LDYwNiAtNCw0NTkgWiIvPgogIDwvZz4KIDwvZGVmcz4KIDxkZWZzIGNsYXNzPSJUZXh0RW1iZWRkZWRCaXRtYXBzIi8+CiA8Zz4KICA8ZyBpZD0iaWQyIiBjbGFzcz0iTWFzdGVyX1NsaWRlIj4KICAgPGcgaWQ9ImJnLWlkMiIgY2xhc3M9IkJhY2tncm91bmQiLz4KICAgPGcgaWQ9ImJvLWlkMiIgY2xhc3M9IkJhY2tncm91bmRPYmplY3RzIi8+CiAgPC9nPgogPC9nPgogPGcgY2xhc3M9IlNsaWRlR3JvdXAiPgogIDxnPgogICA8ZyBpZD0iaWQxIiBjbGFzcz0iU2xpZGUiIGNsaXAtcGF0aD0idXJsKCNwcmVzZW50YXRpb25fY2xpcF9wYXRoKSI+CiAgICA8ZyBjbGFzcz0iUGFnZSI+CiAgICAgPGcgY2xhc3M9ImNvbS5zdW4uc3Rhci5kcmF3aW5nLlJlY3RhbmdsZVNoYXBlIj4KICAgICAgPGcgaWQ9ImlkMyI+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gODQ1MCw3MDAwIEwgNzAwMCw3MDAwIDcwMDAsMzAwMCA5OTAwLDMwMDAgOTkwMCw3MDAwIDg0NTAsNzAwMCBaIi8+CiAgICAgIDwvZz4KICAgICA8L2c+CiAgICAgPGcgY2xhc3M9ImNvbS5zdW4uc3Rhci5kcmF3aW5nLlJlY3RhbmdsZVNoYXBlIj4KICAgICAgPGcgaWQ9ImlkNCI+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gMTIwNTAsNzAwMCBMIDEwMTAwLDcwMDAgMTAxMDAsMzAwMCAxNDAwMCwzMDAwIDE0MDAwLDcwMDAgMTIwNTAsNzAwMCBaIi8+CiAgICAgIDwvZz4KICAgICA8L2c+CiAgICAgPGcgY2xhc3M9ImNvbS5zdW4uc3Rhci5kcmF3aW5nLkVsbGlwc2VTaGFwZSI+CiAgICAgIDxnIGlkPSJpZDUiPgogICAgICAgPHBhdGggZmlsbD0ibm9uZSIgc3Ryb2tlPSJyZ2IoMCwwLDApIiBkPSJNIDg5OTksMzMwMCBDIDkxMDUsMzMxMiA5MTk1LDMzODMgOTI4OCwzNTMxIDkzODcsMzY5MCA5NDU5LDM4ODkgOTUxNiw0MTY1IDk1NzQsNDQ0MSA5NjAwLDQ3MTIgOTYwMCw1MDMxIDk2MDAsNTM1MCA5NTc0LDU2MjEgOTUxNiw1ODk3IDk0NTksNjE3MyA5NDAyLDYzMjggOTMxOSw2NDc4Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJyZ2IoMCwwLDApIiBzdHJva2U9Im5vbmUiIGQ9Ik0gOTE0MSw2NzAxIEwgOTQwNSw2NTI2IDkyNDgsNjQwMyA5MTQxLDY3MDEgWiIvPgogICAgICA8L2c+CiAgICAgPC9nPgogICAgIDxnIGNsYXNzPSJjb20uc3VuLnN0YXIuZHJhd2luZy5FbGxpcHNlU2hhcGUiPgogICAgICA8ZyBpZD0iaWQ2Ij4KICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0icmdiKDAsMCwwKSIgZD0iTSAxMDc5NCw2NzEwIEMgMTA3NDgsNjY2OSAxMDcxMCw2NjE4IDEwNjY4LDY1NDAgMTA1ODMsNjM4MCAxMDUyMSw2MTgxIDEwNDcyLDU5MDUgMTA0MjIsNTYyOCAxMDQwMCw1MzU2IDEwNDAwLDUwMzYgMTA0MDAsNDcxNiAxMDQyMiw0NDQ0IDEwNDcyLDQxNjggMTA1MjEsMzg5MSAxMDU4MywzNjkyIDEwNjY4LDM1MzIgMTA3NDgsMzM4MyAxMDY5MCwzNDkyIDEwNzAxLDM0NzQiLz4KICAgICAgIDxwYXRoIGZpbGw9InJnYigwLDAsMCkiIHN0cm9rZT0ibm9uZSIgZD0iTSAxMDkxNiwzMzAwIEwgMTA2MjIsMzQxNiAxMDc1MCwzNTY5IDEwOTE2LDMzMDAgWiIvPgogICAgICA8L2c+CiAgICAgPC9nPgogICAgIDxnIGNsYXNzPSJjb20uc3VuLnN0YXIuZHJhd2luZy5DdXN0b21TaGFwZSI+CiAgICAgIDxnIGlkPSJpZDciPgogICAgICAgPHBhdGggZmlsbD0ibm9uZSIgc3Ryb2tlPSJyZ2IoMCwwLDApIiBkPSJNIDk4OTksNjkwMCBDIDk5NTUsNjkwMCA5OTk5LDY5NDMgOTk5OSw2OTk5IDk5OTksNzA1NSA5OTU1LDcwOTkgOTg5OSw3MDk5IDk4NDMsNzA5OSA5ODAwLDcwNTUgOTgwMCw2OTk5IDk4MDAsNjk0MyA5ODQzLDY5MDAgOTg5OSw2OTAwIFoiLz4KICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0icmdiKDAsMCwwKSIgZD0iTSA5ODAwLDY5MDAgTCA5ODAwLDY5MDAgWiIvPgogICAgICAgPHBhdGggZmlsbD0ibm9uZSIgc3Ryb2tlPSJyZ2IoMCwwLDApIiBkPSJNIDEwMDAxLDcxMDEgTCAxMDAwMSw3MTAxIFoiLz4KICAgICAgPC9nPgogICAgIDwvZz4KICAgICA8ZyBjbGFzcz0iY29tLnN1bi5zdGFyLmRyYXdpbmcuQ3VzdG9tU2hhcGUiPgogICAgICA8ZyBpZD0iaWQ4Ij4KICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0icmdiKDAsMCwwKSIgZD0iTSAxMDA5OSwyOTAwIEMgMTAxNTUsMjkwMCAxMDE5OSwyOTQzIDEwMTk5LDI5OTkgMTAxOTksMzA1NSAxMDE1NSwzMDk5IDEwMDk5LDMwOTkgMTAwNDMsMzA5OSAxMDAwMCwzMDU1IDEwMDAwLDI5OTkgMTAwMDAsMjk0MyAxMDA0MywyOTAwIDEwMDk5LDI5MDAgWiIvPgogICAgICAgPHBhdGggZmlsbD0ibm9uZSIgc3Ryb2tlPSJyZ2IoMCwwLDApIiBkPSJNIDEwMDAwLDI5MDAgTCAxMDAwMCwyOTAwIFoiLz4KICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0icmdiKDAsMCwwKSIgZD0iTSAxMDIwMSwzMTAxIEwgMTAyMDEsMzEwMSBaIi8+CiAgICAgIDwvZz4KICAgICA8L2c+CiAgICAgPGcgY2xhc3M9ImNvbS5zdW4uc3Rhci5kcmF3aW5nLkN1c3RvbVNoYXBlIj4KICAgICAgPGcgaWQ9ImlkOSI+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gOTg5OSwyOTAwIEMgOTk1NSwyOTAwIDk5OTksMjk0MyA5OTk5LDI5OTkgOTk5OSwzMDU1IDk5NTUsMzA5OSA5ODk5LDMwOTkgOTg0MywzMDk5IDk4MDAsMzA1NSA5ODAwLDI5OTkgOTgwMCwyOTQzIDk4NDMsMjkwMCA5ODk5LDI5MDAgWiIvPgogICAgICAgPHBhdGggZmlsbD0ibm9uZSIgc3Ryb2tlPSJyZ2IoMCwwLDApIiBkPSJNIDk4MDAsMjkwMCBMIDk4MDAsMjkwMCBaIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gMTAwMDEsMzEwMSBMIDEwMDAxLDMxMDEgWiIvPgogICAgICA8L2c+CiAgICAgPC9nPgogICAgIDxnIGNsYXNzPSJjb20uc3VuLnN0YXIuZHJhd2luZy5DdXN0b21TaGFwZSI+CiAgICAgIDxnIGlkPSJpZDEwIj4KICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0icmdiKDAsMCwwKSIgZD0iTSA5ODk5LDQ5MDAgQyA5OTU1LDQ5MDAgOTk5OSw0OTQzIDk5OTksNDk5OSA5OTk5LDUwNTUgOTk1NSw1MDk5IDk4OTksNTA5OSA5ODQzLDUwOTkgOTgwMCw1MDU1IDk4MDAsNDk5OSA5ODAwLDQ5NDMgOTg0Myw0OTAwIDk4OTksNDkwMCBaIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gOTgwMCw0OTAwIEwgOTgwMCw0OTAwIFoiLz4KICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0icmdiKDAsMCwwKSIgZD0iTSAxMDAwMSw1MTAxIEwgMTAwMDEsNTEwMSBaIi8+CiAgICAgIDwvZz4KICAgICA8L2c+CiAgICAgPGcgY2xhc3M9ImNvbS5zdW4uc3Rhci5kcmF3aW5nLkN1c3RvbVNoYXBlIj4KICAgICAgPGcgaWQ9ImlkMTEiPgogICAgICAgPHBhdGggZmlsbD0ibm9uZSIgc3Ryb2tlPSJyZ2IoMCwwLDApIiBkPSJNIDEwMDk5LDQ5MDAgQyAxMDE1NSw0OTAwIDEwMTk5LDQ5NDMgMTAxOTksNDk5OSAxMDE5OSw1MDU1IDEwMTU1LDUwOTkgMTAwOTksNTA5OSAxMDA0Myw1MDk5IDEwMDAwLDUwNTUgMTAwMDAsNDk5OSAxMDAwMCw0OTQzIDEwMDQzLDQ5MDAgMTAwOTksNDkwMCBaIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gMTAwMDAsNDkwMCBMIDEwMDAwLDQ5MDAgWiIvPgogICAgICAgPHBhdGggZmlsbD0ibm9uZSIgc3Ryb2tlPSJyZ2IoMCwwLDApIiBkPSJNIDEwMjAxLDUxMDEgTCAxMDIwMSw1MTAxIFoiLz4KICAgICAgPC9nPgogICAgIDwvZz4KICAgICA8ZyBjbGFzcz0iY29tLnN1bi5zdGFyLmRyYXdpbmcuQ3VzdG9tU2hhcGUiPgogICAgICA8ZyBpZD0iaWQxMiI+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gMTAwOTksNjkwMCBDIDEwMTU1LDY5MDAgMTAxOTksNjk0MyAxMDE5OSw2OTk5IDEwMTk5LDcwNTUgMTAxNTUsNzA5OSAxMDA5OSw3MDk5IDEwMDQzLDcwOTkgMTAwMDAsNzA1NSAxMDAwMCw2OTk5IDEwMDAwLDY5NDMgMTAwNDMsNjkwMCAxMDA5OSw2OTAwIFoiLz4KICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0icmdiKDAsMCwwKSIgZD0iTSAxMDAwMCw2OTAwIEwgMTAwMDAsNjkwMCBaIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gMTAyMDEsNzEwMSBMIDEwMjAxLDcxMDEgWiIvPgogICAgICA8L2c+CiAgICAgPC9nPgogICAgIDxnIGNsYXNzPSJjb20uc3VuLnN0YXIuZHJhd2luZy5DdXN0b21TaGFwZSI+CiAgICAgIDxnIGlkPSJpZDEzIj4KICAgICAgIDxwYXRoIGZpbGw9InJnYigyNTUsMjU1LDI1NSkiIHN0cm9rZT0ibm9uZSIgZD0iTSA1MTAwLDUyMDAgTCAzNTAwLDUyMDAgMzUwMCwzMDAwIDY3MDAsMzAwMCA2NzAwLDUyMDAgNTEwMCw1MjAwIFoiLz4KICAgICAgIDx0ZXh0IGNsYXNzPSJUZXh0U2hhcGUiPjx0c3BhbiBjbGFzcz0iVGV4dFBhcmFncmFwaCIgZm9udC1mYW1pbHk9IkxpYmVyYXRpb24gU2Fucywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIzNTNweCIgZm9udC13ZWlnaHQ9IjQwMCI+PHRzcGFuIGNsYXNzPSJUZXh0UG9zaXRpb24iIHg9IjM3NTAiIHk9IjM0MzMiPjx0c3BhbiBmaWxsPSJyZ2IoMCwwLDApIiBzdHJva2U9Im5vbmUiPlN1YmRpdmlzaW9uIDwvdHNwYW4+PC90c3Bhbj48dHNwYW4gY2xhc3M9IlRleHRQb3NpdGlvbiIgeD0iMzc1MCIgeT0iMzgyNyI+PHRzcGFuIGZpbGw9InJnYigwLDAsMCkiIHN0cm9rZT0ibm9uZSI+cG9pbnRzIG5lZWQgdG8gPC90c3Bhbj48L3RzcGFuPjx0c3BhbiBjbGFzcz0iVGV4dFBvc2l0aW9uIiB4PSIzNzUwIiB5PSI0MjIxIj48dHNwYW4gZmlsbD0icmdiKDAsMCwwKSIgc3Ryb2tlPSJub25lIj5sYW5kIG9uIHRoZSBzYW1lIDwvdHNwYW4+PC90c3Bhbj48dHNwYW4gY2xhc3M9IlRleHRQb3NpdGlvbiIgeD0iMzc1MCIgeT0iNDYxNSI+PHRzcGFuIGZpbGw9InJnYigwLDAsMCkiIHN0cm9rZT0ibm9uZSI+bG9jYXRpb24gdG8gPC90c3Bhbj48L3RzcGFuPjx0c3BhbiBjbGFzcz0iVGV4dFBvc2l0aW9uIiB4PSIzNzUwIiB5PSI1MDA5Ij48dHNwYW4gZmlsbD0icmdiKDAsMCwwKSIgc3Ryb2tlPSJub25lIj5wcmV2ZW50IGNyYWNraW5nPC90c3Bhbj48L3RzcGFuPjwvdHNwYW4+PC90ZXh0PgogICAgICA8L2c+CiAgICAgPC9nPgogICAgIDxnIGNsYXNzPSJjb20uc3VuLnN0YXIuZHJhd2luZy5MaW5lU2hhcGUiPgogICAgICA8ZyBpZD0iaWQxNCI+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gNjYwMCw0MjAwIEwgNjY1MSw0MjEzIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gNjcwMyw0MjI3IEwgNjc1NCw0MjQwIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gNjgwNiw0MjUzIEwgNjg1Nyw0MjY2Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gNjkwOCw0MjgwIEwgNjk2MCw0MjkzIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gNzAxMSw0MzA2IEwgNzA2Myw0MzE5Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gNzExNCw0MzMzIEwgNzE2NSw0MzQ2Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gNzIxNyw0MzU5IEwgNzI2OCw0MzcyIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gNzMyMCw0Mzg2IEwgNzM3MSw0Mzk5Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gNzQyMyw0NDEyIEwgNzQ3NCw0NDI2Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gNzUyNSw0NDM5IEwgNzU3Nyw0NDUyIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gNzYyOCw0NDY1IEwgNzY4MCw0NDc5Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gNzczMSw0NDkyIEwgNzc4Miw0NTA1Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gNzgzNCw0NTE4IEwgNzg4NSw0NTMyIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gNzkzNyw0NTQ1IEwgNzk4OCw0NTU4Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gODAzOSw0NTcxIEwgODA5MSw0NTg1Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gODE0Miw0NTk4IEwgODE5NCw0NjExIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gODI0NSw0NjI1IEwgODI5Niw0NjM4Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gODM0OCw0NjUxIEwgODM5OSw0NjY0Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gODQ1MSw0Njc4IEwgODUwMiw0NjkxIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gODU1Myw0NzA0IEwgODYwNSw0NzE3Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gODY1Niw0NzMxIEwgODcwOCw0NzQ0Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gODc1OSw0NzU3IEwgODgxMSw0NzcwIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gODg2Miw0Nzg0IEwgODkxMyw0Nzk3Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gODk2NSw0ODEwIEwgOTAxNiw0ODI0Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gOTA2OCw0ODM3IEwgOTExOSw0ODUwIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gOTE3MCw0ODYzIEwgOTIyMiw0ODc3Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gOTI3Myw0ODkwIEwgOTMyNSw0OTAzIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gOTM3Niw0OTE2IEwgOTQyNyw0OTMwIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gOTQ3OSw0OTQzIEwgOTUzMCw0OTU2Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gOTU4Miw0OTY5IEwgOTYzMyw0OTgzIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gOTY4NCw0OTk2IEwgOTcwMCw1MDAwIi8+CiAgICAgIDwvZz4KICAgICA8L2c+CiAgICAgPGcgY2xhc3M9ImNvbS5zdW4uc3Rhci5kcmF3aW5nLkN1c3RvbVNoYXBlIj4KICAgICAgPGcgaWQ9ImlkMTUiPgogICAgICAgPHBhdGggZmlsbD0icmdiKDI1NSwyNTUsMjU1KSIgc3Ryb2tlPSJub25lIiBkPSJNIDEyNjUwLDI3MDAgTCAxMDcwMCwyNzAwIDEwNzAwLDE1MDAgMTQ2MDAsMTUwMCAxNDYwMCwyNzAwIDEyNjUwLDI3MDAgWiIvPgogICAgICAgPHRleHQgY2xhc3M9IlRleHRTaGFwZSI+PHRzcGFuIGNsYXNzPSJUZXh0UGFyYWdyYXBoIiBmb250LWZhbWlseT0iTGliZXJhdGlvbiBTYW5zLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjM1M3B4IiBmb250LXdlaWdodD0iNDAwIj48dHNwYW4gY2xhc3M9IlRleHRQb3NpdGlvbiIgeD0iMTA5NTAiIHk9IjIwMjQiPjx0c3BhbiBmaWxsPSJyZ2IoMCwwLDApIiBzdHJva2U9Im5vbmUiPkNvcm5lciBwb2ludHMgc3RhcnQgPC90c3Bhbj48L3RzcGFuPjx0c3BhbiBjbGFzcz0iVGV4dFBvc2l0aW9uIiB4PSIxMDk1MCIgeT0iMjQxOCI+PHRzcGFuIGZpbGw9InJnYigwLDAsMCkiIHN0cm9rZT0ibm9uZSI+d2l0aCB0aGUgc2FtZSB2YWx1ZXM8L3RzcGFuPjwvdHNwYW4+PC90c3Bhbj48L3RleHQ+CiAgICAgIDwvZz4KICAgICA8L2c+CiAgICAgPGcgY2xhc3M9ImNvbS5zdW4uc3Rhci5kcmF3aW5nLkN1c3RvbVNoYXBlIj4KICAgICAgPGcgaWQ9ImlkMTYiPgogICAgICAgPHBhdGggZmlsbD0icmdiKDI1NSwyNTUsMjU1KSIgc3Ryb2tlPSJub25lIiBkPSJNIDEyODUwLDg1MDAgTCAxMDkwMCw4NTAwIDEwOTAwLDczMDAgMTQ4MDAsNzMwMCAxNDgwMCw4NTAwIDEyODUwLDg1MDAgWiIvPgogICAgICAgPHRleHQgY2xhc3M9IlRleHRTaGFwZSI+PHRzcGFuIGNsYXNzPSJUZXh0UGFyYWdyYXBoIiBmb250LWZhbWlseT0iTGliZXJhdGlvbiBTYW5zLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjM1M3B4IiBmb250LXdlaWdodD0iNDAwIj48dHNwYW4gY2xhc3M9IlRleHRQb3NpdGlvbiIgeD0iMTExNTAiIHk9Ijc4MjQiPjx0c3BhbiBmaWxsPSJyZ2IoMCwwLDApIiBzdHJva2U9Im5vbmUiPkNvcm5lciBwb2ludHMgc3RhcnQgPC90c3Bhbj48L3RzcGFuPjx0c3BhbiBjbGFzcz0iVGV4dFBvc2l0aW9uIiB4PSIxMTE1MCIgeT0iODIxOCI+PHRzcGFuIGZpbGw9InJnYigwLDAsMCkiIHN0cm9rZT0ibm9uZSI+d2l0aCB0aGUgc2FtZSB2YWx1ZXM8L3RzcGFuPjwvdHNwYW4+PC90c3Bhbj48L3RleHQ+CiAgICAgIDwvZz4KICAgICA8L2c+CiAgICAgPGcgY2xhc3M9ImNvbS5zdW4uc3Rhci5kcmF3aW5nLkN1c3RvbVNoYXBlIj4KICAgICAgPGcgaWQ9ImlkMTciPgogICAgICAgPHBhdGggZmlsbD0icmdiKDI1NSwyNTUsMjU1KSIgc3Ryb2tlPSJub25lIiBkPSJNIDEyNDAwLDUyMDAgTCAxMDkwMCw1MjAwIDEwOTAwLDMzMDAgMTM5MDAsMzMwMCAxMzkwMCw1MjAwIDEyNDAwLDUyMDAgWiIvPgogICAgICAgPHRleHQgY2xhc3M9IlRleHRTaGFwZSI+PHRzcGFuIGNsYXNzPSJUZXh0UGFyYWdyYXBoIiBmb250LWZhbWlseT0iTGliZXJhdGlvbiBTYW5zLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjM1M3B4IiBmb250LXdlaWdodD0iNDAwIj48dHNwYW4gY2xhc3M9IlRleHRQb3NpdGlvbiIgeD0iMTExNTAiIHk9IjM3ODAiPjx0c3BhbiBmaWxsPSJyZ2IoMCwwLDApIiBzdHJva2U9Im5vbmUiPk9wcG9zaW5nIDwvdHNwYW4+PC90c3Bhbj48dHNwYW4gY2xhc3M9IlRleHRQb3NpdGlvbiIgeD0iMTExNTAiIHk9IjQxNzQiPjx0c3BhbiBmaWxsPSJyZ2IoMCwwLDApIiBzdHJva2U9Im5vbmUiPmRpcmVjdGlvbnMgb2YgPC90c3Bhbj48L3RzcGFuPjx0c3BhbiBjbGFzcz0iVGV4dFBvc2l0aW9uIiB4PSIxMTE1MCIgeT0iNDU2OCI+PHRzcGFuIGZpbGw9InJnYigwLDAsMCkiIHN0cm9rZT0ibm9uZSI+ZWRnZSB3YWxraW5nIDwvdHNwYW4+PC90c3Bhbj48dHNwYW4gY2xhc3M9IlRleHRQb3NpdGlvbiIgeD0iMTExNTAiIHk9IjQ5NjIiPjx0c3BhbiBmaWxsPSJyZ2IoMCwwLDApIiBzdHJva2U9Im5vbmUiPmZvciBzdWJkaXZpc2lvbjwvdHNwYW4+PC90c3Bhbj48L3RzcGFuPjwvdGV4dD4KICAgICAgPC9nPgogICAgIDwvZz4KICAgICA8ZyBjbGFzcz0iY29tLnN1bi5zdGFyLmRyYXdpbmcuTGluZVNoYXBlIj4KICAgICAgPGcgaWQ9ImlkMTgiPgogICAgICAgPHBhdGggZmlsbD0ibm9uZSIgc3Ryb2tlPSJyZ2IoMCwwLDApIiBkPSJNIDEwMzAwLDI5MDAgTCAxMDM0MSwyODY3Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gMTAzODMsMjgzNCBMIDEwNDI0LDI4MDEiLz4KICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0icmdiKDAsMCwwKSIgZD0iTSAxMDQ2NiwyNzY3IEwgMTA1MDcsMjczNCIvPgogICAgICAgPHBhdGggZmlsbD0ibm9uZSIgc3Ryb2tlPSJyZ2IoMCwwLDApIiBkPSJNIDEwNTQ5LDI3MDEgTCAxMDU5MCwyNjY4Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gMTA2MzIsMjYzNSBMIDEwNjczLDI2MDIiLz4KICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0icmdiKDAsMCwwKSIgZD0iTSAxMDcxNSwyNTY4IEwgMTA3NTYsMjUzNSIvPgogICAgICAgPHBhdGggZmlsbD0ibm9uZSIgc3Ryb2tlPSJyZ2IoMCwwLDApIiBkPSJNIDEwNzk3LDI1MDIgTCAxMDgwMCwyNTAwIi8+CiAgICAgIDwvZz4KICAgICA8L2c+CiAgICAgPGcgY2xhc3M9ImNvbS5zdW4uc3Rhci5kcmF3aW5nLkxpbmVTaGFwZSI+CiAgICAgIDxnIGlkPSJpZDE5Ij4KICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0icmdiKDAsMCwwKSIgZD0iTSAxMDIwMCw3MTAwIEwgMTAyNDMsNzEzMSIvPgogICAgICAgPHBhdGggZmlsbD0ibm9uZSIgc3Ryb2tlPSJyZ2IoMCwwLDApIiBkPSJNIDEwMjg2LDcxNjIgTCAxMDMzMCw3MTkzIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gMTAzNzMsNzIyMyBMIDEwNDE2LDcyNTQiLz4KICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0icmdiKDAsMCwwKSIgZD0iTSAxMDQ1OSw3Mjg1IEwgMTA1MDIsNzMxNiIvPgogICAgICAgPHBhdGggZmlsbD0ibm9uZSIgc3Ryb2tlPSJyZ2IoMCwwLDApIiBkPSJNIDEwNTQ2LDczNDcgTCAxMDU4OSw3Mzc4Ii8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gMTA2MzIsNzQwOSBMIDEwNjc1LDc0MzkiLz4KICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0icmdiKDAsMCwwKSIgZD0iTSAxMDcxOCw3NDcwIEwgMTA3NjIsNzUwMSIvPgogICAgICAgPHBhdGggZmlsbD0ibm9uZSIgc3Ryb2tlPSJyZ2IoMCwwLDApIiBkPSJNIDEwODA1LDc1MzIgTCAxMDg0OCw3NTYzIi8+CiAgICAgICA8cGF0aCBmaWxsPSJub25lIiBzdHJva2U9InJnYigwLDAsMCkiIGQ9Ik0gMTA4OTEsNzU5NCBMIDEwOTAwLDc2MDAiLz4KICAgICAgPC9nPgogICAgIDwvZz4KICAgIDwvZz4KICAgPC9nPgogIDwvZz4KIDwvZz4KPC9zdmc+" alt="precise">
9148</div>
9149</div>
9150<div class="paragraph">
9151<p>Without any qualifiers, implementations are permitted to perform
9152optimizations that effectively modify the order or number of operations used
9153to evaluate an expression, even if those optimizations may produce slightly
9154different results relative to unoptimized code.</p>
9155</div>
9156<div class="paragraph">
9157<p>The <strong>precise</strong> qualifier ensures that operations contributing to a
9158variable&#8217;s value are done in their stated order and with operator consistency.
9159The order is determined by operator precedence and parenthesis, as described in
9160&#8220;<a href="#operators">Operators</a>&#8221;.
9161Operator consistency means for each particular operator, for example the
9162multiply operator (<strong>*</strong>), its operation is always computed with the same
9163precision.
9164Specifically, values computed by compiler-generated code must adhere to the
9165following identities:</p>
9166</div>
9167<div class="olist arabic">
9168<ol class="arabic">
9169<li>
9170<p>a + b = b + a</p>
9171</li>
9172<li>
9173<p>a * b = b * a</p>
9174</li>
9175<li>
9176<p>a * b + c * d = b * a + c* d = d * c + b * a = &lt;any other mathematically
9177valid combination&gt;</p>
9178</li>
9179</ol>
9180</div>
9181<div class="paragraph">
9182<p>While the following are prevented:</p>
9183</div>
9184<div class="olist arabic">
9185<ol class="arabic">
9186<li>
9187<p>a + (b + c) is not allowed to become (a + b) + c</p>
9188</li>
9189<li>
9190<p>a * (b * c) is not allowed to become (a * b) * c</p>
9191</li>
9192<li>
9193<p>a * b + c is not allowed to become a single operation <strong>fma</strong>(a, b, c)</p>
9194</li>
9195</ol>
9196</div>
9197<div class="paragraph">
9198<p>Where <em>a</em>, <em>b</em>, <em>c</em>, and <em>d</em>, are scalars or vectors, not matrices.
9199(Matrix multiplication generally does not commute.) It is the shader
9200writer&#8217;s responsibility to express the computation in terms of these rules
9201and the compiler&#8217;s responsibility to follow these rules.
9202See the description of <em>gl_TessCoord</em> for the rules the tessellation stages
9203are responsible for following, which in conjunction with the above allow
9204avoiding cracking when subdividing.</p>
9205</div>
9206<div class="paragraph">
9207<p>For example,</p>
9208</div>
9209<div class="listingblock">
9210<div class="content">
9211<pre class="CodeRay highlight"><code data-lang="c++">precise out vec4 position;</code></pre>
9212</div>
9213</div>
9214<div class="paragraph">
9215<p>declares that operations used to produce the value of <em>position</em> must be
9216performed in exactly the order specified in the source code and with all
9217operators being treated consistently.
9218As with the <strong>invariant</strong> qualifier (see &#8220;<a href="#the-invariant-qualifier">The
9219Invariant Qualifier</a>&#8221;), the <strong>precise</strong> qualifier may be used to qualify a
9220built-in or previously declared user-defined variable as being precise:</p>
9221</div>
9222<div class="listingblock">
9223<div class="content">
9224<pre class="CodeRay highlight"><code data-lang="c++">out vec3 Color;
9225precise Color; <span class="comment">// make existing Color be precise</span></code></pre>
9226</div>
9227</div>
9228<div class="paragraph">
9229<p>When applied to a block, a structure type, or a variable of structure type,
9230<strong>precise</strong> applies to each contained member, recursively.</p>
9231</div>
9232<div class="paragraph">
9233<p>This qualifier will affect the evaluation of an r-value in a particular
9234function if and only if the result is eventually consumed in the same
9235function by an l-value qualified as <strong>precise</strong>.
9236Any other expressions within a function are not affected, including return
9237values and output parameters not declared as <strong>precise</strong> but that are
9238eventually consumed outside the function by a variable qualified as
9239<strong>precise</strong>. Unaffected expressions also include the controlling expressions
9240in selection and iteration statements and the condition in ternary
9241operators (<strong>?:</strong>).</p>
9242</div>
9243<div class="paragraph">
9244<p>Some examples of the use of <strong>precise</strong>:</p>
9245</div>
9246<div class="listingblock">
9247<div class="content">
9248<pre class="CodeRay highlight"><code data-lang="c++">in vec4 a, b, c, d;
9249precise out vec4 v;
9250
9251<span class="predefined-type">float</span> func(<span class="predefined-type">float</span> e, <span class="predefined-type">float</span> f, <span class="predefined-type">float</span> g, <span class="predefined-type">float</span> h)
9252{
9253    <span class="keyword">return</span> (e*f) + (g*h); <span class="comment">// no constraint on order or operator consistency</span>
9254}
9255
9256<span class="predefined-type">float</span> func2(<span class="predefined-type">float</span> e, <span class="predefined-type">float</span> f, <span class="predefined-type">float</span> g, <span class="predefined-type">float</span> h)
9257{
9258    precise <span class="predefined-type">float</span> result = (e*f) + (g*h); <span class="comment">// ensures same precision for the two multiplies</span>
9259    <span class="keyword">return</span> result;
9260}
9261
9262<span class="predefined-type">float</span> func3(<span class="predefined-type">float</span> i, <span class="predefined-type">float</span> j, precise out <span class="predefined-type">float</span> k)
9263{
9264    k = i * i + j;        <span class="comment">// precise, due to &lt;k&gt; declaration</span>
9265}
9266
9267<span class="directive">void</span> main()
9268{
9269    vec3 r = vec3(a * b);             <span class="comment">// precise, used to compute v.xyz</span>
9270    vec3 s = vec3(c * d);             <span class="comment">// precise, used to compute v.xyz</span>
9271    v.xyz = r + s;                    <span class="comment">// precise</span>
9272    v.w = (a.w * b.w) + (c.w * d.w);  <span class="comment">// precise</span>
9273    v.x = func(a.x, b.x, c.x, d.x);   <span class="comment">// values computed in func() are NOT precise</span>
9274    v.x = func2(a.x, b.x, c.x, d.x);  <span class="comment">// precise!</span>
9275    func3(a.x * b.x, c.x * d.x, v.x); <span class="comment">// precise!</span>
9276}</code></pre>
9277</div>
9278</div>
9279<div class="paragraph">
9280<p>For the purposes of determining if an output from one shader stage matches
9281an input of the next stage, the <strong>precise</strong> qualifier need not match between
9282the input and the output.</p>
9283</div>
9284<div class="paragraph">
9285<p>All constant expressions are evaluated as if <strong>precise</strong> was present, whether
9286or not it is present.
9287However, as described in &#8220;<a href="#constant-expressions">Constant Expressions</a>&#8221;,
9288there is no requirement that a compile-time constant expression evaluates to
9289the same value as a corresponding non-constant expression.</p>
9290</div>
9291</div>
9292<div class="sect2">
9293<h3 id="memory-qualifiers">4.10. Memory Qualifiers</h3>
9294<div class="paragraph">
9295<p>Shader storage blocks, variables declared within shader storage blocks and
9296variables declared as image types (the basic opaque types with &#8220;<strong>image</strong>&#8221;
9297in their keyword), can be further qualified with one or more of the
9298following memory qualifiers:</p>
9299</div>
9300<table class="tableblock frame-all grid-all stretch">
9301<colgroup>
9302<col style="width: 50%;">
9303<col style="width: 50%;">
9304</colgroup>
9305<thead>
9306<tr>
9307<th class="tableblock halign-left valign-top">Qualifier</th>
9308<th class="tableblock halign-left valign-top">Meaning</th>
9309</tr>
9310</thead>
9311<tbody>
9312<tr>
9313<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>coherent</strong></p></td>
9314<td class="tableblock halign-left valign-top"><p class="tableblock">memory variable where reads and writes are coherent with
9315                reads and writes from other shader invocations</p></td>
9316</tr>
9317<tr>
9318<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>volatile</strong></p></td>
9319<td class="tableblock halign-left valign-top"><p class="tableblock">memory variable whose underlying value may be changed at any
9320                point during shader execution by some source other than the
9321                current shader invocation</p></td>
9322</tr>
9323<tr>
9324<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>restrict</strong></p></td>
9325<td class="tableblock halign-left valign-top"><p class="tableblock">memory variable where use of that variable is the only way
9326                to read and write the underlying memory in the relevant
9327                shader stage</p></td>
9328</tr>
9329<tr>
9330<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>readonly</strong></p></td>
9331<td class="tableblock halign-left valign-top"><p class="tableblock">memory variable that can be used to read the underlying
9332                memory, but cannot be used to write the underlying memory</p></td>
9333</tr>
9334<tr>
9335<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>writeonly</strong></p></td>
9336<td class="tableblock halign-left valign-top"><p class="tableblock">memory variable that can be used to write the underlying
9337                memory, but cannot be used to read the underlying memory</p></td>
9338</tr>
9339</tbody>
9340</table>
9341<div class="paragraph">
9342<p>Memory accesses to image variables declared using the <strong>coherent</strong> qualifier
9343are performed coherently with accesses to the same location from other
9344shader invocations.
9345In particular, when reading a variable declared as <strong>coherent</strong>, the values
9346returned will reflect the results of previously completed writes performed
9347by other shader invocations.
9348When writing a variable declared as <strong>coherent</strong>, the values written will be
9349reflected in subsequent coherent reads performed by other shader
9350invocations.</p>
9351</div>
9352<div class="paragraph">
9353<p>As described in section
93547.12
9355&#8220;Shader Memory Access&#8221; of the
9356<a href="#references">OpenGL Specification</a>, shader memory reads and writes complete in a
9357largely undefined order.
9358The built-in function <strong>memoryBarrier</strong>() can be used if needed to guarantee
9359the completion and relative ordering of memory accesses performed by a
9360single shader invocation.</p>
9361</div>
9362<div class="paragraph">
9363<p>When accessing memory using variables not declared as <strong>coherent</strong>, the memory
9364accessed by a shader may be cached by the implementation to service future
9365accesses to the same address.
9366Memory stores may be cached in such a way that the values written may not be
9367visible to other shader invocations accessing the same memory.
9368The implementation may cache the values fetched by memory reads and return
9369the same values to any shader invocation accessing the same memory, even if
9370the underlying memory has been modified since the first memory read.
9371While variables not declared as <strong>coherent</strong> may not be useful for
9372communicating between shader invocations, using non-coherent accesses may
9373result in higher performance.</p>
9374</div>
9375<div class="paragraph">
9376<p>Memory accesses to image variables declared using the <strong>volatile</strong> qualifier
9377must treat the underlying memory as though it could be read or written at
9378any point during shader execution by some source other than the executing
9379shader invocation.
9380When a volatile variable is read, its value must be re-fetched from the
9381underlying memory, even if the shader invocation performing the read had
9382previously fetched its value from the same memory.
9383When a volatile variable is written, its value must be written to the
9384underlying memory, even if the compiler can conclusively determine that its
9385value will be overwritten by a subsequent write.
9386Since the external source reading or writing a <strong>volatile</strong> variable may be
9387another shader invocation, variables declared as <strong>volatile</strong> are
9388automatically treated as coherent.</p>
9389</div>
9390<div class="paragraph">
9391<p>Memory accesses to image variables declared using the <strong>restrict</strong> qualifier
9392may be compiled assuming that the variable used to perform the memory access
9393is the only way to access the underlying memory using the shader stage in
9394question.
9395This allows the compiler to coalesce or reorder loads and stores using
9396<strong>restrict</strong>-qualified image variables in ways that wouldn&#8217;t be permitted
9397for image variables not so qualified, because the compiler can assume that
9398the underlying image won&#8217;t be read or written by other code.
9399Applications are responsible for ensuring that image memory referenced by
9400variables qualified with <strong>restrict</strong> will not be referenced using other
9401variables in the same scope; otherwise, accesses to <strong>restrict</strong>-qualified
9402variables will have undefined results.</p>
9403</div>
9404<div class="paragraph">
9405<p>Memory accesses to image variables declared using the <strong>readonly</strong> qualifier
9406may only read the underlying memory, which is treated as read-only memory
9407and cannot be written to.
9408It is a compile-time error to pass an image variable qualified with
9409<strong>readonly</strong> to <strong>imageStore</strong>() or other built-in functions that modify image
9410memory.</p>
9411</div>
9412<div class="paragraph">
9413<p>Memory accesses to image variables declared using the <strong>writeonly</strong> qualifier
9414may only write the underlying memory; the underlying memory cannot be read.
9415It is a compile-time error to pass an image variable qualified with
9416<strong>writeonly</strong> to <strong>imageLoad</strong>() or other built-in functions that read image
9417memory.</p>
9418</div>
9419<div class="paragraph">
9420<p>A variable could be qualified as both <strong>readonly</strong> and <strong>writeonly</strong>, disallowing
9421both read and write. Such variables can still be used with some queries, for
9422example <strong>imageSize</strong>() and <strong>.length</strong>().</p>
9423</div>
9424<div class="paragraph">
9425<p>The memory qualifiers <strong>coherent</strong>, <strong>volatile</strong>, <strong>restrict</strong>, <strong>readonly</strong>, and
9426<strong>writeonly</strong> may be used in the declaration of buffer variables (i.e.,
9427members of shader storage blocks).
9428When a buffer variable is declared with a memory qualifier, the behavior
9429specified for memory accesses involving image variables described above
9430applies identically to memory accesses involving that buffer variable.
9431It is a compile-time error to assign to a buffer variable qualified with
9432<strong>readonly</strong> or to read from a buffer variable qualified with <strong>writeonly</strong>.
9433The combination <strong>readonly</strong> <strong>writeonly</strong> is allowed.</p>
9434</div>
9435<div class="paragraph">
9436<p>Additionally, memory qualifiers may be used at the block-level declaration
9437of a shader storage block, including the combination <strong>readonly</strong> <strong>writeonly</strong>.
9438When a block declaration is qualified with a memory qualifier, it is as if
9439all of its members were declared with the same memory qualifier.
9440For example, the block declaration</p>
9441</div>
9442<div class="listingblock">
9443<div class="content">
9444<pre class="CodeRay highlight"><code data-lang="c++">coherent buffer Block {
9445    readonly vec4 member1;
9446    vec4 member2;
9447};</code></pre>
9448</div>
9449</div>
9450<div class="paragraph">
9451<p>is equivalent to</p>
9452</div>
9453<div class="listingblock">
9454<div class="content">
9455<pre class="CodeRay highlight"><code data-lang="c++">buffer Block {
9456    coherent readonly vec4 member1;
9457    coherent vec4 member2;
9458};</code></pre>
9459</div>
9460</div>
9461<div class="paragraph">
9462<p>Memory qualifiers are only supported in the declarations of image variables,
9463buffer variables, and shader storage blocks; it is an error to use such
9464qualifiers in any other declarations.</p>
9465</div>
9466<div class="paragraph">
9467<p>When calling user-defined functions, variables qualified with <strong>coherent</strong>,
9468<strong>volatile</strong>, <strong>readonly</strong>, or <strong>writeonly</strong> may not be passed to functions whose
9469formal parameters lack such qualifiers.
9470(See &#8220;<a href="#function-definitions">Function Definitions</a>&#8221; for more detail on
9471function calling.) It is legal to have any additional memory qualifiers on a
9472formal parameter, but only <strong>restrict</strong> can be taken away from a calling
9473argument, by a formal parameter that lacks the <strong>restrict</strong> qualifier.</p>
9474</div>
9475<div class="paragraph">
9476<p>When a built-in function is called, the code generated is to be based on the
9477actual qualification of the calling argument, not on the list of memory
9478qualifiers specified on the formal parameter in the prototype.</p>
9479</div>
9480<div class="listingblock">
9481<div class="content">
9482<pre class="CodeRay highlight"><code data-lang="c++">vec4 funcA(restrict image2D a) { ... }
9483vec4 funcB(image2D a) { ... }
9484layout(rgba32f) uniform image2D img1;
9485layout(rgba32f) coherent uniform image2D img2;
9486
9487funcA(img1);        <span class="comment">// OK, adding &quot;restrict&quot; is allowed</span>
9488funcB(img2);        <span class="comment">// illegal, stripping &quot;coherent&quot; is not</span></code></pre>
9489</div>
9490</div>
9491<div class="paragraph">
9492<p>Layout qualifiers cannot be used on formal function parameters, and layout
9493qualification is not included in parameter matching.</p>
9494</div>
9495<div class="paragraph">
9496<p>Note that the use of <strong>const</strong> in an image variable declaration is qualifying
9497the const-ness of the variable being declared, not the image it refers to.
9498The qualifier <strong>readonly</strong> qualifies the image memory (as accessed through
9499that variable) while <strong>const</strong> qualifies the variable itself.</p>
9500</div>
9501</div>
9502<div class="sect2">
9503<h3 id="specialization-constant-qualifier">4.11. Specialization-Constant Qualifier</h3>
9504<div class="paragraph">
9505<p>Specialization constants are used only for SPIR-V and declared using the
9506<strong>constant_id</strong> layout qualifier.
9507For example:</p>
9508</div>
9509<div class="listingblock">
9510<div class="content">
9511<pre class="CodeRay highlight"><code data-lang="c++">layout(constant_id = <span class="integer">17</span>) <span class="directive">const</span> <span class="predefined-type">int</span> arraySize = <span class="integer">12</span>;</code></pre>
9512</div>
9513</div>
9514<div class="paragraph">
9515<p>The above makes a specialization constant with a default value of 12.
9516The number 17 is an example author-chosen id by which the API or other tools
9517can later refer to this specific specialization constant.
9518If it is never changed before final lowering, it will retain the value of
951912.
9520It is a compile-time error to use the <strong>constant_id</strong> qualifier on anything
9521but SPIR-V generation of a scalar <strong>bool</strong>, <strong>int</strong>, <strong>uint</strong>, <strong>float</strong>, or
9522<strong>double</strong>.</p>
9523</div>
9524<div class="paragraph">
9525<p>Built-in constants can be declared to be specialization constants.
9526For example:</p>
9527</div>
9528<div class="listingblock">
9529<div class="content">
9530<pre class="CodeRay highlight"><code data-lang="c++">layout(constant_id = <span class="integer">31</span>) gl_MaxClipDistances; <span class="comment">// add specialization_id</span></code></pre>
9531</div>
9532</div>
9533<div class="paragraph">
9534<p>The declaration uses just the name of the previously declared built-in
9535variable, with a <strong>constant_id</strong> layout-qualifier declaration.
9536It is a compile-time error to do this after the constant has been used:
9537Constants are strictly either non-specialization constants or specialization
9538constants, not both.</p>
9539</div>
9540<div class="paragraph">
9541<p>The built-in constant vector <em>gl_WorkGroupSize</em> can be specialized using the
9542<strong>local_size_{xyz}_id</strong> qualifiers, to individually give the components an id.
9543For example:</p>
9544</div>
9545<div class="listingblock">
9546<div class="content">
9547<pre class="CodeRay highlight"><code data-lang="c++">layout(local_size_x_id = <span class="integer">18</span>, local_size_z_id = <span class="integer">19</span>) in;</code></pre>
9548</div>
9549</div>
9550<div class="paragraph">
9551<p>This leaves <em>gl_WorkGroupSize.y</em> as a non-specialization constant, with
9552<em>gl_WorkGroupSize</em> being a partially specialized vector.
9553Its <em>x</em> and <em>z</em> components can be later specialized, after generating
9554SPIR-V, using the ids 18 and 19.
9555These ids are declared independently from declaring the workgroup size:</p>
9556</div>
9557<div class="listingblock">
9558<div class="content">
9559<pre class="CodeRay highlight"><code data-lang="c++">layout(local_size_x = <span class="integer">32</span>, local_size_y = <span class="integer">32</span>) in;   <span class="comment">// size is (32,32,1)</span>
9560layout(local_size_x_id = <span class="integer">18</span>) in;                   <span class="comment">// constant_id for x</span>
9561layout(local_size_z_id = <span class="integer">19</span>) in;                   <span class="comment">// constant_id for z</span></code></pre>
9562</div>
9563</div>
9564<div class="paragraph">
9565<p>Existing rules for declaring <strong>local_size_x</strong>, <strong>local_size_y</strong>, and
9566<strong>local_size_z</strong> are not changed.
9567For the local-size ids, it is a compile-time error to provide different id
9568values for the same local-size id, or to provide them after any use.
9569Otherwise, order, placement, number of statements, and replication do not
9570cause errors.</p>
9571</div>
9572<div class="paragraph">
9573<p>Two arrays sized with specialization constants are the same type only if
9574sized with the same symbol, and involving no operations.
9575For example:</p>
9576</div>
9577<div class="listingblock">
9578<div class="content">
9579<pre class="CodeRay highlight"><code data-lang="c++">layout(constant_id = <span class="integer">51</span>) <span class="directive">const</span> <span class="predefined-type">int</span> aSize = <span class="integer">20</span>;
9580<span class="directive">const</span> <span class="predefined-type">int</span> pad = <span class="integer">2</span>;
9581<span class="directive">const</span> <span class="predefined-type">int</span> total = aSize + pad; <span class="comment">// specialization constant</span>
9582<span class="predefined-type">int</span> a[total], b[total];        <span class="comment">// a and b have the same type</span>
9583<span class="predefined-type">int</span> c[<span class="integer">22</span>];                     <span class="comment">// different type than a or b</span>
9584<span class="predefined-type">int</span> d[aSize + pad];            <span class="comment">// different type than a, b, or c</span>
9585<span class="predefined-type">int</span> e[aSize + <span class="integer">2</span>];              <span class="comment">// different type than a, b, c, or d</span></code></pre>
9586</div>
9587</div>
9588<div class="paragraph">
9589<p>Types containing arrays sized with a specialization constant cannot be
9590compared, assigned as aggregates, declared with an initializer, or used as
9591an initializer.
9592They can, however, be passed as arguments to functions having formal
9593parameters of the same type.
9594Only the outer-most dimension of a variable declared as an array of arrays
9595can be a specialization constant, otherwise a compile-time error results.</p>
9596</div>
9597<div class="paragraph">
9598<p>Arrays inside a block may be sized with a specialization constant, but the
9599block will have a static layout.
9600Changing the specialized size will not re-layout the block.
9601In the absence of explicit offsets, the layout will be based on the default
9602size of the array.</p>
9603</div>
9604</div>
9605<div class="sect2">
9606<h3 id="order-of-qualification">4.12. Order and Repetition of Qualification</h3>
9607<div class="paragraph">
9608<p>When multiple qualifiers are present in a declaration, they may appear in
9609any order, but they must all appear before the type.
9610The <strong>layout</strong> qualifier is the only qualifier that can appear more than once.
9611Further, a declaration can have at most one storage qualifier, at most one
9612auxiliary storage qualifier, and at most one interpolation qualifier.
9613If <strong>inout</strong> is used, neither <strong>in</strong> nor <strong>out</strong> may be used.
9614Multiple memory qualifiers can be used.
9615Any violation of these rules will cause a compile-time error.</p>
9616</div>
9617</div>
9618<div class="sect2">
9619<h3 id="empty-declarations">4.13. Empty Declarations</h3>
9620<div class="paragraph">
9621<p><em>Empty declarations</em> are declarations without a variable name, meaning no
9622object is instantiated by the declaration.
9623Generally, empty declarations are allowed.
9624Some are useful when declaring structures, while many others have no effect.
9625For example:</p>
9626</div>
9627<div class="listingblock">
9628<div class="content">
9629<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">int</span>;               <span class="comment">// No effect</span>
9630<span class="keyword">struct</span> S {<span class="predefined-type">int</span> x;}; <span class="comment">// Defines a struct S</span></code></pre>
9631</div>
9632</div>
9633<div class="paragraph">
9634<p>The combinations of qualifiers that cause compile-time or link-time errors
9635are the same whether or not the declaration is empty, for example:</p>
9636</div>
9637<div class="listingblock">
9638<div class="content">
9639<pre class="CodeRay highlight"><code data-lang="c++">invariant in <span class="predefined-type">float</span> x; <span class="comment">// Error. An input cannot be invariant.</span>
9640invariant in <span class="predefined-type">float</span>;   <span class="comment">// Error even though no variable is declared.</span></code></pre>
9641</div>
9642</div>
9643</div>
9644</div>
9645</div>
9646<div class="sect1">
9647<h2 id="operators-and-expressions">5. Operators and Expressions</h2>
9648<div class="sectionbody">
9649<div class="sect2">
9650<h3 id="operators">5.1. Operators</h3>
9651<div class="paragraph">
9652<p>The OpenGL Shading Language has the following operators.</p>
9653</div>
9654<table class="tableblock frame-all grid-all stretch">
9655<colgroup>
9656<col style="width: 25%;">
9657<col style="width: 25%;">
9658<col style="width: 25%;">
9659<col style="width: 25%;">
9660</colgroup>
9661<thead>
9662<tr>
9663<th class="tableblock halign-left valign-top">Precedence</th>
9664<th class="tableblock halign-left valign-top">Operator Class</th>
9665<th class="tableblock halign-left valign-top">Operators</th>
9666<th class="tableblock halign-left valign-top">Associativity</th>
9667</tr>
9668</thead>
9669<tbody>
9670<tr>
9671<td class="tableblock halign-left valign-top"><p class="tableblock">1 (highest)</p></td>
9672<td class="tableblock halign-left valign-top"><p class="tableblock">parenthetical grouping</p></td>
9673<td class="tableblock halign-left valign-top"><p class="tableblock">( )</p></td>
9674<td class="tableblock halign-left valign-top"><p class="tableblock">NA</p></td>
9675</tr>
9676<tr>
9677<td class="tableblock halign-left valign-top"><p class="tableblock">2</p></td>
9678<td class="tableblock halign-left valign-top"><p class="tableblock">array subscript<br>
9679                 function call and constructor structure<br>
9680                 field or method selector, swizzle<br>
9681                 post fix increment and decrement</p></td>
9682<td class="tableblock halign-left valign-top"><p class="tableblock">[ ]<br>
9683                                                  ( )<br>
9684                                                  .<br>
9685                                                  ++ --</p></td>
9686<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
9687</tr>
9688<tr>
9689<td class="tableblock halign-left valign-top"><p class="tableblock">3</p></td>
9690<td class="tableblock halign-left valign-top"><p class="tableblock">prefix increment and decrement<br>
9691                 unary</p></td>
9692<td class="tableblock halign-left valign-top"><p class="tableblock">++ --<br>
9693                                                  + - ~ !</p></td>
9694<td class="tableblock halign-left valign-top"><p class="tableblock">Right to Left</p></td>
9695</tr>
9696<tr>
9697<td class="tableblock halign-left valign-top"><p class="tableblock">4</p></td>
9698<td class="tableblock halign-left valign-top"><p class="tableblock">multiplicative</p></td>
9699<td class="tableblock halign-left valign-top"><p class="tableblock">* / %</p></td>
9700<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
9701</tr>
9702<tr>
9703<td class="tableblock halign-left valign-top"><p class="tableblock">5</p></td>
9704<td class="tableblock halign-left valign-top"><p class="tableblock">additive</p></td>
9705<td class="tableblock halign-left valign-top"><p class="tableblock">+ -</p></td>
9706<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
9707</tr>
9708<tr>
9709<td class="tableblock halign-left valign-top"><p class="tableblock">6</p></td>
9710<td class="tableblock halign-left valign-top"><p class="tableblock">bit-wise shift</p></td>
9711<td class="tableblock halign-left valign-top"><p class="tableblock">&lt;&lt; &gt;&gt;</p></td>
9712<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
9713</tr>
9714<tr>
9715<td class="tableblock halign-left valign-top"><p class="tableblock">7</p></td>
9716<td class="tableblock halign-left valign-top"><p class="tableblock">relational</p></td>
9717<td class="tableblock halign-left valign-top"><p class="tableblock">&lt; &gt; &lt;= &gt;=</p></td>
9718<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
9719</tr>
9720<tr>
9721<td class="tableblock halign-left valign-top"><p class="tableblock">8</p></td>
9722<td class="tableblock halign-left valign-top"><p class="tableblock">equality</p></td>
9723<td class="tableblock halign-left valign-top"><p class="tableblock">== !=</p></td>
9724<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
9725</tr>
9726<tr>
9727<td class="tableblock halign-left valign-top"><p class="tableblock">9</p></td>
9728<td class="tableblock halign-left valign-top"><p class="tableblock">bit-wise and</p></td>
9729<td class="tableblock halign-left valign-top"><p class="tableblock">&amp;</p></td>
9730<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
9731</tr>
9732<tr>
9733<td class="tableblock halign-left valign-top"><p class="tableblock">10</p></td>
9734<td class="tableblock halign-left valign-top"><p class="tableblock">bit-wise exclusive or</p></td>
9735<td class="tableblock halign-left valign-top"><p class="tableblock">^</p></td>
9736<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
9737</tr>
9738<tr>
9739<td class="tableblock halign-left valign-top"><p class="tableblock">11</p></td>
9740<td class="tableblock halign-left valign-top"><p class="tableblock">bit-wise inclusive or</p></td>
9741<td class="tableblock halign-left valign-top"><p class="tableblock">|</p></td>
9742<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
9743</tr>
9744<tr>
9745<td class="tableblock halign-left valign-top"><p class="tableblock">12</p></td>
9746<td class="tableblock halign-left valign-top"><p class="tableblock">logical and</p></td>
9747<td class="tableblock halign-left valign-top"><p class="tableblock">&amp;&amp;</p></td>
9748<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
9749</tr>
9750<tr>
9751<td class="tableblock halign-left valign-top"><p class="tableblock">13</p></td>
9752<td class="tableblock halign-left valign-top"><p class="tableblock">logical exclusive or</p></td>
9753<td class="tableblock halign-left valign-top"><p class="tableblock">^^</p></td>
9754<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
9755</tr>
9756<tr>
9757<td class="tableblock halign-left valign-top"><p class="tableblock">14</p></td>
9758<td class="tableblock halign-left valign-top"><p class="tableblock">logical inclusive or</p></td>
9759<td class="tableblock halign-left valign-top"><p class="tableblock">||</p></td>
9760<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
9761</tr>
9762<tr>
9763<td class="tableblock halign-left valign-top"><p class="tableblock">15</p></td>
9764<td class="tableblock halign-left valign-top"><p class="tableblock">selection</p></td>
9765<td class="tableblock halign-left valign-top"><p class="tableblock">? :</p></td>
9766<td class="tableblock halign-left valign-top"><p class="tableblock">Right to Left</p></td>
9767</tr>
9768<tr>
9769<td class="tableblock halign-left valign-top"><p class="tableblock">16</p></td>
9770<td class="tableblock halign-left valign-top"><p class="tableblock">Assignment<br>
9771                 arithmetic assignments</p></td>
9772<td class="tableblock halign-left valign-top"><p class="tableblock">=<br>
9773                                                  += -=<br>
9774                                                  *= /=<br>
9775                                                  %= &lt;&lt;= &gt;&gt;=<br>
9776                                                  &amp;= ^= |=</p></td>
9777<td class="tableblock halign-left valign-top"><p class="tableblock">Right to Left</p></td>
9778</tr>
9779<tr>
9780<td class="tableblock halign-left valign-top"><p class="tableblock">17 (lowest)</p></td>
9781<td class="tableblock halign-left valign-top"><p class="tableblock">sequence</p></td>
9782<td class="tableblock halign-left valign-top"><p class="tableblock">,</p></td>
9783<td class="tableblock halign-left valign-top"><p class="tableblock">Left to Right</p></td>
9784</tr>
9785</tbody>
9786</table>
9787<div class="paragraph">
9788<p>There is no address-of operator nor a dereference operator.
9789There is no typecast operator; constructors are used instead.</p>
9790</div>
9791</div>
9792<div class="sect2">
9793<h3 id="array-operations">5.2. Array Operations</h3>
9794<div class="paragraph">
9795<p>These are now described in &#8220;<a href="#structure-and-array-operations">Structure and
9796Array Operations</a>&#8221;.</p>
9797</div>
9798</div>
9799<div class="sect2">
9800<h3 id="function-calls">5.3. Function Calls</h3>
9801<div class="paragraph">
9802<p>If a function returns a value, then a call to that function may be used as
9803an expression, whose type will be the type that was used to declare or
9804define the function.</p>
9805</div>
9806<div class="paragraph">
9807<p>Function definitions and calling conventions are discussed in
9808&#8220;<a href="#function-definitions">Function Definitions</a>&#8221;.</p>
9809</div>
9810</div>
9811<div class="sect2">
9812<h3 id="constructors">5.4. Constructors</h3>
9813<div class="paragraph">
9814<p>Constructors use the function call syntax, where the function name is a
9815type, and the call makes an object of that type.
9816Constructors are used the same way in both initializers and expressions.
9817(See &#8220;<a href="#shading-language-grammar">Shading Language Grammar</a>&#8221; for details.)
9818The parameters are used to initialize the constructed value.
9819Constructors can be used to request a data type conversion to change from
9820one scalar type to another scalar type, or to build larger types out of
9821smaller types, or to reduce a larger type to a smaller type.</p>
9822</div>
9823<div class="paragraph">
9824<p>In general, constructors are not built-in functions with predetermined
9825prototypes.
9826For arrays and structures, there must be exactly one argument in the
9827constructor for each element or member.
9828For the other types, the arguments must provide a sufficient number of
9829components to perform the initialization, and it is a compile-time error to
9830include so many arguments that they cannot all be used.
9831Detailed rules follow.
9832The prototypes actually listed below are merely a subset of examples.</p>
9833</div>
9834<div class="sect3">
9835<h4 id="conversion-and-scalar-constructors">5.4.1. Conversion and Scalar Constructors</h4>
9836<div class="paragraph">
9837<p>Converting between scalar types is done as the following prototypes
9838indicate:</p>
9839</div>
9840<div class="listingblock">
9841<div class="content">
9842<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">int</span>(uint)     <span class="comment">// converts an unsigned integer to a signed integer</span>
9843<span class="predefined-type">int</span>(<span class="predefined-type">bool</span>)     <span class="comment">// converts a Boolean value to an int</span>
9844<span class="predefined-type">int</span>(<span class="predefined-type">float</span>)    <span class="comment">// converts a float value to an int</span>
9845<span class="predefined-type">int</span>(<span class="predefined-type">double</span>)   <span class="comment">// converts a double value to a signed integer</span>
9846uint(<span class="predefined-type">int</span>)     <span class="comment">// converts a signed integer value to an unsigned integer</span>
9847uint(<span class="predefined-type">bool</span>)    <span class="comment">// converts a Boolean value to an unsigned integer</span>
9848uint(<span class="predefined-type">float</span>)   <span class="comment">// converts a float value to an unsigned integer</span>
9849uint(<span class="predefined-type">double</span>)  <span class="comment">// converts a double value to an unsigned integer</span>
9850<span class="predefined-type">bool</span>(<span class="predefined-type">int</span>)     <span class="comment">// converts a signed integer value to a Boolean</span>
9851<span class="predefined-type">bool</span>(uint)    <span class="comment">// converts an unsigned integer value to a Boolean value</span>
9852<span class="predefined-type">bool</span>(<span class="predefined-type">float</span>)   <span class="comment">// converts a float value to a Boolean</span>
9853<span class="predefined-type">bool</span>(<span class="predefined-type">double</span>)  <span class="comment">// converts a double value to a Boolean</span>
9854<span class="predefined-type">float</span>(<span class="predefined-type">int</span>)    <span class="comment">// converts a signed integer value to a float</span>
9855<span class="predefined-type">float</span>(uint)   <span class="comment">// converts an unsigned integer value to a float value</span>
9856<span class="predefined-type">float</span>(<span class="predefined-type">bool</span>)   <span class="comment">// converts a Boolean value to a float</span>
9857<span class="predefined-type">float</span>(<span class="predefined-type">double</span>) <span class="comment">// converts a double value to a float</span>
9858<span class="predefined-type">double</span>(<span class="predefined-type">int</span>)   <span class="comment">// converts a signed integer value to a double</span>
9859<span class="predefined-type">double</span>(uint)  <span class="comment">// converts an unsigned integer value to a double</span>
9860<span class="predefined-type">double</span>(<span class="predefined-type">bool</span>)  <span class="comment">// converts a Boolean value to a double</span>
9861<span class="predefined-type">double</span>(<span class="predefined-type">float</span>) <span class="comment">// converts a float value to a double</span></code></pre>
9862</div>
9863</div>
9864<div class="paragraph">
9865<p>When constructors are used to convert a floating-point type to an integer
9866type, the fractional part of the floating-point value is dropped.
9867It is undefined to convert a negative floating-point value to an <strong>uint</strong>.</p>
9868</div>
9869<div class="paragraph">
9870<p>Integer values having more bits of precision than a single-precision
9871floating-point mantissa will lose precision when converted to <strong>float</strong>.</p>
9872</div>
9873<div class="paragraph">
9874<p>When a constructor is used to convert any integer or floating-point type to
9875a <strong>bool</strong>, 0 and 0.0 are converted to <strong>false</strong>, and non-zero values are
9876converted to <strong>true</strong>.
9877When a constructor is used to convert a <strong>bool</strong> to any integer or
9878floating-point type, <strong>false</strong> is converted to 0 or 0.0, and <strong>true</strong> is
9879converted to 1 or 1.0.</p>
9880</div>
9881<div class="paragraph">
9882<p>The constructor <strong>int</strong>(<strong>uint</strong>) preserves the bit pattern in the argument,
9883which will change the argument&#8217;s value if its sign bit is set.
9884The constructor <strong>uint</strong>(<strong>int</strong>) preserves the bit pattern in the argument,
9885which will change its value if it is negative.</p>
9886</div>
9887<div class="paragraph">
9888<p>Identity constructors, like <strong>float</strong>(<strong>float</strong>) are also legal, but of little
9889use.</p>
9890</div>
9891<div class="paragraph">
9892<p>Scalar constructors with non-scalar parameters can be used to take the first
9893element from a non-scalar.
9894For example, the constructor <strong>float</strong>(<strong>vec3</strong>) will select the first component
9895of the <strong>vec3</strong> parameter.</p>
9896</div>
9897</div>
9898<div class="sect3">
9899<h4 id="vector-and-matrix-constructors">5.4.2. Vector and Matrix Constructors</h4>
9900<div class="paragraph">
9901<p>Constructors can be used to create vectors or matrices from a set of
9902scalars, vectors, or matrices.
9903This includes the ability to shorten vectors.</p>
9904</div>
9905<div class="paragraph">
9906<p>If there is a single scalar parameter to a vector constructor, it is used to
9907initialize all components of the constructed vector to that scalar&#8217;s value.
9908If there is a single scalar parameter to a matrix constructor, it is used to
9909initialize all the components on the matrix&#8217;s diagonal, with the remaining
9910components initialized to 0.0.</p>
9911</div>
9912<div class="paragraph">
9913<p>If a vector is constructed from multiple scalars, one or more vectors, or
9914one or more matrices, or a mixture of these, the vector&#8217;s components will be
9915constructed in order from the components of the arguments.
9916The arguments will be consumed left to right, and each argument will have
9917all its components consumed, in order, before any components from the next
9918argument are consumed.
9919Similarly for constructing a matrix from multiple scalars or vectors, or a
9920mixture of these.
9921Matrix components will be constructed and consumed in column major order.
9922In these cases, there must be enough components provided in the arguments to
9923provide an initializer for every component in the constructed value.
9924It is a compile-time error to provide extra arguments beyond this last used
9925argument.</p>
9926</div>
9927<div class="paragraph">
9928<p>If a matrix is constructed from a matrix, then each component (column <em>i</em>,
9929row <em>j</em>) in the result that has a corresponding component (column <em>i</em>, row
9930<em>j</em>) in the argument will be initialized from there.
9931All other components will be initialized to the identity matrix.
9932If a matrix argument is given to a matrix constructor, it is
9933a compile-time error to have any other arguments.</p>
9934</div>
9935<div class="paragraph">
9936<p>If the basic type (<strong>bool</strong>, <strong>int</strong>,
9937<strong>float</strong>, or <strong>double</strong>)
9938of a parameter to a
9939constructor does not match the basic type of the object being constructed,
9940the scalar construction rules (above) are used to convert the parameters.</p>
9941</div>
9942<div class="paragraph">
9943<p>Some useful vector constructors are as follows:</p>
9944</div>
9945<div class="listingblock">
9946<div class="content">
9947<pre class="CodeRay highlight"><code data-lang="c++">vec3(<span class="predefined-type">float</span>)          <span class="comment">// initializes each component of the vec3 with the float</span>
9948vec4(ivec4)          <span class="comment">// makes a vec4 with component-wise conversion</span>
9949vec4(mat2)           <span class="comment">// the vec4 is column 0 followed by column 1</span>
9950vec2(<span class="predefined-type">float</span>, <span class="predefined-type">float</span>)   <span class="comment">// initializes a vec2 with 2 floats</span>
9951ivec3(<span class="predefined-type">int</span>, <span class="predefined-type">int</span>, <span class="predefined-type">int</span>) <span class="comment">// initializes an ivec3 with 3 ints</span>
9952bvec4(<span class="predefined-type">int</span>, <span class="predefined-type">int</span>, <span class="predefined-type">float</span>, <span class="predefined-type">float</span>) <span class="comment">// uses 4 Boolean conversions</span>
9953vec2(vec3)           <span class="comment">// drops the third component of a vec3</span>
9954vec3(vec4)           <span class="comment">// drops the fourth component of a vec4</span>
9955vec3(vec2, <span class="predefined-type">float</span>)    <span class="comment">// vec3.x = vec2.x, vec3.y = vec2.y, vec3.z = float</span>
9956vec3(<span class="predefined-type">float</span>, vec2)    <span class="comment">// vec3.x = float, vec3.y = vec2.x, vec3.z = vec2.y</span>
9957vec4(vec3, <span class="predefined-type">float</span>)
9958vec4(<span class="predefined-type">float</span>, vec3)
9959vec4(vec2, vec2)</code></pre>
9960</div>
9961</div>
9962<div class="paragraph">
9963<p>Some examples of these are:</p>
9964</div>
9965<div class="listingblock">
9966<div class="content">
9967<pre class="CodeRay highlight"><code data-lang="c++">vec4 color = vec4(<span class="float">0</span><span class="float">.0</span>, <span class="float">1</span><span class="float">.0</span>, <span class="float">0</span><span class="float">.0</span>, <span class="float">1</span><span class="float">.0</span>);
9968vec4 rgba = vec4(<span class="float">1</span><span class="float">.0</span>);      <span class="comment">// sets each component to 1.0</span>
9969vec3 rgb = vec3(color);     <span class="comment">// drop the 4th component</span></code></pre>
9970</div>
9971</div>
9972<div class="paragraph">
9973<p>To initialize the diagonal of a matrix with all other elements set to zero:</p>
9974</div>
9975<div class="listingblock">
9976<div class="content">
9977<pre class="CodeRay highlight"><code data-lang="c++">mat2(<span class="predefined-type">float</span>)
9978mat3(<span class="predefined-type">float</span>)
9979mat4(<span class="predefined-type">float</span>)</code></pre>
9980</div>
9981</div>
9982<div class="paragraph">
9983<p>That is, <em>result[i][j]</em> is set to the <em>float</em> argument for all \(i
9984= j\) and set to 0 for all \(i \neq j\).</p>
9985</div>
9986<div class="paragraph">
9987<p>To initialize a matrix by specifying vectors or scalars, the components are
9988assigned to the matrix elements in column-major order.</p>
9989</div>
9990<div class="listingblock">
9991<div class="content">
9992<pre class="CodeRay highlight"><code data-lang="c++">mat2(vec2, vec2);                 <span class="comment">// one column per argument</span>
9993mat3(vec3, vec3, vec3);           <span class="comment">// one column per argument</span>
9994mat4(vec4, vec4, vec4, vec4);     <span class="comment">// one column per argument</span>
9995mat3x2(vec2, vec2, vec2);         <span class="comment">// one column per argument</span>
9996dmat2(dvec2, dvec2);
9997dmat3(dvec3, dvec3, dvec3);
9998dmat4(dvec4, dvec4, dvec4, dvec4);
9999mat2(<span class="predefined-type">float</span>, <span class="predefined-type">float</span>,                <span class="comment">// first column</span>
10000     <span class="predefined-type">float</span>, <span class="predefined-type">float</span>);               <span class="comment">// second column</span>
10001mat3(<span class="predefined-type">float</span>, <span class="predefined-type">float</span>, <span class="predefined-type">float</span>,         <span class="comment">// first column</span>
10002     <span class="predefined-type">float</span>, <span class="predefined-type">float</span>, <span class="predefined-type">float</span>,         <span class="comment">// second column</span>
10003     <span class="predefined-type">float</span>, <span class="predefined-type">float</span>, <span class="predefined-type">float</span>);        <span class="comment">// third column</span>
10004mat4(<span class="predefined-type">float</span>, <span class="predefined-type">float</span>, <span class="predefined-type">float</span>, <span class="predefined-type">float</span>,  <span class="comment">// first column</span>
10005     <span class="predefined-type">float</span>, <span class="predefined-type">float</span>, <span class="predefined-type">float</span>, <span class="predefined-type">float</span>,  <span class="comment">// second column</span>
10006     <span class="predefined-type">float</span>, <span class="predefined-type">float</span>, <span class="predefined-type">float</span>, <span class="predefined-type">float</span>,  <span class="comment">// third column</span>
10007     <span class="predefined-type">float</span>, <span class="predefined-type">float</span>, <span class="predefined-type">float</span>, <span class="predefined-type">float</span>); <span class="comment">// fourth column</span>
10008mat2x3(vec2, <span class="predefined-type">float</span>,               <span class="comment">// first column</span>
10009       vec2, <span class="predefined-type">float</span>);              <span class="comment">// second column</span>
10010dmat2x4(dvec3, <span class="predefined-type">double</span>,            <span class="comment">// first column</span>
10011        <span class="predefined-type">double</span>, dvec3);           <span class="comment">// second column</span></code></pre>
10012</div>
10013</div>
10014<div class="paragraph">
10015<p>A wide range of other possibilities exist, to construct a matrix from
10016vectors and scalars, as long as enough components are present to initialize
10017the matrix.
10018To construct a matrix from a matrix:</p>
10019</div>
10020<div class="listingblock">
10021<div class="content">
10022<pre class="CodeRay highlight"><code data-lang="c++">mat3x3(mat4x4); <span class="comment">// takes the upper-left 3x3 of the mat4x4</span>
10023mat2x3(mat4x2); <span class="comment">// takes the upper-left 2x2 of the mat4x4, last row is 0,0</span>
10024mat4x4(mat3x3); <span class="comment">// puts the mat3x3 in the upper-left, sets the lower right</span>
10025                <span class="comment">// component to 1, and the rest to 0</span></code></pre>
10026</div>
10027</div>
10028</div>
10029<div class="sect3">
10030<h4 id="structure-constructors">5.4.3. Structure Constructors</h4>
10031<div class="paragraph">
10032<p>Once a structure is defined, and its type is given a name, a constructor is
10033available with the same name to construct instances of that structure.
10034For example:</p>
10035</div>
10036<div class="listingblock">
10037<div class="content">
10038<pre class="CodeRay highlight"><code data-lang="c++"><span class="keyword">struct</span> light {
10039    <span class="predefined-type">float</span> intensity;
10040    vec3 position;
10041};
10042
10043light lightVar = light(<span class="float">3</span><span class="float">.0</span>, vec3(<span class="float">1</span><span class="float">.0</span>, <span class="float">2</span><span class="float">.0</span>, <span class="float">3</span><span class="float">.0</span>));</code></pre>
10044</div>
10045</div>
10046<div class="paragraph">
10047<p>The arguments to the constructor will be used to set the structure&#8217;s
10048members, in order, using one argument per member.
10049Each argument must be the same type as the member it
10050sets, or be a type that can be converted to the member&#8217;s type according to
10051section &#8220;<a href="#implicit-conversions">Implicit Conversions</a>&#8221;.</p>
10052</div>
10053<div class="paragraph">
10054<p>Structure constructors can be used as initializers or in expressions.</p>
10055</div>
10056</div>
10057<div class="sect3">
10058<h4 id="array-constructors">5.4.4. Array Constructors</h4>
10059<div class="paragraph">
10060<p>Array types can also be used as constructor names, which can then be used in
10061expressions or initializers.
10062For example,</p>
10063</div>
10064<div class="listingblock">
10065<div class="content">
10066<pre class="CodeRay highlight"><code data-lang="c++"><span class="directive">const</span> <span class="predefined-type">float</span> c[<span class="integer">3</span>] = <span class="predefined-type">float</span>[<span class="integer">3</span>](<span class="float">5</span><span class="float">.0</span>, <span class="float">7</span><span class="float">.2</span>, <span class="float">1</span><span class="float">.1</span>);
10067<span class="directive">const</span> <span class="predefined-type">float</span> d[<span class="integer">3</span>] = <span class="predefined-type">float</span>[](<span class="float">5</span><span class="float">.0</span>, <span class="float">7</span><span class="float">.2</span>, <span class="float">1</span><span class="float">.1</span>);
10068
10069<span class="predefined-type">float</span> g;
10070...
10071<span class="predefined-type">float</span> a[<span class="integer">5</span>] = <span class="predefined-type">float</span>[<span class="integer">5</span>](g, <span class="integer">1</span>, g, <span class="float">2</span><span class="float">.3</span>, g);
10072<span class="predefined-type">float</span> b[<span class="integer">3</span>];
10073
10074b = <span class="predefined-type">float</span>[<span class="integer">3</span>](g, g + <span class="float">1</span><span class="float">.0</span>, g + <span class="float">2</span><span class="float">.0</span>);</code></pre>
10075</div>
10076</div>
10077<div class="paragraph">
10078<p>There must be exactly the same number of arguments as the size of the array
10079being constructed.
10080If no size is present in the constructor, then the array is explicitly sized
10081to the number of arguments provided.
10082The arguments are assigned in order, starting at element 0, to the elements
10083of the constructed array.
10084Each argument must be the same type as the element type of the
10085array, or be
10086a type that can be converted to the element type of the array according to
10087&#8220;<a href="#implicit-conversions">Implicit Conversions</a>&#8221;.</p>
10088</div>
10089<div class="paragraph">
10090<p>Arrays of arrays are similarly constructed, and the size for any dimension
10091is <strong class="purple">optional</strong></p>
10092</div>
10093<div class="listingblock">
10094<div class="content">
10095<pre class="CodeRay highlight"><code data-lang="c++">vec4 b[<span class="integer">2</span>] = ...;
10096vec4[<span class="integer">3</span>][<span class="integer">2</span>](b, b, b);    <span class="comment">// constructor</span>
10097vec4[][<span class="integer">2</span>](b, b, b);     <span class="comment">// constructor, valid, size deduced</span>
10098vec4[<span class="integer">3</span>][](b, b, b);     <span class="comment">// constructor, valid, size deduced</span>
10099vec4[][](b, b, b);      <span class="comment">// constructor, valid, both sizes deduced</span></code></pre>
10100</div>
10101</div>
10102</div>
10103<div class="sect3">
10104<h4 id="_texture_combined_sampler_constructors">5.4.5. Texture-Combined Sampler Constructors</h4>
10105<div class="paragraph">
10106<p>Texture-combined sampler constructors are only available when targeting Vulkan.</p>
10107</div>
10108<div class="paragraph">
10109<p>Texture-combined sampler types, like <strong>sampler2D</strong>, can be declared with an
10110initializer
10111that is a constructor of the same type, and consuming a texture and a
10112<strong>sampler</strong> or <strong>samplerShadow</strong>.
10113For example:</p>
10114</div>
10115<div class="listingblock">
10116<div class="content">
10117<pre class="CodeRay highlight"><code data-lang="c++">    layout(...) uniform sampler s;   <span class="comment">// handle to filtering information</span>
10118    layout(...) uniform texture2D t; <span class="comment">// handle to a texture</span>
10119    layout(...) in vec2 tCoord;
10120    ...
10121    texture(sampler2D(t, s), tCoord);</code></pre>
10122</div>
10123</div>
10124<div class="paragraph">
10125<p>The result of a texture-combined sampler constructor cannot be assigned to a
10126variable:</p>
10127</div>
10128<div class="listingblock">
10129<div class="content">
10130<pre class="CodeRay highlight"><code data-lang="c++">    ... sampler2D sConstruct = sampler2D(t, s);  <span class="comment">// ERROR</span></code></pre>
10131</div>
10132</div>
10133<div class="paragraph">
10134<p>Texture-combined sampler constructors can only be consumed by a function parameter.</p>
10135</div>
10136<div class="paragraph">
10137<p>Texture-combined sampler constructors of arrays are illegal:</p>
10138</div>
10139<div class="listingblock">
10140<div class="content">
10141<pre class="CodeRay highlight"><code data-lang="c++">    layout(...) uniform texture2D tArray[<span class="integer">6</span>];
10142    ...
10143    ... sampler2D[](tArray, s) ...  <span class="comment">// ERROR</span></code></pre>
10144</div>
10145</div>
10146<div class="paragraph">
10147<p>Formally:</p>
10148</div>
10149<div class="ulist">
10150<ul>
10151<li>
10152<p>every texture-combined sampler type can be used as a constructor</p>
10153</li>
10154<li>
10155<p>the type of the constructor must match the type of the variable being declared</p>
10156</li>
10157<li>
10158<p>the constructor&#8217;s first argument must be a texture type</p>
10159</li>
10160<li>
10161<p>the constructor&#8217;s second argument must be a scalar of type <strong>sampler</strong>
10162or <strong>samplerShadow</strong></p>
10163</li>
10164<li>
10165<p>the dimensionality (1D, 2D, 3D, Cube, Rect, Buffer, MS, and Array)
10166of the texture type must match that of the constructed type
10167(that is, the suffixes of the type of the first argument and the
10168type of the constructor will be spelled the same way)</p>
10169</li>
10170<li>
10171<p>there is no control flow construct (e.g., <code>?:</code>) that consumes any sampler type</p>
10172</li>
10173</ul>
10174</div>
10175<div class="paragraph">
10176<p>Note: Shadow mismatches are allowed between constructors and the second argument.
10177Texture-combined non-shadow samplers can be constructed from <strong>samplerShadow</strong> and
10178texture-combined shadow samplers can be constructed from <strong>sampler</strong>.</p>
10179</div>
10180</div>
10181</div>
10182<div class="sect2">
10183<h3 id="vector-components">5.5. Vector and Scalar Components and Length</h3>
10184<div class="paragraph">
10185<p>The names of the components of a vector
10186or scalar
10187are denoted by a single letter.
10188As a notational convenience, several letters are associated with each
10189component based on common usage of position, color or texture coordinate
10190vectors.
10191The individual components can be selected by following the variable name
10192with period (<strong>.</strong>) and then the component name.</p>
10193</div>
10194<div class="paragraph">
10195<p>The component names supported are:</p>
10196</div>
10197<table class="tableblock frame-all grid-all fit-content">
10198<colgroup>
10199<col>
10200<col>
10201</colgroup>
10202<tbody>
10203<tr>
10204<td class="tableblock halign-left valign-top"><p class="tableblock"><em>{ x, y, z, w }</em></p></td>
10205<td class="tableblock halign-left valign-top"><p class="tableblock">Useful when accessing vectors that represent points or normals</p></td>
10206</tr>
10207<tr>
10208<td class="tableblock halign-left valign-top"><p class="tableblock"><em>{ r, g, b, a }</em></p></td>
10209<td class="tableblock halign-left valign-top"><p class="tableblock">Useful when accessing vectors that represent colors</p></td>
10210</tr>
10211<tr>
10212<td class="tableblock halign-left valign-top"><p class="tableblock"><em>{ s, t, p, q }</em></p></td>
10213<td class="tableblock halign-left valign-top"><p class="tableblock">Useful when accessing vectors that represent texture coordinates</p></td>
10214</tr>
10215</tbody>
10216</table>
10217<div class="paragraph">
10218<p>The component names <em>x</em>, <em>r</em>, and <em>s</em> are, for example, synonyms for the
10219same (first) component in a vector.
10220They are also the names of the only component in a scalar.</p>
10221</div>
10222<div class="paragraph">
10223<p>Note that the third component of the texture coordinate set
10224has been renamed <em>p</em> so as to avoid the confusion with <em>r</em> (for
10225red) in a color.</p>
10226</div>
10227<div class="paragraph">
10228<p>Accessing components beyond those declared for the type is
10229a compile-time error so, for example:</p>
10230</div>
10231<div class="listingblock">
10232<div class="content">
10233<pre class="CodeRay highlight"><code data-lang="c++">vec2 pos;
10234<span class="predefined-type">float</span> height;
10235pos.x       <span class="comment">// is legal</span>
10236pos.z       <span class="comment">// is illegal</span>
10237height.x    <span class="comment">// is legal</span>
10238height.y    <span class="comment">// is illegal</span></code></pre>
10239</div>
10240</div>
10241<div class="paragraph">
10242<p>The component selection syntax allows multiple components to be selected by
10243appending their names (from the same name set) after the period (<strong>.</strong>).</p>
10244</div>
10245<div class="listingblock">
10246<div class="content">
10247<pre class="CodeRay highlight"><code data-lang="c++">vec4 v4;
10248v4.rgba;    <span class="comment">// is a vec4 and the same as just using v4,</span>
10249v4.rgb;     <span class="comment">// is a vec3,</span>
10250v4.b;       <span class="comment">// is a float,</span>
10251v4.xy;      <span class="comment">// is a vec2,</span>
10252v4.xgba;    <span class="comment">// is illegal - the component names do not come from the same set</span></code></pre>
10253</div>
10254</div>
10255<div class="paragraph">
10256<p>No more than 4 components can be selected.</p>
10257</div>
10258<div class="listingblock">
10259<div class="content">
10260<pre class="CodeRay highlight"><code data-lang="c++">vec4 v4;
10261v4.xyzwxy;      <span class="comment">// is illegal since it has 6 components</span>
10262(v4.xyzwxy).xy; <span class="comment">// is illegal since the intermediate value has 6</span>
10263components</code></pre>
10264</div>
10265</div>
10266<div class="paragraph">
10267<p>The order of the components can be different to swizzle them, or replicated:</p>
10268</div>
10269<div class="listingblock">
10270<div class="content">
10271<pre class="CodeRay highlight"><code data-lang="c++">vec4 pos = vec4(<span class="float">1</span><span class="float">.0</span>, <span class="float">2</span><span class="float">.0</span>, <span class="float">3</span><span class="float">.0</span>, <span class="float">4</span><span class="float">.0</span>);
10272vec4 swiz = pos.wzyx;   <span class="comment">// swiz = (4.0, 3.0, 2.0, 1.0)</span>
10273vec4 dup = pos.xxyy;    <span class="comment">// dup = (1.0, 1.0, 2.0, 2.0)</span></code></pre>
10274</div>
10275</div>
10276<div class="paragraph">
10277<p>This notation is more concise than the constructor syntax.
10278To form an r-value, it can be applied to any expression that results in a
10279vector or scalar r-value.</p>
10280</div>
10281<div class="paragraph">
10282<p>The component group notation can occur on the left hand side of an
10283expression.</p>
10284</div>
10285<div class="listingblock">
10286<div class="content">
10287<pre class="CodeRay highlight"><code data-lang="c++">vec4 pos = vec4(<span class="float">1</span><span class="float">.0</span>, <span class="float">2</span><span class="float">.0</span>, <span class="float">3</span><span class="float">.0</span>, <span class="float">4</span><span class="float">.0</span>);
10288pos.xw = vec2(<span class="float">5</span><span class="float">.0</span>, <span class="float">6</span><span class="float">.0</span>);        <span class="comment">// pos = (5.0, 2.0, 3.0, 6.0)</span>
10289pos.wx = vec2(<span class="float">7</span><span class="float">.0</span>, <span class="float">8</span><span class="float">.0</span>);        <span class="comment">// pos = (8.0, 2.0, 3.0, 7.0)</span>
10290pos.xx = vec2(<span class="float">3</span><span class="float">.0</span>, <span class="float">4</span><span class="float">.0</span>);        <span class="comment">// illegal - 'x' used twice</span>
10291pos.xy = vec3(<span class="float">1</span><span class="float">.0</span>, <span class="float">2</span><span class="float">.0</span>, <span class="float">3</span><span class="float">.0</span>);   <span class="comment">// illegal - mismatch between vec2 and vec3</span></code></pre>
10292</div>
10293</div>
10294<div class="paragraph">
10295<p>To form an l-value, swizzling must further be applied to an l-value and
10296contain no duplicate components. It results in an l-value of scalar or
10297vector type, depending on number of components specified.</p>
10298</div>
10299<div class="paragraph">
10300<p>Array subscripting syntax can also be applied to vectors (but not to
10301scalars) to provide numeric indexing.
10302So in</p>
10303</div>
10304<div class="listingblock">
10305<div class="content">
10306<pre class="CodeRay highlight"><code data-lang="c++">vec4 pos;</code></pre>
10307</div>
10308</div>
10309<div class="paragraph">
10310<p><em>pos[2]</em> refers to the third element of <em>pos</em> and is equivalent to <em>pos.z</em>.
10311This allows variable indexing into a vector, as well as a generic way of
10312accessing components.
10313Any integer expression can be used as the subscript.
10314The first component is at index zero.
10315Reading from or writing to a vector using a constant integral expression
10316with a value that is negative or greater than or equal to the size of the
10317vector results in a compile-time error.
10318When indexing with non-constant expressions, behavior is undefined if the
10319index is negative, or greater than or equal to the size of the vector.</p>
10320</div>
10321<div class="paragraph">
10322<p>The <strong>length</strong>() method may be applied to vectors (but not scalars).
10323The result is the number of components in the vector.
10324For example,</p>
10325</div>
10326<div class="listingblock">
10327<div class="content">
10328<pre class="CodeRay highlight"><code data-lang="c++">vec3 v;
10329<span class="directive">const</span> <span class="predefined-type">int</span> L = v.length();</code></pre>
10330</div>
10331</div>
10332<div class="paragraph">
10333<p>sets the constant <em>L</em> to 3.
10334The type returned by <strong>.length</strong>() on a vector is <strong>int</strong>, and the value
10335returned is a constant expression.</p>
10336</div>
10337</div>
10338<div class="sect2">
10339<h3 id="matrix-components">5.6. Matrix Components</h3>
10340<div class="paragraph">
10341<p>The components of a matrix can be accessed using array subscripting syntax.
10342Applying a single subscript to a matrix treats the matrix as an array of
10343column vectors, and selects a single column, whose type is a vector of the
10344same size as the (column size of the) matrix.
10345The leftmost column is column 0.
10346A second subscript would then operate on the resulting vector, as defined
10347earlier for vectors.
10348Hence, two subscripts select a column and then a row.</p>
10349</div>
10350<div class="listingblock">
10351<div class="content">
10352<pre class="CodeRay highlight"><code data-lang="c++">mat4 m;
10353m[<span class="integer">1</span>] = vec4(<span class="float">2</span><span class="float">.0</span>);   <span class="comment">// sets the second column to all 2.0</span>
10354m[<span class="integer">0</span>][<span class="integer">0</span>] = <span class="float">1</span><span class="float">.0</span>;      <span class="comment">// sets the upper left element to 1.0</span>
10355m[<span class="integer">2</span>][<span class="integer">3</span>] = <span class="float">2</span><span class="float">.0</span>;      <span class="comment">// sets the 4th element of the third column to 2.0</span></code></pre>
10356</div>
10357</div>
10358<div class="paragraph">
10359<p>Behavior is undefined when accessing a component outside the bounds of a
10360matrix with a non-constant expression.
10361It is a compile-time error to access a matrix with a constant expression
10362that is outside the bounds of the matrix.</p>
10363</div>
10364<div class="paragraph">
10365<p>The <strong>length</strong>() method may be applied to matrices.
10366The result is the number of columns of the matrix.
10367For example,</p>
10368</div>
10369<div class="listingblock">
10370<div class="content">
10371<pre class="CodeRay highlight"><code data-lang="c++">mat3x4 v;
10372<span class="directive">const</span> <span class="predefined-type">int</span> L = v.length();</code></pre>
10373</div>
10374</div>
10375<div class="paragraph">
10376<p>sets the constant <em>L</em> to 3.
10377The type returned by <strong>.length</strong>() on a matrix is <strong>int</strong>, and the value
10378returned is a constant expression.</p>
10379</div>
10380</div>
10381<div class="sect2">
10382<h3 id="structure-and-array-operations">5.7. Structure and Array Operations</h3>
10383<div class="paragraph">
10384<p>The members of a structure and the <strong>length</strong>() method of an array are
10385selected using the period (<strong>.</strong>).</p>
10386</div>
10387<div class="paragraph">
10388<p>In total, only the following operators are allowed to operate on arrays and
10389structures as whole entities:</p>
10390</div>
10391<table class="tableblock frame-all grid-all fit-content">
10392<colgroup>
10393<col>
10394<col>
10395</colgroup>
10396<tbody>
10397<tr>
10398<td class="tableblock halign-left valign-top"><p class="tableblock">field selector</p></td>
10399<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>.</strong></p></td>
10400</tr>
10401<tr>
10402<td class="tableblock halign-left valign-top"><p class="tableblock">equality</p></td>
10403<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>==</strong> <strong>!=</strong></p></td>
10404</tr>
10405<tr>
10406<td class="tableblock halign-left valign-top"><p class="tableblock">assignment</p></td>
10407<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>=</strong></p></td>
10408</tr>
10409<tr>
10410<td class="tableblock halign-left valign-top"><p class="tableblock">Ternary operator</p></td>
10411<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>?:</strong></p></td>
10412</tr>
10413<tr>
10414<td class="tableblock halign-left valign-top"><p class="tableblock">Sequence operator</p></td>
10415<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>,</strong></p></td>
10416</tr>
10417<tr>
10418<td class="tableblock halign-left valign-top"><p class="tableblock">indexing (arrays only)</p></td>
10419<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>[</strong> <strong>]</strong></p></td>
10420</tr>
10421</tbody>
10422</table>
10423<div class="paragraph">
10424<p>The equality operators and assignment operator are only allowed if the two
10425operands are same size and type.
10426The operands cannot contain any opaque types.
10427Structure types must be of the same declared structure.
10428Both array operands must be
10429explicitly
10430sized.
10431When using the equality operators, two structures are equal if and only if
10432all the members are component-wise equal, and two arrays are equal if and
10433only if all the elements are element-wise equal.</p>
10434</div>
10435<div class="paragraph">
10436<p>Array elements are accessed using the array subscript operator (<strong>[ ]</strong>).
10437An example of accessing an array element is</p>
10438</div>
10439<div class="listingblock">
10440<div class="content">
10441<pre class="CodeRay highlight"><code data-lang="c++">diffuseColor += lightIntensity[<span class="integer">3</span>] * NdotL;</code></pre>
10442</div>
10443</div>
10444<div class="paragraph">
10445<p>Array indices start at zero.
10446Array elements are accessed using an expression whose type is <strong>int</strong> or
10447<strong>uint</strong>.</p>
10448</div>
10449<div class="paragraph">
10450<p>Behavior is undefined if a shader subscripts an array with an index less
10451than 0 or greater than or equal to the size the array was declared with.</p>
10452</div>
10453<div class="paragraph">
10454<p>Arrays can also be accessed with the method operator (<strong>.</strong>) and the <strong>length</strong>
10455method to query the size of the array:</p>
10456</div>
10457<div class="listingblock">
10458<div class="content">
10459<pre class="CodeRay highlight"><code data-lang="c++">lightIntensity.length() <span class="comment">// return the size of the array</span></code></pre>
10460</div>
10461</div>
10462</div>
10463<div class="sect2">
10464<h3 id="assignments">5.8. Assignments</h3>
10465<div class="paragraph">
10466<p>Assignments of values to variable names are done with the assignment
10467operator (<strong>=</strong>):</p>
10468</div>
10469<div class="dlist">
10470<dl>
10471<dt class="hdlist1"></dt>
10472<dd>
10473<p><em>lvalue-expression</em> = <em>rvalue-expression</em></p>
10474</dd>
10475</dl>
10476</div>
10477<div class="paragraph">
10478<p>The <em>lvalue-expression</em> evaluates to an l-value.
10479The assignment operator stores the value of <em>rvalue-expression</em> into the
10480l-value and returns an r-value with the type and precision of
10481<em>lvalue-expression</em>.
10482The <em>lvalue-expression</em> and <em>rvalue-expression</em> must have the same
10483type, or the expression must have a type in the table in section
10484&#8220;<a href="#implicit-conversions">Implicit Conversions</a>&#8221; that converts to the type
10485of <em>lvalue-expression</em>, in which case an implicit conversion will be done on
10486the <em>rvalue-expression</em> before the assignment is done.
10487Any other desired type-conversions must be specified explicitly via a
10488constructor.
10489It is a compile-time error if the l-value is not writable.
10490Variables that are built-in types, entire structures or arrays, structure
10491members, l-values with the field selector (<strong>.</strong>) applied to select components
10492or swizzles without repeated fields, l-values within parentheses, and
10493l-values dereferenced with the array subscript operator (<strong>[ ]</strong>) are all
10494l-values.
10495Other binary or unary expressions, function names, swizzles with repeated
10496fields, and constants cannot be l-values.
10497The ternary operator (<strong>?:</strong>) is also not allowed as an l-value.
10498Using an incorrect expression as an l-value results in a compile-time error.</p>
10499</div>
10500<div class="paragraph">
10501<p>Expressions on the left of an assignment are evaluated before expressions on
10502the right of the assignment.</p>
10503</div>
10504<div class="paragraph">
10505<p>The other assignment operators are</p>
10506</div>
10507<div class="ulist">
10508<ul>
10509<li>
10510<p>add into (<strong>+=</strong>)</p>
10511</li>
10512<li>
10513<p>subtract from (<strong>-=</strong>)</p>
10514</li>
10515<li>
10516<p>multiply into (<strong>*=</strong>)</p>
10517</li>
10518<li>
10519<p>divide into (<strong>/=</strong>)</p>
10520</li>
10521<li>
10522<p>modulus into (<strong>%=</strong>)</p>
10523</li>
10524<li>
10525<p>left shift by (<strong>&lt;&lt;=</strong>)</p>
10526</li>
10527<li>
10528<p>right shift by (<strong>&gt;&gt;=</strong>)</p>
10529</li>
10530<li>
10531<p>and into (<strong>&amp;=</strong>)</p>
10532</li>
10533<li>
10534<p>inclusive-or into (<strong>|=</strong>)</p>
10535</li>
10536<li>
10537<p>exclusive-or into (<strong>^=</strong>)</p>
10538</li>
10539</ul>
10540</div>
10541<div class="paragraph">
10542<p>where the general expression</p>
10543</div>
10544<div class="dlist">
10545<dl>
10546<dt class="hdlist1"></dt>
10547<dd>
10548<p><em>lvalue</em> <em>op</em>= <em>expression</em></p>
10549</dd>
10550</dl>
10551</div>
10552<div class="paragraph">
10553<p>is equivalent to</p>
10554</div>
10555<div class="dlist">
10556<dl>
10557<dt class="hdlist1"></dt>
10558<dd>
10559<p><em>lvalue</em> = <em>lvalue</em> <em>op</em> <em>expression</em></p>
10560</dd>
10561</dl>
10562</div>
10563<div class="paragraph">
10564<p>where <em>lvalue</em> is the value returned by <em>lvalue-expression</em>, <em>op</em> is as
10565described below, and the <em>lvalue-expression</em> and <em>expression</em> must satisfy
10566the semantic requirements of both <em>op</em> and equals (<strong>=</strong>).</p>
10567</div>
10568<div class="paragraph">
10569<p>Reading a variable before writing (or initializing) it is legal, however the
10570value is undefined.</p>
10571</div>
10572</div>
10573<div class="sect2">
10574<h3 id="expressions">5.9. Expressions</h3>
10575<div class="paragraph">
10576<p>Expressions in the shading language are built from the following:</p>
10577</div>
10578<div class="ulist">
10579<ul>
10580<li>
10581<p>Constants of type <strong>bool</strong>, all integral types, all floating-point types,
10582all vector types, and all matrix types.</p>
10583</li>
10584<li>
10585<p>Constructors of all types.</p>
10586</li>
10587<li>
10588<p>Variable names of all types.</p>
10589</li>
10590<li>
10591<p>An array, vector, or matrix expression with the <strong>length</strong>() method
10592applied.</p>
10593</li>
10594<li>
10595<p>Subscripted arrays.</p>
10596</li>
10597<li>
10598<p>Function calls that return values.
10599In some cases, function calls returning <strong>void</strong> are also allowed in
10600expressions as specified below.</p>
10601</li>
10602<li>
10603<p>Component field selectors and array subscript results.</p>
10604</li>
10605<li>
10606<p>Parenthesized expressions.
10607Any expression, including expressions with void type can be
10608parenthesized.
10609Parentheses can be used to group operations.
10610Operations within parentheses are done before operations across
10611parentheses.</p>
10612</li>
10613<li>
10614<p>The arithmetic binary operators add (<strong>+</strong>), subtract (<strong>-</strong>), multiply
10615(<strong>*</strong>), and divide (<strong>/</strong>) operate on integer and floating-point scalars,
10616vectors, and matrices.
10617If the fundamental types in the operands do not match, then the
10618conversions from &#8220;<a href="#implicit-conversions">Implicit Conversions</a>&#8221; are
10619applied to create matching types.
10620All arithmetic binary operators result in the same fundamental type
10621(signed integer, unsigned integer, single-precision floating-point, or
10622double-precision floating-point) as the operands they operate on, after
10623operand type conversion.
10624After conversion, the following cases are valid</p>
10625<div class="ulist">
10626<ul>
10627<li>
10628<p>The two operands are scalars.
10629In this case the operation is applied, resulting in a scalar.</p>
10630</li>
10631<li>
10632<p>One operand is a scalar, and the other is a vector or matrix.
10633In this case, the scalar operation is applied independently to each
10634component of the vector or matrix, resulting in the same size vector or
10635matrix.</p>
10636</li>
10637<li>
10638<p>The two operands are vectors of the same size.
10639In this case, the operation is done component-wise resulting in the
10640same size vector.</p>
10641</li>
10642<li>
10643<p>The operator is add (<strong>+</strong>), subtract (<strong>-</strong>), or divide (<strong>/</strong>), and the
10644operands are matrices with the same number of rows and the same number
10645of columns.
10646In this case, the operation is done component-wise resulting in the
10647same size matrix.</p>
10648</li>
10649<li>
10650<p>The operator is multiply (<strong>*</strong>), where both operands are matrices or one
10651operand is a vector and the other a matrix.
10652A right vector operand is treated as a column vector and a left vector
10653operand as a row vector.
10654In all these cases, it is required that the number of columns of the
10655left operand is equal to the number of rows of the right operand.
10656Then, the multiply (<strong>*</strong>) operation does a linear algebraic multiply,
10657yielding an object that has the same number of rows as the left operand
10658and the same number of columns as the right operand.
10659&#8220;<a href="#vector-and-matrix-operations">Vector and Matrix Operations</a>&#8221;
10660explains in more detail how vectors and matrices are operated on.</p>
10661<div class="openblock">
10662<div class="content">
10663<div class="paragraph">
10664<p>All other cases result in a compile-time error.</p>
10665</div>
10666<div class="paragraph">
10667<p>Use the built-in functions <strong>dot</strong>, <strong>cross</strong>, <strong>matrixCompMult</strong>, and
10668<strong>outerProduct</strong>, to get, respectively, vector dot product, vector cross
10669product, matrix component-wise multiplication, and the matrix product of a
10670column vector times a row vector.</p>
10671</div>
10672</div>
10673</div>
10674</li>
10675</ul>
10676</div>
10677</li>
10678<li>
10679<p>The operator modulus (<strong>%</strong>) operates on signed or unsigned integers or
10680integer vectors.
10681If the fundamental types in the operands do not match, then the
10682conversions from &#8220;<a href="#implicit-conversions">Implicit Conversions</a>&#8221; are
10683applied to create matching types.
10684The operands cannot be vectors of differing size; this is
10685a compile-time error.
10686If one operand is a scalar and the other vector, then the scalar is
10687applied component-wise to the vector, resulting in the same type as the
10688vector.
10689If both are vectors of the same size, the result is computed
10690component-wise.
10691The resulting value is undefined for any component computed with a
10692second operand that is zero, while results for other components with
10693non-zero second operands remain defined.
10694If both operands are non-negative, then the remainder is non-negative.
10695Results are undefined if one or both operands are negative.
10696The operator modulus (<strong>%</strong>) is not defined for any other data types
10697(non-integer types).</p>
10698</li>
10699<li>
10700<p>The arithmetic unary operators negate (<strong>-</strong>), post- and pre-increment and
10701decrement (<strong>--</strong> and <strong>++</strong>) operate on integer or floating-point values
10702(including vectors and matrices).
10703All unary operators work component-wise on their operands.
10704These result with the same type they operated on.
10705For post- and pre-increment and decrement, the expression must be a writable
10706l-value.
10707Pre-increment and pre-decrement add or subtract 1 or 1.0 to the contents
10708of the expression they operate on, and the value of the pre-increment or
10709pre-decrement expression is the resulting value of that modification.
10710Post-increment and post-decrement expressions add or subtract 1 or 1.0
10711to the contents of the expression they operate on, but the resulting
10712expression has the expression&#8217;s value before the post-increment or
10713post-decrement was executed.</p>
10714</li>
10715<li>
10716<p>The relational operators greater than (<strong>&gt;</strong>), less than (<strong>&lt;</strong>), greater
10717than or equal (<strong>&gt;=</strong>), and less than or equal (<strong>&lt;=</strong>) operate only on
10718scalar integer and scalar floating-point expressions.
10719The result is scalar Boolean.
10720Either the operands' types must match, or the conversions from section
10721&#8220;<a href="#implicit-conversions">Implicit Conversions</a>&#8221; will be applied to
10722obtain matching types.
10723To do component-wise relational comparisons on vectors, use the built-in
10724functions <strong>lessThan</strong>, <strong>lessThanEqual</strong>, <strong>greaterThan</strong>, and
10725<strong>greaterThanEqual.</strong></p>
10726</li>
10727<li>
10728<p>The equality operators <strong>equal</strong> (<strong>==</strong>), and not equal (<strong>!=</strong>) operate on
10729all types except opaque types, aggregates that contain opaque types,
10730subroutine uniforms, and aggregates that contain subroutine uniforms.
10731They result in a scalar Boolean.
10732If the operand types do not match, then there must be a conversion from
10733&#8220;<a href="#implicit-conversions">Implicit Conversions</a>&#8221; applied to one operand
10734that can make them match, in which case this conversion is done.
10735For vectors, matrices, structures, and arrays, all components, members,
10736or elements of one operand must equal the corresponding components,
10737members, or elements in the other operand for the operands to be
10738considered equal.
10739To get a vector of component-wise equality results for vectors, use the
10740built-in functions <strong>equal</strong> and <strong>notEqual</strong>.</p>
10741</li>
10742<li>
10743<p>The logical binary operators and (<strong>&amp;&amp;</strong>), or (<strong>||</strong>), and exclusive or
10744(<strong>^^</strong>) operate only on two Boolean expressions and result in a Boolean
10745expression.
10746And (<strong>&amp;&amp;</strong>) will only evaluate the right hand operand if the left hand
10747operand evaluated to <strong>true</strong>.
10748Or (<strong>||</strong>) will only evaluate the right hand operand if the left hand
10749operand evaluated to <strong>false</strong>.
10750Exclusive or (<strong>^^</strong>) will always evaluate both operands.</p>
10751</li>
10752<li>
10753<p>The logical unary operator not (<strong>!</strong>).
10754It operates only on a Boolean expression and results in a Boolean
10755expression.
10756To operate on a vector, use the built-in function <strong>not</strong>.</p>
10757</li>
10758<li>
10759<p>The sequence (<strong>,</strong>) operator that operates on expressions by returning
10760the type and value of the right-most expression in a comma separated
10761list of expressions.
10762All expressions are evaluated, in order, from left to right.
10763The operands to the sequence operator may have <strong>void</strong> type.
10764Opaque types cannot be used with the sequence (,) operator.</p>
10765</li>
10766<li>
10767<p>The ternary selection operator (<strong>?:</strong>).
10768It operates on three expressions (<em>exp1</em> <strong>?</strong> <em>exp2</em> <strong>:</strong> <em>exp3</em>).
10769This operator evaluates the first expression, which must result in a
10770scalar Boolean.
10771If the result is true, it selects to evaluate the second expression,
10772otherwise it selects to evaluate the third expression.
10773Only one of the second and third expressions is evaluated.
10774The second and third expressions cannot be opaque types,
10775or there will be a compile-time error.
10776Otherwise,
10777the second and third expressions can be any type, including <strong>void</strong>, as
10778long their types match, or there is a conversion in section
10779&#8220;<a href="#implicit-conversions">Implicit Conversions</a>&#8221; that can be applied to
10780one of the expressions to make their types match.
10781This resulting matching type is the type of the entire expression.</p>
10782</li>
10783<li>
10784<p>The one&#8217;s complement operator (<strong>~</strong>).
10785The operand must be of type signed or unsigned integer or integer
10786vector, and the result is the one&#8217;s complement of its operand; each bit
10787of each component is complemented, including any sign bits.</p>
10788</li>
10789<li>
10790<p>The shift operators (<strong>&lt;&lt;</strong>) and (<strong>&gt;&gt;</strong>).
10791For both operators, the operands must be signed or unsigned integers or
10792integer vectors.
10793One operand can be signed while the other is unsigned.
10794In all cases, the resulting type will be the same type as the left
10795operand.
10796If the first operand is a scalar, the second operand has to be a scalar
10797as well.
10798If the first operand is a vector, the second operand must be a scalar or
10799a vector with the same size as the first operand, and the result is
10800computed component-wise.
10801The result is undefined if the right operand is negative, or greater
10802than or equal to the number of bits in the left expression&#8217;s base type.
10803The value of E1 &lt;&lt; E2 is E1 (interpreted as a bit pattern) left-shifted
10804by E2 bits.
10805The value of E1 &gt;&gt; E2 is E1 right-shifted by E2 bit positions.
10806If E1 is a signed integer, the right-shift will extend the sign bit.
10807If E1 is an unsigned integer, the right-shift will zero-extend.</p>
10808</li>
10809<li>
10810<p>The bitwise operators and (<strong>&amp;</strong>), exclusive-or (<strong>^</strong>), and inclusive-or
10811(<strong>|</strong>).
10812The operands must be of type signed or unsigned integers or integer
10813vectors.
10814The operands cannot be vectors of differing size; this is a compile-time error.
10815If one operand is a scalar and the other a vector, the scalar is applied
10816component-wise to the vector, resulting in the same type as the vector.
10817If the fundamental types in the operands do not match, then the
10818conversions from &#8220;<a href="#implicit-conversions">Implicit Conversions</a>&#8221; are
10819applied to create matching types, and this will be the resulting
10820fundamental type.
10821For and (<strong>&amp;</strong>), the result is the bitwise-and function of the operands.
10822For exclusive-or (<strong>^</strong>), the result is the bitwise exclusive-or function
10823of the operands.
10824For inclusive-or (<strong>|</strong>), the result is the bitwise inclusive-or function
10825of the operands.</p>
10826</li>
10827</ul>
10828</div>
10829<div class="paragraph">
10830<p>For a complete specification of the syntax of expressions, see
10831&#8220;<a href="#shading-language-grammar">Shading Language Grammar</a>&#8221;.</p>
10832</div>
10833</div>
10834<div class="sect2">
10835<h3 id="vector-and-matrix-operations">5.10. Vector and Matrix Operations</h3>
10836<div class="paragraph">
10837<p>With a few exceptions, operations are component-wise.
10838Usually, when an operator operates on a vector or matrix, it is operating
10839independently on each component of the vector or matrix, in a component-wise
10840fashion.
10841For example,</p>
10842</div>
10843<div class="listingblock">
10844<div class="content">
10845<pre class="CodeRay highlight"><code data-lang="c++">vec3 v, u;
10846<span class="predefined-type">float</span> f;
10847v = u + f;</code></pre>
10848</div>
10849</div>
10850<div class="paragraph">
10851<p>will be equivalent to</p>
10852</div>
10853<div class="listingblock">
10854<div class="content">
10855<pre class="CodeRay highlight"><code data-lang="c++">v.x = u.x + f;
10856v.y = u.y + f;
10857v.z = u.z + f;</code></pre>
10858</div>
10859</div>
10860<div class="paragraph">
10861<p>And</p>
10862</div>
10863<div class="listingblock">
10864<div class="content">
10865<pre class="CodeRay highlight"><code data-lang="c++">vec3 v, u, w;
10866w = v + u;</code></pre>
10867</div>
10868</div>
10869<div class="paragraph">
10870<p>will be equivalent to</p>
10871</div>
10872<div class="listingblock">
10873<div class="content">
10874<pre class="CodeRay highlight"><code data-lang="c++">w.x = v.x + u.x;
10875w.y = v.y + u.y;
10876w.z = v.z + u.z;</code></pre>
10877</div>
10878</div>
10879<div class="paragraph">
10880<p>and likewise for most operators and all integer and floating-point vector
10881and matrix types.
10882The exceptions are matrix multiplied by vector, vector multiplied by matrix,
10883and matrix multiplied by matrix.
10884These do not operate component-wise, but rather perform the correct linear
10885algebraic multiply.</p>
10886</div>
10887<div class="listingblock">
10888<div class="content">
10889<pre class="CodeRay highlight"><code data-lang="c++">vec3 v, u;
10890mat3 m;
10891u = v * m;</code></pre>
10892</div>
10893</div>
10894<div class="paragraph">
10895<p>is equivalent to</p>
10896</div>
10897<div class="listingblock">
10898<div class="content">
10899<pre class="CodeRay highlight"><code data-lang="c++">u.x = dot(v, m[<span class="integer">0</span>]); <span class="comment">// m[0] is the left column of m</span>
10900u.y = dot(v, m[<span class="integer">1</span>]); <span class="comment">// dot(a,b) is the inner (dot) product of a and b</span>
10901u.z = dot(v, m[<span class="integer">2</span>]);</code></pre>
10902</div>
10903</div>
10904<div class="paragraph">
10905<p>And</p>
10906</div>
10907<div class="listingblock">
10908<div class="content">
10909<pre class="CodeRay highlight"><code data-lang="c++">u = m * v;</code></pre>
10910</div>
10911</div>
10912<div class="paragraph">
10913<p>is equivalent to</p>
10914</div>
10915<div class="listingblock">
10916<div class="content">
10917<pre class="CodeRay highlight"><code data-lang="c++">u.x = m[<span class="integer">0</span>].x * v.x + m[<span class="integer">1</span>].x * v.y + m[<span class="integer">2</span>].x * v.z;
10918u.y = m[<span class="integer">0</span>].y * v.x + m[<span class="integer">1</span>].y * v.y + m[<span class="integer">2</span>].y * v.z;
10919u.z = m[<span class="integer">0</span>].z * v.x + m[<span class="integer">1</span>].z * v.y + m[<span class="integer">2</span>].z * v.z;</code></pre>
10920</div>
10921</div>
10922<div class="paragraph">
10923<p>And</p>
10924</div>
10925<div class="listingblock">
10926<div class="content">
10927<pre class="CodeRay highlight"><code data-lang="c++">mat3 m, n, r;
10928r = m * n;</code></pre>
10929</div>
10930</div>
10931<div class="paragraph">
10932<p>is equivalent to</p>
10933</div>
10934<div class="listingblock">
10935<div class="content">
10936<pre class="CodeRay highlight"><code data-lang="c++">r[<span class="integer">0</span>].x = m[<span class="integer">0</span>].x * n[<span class="integer">0</span>].x + m[<span class="integer">1</span>].x * n[<span class="integer">0</span>].y + m[<span class="integer">2</span>].x * n[<span class="integer">0</span>].z;
10937r[<span class="integer">1</span>].x = m[<span class="integer">0</span>].x * n[<span class="integer">1</span>].x + m[<span class="integer">1</span>].x * n[<span class="integer">1</span>].y + m[<span class="integer">2</span>].x * n[<span class="integer">1</span>].z;
10938r[<span class="integer">2</span>].x = m[<span class="integer">0</span>].x * n[<span class="integer">2</span>].x + m[<span class="integer">1</span>].x * n[<span class="integer">2</span>].y + m[<span class="integer">2</span>].x * n[<span class="integer">2</span>].z;
10939r[<span class="integer">0</span>].y = m[<span class="integer">0</span>].y * n[<span class="integer">0</span>].x + m[<span class="integer">1</span>].y * n[<span class="integer">0</span>].y + m[<span class="integer">2</span>].y * n[<span class="integer">0</span>].z;
10940r[<span class="integer">1</span>].y = m[<span class="integer">0</span>].y * n[<span class="integer">1</span>].x + m[<span class="integer">1</span>].y * n[<span class="integer">1</span>].y + m[<span class="integer">2</span>].y * n[<span class="integer">1</span>].z;
10941r[<span class="integer">2</span>].y = m[<span class="integer">0</span>].y * n[<span class="integer">2</span>].x + m[<span class="integer">1</span>].y * n[<span class="integer">2</span>].y + m[<span class="integer">2</span>].y * n[<span class="integer">2</span>].z;
10942r[<span class="integer">0</span>].z = m[<span class="integer">0</span>].z * n[<span class="integer">0</span>].x + m[<span class="integer">1</span>].z * n[<span class="integer">0</span>].y + m[<span class="integer">2</span>].z * n[<span class="integer">0</span>].z;
10943r[<span class="integer">1</span>].z = m[<span class="integer">0</span>].z * n[<span class="integer">1</span>].x + m[<span class="integer">1</span>].z * n[<span class="integer">1</span>].y + m[<span class="integer">2</span>].z * n[<span class="integer">1</span>].z;
10944r[<span class="integer">2</span>].z = m[<span class="integer">0</span>].z * n[<span class="integer">2</span>].x + m[<span class="integer">1</span>].z * n[<span class="integer">2</span>].y + m[<span class="integer">2</span>].z * n[<span class="integer">2</span>].z;</code></pre>
10945</div>
10946</div>
10947<div class="paragraph">
10948<p>and similarly for other sizes of vectors and matrices.</p>
10949</div>
10950</div>
10951<div class="sect2">
10952<h3 id="out-of-bounds-accesses">5.11. Out-of-Bounds Accesses</h3>
10953<div class="paragraph">
10954<p>In the subsections described above for array, vector, matrix and structure
10955accesses, any out-of-bounds access produced undefined behavior.
10956However, if robust buffer access is enabled via the API, such
10957accesses will be bound within the memory extent of the active program.
10958It will not be possible to access memory from other programs, and accesses
10959will not result in abnormal program termination.
10960Out-of-bounds reads return undefined values, which include values from other
10961variables of the active program or zero.
10962Out-of-bounds writes may be discarded or overwrite other variables of the
10963active program, depending on the value of the computed index and how this
10964relates to the extent of the active program&#8217;s memory.
10965Applications that require defined behavior for out-of-bounds accesses should
10966range check all computed indices before dereferencing an array.</p>
10967</div>
10968</div>
10969<div class="sect2">
10970<h3 id="specialization-constant-operations">5.12. Specialization-Constant Operations</h3>
10971<div class="paragraph">
10972<p>Specialization-constant operations are only available when targeting SPIR-V.</p>
10973</div>
10974<div class="paragraph">
10975<p>Only some operations discussed in this section may be applied to a
10976specialization constant and still yield a result that is a specialization
10977constant.
10978The operations that do so are listed below.
10979When a specialization constant is operated on with one of these operators
10980and with another constant or specialization constant, the result is
10981implicitly a specialization constant.</p>
10982</div>
10983<div class="ulist">
10984<ul>
10985<li>
10986<p><strong>int</strong>(), <strong>uint</strong>(), and <strong>bool</strong>() constructors for type conversions from
10987any of the following types to any of the following types:</p>
10988<div class="ulist">
10989<ul>
10990<li>
10991<p><strong>int</strong></p>
10992</li>
10993<li>
10994<p><strong>uint</strong></p>
10995</li>
10996<li>
10997<p><strong>bool</strong></p>
10998</li>
10999</ul>
11000</div>
11001</li>
11002<li>
11003<p>vector versions of the above conversion constructors</p>
11004</li>
11005<li>
11006<p>allowed implicit conversions of the above</p>
11007</li>
11008<li>
11009<p>swizzles (e.g. <code>foo.yx</code>)</p>
11010</li>
11011<li>
11012<p>the following when applied to integer or unsigned integer types:</p>
11013<div class="ulist">
11014<ul>
11015<li>
11016<p>unary negative (<strong>-</strong>)</p>
11017</li>
11018<li>
11019<p>binary operations (<strong>+</strong>, <strong>-</strong>, <strong>*</strong>, <strong>/</strong>, <strong>%</strong>)</p>
11020</li>
11021<li>
11022<p>shift (<strong>&lt;&lt;</strong>, <strong>&gt;&gt;</strong>)</p>
11023</li>
11024<li>
11025<p>bitwise operations (<strong>&amp;</strong>, <strong>|</strong>, <strong>^</strong>)</p>
11026</li>
11027</ul>
11028</div>
11029</li>
11030<li>
11031<p>the following when applied to integer or unsigned integer scalar types:</p>
11032<div class="ulist">
11033<ul>
11034<li>
11035<p>comparison (<strong>==</strong>, <strong>!=</strong>, <strong>&gt;</strong>, <strong>&gt;=</strong>, <strong>&lt;</strong>, <strong>&#8656;</strong>)</p>
11036</li>
11037</ul>
11038</div>
11039</li>
11040<li>
11041<p>The following when applied to the Boolean scalar type:</p>
11042<div class="ulist">
11043<ul>
11044<li>
11045<p>not (<strong>!</strong>)</p>
11046</li>
11047<li>
11048<p>logical operations (<strong>&amp;&amp;</strong>, <strong>||</strong>, <strong>^^</strong>)</p>
11049</li>
11050<li>
11051<p>comparison (<strong>==</strong>, <strong>!=</strong>)</p>
11052</li>
11053</ul>
11054</div>
11055</li>
11056<li>
11057<p>the ternary operator (<strong>?:</strong>)</p>
11058</li>
11059</ul>
11060</div>
11061</div>
11062</div>
11063</div>
11064<div class="sect1">
11065<h2 id="statements-and-structure">6. Statements and Structure</h2>
11066<div class="sectionbody">
11067<div class="paragraph">
11068<p>The fundamental building blocks of the OpenGL Shading Language are:</p>
11069</div>
11070<div class="ulist">
11071<ul>
11072<li>
11073<p>statements and declarations</p>
11074</li>
11075<li>
11076<p>function definitions</p>
11077</li>
11078<li>
11079<p>selection (<strong>if</strong>-<strong>else</strong> and <strong>switch</strong>-<strong>case</strong>-<strong>default</strong>)</p>
11080</li>
11081<li>
11082<p>iteration (<strong>for</strong>, <strong>while</strong>, and <strong>do</strong>-<strong>while</strong>)</p>
11083</li>
11084<li>
11085<p>jumps (<strong>discard</strong>, <strong>return</strong>, <strong>break</strong>, and <strong>continue</strong>)</p>
11086</li>
11087</ul>
11088</div>
11089<div class="paragraph">
11090<p>The overall structure of a shader is as follows</p>
11091</div>
11092<div class="openblock bnf">
11093<div class="content">
11094<div class="dlist">
11095<dl>
11096<dt class="hdlist1"><em>translation-unit</em> : </dt>
11097<dd>
11098<p><em>global-declaration</em><br>
11099<em>translation-unit</em> <em>global-declaration</em></p>
11100</dd>
11101<dt class="hdlist1"><em>global-declaration</em> : </dt>
11102<dd>
11103<p><em>function-definition</em><br>
11104<em>declaration</em></p>
11105</dd>
11106</dl>
11107</div>
11108</div>
11109</div>
11110<div class="paragraph">
11111<p>That is, a shader is a sequence of declarations and function bodies.
11112Function bodies are defined as</p>
11113</div>
11114<div class="openblock bnf">
11115<div class="content">
11116<div class="dlist">
11117<dl>
11118<dt class="hdlist1"><em>function-definition</em> : </dt>
11119<dd>
11120<p><em>function-prototype</em> <strong>{</strong> <em>statement-list</em> <strong>}</strong></p>
11121</dd>
11122<dt class="hdlist1"><em>statement-list</em> : </dt>
11123<dd>
11124<p><em>statement</em><br>
11125<em>statement-list</em> <em>statement</em></p>
11126</dd>
11127<dt class="hdlist1"><em>statement</em> : </dt>
11128<dd>
11129<p><em>compound-statement</em><br>
11130<em>simple-statement</em></p>
11131</dd>
11132</dl>
11133</div>
11134</div>
11135</div>
11136<div class="paragraph">
11137<p>Curly braces are used to group sequences of statements into compound
11138statements.</p>
11139</div>
11140<div class="openblock bnf">
11141<div class="content">
11142<div class="dlist">
11143<dl>
11144<dt class="hdlist1"><em>compound-statement</em> : </dt>
11145<dd>
11146<p><strong>{</strong> <em>statement-list</em> <strong>}</strong></p>
11147</dd>
11148<dt class="hdlist1"><em>simple-statement</em> : </dt>
11149<dd>
11150<p><em>declaration-statement</em><br>
11151<em>expression-statement</em><br>
11152<em>selection-statement</em><br>
11153<em>iteration-statement</em><br>
11154<em>jump-statement</em></p>
11155</dd>
11156</dl>
11157</div>
11158</div>
11159</div>
11160<div class="paragraph">
11161<p>Simple declaration, expression, and jump statements end in a semi-colon.</p>
11162</div>
11163<div class="paragraph">
11164<p>This above is slightly simplified, and the complete grammar specified in
11165&#8220;<a href="#shading-language-grammar">Shading Language Grammar</a>&#8221; should be used as
11166the definitive specification.</p>
11167</div>
11168<div class="paragraph">
11169<p>Declarations and expressions have already been discussed.</p>
11170</div>
11171<div class="sect2">
11172<h3 id="function-definitions">6.1. Function Definitions</h3>
11173<div class="paragraph">
11174<p>As indicated by the grammar above, a valid shader is a sequence of global
11175declarations and function definitions.
11176A function is declared as the following example shows:</p>
11177</div>
11178<div class="listingblock">
11179<div class="content">
11180<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">// prototype</span>
11181returnType functionName (type0 arg0, type1 arg1, ..., typen argn);</code></pre>
11182</div>
11183</div>
11184<div class="paragraph">
11185<p>and a function is defined like</p>
11186</div>
11187<div class="listingblock">
11188<div class="content">
11189<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">// definition</span>
11190returnType functionName (type0 arg0, type1 arg1, ..., typen argn)
11191{
11192    <span class="comment">// do some computation</span>
11193    <span class="keyword">return</span> returnValue;
11194}</code></pre>
11195</div>
11196</div>
11197<div class="paragraph">
11198<p>where <em>returnType</em> must be present and cannot be void, or:</p>
11199</div>
11200<div class="listingblock">
11201<div class="content">
11202<pre class="CodeRay highlight"><code data-lang="c++"><span class="directive">void</span> functionName (type0 arg0, type1 arg1, ..., typen argn)
11203{
11204    <span class="comment">// do some computation</span>
11205    <span class="keyword">return</span>; <span class="comment">// optional</span>
11206}</code></pre>
11207</div>
11208</div>
11209<div class="paragraph">
11210<p>If the type of <em>returnValue</em> does not match <em>returnType</em>, there must be an
11211implicit conversion in &#8220;<a href="#implicit-conversions">Implicit Conversions</a>&#8221;
11212that converts the type of <em>returnValue</em> to <em>returnType</em>, or a compile-time
11213error will result.</p>
11214</div>
11215<div class="paragraph">
11216<p>Each of the <em>typeN</em> must include a type and can optionally include parameter
11217qualifiers.
11218The formal argument names (<em>args</em> above) in the declarations are optional
11219for both the declaration and definition forms.</p>
11220</div>
11221<div class="paragraph">
11222<p>A function is called by using its name followed by a list of arguments in
11223parentheses.</p>
11224</div>
11225<div class="paragraph">
11226<p>Arrays are allowed as arguments and as the return type.
11227In both cases, the array must be
11228explicitly
11229sized.
11230An array is passed or returned by using just its name, without brackets, and
11231the size of the array must match the size specified in the function&#8217;s
11232declaration.</p>
11233</div>
11234<div class="paragraph">
11235<p>Structures are also allowed as argument types.
11236The return type can also be a structure.</p>
11237</div>
11238<div class="paragraph">
11239<p>See &#8220;<a href="#shading-language-grammar">Shading Language Grammar</a>&#8221; for the
11240definitive reference on the syntax to declare and define functions.</p>
11241</div>
11242<div class="paragraph">
11243<p>All functions must be either declared with a prototype or defined with a
11244body before they are called.
11245For example:</p>
11246</div>
11247<div class="listingblock">
11248<div class="content">
11249<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span> myfunc (<span class="predefined-type">float</span> f,      <span class="comment">// f is an input parameter</span>
11250              out <span class="predefined-type">float</span> g); <span class="comment">// g is an output parameter</span></code></pre>
11251</div>
11252</div>
11253<div class="paragraph">
11254<p>Functions that return no value must be declared as <strong>void</strong>.
11255A <strong>void</strong> function can only use <strong>return</strong> without a return argument, even if
11256the return argument has <strong>void</strong> type.
11257Return statements only accept values:</p>
11258</div>
11259<div class="listingblock">
11260<div class="content">
11261<pre class="CodeRay highlight"><code data-lang="c++"><span class="directive">void</span> func1() { }
11262<span class="directive">void</span> func2() { <span class="keyword">return</span> func1(); } <span class="comment">// illegal return statement</span></code></pre>
11263</div>
11264</div>
11265<div class="paragraph">
11266<p>Only a precision qualifier is allowed on the return type of a function.
11267Formal parameters can have parameter, precision, and memory qualifiers, but
11268no other qualifiers.</p>
11269</div>
11270<div class="paragraph">
11271<p>Functions that accept no input arguments need not use <strong>void</strong> in the argument
11272list because prototypes (or definitions) are required and therefore there is
11273no ambiguity when an empty argument list &#8220;( )&#8221; is declared.
11274The idiom &#8220;(<strong>void</strong>)&#8221; as a parameter list is provided for convenience.</p>
11275</div>
11276<div class="paragraph">
11277<p>Function names can be overloaded.
11278The same function name can be used for multiple functions, as long as the
11279parameter types differ.
11280If a function name is declared twice with the same parameter types, then the
11281return types and all qualifiers must also match, and it is the same function
11282being declared.</p>
11283</div>
11284<div class="paragraph">
11285<p>For example,</p>
11286</div>
11287<div class="listingblock">
11288<div class="content">
11289<pre class="CodeRay highlight"><code data-lang="c++">vec4 f(in vec4 x, out vec4 y);       <span class="comment">// (A)</span>
11290vec4 f(in vec4 x, out uvec4 y);      <span class="comment">// (B) okay, different argument type</span>
11291vec4 f(in ivec4 x, out dvec4 y);     <span class="comment">// (C) okay, different argument type</span>
11292<span class="predefined-type">int</span> f(in vec4 x, out vec4 y);        <span class="comment">// error, only return type differs</span>
11293vec4 f(in vec4 x, in vec4 y);        <span class="comment">// error, only qualifier differs</span>
11294vec4 f(<span class="directive">const</span> in vec4 x, out vec4 y); <span class="comment">// error, only qualifier differs</span></code></pre>
11295</div>
11296</div>
11297<div class="paragraph">
11298<p>When function calls are resolved, an exact type match for all the arguments
11299is sought.
11300If an exact match is found, all other functions are ignored, and the exact
11301match is used.
11302If no exact match is found, then the implicit conversions in section
11303&#8220;<a href="#implicit-conversions">Implicit Conversions</a>&#8221; will be applied to find a
11304match.
11305Mismatched types on input parameters (<strong>in</strong> or <strong>inout</strong> or default) <strong>must</strong>
11306have a conversion from the calling argument type to the formal parameter
11307type.
11308Mismatched types on output parameters (<strong>out</strong> or <strong>inout</strong>) must have a
11309conversion from the formal parameter type to the calling argument type.</p>
11310</div>
11311<div class="paragraph">
11312<p>If implicit conversions can be used to find more than one matching function,
11313a single best-matching function is sought.
11314To determine a best match, the conversions between calling argument and
11315formal parameter types are compared for each function argument and pair of
11316matching functions.
11317After these comparisons are performed, each pair of matching functions are
11318compared.
11319A function declaration <em>A</em> is considered a better match than function
11320declaration <em>B</em> if</p>
11321</div>
11322<div class="ulist">
11323<ul>
11324<li>
11325<p>for at least one function argument, the conversion for that argument in
11326<em>A</em> is better than the corresponding conversion in <em>B</em>; and</p>
11327</li>
11328<li>
11329<p>there is no function argument for which the conversion in <em>B</em> is better
11330than the corresponding conversion in <em>A</em>.</p>
11331</li>
11332</ul>
11333</div>
11334<div class="paragraph">
11335<p>If a single function declaration is considered a better match than every
11336other matching function declaration, it will be used.
11337Otherwise, a compile-time semantic error for an ambiguous overloaded
11338function call occurs.</p>
11339</div>
11340<div class="paragraph">
11341<p>To determine whether the conversion for a single argument in one match is
11342better than that for another match, the following rules are applied, in
11343order:</p>
11344</div>
11345<div class="olist arabic">
11346<ol class="arabic">
11347<li>
11348<p>An exact match is better than a match involving any implicit conversion.</p>
11349</li>
11350<li>
11351<p>A match involving an implicit conversion from <strong>float</strong> to <strong>double</strong> is
11352better than a match involving any other implicit conversion.</p>
11353</li>
11354<li>
11355<p>A match involving an implicit conversion from either <strong>int</strong> or <strong>uint</strong> to
11356<strong>float</strong> is better than a match involving an implicit conversion from
11357either <strong>int</strong> or <strong>uint</strong> to <strong>double</strong>.</p>
11358</li>
11359</ol>
11360</div>
11361<div class="paragraph">
11362<p>If none of the rules above apply to a particular pair of conversions,
11363neither conversion is considered better than the other.</p>
11364</div>
11365<div class="paragraph">
11366<p>For the example function prototypes (A), (B), and &#169; above, the following
11367examples show how the rules apply to different sets of calling argument
11368types:</p>
11369</div>
11370<div class="listingblock">
11371<div class="content">
11372<pre class="CodeRay highlight"><code data-lang="c++">f(vec4, vec4)   <span class="comment">// exact match of vec4 f(in vec4 x, out vec4 y)</span>
11373f(vec4, uvec4)  <span class="comment">// exact match of vec4 f(in vec4 x, out uvec4 y)</span>
11374f(vec4, ivec4)  <span class="comment">// matched to vec4 f(in vec4 x, out vec4 y)</span>
11375                <span class="comment">// (C) not relevant, can't convert vec4 to</span>
11376                <span class="comment">// ivec4. (A) better than (B) for 2nd</span>
11377                <span class="comment">// argument (rule 3), same on first argument.</span>
11378f(ivec4, vec4); <span class="comment">// NOT matched. All three match by implicit</span>
11379                <span class="comment">// conversion. (C) is better than (A) and (B)</span>
11380                <span class="comment">// on the first argument. (A) is better than</span>
11381                <span class="comment">// (B) and (C).</span></code></pre>
11382</div>
11383</div>
11384<div class="paragraph">
11385<p>User-defined functions can have multiple declarations, but only one
11386definition.</p>
11387</div>
11388<div class="paragraph">
11389<p>A shader can redefine built-in functions.
11390If a built-in function is redeclared in a shader (i.e., a prototype is
11391visible) before a call to it, then the linker will only attempt to resolve
11392that call within the set of shaders that are linked with it.</p>
11393</div>
11394<div class="paragraph">
11395<p>The function <em>main</em> is used as the entry point to a shader executable.
11396A shader need not contain a function named <em>main</em>, but one shader in a set
11397of shaders linked together to form a single shader executable must, or a
11398link-time error results.
11399This function takes no arguments, returns no value, and must be declared as
11400type <strong>void</strong>:</p>
11401</div>
11402<div class="listingblock">
11403<div class="content">
11404<pre class="CodeRay highlight"><code data-lang="c++"><span class="directive">void</span> main()
11405{
11406    ...
11407}</code></pre>
11408</div>
11409</div>
11410<div class="paragraph">
11411<p>The function <em>main</em> can contain uses of <strong>return</strong>.
11412See &#8220;<a href="#jumps">Jumps</a>&#8221; for more details.</p>
11413</div>
11414<div class="paragraph">
11415<p>It is a compile-time or link-time error to declare or define a function
11416<strong>main</strong> with any other parameters or return type.</p>
11417</div>
11418<div class="sect3">
11419<h4 id="function-calling-conventions">6.1.1. Function Calling Conventions</h4>
11420<div class="paragraph">
11421<p>Functions are called by value-return.
11422This means input arguments are copied into the function at call time, and
11423output arguments are copied back to the caller before function exit.
11424Because the function works with local copies of parameters, there are no
11425issues regarding aliasing of variables within a function.
11426To control what parameters are copied in and/or out through a function
11427definition or declaration:</p>
11428</div>
11429<div class="ulist">
11430<ul>
11431<li>
11432<p>The keyword <strong>in</strong> is used as a qualifier to denote a parameter is to be
11433copied in, but not copied out.</p>
11434</li>
11435<li>
11436<p>The keyword <strong>out</strong> is used as a qualifier to denote a parameter is to be
11437copied out, but not copied in.
11438This should be used whenever possible to avoid unnecessarily copying
11439parameters in.</p>
11440</li>
11441<li>
11442<p>The keyword <strong>inout</strong> is used as a qualifier to denote the parameter is to
11443be both copied in and copied out.
11444It means the same thing as specifying both <strong>in</strong> and <strong>out</strong>.</p>
11445</li>
11446<li>
11447<p>A function parameter declared with no such qualifier means the same
11448thing as specifying <strong>in</strong>.</p>
11449</li>
11450</ul>
11451</div>
11452<div class="paragraph">
11453<p>All arguments are evaluated at call time, exactly once, in order, from left
11454to right.
11455Evaluation of an <strong>in</strong> parameter results in a value that is copied to the
11456formal parameter.
11457Evaluation of an <strong>out</strong> parameter results in an l-value that is used to copy
11458out a value when the function returns.
11459Evaluation of an <strong>inout</strong> parameter results in both a value and an l-value;
11460the value is copied to the formal parameter at call time and the l-value is
11461used to copy out a value when the function returns.</p>
11462</div>
11463<div class="paragraph">
11464<p>The order in which output parameters are copied back to the caller is
11465undefined.</p>
11466</div>
11467<div class="paragraph">
11468<p>If the function matching described in the previous section required argument
11469type conversions, these conversions are applied at copy-in and copy-out
11470times.</p>
11471</div>
11472<div class="paragraph">
11473<p>In a function, writing to an input-only parameter is allowed.
11474Only the function&#8217;s copy is modified.
11475This can be prevented by declaring a parameter with the <strong>const</strong> qualifier.</p>
11476</div>
11477<div class="paragraph">
11478<p>When calling a function, expressions that do not evaluate to l-values cannot
11479be passed to parameters declared as <strong>out</strong> or <strong>inout</strong>, or a compile-time error
11480results.</p>
11481</div>
11482<div class="openblock bnf">
11483<div class="content">
11484<div class="dlist">
11485<dl>
11486<dt class="hdlist1"><em>function-prototype</em> : </dt>
11487<dd>
11488<p><em>precision-qualifier</em> <em>type</em> <em>function-name</em> <strong>(</strong> <em>parameter-qualifiers</em>
11489<em>precision-qualifier</em> <em>type</em> <em>name</em> <em>array-specifier</em> <strong>,</strong> &#8230;&#8203;
11490<strong>)</strong></p>
11491</dd>
11492<dt class="hdlist1"><em>type</em> : </dt>
11493<dd>
11494<p>any basic type, array type, structure name, or structure definition</p>
11495</dd>
11496<dt class="hdlist1"><em>parameter-qualifiers</em> : </dt>
11497<dd>
11498<p><em>empty</em><br>
11499list of <em>parameter-qualifier</em></p>
11500</dd>
11501<dt class="hdlist1"><em>parameter-qualifier</em> : </dt>
11502<dd>
11503<p><strong>const</strong><br>
11504<strong>in</strong><br>
11505<strong>out</strong><br>
11506<strong>inout</strong><br>
11507<strong>precise</strong><br>
11508<em>memory-qualifier</em><br>
11509<em>precision-qualifier</em></p>
11510</dd>
11511<dt class="hdlist1"><em>name</em> : </dt>
11512<dd>
11513<p>empty<br>
11514identifier</p>
11515</dd>
11516<dt class="hdlist1"><em>array-specifier</em> : </dt>
11517<dd>
11518<p>empty<br>
11519<strong>[</strong> <em>integral-constant-expression</em> <strong>]</strong></p>
11520</dd>
11521</dl>
11522</div>
11523</div>
11524</div>
11525<div class="paragraph">
11526<p>The <strong>const</strong> qualifier cannot be used with <strong>out</strong> or <strong>inout</strong>, or
11527a compile-time error results.
11528The above is used both for function declarations (i.e., prototypes) and for
11529function definitions.
11530Hence, function definitions can have unnamed arguments.</p>
11531</div>
11532<div class="paragraph">
11533<p>Recursion is not allowed, not even statically.
11534Static recursion is present if the static function-call graph of a program
11535contains cycles.
11536This includes all potential function calls through variables declared as
11537<strong>subroutine</strong> <strong>uniform</strong> (described below).
11538It is a compile-time or link-time error if a single compilation unit
11539(shader) contains either static recursion or the potential for recursion
11540through subroutine variables.</p>
11541</div>
11542</div>
11543<div class="sect3">
11544<h4 id="subroutines">6.1.2. Subroutines</h4>
11545<div class="paragraph">
11546<p>Subroutines provide a mechanism allowing shaders to be compiled in a manner
11547where the target of one or more function calls can be changed at run-time
11548without requiring any shader recompilation.
11549For example, a single shader may be compiled with support for multiple
11550illumination algorithms to handle different kinds of lights or surface
11551materials.
11552An application using such a shader may switch illumination algorithms by
11553changing the value of its subroutine uniforms.
11554To use subroutines, a subroutine type is declared, one or more functions are
11555associated with that subroutine type, and a subroutine variable of that type
11556is declared.
11557The function currently assigned to the variable function is then called by
11558using function calling syntax replacing a function name with the name of the
11559subroutine variable.
11560Subroutine variables are uniforms, and are assigned to specific functions
11561only through commands (<strong>UniformSubroutinesuiv</strong>) in the OpenGL API.</p>
11562</div>
11563<div class="paragraph">
11564<p>Subroutine functionality is not available when generating SPIR-V.</p>
11565</div>
11566<div class="paragraph">
11567<p>Subroutine types are declared using a statement similar to a function
11568declaration, with the <strong>subroutine</strong> keyword, as follows:</p>
11569</div>
11570<div class="listingblock">
11571<div class="content">
11572<pre class="CodeRay highlight"><code data-lang="c++">subroutine returnType subroutineTypeName(type0 arg0, type1 arg1,
11573                                         ..., typen argn);</code></pre>
11574</div>
11575</div>
11576<div class="paragraph">
11577<p>As with function declarations, the formal argument names (<em>args</em> above) are
11578optional.
11579Functions are associated with subroutine types of matching declarations by
11580defining the function with the <strong>subroutine</strong> keyword and a list of subroutine
11581types the function matches:</p>
11582</div>
11583<div class="listingblock">
11584<div class="content">
11585<pre class="CodeRay highlight"><code data-lang="c++">subroutine(subroutineTypeName0, ..., subroutineTypeNameN)
11586returnType functionName(type0 arg0, type1 arg1, ..., typen argn)
11587{ ... } <span class="comment">// function body</span></code></pre>
11588</div>
11589</div>
11590<div class="paragraph">
11591<p>It is a compile-time error if arguments and return type don&#8217;t match between
11592the function and each associated subroutine type.</p>
11593</div>
11594<div class="paragraph">
11595<p>Functions declared with <strong>subroutine</strong> must include a body.
11596An overloaded function cannot be declared with <strong>subroutine</strong>; a program will
11597fail to compile or link if any shader or stage contains two or more
11598functions with the same name if the name is associated with a subroutine
11599type.</p>
11600</div>
11601<div class="paragraph">
11602<p>A function declared with <strong>subroutine</strong> can also be called directly with a
11603static use of <em>functionName</em>, as is done with non-subroutine function
11604declarations and calls.</p>
11605</div>
11606<div class="paragraph">
11607<p>Subroutine type variables are required to be <em>subroutine uniforms</em>, and are
11608declared with a specific subroutine type in a subroutine uniform variable
11609declaration:</p>
11610</div>
11611<div class="listingblock">
11612<div class="content">
11613<pre class="CodeRay highlight"><code data-lang="c++">subroutine uniform subroutineTypeName subroutineVarName;</code></pre>
11614</div>
11615</div>
11616<div class="paragraph">
11617<p>Subroutine uniform variables are called the same way functions are called.
11618When a subroutine variable (or an element of a subroutine variable array) is
11619associated with a particular function, all function calls through that
11620variable will call that particular function.</p>
11621</div>
11622<div class="paragraph">
11623<p>Unlike other uniform variables, subroutine uniform variables are scoped to
11624the shader execution stage the variable is declared in.</p>
11625</div>
11626<div class="paragraph">
11627<p>Subroutine variables may be declared as explicitly-sized arrays, which can
11628be indexed only with dynamically uniform expressions.</p>
11629</div>
11630<div class="paragraph">
11631<p>It is a compile-time error to use the <strong>subroutine</strong> keyword in any places
11632other than (as shown above) to</p>
11633</div>
11634<div class="ulist">
11635<ul>
11636<li>
11637<p>declare a subroutine type at global scope,</p>
11638</li>
11639<li>
11640<p>declare a function as a subroutine, or</p>
11641</li>
11642<li>
11643<p>declare a subroutine variable at global scope.</p>
11644</li>
11645</ul>
11646</div>
11647</div>
11648</div>
11649<div class="sect2">
11650<h3 id="selection">6.2. Selection</h3>
11651<div class="paragraph">
11652<p>Conditional control flow in the shading language is done by either <strong>if</strong>,
11653<strong>if</strong>-<strong>else</strong>, or <strong>switch</strong> statements:</p>
11654</div>
11655<div class="openblock bnf">
11656<div class="content">
11657<div class="dlist">
11658<dl>
11659<dt class="hdlist1"><em>selection-statement</em> : </dt>
11660<dd>
11661<p><strong>if</strong> <strong>(</strong> <em>bool-expression</em> <strong>)</strong> <em>statement</em><br>
11662<strong>if</strong> <strong>(</strong> <em>bool-expression</em> <strong>)</strong> <em>statement</em> <strong>else</strong> <em>statement</em><br>
11663<strong>switch</strong> <strong>(</strong> <em>init-expression</em> <strong>)</strong> <strong>{</strong> <em>switch-statement-list<sub>opt</sub></em> <strong>}</strong></p>
11664</dd>
11665</dl>
11666</div>
11667</div>
11668</div>
11669<div class="paragraph">
11670<p>Where <em>switch-statement-list</em> is a nested scope containing a list of zero or
11671more <em>switch-statement</em> and other statements defined by the language, where
11672<em>switch-statement</em> adds some forms of labels.
11673That is</p>
11674</div>
11675<div class="openblock bnf">
11676<div class="content">
11677<div class="dlist">
11678<dl>
11679<dt class="hdlist1"><em>switch-statement-list</em> : </dt>
11680<dd>
11681<p><em>switch-statement</em><br>
11682<em>switch-statement-list</em> <em>switch-statement</em></p>
11683</dd>
11684<dt class="hdlist1"><em>switch-statement</em> : </dt>
11685<dd>
11686<p><strong>case</strong> <em>constant-expression</em> <strong>:</strong><br>
11687<strong>default</strong> <strong>:</strong> <em>statement</em></p>
11688</dd>
11689</dl>
11690</div>
11691</div>
11692</div>
11693<div class="paragraph">
11694<p>Note the above grammar&#8217;s purpose is to aid discussion in this section; the
11695normative grammar is in &#8220;<a href="#shading-language-grammar">Shading Language
11696Grammar</a>&#8221;.</p>
11697</div>
11698<div class="paragraph">
11699<p>If an <strong>if</strong>-expression evaluates to <strong>true</strong>, then the first <em>statement</em> is
11700executed.
11701If it evaluates to <strong>false</strong> and there is an <strong>else</strong> part then the second
11702<em>statement</em> is executed.</p>
11703</div>
11704<div class="paragraph">
11705<p>Any expression whose type evaluates to a Boolean can be used as the
11706conditional expression <em>bool-expression</em>.
11707Vector types are not accepted as the expression to <strong>if</strong>.</p>
11708</div>
11709<div class="paragraph">
11710<p>Conditionals can be nested.</p>
11711</div>
11712<div class="paragraph">
11713<p>The type of <em>init-expression</em> in a <strong>switch</strong> statement must be a scalar
11714integer.
11715The type of the <em>constant-expression</em> value in a case label also must be a
11716scalar integer.
11717When any pair of these values is tested for &#8220;equal value&#8221; and the types do
11718not match, an implicit conversion will be done to convert the <strong>int</strong> to a
11719<strong>uint</strong> (see &#8220;<a href="#implicit-conversions">Implicit Conversions</a>&#8221;) before the
11720compare is done.
11721If a <strong>case</strong> label has a <em>constant-expression</em> of equal value to
11722<em>init-expression</em>, execution will continue after that label.
11723Otherwise, if there is a <strong>default</strong> label, execution will continue after that
11724label.
11725Otherwise, execution skips the rest of the switch statement.
11726It is a compile-time error to have more than one <strong>default</strong> or a replicated
11727<em>constant-expression</em>.
11728A <strong>break</strong> statement not nested in a loop or other switch statement (either
11729not nested or nested only in <strong>if</strong> or <strong>if</strong>-<strong>else</strong> statements) will also skip
11730the rest of the switch statement.
11731Fall through labels are allowed, but it is a compile-time error to have no
11732statement between a label and the end of the switch statement.
11733No statements are allowed in a switch statement before the first <strong>case</strong>
11734statement.</p>
11735</div>
11736<div class="paragraph">
11737<p>The <strong>case</strong> and <strong>default</strong> labels can only appear within a <strong>switch</strong> statement.
11738No <strong>case</strong> or <strong>default</strong> labels can be nested inside other statements or
11739compound statements within their corresponding <strong>switch</strong>.</p>
11740</div>
11741</div>
11742<div class="sect2">
11743<h3 id="iteration">6.3. Iteration</h3>
11744<div class="paragraph">
11745<p>For, while, and do loops are allowed as follows:</p>
11746</div>
11747<div class="listingblock">
11748<div class="content">
11749<pre class="CodeRay highlight"><code data-lang="c++"><span class="keyword">for</span> (init-expression; condition-expression; loop-expression)
11750    sub-statement
11751<span class="keyword">while</span> (condition-expression)
11752    sub-statement
11753<span class="keyword">do</span>
11754    statement
11755<span class="keyword">while</span> (condition-expression)</code></pre>
11756</div>
11757</div>
11758<div class="paragraph">
11759<p>See &#8220;<a href="#shading-language-grammar">Shading Language Grammar</a>&#8221; for the
11760definitive specification of loops.</p>
11761</div>
11762<div class="paragraph">
11763<p>The <strong>for</strong> loop first evaluates the <em>init-expression</em>, then the
11764<em>condition-expression</em>.
11765If the <em>condition-expression</em> evaluates to <strong>true</strong>, then the body of the loop
11766is executed.
11767After the body is executed, a <strong>for</strong> loop will then evaluate the
11768<em>loop-expression</em>, and then loop back to evaluate the
11769<em>condition-expression</em>, repeating until the <em>condition-expression</em> evaluates
11770to <strong>false</strong>.
11771The loop is then exited, skipping its body and skipping its
11772<em>loop-expression</em>.
11773Variables modified by the <em>loop-expression</em> maintain their value after the
11774loop is exited, provided they are still in scope.
11775Variables declared in <em>init-expression</em> or <em>condition-expression</em> are only
11776in scope until the end of the sub-statement of the <strong>for</strong> loop.</p>
11777</div>
11778<div class="paragraph">
11779<p>The <strong>while</strong> loop first evaluates the <em>condition-expression</em>.
11780If <strong>true</strong>, then the body is executed.
11781This is then repeated, until the <em>condition-expression</em> evaluates to
11782<strong>false</strong>, exiting the loop and skipping its body.
11783Variables declared in the <em>condition-expression</em> are only in scope until the
11784end of the sub-statement of the <strong>while</strong> loop.</p>
11785</div>
11786<div class="paragraph">
11787<p>The <strong>do</strong>-<strong>while</strong> loop first executes the body, then executes the
11788<em>condition-expression</em>.
11789This is repeated until <em>condition-expression</em> evaluates to <strong>false</strong>, and then
11790the loop is exited.</p>
11791</div>
11792<div class="paragraph">
11793<p>Expressions for <em>condition-expression</em> must evaluate to a Boolean.</p>
11794</div>
11795<div class="paragraph">
11796<p>Both the <em>condition-expression</em> and the <em>init-expression</em> can declare and
11797initialize a variable, except in the <strong>do</strong>-<strong>while</strong> loop, which cannot declare
11798a variable in its <em>condition-expression</em>.
11799The variable&#8217;s scope lasts only until the end of the sub-statement that
11800forms the body of the loop.</p>
11801</div>
11802<div class="paragraph">
11803<p>Loops can be nested.</p>
11804</div>
11805<div class="paragraph">
11806<p>Non-terminating loops are allowed.
11807The consequences of very long or non-terminating loops are platform
11808dependent.</p>
11809</div>
11810</div>
11811<div class="sect2">
11812<h3 id="jumps">6.4. Jumps</h3>
11813<div class="paragraph">
11814<p>These are the jumps:</p>
11815</div>
11816<div class="openblock bnf">
11817<div class="content">
11818<div class="dlist">
11819<dl>
11820<dt class="hdlist1"><em>jump_statement</em> : </dt>
11821<dd>
11822<p><strong>continue</strong> <strong>;</strong><br>
11823<strong>break</strong> <strong>;</strong><br>
11824<strong>return</strong> <strong>;</strong><br>
11825<strong>return</strong> <em>expression</em> <strong>;</strong><br>
11826<strong>discard</strong> <strong>;</strong> // in the fragment shader language only</p>
11827</dd>
11828</dl>
11829</div>
11830</div>
11831</div>
11832<div class="paragraph">
11833<p>There is no &#8220;goto&#8221; or other non-structured flow of control.</p>
11834</div>
11835<div class="paragraph">
11836<p>The <strong>continue</strong> jump is used only in loops.
11837It skips the remainder of the body of the inner-most loop of which it is
11838inside.
11839For <strong>while</strong> and <strong>do</strong>-<strong>while</strong> loops, this jump is to the next evaluation of
11840the loop <em>condition-expression</em> from which the loop continues as previously
11841defined.
11842For <strong>for</strong> loops, the jump is to the <em>loop-expression</em>, followed by the
11843<em>condition-expression</em>.</p>
11844</div>
11845<div class="paragraph">
11846<p>The <strong>break</strong> jump can also be used only in loops and <strong>switch</strong> statements.
11847It is simply an immediate exit of the inner-most loop or <strong>switch</strong> statements
11848containing the <strong>break</strong>.
11849No further execution of <em>condition-expression</em>, <em>loop-expression</em>, or
11850<em>switch-statement</em> is done.</p>
11851</div>
11852<div class="paragraph">
11853<p>The <strong>discard</strong> keyword is only allowed within fragment shaders.
11854It can be used within a fragment shader to abandon the operation on the
11855current fragment.
11856This keyword causes the fragment to be discarded and no updates to any
11857buffers will occur.
11858Any prior writes to other buffers such as shader storage buffers are
11859unaffected.
11860Control flow exits the shader, and subsequent implicit or explicit
11861derivatives are undefined when this control flow is non-uniform (meaning
11862different fragments within the primitive take different control paths).
11863It would typically be used within a conditional statement, for example:</p>
11864</div>
11865<div class="listingblock">
11866<div class="content">
11867<pre class="CodeRay highlight"><code data-lang="c++"><span class="keyword">if</span> (intensity &lt; <span class="float">0</span><span class="float">.0</span>)
11868    discard;</code></pre>
11869</div>
11870</div>
11871<div class="paragraph">
11872<p>A fragment shader may test a fragment&#8217;s alpha value and discard the fragment
11873based on that test.
11874However, it should be noted that coverage testing occurs after the fragment
11875shader runs, and the coverage test can change the alpha value.</p>
11876</div>
11877<div class="paragraph">
11878<p>The <strong>return</strong> jump causes immediate exit of the current function.
11879If it has <em>expression</em> then that is the return value for the function.</p>
11880</div>
11881<div class="paragraph">
11882<p>The function <em>main</em> can use <strong>return</strong>.
11883This simply causes <em>main</em> to exit in the same way as when the end of the
11884function had been reached.
11885It does not imply a use of <strong>discard</strong> in a fragment shader.
11886Using <strong>return</strong> in <em>main</em> before defining outputs will have the same behavior
11887as reaching the end of <em>main</em> before defining outputs.</p>
11888</div>
11889</div>
11890</div>
11891</div>
11892<div class="sect1">
11893<h2 id="built-in-variables">7. Built-In Variables</h2>
11894<div class="sectionbody">
11895<div class="sect2">
11896<h3 id="built-in-language-variables">7.1. Built-In Language Variables</h3>
11897<div class="paragraph">
11898<p>Some operations occur outside shader functionality and need to provide
11899values to or receive values from shader executables.
11900Shaders communicate with fixed-function pipeline stages, and
11901optionally with other shader executables, through the use of built-in input
11902and output variables.</p>
11903</div>
11904<div class="sect3">
11905<h4 id="vertex-shader-special-variables">7.1.1. Vertex Shader Special Variables</h4>
11906<div class="paragraph">
11907<p>The built-in vertex shader variables are intrinsically declared as follows:</p>
11908</div>
11909<div class="listingblock">
11910<div class="content">
11911<pre class="CodeRay highlight"><code data-lang="c++">in <span class="predefined-type">int</span> gl_VertexID;       <span class="comment">// only present when not targeting Vulkan</span>
11912in <span class="predefined-type">int</span> gl_InstanceID;     <span class="comment">// only present when not targeting Vulkan</span>
11913in <span class="predefined-type">int</span> gl_VertexIndex;    <span class="comment">// only present when targeting Vulkan</span>
11914in <span class="predefined-type">int</span> gl_InstanceIndex;  <span class="comment">// only present when targeting Vulkan</span>
11915in <span class="predefined-type">int</span> gl_DrawID;
11916in <span class="predefined-type">int</span> gl_BaseVertex;
11917in <span class="predefined-type">int</span> gl_BaseInstance;
11918
11919out gl_PerVertex {
11920    vec4 gl_Position;
11921    <span class="predefined-type">float</span> gl_PointSize;
11922    <span class="predefined-type">float</span> gl_ClipDistance[];
11923    <span class="predefined-type">float</span> gl_CullDistance[];
11924};</code></pre>
11925</div>
11926</div>
11927<div class="paragraph">
11928<p>The variable <em>gl_Position</em> is intended for writing the homogeneous vertex
11929position.
11930It can be written at any time during shader execution.
11931This value will be used by primitive assembly, clipping, culling, and other
11932fixed functionality operations, if present, that operate on primitives after
11933vertex processing has occurred.
11934Its value is undefined after the vertex processing stage if the vertex
11935shader executable does not write <em>gl_Position</em>.</p>
11936</div>
11937<div class="paragraph">
11938<p>The variable <em>gl_PointSize</em> is intended for a shader to write the size of
11939the point to be rasterized.
11940It is measured in pixels.
11941If <em>gl_PointSize</em> is not written to, its value is undefined in subsequent
11942pipe stages.</p>
11943</div>
11944<div class="paragraph">
11945<p>The variable <em>gl_ClipDistance</em> is intended for writing clip distances, and
11946provides the forward compatible mechanism for controlling user clipping.
11947The element <em>gl_ClipDistance[i]</em> specifies a clip distance for each plane
11948<em>i</em>.
11949A distance of 0 means the vertex is on the plane, a positive distance means
11950the vertex is inside the clip plane, and a negative distance means the point
11951is outside the clip plane.
11952The clip distances will be linearly interpolated across the primitive and
11953the portion of the primitive with interpolated distances less than 0 will be
11954clipped.</p>
11955</div>
11956<div class="paragraph">
11957<p>The <em>gl_ClipDistance</em> array is predeclared as unsized and must be explicitly
11958sized by the shader either redeclaring it with a size or implicitly sized by
11959indexing it only with constant integral expressions.
11960This needs to size the array to include all the clip planes that are enabled
11961via the API; if the size does not include all enabled planes,
11962results are undefined.
11963The size can be at most <em>gl_MaxClipDistances</em>.
11964The number of varying components (see <em>gl_MaxVaryingComponents)</em> consumed by
11965<em>gl_ClipDistance</em> will match the size of the array, no matter how many
11966planes are enabled.
11967The shader must also set all values in <em>gl_ClipDistance</em> that have been
11968enabled via the API, or results are undefined.
11969Values written into <em>gl_ClipDistance</em> for planes that are not enabled have
11970no effect.</p>
11971</div>
11972<div class="paragraph">
11973<p>The variable <em>gl_CullDistance</em> provides a mechanism for controlling user
11974culling.
11975The element <em>gl_CullDistance[i]</em> specifies a cull distance for plane <em>i</em>.
11976A distance of 0 means the vertex is on the plane, a positive distance means
11977the vertex is inside the cull volume, and a negative distance means the
11978point is outside the cull volume.
11979Primitives whose vertices all have a negative cull distance for plane <em>i</em>
11980will be discarded.</p>
11981</div>
11982<div class="paragraph">
11983<p>The <em>gl_CullDistance</em> array is predeclared as unsized and must be sized by
11984the shader either redeclaring it with a size or indexing it only with
11985constant integral expressions.
11986The size determines the number and set of enabled cull distances and can be
11987at most <em>gl_MaxCullDistances</em>.
11988The number of varying components (see <em>gl_MaxVaryingComponents</em>) consumed by
11989<em>gl_CullDistance</em> will match the size of the array.
11990Shaders writing <em>gl_CullDistance</em> must write all enabled distances, or
11991culling results are undefined.</p>
11992</div>
11993<div class="paragraph">
11994<p>As an output variable, <em>gl_CullDistance</em> provides the place for the shader
11995to write these distances.
11996As an input in all but the fragment language, it reads the values written in
11997the previous shader stage.
11998In the fragment language, <em>gl_CullDistance</em> array contains linearly
11999interpolated values for the vertex values written by a shader to the
12000<em>gl_CullDistance</em> vertex output variable.</p>
12001</div>
12002<div class="paragraph">
12003<p>It is a compile-time or link-time error for the set of shaders forming a
12004program to have the sum of the sizes of the <em>gl_ClipDistance</em> and
12005<em>gl_CullDistance</em> arrays to be larger than
12006<em>gl_MaxCombinedClipAndCullDistances</em>.</p>
12007</div>
12008<div class="paragraph">
12009<p>The variable <em>gl_VertexID</em> is a vertex shader input variable that holds an
12010integer index for the vertex, as defined under &#8220;Shader Inputs&#8221; in section
1201111.1.3.9 &#8220;Shader Inputs&#8221; of the <a href="#references">OpenGL Specification</a>.
12012It is only present when not targeting Vulkan.
12013Even when present, the value of <em>gl_VertexID</em> is not always defined.</p>
12014</div>
12015<div class="paragraph">
12016<p>The variable <em>gl_InstanceID</em> is a vertex shader input variable that holds
12017the instance number of the current primitive in an instanced draw call (see
12018&#8220;Shader Inputs&#8221; in section 11.1.3.9 &#8220;Shader Inputs&#8221; of the
12019<a href="#references">OpenGL Specification</a>).
12020It is only present when not targeting Vulkan.
12021If the current primitive does not come from an instanced draw call, the
12022value of <em>gl_InstanceID</em> is zero.</p>
12023</div>
12024<div class="paragraph">
12025<p>The variable <em>gl_VertexIndex</em> is a vertex language input variable that
12026holds an integer index for the vertex, relative to a base.
12027It is only present when targeting Vulkan.
12028Even when present, the value of <em>gl_VertexIndex</em> is not always defined.</p>
12029</div>
12030<div class="paragraph">
12031<p>The variable <em>gl_InstanceIndex</em> is a vertex language input variable that
12032holds the instance number of the current primitive in an instanced draw
12033call, relative to a base.
12034It is only present when targeting Vulkan.
12035If the current primitive does not come from an instanced draw call,
12036the value of gl_InstanceIndex is zero.</p>
12037</div>
12038<div class="paragraph">
12039<p>The variable <em>gl_DrawID</em> is a vertex shader input variable that holds the
12040integer index of the drawing command to which the current vertex belongs
12041(see &#8220;Shader Inputs&#8221; in section 11.1.3.9 of the <a href="#references">OpenGL Specification</a>).
12042If the vertex is not invoked by a <strong>Multi</strong>* form of a draw command, then the
12043value of <em>gl_DrawID</em> is zero.</p>
12044</div>
12045<div class="paragraph">
12046<p>The variable <em>gl_BaseVertex</em> is a vertex shader input variable that holds
12047the integer value passed to the baseVertex parameter of the command that
12048resulted in the current shader invocation (see &#8220;Shader Inputs&#8221; in section
1204911.1.3.9 of the <a href="#references">OpenGL Specification</a>).</p>
12050</div>
12051<div class="paragraph">
12052<p>The variable <em>gl_BaseInstance</em> is a vertex shader input variable that holds
12053the integer value passed to the baseInstance parameter of the command that
12054resulted in the current shader invocation (see &#8220;Shader Inputs&#8221; in section
1205511.1.3.9 of the <a href="#references">OpenGL Specification</a>).</p>
12056</div>
12057</div>
12058<div class="sect3">
12059<h4 id="tessellation-control-shader-special-variables">7.1.2. Tessellation Control Shader Special Variables</h4>
12060<div class="paragraph">
12061<p>In the tessellation control shader, built-in variables are intrinsically
12062declared as:</p>
12063</div>
12064<div class="listingblock">
12065<div class="content">
12066<pre class="CodeRay highlight"><code data-lang="c++">in gl_PerVertex {
12067    vec4 gl_Position;
12068    <span class="predefined-type">float</span> gl_PointSize;
12069    <span class="predefined-type">float</span> gl_ClipDistance[];
12070    <span class="predefined-type">float</span> gl_CullDistance[];
12071} gl_in[gl_MaxPatchVertices];
12072
12073in <span class="predefined-type">int</span> gl_PatchVerticesIn;
12074in <span class="predefined-type">int</span> gl_PrimitiveID;
12075in <span class="predefined-type">int</span> gl_InvocationID;
12076
12077out gl_PerVertex {
12078    vec4 gl_Position;
12079    <span class="predefined-type">float</span> gl_PointSize;
12080    <span class="predefined-type">float</span> gl_ClipDistance[];
12081    <span class="predefined-type">float</span> gl_CullDistance[];
12082} gl_out[];
12083
12084patch out <span class="predefined-type">float</span> gl_TessLevelOuter[<span class="integer">4</span>];
12085patch out <span class="predefined-type">float</span> gl_TessLevelInner[<span class="integer">2</span>];</code></pre>
12086</div>
12087</div>
12088<div class="sect4">
12089<h5 id="tessellation-control-input-variables">Tessellation Control Input Variables</h5>
12090<div class="paragraph">
12091<p><em>gl_Position</em>, <em>gl_PointSize</em>, <em>gl_ClipDistance</em>, and <em>gl_CullDistance</em>
12092contain the values written in the previous shader stage to the corresponding
12093outputs.</p>
12094</div>
12095<div class="paragraph">
12096<p><em>gl_PatchVerticesIn</em> contains the number of vertices in the input patch
12097being processed by the shader.
12098A single shader can read patches of differing sizes, so the value of
12099<em>gl_PatchVerticesIn</em> may differ between patches.</p>
12100</div>
12101<div class="paragraph">
12102<p><em>gl_PrimitiveID</em> contains the number of primitives processed by the shader
12103since the current set of rendering primitives was started.</p>
12104</div>
12105<div class="paragraph">
12106<p><em>gl_InvocationID</em> contains the number of the output patch vertex assigned to
12107the tessellation control shader invocation.
12108It is assigned integer values in the range [0, N-1], where N is the number
12109of output patch vertices per primitive.</p>
12110</div>
12111</div>
12112<div class="sect4">
12113<h5 id="tessellation-control-output-variables">Tessellation Control Output Variables</h5>
12114<div class="paragraph">
12115<p><em>gl_Position</em>, <em>gl_PointSize</em>, <em>gl_ClipDistance</em>, and <em>gl_CullDistance</em> are
12116used in the same fashion as the corresponding output variables in the vertex
12117shader.</p>
12118</div>
12119<div class="paragraph">
12120<p>The values written to <em>gl_TessLevelOuter</em> and <em>gl_TessLevelInner</em> are
12121assigned to the corresponding outer and inner tessellation levels of the
12122output patch.
12123They are used by the tessellation primitive generator to control primitive
12124tessellation and may be read by tessellation evaluation shaders.</p>
12125</div>
12126</div>
12127</div>
12128<div class="sect3">
12129<h4 id="tessellation-evaluation-shader-special-variables">7.1.3. Tessellation Evaluation Shader Special Variables</h4>
12130<div class="paragraph">
12131<p>In the tessellation evaluation shader, built-in variables are intrinsically
12132declared as:</p>
12133</div>
12134<div class="listingblock">
12135<div class="content">
12136<pre class="CodeRay highlight"><code data-lang="c++">in gl_PerVertex {
12137    vec4 gl_Position;
12138    <span class="predefined-type">float</span> gl_PointSize;
12139    <span class="predefined-type">float</span> gl_ClipDistance[];
12140    <span class="predefined-type">float</span> gl_CullDistance[];
12141} gl_in[gl_MaxPatchVertices];
12142
12143in <span class="predefined-type">int</span> gl_PatchVerticesIn;
12144in <span class="predefined-type">int</span> gl_PrimitiveID;
12145in vec3 gl_TessCoord;
12146patch in <span class="predefined-type">float</span> gl_TessLevelOuter[<span class="integer">4</span>];
12147patch in <span class="predefined-type">float</span> gl_TessLevelInner[<span class="integer">2</span>];
12148
12149out gl_PerVertex {
12150    vec4 gl_Position;
12151    <span class="predefined-type">float</span> gl_PointSize;
12152    <span class="predefined-type">float</span> gl_ClipDistance[];
12153    <span class="predefined-type">float</span> gl_CullDistance[];
12154};</code></pre>
12155</div>
12156</div>
12157<div class="sect4">
12158<h5 id="tessellation-evaluation-input-variables">Tessellation Evaluation Input Variables</h5>
12159<div class="paragraph">
12160<p><em>gl_Position</em>, <em>gl_PointSize</em>, <em>gl_ClipDistance</em>, and <em>gl_CullDistance</em>
12161contain the values written in the previous shader stage to the corresponding
12162outputs.</p>
12163</div>
12164<div class="paragraph">
12165<p><em>gl_PatchVerticesIn</em> and <em>gl_PrimitiveID</em> are defined in the same fashion as
12166the corresponding input variables in the tessellation control shader.</p>
12167</div>
12168<div class="paragraph">
12169<p><em>gl_TessCoord</em> specifies a three-component <em>(u,v,w)</em> vector identifying the
12170position of the vertex being processed by the shader relative to the
12171primitive being tessellated.
12172Its values will obey the properties</p>
12173</div>
12174<div class="listingblock">
12175<div class="content">
12176<pre class="CodeRay highlight"><code data-lang="c++">gl_TessCoord.x == <span class="float">1</span><span class="float">.0</span> - (<span class="float">1</span><span class="float">.0</span> - gl_TessCoord.x) <span class="comment">// two operations performed</span>
12177gl_TessCoord.y == <span class="float">1</span><span class="float">.0</span> - (<span class="float">1</span><span class="float">.0</span> - gl_TessCoord.y) <span class="comment">// two operations performed</span>
12178gl_TessCoord.z == <span class="float">1</span><span class="float">.0</span> - (<span class="float">1</span><span class="float">.0</span> - gl_TessCoord.z) <span class="comment">// two operations performed</span></code></pre>
12179</div>
12180</div>
12181<div class="paragraph">
12182<p>to aid in replicating subdivision computations.</p>
12183</div>
12184<div class="paragraph">
12185<p>If a tessellation control shader is active, the input variables
12186<em>gl_TessLevelOuter</em> and <em>gl_TessLevelInner</em> are filled with the
12187corresponding outputs written by the tessellation control shader.
12188Otherwise, they are assigned with default tessellation levels specified in
12189section 11.2.3.3 &#8220;Tessellation Evaluation Shader Inputs&#8221; of the
12190<a href="#references">OpenGL Specification</a>.</p>
12191</div>
12192</div>
12193<div class="sect4">
12194<h5 id="tessellation-evaluation-output-variables">Tessellation Evaluation Output Variables</h5>
12195<div class="paragraph">
12196<p><em>gl_Position</em>, <em>gl_PointSize</em>, <em>gl_ClipDistance</em>, and <em>gl_CullDistance</em> are
12197used in the same fashion as the corresponding output variables in the vertex
12198shader.</p>
12199</div>
12200</div>
12201</div>
12202<div class="sect3">
12203<h4 id="geometry-shader-special-variables">7.1.4. Geometry Shader Special Variables</h4>
12204<div class="paragraph">
12205<p>In the geometry shader, built-in variables are intrinsically declared as:</p>
12206</div>
12207<div class="listingblock">
12208<div class="content">
12209<pre class="CodeRay highlight"><code data-lang="c++">in gl_PerVertex {
12210    vec4 gl_Position;
12211    <span class="predefined-type">float</span> gl_PointSize;
12212    <span class="predefined-type">float</span> gl_ClipDistance[];
12213    <span class="predefined-type">float</span> gl_CullDistance[];
12214} gl_in[];
12215
12216in <span class="predefined-type">int</span> gl_PrimitiveIDIn;
12217in <span class="predefined-type">int</span> gl_InvocationID;
12218
12219out gl_PerVertex {
12220    vec4 gl_Position;
12221    <span class="predefined-type">float</span> gl_PointSize;
12222    <span class="predefined-type">float</span> gl_ClipDistance[];
12223    <span class="predefined-type">float</span> gl_CullDistance[];
12224};
12225
12226out <span class="predefined-type">int</span> gl_PrimitiveID;
12227out <span class="predefined-type">int</span> gl_Layer;
12228out <span class="predefined-type">int</span> gl_ViewportIndex;</code></pre>
12229</div>
12230</div>
12231<div class="sect4">
12232<h5 id="geometry-shader-input-variables">Geometry Shader Input Variables</h5>
12233<div class="paragraph">
12234<p><em>gl_Position</em>, <em>gl_PointSize</em>, <em>gl_ClipDistance</em>, and <em>gl_CullDistance</em>
12235contain the values written in the previous shader stage to the corresponding
12236outputs.</p>
12237</div>
12238<div class="paragraph">
12239<p><em>gl_PrimitiveIDIn</em> contains the number of primitives processed by the shader
12240since the current set of rendering primitives was started.</p>
12241</div>
12242<div class="paragraph">
12243<p><em>gl_InvocationID</em> contains the invocation number assigned to the geometry
12244shader invocation.
12245It is assigned integer values in the range [0, N-1], where N is the number
12246of geometry shader invocations per primitive.</p>
12247</div>
12248</div>
12249<div class="sect4">
12250<h5 id="geometry-shader-output-variables">Geometry Shader Output Variables</h5>
12251<div class="paragraph">
12252<p><em>gl_Position</em>, <em>gl_PointSize</em>, <em>gl_ClipDistance</em>, and <em>gl_CullDistance</em> are
12253used in the same fashion as the corresponding output variables in the vertex
12254shader.</p>
12255</div>
12256<div class="paragraph">
12257<p><em>gl_PrimitiveID</em> is filled with a single integer that serves as a primitive
12258identifier to the fragment shader.
12259This is then available to fragment shaders, which will select the written
12260primitive ID from the provoking vertex of the primitive being shaded.
12261If a fragment shader using <em>gl_PrimitiveID</em> is active and a geometry shader
12262is also active, the geometry shader must write to <em>gl_PrimitiveID</em> or the
12263fragment shader input <em>gl_PrimitiveID</em> is undefined.
12264See section 11.3.4.5 &#8220;Geometry Shader Outputs&#8221; of the
12265<a href="#references">OpenGL Specification</a> for more information.</p>
12266</div>
12267<div class="paragraph">
12268<p><em>gl_Layer</em> is used to select a specific layer (or face and layer of a cube
12269map) of a multi-layer framebuffer attachment.
12270The actual layer used will come from one of the vertices in the primitive
12271being shaded.
12272Which vertex the layer comes from is determined as discussed in section
1227311.3.4.6 &#8220;Layer and Viewport Selection&#8221; of the <a href="#references">OpenGL Specification</a>
12274but may be undefined, so it is best to write the same layer value for all
12275vertices of a primitive.
12276If a shader statically assigns a value to <em>gl_Layer</em>, layered rendering mode
12277is enabled.
12278See section 11.3.4.5 &#8220;Geometry Shader Outputs&#8221; and section 9.4.9 &#8220;Layered
12279Framebuffers&#8221; of the <a href="#references">OpenGL Specification</a> for more information.
12280If a shader statically assigns a value to <em>gl_Layer</em>, and there is an
12281execution path through the shader that does not set <em>gl_Layer</em>, then the
12282value of <em>gl_Layer</em> is undefined for executions of the shader that take that
12283path.</p>
12284</div>
12285<div class="paragraph">
12286<p>The output variable <em>gl_Layer</em> takes on a special value when used with an
12287array of cube map textures.
12288Instead of only referring to the layer, it is used to select a cube map face
12289and a layer.
12290Setting <em>gl_Layer</em> to the value <em>layer*6+face</em> will render to face <em>face</em> of
12291the cube defined in layer <em>layer</em>.
12292The face values are defined in table 9.3 of section 9.4.9 &#8220;Layered
12293Framebuffers&#8221; of the <a href="#references">OpenGL Specification</a>,
12294but repeated below for clarity.</p>
12295</div>
12296<table class="tableblock frame-all grid-all stretch">
12297<colgroup>
12298<col style="width: 50%;">
12299<col style="width: 50%;">
12300</colgroup>
12301<thead>
12302<tr>
12303<th class="tableblock halign-left valign-top">Face Value</th>
12304<th class="tableblock halign-left valign-top">Resulting Target</th>
12305</tr>
12306</thead>
12307<tbody>
12308<tr>
12309<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
12310<td class="tableblock halign-left valign-top"><p class="tableblock">TEXTURE_CUBE_MAP_POSITIVE_X</p></td>
12311</tr>
12312<tr>
12313<td class="tableblock halign-left valign-top"><p class="tableblock">1</p></td>
12314<td class="tableblock halign-left valign-top"><p class="tableblock">TEXTURE_CUBE_MAP_NEGATIVE_X</p></td>
12315</tr>
12316<tr>
12317<td class="tableblock halign-left valign-top"><p class="tableblock">2</p></td>
12318<td class="tableblock halign-left valign-top"><p class="tableblock">TEXTURE_CUBE_MAP_POSITIVE_Y</p></td>
12319</tr>
12320<tr>
12321<td class="tableblock halign-left valign-top"><p class="tableblock">3</p></td>
12322<td class="tableblock halign-left valign-top"><p class="tableblock">TEXTURE_CUBE_MAP_NEGATIVE_Y</p></td>
12323</tr>
12324<tr>
12325<td class="tableblock halign-left valign-top"><p class="tableblock">4</p></td>
12326<td class="tableblock halign-left valign-top"><p class="tableblock">TEXTURE_CUBE_MAP_POSITIVE_Z</p></td>
12327</tr>
12328<tr>
12329<td class="tableblock halign-left valign-top"><p class="tableblock">5</p></td>
12330<td class="tableblock halign-left valign-top"><p class="tableblock">TEXTURE_CUBE_MAP_NEGATIVE_Z</p></td>
12331</tr>
12332</tbody>
12333</table>
12334<div class="paragraph">
12335<p>For example, to render to the positive <em>y</em> cube map face located in the 5th
12336layer of the cube map array, <em>gl_Layer</em> should be set to <em>5 * 6 + 2</em>.</p>
12337</div>
12338<div class="paragraph">
12339<p>The output variable <em>gl_ViewportIndex</em> provides the index of the viewport to
12340which the next primitive emitted from the geometry shader should be drawn.
12341Primitives generated by the geometry shader will undergo viewport
12342transformation and scissor testing using the viewport transformation and
12343scissor rectangle selected by the value of <em>gl_ViewportIndex</em>.
12344The viewport index used will come from one of the vertices in the primitive
12345being shaded.
12346However, which vertex the viewport index comes from is
12347implementation-dependent, so it is best to use the same viewport index for
12348all vertices of the primitive.
12349If a geometry shader does not assign a value to <em>gl_ViewportIndex</em>, viewport
12350transform and scissor rectangle zero will be used.
12351If a geometry shader statically assigns a value to <em>gl_ViewportIndex</em> and
12352there is a path through the shader that does not assign a value to
12353<em>gl_ViewportIndex</em>, the value of <em>gl_ViewportIndex</em> is undefined for
12354executions of the shader that take that path.
12355See section 11.3.4.6 &#8220;Layer and Viewport Selection&#8221; of the
12356<a href="#references">OpenGL Specification</a> for more information.</p>
12357</div>
12358</div>
12359</div>
12360<div class="sect3">
12361<h4 id="fragment-shader-special-variables">7.1.5. Fragment Shader Special Variables</h4>
12362<div class="paragraph">
12363<p>The built-in special variables that are accessible from a fragment shader
12364are intrinsically declared as follows:</p>
12365</div>
12366<div class="listingblock">
12367<div class="content">
12368<pre class="CodeRay highlight"><code data-lang="c++">in vec4 gl_FragCoord;
12369in <span class="predefined-type">bool</span> gl_FrontFacing;
12370in <span class="predefined-type">float</span> gl_ClipDistance[];
12371in <span class="predefined-type">float</span> gl_CullDistance[];
12372in vec2 gl_PointCoord;
12373in <span class="predefined-type">int</span> gl_PrimitiveID;
12374in <span class="predefined-type">int</span> gl_SampleID;
12375in vec2 gl_SamplePosition;
12376in <span class="predefined-type">int</span> gl_SampleMaskIn[];
12377in <span class="predefined-type">int</span> gl_Layer;
12378in <span class="predefined-type">int</span> gl_ViewportIndex;
12379in <span class="predefined-type">bool</span> gl_HelperInvocation;
12380
12381out <span class="predefined-type">float</span> gl_FragDepth;
12382out <span class="predefined-type">int</span> gl_SampleMask[];</code></pre>
12383</div>
12384</div>
12385<div class="paragraph">
12386<p>The output of the fragment shader executable is processed by the fixed
12387function operations at the back end of the API pipeline.</p>
12388</div>
12389<div class="paragraph">
12390<p>The fixed functionality computed depth for a fragment may be obtained by
12391reading <em>gl_FragCoord.z</em>, described below.</p>
12392</div>
12393<div class="paragraph">
12394<p>Writing to <em>gl_FragDepth</em> will establish the depth value for the fragment
12395being processed.
12396If depth buffering is enabled, and no shader writes <em>gl_FragDepth</em>, then the
12397fixed function value for depth will be used as the fragment&#8217;s depth value.
12398If a shader statically assigns a value to <em>gl_FragDepth</em>, and there is an
12399execution path through the shader that does not set <em>gl_FragDepth</em>, then the
12400value of the fragment&#8217;s depth may be undefined for executions of the shader
12401that take that path.
12402That is, if the set of linked fragment shaders statically contain a write to
12403<em>gl_FragDepth</em>, then it is responsible for always writing it.</p>
12404</div>
12405<div class="paragraph">
12406<p>If a shader executes the <strong>discard</strong> keyword, the fragment is discarded, and
12407the values of any user-defined fragment outputs, <em>gl_FragDepth</em>, and
12408<em>gl_SampleMask</em> become irrelevant.</p>
12409</div>
12410<div class="paragraph">
12411<p>The variable <em>gl_FragCoord</em> is available as an input variable from within
12412fragment shaders and it holds the window relative coordinates (<em>x</em>, <em>y</em>,
12413<em>z</em>, <em>1/w</em>) values for the fragment.
12414If multi-sampling, this value can be for any location within the pixel, or
12415one of the fragment samples.
12416The use of <strong>centroid</strong> does not further restrict this value to be inside the
12417current primitive.
12418This value is the result of the fixed functionality that interpolates
12419primitives after vertex processing to generate fragments.
12420The <em>z</em> component is the depth value that would be used for the fragment&#8217;s
12421depth if no shader contained any writes to <em>gl_FragDepth</em>.
12422This is useful for invariance if a shader conditionally computes
12423<em>gl_FragDepth</em> but otherwise wants the fixed functionality fragment depth.</p>
12424</div>
12425<div class="paragraph">
12426<p>Fragment shaders have access to the input built-in variable
12427<em>gl_FrontFacing</em>, whose value is <strong>true</strong> if the fragment belongs to a
12428front-facing primitive.
12429One use of this is to emulate two-sided lighting by selecting one of two
12430colors calculated by a vertex or geometry shader.</p>
12431</div>
12432<div class="paragraph">
12433<p>The values in <em>gl_PointCoord</em> are two-dimensional coordinates indicating
12434where within a point primitive the current fragment is located, when point
12435sprites are enabled.
12436They range from 0.0 to 1.0 across the point.
12437If the current primitive is not a point, or if point sprites are not
12438enabled, then the values read from <em>gl_PointCoord</em> are undefined.</p>
12439</div>
12440<div class="paragraph">
12441<p>For both the input array <em>gl_SampleMaskIn[]</em> and the output array
12442<em>gl_SampleMask[]</em>, bit <em>B</em> of mask <em>M</em> (<em>gl_SampleMaskIn[M]</em> or
12443<em>gl_SampleMask[M]</em>) corresponds to sample <em>32*M+B</em>.
12444These arrays have <strong>ceil</strong>(<em>s</em>/32) elements, where <em>s</em> is the maximum number
12445of color samples supported by the implementation.</p>
12446</div>
12447<div class="paragraph">
12448<p>The input variable <em>gl_SampleMaskIn</em> indicates the set of samples covered by
12449the primitive generating the fragment during multisample rasterization.
12450It has a sample bit set if and only if the sample is considered covered for
12451this fragment shader invocation.</p>
12452</div>
12453<div class="paragraph">
12454<p>The output array <em>gl_SampleMask[]</em> sets the sample mask for the fragment
12455being processed.
12456Coverage for the current fragment will become the logical AND of the
12457coverage mask and the output <em>gl_SampleMask</em>.
12458This array must be sized in the fragment shader either implicitly or
12459explicitly, to be no larger than the implementation-dependent maximum
12460sample-mask (as an array of 32bit elements), determined by the maximum
12461number of samples..
12462If the fragment shader statically assigns a value to <em>gl_SampleMask</em>, the
12463sample mask will be undefined for any array elements of any fragment shader
12464invocations that fail to assign a value.
12465If a shader does not statically assign a value to <em>gl_SampleMask</em>, the
12466sample mask has no effect on the processing of a fragment.</p>
12467</div>
12468<div class="paragraph">
12469<p>The input variable <em>gl_SampleID</em> is filled with the sample number of the
12470sample currently being processed.
12471This variable is in the range <em>0</em> to <em>gl_NumSamples-1</em>, where
12472<em>gl_NumSamples</em> is the total number of samples in the framebuffer, or 1 if
12473rendering to a non-multisample framebuffer.
12474Any static use of this variable in a fragment shader causes the entire
12475shader to be evaluated per-sample.</p>
12476</div>
12477<div class="paragraph">
12478<p>The input variable <em>gl_SamplePosition</em> contains the position of the current
12479sample within the multisample draw buffer.
12480The <em>x</em> and <em>y</em> components of <em>gl_SamplePosition</em> contain the sub-pixel
12481coordinate of the current sample and will have values in the range 0.0 to
124821.0.
12483Any static use of this variable in a fragment shader causes the entire
12484shader to be evaluated per sample.</p>
12485</div>
12486<div class="paragraph">
12487<p>The value <em>gl_HelperInvocation</em> is <strong>true</strong> if the fragment shader invocation
12488is considered a <em>helper invocation</em> and is <strong>false</strong> otherwise.
12489A helper invocation is a fragment shader invocation that is created solely
12490for the purposes of evaluating derivatives for use in non-helper fragment
12491shader invocations.
12492Such derivatives are computed implicitly in the built-in function
12493<strong>texture</strong>() (see &#8220;<a href="#texture-functions">Texture Functions</a>&#8221;), and
12494explicitly in the derivative functions in
12495&#8220;<a href="#derivative-functions">Derivative Functions</a>&#8221;, for example <strong>dFdx</strong>() and
12496<strong>dFdy</strong>().</p>
12497</div>
12498<div class="paragraph">
12499<p>Fragment shader helper invocations execute the same shader code as
12500non-helper invocations, but will not have side effects that modify the
12501framebuffer or other shader-accessible memory.
12502In particular:</p>
12503</div>
12504<div class="ulist">
12505<ul>
12506<li>
12507<p>Fragments corresponding to helper invocations are discarded when shader
12508execution is complete, without updating the framebuffer.</p>
12509</li>
12510<li>
12511<p>Stores to image and buffer variables performed by helper invocations
12512have no effect on the underlying image or buffer memory.</p>
12513</li>
12514<li>
12515<p>Atomic operations to image, buffer, or atomic counter variables
12516performed by helper invocations have no effect on the underlying image
12517or buffer memory.
12518The values returned by such atomic operations are undefined.</p>
12519</li>
12520</ul>
12521</div>
12522<div class="paragraph">
12523<p>Helper invocations may be generated for pixels not covered by a primitive
12524being rendered.
12525While fragment shader inputs qualified with <strong>centroid</strong> are normally required
12526to be sampled in the intersection of the pixel and the primitive, the
12527requirement is ignored for such pixels since there is no intersection
12528between the pixel and primitive.</p>
12529</div>
12530<div class="paragraph">
12531<p>Helper invocations may also be generated for fragments that are covered by a
12532primitive being rendered when the fragment is killed by early fragment tests
12533(using the <strong>early_fragment_tests</strong> qualifier) or where the implementation is
12534able to determine that executing the fragment shader would have no effect
12535other than assisting in computing derivatives for other fragment shader
12536invocations.</p>
12537</div>
12538<div class="paragraph">
12539<p>The set of helper invocations generated when processing any set of
12540primitives is implementation-dependent.</p>
12541</div>
12542<div class="paragraph">
12543<p><em>gl_ClipDistance</em> contains linearly interpolated values for the vertex-
12544pipeline values written by a shader to the <em>gl_ClipDistance</em> output
12545variable. Only elements in this array that have clipping enabled will
12546have defined values.</p>
12547</div>
12548<div class="paragraph">
12549<p>The input variable <em>gl_PrimitiveID</em> is filled with the value written to the
12550<em>gl_PrimitiveID</em> geometry shader output, if a geometry shader is present.
12551Otherwise, it is filled with the number of primitives processed by the
12552shader since the current set of rendering primitives was started.</p>
12553</div>
12554<div class="paragraph">
12555<p>The input variable <em>gl_Layer</em> is filled with the value written to the
12556<em>gl_Layer</em> geometry shader output, if a geometry shader is present.
12557If the geometry stage does not dynamically assign a value to <em>gl_Layer</em>, the
12558value of <em>gl_Layer</em> in the fragment stage will be undefined.
12559If the geometry stage makes no static assignment to <em>gl_Layer</em>, the input
12560value in the fragment stage will be zero.
12561Otherwise, the fragment stage will read the same value written by the
12562geometry stage, even if that value is out of range.
12563If a fragment shader contains a static access to <em>gl_Layer</em>, it will count
12564against the implementation defined limit for the maximum number of inputs to
12565the fragment stage.</p>
12566</div>
12567<div class="paragraph">
12568<p>The input variable <em>gl_ViewportIndex</em> is filled with the value written to
12569the output variable <em>gl_ViewportIndex</em> in the geometry stage, if a geometry
12570shader is present.
12571If the geometry stage does not dynamically assign a value to
12572<em>gl_ViewportIndex</em>, the value of <em>gl_ViewportIndex</em> in the fragment shader
12573will be undefined.
12574If the geometry stage makes no static assignment to <em>gl_ViewportIndex</em>, the
12575fragment stage will read zero.
12576Otherwise, the fragment stage will read the same value written by the
12577geometry stage, even if that value is out of range.
12578If a fragment shader contains a static access to <em>gl_ViewportIndex</em>, it will
12579count against the implementation defined limit for the maximum number of
12580inputs to the fragment stage.</p>
12581</div>
12582</div>
12583<div class="sect3">
12584<h4 id="compute-shader-special-variables">7.1.6. Compute Shader Special Variables</h4>
12585<div class="paragraph">
12586<p>In the compute shader, built-in variables are declared as follows:</p>
12587</div>
12588<div class="listingblock">
12589<div class="content">
12590<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">// workgroup dimensions</span>
12591in uvec3 gl_NumWorkGroups;
12592<span class="directive">const</span> uvec3 gl_WorkGroupSize;
12593
12594<span class="comment">// workgroup and invocation IDs</span>
12595in uvec3 gl_WorkGroupID;
12596in uvec3 gl_LocalInvocationID;
12597
12598<span class="comment">// derived variables</span>
12599in uvec3 gl_GlobalInvocationID;
12600in uint gl_LocalInvocationIndex;</code></pre>
12601</div>
12602</div>
12603<div class="paragraph">
12604<p>The built-in variable <em>gl_NumWorkGroups</em> is a compute-shader input variable
12605containing the number of workgroups in each dimension of the dispatch that
12606will execute the compute shader.
12607Its content is equal to the values specified in the <em>num_groups_x</em>,
12608<em>num_groups_y</em>, and <em>num_groups_z</em> parameters passed to the
12609<em>DispatchCompute</em> API entry point.</p>
12610</div>
12611<div class="paragraph">
12612<p>The built-in constant <em>gl_WorkGroupSize</em> is a compute-shader constant
12613containing the workgroup size of the shader.
12614The size of the workgroup in the <em>X</em>, <em>Y</em>, and <em>Z</em> dimensions is stored in
12615the <em>x</em>, <em>y</em>, and <em>z</em> components.
12616The constants values in <em>gl_WorkGroupSize</em> will match those specified in the
12617required <strong>local_size_x</strong>, <strong>local_size_y</strong>, and <strong>local_size_z</strong> layout
12618qualifiers for the current shader.
12619This is a constant so that it can be used to size arrays of memory that can
12620be shared within the workgroup.
12621It is a compile-time error to use <em>gl_WorkGroupSize</em> in a shader that does
12622not declare a fixed workgroup size, or before that shader has declared a
12623fixed workgroup size, using <strong>local_size_x</strong>, <strong>local_size_y</strong>, and
12624<strong>local_size_z</strong>.</p>
12625</div>
12626<div class="paragraph">
12627<p>The built-in variable <em>gl_WorkGroupID</em> is a compute-shader input variable
12628containing the three-dimensional index of the workgroup that the
12629current invocation is executing in.
12630The possible values range across the parameters passed into
12631<em>DispatchCompute</em>, i.e., from (0, 0, 0) to (<em>gl_NumWorkGroups.x</em> - 1,
12632<em>gl_NumWorkGroups.y</em> - 1, <em>gl_NumWorkGroups.z</em> -1).</p>
12633</div>
12634<div class="paragraph">
12635<p>The built-in variable <em>gl_LocalInvocationID</em> is a compute-shader input
12636variable containing the three-dimensional index of the current work item
12637within the workgroup.
12638The possible values for this variable range across the workgroup
12639size, i.e., (0,0,0) to (<em>gl_WorkGroupSize.x</em> - 1, <em>gl_WorkGroupSize.y</em> - 1,
12640<em>gl_WorkGroupSize.z</em> - 1). Use of <em>gl_LocalInvocationID</em> is allowed
12641before declarations of <strong>local_size_x</strong>, <strong>local_size_y</strong>, and <strong>local_size_z</strong>.</p>
12642</div>
12643<div class="paragraph">
12644<p>The built-in variable <em>gl_GlobalInvocationID</em> is a compute shader input
12645variable containing the global index of the current work item.
12646This value uniquely identifies this invocation from all other invocations
12647across all workgroups initiated by the current <em>DispatchCompute</em> call.
12648This is computed as:</p>
12649</div>
12650<div class="listingblock">
12651<div class="content">
12652<pre class="CodeRay highlight"><code data-lang="c++">gl_GlobalInvocationID =
12653    gl_WorkGroupID * gl_WorkGroupSize + gl_LocalInvocationID;</code></pre>
12654</div>
12655</div>
12656<div class="paragraph">
12657<p>The built-in variable <em>gl_LocalInvocationIndex</em> is a compute shader input
12658variable that contains the one-dimensional representation of the
12659<em>gl_LocalInvocationID</em>.
12660This is computed as:</p>
12661</div>
12662<div class="listingblock">
12663<div class="content">
12664<pre class="CodeRay highlight"><code data-lang="c++">gl_LocalInvocationIndex =
12665    gl_LocalInvocationID.z * gl_WorkGroupSize.x * gl_WorkGroupSize.y +
12666    gl_LocalInvocationID.y * gl_WorkGroupSize.x +
12667    gl_LocalInvocationID.x;</code></pre>
12668</div>
12669</div>
12670<div class="paragraph">
12671<p>Use of <em>gl_LocalInvocationIndex</em> is allowed before declarations of
12672<strong>local_size_x</strong>, <strong>local_size_y</strong>, and <strong>local_size_z</strong>.</p>
12673</div>
12674</div>
12675<div class="sect3">
12676<h4 id="compatibility-profile-built-in-language-variables">7.1.7. Compatibility Profile Built-In Language Variables</h4>
12677<div class="paragraph">
12678<p>When using the compatibility profile, the GL can provide fixed functionality
12679behavior for the vertex and fragment programmable pipeline stages.
12680For example, mixing a fixed functionality vertex stage with a programmable
12681fragment stage.</p>
12682</div>
12683<div class="paragraph">
12684<p>The following built-in vertex, tessellation control, tessellation
12685evaluation, and geometry output variables are available to specify inputs
12686for the subsequent programmable shader stage or the fixed functionality
12687fragment stage.
12688A particular one should be written to if any functionality in a
12689corresponding fragment shader or fixed pipeline uses it or state derived
12690from it.
12691Otherwise, behavior is undefined.
12692The following members are added to the output <em>gl_PerVertex</em> block in these
12693languages:</p>
12694</div>
12695<div class="listingblock">
12696<div class="content">
12697<pre class="CodeRay highlight"><code data-lang="c++">out gl_PerVertex { <span class="comment">// part of the gl_PerVertex block described in 7.1</span>
12698    <span class="comment">// in addition to other gl_PerVertex members...</span>
12699    vec4  gl_ClipVertex;
12700    vec4  gl_FrontColor;
12701    vec4  gl_BackColor;
12702    vec4  gl_FrontSecondaryColor;
12703    vec4  gl_BackSecondaryColor;
12704    vec4  gl_TexCoord[];
12705    <span class="predefined-type">float</span> gl_FogFragCoord;
12706};</code></pre>
12707</div>
12708</div>
12709<div class="paragraph">
12710<p>The output variable <em>gl_ClipVertex</em> provides a place for vertex and geometry
12711shaders to write the coordinate to be used with the user clipping planes.
12712Writing to <em>gl_ClipDistance</em> is the preferred method for user clipping.
12713It is a compile-time or link-time error for the set of shaders forming a
12714program to statically read or write both <em>gl_ClipVertex</em> and either
12715<em>gl_ClipDistance</em> or <em>gl_CullDistance</em>.
12716If neither <em>gl_ClipVertex</em> nor <em>gl_ClipDistance</em> is written, their values
12717are undefined and any clipping against user clip planes is also undefined.</p>
12718</div>
12719<div class="paragraph">
12720<p>Similarly to what was previously described for the core profile, the
12721<em>gl_PerVertex</em> block can be redeclared in a shader to explicitly include
12722these additional members.
12723For example:</p>
12724</div>
12725<div class="listingblock">
12726<div class="content">
12727<pre class="CodeRay highlight"><code data-lang="c++">out gl_PerVertex {
12728    vec4 gl_Position;    <span class="comment">// will use gl_Position</span>
12729    vec4 gl_FrontColor;  <span class="comment">// will consume gl_color in the fragment shader</span>
12730    vec4 gl_BackColor;
12731    vec4 gl_TexCoord[<span class="integer">3</span>]; <span class="comment">// 3 elements of gl_TexCoord will be used</span>
12732}; <span class="comment">// no other aspects of the fixed interface will be used</span></code></pre>
12733</div>
12734</div>
12735<div class="paragraph">
12736<p>The user must ensure the clip vertex and user clipping planes are defined in
12737the same coordinate space.
12738User clip planes work properly only under linear transform.
12739It is undefined what happens under non-linear transform.</p>
12740</div>
12741<div class="paragraph">
12742<p>The output variables <em>gl_FrontColor</em>, <em>glFrontSecondaryColor</em>,
12743<em>gl_BackColor</em>, and <em>glBackSecondaryColor</em> assign primary and secondary
12744colors for front and back faces of primitives containing the vertex being
12745processed.
12746The output variable <em>gl_TexCoord</em> assigns texture coordinates for the vertex
12747being processed.</p>
12748</div>
12749<div class="paragraph">
12750<p>For <em>gl_FogFragCoord</em>, the value written will be used as the &#8220;c&#8221; value in
12751section 16.4 &#8220;Fog&#8221; of the Compatibility profile of the
12752<a href="#references">OpenGL Specification</a>, by the fixed functionality pipeline.
12753For example, if the z-coordinate of the fragment in eye space is desired as
12754&#8220;c&#8221;, then that&#8217;s what the vertex shader executable should write into
12755<em>gl_FogFragCoord</em>.</p>
12756</div>
12757<div class="paragraph">
12758<p>As with all arrays, indices used to subscript <em>gl_TexCoord</em> must either be a
12759constant integral expressions, or this array must be redeclared by the
12760shader with a size.
12761The size can be at most <em>gl_MaxTextureCoords</em>.
12762Using indices close to 0 may aid the implementation in preserving varying
12763resources.
12764The redeclaration of <em>gl_TexCoord</em> can also be done at global scope as, for
12765example:</p>
12766</div>
12767<div class="listingblock">
12768<div class="content">
12769<pre class="CodeRay highlight"><code data-lang="c++">in vec4 gl_TexCoord[<span class="integer">3</span>];
12770out vec4 gl_TexCoord[<span class="integer">4</span>];</code></pre>
12771</div>
12772</div>
12773<div class="paragraph">
12774<p>(This treatment is a special case for <em>gl_TexCoord[]</em>, not a general method
12775for redeclaring members of blocks.) It is a compile-time error to redeclare
12776<em>gl_TexCoord[]</em> at global scope if there is a redeclaration of the
12777corresponding built-in block; only one form of redeclaration is allowed
12778within a shader (and hence within a stage, as block redeclarations must
12779match across all shaders using it).</p>
12780</div>
12781<div class="paragraph">
12782<p>In the tessellation control, evaluation, and geometry shaders, the outputs
12783of the previous stage described above are also available in the input
12784<em>gl_PerVertex</em> block in these languages.</p>
12785</div>
12786<div class="listingblock">
12787<div class="content">
12788<pre class="CodeRay highlight"><code data-lang="c++">in gl_PerVertex { <span class="comment">// part of the gl_PerVertex block described in 7.1</span>
12789    <span class="comment">// in addition to other gl_PerVertex members...</span>
12790    vec4  gl_ClipVertex;
12791    vec4  gl_FrontColor;
12792    vec4  gl_BackColor;
12793    vec4  gl_FrontSecondaryColor;
12794    vec4  gl_BackSecondaryColor;
12795    vec4  gl_TexCoord[];
12796    <span class="predefined-type">float</span> gl_FogFragCoord;
12797} gl_in[];</code></pre>
12798</div>
12799</div>
12800<div class="paragraph">
12801<p>These can be redeclared to establish an explicit pipeline interface, the
12802same way as described above for the output block <em>gl_PerVertex</em>, and the
12803input redeclaration must match the output redeclaration of the previous
12804stage.
12805However, when a built-in interface block with an instance name is redeclared
12806(e.g. <em>gl_in</em>), the instance name must be included in the redeclaration.
12807It is a compile-time error to not include the built-in instance name or to
12808change its name.
12809For example,</p>
12810</div>
12811<div class="listingblock">
12812<div class="content">
12813<pre class="CodeRay highlight"><code data-lang="c++">in gl_PerVertex {
12814    vec4 gl_ClipVertex;
12815    vec4 gl_FrontColor;
12816} gl_in[]; <span class="comment">// must be present and must be &quot;gl_in[]&quot;</span></code></pre>
12817</div>
12818</div>
12819<div class="paragraph">
12820<p>Built-in block arrays predeclared with a size can be redeclared with unsized syntax.
12821This keeps their size equal to the original predeclared size.</p>
12822</div>
12823<div class="paragraph">
12824<p>Treatment of <em>gl_TexCoord[]</em> redeclaration is also identical to that
12825described for the output block <em>gl_TexCoord[]</em> redeclaration.</p>
12826</div>
12827<div class="paragraph">
12828<p>The following fragment input block is also available in a fragment shader
12829when using the compatibility profile:</p>
12830</div>
12831<div class="listingblock">
12832<div class="content">
12833<pre class="CodeRay highlight"><code data-lang="c++">in gl_PerFragment {
12834    in <span class="predefined-type">float</span> gl_FogFragCoord;
12835    in vec4  gl_TexCoord[];
12836    in vec4  gl_Color;
12837    in vec4  gl_SecondaryColor;
12838};</code></pre>
12839</div>
12840</div>
12841<div class="paragraph">
12842<p>The values in <em>gl_Color</em> and <em>gl_SecondaryColor</em> will be derived
12843automatically by the system from <em>gl_FrontColor</em>, <em>gl_BackColor</em>,
12844<em>gl_FrontSecondaryColor</em>, and <em>gl_BackSecondaryColor</em> based on which face is
12845visible in the primitive producing the fragment.
12846If fixed functionality is used for vertex processing, then <em>gl_FogFragCoord</em>
12847will either be the z-coordinate of the fragment in eye space, or the
12848interpolation of the fog coordinate, as described in section 16.4 &#8220;Fog&#8221; of
12849the Compatibility profile of the <a href="#references">OpenGL Specification</a>.
12850The <em>gl_TexCoord[]</em> values are the interpolated <em>gl_TexCoord[]</em> values from
12851a vertex shader or the texture coordinates of any fixed pipeline based
12852vertex functionality.</p>
12853</div>
12854<div class="paragraph">
12855<p>Indices to the fragment shader <em>gl_TexCoord</em> array are as described above in
12856the vertex shader text.</p>
12857</div>
12858<div class="paragraph">
12859<p>As described above for the input and output <em>gl_PerVertex</em> blocks, the
12860<em>gl_PerFragment</em> block can be redeclared to create an explicit interface to
12861another program.
12862When matching these interfaces between separate programs, members in the
12863<em>gl_PerVertex</em> output block must be declared if and only if the
12864corresponding fragment shader members generated from them are present in the
12865<em>gl_PerFragment</em> input block.
12866These matches are described in detail in section 7.4.1 &#8220;Shader Interface
12867Matching&#8221; of the <a href="#references">OpenGL Specification</a>.
12868If they don&#8217;t match within a program, a link-time error will result.
12869If the mismatch is between two programs, values passed between programs are
12870undefined.
12871Unlike with all other block matching, the order of declaration within
12872<em>gl_PerFragment</em> does not have to match across shaders and does not have to
12873correspond with order of declaration in a matching <em>gl_PerVertex</em>
12874redeclaration.</p>
12875</div>
12876<div class="paragraph">
12877<p>The following fragment output variables are available in a fragment shader
12878when using the compatibility profile:</p>
12879</div>
12880<div class="listingblock">
12881<div class="content">
12882<pre class="CodeRay highlight"><code data-lang="c++">out vec4 gl_FragColor;
12883out vec4 gl_FragData[gl_MaxDrawBuffers];</code></pre>
12884</div>
12885</div>
12886<div class="paragraph">
12887<p>Writing to <em>gl_FragColor</em> specifies the fragment color that will be used by
12888the subsequent fixed functionality pipeline.
12889If subsequent fixed functionality consumes fragment color and an execution
12890of the fragment shader executable does not write a value to <em>gl_FragColor</em>
12891then the fragment color consumed is undefined.</p>
12892</div>
12893<div class="paragraph">
12894<p>The variable <em>gl_FragData</em> is an array.
12895Writing to <em>gl_FragData[n]</em> specifies the fragment data that will be used by
12896the subsequent fixed functionality pipeline for data <em>n</em>.
12897If subsequent fixed functionality consumes fragment data and an execution of
12898a fragment shader executable does not write a value to it, then the fragment
12899data consumed is undefined.</p>
12900</div>
12901<div class="paragraph">
12902<p>If a shader statically assigns a value to <em>gl_FragColor</em>, it may not assign
12903a value to any element of <em>gl_FragData</em>.
12904If a shader statically writes a value to any element of <em>gl_FragData</em>, it
12905may not assign a value to <em>gl_FragColor</em>.
12906That is, a shader may assign values to either <em>gl_FragColor</em> or
12907<em>gl_FragData</em>, but not both.
12908Multiple shaders linked together must also consistently write just one of
12909these variables.
12910Similarly, if user-declared output variables are in use (statically assigned
12911to), then the built-in variables <em>gl_FragColor</em> and <em>gl_FragData</em> may not be
12912assigned to.
12913These incorrect usages all generate compile-time or link-time errors.</p>
12914</div>
12915<div class="paragraph">
12916<p>If a shader executes the <strong>discard</strong> keyword, the fragment is discarded, and
12917the values of <em>gl_FragDepth</em> and <em>gl_FragColor</em> become irrelevant.</p>
12918</div>
12919</div>
12920</div>
12921<div class="sect2">
12922<h3 id="compatibility-profile-vertex-shader-built-in-inputs">7.2. Compatibility Profile Vertex Shader Built-In Inputs</h3>
12923<div class="paragraph">
12924<p>The following predeclared input names can be used from within a vertex
12925shader to access the current values of OpenGL state when using the
12926compatibility profile.</p>
12927</div>
12928<div class="listingblock">
12929<div class="content">
12930<pre class="CodeRay highlight"><code data-lang="c++">in vec4 gl_Color;
12931in vec4 gl_SecondaryColor;
12932in vec3 gl_Normal;
12933in vec4 gl_Vertex;
12934in vec4 gl_MultiTexCoord0;
12935in vec4 gl_MultiTexCoord1;
12936in vec4 gl_MultiTexCoord2;
12937in vec4 gl_MultiTexCoord3;
12938in vec4 gl_MultiTexCoord4;
12939in vec4 gl_MultiTexCoord5;
12940in vec4 gl_MultiTexCoord6;
12941in vec4 gl_MultiTexCoord7;
12942in <span class="predefined-type">float</span> gl_FogCoord;</code></pre>
12943</div>
12944</div>
12945</div>
12946<div class="sect2">
12947<h3 id="built-in-constants">7.3. Built-In Constants</h3>
12948<div class="paragraph">
12949<p>The following built-in constants are declared in all shaders.
12950The actual values used are implementation-dependent, but must be at least
12951the value shown.</p>
12952</div>
12953<div class="listingblock">
12954<div class="content">
12955<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">//</span>
12956<span class="comment">// Implementation-dependent constants. The example values below</span>
12957<span class="comment">// are the minimum values allowed for these maximums.</span>
12958<span class="comment">//</span></code></pre>
12959</div>
12960</div>
12961<div class="listingblock">
12962<div class="content">
12963<pre class="CodeRay highlight"><code data-lang="c++"><span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxVertexAttribs = <span class="integer">16</span>;
12964<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxVertexUniformVectors = <span class="integer">256</span>;
12965<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxVertexUniformComponents = <span class="integer">1024</span>;
12966<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxVertexOutputComponents = <span class="integer">64</span>;
12967<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxVaryingComponents = <span class="integer">60</span>;
12968<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxVaryingVectors = <span class="integer">15</span>;
12969<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxVertexTextureImageUnits = <span class="integer">16</span>;
12970<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxVertexImageUniforms = <span class="integer">0</span>;
12971<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxVertexAtomicCounters = <span class="integer">0</span>;
12972<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxVertexAtomicCounterBuffers = <span class="integer">0</span>;
12973
12974<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessPatchComponents = <span class="integer">120</span>;
12975<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxPatchVertices = <span class="integer">32</span>;
12976<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessGenLevel = <span class="integer">64</span>;
12977
12978<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessControlInputComponents = <span class="integer">128</span>;
12979<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessControlOutputComponents = <span class="integer">128</span>;
12980<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessControlTextureImageUnits = <span class="integer">16</span>;
12981<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessControlUniformComponents = <span class="integer">1024</span>;
12982<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessControlTotalOutputComponents = <span class="integer">4096</span>;
12983<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessControlImageUniforms = <span class="integer">0</span>;
12984<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessControlAtomicCounters = <span class="integer">0</span>;
12985<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessControlAtomicCounterBuffers = <span class="integer">0</span>;
12986
12987<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessEvaluationInputComponents = <span class="integer">128</span>;
12988<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessEvaluationOutputComponents = <span class="integer">128</span>;
12989<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessEvaluationTextureImageUnits = <span class="integer">16</span>;
12990<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessEvaluationUniformComponents = <span class="integer">1024</span>;
12991<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessEvaluationImageUniforms = <span class="integer">0</span>;
12992<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessEvaluationAtomicCounters = <span class="integer">0</span>;
12993<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTessEvaluationAtomicCounterBuffers = <span class="integer">0</span>;
12994
12995<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxGeometryInputComponents = <span class="integer">64</span>;
12996<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxGeometryOutputComponents = <span class="integer">128</span>;
12997<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxGeometryImageUniforms = <span class="integer">0</span>;
12998<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxGeometryTextureImageUnits = <span class="integer">16</span>;
12999<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxGeometryOutputVertices = <span class="integer">256</span>;
13000<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxGeometryTotalOutputComponents = <span class="integer">1024</span>;
13001<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxGeometryUniformComponents = <span class="integer">1024</span>;
13002<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxGeometryVaryingComponents = <span class="integer">64</span>;            <span class="comment">// deprecated</span>
13003<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxGeometryAtomicCounters = <span class="integer">0</span>;
13004<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxGeometryAtomicCounterBuffers = <span class="integer">0</span>;
13005
13006<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxFragmentImageUniforms = <span class="integer">8</span>;
13007<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxFragmentInputComponents = <span class="integer">128</span>;
13008<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxFragmentUniformVectors = <span class="integer">256</span>;
13009<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxFragmentUniformComponents = <span class="integer">1024</span>;
13010<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxFragmentAtomicCounters = <span class="integer">8</span>;
13011<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxFragmentAtomicCounterBuffers = <span class="integer">1</span>;
13012
13013<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxDrawBuffers = <span class="integer">8</span>;
13014<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTextureImageUnits = <span class="integer">16</span>;
13015<span class="directive">const</span> <span class="predefined-type">int</span> gl_MinProgramTexelOffset = -<span class="integer">8</span>;
13016<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxProgramTexelOffset = <span class="integer">7</span>;
13017<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxImageUnits = <span class="integer">8</span>;
13018<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxSamples = <span class="integer">4</span>;
13019<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxImageSamples = <span class="integer">0</span>;
13020<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxClipDistances = <span class="integer">8</span>;
13021<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxCullDistances = <span class="integer">8</span>;
13022<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxViewports = <span class="integer">16</span>;
13023
13024<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxComputeImageUniforms = <span class="integer">8</span>;
13025<span class="directive">const</span> ivec3 gl_MaxComputeWorkGroupCount = { <span class="integer">65535</span>, <span class="integer">65535</span>, <span class="integer">65535</span> };
13026<span class="directive">const</span> ivec3 gl_MaxComputeWorkGroupSize = { <span class="integer">1024</span>, <span class="integer">1024</span>, <span class="integer">64</span> };
13027<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxComputeUniformComponents = <span class="integer">1024</span>;
13028<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxComputeTextureImageUnits = <span class="integer">16</span>;
13029<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxComputeAtomicCounters = <span class="integer">8</span>;
13030<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxComputeAtomicCounterBuffers = <span class="integer">8</span>;
13031
13032<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxCombinedTextureImageUnits = <span class="integer">96</span>;
13033<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxCombinedImageUniforms = <span class="integer">48</span>;
13034<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxCombinedImageUnitsAndFragmentOutputs = <span class="integer">8</span>;  <span class="comment">// deprecated</span>
13035<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxCombinedShaderOutputResources = <span class="integer">16</span>;
13036<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxCombinedAtomicCounters = <span class="integer">8</span>;
13037<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxCombinedAtomicCounterBuffers = <span class="integer">1</span>;
13038<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxCombinedClipAndCullDistances = <span class="integer">8</span>;
13039<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxAtomicCounterBindings = <span class="integer">1</span>;
13040<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxAtomicCounterBufferSize = <span class="integer">32</span>;
13041
13042<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTransformFeedbackBuffers = <span class="integer">4</span>;
13043<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTransformFeedbackInterleavedComponents = <span class="integer">64</span>;
13044
13045<span class="directive">const</span> highp <span class="predefined-type">int</span> gl_MaxInputAttachments = <span class="integer">1</span>;  <span class="comment">// only present when targeting Vulkan</span></code></pre>
13046</div>
13047</div>
13048<div class="paragraph">
13049<p>The constant <em>gl_MaxVaryingFloats</em> is removed in the core profile, use
13050<em>gl_MaxVaryingComponents</em> instead.</p>
13051</div>
13052<div class="sect3">
13053<h4 id="compatibility-profile-built-in-constants">7.3.1. Compatibility Profile Built-In Constants</h4>
13054<div class="listingblock">
13055<div class="content">
13056<pre class="CodeRay highlight"><code data-lang="c++"><span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTextureUnits = <span class="integer">2</span>;
13057<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxTextureCoords = <span class="integer">8</span>;
13058<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxClipPlanes = <span class="integer">8</span>;
13059<span class="directive">const</span> <span class="predefined-type">int</span> gl_MaxVaryingFloats = <span class="integer">60</span>;</code></pre>
13060</div>
13061</div>
13062</div>
13063</div>
13064<div class="sect2">
13065<h3 id="built-in-uniform-state">7.4. Built-In Uniform State</h3>
13066<div class="paragraph">
13067<p>Built-in uniform state is not available when generating SPIR-V.
13068Otherwise, as an aid to accessing OpenGL processing state, the following
13069uniform variables are built into the OpenGL Shading Language.</p>
13070</div>
13071<div class="listingblock">
13072<div class="content">
13073<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">//</span>
13074<span class="comment">// Depth range in window coordinates,</span>
13075<span class="comment">// section 13.6.1 &quot;Controlling the Viewport&quot; in the</span>
13076<span class="comment">// OpenGL Specification.</span>
13077<span class="comment">//</span>
13078<span class="comment">// Note: Depth-range state is only for viewport 0.</span>
13079<span class="comment">//</span>
13080<span class="keyword">struct</span> gl_DepthRangeParameters {
13081    <span class="predefined-type">float</span> near; <span class="comment">// n</span>
13082    <span class="predefined-type">float</span> far;  <span class="comment">// f</span>
13083    <span class="predefined-type">float</span> diff; <span class="comment">// f - n</span>
13084};
13085uniform gl_DepthRangeParameters gl_DepthRange;
13086uniform <span class="predefined-type">int</span> gl_NumSamples;</code></pre>
13087</div>
13088</div>
13089<div class="paragraph">
13090<p>These variables are only guaranteed to be available in the fragment stage.
13091In other stages, their presence and function is implementation-defined.</p>
13092</div>
13093<div class="sect3">
13094<h4 id="compatibility-profile-state">7.4.1. Compatibility Profile State</h4>
13095<div class="paragraph">
13096<p>These variables are present only in the compatibility profile.
13097They are not available to compute shaders, but are available to all other
13098shaders.</p>
13099</div>
13100<div class="listingblock">
13101<div class="content">
13102<pre class="CodeRay highlight"><code data-lang="c++"><span class="comment">//</span>
13103<span class="comment">// compatibility profile only</span>
13104<span class="comment">//</span>
13105uniform mat4 gl_ModelViewMatrix;
13106uniform mat4 gl_ProjectionMatrix;
13107uniform mat4 gl_ModelViewProjectionMatrix;
13108uniform mat4 gl_TextureMatrix[gl_MaxTextureCoords];
13109
13110<span class="comment">//</span>
13111<span class="comment">// compatibility profile only</span>
13112<span class="comment">//</span>
13113uniform mat3 gl_NormalMatrix; <span class="comment">// transpose of the inverse of the</span>
13114                              <span class="comment">// upper leftmost 3x3 of gl_ModelViewMatrix</span>
13115
13116uniform mat4 gl_ModelViewMatrixInverse;
13117uniform mat4 gl_ProjectionMatrixInverse;
13118uniform mat4 gl_ModelViewProjectionMatrixInverse;
13119uniform mat4 gl_TextureMatrixInverse[gl_MaxTextureCoords];
13120
13121uniform mat4 gl_ModelViewMatrixTranspose;
13122uniform mat4 gl_ProjectionMatrixTranspose;
13123uniform mat4 gl_ModelViewProjectionMatrixTranspose;
13124uniform mat4 gl_TextureMatrixTranspose[gl_MaxTextureCoords];
13125
13126uniform mat4 gl_ModelViewMatrixInverseTranspose;
13127uniform mat4 gl_ProjectionMatrixInverseTranspose;
13128uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose;
13129uniform mat4 gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];
13130
13131<span class="comment">//</span>
13132<span class="comment">// compatibility profile only</span>
13133<span class="comment">//</span>
13134uniform <span class="predefined-type">float</span> gl_NormalScale;
13135
13136<span class="comment">//</span>
13137<span class="comment">// compatibility profile only</span>
13138<span class="comment">//</span>
13139uniform vec4 gl_ClipPlane[gl_MaxClipPlanes];
13140
13141<span class="comment">//</span>
13142<span class="comment">// compatibility profile only</span>
13143<span class="comment">//</span>
13144<span class="keyword">struct</span> gl_PointParameters {
13145    <span class="predefined-type">float</span> size;
13146    <span class="predefined-type">float</span> sizeMin;
13147    <span class="predefined-type">float</span> sizeMax;
13148    <span class="predefined-type">float</span> fadeThresholdSize;
13149    <span class="predefined-type">float</span> distanceConstantAttenuation;
13150    <span class="predefined-type">float</span> distanceLinearAttenuation;
13151    <span class="predefined-type">float</span> distanceQuadraticAttenuation;
13152};
13153
13154uniform gl_PointParameters gl_Point;
13155
13156<span class="comment">//</span>
13157<span class="comment">// compatibility profile only</span>
13158<span class="comment">//</span>
13159<span class="keyword">struct</span> gl_MaterialParameters {
13160 vec4 emission;   <span class="comment">// Ecm</span>
13161 vec4 ambient;    <span class="comment">// Acm</span>
13162 vec4 diffuse;    <span class="comment">// Dcm</span>
13163 vec4 specular;   <span class="comment">// Scm</span>
13164 <span class="predefined-type">float</span> shininess; <span class="comment">// Srm</span>
13165};
13166uniform gl_MaterialParameters gl_FrontMaterial;
13167uniform gl_MaterialParameters gl_BackMaterial;
13168
13169<span class="comment">//</span>
13170<span class="comment">// compatibility profile only</span>
13171<span class="comment">//</span>
13172<span class="keyword">struct</span> gl_LightSourceParameters {
13173    vec4 ambient;               <span class="comment">// Acli</span>
13174    vec4 diffuse;               <span class="comment">// Dcli</span>
13175    vec4 specular;              <span class="comment">// Scli</span>
13176    vec4 position;              <span class="comment">// Ppli</span>
13177    vec4 halfVector;            <span class="comment">// Derived: Hi</span>
13178    vec3 spotDirection;         <span class="comment">// Sdli</span>
13179    <span class="predefined-type">float</span> spotExponent;         <span class="comment">// Srli</span>
13180    <span class="predefined-type">float</span> spotCutoff;           <span class="comment">// Crli</span>
13181                                <span class="comment">// (range: [0.0,90.0], 180.0)</span>
13182    <span class="predefined-type">float</span> spotCosCutoff;        <span class="comment">// Derived: cos(Crli)</span>
13183                                <span class="comment">// (range: [1.0,0.0],-1.0)</span>
13184    <span class="predefined-type">float</span> constantAttenuation;  <span class="comment">// K0</span>
13185    <span class="predefined-type">float</span> linearAttenuation;    <span class="comment">// K1</span>
13186    <span class="predefined-type">float</span> quadraticAttenuation; <span class="comment">// K2</span>
13187};
13188
13189uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];
13190
13191<span class="keyword">struct</span> gl_LightModelParameters {
13192    vec4 ambient;                  <span class="comment">// Acs</span>
13193};
13194
13195uniform gl_LightModelParameters gl_LightModel;
13196
13197<span class="comment">//</span>
13198<span class="comment">// compatibility profile only</span>
13199<span class="comment">//</span>
13200<span class="comment">// Derived state from products of light and material.</span>
13201<span class="comment">//</span>
13202
13203<span class="keyword">struct</span> gl_LightModelProducts {
13204    vec4 sceneColor; <span class="comment">// Derived. Ecm + Acm * Acs</span>
13205};
13206
13207uniform gl_LightModelProducts gl_FrontLightModelProduct;
13208uniform gl_LightModelProducts gl_BackLightModelProduct;
13209
13210<span class="keyword">struct</span> gl_LightProducts {
13211    vec4 ambient; <span class="comment">// Acm * Acli</span>
13212    vec4 diffuse; <span class="comment">// Dcm * Dcli</span>
13213    vec4 specular; <span class="comment">// Scm * Scli</span>
13214};
13215
13216uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];
13217uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];
13218
13219<span class="comment">//</span>
13220<span class="comment">// compatibility profile only</span>
13221<span class="comment">//</span>
13222uniform vec4 gl_TextureEnvColor[gl_MaxTextureUnits];
13223uniform vec4 gl_EyePlaneS[gl_MaxTextureCoords];
13224uniform vec4 gl_EyePlaneT[gl_MaxTextureCoords];
13225uniform vec4 gl_EyePlaneR[gl_MaxTextureCoords];
13226uniform vec4 gl_EyePlaneQ[gl_MaxTextureCoords];
13227uniform vec4 gl_ObjectPlaneS[gl_MaxTextureCoords];
13228uniform vec4 gl_ObjectPlaneT[gl_MaxTextureCoords];
13229uniform vec4 gl_ObjectPlaneR[gl_MaxTextureCoords];
13230uniform vec4 gl_ObjectPlaneQ[gl_MaxTextureCoords];
13231
13232<span class="comment">//</span>
13233<span class="comment">// compatibility profile only</span>
13234<span class="comment">//</span>
13235<span class="keyword">struct</span> gl_FogParameters {
13236    vec4 color;
13237    <span class="predefined-type">float</span> density;
13238    <span class="predefined-type">float</span> start;
13239    <span class="predefined-type">float</span> end;
13240    <span class="predefined-type">float</span> scale; <span class="comment">// Derived: 1.0 / (end - start)</span>
13241};
13242
13243uniform gl_FogParameters gl_Fog;</code></pre>
13244</div>
13245</div>
13246</div>
13247</div>
13248<div class="sect2">
13249<h3 id="redeclaring-built-in-blocks">7.5. Redeclaring Built-In Blocks</h3>
13250<div class="paragraph">
13251<p>The <em>gl_PerVertex</em> block can be redeclared in a shader to explicitly
13252indicate what subset of the fixed pipeline interface will be used.
13253This is necessary to establish the interface between multiple programs.
13254For example:</p>
13255</div>
13256<div class="listingblock">
13257<div class="content">
13258<pre class="CodeRay highlight"><code data-lang="c++">out gl_PerVertex {
13259    vec4 gl_Position;   <span class="comment">// will use gl_Position</span>
13260    <span class="predefined-type">float</span> gl_PointSize; <span class="comment">// will use gl_PointSize</span>
13261    vec4 t;             <span class="comment">// error, only gl_PerVertex members allowed</span>
13262}; <span class="comment">// no other members of gl_PerVertex will be used</span></code></pre>
13263</div>
13264</div>
13265<div class="paragraph">
13266<p>This establishes the output interface the shader will use with the
13267subsequent pipeline stage.
13268It must be a subset of the built-in members of <em>gl_PerVertex</em>.
13269Such a redeclaration can also add the <strong>invariant</strong> qualifier, interpolation
13270qualifiers, and the layout qualifiers <strong>xfb_offset</strong>, <strong>xfb_buffer</strong>, and
13271<strong>xfb_stride</strong>.
13272It can also add an array size for unsized arrays.
13273For example:</p>
13274</div>
13275<div class="listingblock">
13276<div class="content">
13277<pre class="CodeRay highlight"><code data-lang="c++">out layout(xfb_buffer = <span class="integer">1</span>, xfb_stride = <span class="integer">16</span>) gl_PerVertex {
13278    vec4 gl_Position;
13279    layout(xfb_offset = <span class="integer">0</span>) <span class="predefined-type">float</span> gl_ClipDistance[<span class="integer">4</span>];
13280};</code></pre>
13281</div>
13282</div>
13283<div class="paragraph">
13284<p>Other layout qualifiers, like <strong>location</strong>, cannot be added to such a
13285redeclaration, unless specifically stated.</p>
13286</div>
13287<div class="paragraph">
13288<p>If a built-in interface block is redeclared, it must appear in the shader
13289before any use of any member included in the built-in declaration, or a
13290compile-time error will result.
13291It is also a compile-time error to redeclare the block more than once or to
13292redeclare a built-in block and then use a member from that built-in block
13293that was not included in the redeclaration.
13294Also, if a built-in interface block is redeclared, no member of the built-in
13295declaration can be redeclared outside the block redeclaration.
13296If multiple shaders using members of a built-in block belonging to the same
13297interface are linked together in the same program, they must all redeclare
13298the built-in block in the same way, as described in
13299&#8220;<a href="#interface-blocks">Interface Blocks</a>&#8221; for interface block matching, or a
13300link-time error will result.
13301It will also be a link-time error if some shaders in a program redeclare a
13302specific built-in interface block while another shader in that program does
13303not redeclare that interface block yet still uses a member of that interface
13304block.
13305If a built-in block interface is formed across shaders in different
13306programs, the shaders must all redeclare the built-in block in the same way
13307(as described for a single program), or the values passed along the
13308interface are undefined.</p>
13309</div>
13310</div>
13311</div>
13312</div>
13313<div class="sect1">
13314<h2 id="built-in-functions">8. Built-In Functions</h2>
13315<div class="sectionbody">
13316<div class="paragraph">
13317<p>The OpenGL Shading Language defines an assortment of built-in convenience functions for
13318scalar and vector operations.
13319Many of these built-in functions can be used in more than one type of
13320shader, but some are intended to provide a direct mapping to hardware and so
13321are available only for a specific type of shader.</p>
13322</div>
13323<div class="paragraph">
13324<p>The built-in functions basically fall into three categories:</p>
13325</div>
13326<div class="ulist">
13327<ul>
13328<li>
13329<p>They expose some necessary hardware functionality in a convenient way
13330such as accessing a texture map.
13331There is no way in the language for these functions to be emulated by a
13332shader.</p>
13333</li>
13334<li>
13335<p>They represent a trivial operation (clamp, mix, etc.) that is very
13336simple for the user to write, but they are very common and may have
13337direct hardware support.
13338It is a very hard problem for the compiler to map expressions to complex
13339assembler instructions.</p>
13340</li>
13341<li>
13342<p>They represent an operation graphics hardware is likely to accelerate at
13343some point.
13344The trigonometry functions fall into this category.</p>
13345</li>
13346</ul>
13347</div>
13348<div class="paragraph">
13349<p>Many of the functions are similar to the same named ones in common C
13350libraries, but they support vector input as well as the more traditional
13351scalar input.</p>
13352</div>
13353<div class="paragraph">
13354<p>Applications should be encouraged to use the built-in functions rather than
13355do the equivalent computations in their own shader code since the built-in
13356functions are assumed to be optimal (e.g. perhaps supported directly in
13357hardware).</p>
13358</div>
13359<div class="paragraph">
13360<p>User code can replace built-in functions with their own if they choose, by
13361simply redeclaring and defining the same name and argument list.
13362Because built-in functions are in a more outer scope than user built-in
13363functions, doing this will hide all built-in functions with the same name as
13364the redeclared function.</p>
13365</div>
13366<div class="paragraph">
13367<p>When the built-in functions are specified below, where the input arguments
13368(and corresponding output) can be <strong>float</strong>, <strong>vec2</strong>, <strong>vec3</strong>, or <strong>vec4</strong>,
13369<em>genFType</em> is used as the argument.
13370Where the input arguments (and corresponding output) can be <strong>int</strong>, <strong>ivec2</strong>,
13371<strong>ivec3</strong>, or <strong>ivec4</strong>, <em>genIType</em> is used as the argument.
13372Where the input arguments (and corresponding output) can be <strong>uint</strong>, <strong>uvec2</strong>,
13373<strong>uvec3</strong>, or <strong>uvec4</strong>, <em>genUType</em> is used as the argument.
13374Where the input arguments (or corresponding output) can be <strong>bool</strong>, <strong>bvec2</strong>,
13375<strong>bvec3</strong>, or <strong>bvec4</strong>, <em>genBType</em> is used as the argument.
13376Where the input arguments (and corresponding output) can be <strong>double</strong>,
13377<strong>dvec2</strong>, <strong>dvec3</strong>, <strong>dvec4</strong>, <em>genDType</em> is used as the argument.
13378For any specific use of a function, the actual types substituted for
13379<em>genFType</em>, <em>genIType</em>, <em>genUType</em>, or <em>genBType</em> have to have the same
13380number of components for all arguments and for the return type.
13381Similarly, <em>mat</em> is used for any matrix basic
13382type with single-precision
13383components and <em>dmat</em> is used for any matrix basic type with
13384double-precision components.</p>
13385</div>
13386<div class="paragraph">
13387<p>Built-in functions have an effective precision qualification.
13388This qualification cannot be set explicitly and may be different from the
13389precision qualification of the result.</p>
13390</div>
13391<div class="paragraph">
13392<p>Note: In general, as has been noted, precision qualification is ignored
13393unless targeting Vulkan.</p>
13394</div>
13395<div class="paragraph">
13396<p>The precision qualification of the operation of a built-in function is based
13397on the precision qualification of its formal parameters and actual
13398parameters (input arguments): When a formal parameter specifies a precision
13399qualifier, that is used, otherwise, the precision qualification of the
13400actual (calling) argument is used.
13401The highest precision of these will be the precision of the operation of the
13402built-in function.
13403Generally, this is applied across all arguments to a built-in function, with
13404the exceptions being:</p>
13405</div>
13406<div class="ulist">
13407<ul>
13408<li>
13409<p><strong>bitfieldExtract</strong> and <strong>bitfieldInsert</strong> ignore the <em>offset</em> and <em>bits</em>
13410arguments.</p>
13411</li>
13412<li>
13413<p><strong>interpolateAt</strong> functions only look at the <em>interpolant</em> argument.</p>
13414</li>
13415</ul>
13416</div>
13417<div class="paragraph">
13418<p>The precision qualification of the result of a built-in function is
13419determined in one of the following ways:</p>
13420</div>
13421<div class="paragraph">
13422<p>For the texture sampling, image load and image store functions, the
13423precision of the return type matches the precision of the
13424texture-combined sampler type:</p>
13425</div>
13426<div class="listingblock">
13427<div class="content">
13428<pre class="CodeRay highlight"><code data-lang="c++">uniform lowp sampler2D texSampler;
13429highp vec2 coord;
13430...
13431lowp vec4 col = texture (texSampler, coord); <span class="comment">// texture() returns lowp</span></code></pre>
13432</div>
13433</div>
13434<div class="paragraph">
13435<p>Otherwise:</p>
13436</div>
13437<div class="ulist">
13438<ul>
13439<li>
13440<p>For prototypes that do not specify a resulting precision qualifier, the
13441precision will be the same as the precision of the operation (as defined
13442earlier).</p>
13443</li>
13444<li>
13445<p>For prototypes that do specify a resulting precision qualifier, the
13446specified precision qualifier is the precision qualification of the
13447result.</p>
13448</li>
13449</ul>
13450</div>
13451<div class="paragraph">
13452<p>Where the built-in functions in the following sections specify an equation,
13453the entire equation will be evaluated at the operation&#8217;s precision.
13454This may lead to underflow or overflow in the result, even when the correct
13455result could be represented in the operation precision.</p>
13456</div>
13457<div class="sect2">
13458<h3 id="angle-and-trigonometry-functions">8.1. Angle and Trigonometry Functions</h3>
13459<div class="paragraph">
13460<p>Function parameters specified as <em>angle</em> are assumed to be in units of
13461radians.
13462In no case will any of these functions result in a divide by zero error.
13463If the divisor of a ratio is 0, then results will be undefined.</p>
13464</div>
13465<div class="paragraph">
13466<p>These all operate component-wise.
13467The description is per component.</p>
13468</div>
13469<table class="tableblock frame-all grid-all stretch">
13470<colgroup>
13471<col style="width: 50%;">
13472<col style="width: 50%;">
13473</colgroup>
13474<thead>
13475<tr>
13476<th class="tableblock halign-left valign-top">Syntax</th>
13477<th class="tableblock halign-left valign-top">Description</th>
13478</tr>
13479</thead>
13480<tbody>
13481<tr>
13482<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>radians</strong>(genFType <em>degrees</em>)</p></td>
13483<td class="tableblock halign-left valign-top"><p class="tableblock">Converts <em>degrees</em> to radians, i.e.,
13484      <span class="eq">(π / 180) · degrees</span>.</p></td>
13485</tr>
13486<tr>
13487<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>degrees</strong>(genFType <em>radians</em>)</p></td>
13488<td class="tableblock halign-left valign-top"><p class="tableblock">Converts <em>radians</em> to degrees, i.e.,
13489      <span class="eq">(180 / π) · radians</span>.</p></td>
13490</tr>
13491<tr>
13492<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>sin</strong>(genFType <em>angle</em>)</p></td>
13493<td class="tableblock halign-left valign-top"><p class="tableblock">The standard trigonometric sine function.</p></td>
13494</tr>
13495<tr>
13496<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>cos</strong>(genFType <em>angle</em>)</p></td>
13497<td class="tableblock halign-left valign-top"><p class="tableblock">The standard trigonometric cosine function.</p></td>
13498</tr>
13499<tr>
13500<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>tan</strong>(genFType <em>angle</em>)</p></td>
13501<td class="tableblock halign-left valign-top"><p class="tableblock">The standard trigonometric tangent.</p></td>
13502</tr>
13503<tr>
13504<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>asin</strong>(genFType <em>x</em>)</p></td>
13505<td class="tableblock halign-left valign-top"><p class="tableblock">Arc sine.
13506      Returns an angle whose sine is <em>x</em>.
13507      The range of values returned by this function is
13508      <span class="eq">[-π / 2, π / 2]</span>.
13509      Results are undefined if <span class="eq">|x| &gt; 1</span>.</p></td>
13510</tr>
13511<tr>
13512<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>acos</strong>(genFType <em>x</em>)</p></td>
13513<td class="tableblock halign-left valign-top"><p class="tableblock">Arc cosine.
13514      Returns an angle whose cosine is <em>x</em>.
13515      The range of values returned by this function is <span class="eq">[0,π]</span>.
13516      Results are undefined if <span class="eq">|x| &gt; 1</span>.</p></td>
13517</tr>
13518<tr>
13519<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>atan</strong>(genFType <em>y</em>, genFType <em>x</em>)</p></td>
13520<td class="tableblock halign-left valign-top"><p class="tableblock">Arc tangent.
13521      Returns an angle whose tangent is <span class="eq">y / x</span>.
13522      The signs of <em>x</em> and <em>y</em> are used to determine what quadrant the angle
13523      is in.
13524      The range of values returned by this function is <span class="eq">[-π, π</span>.
13525      Results are undefined if <em>x</em> and <em>y</em> are both 0.</p></td>
13526</tr>
13527<tr>
13528<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>atan</strong>(genFType <em>y_over_x</em>)</p></td>
13529<td class="tableblock halign-left valign-top"><p class="tableblock">Arc tangent.
13530      Returns an angle whose tangent is <em>y_over_x</em>.
13531      The range of values returned by this function is
13532      <span class="eq">[-π / 2, π / 2]</span>.</p></td>
13533</tr>
13534<tr>
13535<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>sinh</strong>(genFType <em>x</em>)</p></td>
13536<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the hyperbolic sine function <span class="eq">(e<sup>x</sup> - e<sup>-x</sup>) / 2</span>.</p></td>
13537</tr>
13538<tr>
13539<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>cosh</strong>(genFType <em>x</em>)</p></td>
13540<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the hyperbolic cosine function <span class="eq">(e<sup>x</sup> + e<sup>-x</sup>) / 2</span>.</p></td>
13541</tr>
13542<tr>
13543<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>tanh</strong>(genFType <em>x</em>)</p></td>
13544<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the hyperbolic tangent function <span class="eq">sinh(x) / cosh(x)</span>.</p></td>
13545</tr>
13546<tr>
13547<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>asinh</strong>(genFType <em>x</em>)</p></td>
13548<td class="tableblock halign-left valign-top"><p class="tableblock">Arc hyperbolic sine; returns the inverse of <strong>sinh</strong>.</p></td>
13549</tr>
13550<tr>
13551<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>acosh</strong>(genFType <em>x</em>)</p></td>
13552<td class="tableblock halign-left valign-top"><p class="tableblock">Arc hyperbolic cosine; returns the non-negative inverse of <strong>cosh</strong>.
13553      Results are undefined if <span class="eq">x &lt; 1</span>.</p></td>
13554</tr>
13555<tr>
13556<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>atanh</strong>(genFType <em>x</em>)</p></td>
13557<td class="tableblock halign-left valign-top"><p class="tableblock">Arc hyperbolic tangent; returns the inverse of <strong>tanh</strong>.
13558      Results are undefined if <span class="eq">x ≥ 1</span>.</p></td>
13559</tr>
13560</tbody>
13561</table>
13562</div>
13563<div class="sect2">
13564<h3 id="exponential-functions">8.2. Exponential Functions</h3>
13565<div class="paragraph">
13566<p>These all operate component-wise.
13567The description is per component.</p>
13568</div>
13569<table class="tableblock frame-all grid-all stretch">
13570<colgroup>
13571<col style="width: 50%;">
13572<col style="width: 50%;">
13573</colgroup>
13574<thead>
13575<tr>
13576<th class="tableblock halign-left valign-top">Syntax</th>
13577<th class="tableblock halign-left valign-top">Description</th>
13578</tr>
13579</thead>
13580<tbody>
13581<tr>
13582<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>pow</strong>(genFType <em>x</em>, genFType <em>y</em>)</p></td>
13583<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <em>x</em> raised to the <em>y</em> power, i.e., <span class="eq">x<sup>y</sup></span>.
13584      Results are undefined if <span class="eq">x &lt; 0</span>.
13585      Results are undefined if <span class="eq">x = 0</span> and <span class="eq">y ≤ 0</span>.</p></td>
13586</tr>
13587<tr>
13588<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>exp</strong>(genFType <em>x</em>)</p></td>
13589<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the natural exponentiation of <em>x</em>, i.e., <span class="eq">e<sup>x</sup></span>.</p></td>
13590</tr>
13591<tr>
13592<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>log</strong>(genFType <em>x</em>)</p></td>
13593<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the natural logarithm of <em>x</em>, i.e., returns the value <em>y</em>
13594      which satisfies the equation <span class="eq">x = e<sup>y</sup></span>.
13595      Results are undefined if <span class="eq">x ≤ 0</span>.</p></td>
13596</tr>
13597<tr>
13598<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>exp2</strong>(genFType <em>x</em>)</p></td>
13599<td class="tableblock halign-left valign-top"><p class="tableblock">Returns 2 raised to the <em>x</em> power, i.e., <span class="eq">2<sup>x</sup></span>.</p></td>
13600</tr>
13601<tr>
13602<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>log2</strong>(genFType <em>x</em>)</p></td>
13603<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the base 2 logarithm of <em>x</em>, i.e., returns the value <em>y</em> which
13604      satisfies the equation <span class="eq">x = 2<sup>y</sup></span>.
13605      Results are undefined if <span class="eq">x ≤ 0</span>.</p></td>
13606</tr>
13607<tr>
13608<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>sqrt</strong>(genFType <em>x</em>)<br>
13609  genDType <strong>sqrt</strong>(genDType <em>x</em>)</p></td>
13610<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <span class="eq">sqrt(x)</span>.
13611      Results are undefined if <span class="eq">x &lt; 0</span>.</p></td>
13612</tr>
13613<tr>
13614<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>inversesqrt</strong>(genFType <em>x</em>)<br>
13615  genDType <strong>inversesqrt</strong>(genDType <em>x</em>)</p></td>
13616<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <span class="eq">1 / sqrt(x)</span>.
13617      Results are undefined if <span class="eq">x ≤ 0</span>.</p></td>
13618</tr>
13619</tbody>
13620</table>
13621</div>
13622<div class="sect2">
13623<h3 id="common-functions">8.3. Common Functions</h3>
13624<div class="paragraph">
13625<p>These all operate component-wise.
13626The description is per component.</p>
13627</div>
13628<table class="tableblock frame-all grid-all stretch">
13629<colgroup>
13630<col style="width: 50%;">
13631<col style="width: 50%;">
13632</colgroup>
13633<thead>
13634<tr>
13635<th class="tableblock halign-left valign-top">Syntax</th>
13636<th class="tableblock halign-left valign-top">Description</th>
13637</tr>
13638</thead>
13639<tbody>
13640<tr>
13641<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>abs</strong>(genFType <em>x</em>)<br>
13642  genIType <strong>abs</strong>(genIType <em>x</em>)<br>
13643  genDType <strong>abs</strong>(genDType <em>x</em>)</p></td>
13644<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <em>x</em> if <span class="eq">x ≥ 0</span>; otherwise it returns -<em>x</em>.</p></td>
13645</tr>
13646<tr>
13647<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>sign</strong>(genFType <em>x</em>)<br>
13648  genIType <strong>sign</strong>(genIType <em>x</em>)<br>
13649  genDType <strong>sign</strong>(genDType <em>x</em>)</p></td>
13650<td class="tableblock halign-left valign-top"><p class="tableblock">Returns 1.0 if <em>x</em> &gt; 0, 0.0 if <em>x</em> = 0, or -1.0 if <em>x</em> &lt; 0.</p></td>
13651</tr>
13652<tr>
13653<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>floor</strong>(genFType <em>x</em>)<br>
13654  genDType <strong>floor</strong>(genDType <em>x</em>)</p></td>
13655<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a value equal to the nearest integer that is less than or
13656      equal to <em>x</em>.</p></td>
13657</tr>
13658<tr>
13659<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>trunc</strong>(genFType <em>x</em>)<br>
13660  genDType <strong>trunc</strong>(genDType <em>x</em>)</p></td>
13661<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a value equal to the nearest integer to <em>x</em> whose absolute
13662      value is not larger than the absolute value of <em>x</em>.</p></td>
13663</tr>
13664<tr>
13665<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>round</strong>(genFType <em>x</em>)<br>
13666  genDType <strong>round</strong>(genDType <em>x</em>)</p></td>
13667<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a value equal to the nearest integer to <em>x</em>.
13668      The fraction 0.5 will round in a direction chosen by the
13669      implementation, presumably the direction that is fastest.
13670      This includes the possibility that <strong>round</strong>(<em>x</em>) returns the same value
13671      as <strong>roundEven</strong>(<em>x</em>) for all values of <em>x</em>.</p></td>
13672</tr>
13673<tr>
13674<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>roundEven</strong>(genFType <em>x</em>)<br>
13675  genDType <strong>roundEven</strong>(genDType <em>x</em>)</p></td>
13676<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a value equal to the nearest integer to <em>x</em>.
13677      A fractional part of 0.5 will round toward the nearest even integer.
13678      (Both 3.5 and 4.5 for x will return 4.0.)</p></td>
13679</tr>
13680<tr>
13681<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>ceil</strong>(genFType <em>x</em>)<br>
13682  genDType <strong>ceil</strong>(genDType <em>x</em>)</p></td>
13683<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a value equal to the nearest integer that is greater than or
13684      equal to <em>x</em>.</p></td>
13685</tr>
13686<tr>
13687<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>fract</strong>(genFType <em>x</em>)<br>
13688  genDType <strong>fract</strong>(genDType <em>x</em>)<br></p></td>
13689<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <em>x</em> - <strong>floor</strong>(<em>x</em>).</p></td>
13690</tr>
13691<tr>
13692<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>mod</strong>(genFType <em>x</em>, float <em>y</em>)<br>
13693  genFType <strong>mod</strong>(genFType <em>x</em>, genFType <em>y</em>)<br>
13694  genDType <strong>mod</strong>(genDType <em>x</em>, double <em>y</em>)<br>
13695  genDType <strong>mod</strong>(genDType <em>x</em>, genDType <em>y</em>)<br></p></td>
13696<td class="tableblock halign-left valign-top"><p class="tableblock">Modulus.
13697      Returns <span class="eq">x - y · <strong>floor</strong>(x / y)</span>.</p></td>
13698</tr>
13699<tr>
13700<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>modf</strong>(genFType <em>x</em>, out genFType <em>i</em>)<br>
13701  genDType <strong>modf</strong>(genDType <em>x</em>, out genDType <em>i</em>)</p></td>
13702<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the fractional part of <em>x</em> and sets <em>i</em> to the integer part (as
13703      a whole number floating-point value).
13704      Both the return value and the output parameter will have the same sign
13705      as <em>x</em>.</p></td>
13706</tr>
13707<tr>
13708<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>min</strong>(genFType <em>x</em>, genFType <em>y</em>)<br>
13709  genFType <strong>min</strong>(genFType <em>x</em>, float <em>y</em>)<br>
13710  genDType <strong>min</strong>(genDType <em>x</em>, genDType <em>y</em>)<br>
13711  genDType <strong>min</strong>(genDType <em>x</em>, double <em>y</em>)<br>
13712  genIType <strong>min</strong>(genIType <em>x</em>, genIType <em>y</em>)<br>
13713  genIType <strong>min</strong>(genIType <em>x</em>, int <em>y</em>)<br>
13714  genUType <strong>min</strong>(genUType <em>x</em>, genUType <em>y</em>)<br>
13715  genUType <strong>min</strong>(genUType <em>x</em>, uint <em>y</em>)</p></td>
13716<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <em>y</em> if <em>y</em> &lt; <em>x;</em> otherwise it returns <em>x</em>.</p></td>
13717</tr>
13718<tr>
13719<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>max</strong>(genFType <em>x</em>, genFType <em>y</em>)<br>
13720  genFType <strong>max</strong>(genFType <em>x</em>, float <em>y</em>)<br>
13721  genDType <strong>max</strong>(genDType <em>x</em>, genDType <em>y</em>)<br>
13722  genDType <strong>max</strong>(genDType <em>x</em>, double <em>y</em>)<br>
13723  genIType <strong>max</strong>(genIType <em>x</em>, genIType <em>y</em>)<br>
13724  genIType <strong>max</strong>(genIType <em>x</em>, int <em>y</em>)<br>
13725  genUType <strong>max</strong>(genUType <em>x</em>, genUType <em>y</em>)<br>
13726  genUType <strong>max</strong>(genUType <em>x</em>, uint <em>y</em>)</p></td>
13727<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <em>y</em> if <em>x</em> &lt; <em>y;</em> otherwise it returns <em>x</em>.</p></td>
13728</tr>
13729<tr>
13730<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>clamp</strong>(genFType <em>x</em>, genFType <em>minVal</em>, genFType <em>maxVal</em>)<br>
13731  genFType <strong>clamp</strong>(genFType <em>x</em>, float <em>minVal</em>, float <em>maxVal</em>)<br>
13732  genDType <strong>clamp</strong>(genDType <em>x</em>, genDType <em>minVal</em>, genDType <em>maxVal</em>)<br>
13733  genDType <strong>clamp</strong>(genDType <em>x</em>, double <em>minVal</em>, double <em>maxVal</em>)<br>
13734  genIType <strong>clamp</strong>(genIType <em>x</em>, genIType <em>minVal</em>, genIType <em>maxVal</em>)<br>
13735  genIType <strong>clamp</strong>(genIType <em>x</em>, int <em>minVal</em>, int <em>maxVal</em>)<br>
13736  genUType <strong>clamp</strong>(genUType <em>x</em>, genUType <em>minVal</em>, genUType <em>maxVal</em>)<br>
13737  genUType <strong>clamp</strong>(genUType <em>x</em>, uint <em>minVal</em>, uint <em>maxVal</em>)</p></td>
13738<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <strong>min</strong>(<strong>max</strong>(<em>x</em>, <em>minVal</em>), <em>maxVal</em>).
13739      Results are undefined if <em>minVal</em> &gt; <em>maxVal</em>.</p></td>
13740</tr>
13741<tr>
13742<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>mix</strong>(genFType <em>x</em>, genFType <em>y</em>, genFType <em>a</em>)<br>
13743  genFType <strong>mix</strong>(genFType <em>x</em>, genFType <em>y</em>, float <em>a</em>)<br>
13744  genDType <strong>mix</strong>(genDType <em>x</em>, genDType <em>y</em>, genDType <em>a</em>)<br>
13745  genDType <strong>mix</strong>(genDType <em>x</em>, genDType <em>y</em>, double <em>a</em>)<br></p></td>
13746<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the linear blend of <em>x</em> and <em>y</em>, i.e.,
13747      <span class="eq">x · (1 - a) + y · a</span>.</p></td>
13748</tr>
13749<tr>
13750<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>mix</strong>(genFType <em>x</em>, genFType <em>y</em>,  genBType <em>a</em>)<br>
13751  genDType <strong>mix</strong>(genDType <em>x</em>, genDType <em>y</em>, genBType <em>a</em>)<br>
13752  genIType <strong>mix</strong>(genIType <em>x</em>, genIType <em>y</em>, genBType <em>a</em>)<br>
13753  genUType <strong>mix</strong>(genUType <em>x</em>, genUType <em>y</em>, genBType <em>a</em>)<br>
13754  genBType <strong>mix</strong>(genBType <em>x</em>, genBType <em>y</em>, genBType <em>a</em>)</p></td>
13755<td class="tableblock halign-left valign-top"><p class="tableblock">Selects which vector each returned component comes from.
13756      For a component of <em>a</em> that is <strong>false</strong>, the corresponding component of
13757      <em>x</em> is returned.
13758      For a component of <em>a</em> that is <strong>true</strong>, the corresponding component of
13759      <em>y</em> is returned.
13760      Components of <em>x</em> and <em>y</em> that are not selected are allowed to be
13761      invalid floating-point values and will have no effect on the results.
13762      Thus, this provides different functionality than, for example,<br>
13763      genFType <strong>mix</strong>(genFType <em>x</em>, genFType <em>y</em>, genFType(<em>a</em>))<br>
13764      where <em>a</em> is a Boolean vector.</p></td>
13765</tr>
13766<tr>
13767<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>step</strong>(genFType <em>edge</em>, genFType <em>x</em>)<br>
13768  genFType <strong>step</strong>(float <em>edge</em>, genFType <em>x</em>)<br>
13769  genDType <strong>step</strong>(genDType <em>edge</em>, genDType <em>x</em>)<br>
13770  genDType <strong>step</strong>(double <em>edge</em>, genDType <em>x</em>)</p></td>
13771<td class="tableblock halign-left valign-top"><p class="tableblock">Returns 0.0 if <em>x</em> &lt; <em>edge;</em> otherwise it returns 1.0.</p></td>
13772</tr>
13773<tr>
13774<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>smoothstep</strong>(genFType <em>edge0</em>, genFType <em>edge1</em>, genFType <em>x</em>)<br>
13775  genFType <strong>smoothstep</strong>(float <em>edge0</em>, float <em>edge1</em>, genFType <em>x</em>)<br>
13776  genDType <strong>smoothstep</strong>(genDType <em>edge0</em>, genDType <em>edge1</em>, genDType <em>x</em>)<br>
13777  genDType <strong>smoothstep</strong>(double <em>edge0</em>, double <em>edge1</em>, genDType <em>x</em>)<br></p></td>
13778<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
13779<p>Returns 0.0 if <span class="eq">x ≤ edge0</span> and 1.0 if <span class="eq">x ≥ edge1</span>, and
13780      performs smooth Hermite interpolation between 0 and 1 when <span class="eq">edge0
13781      &lt; x &lt; edge1</span>.
13782      This is useful in cases where you would want a threshold function with
13783      a smooth transition.
13784      This is equivalent to:</p>
13785</div>
13786<div class="openblock">
13787<div class="content">
13788<div class="listingblock">
13789<div class="content">
13790<pre class="CodeRay highlight"><code data-lang="c++">genFType t;
13791t = clamp ((x - edge0) / (edge1 - edge0), <span class="integer">0</span>, <span class="integer">1</span>);
13792<span class="keyword">return</span> t * t * (<span class="integer">3</span> - <span class="integer">2</span> * t);</code></pre>
13793</div>
13794</div>
13795<div class="paragraph">
13796<p>(And similarly for doubles.) Results are undefined if <span class="eq">edge0 ≥
13797edge1</span>.</p>
13798</div>
13799</div>
13800</div></div></td>
13801</tr>
13802<tr>
13803<td class="tableblock halign-left valign-top"><p class="tableblock">genBType <strong>isnan</strong>(genFType <em>x</em>)<br>
13804  genBType <strong>isnan</strong>(genDType <em>x</em>)</p></td>
13805<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <strong>true</strong> if <em>x</em> holds a NaN.
13806      Returns <strong>false</strong> otherwise.
13807      Always returns <strong>false</strong> if NaNs are not implemented.</p></td>
13808</tr>
13809<tr>
13810<td class="tableblock halign-left valign-top"><p class="tableblock">genBType <strong>isinf</strong>(genFType <em>x</em>)<br>
13811  genBType <strong>isinf</strong>(genDType <em>x</em>)</p></td>
13812<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <strong>true</strong> if <em>x</em> holds a positive infinity or negative infinity.
13813      Returns <strong>false</strong> otherwise.</p></td>
13814</tr>
13815<tr>
13816<td class="tableblock halign-left valign-top"><p class="tableblock">genIType <strong>floatBitsToInt</strong>(highp genFType <em>value</em>)<br>
13817  genUType <strong>floatBitsToUint</strong>(highp genFType <em>value</em>)</p></td>
13818<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a signed or unsigned integer value representing the encoding
13819      of a floating-point value.
13820      The <strong>float</strong> value&#8217;s bit-level representation is preserved.</p></td>
13821</tr>
13822<tr>
13823<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>intBitsToFloat</strong>(highp genIType <em>value</em>)<br>
13824  genFType <strong>uintBitsToFloat</strong>(highp genUType <em>value</em>)</p></td>
13825<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a floating-point value corresponding to a signed or unsigned
13826      integer encoding of a floating-point value.
13827      If a NaN is passed in, it will not signal, and the resulting value is
13828      unspecified.
13829      If an Inf is passed in, the resulting value is the corresponding Inf.
13830      Otherwise, the bit-level representation is preserved.</p></td>
13831</tr>
13832<tr>
13833<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>fma</strong>(genFType <em>a</em>, genFType <em>b</em>, genFType <em>c</em>)<br>
13834  genDType <strong>fma</strong>(genDType <em>a</em>, genDType <em>b</em>, genDType <em>c</em>)</p></td>
13835<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
13836<p>Computes and returns <code>a * b + c</code>.
13837      In uses where the return value is eventually consumed by a variable
13838      declared as <strong>precise</strong>:</p>
13839</div>
13840<div class="openblock">
13841<div class="content">
13842<div class="ulist">
13843<ul>
13844<li>
13845<p><strong>fma</strong>() is considered a single operation, whereas the expression <code>a * b
13846+ c</code> consumed by a variable declared <strong>precise</strong> is considered two
13847operations.</p>
13848</li>
13849<li>
13850<p>The precision of <strong>fma</strong>() can differ from the precision of the expression
13851<code>a * b + c</code>.</p>
13852</li>
13853<li>
13854<p><strong>fma</strong>() will be computed with the same precision as any other <strong>fma</strong>()
13855consumed by a precise variable, giving invariant results for the same
13856input values of <em>a</em>, <em>b</em>, and <em>c</em>.</p>
13857</li>
13858</ul>
13859</div>
13860<div class="paragraph">
13861<p>Otherwise, in the absence of <strong>precise</strong> consumption, there are no special
13862constraints on the number of operations or difference in precision between
13863<strong>fma</strong>() and the expression <code>a * b + c</code>.</p>
13864</div>
13865</div>
13866</div></div></td>
13867</tr>
13868<tr>
13869<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>frexp</strong>(highp genFType <em>x</em>, out highp genIType <em>exp</em>)
13870  genDType <strong>frexp</strong>(genDType <em>x</em>, out genIType <em>exp</em>)<br></p></td>
13871<td class="tableblock halign-left valign-top"><p class="tableblock">Splits <em>x</em> into a floating-point significand in the range
13872      <span class="eq">[0.5,1.0]</span>, and an integral exponent of two, such that</p>
13873<p class="tableblock">      <span class="eq">x = significant · 2<sup>exponent</sup></span></p>
13874<p class="tableblock">      The significand is returned by the function and the exponent is
13875      returned in the parameter <em>exp</em>.
13876      For a floating-point value of zero, the significand and exponent are
13877      both zero.</p>
13878<p class="tableblock">      If an implementation supports signed zero, an input value of minus
13879      zero should return a significand of minus zero.
13880      For a floating-point value that is an infinity or is not a number, the
13881      results are undefined.</p>
13882<p class="tableblock">      If the input <em>x</em> is a vector, this operation is performed in a
13883      component-wise manner; the value returned by the function and the
13884      value written to <em>exp</em> are vectors with the same number of components
13885      as <em>x</em>.</p></td>
13886</tr>
13887<tr>
13888<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>ldexp</strong>(highp genFType <em>x</em>, highp genIType <em>exp</em>)<br>
13889  genDType <strong>ldexp</strong>(genDType <em>x</em>, genIType <em>exp</em>)</p></td>
13890<td class="tableblock halign-left valign-top"><p class="tableblock">Builds a floating-point number from <em>x</em> and the corresponding integral
13891      exponent of two in <em>exp</em>, returning:</p>
13892<p class="tableblock">      <span class="eq">significand · 2<sup>exponent</sup></span></p>
13893<p class="tableblock">      If this product is too large to be represented in the floating-point
13894      type, the result is undefined.</p>
13895<p class="tableblock">      If <em>exp</em> is greater than +128 (single-precision) or +1024
13896      (double-precision), the value returned is undefined.
13897      If <em>exp</em> is less than -126 (single-precision) or -1022
13898      (double-precision), the value returned may be flushed to zero.
13899      Additionally, splitting the value into a significand and exponent
13900      using <strong>frexp</strong>() and then reconstructing a floating-point value using
13901      <strong>ldexp</strong>() should yield the original input for zero and all finite
13902      non-denormalized values.<br>
13903      If the input <em>x</em> is a vector, this operation is performed in a
13904      component-wise manner; the value passed in <em>exp</em> and returned by the
13905      function are vectors with the same number of components as <em>x</em>.</p></td>
13906</tr>
13907</tbody>
13908</table>
13909</div>
13910<div class="sect2">
13911<h3 id="floating-point-pack-and-unpack-functions">8.4. Floating-Point Pack and Unpack Functions</h3>
13912<div class="paragraph">
13913<p>These functions do not operate component-wise, rather, as described in each
13914case.</p>
13915</div>
13916<table class="tableblock frame-all grid-all stretch">
13917<colgroup>
13918<col style="width: 50%;">
13919<col style="width: 50%;">
13920</colgroup>
13921<thead>
13922<tr>
13923<th class="tableblock halign-left valign-top">Syntax</th>
13924<th class="tableblock halign-left valign-top">Description</th>
13925</tr>
13926</thead>
13927<tbody>
13928<tr>
13929<td class="tableblock halign-left valign-top"><p class="tableblock">highp uint <strong>packUnorm2x16</strong>(vec2 <em>v</em>)<br>
13930  highp uint <strong>packSnorm2x16</strong>(vec2 <em>v</em>)<br>
13931   uint <strong>packUnorm4x8</strong>(vec4 <em>v</em>)<br>
13932   uint <strong>packSnorm4x8</strong>(vec4 <em>v</em>)</p></td>
13933<td class="tableblock halign-left valign-top"><p class="tableblock">First, converts each component of the normalized floating-point value
13934      <em>v</em> into 16-bit (<strong>2x16</strong>) or 8-bit (<strong>4x8</strong>) integer values.
13935      Then, the results are packed into the returned 32-bit unsigned
13936      integer.</p>
13937<p class="tableblock">      The conversion for component <em>c</em> of <em>v</em> to fixed point is done as
13938      follows:</p>
13939<p class="tableblock">      <strong>packUnorm2x16</strong>: <strong>round</strong>(<strong>clamp</strong>(<em>c</em>, 0, +1) * 65535.0)<br>
13940      <strong>packSnorm2x16:</strong> <strong>round</strong>(<strong>clamp</strong>(<em>c</em>, -1, +1) * 32767.0)<br>
13941      <strong>packUnorm4x8</strong>: <strong>round</strong>(<strong>clamp</strong>(<em>c</em>, 0, +1) * 255.0)<br>
13942      <strong>packSnorm4x8</strong>: <strong>round</strong>(<strong>clamp</strong>(<em>c</em>, -1, +1) * 127.0)</p>
13943<p class="tableblock">      The first component of the vector will be written to the least
13944      significant bits of the output; the last component will be written to
13945      the most significant bits.</p></td>
13946</tr>
13947<tr>
13948<td class="tableblock halign-left valign-top"><p class="tableblock"> vec2 <strong>unpackUnorm2x16</strong>(highp uint <em>p</em>)<br>
13949   vec2 <strong>unpackSnorm2x16</strong>(highp uint <em>p</em>)<br>
13950   vec4 <strong>unpackUnorm4x8</strong>(highp uint <em>p</em>)<br>
13951   vec4 <strong>unpackSnorm4x8</strong>(highp uint <em>p</em>)</p></td>
13952<td class="tableblock halign-left valign-top"><p class="tableblock">First, unpacks a single 32-bit unsigned integer <em>p</em> into a pair of
13953      16-bit unsigned integers, a pair of 16-bit signed integers, four 8-bit
13954      unsigned integers, or four 8-bit signed integers, respectively.
13955      Then, each component is converted to a normalized floating-point value
13956      to generate the returned two- or four-component vector.</p>
13957<p class="tableblock">      The conversion for unpacked fixed-point value <em>f</em> to floating-point is
13958      done as follows:</p>
13959<p class="tableblock">      <strong>unpackUnorm2x16</strong>: <em>f</em> / 65535.0<br>
13960      <strong>unpackSnorm2x16</strong>: <strong>clamp</strong>(<em>f</em> / 32767.0, -1, +1)<br>
13961      <strong>unpackUnorm4x8</strong>: <em>f</em> / 255.0<br>
13962      <strong>unpackSnorm4x8</strong>: <strong>clamp</strong>(<em>f</em> / 127.0, -1, +1)</p>
13963<p class="tableblock">      The first component of the returned vector will be extracted from the
13964      least significant bits of the input; the last component will be
13965      extracted from the most significant bits.</p></td>
13966</tr>
13967<tr>
13968<td class="tableblock halign-left valign-top"><p class="tableblock"> uint <strong>packHalf2x16</strong>(vec2 <em>v</em>)</p></td>
13969<td class="tableblock halign-left valign-top"><p class="tableblock">Returns an unsigned integer obtained by converting the components of a
13970      two-component floating-point vector to the 16-bit floating-point
13971      representation of the <a href="#references">API</a>, and
13972      then packing these two 16-bit integers into a 32-bit unsigned integer.</p>
13973<p class="tableblock">      The first vector component specifies the 16 least-significant bits of
13974      the result; the second component specifies the 16 most-significant
13975      bits.</p></td>
13976</tr>
13977<tr>
13978<td class="tableblock halign-left valign-top"><p class="tableblock"> vec2 <strong>unpackHalf2x16</strong>( uint <em>v</em>)</p></td>
13979<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a two-component floating-point vector with components obtained
13980      by unpacking a 32-bit unsigned integer into a pair of 16-bit values,
13981      interpreting those values as 16-bit floating-point numbers according
13982      to the <a href="#references">API</a>, and converting them to
13983      32-bit floating-point values.</p>
13984<p class="tableblock">      The first component of the vector is obtained from the 16
13985      least-significant bits of <em>v</em>; the second component is obtained from
13986      the 16 most-significant bits of <em>v</em>.</p></td>
13987</tr>
13988<tr>
13989<td class="tableblock halign-left valign-top"><p class="tableblock">double <strong>packDouble2x32</strong>(uvec2 <em>v</em>)<br></p></td>
13990<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a double-precision value obtained by packing the components of
13991      <em>v</em> into a 64-bit value.
13992      If an IEEE 754 Inf or NaN is created, it will not signal, and the
13993      resulting floating-point value is unspecified.
13994      Otherwise, the bit-level representation of <em>v</em> is preserved.
13995      The first vector component specifies the 32 least significant bits;
13996      the second component specifies the 32 most significant bits.</p></td>
13997</tr>
13998<tr>
13999<td class="tableblock halign-left valign-top"><p class="tableblock">uvec2 <strong>unpackDouble2x32</strong>(double <em>v</em>)</p></td>
14000<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a two-component unsigned integer vector representation of <em>v</em>.
14001      The bit-level representation of <em>v</em> is preserved.
14002      The first component of the vector contains the 32 least significant
14003      bits of the double; the second component consists of the 32 most
14004      significant bits.</p></td>
14005</tr>
14006</tbody>
14007</table>
14008</div>
14009<div class="sect2">
14010<h3 id="geometric-functions">8.5. Geometric Functions</h3>
14011<div class="paragraph">
14012<p>These operate on vectors as vectors, not component-wise.</p>
14013</div>
14014<table class="tableblock frame-all grid-all stretch">
14015<colgroup>
14016<col style="width: 50%;">
14017<col style="width: 50%;">
14018</colgroup>
14019<thead>
14020<tr>
14021<th class="tableblock halign-left valign-top">Syntax</th>
14022<th class="tableblock halign-left valign-top">Description</th>
14023</tr>
14024</thead>
14025<tbody>
14026<tr>
14027<td class="tableblock halign-left valign-top"><p class="tableblock">float <strong>length</strong>(genFType <em>x</em>)<br>
14028  double <strong>length</strong>(genDType <em>x</em>)</p></td>
14029<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
14030<p>Returns the length of vector <em>x</em>, i.e.,
14031      <span class="eq">sqrt( x<sub>0</sub><sup>2</sup> + x<sub>1</sub><sup>2</sup> + &#8230;&#8203; )</span>.</p>
14032</div></div></td>
14033</tr>
14034<tr>
14035<td class="tableblock halign-left valign-top"><p class="tableblock">float <strong>distance</strong>(genFType <em>p0</em>, genFType <em>p1</em>)<br>
14036  double <strong>distance</strong>(genDType <em>p0</em>, genDType <em>p1</em>)</p></td>
14037<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the distance between <em>p0</em> and <em>p1</em>, i.e.,
14038      <strong>length</strong>(<em>p0</em> - <em>p1</em>)</p></td>
14039</tr>
14040<tr>
14041<td class="tableblock halign-left valign-top"><p class="tableblock">float <strong>dot</strong>(genFType <em>x</em>, genFType <em>y</em>)<br>
14042  double <strong>dot</strong>(genDType <em>x</em>, genDType <em>y</em>)</p></td>
14043<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the dot product of <em>x</em> and <em>y</em>, i.e.,
14044      <span class="eq">x<sub>0</sub> · y<sub>0</sub> + x<sub>1</sub> · y<sub>1</sub> + &#8230;&#8203;</span></p></td>
14045</tr>
14046<tr>
14047<td class="tableblock halign-left valign-top"><p class="tableblock">vec3 <strong>cross</strong>(vec3 <em>x</em>, vec3 <em>y</em>)<br>
14048  dvec3 <strong>cross</strong>(dvec3 <em>x</em>, dvec3 <em>y</em>)</p></td>
14049<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
14050<p>Returns the cross product of <em>x</em> and <em>y</em>, i.e.,
14051      <span class="eq">(x<sub>1</sub> · y<sub>2</sub> - y<sub>1</sub> · x<sub>2</sub>,
14052            x<sub>2</sub> · y<sub>0</sub> - y<sub>2</sub> · x<sub>0</sub>,
14053            x<sub>0</sub> · y<sub>1</sub> - y<sub>0</sub> · x<sub>1</sub>)</span>.</p>
14054</div></div></td>
14055</tr>
14056<tr>
14057<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>normalize</strong>(genFType <em>x</em>)<br>
14058  genDType <strong>normalize</strong>(genDType <em>x</em>)</p></td>
14059<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a vector in the same direction as <em>x</em> but with a length of 1,
14060      i.e. <em>x</em> / <strong>length</strong>(x).</p></td>
14061</tr>
14062<tr>
14063<td class="tableblock halign-left valign-top"><p class="tableblock">compatibility profile only<br>
14064  vec4 <strong>ftransform</strong>()</p></td>
14065<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
14066<p>Available only when using the compatibility profile.
14067      For core OpenGL, use <strong>invariant</strong>.<br>
14068      For vertex shaders only.
14069      This function will ensure that the incoming vertex value will be
14070      transformed in a way that produces exactly the same result as would be
14071      produced by OpenGL&#8217;s fixed functionality transform.
14072      It is intended to be used to compute <em>gl_Position</em>, e.g.</p>
14073</div>
14074<div class="openblock">
14075<div class="content">
14076<div class="dlist">
14077<dl>
14078<dt class="hdlist1"></dt>
14079<dd>
14080<p><em>gl_Position</em> = <strong>ftransform</strong>()</p>
14081</dd>
14082</dl>
14083</div>
14084<div class="paragraph">
14085<p>This function should be used, for example, when an application is rendering
14086the same geometry in separate passes, and one pass uses the fixed
14087functionality path to render and another pass uses programmable shaders.</p>
14088</div>
14089</div>
14090</div></div></td>
14091</tr>
14092<tr>
14093<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>faceforward</strong>(genFType <em>N</em>, genFType <em>I</em>, genFType <em>Nref</em>)<br>
14094  genDType <strong>faceforward</strong>(genDType <em>N</em>, genDType <em>I</em>, genDType <em>Nref</em>)</p></td>
14095<td class="tableblock halign-left valign-top"><p class="tableblock">If <strong>dot</strong>(<em>Nref</em>, <em>I</em>) &lt; 0 return <em>N</em>, otherwise return -<em>N</em>.</p></td>
14096</tr>
14097<tr>
14098<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>reflect</strong>(genFType <em>I</em>, genFType <em>N</em>)<br>
14099  genDType <strong>reflect</strong>(genDType <em>I</em>, genDType <em>N</em>)</p></td>
14100<td class="tableblock halign-left valign-top"><p class="tableblock">For the incident vector <em>I</em> and surface orientation <em>N</em>, returns the
14101      reflection direction: <span class="eq">I - 2 · <strong>dot</strong>(N, I) · N</span>.
14102      <em>N</em> must already be normalized in order to achieve the desired result.</p></td>
14103</tr>
14104<tr>
14105<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>refract</strong>(genFType <em>I</em>, genFType <em>N</em>, float <em>eta</em>)<br>
14106  genDType <strong>refract</strong>(genDType <em>I</em>, genDType <em>N</em>, double <em>eta</em>)</p></td>
14107<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
14108<p>For the incident vector <em>I</em> and surface normal <em>N</em>, and the ratio of
14109      indices of refraction <em>eta</em>, return the refraction vector.
14110      The result is computed by the <a href="#refraction-equation">refraction
14111      equation</a> shown below.</p>
14112</div>
14113<div class="literalblock">
14114<div class="content">
14115<pre>The input parameters for the incident vector _I_ and the surface
14116normal _N_ must already be normalized to get the desired results.</pre>
14117</div>
14118</div></div></td>
14119</tr>
14120</tbody>
14121</table>
14122<div class="sect3">
14123<h4 id="refraction-equation">8.5.1. Refraction Equation</h4>
14124<div class="stemblock">
14125<div class="content">
14126\[k = 1.0 - eta * eta * (1.0 - \textbf{dot}(N,I) \cdot \textbf{dot}(N,I))\]
14127</div>
14128</div>
14129<div class="stemblock">
14130<div class="content">
14131\[\begin{aligned}
14132result &amp;=
14133  \begin{cases}
14134    genFType(0.0), &amp; k &lt; 0.0 \\
14135    eta * I - (eta * \textbf{dot}(N,I) + \sqrt { k }) * N, &amp; \textbf{otherwise}
14136  \end{cases}
14137\end{aligned}\]
14138</div>
14139</div>
14140</div>
14141</div>
14142<div class="sect2">
14143<h3 id="matrix-functions">8.6. Matrix Functions</h3>
14144<div class="paragraph">
14145<p>For each of the following built-in matrix functions, there is both a
14146single-precision floating-point version, where all arguments and return
14147values are single precision, and a double-precision floating-point version,
14148where all arguments and return values are double precision.
14149Only the single-precision floating-point version is shown.</p>
14150</div>
14151<table class="tableblock frame-all grid-all stretch">
14152<colgroup>
14153<col style="width: 50%;">
14154<col style="width: 50%;">
14155</colgroup>
14156<thead>
14157<tr>
14158<th class="tableblock halign-left valign-top">Syntax</th>
14159<th class="tableblock halign-left valign-top">Description</th>
14160</tr>
14161</thead>
14162<tbody>
14163<tr>
14164<td class="tableblock halign-left valign-top"><p class="tableblock">mat <strong>matrixCompMult</strong>(mat <em>x</em>, mat <em>y</em>)</p></td>
14165<td class="tableblock halign-left valign-top"><p class="tableblock">Multiply matrix <em>x</em> by matrix <em>y</em> component-wise, i.e., result[i][j]
14166      is the scalar product of <em>x</em>[i][j] and <em>y</em>[i][j].<br></p>
14167<p class="tableblock">      Note: to get linear algebraic matrix multiplication, use the multiply
14168      operator (<strong>*</strong>).</p></td>
14169</tr>
14170<tr>
14171<td class="tableblock halign-left valign-top"><p class="tableblock">mat2 <strong>outerProduct</strong>(vec2 <em>c</em>, vec2 <em>r</em>)<br>
14172  mat3 <strong>outerProduct</strong>(vec3 <em>c</em>, vec3 <em>r</em>)<br>
14173  mat4 <strong>outerProduct</strong>(vec4 <em>c</em>, vec4 <em>r</em>)<br>
14174  mat2x3 <strong>outerProduct</strong>(vec3 <em>c</em>, vec2 <em>r</em>)<br>
14175  mat3x2 <strong>outerProduct</strong>(vec2 <em>c</em>, vec3 <em>r</em>)<br>
14176  mat2x4 <strong>outerProduct</strong>(vec4 <em>c</em>, vec2 <em>r</em>)<br>
14177  mat4x2 <strong>outerProduct</strong>(vec2 <em>c</em>, vec4 <em>r</em>)<br>
14178  mat3x4 <strong>outerProduct</strong>(vec4 <em>c</em>, vec3 <em>r</em>)<br>
14179  mat4x3 <strong>outerProduct</strong>(vec3 <em>c</em>, vec4 <em>r</em>)</p></td>
14180<td class="tableblock halign-left valign-top"><p class="tableblock">Treats the first parameter <em>c</em> as a column vector (matrix with one
14181      column) and the second parameter <em>r</em> as a row vector (matrix with one
14182      row) and does a linear algebraic matrix multiply <em>c</em> * <em>r</em>, yielding a
14183      matrix whose number of rows is the number of components in <em>c</em> and
14184      whose number of columns is the number of components in <em>r</em>.</p></td>
14185</tr>
14186<tr>
14187<td class="tableblock halign-left valign-top"><p class="tableblock">mat2 <strong>transpose</strong>(mat2 <em>m</em>)<br>
14188  mat3 <strong>transpose</strong>(mat3 <em>m</em>)<br>
14189  mat4 <strong>transpose</strong>(mat4 <em>m</em>)<br>
14190  mat2x3 <strong>transpose</strong>(mat3x2 <em>m</em>)<br>
14191  mat3x2 <strong>transpose</strong>(mat2x3 <em>m</em>)<br>
14192  mat2x4 <strong>transpose</strong>(mat4x2 <em>m</em>)<br>
14193  mat4x2 <strong>transpose</strong>(mat2x4 <em>m</em>)<br>
14194  mat3x4 <strong>transpose</strong>(mat4x3 <em>m</em>)<br>
14195  mat4x3 <strong>transpose</strong>(mat3x4 <em>m</em>)</p></td>
14196<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a matrix that is the transpose of <em>m</em>.
14197      The input matrix <em>m</em> is not modified.</p></td>
14198</tr>
14199<tr>
14200<td class="tableblock halign-left valign-top"><p class="tableblock">float <strong>determinant</strong>(mat2 <em>m</em>)<br>
14201  float <strong>determinant</strong>(mat3 <em>m</em>)<br>
14202  float <strong>determinant</strong>(mat4 <em>m</em>)</p></td>
14203<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the determinant of <em>m</em>.</p></td>
14204</tr>
14205<tr>
14206<td class="tableblock halign-left valign-top"><p class="tableblock">mat2 <strong>inverse</strong>(mat2 <em>m</em>)<br>
14207  mat3 <strong>inverse</strong>(mat3 <em>m</em>)<br>
14208  mat4 <strong>inverse</strong>(mat4 <em>m</em>)</p></td>
14209<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a matrix that is the inverse of <em>m</em>.
14210      The input matrix <em>m</em> is not modified.
14211      The values in the returned matrix are undefined if <em>m</em> is singular or
14212      poorly-conditioned (nearly singular).</p></td>
14213</tr>
14214</tbody>
14215</table>
14216</div>
14217<div class="sect2">
14218<h3 id="vector-relational-functions">8.7. Vector Relational Functions</h3>
14219<div class="paragraph">
14220<p>Relational and equality operators (<strong>&lt;</strong>, <strong>&lt;=</strong>, <strong>&gt;</strong>, <strong>&gt;=</strong>, <strong>==</strong>, <strong>!=</strong>) are
14221defined to operate on scalars and produce scalar Boolean results.
14222For vector results, use the following built-in functions.
14223Below, the following placeholders are used for the listed specific types:</p>
14224</div>
14225<table class="tableblock frame-all grid-all stretch">
14226<colgroup>
14227<col style="width: 50%;">
14228<col style="width: 50%;">
14229</colgroup>
14230<thead>
14231<tr>
14232<th class="tableblock halign-left valign-top">Placeholder</th>
14233<th class="tableblock halign-left valign-top">Specific Types Allowed</th>
14234</tr>
14235</thead>
14236<tbody>
14237<tr>
14238<td class="tableblock halign-left valign-top"><p class="tableblock">bvec</p></td>
14239<td class="tableblock halign-left valign-top"><p class="tableblock">bvec2, bvec3, bvec4</p></td>
14240</tr>
14241<tr>
14242<td class="tableblock halign-left valign-top"><p class="tableblock">ivec</p></td>
14243<td class="tableblock halign-left valign-top"><p class="tableblock">ivec2, ivec3, ivec4</p></td>
14244</tr>
14245<tr>
14246<td class="tableblock halign-left valign-top"><p class="tableblock">uvec</p></td>
14247<td class="tableblock halign-left valign-top"><p class="tableblock">uvec2, uvec3, uvec4</p></td>
14248</tr>
14249<tr>
14250<td class="tableblock halign-left valign-top"><p class="tableblock">vec</p></td>
14251<td class="tableblock halign-left valign-top"><p class="tableblock">vec2, vec3, vec4, dvec2, dvec3, dvec4</p></td>
14252</tr>
14253</tbody>
14254</table>
14255<div class="paragraph">
14256<p>In all cases, the sizes of all the input and return vectors for any
14257particular call must match.</p>
14258</div>
14259<table class="tableblock frame-all grid-all stretch">
14260<colgroup>
14261<col style="width: 50%;">
14262<col style="width: 50%;">
14263</colgroup>
14264<thead>
14265<tr>
14266<th class="tableblock halign-left valign-top">Syntax</th>
14267<th class="tableblock halign-left valign-top">Description</th>
14268</tr>
14269</thead>
14270<tbody>
14271<tr>
14272<td class="tableblock halign-left valign-top"><p class="tableblock">bvec <strong>lessThan</strong>(vec x, vec y)<br>
14273  bvec <strong>lessThan</strong>(ivec x, ivec y)<br>
14274  bvec <strong>lessThan</strong>(uvec x, uvec y)</p></td>
14275<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the component-wise compare of <span class="eq">x &lt; y</span>.</p></td>
14276</tr>
14277<tr>
14278<td class="tableblock halign-left valign-top"><p class="tableblock">bvec <strong>lessThanEqual</strong>(vec x, vec y)<br>
14279  bvec <strong>lessThanEqual</strong>(ivec x, ivec y)<br>
14280  bvec <strong>lessThanEqual</strong>(uvec x, uvec y)</p></td>
14281<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the component-wise compare of <span class="eq">x ≤ y</span>.</p></td>
14282</tr>
14283<tr>
14284<td class="tableblock halign-left valign-top"><p class="tableblock">bvec <strong>greaterThan</strong>(vec x, vec y)<br>
14285  bvec <strong>greaterThan</strong>(ivec x, ivec y)<br>
14286  bvec <strong>greaterThan</strong>(uvec x, uvec y)</p></td>
14287<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the component-wise compare of <span class="eq">x &gt; y</span>.</p></td>
14288</tr>
14289<tr>
14290<td class="tableblock halign-left valign-top"><p class="tableblock">bvec <strong>greaterThanEqual</strong>(vec x, vec y)<br>
14291  bvec <strong>greaterThanEqual</strong>(ivec x, ivec y)<br>
14292  bvec <strong>greaterThanEqual</strong>(uvec x, uvec y)</p></td>
14293<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the component-wise compare of <span class="eq">x ≥ y</span>.</p></td>
14294</tr>
14295<tr>
14296<td class="tableblock halign-left valign-top"><p class="tableblock">bvec <strong>equal</strong>(vec x, vec y)<br>
14297  bvec <strong>equal</strong>(ivec x, ivec y)<br>
14298  bvec <strong>equal</strong>(uvec x, uvec y)<br>
14299  bvec <strong>equal</strong>(bvec x, bvec y)</p></td>
14300<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the component-wise compare of <span class="eq">x == y</span>.</p></td>
14301</tr>
14302<tr>
14303<td class="tableblock halign-left valign-top"><p class="tableblock">bvec <strong>notEqual</strong>(vec x, vec y)<br>
14304  bvec <strong>notEqual</strong>(ivec x, ivec y)<br>
14305  bvec <strong>notEqual</strong>(uvec x, uvec y)<br>
14306  bvec <strong>notEqual</strong>(bvec x, bvec y)</p></td>
14307<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the component-wise compare of <span class="eq">x ≠ y</span>.</p></td>
14308</tr>
14309<tr>
14310<td class="tableblock halign-left valign-top"><p class="tableblock">bool <strong>any</strong>(bvec x)</p></td>
14311<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <strong>true</strong> if any component of <em>x</em> is <strong>true</strong>.</p></td>
14312</tr>
14313<tr>
14314<td class="tableblock halign-left valign-top"><p class="tableblock">bool <strong>all</strong>(bvec x)</p></td>
14315<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <strong>true</strong> only if all components of <em>x</em> are <strong>true</strong>.</p></td>
14316</tr>
14317<tr>
14318<td class="tableblock halign-left valign-top"><p class="tableblock">bvec <strong>not</strong>(bvec x)</p></td>
14319<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the component-wise logical complement of <em>x</em>.</p></td>
14320</tr>
14321</tbody>
14322</table>
14323</div>
14324<div class="sect2">
14325<h3 id="integer-functions">8.8. Integer Functions</h3>
14326<div class="paragraph">
14327<p>These all operate component-wise.
14328The description is per component.
14329The notation [<em>a</em>, <em>b</em>] means the set of bits from bit-number <em>a</em> through
14330bit-number <em>b</em>, inclusive.
14331The lowest-order bit is bit 0.
14332&#8220;Bit number&#8221; will always refer to counting up from the lowest-order bit as
14333bit 0.</p>
14334</div>
14335<table class="tableblock frame-all grid-all stretch">
14336<colgroup>
14337<col style="width: 50%;">
14338<col style="width: 50%;">
14339</colgroup>
14340<thead>
14341<tr>
14342<th class="tableblock halign-left valign-top">Syntax</th>
14343<th class="tableblock halign-left valign-top">Description</th>
14344</tr>
14345</thead>
14346<tbody>
14347<tr>
14348<td class="tableblock halign-left valign-top"><p class="tableblock">genUType <strong>uaddCarry</strong>(highp genUType <em>x</em>, highp genUType <em>y</em>, out lowp genUType <em>carry</em>)</p></td>
14349<td class="tableblock halign-left valign-top"><p class="tableblock">Adds 32-bit unsigned integers <em>x</em> and <em>y</em>, returning the sum modulo
14350      2<sup>32</sup>.
14351      The value <em>carry</em> is set to zero if the sum was less than 2<sup>32</sup>, or
14352      one otherwise.</p></td>
14353</tr>
14354<tr>
14355<td class="tableblock halign-left valign-top"><p class="tableblock">genUType <strong>usubBorrow</strong>(highp genUType <em>x</em>, highp genUType <em>y</em>, out lowp genUType <em>borrow</em>)</p></td>
14356<td class="tableblock halign-left valign-top"><p class="tableblock">Subtracts the 32-bit unsigned integer <em>y</em> from <em>x</em>, returning the
14357      difference if non-negative, or 2<sup>32</sup> plus the difference otherwise.
14358      The value <em>borrow</em> is set to zero if <span class="eq">x ≥ y</span>, or one
14359      otherwise.</p></td>
14360</tr>
14361<tr>
14362<td class="tableblock halign-left valign-top"><p class="tableblock">void <strong>umulExtended</strong>(highp genUType <em>x</em>, highp genUType <em>y</em>, out highp genUType <em>msb</em>, out highp genUType <em>lsb</em>)<br>
14363  void <strong>imulExtended</strong>(highp genIType <em>x</em>, highp genIType <em>y</em>, out highp genIType <em>msb</em>, out highp genIType <em>lsb</em>)</p></td>
14364<td class="tableblock halign-left valign-top"><p class="tableblock">Multiplies 32-bit unsigned or signed integers <em>x</em> and <em>y</em>, producing a
14365      64-bit result.
14366      The 32 least-significant bits are returned in <em>lsb</em>.
14367      The 32 most-significant bits are returned in <em>msb</em>.</p></td>
14368</tr>
14369<tr>
14370<td class="tableblock halign-left valign-top"><p class="tableblock">genIType <strong>bitfieldExtract</strong>(genIType <em>value</em>, int <em>offset</em>, int <em>bits</em>)<br>
14371  genUType <strong>bitfieldExtract</strong>(genUType <em>value</em>, int <em>offset</em>, int <em>bits</em>)</p></td>
14372<td class="tableblock halign-left valign-top"><p class="tableblock">Extracts bits <span class="eq">[offset, offset + bits - 1]</span> from <em>value</em>,
14373      returning them in the least significant bits of the result.<br></p>
14374<p class="tableblock">      For unsigned data types, the most significant bits of the result will
14375      be set to zero.
14376      For signed data types, the most significant bits will be set to the
14377      value of bit <span class="eq">offset + bits - 1</span>.<br></p>
14378<p class="tableblock">      If <em>bits</em> is zero, the result will be zero.
14379      The result will be undefined if <em>offset</em> or <em>bits</em> is negative, or if
14380      the sum of <em>offset</em> and <em>bits</em> is greater than the number of bits used
14381      to store the operand.
14382      Note that for vector versions of <strong>bitfieldExtract</strong>(), a single pair of
14383      <em>offset</em> and <em>bits</em> values is shared for all components.</p></td>
14384</tr>
14385<tr>
14386<td class="tableblock halign-left valign-top"><p class="tableblock">genIType <strong>bitfieldInsert</strong>(genIType <em>base</em>, genIType <em>insert</em>, int <em>offset</em>, int <em>bits</em>)<br>
14387  genUType <strong>bitfieldInsert</strong>(genUType <em>base</em>, genUType <em>insert</em>, int <em>offset</em>, int <em>bits</em>)</p></td>
14388<td class="tableblock halign-left valign-top"><p class="tableblock">Inserts the <em>bits</em> least significant bits of <em>insert</em> into <em>base</em>.</p>
14389<p class="tableblock">      The result will have bits <span class="eq">[offset, offset + bits - 1]</span> taken from
14390      bits <span class="eq">[0, bits - 1]</span> of <em>insert</em>, and all other bits taken
14391      directly from the corresponding bits of <em>base</em>.
14392      If <em>bits</em> is zero, the result will simply be <em>base</em>.
14393      The result will be undefined if <em>offset</em> or <em>bits</em> is negative, or if
14394      the sum of <em>offset</em> and <em>bits</em> is greater than the number of bits used
14395      to store the operand.<br>
14396      Note that for vector versions of <strong>bitfieldInsert</strong>(), a single pair of
14397      <em>offset</em> and <em>bits</em> values is shared for all components.</p></td>
14398</tr>
14399<tr>
14400<td class="tableblock halign-left valign-top"><p class="tableblock">genIType <strong>bitfieldReverse</strong>(highp genIType <em>value</em>)<br>
14401  genUType <strong>bitfieldReverse</strong>(highp genUType <em>value</em>)</p></td>
14402<td class="tableblock halign-left valign-top"><p class="tableblock">Reverses the bits of <em>value</em>.
14403      The bit numbered <em>n</em> of the result will be taken from bit <span class="eq">(bits -
14404      1) - n</span> of <em>value</em>, where <em>bits</em> is the total number of bits used to
14405      represent <em>value</em>.</p></td>
14406</tr>
14407<tr>
14408<td class="tableblock halign-left valign-top"><p class="tableblock"> genIType <strong>bitCount</strong>(genIType <em>value</em>)<br>
14409   genIType <strong>bitCount</strong>(genUType <em>value</em>)</p></td>
14410<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the number of one bits in the binary representation of
14411      <em>value</em>.</p></td>
14412</tr>
14413<tr>
14414<td class="tableblock halign-left valign-top"><p class="tableblock"> genIType <strong>findLSB</strong>(genIType <em>value</em>)<br>
14415   genIType <strong>findLSB</strong>(genUType <em>value</em>)</p></td>
14416<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the bit number of the least significant one bit in the binary
14417      representation of <em>value</em>.
14418      If <em>value</em> is zero, -1 will be returned.</p></td>
14419</tr>
14420<tr>
14421<td class="tableblock halign-left valign-top"><p class="tableblock"> genIType <strong>findMSB</strong>(highp genIType <em>value</em>)<br>
14422   genIType <strong>findMSB</strong>(highp genUType <em>value</em>)</p></td>
14423<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the bit number of the most significant bit in the binary
14424      representation of <em>value</em>.</p>
14425<p class="tableblock">      For positive integers, the result will be the bit number of the most
14426      significant one bit.
14427      For negative integers, the result will be the bit number of the most
14428      significant zero bit.
14429      For a <em>value</em> of zero or negative one, -1 will be returned.</p></td>
14430</tr>
14431</tbody>
14432</table>
14433</div>
14434<div class="sect2">
14435<h3 id="texture-functions">8.9. Texture Functions</h3>
14436<div class="paragraph">
14437<p>Texture lookup functions are available in all shading stages.
14438However, level-of-detail is implicitly computed only for fragment shaders.
14439Other shaders operate as though the base level-of-detail were computed as
14440zero.
14441The functions in the table below provide access to textures through
14442texture-combined samplers, as set up through the API.
14443Texture properties such as size, pixel format, number of dimensions,
14444filtering method, number of mipmap levels, depth comparison, and so on are
14445also defined by API calls.
14446Such properties are taken into account as the texture is accessed via the
14447built-in functions defined below.</p>
14448</div>
14449<div class="paragraph">
14450<p>Texture data can be stored by the GL as single-precision floating-point,
14451unsigned normalized integer, unsigned integer or signed integer data.
14452This is determined by the type of the internal format of the texture.</p>
14453</div>
14454<div class="paragraph">
14455<p>Texture lookup functions are provided that can return their result as
14456floating-point, unsigned integer or signed integer, depending on the sampler
14457type passed to the lookup function.
14458Care must be taken to use the right sampler type for texture access.
14459The following table lists the supported combinations of sampler types and
14460texture internal formats.
14461Blank entries are unsupported.
14462Doing a texture lookup will return undefined values for unsupported
14463combinations.</p>
14464</div>
14465<div class="paragraph">
14466<p>For depth/stencil textures, the internal texture format is determined by the
14467component being accessed as set through the API.
14468When the depth/stencil texture mode is set to DEPTH_COMPONENT, the internal
14469format of the depth component should be used.
14470When the depth/stencil texture mode is set to STENCIL_INDEX, the internal format
14471of the stencil component should be used.</p>
14472</div>
14473<table class="tableblock frame-all grid-all stretch">
14474<colgroup>
14475<col style="width: 25%;">
14476<col style="width: 25%;">
14477<col style="width: 25%;">
14478<col style="width: 25%;">
14479</colgroup>
14480<thead>
14481<tr>
14482<th class="tableblock halign-left valign-top">Internal Texture Format</th>
14483<th class="tableblock halign-left valign-top">Floating-Point Sampler Types</th>
14484<th class="tableblock halign-left valign-top">Signed Integer Sampler Types</th>
14485<th class="tableblock halign-left valign-top">Unsigned Integer Sampler Types</th>
14486</tr>
14487</thead>
14488<tbody>
14489<tr>
14490<td class="tableblock halign-left valign-top"><p class="tableblock">Floating-point</p></td>
14491<td class="tableblock halign-left valign-top"><p class="tableblock">Supported</p></td>
14492<td class="tableblock halign-left valign-top"></td>
14493<td class="tableblock halign-left valign-top"></td>
14494</tr>
14495<tr>
14496<td class="tableblock halign-left valign-top"><p class="tableblock">Normalized Integer</p></td>
14497<td class="tableblock halign-left valign-top"><p class="tableblock">Supported</p></td>
14498<td class="tableblock halign-left valign-top"></td>
14499<td class="tableblock halign-left valign-top"></td>
14500</tr>
14501<tr>
14502<td class="tableblock halign-left valign-top"><p class="tableblock">Signed Integer</p></td>
14503<td class="tableblock halign-left valign-top"></td>
14504<td class="tableblock halign-left valign-top"><p class="tableblock">Supported</p></td>
14505<td class="tableblock halign-left valign-top"></td>
14506</tr>
14507<tr>
14508<td class="tableblock halign-left valign-top"><p class="tableblock">Unsigned Integer</p></td>
14509<td class="tableblock halign-left valign-top"></td>
14510<td class="tableblock halign-left valign-top"></td>
14511<td class="tableblock halign-left valign-top"><p class="tableblock">Supported</p></td>
14512</tr>
14513</tbody>
14514</table>
14515<div class="paragraph">
14516<p>If an integer sampler type is used, the result of a texture lookup is an
14517<strong>ivec4</strong>.
14518If an unsigned integer sampler type is used, the result of a texture lookup
14519is a <strong>uvec4</strong>.
14520If a floating-point sampler type is used, the result of a texture lookup is
14521a <strong>vec4</strong>.</p>
14522</div>
14523<div class="paragraph">
14524<p>In the prototypes below, the <code>g</code> in the return type <code>gvec4</code> is used
14525as a placeholder for either nothing, <code>i</code>, or <code>u</code> making a return type of
14526<strong>vec4</strong>, <strong>ivec4</strong>, or <strong>uvec4</strong>.
14527In these cases, the sampler argument type also starts with <code>g</code>,
14528indicating the same substitution done on the return type; it is either a
14529single-precision
14530floating-point, signed integer, or unsigned integer sampler, matching the
14531basic type of the return type, as described above.</p>
14532</div>
14533<div class="paragraph">
14534<p>For shadow forms (the sampler parameter is a shadow-type), a depth
14535comparison lookup on the depth texture bound to <em>sampler</em> is done as
14536described in section
145378.23
14538&#8220;Texture Comparison Modes&#8221; of the
14539<a href="#references">OpenGL Specification</a>.
14540See the table below for which component specifies <em>D<sub>ref</sub></em>.
14541The texture bound to <em>sampler</em> must be a depth texture, or results are
14542undefined.
14543If a non-shadow texture call is made to a sampler that represents a depth
14544texture with depth comparisons turned on, then results are undefined.
14545If a shadow texture call is made to a sampler that represents a depth
14546texture with depth comparisons turned off, then results are undefined.
14547If a shadow texture call is made to a sampler that does not represent a
14548depth texture, then results are undefined.</p>
14549</div>
14550<div class="paragraph">
14551<p>In all functions below, the <em>bias</em> parameter is optional for fragment
14552shaders.
14553The <em>bias</em> parameter is not accepted in any other shader stage.
14554For a fragment shader, if <em>bias</em> is present, it is added to the implicit
14555level-of-detail prior to performing the texture access operation.
14556No <em>bias</em> or <em>lod</em> parameters for
14557rectangle textures,
14558multisample textures, or texture buffers
14559are supported because mipmaps are not allowed for these types of textures.</p>
14560</div>
14561<div class="paragraph">
14562<p>The implicit level-of-detail is selected as follows: For a texture that is
14563not mipmapped, the texture is used directly.
14564If it is mipmapped and running in a fragment shader, the level-of-detail
14565computed by the implementation is used to do the texture lookup.
14566If it is mipmapped and running in a non-fragment shader, then the base
14567texture is used.</p>
14568</div>
14569<div class="paragraph">
14570<p>Some texture functions (non-&#8220;<strong>Lod</strong>&#8221; and non-&#8220;<strong>Grad</strong>&#8221; versions) may
14571require implicit derivatives.
14572Implicit derivatives are undefined within non-uniform control flow and for
14573non-fragment shader texture fetches.</p>
14574</div>
14575<div class="paragraph">
14576<p>For <strong>Cube</strong> forms, the direction of <em>P</em> is used to select which face to do a
145772-dimensional texture lookup in, as described in section 8.13 &#8220;Cube Map
14578Texture Selection&#8221; of the <a href="#references">OpenGL Specification</a>.</p>
14579</div>
14580<div class="paragraph">
14581<p>For <strong>Array</strong> forms, the array layer used will be</p>
14582</div>
14583<div class="paragraph">
14584<p>\(\max(0,\min(d-1,\left\lfloor layer + 0.5\right\rfloor))\)</p>
14585</div>
14586<div class="paragraph">
14587<p>where <em>d</em> is the depth of the texture array and <em>layer</em> comes from the
14588component indicated in the tables below.</p>
14589</div>
14590<div class="sect3">
14591<h4 id="texture-query-functions">8.9.1. Texture Query Functions</h4>
14592<div class="paragraph">
14593<p>The <strong>textureSize</strong> functions query the dimensions of a specific texture level
14594for a texture-combined sampler.</p>
14595</div>
14596<div class="paragraph">
14597<p>The <strong>textureQueryLod</strong> functions are available only in a fragment shader.
14598They take the components of <em>P</em> and compute the level-of-detail information
14599that the texture pipe would use to access that texture through a normal
14600texture lookup.
14601The level-of-detail \(\lambda^{'}\) (equation 3.18 of the
14602<a href="#references">OpenGL Specification</a>) is obtained after any level-of-detail bias, but
14603prior to clamping to [TEXTURE_MIN_LOD, TEXTURE_MAX_LOD].
14604The mipmap array(s) that would be accessed are also computed.
14605If a single level-of-detail would be accessed, the level-of-detail number
14606relative to the base level is returned.
14607If multiple levels-of-detail would be accessed, a floating-point number
14608between the two levels is returned, with the fractional part equal to the
14609fractional part of the computed and clamped level-of-detail.</p>
14610</div>
14611<div class="paragraph">
14612<p>The algorithm used is given by the following pseudo-code:</p>
14613</div>
14614<div class="listingblock">
14615<div class="content">
14616<pre class="CodeRay highlight"><code data-lang="c++"><span class="predefined-type">float</span> ComputeAccessedLod(<span class="predefined-type">float</span> computedLod)
14617{
14618    <span class="comment">// Clamp the computed LOD according to the texture LOD clamps.</span>
14619    <span class="keyword">if</span> (computedLod &lt; TEXTURE_MIN_LOD) computedLod = TEXTURE_MIN_LOD;
14620    <span class="keyword">if</span> (computedLod &gt; TEXTURE_MAX_LOD) computedLod = TEXTURE_MAX_LOD;
14621
14622    <span class="comment">// Clamp the computed LOD to the range of accessible levels.</span>
14623    <span class="keyword">if</span> (computedLod &lt; <span class="float">0</span><span class="float">.0</span>)
14624        computedLod = <span class="float">0</span><span class="float">.0</span>;
14625    <span class="keyword">if</span> (computedLod &gt; (<span class="predefined-type">float</span>) maxAccessibleLevel)
14626        computedLod = (<span class="predefined-type">float</span>) maxAccessibleLevel;
14627
14628    <span class="comment">// Return a value according to the min filter.</span>
14629    <span class="keyword">if</span> (TEXTURE_MIN_FILTER is LINEAR <span class="keyword">or</span> NEAREST) {
14630        <span class="keyword">return</span> <span class="float">0</span><span class="float">.0</span>;
14631    } <span class="keyword">else</span> <span class="keyword">if</span> (TEXTURE_MIN_FILTER is NEAREST_MIPMAP_NEAREST
14632               <span class="keyword">or</span> LINEAR_MIPMAP_NEAREST) {
14633        <span class="keyword">return</span> ceil(computedLod + <span class="float">0</span><span class="float">.5</span>) - <span class="float">1</span><span class="float">.0</span>;
14634    } <span class="keyword">else</span> {
14635        <span class="keyword">return</span> computedLod;
14636    }
14637}</code></pre>
14638</div>
14639</div>
14640<div class="paragraph">
14641<p>The value <em>maxAccessibleLevel</em> is the level number of the smallest
14642accessible level of the mipmap array (the value <em>q</em> in section 8.14.3
14643&#8220;Mipmapping&#8221; of the <a href="#references">OpenGL Specification</a>) minus the base level.</p>
14644</div>
14645<table class="tableblock frame-all grid-all stretch">
14646<colgroup>
14647<col style="width: 50%;">
14648<col style="width: 50%;">
14649</colgroup>
14650<thead>
14651<tr>
14652<th class="tableblock halign-left valign-top">Syntax</th>
14653<th class="tableblock halign-left valign-top">Description</th>
14654</tr>
14655</thead>
14656<tbody>
14657<tr>
14658<td class="tableblock halign-left valign-top"><p class="tableblock"> int <strong>textureSize</strong>(gsampler1D <em>sampler</em>, int <em>lod</em>)<br>
14659   ivec2 <strong>textureSize</strong>(gsampler2D <em>sampler</em>, int <em>lod</em>)<br>
14660   ivec3 <strong>textureSize</strong>(gsampler3D <em>sampler</em>, int <em>lod</em>)<br>
14661   ivec2 <strong>textureSize</strong>(gsamplerCube <em>sampler</em>, int <em>lod</em>)<br>
14662   int <strong>textureSize</strong>(sampler1DShadow <em>sampler</em>, int <em>lod</em>)<br>
14663   ivec2 <strong>textureSize</strong>(sampler2DShadow <em>sampler</em>, int <em>lod</em>)<br>
14664   ivec2 <strong>textureSize</strong>(samplerCubeShadow <em>sampler</em>, int <em>lod</em>)
14665   ivec3 <strong>textureSize</strong>(gsamplerCubeArray <em>sampler</em>, int <em>lod</em>)<br>
14666   ivec3 <strong>textureSize</strong>(samplerCubeArrayShadow <em>sampler</em>, int <em>lod</em>)<br>
14667   ivec2 <strong>textureSize</strong>(gsampler2DRect <em>sampler</em>)<br>
14668   ivec2 <strong>textureSize</strong>(sampler2DRectShadow <em>sampler</em>)<br>
14669   ivec2 <strong>textureSize</strong>(gsampler1DArray <em>sampler</em>, int <em>lod</em>)<br>
14670   ivec2 <strong>textureSize</strong>(sampler1DArrayShadow <em>sampler</em>, int <em>lod</em>)<br>
14671   ivec3 <strong>textureSize</strong>(gsampler2DArray <em>sampler</em>, int <em>lod</em>)<br>
14672   ivec3 <strong>textureSize</strong>(sampler2DArrayShadow <em>sampler</em>, int <em>lod</em>)<br>
14673   int <strong>textureSize</strong>(gsamplerBuffer <em>sampler</em>)<br>
14674   ivec2 <strong>textureSize</strong>(gsampler2DMS <em>sampler</em>)<br>
14675   ivec3 <strong>textureSize</strong>(gsampler2DMSArray <em>sampler</em>)</p></td>
14676<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the dimensions of level <em>lod</em> (if present) for the texture
14677      bound to <em>sampler</em>, as described in section
14678      8.11 &#8220;Texture Queries&#8221; of the <a href="#references">OpenGL Specification</a>.<br>
14679      The components in the return value are filled in, in order, with the
14680      width, height, and depth of the texture.</p>
14681<p class="tableblock">      For the array forms, the last component of the return value is the
14682      number of layers in the texture array, or the number of cubes in the
14683      texture cube map array.</p></td>
14684</tr>
14685<tr>
14686<td class="tableblock halign-left valign-top"><p class="tableblock">vec2 <strong>textureQueryLod</strong>(gsampler1D <em>sampler</em>, float <em>P</em>)<br>
14687  vec2 <strong>textureQueryLod</strong>(gsampler2D <em>sampler</em>, vec2 <em>P</em>)<br>
14688  vec2 <strong>textureQueryLod</strong>(gsampler3D <em>sampler</em>, vec3 <em>P</em>)<br>
14689  vec2 <strong>textureQueryLod</strong>(gsamplerCube <em>sampler</em>, vec3 <em>P</em>)<br>
14690  vec2 <strong>textureQueryLod</strong>(gsampler1DArray <em>sampler</em>, float <em>P</em>)<br>
14691  vec2 <strong>textureQueryLod</strong>(gsampler2DArray <em>sampler</em>, vec2 <em>P</em>)<br>
14692  vec2 <strong>textureQueryLod</strong>(gsamplerCubeArray <em>sampler</em>, vec3 <em>P</em>)<br>
14693  vec2 <strong>textureQueryLod</strong>(sampler1DShadow <em>sampler</em>, float <em>P</em>)<br>
14694  vec2 <strong>textureQueryLod</strong>(sampler2DShadow <em>sampler</em>, vec2 <em>P</em>)<br>
14695  vec2 <strong>textureQueryLod</strong>(samplerCubeShadow <em>sampler</em>, vec3 <em>P</em>)<br>
14696  vec2 <strong>textureQueryLod</strong>(sampler1DArrayShadow <em>sampler</em>, float <em>P</em>)<br>
14697  vec2 <strong>textureQueryLod</strong>(sampler2DArrayShadow <em>sampler</em>, vec2 <em>P</em>)<br>
14698  vec2 <strong>textureQueryLod</strong>(samplerCubeArrayShadow <em>sampler</em>, vec3 <em>P</em>)</p></td>
14699<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the mipmap array(s) that would be accessed in the <em>x</em>
14700      component of the return value.</p>
14701<p class="tableblock">      Returns the computed level-of-detail relative to the base level in the
14702      <em>y</em> component of the return value.</p>
14703<p class="tableblock">      If called on an incomplete texture, the results are undefined.</p></td>
14704</tr>
14705<tr>
14706<td class="tableblock halign-left valign-top"><p class="tableblock">int <strong>textureQueryLevels</strong>(gsampler1D <em>sampler</em>)<br>
14707  int <strong>textureQueryLevels</strong>(gsampler2D <em>sampler</em>)<br>
14708  int <strong>textureQueryLevels</strong>(gsampler3D <em>sampler</em>)<br>
14709  int <strong>textureQueryLevels</strong>(gsamplerCube <em>sampler</em>)<br>
14710  int <strong>textureQueryLevels</strong>(gsampler1DArray <em>sampler</em>)<br>
14711  int <strong>textureQueryLevels</strong>(gsampler2DArray <em>sampler</em>)<br>
14712  int <strong>textureQueryLevels</strong>(gsamplerCubeArray <em>sampler</em>)<br>
14713  int <strong>textureQueryLevels</strong>(sampler1DShadow <em>sampler</em>)<br>
14714  int <strong>textureQueryLevels</strong>(sampler2DShadow <em>sampler</em>)<br>
14715  int <strong>textureQueryLevels</strong>(samplerCubeShadow <em>sampler</em>)<br>
14716  int <strong>textureQueryLevels</strong>(sampler1DArrayShadow <em>sampler</em>)<br>
14717  int <strong>textureQueryLevels</strong>(sampler2DArrayShadow <em>sampler</em>)<br>
14718  int <strong>textureQueryLevels</strong>(samplerCubeArrayShadow <em>sampler</em>)</p></td>
14719<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the number of mipmap levels accessible in the texture
14720      associated with <em>sampler</em>, as defined in the <a href="#references">OpenGL Specification.</a></p>
14721<p class="tableblock">      The value zero will be returned if no texture or an incomplete texture
14722      is associated with <em>sampler</em>.</p>
14723<p class="tableblock">      Available in all shader stages.</p></td>
14724</tr>
14725<tr>
14726<td class="tableblock halign-left valign-top"><p class="tableblock">int <strong>textureSamples</strong>(gsampler2DMS <em>sampler</em>)<br>
14727  int <strong>textureSamples</strong>(gsampler2DMSArray <em>sampler</em>)</p></td>
14728<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the number of samples of the texture or textures bound to
14729      <em>sampler</em>.</p></td>
14730</tr>
14731</tbody>
14732</table>
14733</div>
14734<div class="sect3">
14735<h4 id="texel-lookup-functions">8.9.2. Texel Lookup Functions</h4>
14736<table class="tableblock frame-all grid-all stretch">
14737<colgroup>
14738<col style="width: 50%;">
14739<col style="width: 50%;">
14740</colgroup>
14741<thead>
14742<tr>
14743<th class="tableblock halign-left valign-top">Syntax</th>
14744<th class="tableblock halign-left valign-top">Description</th>
14745</tr>
14746</thead>
14747<tbody>
14748<tr>
14749<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>texture</strong>(gsampler1D <em>sampler</em>, float <em>P</em> [, float <em>bias</em>] )<br>
14750  gvec4 <strong>texture</strong>(gsampler2D <em>sampler</em>, vec2 <em>P</em> [, float <em>bias</em>] )<br>
14751  gvec4 <strong>texture</strong>(gsampler3D <em>sampler</em>, vec3 <em>P</em> [, float <em>bias</em>] )<br>
14752  gvec4 <strong>texture</strong>(gsamplerCube <em>sampler</em>, vec3 <em>P</em>[, float <em>bias</em>] )<br>
14753  float <strong>texture</strong>(sampler1DShadow <em>sampler</em>, vec3 <em>P</em> [, float <em>bias</em>])<br>
14754  float <strong>texture</strong>(sampler2DShadow <em>sampler</em>, vec3 <em>P</em> [, float <em>bias</em>])<br>
14755  float <strong>texture</strong>(samplerCubeShadow <em>sampler</em>, vec4 <em>P</em> [, float <em>bias</em>] )<br>
14756  gvec4 <strong>texture</strong>(gsampler2DArray <em>sampler</em>, vec3 <em>P</em> [, float <em>bias</em>] )<br>
14757  gvec4 <strong>texture</strong>(gsamplerCubeArray <em>sampler</em>, vec4 <em>P</em> [, float <em>bias</em>] )<br>
14758  gvec4 <strong>texture</strong>(gsampler1DArray <em>sampler</em>, vec2 <em>P</em> [, float <em>bias</em>] )<br>
14759  float <strong>texture</strong>(sampler1DArrayShadow <em>sampler</em>, vec3 <em>P</em> [, float <em>bias</em>] )<br>
14760  float <strong>texture</strong>(sampler2DArrayShadow <em>sampler</em>, vec4 <em>P</em>)<br>
14761  gvec4 <strong>texture</strong>(gsampler2DRect <em>sampler</em>, vec2 <em>P</em>)<br>
14762  float <strong>texture</strong>(sampler2DRectShadow <em>sampler</em>, vec3 <em>P</em>)<br>
14763  float <strong>texture</strong>(samplerCubeArrayShadow <em>sampler</em>, vec4 <em>P</em>, float <em>compare</em>)</p></td>
14764<td class="tableblock halign-left valign-top"><p class="tableblock">Use the texture coordinate <em>P</em> to do a texture lookup in the texture
14765      currently bound to <em>sampler</em>.</p>
14766<p class="tableblock">      For shadow forms: When <em>compare</em> is present, it is used as <em>D<sub>ref</sub></em>
14767      and the array layer comes from the last component of <em>P</em>.
14768      When <em>compare</em> is not present, the last component of <em>P</em> is used as
14769      <em>D<sub>ref</sub></em> and the array layer comes from the second to last component
14770      of <em>P</em>.
14771      (The second component of <em>P</em> is unused for <strong>1D</strong> shadow lookups.)</p>
14772<p class="tableblock">      For non-shadow forms: the array layer comes from the last component of
14773      <em>P</em>.</p></td>
14774</tr>
14775<tr>
14776<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>textureProj</strong>(gsampler1D <em>sampler</em>, vec2 <em>P</em> [, float <em>bias</em>] )<br>
14777  gvec4 <strong>textureProj</strong>(gsampler1D <em>sampler</em>, vec4 <em>P</em> [, float <em>bias</em>] )<br>
14778  gvec4 <strong>textureProj</strong>(gsampler2D <em>sampler</em>, vec3 <em>P</em> [, float <em>bias</em>] )<br>
14779  gvec4 <strong>textureProj</strong>(gsampler2D <em>sampler</em>, vec4 <em>P</em> [, float <em>bias</em>] )<br>
14780  gvec4 <strong>textureProj</strong>(gsampler3D <em>sampler</em>, vec4 <em>P</em> [, float <em>bias</em>] )<br>
14781  float <strong>textureProj</strong>(sampler1DShadow <em>sampler</em>, vec4 <em>P</em> [, float <em>bias</em>] )<br>
14782  float <strong>textureProj</strong>(sampler2DShadow <em>sampler</em>, vec4 <em>P</em> [, float <em>bias</em>] )<br>
14783  gvec4 <strong>textureProj</strong>(gsampler2DRect <em>sampler</em>, vec3 <em>P</em>)<br>
14784  gvec4 <strong>textureProj</strong>(gsampler2DRect <em>sampler</em>, vec4 <em>P</em>)<br>
14785  float <strong>textureProj</strong>(sampler2DRectShadow <em>sampler</em>, vec4 <em>P</em>)<br></p></td>
14786<td class="tableblock halign-left valign-top"><p class="tableblock">Do a texture lookup with projection.
14787      The texture coordinates consumed from <em>P</em>, not including the last
14788      component of <em>P</em>, are divided by the last component of <em>P</em> to
14789      form projected coordinates <em>P'</em>.
14790      The resulting third component of <em>P</em> in the shadow forms is used as
14791      <em>D<sub>ref</sub></em>.
14792      The third component of <em>P</em> is ignored when <em>sampler</em> has type
14793      <strong>gsampler2D</strong> and <em>P</em> has type <strong>vec4</strong>.
14794      After these values are computed, texture lookup proceeds as in
14795      <strong>texture</strong>.</p></td>
14796</tr>
14797<tr>
14798<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>textureLod</strong>(gsampler1D <em>sampler</em>, float <em>P</em>, float <em>lod</em>)<br>
14799  gvec4 <strong>textureLod</strong>(gsampler2D <em>sampler</em>, vec2 <em>P</em>, float <em>lod</em>)<br>
14800  gvec4 <strong>textureLod</strong>(gsampler3D <em>sampler</em>, vec3 <em>P</em>, float <em>lod</em>)<br>
14801  gvec4 <strong>textureLod</strong>(gsamplerCube <em>sampler</em>, vec3 <em>P</em>, float <em>lod</em>)<br>
14802  float <strong>textureLod</strong>(sampler2DShadow <em>sampler</em>, vec3 <em>P</em>, float <em>lod</em>)<br>
14803  float <strong>textureLod</strong>(sampler1DShadow <em>sampler</em>, vec3 <em>P</em>, float <em>lod</em>)<br>
14804  gvec4 <strong>textureLod</strong>(gsampler1DArray <em>sampler</em>, vec2 <em>P</em>, float <em>lod</em>)<br>
14805  float <strong>textureLod</strong>(sampler1DArrayShadow <em>sampler</em>, vec3 <em>P</em>, float <em>lod</em>)<br>
14806  gvec4 <strong>textureLod</strong>(gsampler2DArray <em>sampler</em>, vec3 <em>P</em>, float <em>lod</em>)<br>
14807  gvec4 <strong>textureLod</strong>(gsamplerCubeArray <em>sampler</em>, vec4 <em>P</em>, float <em>lod</em>)</p></td>
14808<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
14809<p>Do a texture lookup as in <strong>texture</strong> but with explicit level-of-detail;
14810      <em>lod</em> specifies <span class="eq">λ<sub>base</sub>]</span> and sets the partial derivatives
14811      as follows:<br>
14812      (See section 8.14 &#8220;Texture Minification&#8221; and equations 8.4-8.6 of
14813      the <a href="#references">OpenGL Specification</a>.)<br>
14814     <br>
14815      <span class="eq">∂u / ∂x =
14816           ∂v / ∂x =
14817           ∂w / ∂x = 0</span>
14818     <br>
14819      <span class="eq">∂u / ∂y =
14820           ∂v / ∂y =
14821           ∂w / ∂y = 0</span></p>
14822</div></div></td>
14823</tr>
14824<tr>
14825<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>textureOffset</strong>(gsampler1D <em>sampler</em>, float <em>P</em>, int <em>offset</em> [, float <em>bias</em>] )<br>
14826  gvec4 <strong>textureOffset</strong>(gsampler2D <em>sampler</em>, vec2 <em>P</em>, ivec2 <em>offset</em> [, float <em>bias</em>] )<br>
14827  gvec4 <strong>textureOffset</strong>(gsampler3D <em>sampler</em>, vec3 <em>P</em>, ivec3 <em>offset</em> [, float <em>bias</em>] )<br>
14828  float <strong>textureOffset</strong>(sampler2DShadow <em>sampler</em>, vec3 <em>P</em>, ivec2 <em>offset</em> [, float <em>bias</em>] )<br>
14829  gvec4 <strong>textureOffset</strong>(gsampler2DRect <em>sampler</em>, vec2 <em>P</em>, ivec2 <em>offset</em>)<br>
14830  float <strong>textureOffset</strong>(sampler2DRectShadow <em>sampler</em>, vec3 <em>P</em>, ivec2 <em>offset</em>)<br>
14831  float <strong>textureOffset</strong>(sampler1DShadow <em>sampler</em>, vec3 <em>P</em>, int <em>offset</em> [, float <em>bias</em>] )<br>
14832  gvec4 <strong>textureOffset</strong>(gsampler1DArray <em>sampler</em>, vec2 <em>P</em>, int <em>offset</em> [, float <em>bias</em>] )<br>
14833  gvec4 <strong>textureOffset</strong>(gsampler2DArray <em>sampler</em>, vec3 <em>P</em>, ivec2 <em>offset</em> [, float <em>bias</em>] )<br>
14834  float <strong>textureOffset</strong>(sampler1DArrayShadow <em>sampler</em>, vec3 <em>P</em>, int <em>offset</em> [, float <em>bias</em>] )<br>
14835  float <strong>textureOffset</strong>(sampler2DArrayShadow <em>sampler</em>, vec4 <em>P</em>, ivec2 <em>offset</em>)</p></td>
14836<td class="tableblock halign-left valign-top"><p class="tableblock">Do a texture lookup as in <strong>texture</strong> but with <em>offset</em> added to the
14837      <span class="eq">(u,v,w)</span> texel coordinates before looking up each texel.
14838      The offset value must be a constant expression.
14839      A limited range of offset values are supported; the minimum and
14840      maximum offset values are implementation-dependent and given by
14841      <em>gl_MinProgramTexelOffset</em> and <em>gl_MaxProgramTexelOffset</em>,
14842      respectively.</p>
14843<p class="tableblock">      Note that <em>offset</em> does not apply to the layer coordinate for texture
14844      arrays.
14845      This is explained in detail in section 8.14.2 &#8220;Coordinate Wrapping
14846      and Texel Selection&#8221; of the <a href="#references">OpenGL Specification</a>, where <em>offset</em>
14847      is <span class="eq">(δ<sub>u</sub>, δ<sub>v</sub>, δ<sub>w</sub>)</span>.<br>
14848      Note that texel offsets are also not supported for cube maps.</p></td>
14849</tr>
14850<tr>
14851<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>texelFetch</strong>(gsampler1D <em>sampler</em>, int <em>P</em>, int <em>lod</em>)<br>
14852  gvec4 <strong>texelFetch</strong>(gsampler2D <em>sampler</em>, ivec2 <em>P</em>, int <em>lod</em>)<br>
14853  gvec4 <strong>texelFetch</strong>(gsampler3D <em>sampler</em>, ivec3 <em>P</em>, int <em>lod</em>)
14854  gvec4 <strong>texelFetch</strong>(gsampler2DRect <em>sampler</em>, ivec2 <em>P</em>)<br>
14855  gvec4 <strong>texelFetch</strong>(gsampler1DArray <em>sampler</em>, ivec2 <em>P</em>, int <em>lod</em>)<br>
14856  gvec4 <strong>texelFetch</strong>(gsampler2DArray <em>sampler</em>, ivec3 <em>P</em>, int <em>lod</em>)<br>
14857  gvec4 <strong>texelFetch</strong>(gsamplerBuffer <em>sampler</em>, int <em>P</em>)<br>
14858  gvec4 <strong>texelFetch</strong>(gsampler2DMS <em>sampler</em>, ivec2 <em>P</em>, int <em>sample</em>)<br>
14859  gvec4 <strong>texelFetch</strong>(gsampler2DMSArray <em>sampler</em>, ivec3 <em>P</em>, int <em>sample</em>)</p></td>
14860<td class="tableblock halign-left valign-top"><p class="tableblock">Use integer texture coordinate <em>P</em> to lookup a single texel from
14861      <em>sampler</em>.
14862      The array layer comes from the last component of <em>P</em> for the array
14863      forms.
14864      The level-of-detail <em>lod</em> (if present) is as described in sections
14865      11.1.3.2 &#8220;Texel Fetches&#8221; and 8.14.1 &#8220;Scale Factor and Level of
14866      Detail&#8221; of the <a href="#references">OpenGL Specification</a>.</p></td>
14867</tr>
14868<tr>
14869<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>texelFetchOffset</strong>(gsampler1D <em>sampler</em>, int <em>P</em>, int <em>lod</em>, int <em>offset</em>)<br>
14870  gvec4 <strong>texelFetchOffset</strong>(gsampler2D <em>sampler</em>, ivec2 <em>P</em>, int <em>lod</em>, ivec2 <em>offset</em>)<br>
14871  gvec4 <strong>texelFetchOffset</strong>(gsampler3D <em>sampler</em>, ivec3 <em>P</em>, int <em>lod</em>, ivec3 <em>offset</em>)<br>
14872  gvec4 <strong>texelFetchOffset</strong>(gsampler2DRect <em>sampler</em>, ivec2 <em>P</em>, ivec2 <em>offset</em>)<br>
14873  gvec4 <strong>texelFetchOffset</strong>(gsampler1DArray <em>sampler</em>, ivec2 <em>P</em>, int <em>lod</em>, int <em>offset</em>)<br>
14874  gvec4 <strong>texelFetchOffset</strong>(gsampler2DArray <em>sampler</em>, ivec3 <em>P</em>, int <em>lod</em>, ivec2 <em>offset</em>)</p></td>
14875<td class="tableblock halign-left valign-top"><p class="tableblock">Fetch a single texel as in <strong>texelFetch</strong>, offset by <em>offset</em> as
14876      described in <strong>textureOffset</strong>.</p></td>
14877</tr>
14878<tr>
14879<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>textureProjOffset</strong>(gsampler1D <em>sampler</em>, vec2 <em>P</em>, int <em>offset</em> [, float <em>bias</em>] )<br>
14880  gvec4 <strong>textureProjOffset</strong>(gsampler1D <em>sampler</em>, vec4 <em>P</em>, int <em>offset</em> [, float <em>bias</em>] )<br>
14881  gvec4 <strong>textureProjOffset</strong>(gsampler2D <em>sampler</em>, vec3 <em>P</em>, ivec2 <em>offset</em> [, float <em>bias</em>] )<br>
14882  gvec4 <strong>textureProjOffset</strong>(gsampler2D <em>sampler</em>, vec4 <em>P</em>, ivec2 <em>offset</em> [, float <em>bias</em>] )<br>
14883  gvec4 <strong>textureProjOffset</strong>(gsampler3D <em>sampler</em>, vec4 <em>P</em>, ivec3 <em>offset</em> [, float <em>bias</em>] )<br>
14884  gvec4 <strong>textureProjOffset</strong>(gsampler2DRect <em>sampler</em>, vec3 <em>P</em>, ivec2 <em>offset</em>)<br>
14885  gvec4 <strong>textureProjOffset</strong>(gsampler2DRect <em>sampler</em>, vec4 <em>P</em>, ivec2 <em>offset</em>)<br>
14886  float <strong>textureProjOffset</strong>(sampler2DRectShadow <em>sampler</em>, vec4 <em>P</em>, ivec2 <em>offset</em>)<br>
14887  float <strong>textureProjOffset</strong>(sampler1DShadow <em>sampler</em>, vec4 <em>P</em>, int <em>offset</em> [, float <em>bias</em>] )<br>
14888  float <strong>textureProjOffset</strong>(sampler2DShadow <em>sampler</em>, vec4 <em>P</em>, ivec2 <em>offset</em> [, float <em>bias</em>] )</p></td>
14889<td class="tableblock halign-left valign-top"><p class="tableblock">Do a projective texture lookup as described in <strong>textureProj</strong>, offset
14890      by <em>offset</em> as described in <strong>textureOffset</strong>.</p></td>
14891</tr>
14892<tr>
14893<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>textureLodOffset</strong>(gsampler1D <em>sampler</em>, float <em>P</em>, float <em>lod</em>, int <em>offset</em>)<br>
14894  gvec4 <strong>textureLodOffset</strong>(gsampler2D <em>sampler</em>, vec2 <em>P</em>, float <em>lod</em>, ivec2 <em>offset</em>)<br>
14895  gvec4 <strong>textureLodOffset</strong>(gsampler3D <em>sampler</em>, vec3 <em>P</em>, float <em>lod</em>, ivec3 <em>offset</em>)<br>
14896  float <strong>textureLodOffset</strong>(sampler1DShadow <em>sampler</em>, vec3 <em>P</em>, float <em>lod</em>, int <em>offset</em>)<br>
14897  float <strong>textureLodOffset</strong>(sampler2DShadow <em>sampler</em>,  vec3 <em>P</em>, float <em>lod</em>, ivec2 <em>offset</em>)<br>
14898  gvec4 <strong>textureLodOffset</strong>(gsampler1DArray <em>sampler</em>, vec2 <em>P</em>, float <em>lod</em>, int <em>offset</em>)<br>
14899  gvec4 <strong>textureLodOffset</strong>(gsampler2DArray <em>sampler</em>, vec3 <em>P</em>, float <em>lod</em>, ivec2 <em>offset</em>)<br>
14900  float <strong>textureLodOffset</strong>(sampler1DArrayShadow <em>sampler</em>, vec3 <em>P</em>, float <em>lod</em>, int <em>offset</em>)</p></td>
14901<td class="tableblock halign-left valign-top"><p class="tableblock">Do an offset texture lookup with explicit level-of-detail.
14902      See <strong>textureLod</strong> and <strong>textureOffset</strong>.</p></td>
14903</tr>
14904<tr>
14905<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>textureProjLod</strong>(gsampler1D <em>sampler</em>, vec2 <em>P</em>, float <em>lod</em>)<br>
14906  gvec4 <strong>textureProjLod</strong>(gsampler1D <em>sampler</em>, vec4 <em>P</em>, float <em>lod</em>)<br>
14907  gvec4 <strong>textureProjLod</strong>(gsampler2D <em>sampler</em>, vec3 <em>P</em>, float <em>lod</em>)<br>
14908  gvec4 <strong>textureProjLod</strong>(gsampler2D <em>sampler</em>, vec4 <em>P</em>, float <em>lod</em>)<br>
14909  gvec4 <strong>textureProjLod</strong>(gsampler3D <em>sampler</em>, vec4 <em>P</em>, float <em>lod</em>)<br>
14910  float <strong>textureProjLod</strong>(sampler1DShadow <em>sampler</em>, vec4 <em>P</em>, float <em>lod</em>)<br>
14911  float <strong>textureProjLod</strong>(sampler2DShadow <em>sampler</em>, vec4 <em>P</em>, float <em>lod</em>)</p></td>
14912<td class="tableblock halign-left valign-top"><p class="tableblock">Do a projective texture lookup with explicit level-of-detail.
14913      See <strong>textureProj</strong> and <strong>textureLod</strong>.</p></td>
14914</tr>
14915<tr>
14916<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>textureProjLodOffset</strong>(gsampler1D <em>sampler</em>, vec2 <em>P</em>, float <em>lod</em>, int <em>offset</em>)<br>
14917  gvec4 <strong>textureProjLodOffset</strong>(gsampler1D <em>sampler</em>, vec4 <em>P</em>, float <em>lod</em>, int <em>offset</em>)<br>
14918  gvec4 <strong>textureProjLodOffset</strong>(gsampler2D <em>sampler</em>, vec3 <em>P</em>, float <em>lod</em>, ivec2 <em>offset</em>)<br>
14919  gvec4 <strong>textureProjLodOffset</strong>(gsampler2D <em>sampler</em>, vec4 <em>P</em>, float <em>lod</em>, ivec2 <em>offset</em>)<br>
14920  gvec4 <strong>textureProjLodOffset</strong>(gsampler3D <em>sampler</em>, vec4 <em>P</em>, float <em>lod</em>, ivec3 <em>offset</em>)<br>
14921  float <strong>textureProjLodOffset</strong>(sampler1DShadow <em>sampler</em>, vec4 <em>P</em>, float <em>lod</em>, int <em>offset</em>)<br>
14922  float <strong>textureProjLodOffset</strong>(sampler2DShadow <em>sampler</em>, vec4 <em>P</em>, float <em>lod</em>, ivec2 <em>offset</em>)</p></td>
14923<td class="tableblock halign-left valign-top"><p class="tableblock">Do an offset projective texture lookup with explicit level-of-detail.
14924      See <strong>textureProj</strong>, <strong>textureLod</strong>, and <strong>textureOffset</strong>.</p></td>
14925</tr>
14926<tr>
14927<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>textureGrad</strong>(gsampler1D <em>sampler</em>, <em>float _P</em>, float <em>dPdx</em>, float <em>dPdy</em>)<br>
14928  gvec4 <strong>textureGrad</strong>(gsampler2D <em>sampler</em>, vec2 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>)<br>
14929  gvec4 <strong>textureGrad</strong>(gsampler3D <em>sampler</em>,  <em>P</em>, vec3 <em>dPdx</em>, vec3 <em>dPdy</em>)<br>
14930  gvec4 <strong>textureGrad</strong>(gsamplerCube <em>sampler</em>, vec3 <em>P</em>, vec3 <em>dPdx</em>, vec3 <em>dPdy</em>)<br>
14931  gvec4 <strong>textureGrad</strong>(gsampler2DRect <em>sampler</em>, vec2 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>)<br>
14932  float <strong>textureGrad</strong>(sampler2DRectShadow <em>sampler</em>, vec3 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>)<br>
14933  float <strong>textureGrad</strong>(sampler1DShadow <em>sampler</em>, vec3 <em>P</em>, float <em>dPdx</em>, float <em>dPdy</em>)<br>
14934  gvec4 <strong>textureGrad</strong>(gsampler1DArray <em>sampler</em>, vec2 <em>P</em>, float <em>dPdx</em>, float <em>dPdy</em>)<br>
14935  gvec4 <strong>textureGrad</strong>(gsampler2DArray <em>sampler</em>, vec3 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>)<br>
14936  float <strong>textureGrad</strong>(sampler1DArrayShadow <em>sampler</em>, vec3 <em>P</em>, float <em>dPdx</em>, float <em>dPdy</em>)<br>
14937  float <strong>textureGrad</strong>(sampler2DShadow <em>sampler</em>, vec3 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>)<br>
14938  float <strong>textureGrad</strong>(samplerCubeShadow <em>sampler</em>, vec4 <em>P</em>, vec3 <em>dPdx</em>, vec3 <em>dPdy</em>)<br>
14939  float <strong>textureGrad</strong>(sampler2DArrayShadow <em>sampler</em>, vec4 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>)<br>
14940  gvec4 <strong>textureGrad</strong>(gsamplerCubeArray <em>sampler</em>, vec4 <em>P</em>, vec3 <em>dPdx</em>, vec3 <em>dPdy</em>)<br></p></td>
14941<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
14942<p>Do a texture lookup as in <strong>texture</strong> but with <a href="#explicit-gradients">explicit gradients</a> as shown below.
14943      The partial derivatives of <em>P</em> are with respect to window <em>x</em> and
14944      window <em>y</em>.
14945      For the cube version, the partial derivatives of <em>P</em> are assumed to be
14946      in the coordinate system used before texture coordinates are projected
14947      onto the appropriate cube face.</p>
14948</div></div></td>
14949</tr>
14950<tr>
14951<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>textureGradOffset</strong>(gsampler1D <em>sampler</em>, float <em>P</em>, float <em>dPdx</em>, float <em>dPdy</em>, int <em>offset</em>)<br>
14952  gvec4 <strong>textureGradOffset</strong>(gsampler2D <em>sampler</em>, vec2 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>, ivec2 <em>offset</em>)<br>
14953  gvec4 <strong>textureGradOffset</strong>(gsampler3D <em>sampler</em>, vec3 <em>P</em>, vec3 <em>dPdx</em>, vec3 <em>dPdy</em>, ivec3 <em>offset</em>)<br>
14954  gvec4 <strong>textureGradOffset</strong>(gsampler2DRect <em>sampler</em>, vec2 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>, ivec2 <em>offset</em>)<br>
14955  float <strong>textureGradOffset</strong>(sampler2DRectShadow <em>sampler</em>, vec3 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>, ivec2 <em>offset</em>)<br>
14956  float <strong>textureGradOffset</strong>(sampler1DShadow <em>sampler</em>, vec3 <em>P</em>, float <em>dPdx</em>, float <em>dPdy</em>, int <em>offset</em>)<br>
14957  float <strong>textureGradOffset</strong>(sampler2DShadow <em>sampler</em>, vec3 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>, ivec2 <em>offset</em>)<br>
14958  gvec4 <strong>textureGradOffset</strong>(gsampler2DArray <em>sampler</em>, vec3 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>, ivec2 <em>offset</em>)<br>
14959  gvec4 <strong>textureGradOffset</strong>(gsampler1DArray <em>sampler</em>, vec2 <em>P</em>, float <em>dPdx</em>, float <em>dPdy</em>, int <em>offset</em>)<br>
14960  float <strong>textureGradOffset</strong>(sampler1DArrayShadow <em>sampler</em>, vec3 <em>P</em>, float <em>dPdx</em>, float <em>dPdy</em>, int <em>offset</em>)<br>
14961  float <strong>textureGradOffset</strong>(sampler2DArrayShadow <em>sampler</em>, vec4 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>, ivec2 <em>offset</em>)<br></p></td>
14962<td class="tableblock halign-left valign-top"><p class="tableblock">Do a texture lookup with both explicit gradient and offset, as
14963      described in <strong>textureGrad</strong> and <strong>textureOffset</strong>.</p></td>
14964</tr>
14965<tr>
14966<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>textureProjGrad</strong>(gsampler1D <em>sampler</em>, vec2 <em>P</em>, float <em>dPdx</em>, float <em>dPdy</em>)<br>
14967  gvec4 <strong>textureProjGrad</strong>(gsampler1D <em>sampler</em>, vec4 <em>P</em>, float <em>dPdx</em>, float <em>dPdy</em>)<br>
14968  gvec4 <strong>textureProjGrad</strong>(gsampler2D <em>sampler</em>, vec3 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>)<br>
14969  gvec4 <strong>textureProjGrad</strong>(gsampler2D <em>sampler</em>, vec4 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>)<br>
14970  gvec4 <strong>textureProjGrad</strong>(gsampler3D <em>sampler</em>, vec4 <em>P</em>, vec3 <em>dPdx</em>, vec3 <em>dPdy</em>)<br>
14971  gvec4 <strong>textureProjGrad</strong>(gsampler2DRect <em>sampler</em>, vec3 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>)<br>
14972  gvec4 <strong>textureProjGrad</strong>(gsampler2DRect <em>sampler</em>, vec4 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>)<br>
14973  float <strong>textureProjGrad</strong>(sampler2DRectShadow <em>sampler</em>, vec4 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>)<br>
14974  float <strong>textureProjGrad</strong>(sampler1DShadow <em>sampler</em>, vec4 <em>P</em>, float <em>dPdx</em>, float <em>dPdy</em>)<br>
14975  float <strong>textureProjGrad</strong>(sampler2DShadow <em>sampler</em>, vec4 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>)</p></td>
14976<td class="tableblock halign-left valign-top"><p class="tableblock">Do a texture lookup both projectively, as described in <strong>textureProj</strong>,
14977      and with explicit gradient as described in <strong>textureGrad</strong>.
14978      The partial derivatives <em>dPdx</em> and <em>dPdy</em> are assumed to be already
14979      projected.</p></td>
14980</tr>
14981<tr>
14982<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>textureProjGradOffset</strong>(gsampler1D <em>sampler</em>, vec2 <em>P</em>, float <em>dPdx</em>, float <em>dPdy</em>, int <em>offset</em>)<br>
14983  gvec4 <strong>textureProjGradOffset</strong>(gsampler1D <em>sampler</em>, vec4 <em>P</em>, float <em>dPdx</em>, float <em>dPdy</em>, int <em>offset</em>)<br>
14984  gvec4 <strong>textureProjGradOffset</strong>(gsampler2D <em>sampler</em>, vec3 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>, ivec2 <em>offset</em>)<br>
14985  gvec4 <strong>textureProjGradOffset</strong>(gsampler2D <em>sampler</em>, vec4 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>, ivec2 <em>offset</em>)<br>
14986  gvec4 <strong>textureProjGradOffset</strong>(gsampler3D <em>sampler</em>, vec4 <em>P</em>, vec3 <em>dPdx</em>, vec3 <em>dPdy</em>, ivec3 <em>offset</em>)<br>
14987  gvec4 <strong>textureProjGradOffset</strong>(gsampler2DRect <em>sampler</em>, vec3 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>, ivec2 <em>offset</em>)<br>
14988  gvec4 <strong>textureProjGradOffset</strong>(gsampler2DRect <em>sampler</em>, vec4 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>, ivec2 <em>offset</em>)<br>
14989  float <strong>textureProjGradOffset</strong>(sampler2DRectShadow <em>sampler</em>, vec4 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>, ivec2 <em>offset</em>)<br>
14990  float <strong>textureProjGradOffset</strong>(sampler1DShadow <em>sampler</em>, vec4 <em>P</em>, float <em>dPdx</em>, float <em>dPdy</em>, int <em>offset</em>)<br>
14991  float <strong>textureProjGradOffset</strong>(sampler2DShadow <em>sampler</em>, vec4 <em>P</em>, vec2 <em>dPdx</em>, vec2 <em>dPdy</em>, ivec2 <em>offset</em>)</p></td>
14992<td class="tableblock halign-left valign-top"><p class="tableblock">Do a texture lookup projectively and with explicit gradient as
14993      described in <strong>textureProjGrad</strong>, as well as with offset, as described in
14994      <strong>textureOffset</strong>.</p></td>
14995</tr>
14996</tbody>
14997</table>
14998</div>
14999<div class="sect3">
15000<h4 id="explicit-gradients">8.9.3. Explicit Gradients</h4>
15001<div class="paragraph">
15002<p>In the <strong>textureGrad</strong> functions described above, explicit gradients control
15003texture lookups as follows:</p>
15004</div>
15005<div class="stemblock">
15006<div class="content">
15007\[\begin{aligned}
15008  \frac{\partial{s}}{\partial{x}} &amp; =
15009    \begin{cases}
15010      \frac{\partial{P}}{\partial{x}}, &amp; \text{for a 1D texture} \\[0.8em]
15011      \frac{\partial{P.s}}{\partial{x}}, &amp; \text{otherwise}
15012    \end{cases} \\[2.5em]
15013  \frac{\partial{s}}{\partial{y}} &amp; =
15014    \begin{cases}
15015      \frac{\partial{P}}{\partial{y}}, &amp; \text{for a 1D texture} \\[0.8em]
15016      \frac{\partial{P.s}}{\partial{y}}, &amp; \text{otherwise}
15017    \end{cases} \\[2.5em]
15018  \frac{\partial{t}}{\partial{x}} &amp; =
15019    \begin{cases}
15020      0.0,                               &amp; \text{for a 1D texture} \\[0.8em]
15021      \frac{\partial{P.t}}{\partial{x}}, &amp; \text{otherwise}
15022    \end{cases} \\[2.5em]
15023  \frac{\partial{t}}{\partial{y}} &amp; =
15024    \begin{cases}
15025      0.0,                               &amp; \text{for a 1D texture} \\[0.8em]
15026      \frac{\partial{P.t}}{\partial{y}}, &amp; \text{otherwise}
15027    \end{cases} \\[2.5em]
15028  \frac{\partial{r}}{\partial{x}} &amp; =
15029    \begin{cases}
15030      0.0,                               &amp; \text{for 1D or 2D} \\[0.8em]
15031      \frac{\partial{P.p}}{\partial{x}}, &amp; \text{cube, other}
15032    \end{cases} \\[2.5em]
15033  \frac{\partial{r}}{\partial{y}} &amp; =
15034    \begin{cases}
15035      0.0,                               &amp; \text{for 1D or 2D} \\[0.8em]
15036      \frac{\partial{P.p}}{\partial{y}}, &amp; \text{cube, other}
15037    \end{cases}
15038\end{aligned}\]
15039</div>
15040</div>
15041</div>
15042<div class="sect3">
15043<h4 id="texture-gather-functions">8.9.4. Texture Gather Functions</h4>
15044<div class="paragraph">
15045<p>The texture gather functions take components of a single floating-point
15046vector operand as a texture coordinate, determine a set of four texels to
15047sample from the base level-of-detail of the specified texture image, and
15048return one component from each texel in a four-component result vector.</p>
15049</div>
15050<div class="paragraph">
15051<p>When performing a texture gather operation, the minification and
15052magnification filters are ignored, and the rules for LINEAR filtering in the
15053<a href="#references">OpenGL Specification</a> are applied to the base level of the texture image
15054to identify the four texels <em>i<sub>0</sub> j<sub>1</sub></em>, <em>i<sub>1</sub> j<sub>1</sub></em>, <em>i<sub>1</sub> j<sub>0</sub></em>, and <em>i<sub>0</sub>
15055j<sub>0</sub></em>.
15056The texels are then converted to texture base colors (<em>R<sub>s</sub></em>, <em>G<sub>s</sub></em>,
15057<em>B<sub>s</sub></em>, <em>A<sub>s</sub></em>) according to table 15.1, followed by application of the
15058texture swizzle as described in section 15.2.1 &#8220;Texture Access&#8221; of the
15059<a href="#references">OpenGL Specification</a>.
15060A four-component vector is assembled by taking the selected component from
15061each of the post-swizzled texture source colors in the order (<em>i<sub>0</sub> j<sub>1</sub></em>,
15062<em>i<sub>1</sub> j<sub>1</sub></em>, <em>i<sub>1</sub> j<sub>0</sub></em>, <em>i<sub>0</sub> j<sub>0</sub></em>).</p>
15063</div>
15064<div class="paragraph">
15065<p>For texture gather functions using a texture-combined shadow sampler type,
15066each of the four
15067texel lookups perform a depth comparison against the depth reference value
15068passed in (<em>refZ</em>), and returns the result of that comparison in the
15069appropriate component of the result vector.</p>
15070</div>
15071<div class="paragraph">
15072<p>As with other texture lookup functions, the results of a texture gather are
15073undefined for shadow samplers if the texture referenced is not a depth
15074texture or has depth comparisons disabled; or for non-shadow samplers if the
15075texture referenced is a depth texture with depth comparisons enabled.</p>
15076</div>
15077<table class="tableblock frame-all grid-all stretch">
15078<colgroup>
15079<col style="width: 50%;">
15080<col style="width: 50%;">
15081</colgroup>
15082<thead>
15083<tr>
15084<th class="tableblock halign-left valign-top">Syntax</th>
15085<th class="tableblock halign-left valign-top">Description</th>
15086</tr>
15087</thead>
15088<tbody>
15089<tr>
15090<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>textureGather</strong>(gsampler2D <em>sampler</em>, vec2 <em>P</em> [, int <em>comp</em>])<br>
15091  gvec4 <strong>textureGather</strong>(gsampler2DArray <em>sampler</em>, vec3 <em>P</em> [, int <em>comp</em>])<br>
15092  gvec4 <strong>textureGather</strong>(gsamplerCube <em>sampler</em>, vec3 <em>P</em> [, int <em>comp</em>])<br>
15093  gvec4 <strong>textureGather</strong>(gsamplerCubeArray <em>sampler</em>, vec4 <em>P</em>[, int <em>comp</em>])<br>
15094  gvec4 <strong>textureGather</strong>(gsampler2DRect <em>sampler</em>, vec2 <em>P</em>[, int <em>comp</em>])<br>
15095  vec4 <strong>textureGather</strong>(sampler2DShadow <em>sampler</em>, vec2 <em>P</em>, float <em>refZ</em>)<br>
15096  vec4 <strong>textureGather</strong>(sampler2DArrayShadow <em>sampler</em>, vec3 <em>P</em>, float <em>refZ</em>)<br>
15097  vec4 <strong>textureGather</strong>(samplerCubeShadow <em>sampler</em>, vec3 <em>P</em>, float <em>refZ</em>)<br>
15098  vec4 <strong>textureGather</strong>(samplerCubeArrayShadow <em>sampler</em>, vec4 <em>P</em>, float <em>refZ</em>)<br>
15099  vec4 <strong>textureGather</strong>(sampler2DRectShadow <em>sampler</em>, vec2 <em>P</em>, float <em>refZ</em>)</p></td>
15100<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
15101<p>Returns the value<br></p>
15102</div>
15103<div class="openblock">
15104<div class="content">
15105<div class="listingblock">
15106<div class="content">
15107<pre class="CodeRay highlight"><code data-lang="c++">vec4(Sample_i0_j1(P, base).comp,
15108     Sample_i1_j1(P, base).comp,
15109     Sample_i1_j0(P, base).comp,
15110     Sample_i0_j0(P, base).comp)</code></pre>
15111</div>
15112</div>
15113<div class="paragraph">
15114<p>If specified, the value of <em>comp</em> must be a constant integer expression with
15115a value of 0, 1, 2, or 3, identifying the <em>x</em>, <em>y</em>, <em>z</em>, or <em>w</em>
15116post-swizzled component of the four-component vector lookup result for each
15117texel, respectively.
15118If <em>comp</em> is not specified, it is treated as 0, selecting the <em>x</em> component
15119of each texel to generate the result.</p>
15120</div>
15121</div>
15122</div></div></td>
15123</tr>
15124<tr>
15125<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>textureGatherOffset</strong>(gsampler2D <em>sampler</em>, vec2 <em>P</em>, ivec2 <em>offset</em>, [ int <em>comp</em>])<br>
15126  gvec4 <strong>textureGatherOffset</strong>(gsampler2DArray <em>sampler</em>, vec3 <em>P</em>, ivec2 <em>offset</em> [ int <em>comp</em>])<br>
15127  vec4 <strong>textureGatherOffset</strong>(sampler2DShadow <em>sampler</em>, vec2 <em>P</em>, float <em>refZ</em>, ivec2 <em>offset</em>)<br>
15128  vec4 <strong>textureGatherOffset</strong>(sampler2DArrayShadow <em>sampler</em>, vec3 <em>P</em>, float <em>refZ</em>, ivec2 <em>offset</em>)<br>
15129  gvec4 <strong>textureGatherOffset</strong>(gsampler2DRect <em>sampler</em>, vec2 <em>P</em>, ivec2 <em>offset</em> [ int <em>comp</em>])<br>
15130  vec4 <strong>textureGatherOffset</strong>(sampler2DRectShadow <em>sampler</em>, vec2 <em>P</em>, float <em>refZ</em>, ivec2 <em>offset</em>)</p></td>
15131<td class="tableblock halign-left valign-top"><p class="tableblock">Perform a texture gather operation as in <strong>textureGather</strong> by <em>offset</em>
15132      as described in <strong>textureOffset</strong> except that the <em>offset</em> can be
15133      variable (non constant) and the implementation-dependent minimum and
15134      maximum offset values are given by MIN_PROGRAM_TEXTURE_GATHER_OFFSET
15135      and MAX_PROGRAM_TEXTURE_GATHER_OFFSET, respectively.</p></td>
15136</tr>
15137<tr>
15138<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>textureGatherOffsets</strong>(gsampler2D <em>sampler</em>, vec2 <em>P</em>, ivec2 <em>offsets</em>[4] [, int <em>comp</em>])<br>
15139  gvec4 <strong>textureGatherOffsets</strong>(gsampler2DArray <em>sampler</em>, vec3 <em>P</em>, ivec2 <em>offsets</em>[4]   [, int <em>comp</em>])<br>
15140  vec4 <strong>textureGatherOffsets</strong>(sampler2DShadow <em>sampler</em>, vec2 <em>P</em>, float <em>refZ</em>, ivec2 <em>offsets</em>[4])<br>
15141  vec4 <strong>textureGatherOffsets</strong>(sampler2DArrayShadow <em>sampler</em>, vec3 <em>P</em>, float <em>refZ</em>, ivec2 <em>offsets</em>[4])<br>
15142  gvec4 <strong>textureGatherOffsets</strong>(gsampler2DRect <em>sampler</em>, vec2 <em>P</em>, ivec2 <em>offsets</em>[4] [, int <em>comp</em>])<br>
15143  vec4 <strong>textureGatherOffsets</strong>(sampler2DRectShadow <em>sampler</em>, vec2 <em>P</em>, float <em>refZ</em>, ivec2 <em>offsets</em>[4])</p></td>
15144<td class="tableblock halign-left valign-top"><p class="tableblock">Operate identically to <strong>textureGatherOffset</strong> except that <em>offsets</em> is
15145      used to determine the location of the four texels to sample.
15146      Each of the four texels is obtained by applying the corresponding
15147      offset in <em>offsets</em> as a (<em>u</em>, <em>v</em>) coordinate offset to <em>P</em>,
15148      identifying the four-texel LINEAR footprint, and then selecting the
15149      texel <em>i<sub>0</sub> j<sub>0</sub></em> of that footprint.
15150      The specified values in <em>offsets</em> must be constant integral
15151      expressions.</p></td>
15152</tr>
15153</tbody>
15154</table>
15155</div>
15156<div class="sect3">
15157<h4 id="compatibility-profile-texture-functions">8.9.5. Compatibility Profile Texture Functions</h4>
15158<div class="paragraph">
15159<p>The following texture functions are only in the compatibility profile.</p>
15160</div>
15161<table class="tableblock frame-all grid-all stretch">
15162<colgroup>
15163<col style="width: 50%;">
15164<col style="width: 50%;">
15165</colgroup>
15166<thead>
15167<tr>
15168<th class="tableblock halign-left valign-top">Syntax</th>
15169<th class="tableblock halign-left valign-top">Description</th>
15170</tr>
15171</thead>
15172<tbody>
15173<tr>
15174<td class="tableblock halign-left valign-top"><p class="tableblock">vec4 <strong>texture1D</strong>(sampler1D <em>sampler</em>, float <em>coord</em> [, float <em>bias</em>] )<br>
15175  vec4 <strong>texture1DProj</strong>(sampler1D <em>sampler</em>, vec2 <em>coord</em> [, float <em>bias</em>] )<br>
15176  vec4 <strong>texture1DProj</strong>(sampler1D <em>sampler</em>, vec4 <em>coord</em> [, float <em>bias</em>] )<br>
15177  vec4 <strong>texture1DLod</strong>(sampler1D <em>sampler</em>, float <em>coord</em>, float <em>lod</em>)<br>
15178  vec4 <strong>texture1DProjLod</strong>(sampler1D <em>sampler</em>, vec2 <em>coord</em>, float <em>lod</em>)<br>
15179  vec4 <strong>texture1DProjLod</strong>(sampler1D <em>sampler</em>, vec4 <em>coord</em>, float <em>lod</em>)</p></td>
15180<td class="tableblock halign-left valign-top"><p class="tableblock">See corresponding signature above without &#8220;1D&#8221; in the name.</p></td>
15181</tr>
15182<tr>
15183<td class="tableblock halign-left valign-top"><p class="tableblock">vec4 <strong>texture2D</strong>(sampler2D <em>sampler</em>, vec2 <em>coord</em> [, float <em>bias</em>] )<br>
15184  vec4 <strong>texture2DProj</strong>(sampler2D <em>sampler</em>, vec3 <em>coord</em> [, float <em>bias</em>] )<br>
15185  vec4 <strong>texture2DProj</strong>(sampler2D <em>sampler</em>, vec4 <em>coord</em> [, float <em>bias</em>] )<br>
15186  vec4 <strong>texture2DLod</strong>(sampler2D <em>sampler</em>, vec2 <em>coord</em>, float <em>lod</em>)<br>
15187  vec4 <strong>texture2DProjLod</strong>(sampler2D <em>sampler</em>, vec3 <em>coord</em>, float <em>lod</em>)<br>
15188  vec4 <strong>texture2DProjLod</strong>(sampler2D <em>sampler</em>, vec4 <em>coord</em>, float <em>lod</em>)</p></td>
15189<td class="tableblock halign-left valign-top"><p class="tableblock">See corresponding signature above without &#8220;2D&#8221; in the name.</p></td>
15190</tr>
15191<tr>
15192<td class="tableblock halign-left valign-top"><p class="tableblock">vec4 <strong>texture3D</strong>(sampler3D <em>sampler</em>, vec3 <em>coord</em> [, float <em>bias</em>] )<br>
15193  vec4 <strong>texture3DProj</strong>(sampler3D <em>sampler</em>, vec4 <em>coord</em> [, float <em>bias</em>] )<br>
15194  vec4 <strong>texture3DLod</strong>(sampler3D <em>sampler</em>, vec3 <em>coord</em>, float <em>lod</em>)<br>
15195  vec4 <strong>texture3DProjLod</strong>(sampler3D <em>sampler</em>, vec4 <em>coord</em>, float <em>lod</em>)</p></td>
15196<td class="tableblock halign-left valign-top"><p class="tableblock">See corresponding signature above without &#8220;3D&#8221; in the name.<br>
15197      Use the texture coordinate <em>coord</em> to do a texture lookup in the 3D
15198      texture currently bound to <em>sampler</em>.
15199      For the projective (&#8220;<strong>Proj</strong>&#8221;) versions, the texture coordinate is
15200      divided by <em>coord.q</em>.</p></td>
15201</tr>
15202<tr>
15203<td class="tableblock halign-left valign-top"><p class="tableblock">vec4 <strong>textureCube</strong>(samplerCube <em>sampler</em>, vec3 <em>coord</em> [, float <em>bias</em>] )<br>
15204  vec4 <strong>textureCubeLod</strong>(samplerCube <em>sampler</em>, vec3 <em>coord</em>, float <em>lod</em>)</p></td>
15205<td class="tableblock halign-left valign-top"><p class="tableblock">See corresponding signature above without &#8220;Cube&#8221; in the name.</p></td>
15206</tr>
15207<tr>
15208<td class="tableblock halign-left valign-top"><p class="tableblock">vec4 <strong>shadow1D</strong>(sampler1DShadow <em>sampler</em>, vec3 <em>coord</em> [, float <em>bias</em>] )<br>
15209  vec4 <strong>shadow2D</strong>(sampler2DShadow <em>sampler</em>, vec3 <em>coord</em> [, float <em>bias</em>] )<br>
15210  vec4 <strong>shadow1DProj</strong>(sampler1DShadow <em>sampler</em>, vec4 <em>coord</em> [, float <em>bias</em>] )<br>
15211  vec4 <strong>shadow2DProj</strong>(sampler2DShadow <em>sampler</em>, vec4 <em>coord</em> [, float <em>bias</em>] )<br>
15212  vec4 <strong>shadow1DLod</strong>(sampler1DShadow <em>sampler</em>, vec3 <em>coord</em>, float <em>lod</em>)<br>
15213  vec4 <strong>shadow2DLod</strong>(sampler2DShadow <em>sampler</em>, vec3 <em>coord</em>, float <em>lod</em>)<br>
15214  vec4 <strong>shadow1DProjLod</strong>(sampler1DShadow <em>sampler</em>, vec4 <em>coord</em>, float <em>lod</em>)<br>
15215  vec4 <strong>shadow2DProjLod</strong>(sampler2DShadow <em>sampler</em>, vec4 coord, float <em>lod</em>)</p></td>
15216<td class="tableblock halign-left valign-top"><p class="tableblock">Same functionality as the &#8220;<strong>texture</strong>&#8221; based names above with the
15217      same signature.</p></td>
15218</tr>
15219</tbody>
15220</table>
15221</div>
15222</div>
15223<div class="sect2">
15224<h3 id="atomic-counter-functions">8.10. Atomic Counter Functions</h3>
15225<div class="paragraph">
15226<p>The atomic-counter operations in this section operate atomically with
15227respect to each other.
15228They are atomic for any single counter, meaning any of these operations on a
15229specific counter in one shader instantiation will be indivisible by any of
15230these operations on the same counter from another shader instantiation.
15231There is no guarantee that these operations are atomic with respect to other
15232forms of access to the counter or that they are serialized when applied to
15233separate counters.
15234Such cases would require additional use of fences, barriers, or other forms
15235of synchronization, if atomicity or serialization is desired.</p>
15236</div>
15237<div class="paragraph">
15238<p>The underlying counter is a 32-bit unsigned integer.
15239The result of operations will wrap to [0, 2<sup>32</sup>-1].</p>
15240</div>
15241<table class="tableblock frame-all grid-all stretch">
15242<colgroup>
15243<col style="width: 50%;">
15244<col style="width: 50%;">
15245</colgroup>
15246<thead>
15247<tr>
15248<th class="tableblock halign-left valign-top">Syntax</th>
15249<th class="tableblock halign-left valign-top">Description</th>
15250</tr>
15251</thead>
15252<tbody>
15253<tr>
15254<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicCounterIncrement</strong>(atomic_uint <em>c</em>)</p></td>
15255<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
15256<p>Atomically<br></p>
15257</div>
15258<div class="openblock">
15259<div class="content">
15260<div class="olist arabic">
15261<ol class="arabic">
15262<li>
15263<p>increments the counter for <em>c</em>, and</p>
15264</li>
15265<li>
15266<p>returns its value prior to the increment operation.</p>
15267</li>
15268</ol>
15269</div>
15270<div class="paragraph">
15271<p>These two steps are done atomically with respect to the atomic counter
15272functions in this table.</p>
15273</div>
15274</div>
15275</div></div></td>
15276</tr>
15277<tr>
15278<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicCounterDecrement</strong>(atomic_uint <em>c</em>)</p></td>
15279<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
15280<p>Atomically<br></p>
15281</div>
15282<div class="openblock">
15283<div class="content">
15284<div class="olist arabic">
15285<ol class="arabic">
15286<li>
15287<p>decrements the counter for <em>c</em>, and</p>
15288</li>
15289<li>
15290<p>returns the value resulting from the decrement operation.</p>
15291</li>
15292</ol>
15293</div>
15294<div class="paragraph">
15295<p>These two steps are done atomically with respect to the atomic counter
15296functions in this table.</p>
15297</div>
15298</div>
15299</div></div></td>
15300</tr>
15301<tr>
15302<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicCounter</strong>(atomic_uint <em>c</em>)</p></td>
15303<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the counter value for <em>c</em>.</p></td>
15304</tr>
15305<tr>
15306<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicCounterAdd</strong>(atomic_uint <em>c</em>, uint <em>data</em>)</p></td>
15307<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
15308<p>Atomically<br></p>
15309</div>
15310<div class="openblock">
15311<div class="content">
15312<div class="olist arabic">
15313<ol class="arabic">
15314<li>
15315<p>adds the value of <em>data</em> to the counter for <em>c</em>, and</p>
15316</li>
15317<li>
15318<p>returns its value prior to the operation.</p>
15319</li>
15320</ol>
15321</div>
15322<div class="paragraph">
15323<p>These two steps are done atomically with respect to the atomic counter
15324functions in this table.</p>
15325</div>
15326</div>
15327</div></div></td>
15328</tr>
15329<tr>
15330<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicCounterSubtract</strong>(atomic_uint <em>c</em>, uint <em>data</em>)</p></td>
15331<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
15332<p>Atomically<br></p>
15333</div>
15334<div class="openblock">
15335<div class="content">
15336<div class="olist arabic">
15337<ol class="arabic">
15338<li>
15339<p>subtracts the value of <em>data</em> from the counter for <em>c</em>, and</p>
15340</li>
15341<li>
15342<p>returns its value prior to the operation.</p>
15343</li>
15344</ol>
15345</div>
15346<div class="paragraph">
15347<p>These two steps are done atomically with respect to the atomic counter
15348functions in this table.</p>
15349</div>
15350</div>
15351</div></div></td>
15352</tr>
15353<tr>
15354<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicCounterMin</strong>(atomic_uint <em>c</em>, uint <em>data</em>)</p></td>
15355<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
15356<p>Atomically<br></p>
15357</div>
15358<div class="openblock">
15359<div class="content">
15360<div class="olist arabic">
15361<ol class="arabic">
15362<li>
15363<p>sets the counter for <em>c</em> to the minimum of the value of the counter and
15364the value of <em>data</em>, and</p>
15365</li>
15366<li>
15367<p>returns the value prior to the operation.</p>
15368</li>
15369</ol>
15370</div>
15371<div class="paragraph">
15372<p>These two steps are done atomically with respect to the atomic counter
15373functions in this table.</p>
15374</div>
15375</div>
15376</div></div></td>
15377</tr>
15378<tr>
15379<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicCounterMax</strong>(atomic_uint <em>c</em>, uint <em>data</em>)</p></td>
15380<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
15381<p>Atomically<br></p>
15382</div>
15383<div class="openblock">
15384<div class="content">
15385<div class="olist arabic">
15386<ol class="arabic">
15387<li>
15388<p>sets the counter for <em>c</em> to the maximum of the value of the counter and
15389the value of <em>data</em>, and</p>
15390</li>
15391<li>
15392<p>returns the value prior to the operation.</p>
15393</li>
15394</ol>
15395</div>
15396<div class="paragraph">
15397<p>These two steps are done atomically with respect to the atomic counter
15398functions in this table.</p>
15399</div>
15400</div>
15401</div></div></td>
15402</tr>
15403<tr>
15404<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicCounterAnd</strong>(atomic_uint <em>c</em>, uint <em>data</em>)</p></td>
15405<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
15406<p>Atomically<br></p>
15407</div>
15408<div class="openblock">
15409<div class="content">
15410<div class="olist arabic">
15411<ol class="arabic">
15412<li>
15413<p>sets the counter for <em>c</em> to the bitwise AND of the value of the counter
15414and the value of <em>data</em>, and</p>
15415</li>
15416<li>
15417<p>returns the value prior to the operation.</p>
15418</li>
15419</ol>
15420</div>
15421<div class="paragraph">
15422<p>These two steps are done atomically with respect to the atomic counter
15423functions in this table.</p>
15424</div>
15425</div>
15426</div></div></td>
15427</tr>
15428<tr>
15429<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicCounterOr</strong>(atomic_uint <em>c</em>, uint <em>data</em>)</p></td>
15430<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
15431<p>Atomically<br></p>
15432</div>
15433<div class="openblock">
15434<div class="content">
15435<div class="olist arabic">
15436<ol class="arabic">
15437<li>
15438<p>sets the counter for <em>c</em> to the bitwise OR of the value of the counter
15439and the value of <em>data</em>, and</p>
15440</li>
15441<li>
15442<p>returns the value prior to the operation.</p>
15443</li>
15444</ol>
15445</div>
15446<div class="paragraph">
15447<p>These two steps are done atomically with respect to the atomic counter
15448functions in this table.</p>
15449</div>
15450</div>
15451</div></div></td>
15452</tr>
15453<tr>
15454<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicCounterXor</strong>(atomic_uint <em>c</em>, uint <em>data</em>)</p></td>
15455<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
15456<p>Atomically<br></p>
15457</div>
15458<div class="openblock">
15459<div class="content">
15460<div class="olist arabic">
15461<ol class="arabic">
15462<li>
15463<p>sets the counter for <em>c</em> to the bitwise XOR of the value of the counter
15464and the value of <em>data</em>, and</p>
15465</li>
15466<li>
15467<p>returns the value prior to the operation.</p>
15468</li>
15469</ol>
15470</div>
15471<div class="paragraph">
15472<p>These two steps are done atomically with respect to the atomic counter
15473functions in this table.</p>
15474</div>
15475</div>
15476</div></div></td>
15477</tr>
15478<tr>
15479<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicCounterExchange</strong>(atomic_uint <em>c</em>, uint <em>data</em>)</p></td>
15480<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
15481<p>Atomically<br></p>
15482</div>
15483<div class="openblock">
15484<div class="content">
15485<div class="olist arabic">
15486<ol class="arabic">
15487<li>
15488<p>sets the counter value for <em>c</em> to the value of <em>data</em>, and</p>
15489</li>
15490<li>
15491<p>returns its value prior to the operation.</p>
15492</li>
15493</ol>
15494</div>
15495<div class="paragraph">
15496<p>These two steps are done atomically with respect to the atomic counter
15497functions in this table.</p>
15498</div>
15499</div>
15500</div></div></td>
15501</tr>
15502<tr>
15503<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicCounterCompSwap</strong>(atomic_uint <em>c</em>, uint <em>compare</em>, uint <em>data</em>)</p></td>
15504<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
15505<p>Atomically<br></p>
15506</div>
15507<div class="openblock">
15508<div class="content">
15509<div class="olist arabic">
15510<ol class="arabic">
15511<li>
15512<p>compares the value of <em>compare</em> and the counter value for <em>c</em></p>
15513</li>
15514<li>
15515<p>if the values are equal, sets the counter value for <em>c</em> to the value of
15516<em>data</em>, and</p>
15517</li>
15518<li>
15519<p>returns its value prior to the operation.</p>
15520</li>
15521</ol>
15522</div>
15523<div class="paragraph">
15524<p>These three steps are done atomically with respect to the atomic counter
15525functions in this table.</p>
15526</div>
15527</div>
15528</div></div></td>
15529</tr>
15530</tbody>
15531</table>
15532</div>
15533<div class="sect2">
15534<h3 id="atomic-memory-functions">8.11. Atomic Memory Functions</h3>
15535<div class="paragraph">
15536<p>Atomic memory functions perform atomic operations on an individual signed or
15537unsigned integer stored in buffer object or shared variable storage.
15538All of the atomic memory operations read a value from memory, compute a new
15539value using one of the operations described below, write the new value to
15540memory, and return the original value read.
15541The contents of the memory being updated by the atomic operation are
15542guaranteed not to be modified by any other assignment or atomic memory
15543function in any shader invocation between the time the original value is
15544read and the time the new value is written.</p>
15545</div>
15546<div class="paragraph">
15547<p>Atomic memory functions are supported only for a limited set of variables.
15548A shader will fail to compile if the value passed to the <em>mem</em> argument of
15549an atomic memory function does not correspond to a buffer or shared
15550variable.
15551It is acceptable to pass an element of an array or a single component of a
15552vector to the <em>mem</em> argument of an atomic memory function, as long as the
15553underlying array or vector is a buffer or shared variable.</p>
15554</div>
15555<div class="paragraph">
15556<p>All the built-in functions in this section accept arguments with
15557combinations of <strong>restrict</strong>, <strong>coherent</strong>, and <strong>volatile</strong> memory qualification,
15558despite not having them listed in the prototypes.
15559The atomic operation will operate as required by the calling argument&#8217;s
15560memory qualification, not by the built-in function&#8217;s formal parameter memory
15561qualification.</p>
15562</div>
15563<table class="tableblock frame-all grid-all stretch">
15564<colgroup>
15565<col style="width: 50%;">
15566<col style="width: 50%;">
15567</colgroup>
15568<thead>
15569<tr>
15570<th class="tableblock halign-left valign-top">Syntax</th>
15571<th class="tableblock halign-left valign-top">Description</th>
15572</tr>
15573</thead>
15574<tbody>
15575<tr>
15576<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicAdd</strong>(inout uint <em>mem</em>, uint <em>data</em>)<br>
15577  int <strong>atomicAdd</strong>(inout int <em>mem</em>, int <em>data</em>)</p></td>
15578<td class="tableblock halign-left valign-top"><p class="tableblock">Computes a new value by adding the value of <em>data</em> to the contents
15579      <em>mem</em>.</p></td>
15580</tr>
15581<tr>
15582<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicMin</strong>(inout uint <em>mem</em>, uint <em>data</em>)<br>
15583  int <strong>atomicMin</strong>(inout int <em>mem</em>, int <em>data</em>)</p></td>
15584<td class="tableblock halign-left valign-top"><p class="tableblock">Computes a new value by taking the minimum of the value of <em>data</em> and
15585      the contents of <em>mem</em>.</p></td>
15586</tr>
15587<tr>
15588<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicMax</strong>(inout uint <em>mem</em>, uint <em>data</em>)<br>
15589  int <strong>atomicMax</strong>(inout int <em>mem</em>, int <em>data</em>)</p></td>
15590<td class="tableblock halign-left valign-top"><p class="tableblock">Computes a new value by taking the maximum of the value of <em>data</em> and
15591      the contents of <em>mem</em>.</p></td>
15592</tr>
15593<tr>
15594<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicAnd</strong>(inout uint <em>mem</em>, uint <em>data</em>)<br>
15595  int <strong>atomicAnd</strong>(inout int <em>mem</em>, int <em>data</em>)</p></td>
15596<td class="tableblock halign-left valign-top"><p class="tableblock">Computes a new value by performing a bit-wise AND of the value of
15597      <em>data</em> and the contents of <em>mem</em>.</p></td>
15598</tr>
15599<tr>
15600<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicOr</strong>(inout uint <em>mem</em>, uint <em>data</em>)<br>
15601  int <strong>atomicOr</strong>(inout int <em>mem</em>, int <em>data</em>)</p></td>
15602<td class="tableblock halign-left valign-top"><p class="tableblock">Computes a new value by performing a bit-wise OR of the value of
15603      <em>data</em> and the contents of <em>mem</em>.</p></td>
15604</tr>
15605<tr>
15606<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicXor</strong>(inout uint <em>mem</em>, uint <em>data</em>)<br>
15607  int <strong>atomicXor</strong>(inout int <em>mem</em>, int <em>data</em>)</p></td>
15608<td class="tableblock halign-left valign-top"><p class="tableblock">Computes a new value by performing a bit-wise EXCLUSIVE OR of the
15609      value of <em>data</em> and the contents of <em>mem</em>.</p></td>
15610</tr>
15611<tr>
15612<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicExchange</strong>(inout uint <em>mem</em>, uint <em>data</em>)<br>
15613  int <strong>atomicExchange</strong>(inout int <em>mem</em>, int <em>data</em>)</p></td>
15614<td class="tableblock halign-left valign-top"><p class="tableblock">Computes a new value by simply copying the value of <em>data</em>.</p></td>
15615</tr>
15616<tr>
15617<td class="tableblock halign-left valign-top"><p class="tableblock">uint <strong>atomicCompSwap</strong>(inout uint <em>mem</em>, uint <em>compare</em>, uint <em>data</em>)<br>
15618  int <strong>atomicCompSwap</strong>(inout int <em>mem</em>, int <em>compare</em>, int <em>data</em>)</p></td>
15619<td class="tableblock halign-left valign-top"><p class="tableblock">Compares the value of <em>compare</em> and the contents of <em>mem</em>.
15620      If the values are equal, the new value is given by <em>data</em>; otherwise,
15621      it is taken from the original contents of <em>mem</em>.</p></td>
15622</tr>
15623</tbody>
15624</table>
15625</div>
15626<div class="sect2">
15627<h3 id="image-functions">8.12. Image Functions</h3>
15628<div class="paragraph">
15629<p>Variables using one of the image basic types may be used by the built-in
15630shader image memory functions defined in this section to read and write
15631individual texels of a texture.
15632Each image variable references an image unit, which has a texture image
15633attached.</p>
15634</div>
15635<div class="paragraph">
15636<p>When image memory functions below access memory, an individual texel in the
15637image is identified using an (<em>i</em>), (<em>i, j</em>), or (<em>i, j, k</em>) coordinate
15638corresponding to the values of <em>P</em>.
15639For <strong>image2DMS</strong> and <strong>image2DMSArray</strong> variables (and the corresponding
15640int/unsigned int types) corresponding to multisample textures, each texel
15641may have multiple samples and an individual sample is identified using the
15642integer <em>sample</em> parameter.
15643The coordinates
15644and sample number
15645are used to select an individual texel in the manner described in section
156468.26
15647&#8220;Texture Image Loads and Stores&#8221; of the <a href="#references">OpenGL Specification</a>.</p>
15648</div>
15649<div class="paragraph">
15650<p>Loads and stores support float, integer, and unsigned integer types.
15651The data types below starting <code>gimage</code> serve as placeholders meaning
15652types starting either &#8220;<strong>image</strong>&#8221;, &#8220;<strong>iimage</strong>&#8221;, or &#8220;<strong>uimage</strong>&#8221; in the same
15653way as "<strong>gvec</strong>" or "<strong>gsampler</strong>" in earlier sections.</p>
15654</div>
15655<div class="paragraph">
15656<p>The <em>IMAGE_PARAMS</em> in the prototypes below is a placeholder representing
1565733
15658separate functions, each for a different type of image variable.
15659The <em>IMAGE_PARAMS</em> placeholder is replaced by one of the following parameter
15660lists:</p>
15661</div>
15662<div class="dlist">
15663<dl>
15664<dt class="hdlist1"></dt>
15665<dd>
15666<p>gimage2D <em>image</em>, ivec2 <em>P</em></p>
15667</dd>
15668<dt class="hdlist1"></dt>
15669<dd>
15670<p>gimage3D <em>image</em>, ivec3 <em>P</em></p>
15671</dd>
15672<dt class="hdlist1"></dt>
15673<dd>
15674<p>gimageCube <em>image</em>, ivec3 <em>P</em></p>
15675</dd>
15676<dt class="hdlist1"></dt>
15677<dd>
15678<p>gimageBuffer <em>image</em>, int <em>P</em></p>
15679</dd>
15680<dt class="hdlist1"></dt>
15681<dd>
15682<p>gimage2DArray <em>image</em>, ivec3 <em>P</em></p>
15683</dd>
15684<dt class="hdlist1"></dt>
15685<dd>
15686<p>gimageCubeArray <em>image</em>, ivec3 <em>P</em></p>
15687</dd>
15688<dt class="hdlist1"></dt>
15689<dd>
15690<p>gimage1D <em>image</em>, int <em>P</em></p>
15691</dd>
15692<dt class="hdlist1"></dt>
15693<dd>
15694<p>gimage1DArray <em>image</em>, ivec2 <em>P</em></p>
15695</dd>
15696<dt class="hdlist1"></dt>
15697<dd>
15698<p>gimage2DRect <em>image</em>, ivec2 <em>P</em></p>
15699</dd>
15700<dt class="hdlist1"></dt>
15701<dd>
15702<p>gimage2DMS <em>image</em>, ivec2 <em>P</em>, int <em>sample</em></p>
15703</dd>
15704<dt class="hdlist1"></dt>
15705<dd>
15706<p>gimage2DMSArray <em>image</em>, ivec3 <em>P</em>, int <em>sample</em></p>
15707</dd>
15708</dl>
15709</div>
15710<div class="paragraph">
15711<p>where each of the lines represents one of three different image variable
15712types, and <em>image</em>,
15713<em>P</em>, and <em>sample</em>
15714specify the individual texel to operate on.
15715The method for identifying the individual texel operated on from <em>image</em>,
15716<em>P</em>,
15717and <em>sample</em>,
15718and the method for reading and writing the texel are specified in section
157198.26
15720&#8220;Texture Image Loads and Stores&#8221; of the <a href="#references">OpenGL Specification</a>.</p>
15721</div>
15722<div class="paragraph">
15723<p>The atomic functions perform operations on individual texels or samples of
15724an image variable.
15725Atomic memory operations read a value from the selected texel, compute a new
15726value using one of the operations described below, write the new value to
15727the selected texel, and return the original value read.
15728The contents of the texel being updated by the atomic operation are
15729guaranteed not to be modified by any other image store or atomic function
15730between the time the original value is read and the time the new value is
15731written.</p>
15732</div>
15733<div class="paragraph">
15734<p>Atomic memory operations are supported on only a subset of all image
15735variable types; <em>image</em> must be either:</p>
15736</div>
15737<div class="ulist">
15738<ul>
15739<li>
15740<p>a signed integer image variable (type starts &#8220;<strong>iimage</strong>&#8221;) and a format
15741qualifier of <strong>r32i</strong>, used with a <em>data</em> argument of type <strong>int</strong>, or</p>
15742</li>
15743<li>
15744<p>an unsigned integer image variable (type starts &#8220;<strong>uimage</strong>&#8221;) and a
15745format qualifier of <strong>r32ui</strong>, used with a <em>data</em> argument of type <strong>uint</strong>,
15746or</p>
15747</li>
15748<li>
15749<p>a float image variable (type starts &#8220;<strong>image</strong>&#8221;) and a format qualifier
15750of <strong>r32f</strong>, used with a <em>data</em> argument of type <strong>float</strong>
15751(<strong>imageAtomicExchange</strong> only).</p>
15752</li>
15753</ul>
15754</div>
15755<div class="paragraph">
15756<p>All the built-in functions in this section accept arguments with
15757combinations of <strong>restrict</strong>, <strong>coherent</strong>, and <strong>volatile</strong> memory qualification,
15758despite not having them listed in the prototypes.
15759The image operation will operate as required by the calling argument&#8217;s
15760memory qualification, not by the built-in function&#8217;s formal parameter memory
15761qualification.</p>
15762</div>
15763<table class="tableblock frame-all grid-all stretch">
15764<colgroup>
15765<col style="width: 50%;">
15766<col style="width: 50%;">
15767</colgroup>
15768<thead>
15769<tr>
15770<th class="tableblock halign-left valign-top">Syntax</th>
15771<th class="tableblock halign-left valign-top">Description</th>
15772</tr>
15773</thead>
15774<tbody>
15775<tr>
15776<td class="tableblock halign-left valign-top"><p class="tableblock">   int <strong>imageSize</strong>(readonly writeonly gimage1D <em>image</em>)<br>
15777   ivec2 <strong>imageSize</strong>(readonly writeonly gimage2D <em>image</em>)<br>
15778   ivec3 <strong>imageSize</strong>(readonly writeonly gimage3D <em>image</em>)<br>
15779   ivec2 <strong>imageSize</strong>(readonly writeonly gimageCube <em>image</em>)<br>
15780   ivec3 <strong>imageSize</strong>(readonly writeonly gimageCubeArray <em>image</em>)<br>
15781   ivec3 <strong>imageSize</strong>(readonly writeonly gimage2DArray <em>image</em>)<br>
15782   ivec2 <strong>imageSize</strong>(readonly writeonly gimageRect <em>image</em>)<br>
15783   ivec2 <strong>imageSize</strong>(readonly writeonly gimage1DArray <em>image</em>)<br>
15784   ivec2 <strong>imageSize</strong>(readonly writeonly gimage2DMS <em>image</em>)<br>
15785   ivec3 <strong>imageSize</strong>(readonly writeonly gimage2DMSArray <em>image</em>)<br>
15786     int <strong>imageSize</strong>(readonly writeonly gimageBuffer <em>image</em>)</p></td>
15787<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the dimensions of the image or images bound to <em>image</em>.
15788      For arrayed images, the last component of the return value will hold
15789      the size of the array.
15790      Cube images only return the dimensions of one face, and the number of
15791      cubes in the cube map array, if arrayed.<br>
15792      Note: The qualification <strong>readonly writeonly</strong> accepts a variable
15793      qualified with <strong>readonly</strong>, <strong>writeonly</strong>, both, or neither.
15794      It means the formal argument will be used for neither reading nor
15795      writing to the underlying memory.</p></td>
15796</tr>
15797<tr>
15798<td class="tableblock halign-left valign-top"><p class="tableblock">int <strong>imageSamples</strong>(readonly writeonly gimage2DMS <em>image</em>)<br>
15799  int <strong>imageSamples</strong>(readonly writeonly gimage2DMSArray <em>image</em>)</p></td>
15800<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the number of samples of the image or images bound to <em>image</em>.</p></td>
15801</tr>
15802<tr>
15803<td class="tableblock halign-left valign-top"><p class="tableblock"> gvec4 <strong>imageLoad</strong>(readonly <em>IMAGE_PARAMS</em>)</p></td>
15804<td class="tableblock halign-left valign-top"><p class="tableblock">Loads the texel at the coordinate <em>P</em> from the image unit <em>image</em> (in
15805      <em>IMAGE_PARAMS</em>).
15806      For multisample loads, the sample number is given by <em>sample</em>.
15807      When <em>image</em>, <em>P</em>, and <em>sample</em>
15808      identify a valid texel, the bits used to represent the selected texel in
15809      memory are converted to a <strong>vec4</strong>, <strong>ivec4</strong>, or <strong>uvec4</strong> in the manner
15810      described in section
158118.26
15812      &#8220;Texture Image Loads and Stores&#8221; of the
15813      <a href="#references">OpenGL Specification</a> and returned.</p></td>
15814</tr>
15815<tr>
15816<td class="tableblock halign-left valign-top"><p class="tableblock">void <strong>imageStore</strong>(writeonly <em>IMAGE_PARAMS</em>, gvec4 <em>data</em>)</p></td>
15817<td class="tableblock halign-left valign-top"><p class="tableblock">Stores <em>data</em> into the texel at the coordinate <em>P</em> from the image
15818      specified by <em>image</em>.
15819      For multisample stores, the sample number is given by <em>sample</em>.
15820      When <em>image</em>, <em>P</em>, and <em>sample</em>
15821      identify a valid texel, the bits used to represent <em>data</em> are converted
15822      to the format of the image unit in the manner described in section
158238.26
15824      &#8220;Texture Image Loads and Stores&#8221; of the <a href="#references">OpenGL Specification</a>
15825      and stored to the specified texel.</p></td>
15826</tr>
15827<tr>
15828<td class="tableblock halign-left valign-top"><p class="tableblock"> uint <strong>imageAtomicAdd</strong>(<em>IMAGE_PARAMS</em>, uint <em>data</em>)<br>
15829   int <strong>imageAtomicAdd</strong>(<em>IMAGE_PARAMS</em>, int <em>data</em>)</p></td>
15830<td class="tableblock halign-left valign-top"><p class="tableblock">Computes a new value by adding the value of <em>data</em> to the contents of
15831      the selected texel.</p></td>
15832</tr>
15833<tr>
15834<td class="tableblock halign-left valign-top"><p class="tableblock"> uint <strong>imageAtomicMin</strong>(<em>IMAGE_PARAMS</em>, uint <em>data</em>)<br>
15835   int <strong>imageAtomicMin</strong>(<em>IMAGE_PARAMS</em>, int <em>data</em>)</p></td>
15836<td class="tableblock halign-left valign-top"><p class="tableblock">Computes a new value by taking the minimum of the value of <em>data</em> and
15837      the contents of the selected texel.</p></td>
15838</tr>
15839<tr>
15840<td class="tableblock halign-left valign-top"><p class="tableblock"> uint <strong>imageAtomicMax</strong>(<em>IMAGE_PARAMS</em>, uint <em>data</em>)<br>
15841   int <strong>imageAtomicMax</strong>(<em>IMAGE_PARAMS</em>, int <em>data</em>)</p></td>
15842<td class="tableblock halign-left valign-top"><p class="tableblock">Computes a new value by taking the maximum of the value <em>data</em> and the
15843      contents of the selected texel.</p></td>
15844</tr>
15845<tr>
15846<td class="tableblock halign-left valign-top"><p class="tableblock"> uint <strong>imageAtomicAnd</strong>(<em>IMAGE_PARAMS</em>, uint <em>data</em>)<br>
15847   int <strong>imageAtomicAnd</strong>(<em>IMAGE_PARAMS</em>, int <em>data</em>)</p></td>
15848<td class="tableblock halign-left valign-top"><p class="tableblock">Computes a new value by performing a bit-wise AND of the value of
15849      <em>data</em> and the contents of the selected texel.</p></td>
15850</tr>
15851<tr>
15852<td class="tableblock halign-left valign-top"><p class="tableblock"> uint <strong>imageAtomicOr</strong>(<em>IMAGE_PARAMS</em>, uint <em>data</em>)<br>
15853   int <strong>imageAtomicOr</strong>(<em>IMAGE_PARAMS</em>, int <em>data</em>)</p></td>
15854<td class="tableblock halign-left valign-top"><p class="tableblock">Computes a new value by performing a bit-wise OR of the value of
15855      <em>data</em> and the contents of the selected texel.</p></td>
15856</tr>
15857<tr>
15858<td class="tableblock halign-left valign-top"><p class="tableblock"> uint <strong>imageAtomicXor</strong>(<em>IMAGE_PARAMS</em>, uint <em>data</em>)<br>
15859   int <strong>imageAtomicXor</strong>(<em>IMAGE_PARAMS</em>, int <em>data</em>)</p></td>
15860<td class="tableblock halign-left valign-top"><p class="tableblock">Computes a new value by performing a bit-wise EXCLUSIVE OR of the
15861      value of <em>data</em> and the contents of the selected texel.</p></td>
15862</tr>
15863<tr>
15864<td class="tableblock halign-left valign-top"><p class="tableblock"> uint <strong>imageAtomicExchange</strong>(<em>IMAGE_PARAMS</em>, uint <em>data</em>)<br>
15865   int <strong>imageAtomicExchange</strong>(<em>IMAGE_PARAMS</em>, int <em>data</em>)<br>
15866   float <strong>imageAtomicExchange</strong>(<em>IMAGE_PARAMS</em>, float <em>data</em>)</p></td>
15867<td class="tableblock halign-left valign-top"><p class="tableblock">Computes a new value by simply copying the value of <em>data</em>.</p></td>
15868</tr>
15869<tr>
15870<td class="tableblock halign-left valign-top"><p class="tableblock"> uint <strong>imageAtomicCompSwap</strong>(<em>IMAGE_PARAMS</em>, uint <em>compare</em>, uint <em>data</em>)<br>
15871   int <strong>imageAtomicCompSwap</strong>(<em>IMAGE_PARAMS</em>, int <em>compare</em>, int <em>data</em>)</p></td>
15872<td class="tableblock halign-left valign-top"><p class="tableblock">Compares the value of <em>compare</em> and the contents of the selected
15873      texel.
15874      If the values are equal, the new value is given by <em>data</em>; otherwise,
15875      it is taken from the original value loaded from the texel.</p></td>
15876</tr>
15877</tbody>
15878</table>
15879</div>
15880<div class="sect2">
15881<h3 id="geometry-shader-functions">8.13. Geometry Shader Functions</h3>
15882<div class="paragraph">
15883<p>These functions are only available in geometry shaders.
15884They are described in more depth following the table.</p>
15885</div>
15886<table class="tableblock frame-all grid-all stretch">
15887<colgroup>
15888<col style="width: 50%;">
15889<col style="width: 50%;">
15890</colgroup>
15891<thead>
15892<tr>
15893<th class="tableblock halign-left valign-top">Syntax</th>
15894<th class="tableblock halign-left valign-top">Description</th>
15895</tr>
15896</thead>
15897<tbody>
15898<tr>
15899<td class="tableblock halign-left valign-top"><p class="tableblock">void <strong>EmitStreamVertex</strong>(int <em>stream</em>)</p></td>
15900<td class="tableblock halign-left valign-top"><p class="tableblock">Emits the current values of output variables to the current output
15901      primitive on stream <em>stream</em>.
15902      The argument to <em>stream</em> must be a constant integral expression.
15903      On return from this call, the values of all output variables are
15904      undefined.<br>
15905      Can only be used if multiple output streams are supported.</p></td>
15906</tr>
15907<tr>
15908<td class="tableblock halign-left valign-top"><p class="tableblock">void <strong>EndStreamPrimitive</strong>(int <em>stream</em>)</p></td>
15909<td class="tableblock halign-left valign-top"><p class="tableblock">Completes the current output primitive on stream <em>stream</em> and starts a
15910      new one.
15911      The argument to <em>stream</em> must be a constant integral expression.
15912      No vertex is emitted.<br>
15913      Can only be used if multiple output streams are supported.</p></td>
15914</tr>
15915<tr>
15916<td class="tableblock halign-left valign-top"><p class="tableblock">void <strong>EmitVertex</strong>()<br></p></td>
15917<td class="tableblock halign-left valign-top"><p class="tableblock">Emits the current values of output variables to the current output
15918      primitive.
15919      When multiple output streams are supported, this is equivalent to
15920      calling <strong>EmitStreamVertex</strong>(0).<br>
15921      On return from this call, the values of output variables are
15922      undefined.</p></td>
15923</tr>
15924<tr>
15925<td class="tableblock halign-left valign-top"><p class="tableblock">void <strong>EndPrimitive</strong>()</p></td>
15926<td class="tableblock halign-left valign-top"><p class="tableblock">Completes the current output primitive and starts a new one.
15927      When multiple output streams are supported, this is equivalent to
15928      calling <strong>EndStreamPrimitive</strong>(0).<br>
15929      No vertex is emitted.</p></td>
15930</tr>
15931</tbody>
15932</table>
15933<div class="paragraph">
15934<p>The function <strong>EmitStreamVertex</strong>() specifies that a vertex is completed.
15935A vertex is added to the current output primitive in vertex stream <em>stream</em>
15936using the current values of all built-in and user-defined output variables
15937associated with <em>stream</em>.
15938The values of all output variables for all output streams are undefined
15939after a call to <strong>EmitStreamVertex</strong>().
15940If a geometry shader invocation has emitted more vertices than permitted by
15941the output layout qualifier <strong>max_vertices</strong>, the results of calling
15942<strong>EmitStreamVertex</strong>() are undefined.</p>
15943</div>
15944<div class="paragraph">
15945<p>The function <strong>EndStreamPrimitive</strong>() specifies that the current output
15946primitive for vertex stream <em>stream</em> is completed and a new output primitive
15947(of the same type) will be started by any subsequent <strong>EmitStreamVertex</strong>().
15948This function does not emit a vertex.
15949If the output layout is declared to be <strong>points</strong>, calling
15950<strong>EndStreamPrimitive</strong>() is optional.</p>
15951</div>
15952<div class="paragraph">
15953<p>A geometry shader starts with an output primitive containing no vertices for
15954each stream.
15955When a geometry shader terminates, the current output primitive for each
15956stream is automatically completed.
15957It is not necessary to call <strong>EndStreamPrimitive</strong>() if the geometry shader
15958writes only a single primitive.</p>
15959</div>
15960<div class="paragraph">
15961<p>Multiple output streams are supported only if the output primitive type is
15962declared to be <strong>points</strong>.
15963It is a compile-time or link-time error if a program contains a geometry
15964shader calling <strong>EmitStreamVertex</strong>() or <strong>EndStreamPrimitive</strong>() if its output
15965primitive type is not <strong>points</strong>.</p>
15966</div>
15967</div>
15968<div class="sect2">
15969<h3 id="fragment-processing-functions">8.14. Fragment Processing Functions</h3>
15970<div class="paragraph">
15971<p>Fragment processing functions are only available in fragment shaders.</p>
15972</div>
15973<div class="sect3">
15974<h4 id="derivative-functions">8.14.1. Derivative Functions</h4>
15975<div class="paragraph">
15976<p>Derivatives may be computationally expensive and/or numerically unstable.
15977Therefore, an implementation may approximate the true derivatives
15978by using a fast but not entirely accurate derivative computation.
15979Derivatives are undefined within non-uniform control flow.</p>
15980</div>
15981<div class="paragraph">
15982<p>The expected behavior of a derivative is specified using forward/backward
15983differencing.</p>
15984</div>
15985<div class="paragraph">
15986<p>Forward differencing:</p>
15987</div>
15988<div class="paragraph">
15989<p>\(F(x+dx) - F(x) \sim dFdx(x) \cdot dx (1a)\)</p>
15990</div>
15991<div class="paragraph">
15992<p>\(dFdx(x) \sim \frac{F(x+dx) - F(x)}{dx} (1b)\)</p>
15993</div>
15994<div class="paragraph">
15995<p>Backward differencing:</p>
15996</div>
15997<div class="paragraph">
15998<p>\(F(x-dx) - F(x) \sim -dFdx(x) \cdot dx (2a)\)</p>
15999</div>
16000<div class="paragraph">
16001<p>\(dFdx(x) \sim \frac{F(x) - F(x-dx)}{dx} (2b)\)</p>
16002</div>
16003<div class="paragraph">
16004<p>With single-sample rasterization, \(dx \leq 1.0\) in equations 1b
16005and 2b.
16006For multisample rasterization, \(dx &lt; 2.0\) in equations 1b and 2b.</p>
16007</div>
16008<div class="paragraph">
16009<p>\(dFdy\) is approximated similarly, with <em>y</em> replacing <em>x</em>.</p>
16010</div>
16011<div class="paragraph">
16012<p>With multisample rasterization, for any given fragment or sample, either
16013neighboring fragments or samples may be considered.</p>
16014</div>
16015<div class="paragraph">
16016<p>It is typical to consider a 2x2 square of fragments or samples, and compute
16017independent <strong>dFdxFine</strong> per row and independent <strong>dFdyFine</strong> per column, while
16018computing only a single <strong>dFdxCoarse</strong> and a single <strong>dFdyCoarse</strong> for the
16019entire 2x2 square.
16020Thus, all second-order coarse derivatives, e.g.
16021<strong>dFdxCoarse</strong>(<strong>dFdxCoarse</strong>(<em>x</em>)), may be 0, even for non-linear arguments.
16022However, second-order fine derivatives, e.g. <strong>dFdxFine</strong>(<strong>dFdyFine</strong>(<em>x</em>))
16023will properly reflect the difference between the independent fine
16024derivatives computed within the 2x2 square.</p>
16025</div>
16026<div class="paragraph">
16027<p>The method may differ per fragment, subject to the constraint that the
16028method may vary by window coordinates, not screen coordinates.
16029The invariance requirement described in section 14.2 &#8220;Invariance&#8221; of the
16030<a href="#references">OpenGL Specification</a>, is relaxed for derivative calculations, because
16031the method may be a function of fragment location.</p>
16032</div>
16033<div class="paragraph">
16034<p>In some implementations, varying degrees of derivative accuracy for <strong>dFdx</strong>
16035and <strong>dFdy</strong> may be obtained by providing GL hints (see section 21.4 &#8220;Hints&#8221;
16036of the <a href="#references">OpenGL Specification</a>), allowing a user to make an image quality
16037versus speed trade off.
16038These hints have no effect on <strong>dFdxCoarse</strong>, <strong>dFdyCoarse</strong>, <strong>dFdxFine</strong> and
16039<strong>dFdyFine</strong>.</p>
16040</div>
16041<table class="tableblock frame-all grid-all stretch">
16042<colgroup>
16043<col style="width: 50%;">
16044<col style="width: 50%;">
16045</colgroup>
16046<thead>
16047<tr>
16048<th class="tableblock halign-left valign-top">Syntax</th>
16049<th class="tableblock halign-left valign-top">Description</th>
16050</tr>
16051</thead>
16052<tbody>
16053<tr>
16054<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>dFdx</strong>(genFType <em>p</em>)</p></td>
16055<td class="tableblock halign-left valign-top"><p class="tableblock">Returns either <strong>dFdxFine</strong>(<em>p</em>) or <strong>dFdxCoarse</strong>(<em>p</em>), based on
16056      implementation choice, presumably whichever is the faster, or by whichever
16057      is selected in the API through quality-versus-speed hints.</p></td>
16058</tr>
16059<tr>
16060<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>dFdy</strong>(genFType <em>p</em>)</p></td>
16061<td class="tableblock halign-left valign-top"><p class="tableblock">Returns either <strong>dFdyFine</strong>(<em>p</em>) or <strong>dFdyCoarse</strong>(<em>p</em>), based on
16062      implementation choice, presumably whichever is the faster, or by
16063      whichever is selected in the API through quality-versus-speed hints.</p></td>
16064</tr>
16065<tr>
16066<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>dFdxFine</strong>(genFType <em>p</em>)</p></td>
16067<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the partial derivative of <em>p</em> with respect to the window x
16068      coordinate.
16069      Will use local differencing based on the value of <em>p</em> for the current
16070      fragment and its immediate neighbor(s).</p></td>
16071</tr>
16072<tr>
16073<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>dFdyFine</strong>(genFType <em>p</em>)</p></td>
16074<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the partial derivative of <em>p</em> with respect to the window y
16075      coordinate.
16076      Will use local differencing based on the value of <em>p</em> for the current
16077      fragment and its immediate neighbor(s).</p></td>
16078</tr>
16079<tr>
16080<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>dFdxCoarse</strong>(genFType <em>p</em>)</p></td>
16081<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the partial derivative of <em>p</em> with respect to the window x
16082      coordinate.
16083      Will use local differencing based on the value of <em>p</em> for the current
16084      fragment&#8217;s neighbors, and will possibly, but not necessarily, include
16085      the value of <em>p</em> for the current fragment.
16086      That is, over a given area, the implementation can x compute
16087      derivatives in fewer unique locations than would be allowed for
16088      <strong>dFdxFine</strong>(<em>p</em>).</p></td>
16089</tr>
16090<tr>
16091<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>dFdyCoarse</strong>(genFType <em>p</em>)</p></td>
16092<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the partial derivative of <em>p</em> with respect to the window y
16093      coordinate.
16094      Will use local differencing based on the value of <em>p</em> for the current
16095      fragment&#8217;s neighbors, and will possibly, but not necessarily, include
16096      the value of <em>p</em> for the current fragment.
16097      That is, over a given area, the implementation can compute y
16098      derivatives in fewer unique locations than would be allowed for
16099      <strong>dFdyFine</strong>(<em>p</em>).</p></td>
16100</tr>
16101<tr>
16102<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>fwidth</strong>(genFType <em>p</em>)</p></td>
16103<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <strong>abs</strong>(<strong>dFdx</strong>(<em>p</em>)) + <strong>abs</strong>(<strong>dFdy</strong>(<em>p</em>)).</p></td>
16104</tr>
16105<tr>
16106<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>fwidthFine</strong>(genFType <em>p</em>)</p></td>
16107<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <strong>abs</strong>(<strong>dFdxFine</strong>(<em>p</em>)) + <strong>abs</strong>(<strong>dFdyFine</strong>(<em>p</em>)).</p></td>
16108</tr>
16109<tr>
16110<td class="tableblock halign-left valign-top"><p class="tableblock">genFType <strong>fwidthCoarse</strong>(genFType <em>p</em>)</p></td>
16111<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <strong>abs</strong>(<strong>dFdxCoarse</strong>(<em>p</em>)) + <strong>abs</strong>(<strong>dFdyCoarse</strong>(<em>p</em>)).</p></td>
16112</tr>
16113</tbody>
16114</table>
16115</div>
16116<div class="sect3">
16117<h4 id="interpolation-functions">8.14.2. Interpolation Functions</h4>
16118<div class="paragraph">
16119<p>Built-in interpolation functions are available to compute an interpolated
16120value of a fragment shader input variable at a shader-specified (<em>x</em>, <em>y</em>)
16121location.
16122A separate (<em>x</em>, <em>y</em>) location may be used for each invocation of the
16123built-in function, and those locations may differ from the default (<em>x</em>,
16124<em>y</em>) location used to produce the default value of the input.</p>
16125</div>
16126<div class="paragraph">
16127<p>For all of the interpolation functions, <em>interpolant</em> must be an l-value
16128from an <strong>in</strong> declaration;
16129this can include a variable, a block or structure member, an array element, or
16130some combination of these.
16131Additionally, component selection operators (e.g. <strong>.xy</strong>, <strong>.xxz</strong>) may be applied
16132to <em>interpolant</em>, in which case the interpolation function will return the
16133result of applying the component selection operator to the interpolated value
16134of <em>interpolant</em> (for example, interpolateAt(v.xxz) is defined to return
16135interpolateAt(v).xxz).
16136Arrayed inputs can be indexed with general (nonuniform) integer expressions.</p>
16137</div>
16138<div class="paragraph">
16139<p>If <em>interpolant</em> is declared with the <strong>flat</strong> qualifier, the interpolated
16140value will have the same value everywhere for a single primitive, so the
16141location used for interpolation has no effect and the functions just return
16142that same value.
16143If <em>interpolant</em> is declared with the <strong>centroid</strong> qualifier, the value
16144returned by <strong>interpolateAtSample</strong>() and <strong>interpolateAtOffset</strong>() will be
16145evaluated at the specified location, ignoring the location normally used
16146with the <strong>centroid</strong> qualifier.
16147If <em>interpolant</em> is declared with the <strong>noperspective</strong> qualifier, the
16148interpolated value will be computed without perspective correction.</p>
16149</div>
16150<table class="tableblock frame-all grid-all stretch">
16151<colgroup>
16152<col style="width: 50%;">
16153<col style="width: 50%;">
16154</colgroup>
16155<thead>
16156<tr>
16157<th class="tableblock halign-left valign-top">Syntax</th>
16158<th class="tableblock halign-left valign-top">Description</th>
16159</tr>
16160</thead>
16161<tbody>
16162<tr>
16163<td class="tableblock halign-left valign-top"><p class="tableblock">float <strong>interpolateAtCentroid</strong>(float <em>interpolant</em>)<br>
16164  vec2 <strong>interpolateAtCentroid</strong>(vec2 <em>interpolant</em>)<br>
16165  vec3 <strong>interpolateAtCentroid</strong>(vec3 <em>interpolant</em>)<br>
16166  vec4 <strong>interpolateAtCentroid</strong>(vec4 <em>interpolant</em>)</p></td>
16167<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the value of the input <em>interpolant</em> sampled at a location
16168      inside both the pixel and the primitive being processed.
16169      The value obtained would be the same value assigned to the input
16170      variable if declared with the <strong>centroid</strong> qualifier.</p></td>
16171</tr>
16172<tr>
16173<td class="tableblock halign-left valign-top"><p class="tableblock">float <strong>interpolateAtSample</strong>(float <em>interpolant</em>, int <em>sample</em>)<br>
16174  vec2 <strong>interpolateAtSample</strong>(vec2 <em>interpolant</em>, int <em>sample</em>)<br>
16175  vec3 <strong>interpolateAtSample</strong>(vec3 <em>interpolant</em>, int <em>sample</em>)<br>
16176  vec4 <strong>interpolateAtSample</strong>(vec4 <em>interpolant</em>, int <em>sample</em>)</p></td>
16177<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the value of the input <em>interpolant</em> variable at the location
16178      of sample number <em>sample</em>.
16179      If multisample buffers are not available, the input variable will be
16180      evaluated at the center of the pixel.
16181      If sample <em>sample</em> does not exist, the position used to interpolate
16182      the input variable is undefined.</p></td>
16183</tr>
16184<tr>
16185<td class="tableblock halign-left valign-top"><p class="tableblock">float <strong>interpolateAtOffset</strong>(float <em>interpolant</em>, vec2 offset)<br>
16186  vec2 <strong>interpolateAtOffset</strong>(vec2 <em>interpolant</em>, vec2 offset)<br>
16187  vec3 <strong>interpolateAtOffset</strong>(vec3 <em>interpolant</em>, vec2 offset)<br>
16188  vec4 <strong>interpolateAtOffset</strong>(vec4 <em>interpolant</em>, vec2 offset)</p></td>
16189<td class="tableblock halign-left valign-top"><p class="tableblock">Returns the value of the input <em>interpolant</em> variable sampled at an
16190      offset from the center of the pixel specified by <em>offset</em>.
16191      The two floating-point components of <em>offset</em>, give the offset in
16192      pixels in the <em>x</em> and <em>y</em> directions, respectively.<br>
16193      An offset of (0, 0) identifies the center of the pixel.
16194      The range and granularity of offsets supported by this function is
16195      implementation-dependent.</p></td>
16196</tr>
16197</tbody>
16198</table>
16199</div>
16200</div>
16201<div class="sect2">
16202<h3 id="noise-functions">8.15. Noise Functions</h3>
16203<div class="paragraph">
16204<p>The noise functions <strong>noise1</strong>, <strong>noise2</strong>, <strong>noise3</strong>, and <strong>noise4</strong> have been
16205deprecated starting with version 4.4 of GLSL.
16206When not generating SPIR-V they are defined to return the value 0.0 or a vector
16207whose components are all 0.0. When generating SPIR-V the noise functions are
16208not declared and may not be used.</p>
16209</div>
16210<div class="paragraph">
16211<p>As in previous releases, the noise functions are not semantically considered to
16212be compile-time constant expressions.</p>
16213</div>
16214<table class="tableblock frame-all grid-all stretch">
16215<colgroup>
16216<col style="width: 50%;">
16217<col style="width: 50%;">
16218</colgroup>
16219<thead>
16220<tr>
16221<th class="tableblock halign-left valign-top">Syntax (deprecated)</th>
16222<th class="tableblock halign-left valign-top">Description (deprecated)</th>
16223</tr>
16224</thead>
16225<tbody>
16226<tr>
16227<td class="tableblock halign-left valign-top"><p class="tableblock">float <strong>noise1</strong>(genFType <em>x</em>)</p></td>
16228<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a 1D noise value based on the input value <em>x</em>.</p></td>
16229</tr>
16230<tr>
16231<td class="tableblock halign-left valign-top"><p class="tableblock">vec2 <strong>noise2</strong>(genFType <em>x</em>)</p></td>
16232<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a 2D noise value based on the input value <em>x</em>.</p></td>
16233</tr>
16234<tr>
16235<td class="tableblock halign-left valign-top"><p class="tableblock">vec3 <strong>noise3</strong>(genFType <em>x</em>)</p></td>
16236<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a 3D noise value based on the input value <em>x</em>.</p></td>
16237</tr>
16238<tr>
16239<td class="tableblock halign-left valign-top"><p class="tableblock">vec4 <strong>noise4</strong>(genFType <em>x</em>)</p></td>
16240<td class="tableblock halign-left valign-top"><p class="tableblock">Returns a 4D noise value based on the input value <em>x</em>.</p></td>
16241</tr>
16242</tbody>
16243</table>
16244</div>
16245<div class="sect2">
16246<h3 id="shader-invocation-control-functions">8.16. Shader Invocation Control Functions</h3>
16247<div class="paragraph">
16248<p>The shader invocation control function is only available in tessellation
16249control and compute shaders.
16250It is used to control the relative execution order of multiple shader
16251invocations used to process a patch (in the case of tessellation control
16252shaders) or a workgroup (in the case of compute shaders), which are
16253otherwise executed with an undefined relative order.</p>
16254</div>
16255<table class="tableblock frame-all grid-all stretch">
16256<colgroup>
16257<col style="width: 50%;">
16258<col style="width: 50%;">
16259</colgroup>
16260<thead>
16261<tr>
16262<th class="tableblock halign-left valign-top">Syntax</th>
16263<th class="tableblock halign-left valign-top">Description</th>
16264</tr>
16265</thead>
16266<tbody>
16267<tr>
16268<td class="tableblock halign-left valign-top"><p class="tableblock">void <strong>barrier</strong>()</p></td>
16269<td class="tableblock halign-left valign-top"><p class="tableblock">For any given static instance of <strong>barrier</strong>(), all tessellation control
16270      shader invocations for a single input patch must enter it before any
16271      will be allowed to continue beyond it, or all compute shader
16272      invocations for a single workgroup must enter it before any will
16273      continue beyond it.</p></td>
16274</tr>
16275</tbody>
16276</table>
16277<div class="paragraph">
16278<p>The function <strong>barrier</strong>() provides a partially defined order of execution
16279between shader invocations.
16280The ensures that, for some types of memory accesses, values written by one
16281invocation prior to a given static instance of <strong>barrier</strong>() can be safely read
16282by other invocations after their call to the same static instance <strong>barrier</strong>().
16283Because invocations may execute in an undefined order between these barrier
16284calls, the values of a per-vertex or per-patch output variable for tessellation
16285control shaders, or the values of <strong>shared</strong> variables for compute shaders will be
16286undefined in a number of cases enumerated in
16287&#8220;<a href="#output-variables">Output Variables</a>&#8221; (for tessellation control shaders)
16288and &#8220;<a href="#shared-variables">Shared Variables</a>&#8221; (for compute shaders).</p>
16289</div>
16290<div class="paragraph">
16291<p>For tessellation control shaders, the <strong>barrier</strong>() function may only be
16292placed inside the function <strong>main</strong>() of the shader and may not be called
16293within any control flow.
16294Barriers are also disallowed after a return statement in the function
16295<strong>main</strong>().
16296Any such misplaced barriers result in a compile-time error.</p>
16297</div>
16298<div class="paragraph">
16299<p>A <strong>barrier</strong>() affects control flow but only synchronizes memory accesses
16300to <strong>shared</strong> variables and tessellation control output variables.
16301For other memory accesses, it does not ensure that values written by one invocation
16302prior to a given static instance of <strong>barrier</strong>() can be safely read by other
16303invocations after their call to the same static instance of <strong>barrier</strong>().
16304To achieve this requires the use of both <strong>barrier</strong>() and a memory barrier.</p>
16305</div>
16306<div class="paragraph">
16307<p>For compute shaders, the <strong>barrier</strong>() function may be placed within control
16308flow, but that control flow must be uniform control flow.
16309That is, all the controlling expressions that lead to execution of the
16310barrier must be dynamically uniform expressions.
16311This ensures that if any shader invocation enters a conditional statement,
16312then all invocations will enter it.
16313While compilers are encouraged to give warnings if they can detect this
16314might not happen, compilers cannot completely determine this.
16315Hence, it is the author&#8217;s responsibility to ensure <strong>barrier</strong>() only exists
16316inside uniform control flow.
16317Otherwise, some shader invocations will stall indefinitely, waiting for a
16318barrier that is never reached by other invocations.</p>
16319</div>
16320</div>
16321<div class="sect2">
16322<h3 id="shader-memory-control-functions">8.17. Shader Memory Control Functions</h3>
16323<div class="paragraph">
16324<p>Within a single shader invocation, the visibility and order of writes made
16325by that invocation are well-defined.
16326However, the relative order of reads and writes to a single shared memory
16327address from multiple separate shader invocations is largely undefined.
16328Additionally, the order of accesses to multiple memory addresses performed
16329by a single shader invocation, as observed by other shader invocations, is
16330also undefined.</p>
16331</div>
16332<div class="paragraph">
16333<p>The following built-in functions can be used to control the ordering of
16334reads and writes:</p>
16335</div>
16336<table class="tableblock frame-all grid-all stretch">
16337<colgroup>
16338<col style="width: 50%;">
16339<col style="width: 50%;">
16340</colgroup>
16341<thead>
16342<tr>
16343<th class="tableblock halign-left valign-top">Syntax</th>
16344<th class="tableblock halign-left valign-top">Description</th>
16345</tr>
16346</thead>
16347<tbody>
16348<tr>
16349<td class="tableblock halign-left valign-top"><p class="tableblock">void <strong>memoryBarrier</strong>()</p></td>
16350<td class="tableblock halign-left valign-top"><p class="tableblock">Control the ordering of memory transactions issued by a single shader
16351      invocation.</p></td>
16352</tr>
16353<tr>
16354<td class="tableblock halign-left valign-top"><p class="tableblock">void <strong>memoryBarrierAtomicCounter</strong>()</p></td>
16355<td class="tableblock halign-left valign-top"><p class="tableblock">Control the ordering of accesses to atomic-counter variables issued by
16356      a single shader invocation.</p></td>
16357</tr>
16358<tr>
16359<td class="tableblock halign-left valign-top"><p class="tableblock">void <strong>memoryBarrierBuffer</strong>()</p></td>
16360<td class="tableblock halign-left valign-top"><p class="tableblock">Control the ordering of memory transactions to buffer variables issued
16361      within a single shader invocation.</p></td>
16362</tr>
16363<tr>
16364<td class="tableblock halign-left valign-top"><p class="tableblock">void <strong>memoryBarrierShared</strong>()</p></td>
16365<td class="tableblock halign-left valign-top"><p class="tableblock">Control the ordering of memory transactions to shared variables issued
16366      within a single shader invocation, as viewed by other invocations in
16367      the same workgroup.<br>
16368      Only available in compute shaders.</p></td>
16369</tr>
16370<tr>
16371<td class="tableblock halign-left valign-top"><p class="tableblock">void <strong>memoryBarrierImage</strong>()</p></td>
16372<td class="tableblock halign-left valign-top"><p class="tableblock">Control the ordering of memory transactions to images issued within a
16373      single shader invocation.</p></td>
16374</tr>
16375<tr>
16376<td class="tableblock halign-left valign-top"><p class="tableblock">void <strong>groupMemoryBarrier</strong>()</p></td>
16377<td class="tableblock halign-left valign-top"><p class="tableblock">Control the ordering of all memory transactions issued within a single
16378      shader invocation, as viewed by other invocations in the same workgroup.<br>
16379      Only available in compute shaders.</p></td>
16380</tr>
16381</tbody>
16382</table>
16383<div class="paragraph">
16384<p>The memory barrier built-in functions can be used to order reads and writes
16385to variables stored in memory accessible to other shader invocations.
16386When called, these functions will wait for the completion of all reads and
16387writes previously performed by the caller that access selected variable
16388types, and then return with no other effect.
16389The built-in functions <strong>memoryBarrierAtomicCounter</strong>(),
16390<strong>memoryBarrierBuffer</strong>(), <strong>memoryBarrierImage</strong>(), and <strong>memoryBarrierShared</strong>()
16391wait for the completion of accesses to atomic counter, buffer, image, and
16392shared variables, respectively.
16393The built-in functions <strong>memoryBarrier</strong>() and <strong>groupMemoryBarrier</strong>() wait for
16394the completion of accesses to all of the above variable types.
16395The functions <strong>memoryBarrierShared</strong>() and <strong>groupMemoryBarrier</strong>() are
16396available only in compute shaders; the other functions are available in all
16397shader types.</p>
16398</div>
16399<div class="paragraph">
16400<p>When these functions return, the effects of any memory stores performed
16401using coherent variables prior to the call will be visible to any
16402future<sup>1</sup> coherent access to the same memory performed by any other shader
16403invocation.
16404In particular, the values written this way in one shader stage are
16405guaranteed to be visible to coherent memory accesses performed by shader
16406invocations in subsequent stages when those invocations were triggered by
16407the execution of the original shader invocation (e.g. fragment shader
16408invocations for a primitive resulting from a particular geometry
16409shader invocation).</p>
16410</div>
16411<div class="dlist">
16412<dl>
16413<dt class="hdlist1">1</dt>
16414<dd>
16415<p>An access is only a <em>future</em> access if a <em>happens-before</em> relation can
16416be established between the store and the load.</p>
16417</dd>
16418</dl>
16419</div>
16420<div class="paragraph">
16421<p>Additionally, memory barrier functions order stores performed by the calling
16422invocation, as observed by other shader invocations.
16423Without memory barriers, if one shader invocation performs two stores to
16424coherent variables, a second shader invocation might see the values written
16425by the second store prior to seeing those written by the first.
16426However, if the first shader invocation calls a memory barrier function
16427between the two stores, selected other shader invocations will never see the
16428results of the second store before seeing those of the first.
16429When using the functions <strong>groupMemoryBarrier</strong>() or <strong>memoryBarrierShared</strong>(),
16430this ordering guarantee applies only to other shader invocations in the same
16431compute shader workgroup; all other memory barrier functions provide the
16432guarantee to all other shader invocations.
16433No memory barrier is required to guarantee the order of memory stores as
16434observed by the invocation performing the stores; an invocation reading from
16435a variable that it previously wrote will always see the most recently
16436written value unless another shader invocation also wrote to the same
16437memory.</p>
16438</div>
16439</div>
16440<div class="sect2">
16441<h3 id="_subpass_input_functions">8.18. Subpass-Input Functions</h3>
16442<div class="paragraph">
16443<p>Subpass-input functions are only available when targeting a Vulkan fragment stage.</p>
16444</div>
16445<div class="paragraph">
16446<p>Subpass inputs are read through the built-in functions below. The <code>g</code> is again
16447a placeholder for either nothing, <code>i</code>, or <code>u</code>, indicating either a floating-point,
16448signed integer, or unsigned integer, and these must match between argument type
16449and return type.</p>
16450</div>
16451<table class="tableblock frame-all grid-all stretch">
16452<colgroup>
16453<col style="width: 50%;">
16454<col style="width: 50%;">
16455</colgroup>
16456<thead>
16457<tr>
16458<th class="tableblock halign-left valign-top">Syntax</th>
16459<th class="tableblock halign-left valign-top">Description</th>
16460</tr>
16461</thead>
16462<tbody>
16463<tr>
16464<td class="tableblock halign-left valign-top"><p class="tableblock">gvec4 <strong>subpassLoad</strong>(gsubpassInput subpass)<br>
16465  gvec4 <strong>subpassLoad</strong>(gsubpassInputMS subpass, int sample)</p></td>
16466<td class="tableblock halign-left valign-top"><p class="tableblock">Read from a subpass input, from the implicit location <em>(x, y, layer)</em>
16467      of the current fragment coordinate.</p></td>
16468</tr>
16469</tbody>
16470</table>
16471</div>
16472<div class="sect2">
16473<h3 id="shader-invocation-group-functions">8.19. Shader Invocation Group Functions</h3>
16474<div class="paragraph">
16475<p>Implementations of the OpenGL Shading Language may optionally group multiple shader
16476invocations for a single shader stage into a single SIMD invocation group,
16477where invocations are assigned to groups in an undefined,
16478implementation-dependent manner.
16479Shader algorithms on such implementations may benefit from being able to
16480evaluate a composite of Boolean values over all active invocations in a
16481group.</p>
16482</div>
16483<table class="tableblock frame-all grid-all stretch">
16484<colgroup>
16485<col style="width: 50%;">
16486<col style="width: 50%;">
16487</colgroup>
16488<thead>
16489<tr>
16490<th class="tableblock halign-left valign-top">Syntax</th>
16491<th class="tableblock halign-left valign-top">Description</th>
16492</tr>
16493</thead>
16494<tbody>
16495<tr>
16496<td class="tableblock halign-left valign-top"><p class="tableblock">bool <strong>anyInvocation</strong>(bool <em>value</em>)</p></td>
16497<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <strong>true</strong> if and only if <em>value</em> is <strong>true</strong> for at least one
16498      active invocation in the group.</p></td>
16499</tr>
16500<tr>
16501<td class="tableblock halign-left valign-top"><p class="tableblock">bool <strong>allInvocations</strong>(bool <em>value</em>)</p></td>
16502<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <strong>true</strong> if and only if <em>value</em> is <strong>true</strong> for all active
16503      invocations in the group.</p></td>
16504</tr>
16505<tr>
16506<td class="tableblock halign-left valign-top"><p class="tableblock">bool <strong>allInvocationsEqual</strong>(bool <em>value</em>)</p></td>
16507<td class="tableblock halign-left valign-top"><p class="tableblock">Returns <strong>true</strong> if <em>value</em> is the same for all active invocations in
16508      the group.</p></td>
16509</tr>
16510</tbody>
16511</table>
16512<div class="paragraph">
16513<p>For all of these functions, the same result is returned to all active
16514invocations in the group.</p>
16515</div>
16516<div class="paragraph">
16517<p>These functions may be called within conditionally executed code.
16518In groups where some invocations do not execute the function call, the value
16519returned by the function is not affected by any invocation not calling the
16520function, even when value is well-defined for that invocation.</p>
16521</div>
16522<div class="paragraph">
16523<p>Because these functions depend on the values of <em>value</em> in an undefined
16524group of invocations, the value returned by these functions is largely
16525undefined.
16526However, <strong>anyInvocation</strong>() is guaranteed to return <strong>true</strong> if <em>value</em> is
16527<strong>true</strong>, and <strong>allInvocations</strong>() is guaranteed to return <strong>false</strong> if <em>value</em> is
16528<strong>false</strong>.</p>
16529</div>
16530<div class="paragraph">
16531<p>Because implementations are not required to combine invocations into groups,
16532simply returning <em>value</em> for <strong>anyInvocation</strong>() and <strong>allInvocations</strong>() and
16533returning true for <strong>allInvocationsEqual</strong>() is a legal implementation of
16534these functions.</p>
16535</div>
16536<div class="paragraph">
16537<p>For fragment shaders, invocations in a SIMD invocation group may include
16538invocations corresponding to pixels that are covered by a primitive being
16539rasterized, as well as invocations corresponding to neighboring pixels not
16540covered by the primitive.
16541<em>Helper invocations</em> (see &#8220;<a href="#built-in-language-variables">Built-In Language
16542Variables</a>&#8221;) may be created and the value of <em>value</em> for such
16543helper-invocation pixels may affect the value returned by <strong>anyInvocation</strong>(),
16544<strong>allInvocations</strong>(), and <strong>allInvocationsEqual</strong>().</p>
16545</div>
16546</div>
16547</div>
16548</div>
16549<div class="sect1">
16550<h2 id="shading-language-grammar">9. Shading Language Grammar</h2>
16551<div class="sectionbody">
16552<div class="paragraph">
16553<p>The grammar is fed from the output of lexical analysis.
16554The tokens returned from lexical analysis are</p>
16555</div>
16556<div class="openblock bnf">
16557<div class="content">
16558<div class="paragraph">
16559<p>CONST BOOL FLOAT INT UINT
16560DOUBLE</p>
16561</div>
16562<div class="paragraph">
16563<p>BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4</p>
16564</div>
16565<div class="paragraph">
16566<p>MAT2 MAT3 MAT4
16567MAT2X2 MAT2X3 MAT2X4
16568MAT3X2 MAT3X3 MAT3X4
16569MAT4X2 MAT4X3 MAT4X4</p>
16570</div>
16571<div class="paragraph">
16572<p>DVEC2 DVEC3 DVEC4 DMAT2 DMAT3 DMAT4
16573DMAT2X2 DMAT2X3 DMAT2X4
16574DMAT3X2 DMAT3X3 DMAT3X4
16575DMAT4X2 DMAT4X3 DMAT4X4</p>
16576</div>
16577<div class="paragraph">
16578<p>CENTROID IN OUT INOUT UNIFORM PATCH SAMPLE BUFFER SHARED
16579COHERENT VOLATILE RESTRICT READONLY WRITEONLY
16580NOPERSPECTIVE
16581FLAT SMOOTH LAYOUT</p>
16582</div>
16583<div class="paragraph">
16584<p>ATOMIC_UINT</p>
16585</div>
16586<div class="paragraph">
16587<p>SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER2DSHADOW
16588SAMPLERCUBESHADOW SAMPLER2DARRAY SAMPLER2DARRAYSHADOW
16589ISAMPLER2D ISAMPLER3D ISAMPLERCUBE ISAMPLER2DARRAY
16590USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER2DARRAY</p>
16591</div>
16592<div class="paragraph">
16593<p>SAMPLER1D SAMPLER1DSHADOW
16594SAMPLER1DARRAY SAMPLER1DARRAYSHADOW
16595ISAMPLER1D ISAMPLER1DARRAY
16596USAMPLER1D USAMPLER1DARRAY
16597SAMPLER2DRECT SAMPLER2DRECTSHADOW ISAMPLER2DRECT USAMPLER2DRECT</p>
16598</div>
16599<div class="paragraph">
16600<p>SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
16601SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
16602ISAMPLERCUBEARRAY USAMPLERCUBEARRAY
16603SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
16604SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
16605IMAGE2D IIMAGE2D UIMAGE2D
16606IMAGE3D IIMAGE3D UIMAGE3D
16607IMAGECUBE IIMAGECUBE UIMAGECUBE
16608IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
16609IMAGE2DARRAY IIMAGE2DARRAY UIMAGE2DARRAY
16610IMAGECUBEARRAY IIMAGECUBEARRAY UIMAGECUBEARRAY</p>
16611</div>
16612<div class="paragraph">
16613<p>IMAGE1D IIMAGE1D UIMAGE1D
16614IMAGE1DARRAY IIMAGE1DARRAY UIMAGE1DARRAY
16615IMAGE2DRECT IIMAGE2DRECT UIMAGE2DRECT
16616IMAGE2DMS IIMAGE2DMS UIMAGE2DMS
16617IMAGE2DMSARRAY IIMAGE2DMSARRAY UIMAGE2DMSARRAY</p>
16618</div>
16619<div class="paragraph">
16620<p>STRUCT VOID</p>
16621</div>
16622<div class="paragraph">
16623<p>WHILE BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
16624SUBROUTINE</p>
16625</div>
16626<div class="paragraph">
16627<p>IDENTIFIER TYPE_NAME
16628FLOATCONSTANT INTCONSTANT UINTCONSTANT BOOLCONSTANT
16629DOUBLECONSTANT
16630FIELD_SELECTION</p>
16631</div>
16632<div class="paragraph">
16633<p>LEFT_OP RIGHT_OP
16634INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
16635AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
16636MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
16637SUB_ASSIGN
16638LEFT_PAREN RIGHT_PAREN LEFT_BRACKET RIGHT_BRACKET LEFT_BRACE RIGHT_BRACE DOT
16639COMMA COLON EQUAL SEMICOLON BANG DASH TILDE PLUS STAR SLASH PERCENT
16640LEFT_ANGLE RIGHT_ANGLE VERTICAL_BAR CARET AMPERSAND QUESTION</p>
16641</div>
16642<div class="paragraph">
16643<p>INVARIANT PRECISE
16644HIGH_PRECISION MEDIUM_PRECISION LOW_PRECISION PRECISION</p>
16645</div>
16646</div>
16647</div>
16648<div class="paragraph">
16649<p>The following describes the grammar for the OpenGL Shading Language in terms of the above
16650tokens.
16651The starting rule is <em>translation_unit</em>.
16652An empty shader (one having no tokens to parse, after pre-processing) is
16653valid, resulting in no compile-time errors, even though the grammar below
16654does not have a rule to accept an empty token stream.</p>
16655</div>
16656<div class="openblock bnf">
16657<div class="content">
16658<div class="dlist">
16659<dl>
16660<dt class="hdlist1"><em>variable_identifier</em> : </dt>
16661<dd>
16662<p><em>IDENTIFIER</em></p>
16663</dd>
16664<dt class="hdlist1"><em>primary_expression</em> : </dt>
16665<dd>
16666<p><em>variable_identifier</em><br>
16667<em>INTCONSTANT</em><br>
16668<em>UINTCONSTANT</em><br>
16669<em>FLOATCONSTANT</em><br>
16670<em>BOOLCONSTANT</em><br>
16671<em>DOUBLECONSTANT</em><br>
16672<em>LEFT_PAREN</em> <em>expression</em> <em>RIGHT_PAREN</em></p>
16673</dd>
16674<dt class="hdlist1"><em>postfix_expression</em> : </dt>
16675<dd>
16676<p><em>primary_expression</em><br>
16677<em>postfix_expression</em> <em>LEFT_BRACKET</em> <em>integer_expression</em> <em>RIGHT_BRACKET</em><br>
16678<em>function_call</em><br>
16679<em>postfix_expression</em> <em>DOT</em> <em>FIELD_SELECTION</em><br>
16680<em>postfix_expression</em> <em>INC_OP</em><br>
16681<em>postfix_expression</em> <em>DEC_OP</em></p>
16682</dd>
16683</dl>
16684</div>
16685<div class="admonitionblock note">
16686<table>
16687<tr>
16688<td class="icon">
16689<i class="fa icon-note" title="Note"></i>
16690</td>
16691<td class="content">
16692<div class="paragraph">
16693<p>FIELD_SELECTION includes members in structures, component selection for
16694vectors and the 'length' identifier for the length() method</p>
16695</div>
16696</td>
16697</tr>
16698</table>
16699</div>
16700<div class="dlist">
16701<dl>
16702<dt class="hdlist1"><em>integer_expression</em> : </dt>
16703<dd>
16704<p><em>expression</em></p>
16705</dd>
16706<dt class="hdlist1"><em>function_call</em> : </dt>
16707<dd>
16708<p><em>function_call_or_method</em></p>
16709</dd>
16710<dt class="hdlist1"><em>function_call_or_method</em> : </dt>
16711<dd>
16712<p><em>function_call_generic</em></p>
16713</dd>
16714<dt class="hdlist1"><em>function_call_generic</em> : </dt>
16715<dd>
16716<p><em>function_call_header_with_parameters</em> <em>RIGHT_PAREN</em><br>
16717<em>function_call_header_no_parameters</em> <em>RIGHT_PAREN</em></p>
16718</dd>
16719<dt class="hdlist1"><em>function_call_header_no_parameters</em> : </dt>
16720<dd>
16721<p><em>function_call_header</em> <em>VOID</em><br>
16722<em>function_call_header</em></p>
16723</dd>
16724<dt class="hdlist1"><em>function_call_header_with_parameters</em> : </dt>
16725<dd>
16726<p><em>function_call_header</em> <em>assignment_expression</em><br>
16727<em>function_call_header_with_parameters</em> <em>COMMA</em> <em>assignment_expression</em></p>
16728</dd>
16729<dt class="hdlist1"><em>function_call_header</em> : </dt>
16730<dd>
16731<p><em>function_identifier</em> <em>LEFT_PAREN</em></p>
16732</dd>
16733</dl>
16734</div>
16735<div class="admonitionblock note">
16736<table>
16737<tr>
16738<td class="icon">
16739<i class="fa icon-note" title="Note"></i>
16740</td>
16741<td class="content">
16742<div class="paragraph">
16743<p>Grammar Note: Constructors look like functions, but lexical analysis
16744recognized most of them as keywords.
16745They are now recognized through <em>type_specifier</em>.</p>
16746</div>
16747</td>
16748</tr>
16749</table>
16750</div>
16751<div class="admonitionblock note">
16752<table>
16753<tr>
16754<td class="icon">
16755<i class="fa icon-note" title="Note"></i>
16756</td>
16757<td class="content">
16758<div class="paragraph">
16759<p>Methods (<strong>.length</strong>), subroutine array calls, and identifiers are recognized
16760through <em>postfix_expression</em>.</p>
16761</div>
16762</td>
16763</tr>
16764</table>
16765</div>
16766<div class="dlist">
16767<dl>
16768<dt class="hdlist1"><em>function_identifier</em> : </dt>
16769<dd>
16770<p><em>type_specifier</em><br>
16771<em>postfix_expression</em></p>
16772</dd>
16773<dt class="hdlist1"><em>unary_expression</em> : </dt>
16774<dd>
16775<p><em>postfix_expression</em><br>
16776<em>INC_OP</em> <em>unary_expression</em><br>
16777<em>DEC_OP</em> <em>unary_expression</em><br>
16778<em>unary_operator</em> <em>unary_expression</em></p>
16779</dd>
16780</dl>
16781</div>
16782<div class="admonitionblock note">
16783<table>
16784<tr>
16785<td class="icon">
16786<i class="fa icon-note" title="Note"></i>
16787</td>
16788<td class="content">
16789<div class="paragraph">
16790<p>Grammar Note: No traditional style type casts.</p>
16791</div>
16792</td>
16793</tr>
16794</table>
16795</div>
16796<div class="dlist">
16797<dl>
16798<dt class="hdlist1"><em>unary_operator</em> : </dt>
16799<dd>
16800<p><em>PLUS</em><br>
16801<em>DASH</em><br>
16802<em>BANG</em><br>
16803<em>TILDE</em></p>
16804</dd>
16805</dl>
16806</div>
16807<div class="admonitionblock note">
16808<table>
16809<tr>
16810<td class="icon">
16811<i class="fa icon-note" title="Note"></i>
16812</td>
16813<td class="content">
16814<div class="paragraph">
16815<p>Grammar Note: No '*' or '&amp;' unary ops.
16816Pointers are not supported.</p>
16817</div>
16818</td>
16819</tr>
16820</table>
16821</div>
16822<div class="dlist">
16823<dl>
16824<dt class="hdlist1"><em>multiplicative_expression</em> : </dt>
16825<dd>
16826<p><em>unary_expression</em><br>
16827<em>multiplicative_expression</em> <em>STAR</em> <em>unary_expression</em><br>
16828<em>multiplicative_expression</em> <em>SLASH</em> <em>unary_expression</em><br>
16829<em>multiplicative_expression</em> <em>PERCENT</em> <em>unary_expression</em></p>
16830</dd>
16831<dt class="hdlist1"><em>additive_expression</em> : </dt>
16832<dd>
16833<p><em>multiplicative_expression</em><br>
16834<em>additive_expression</em> <em>PLUS</em> <em>multiplicative_expression</em><br>
16835<em>additive_expression</em> <em>DASH</em> <em>multiplicative_expression</em></p>
16836</dd>
16837<dt class="hdlist1"><em>shift_expression</em> : </dt>
16838<dd>
16839<p><em>additive_expression</em><br>
16840<em>shift_expression</em> <em>LEFT_OP</em> <em>additive_expression</em><br>
16841<em>shift_expression</em> <em>RIGHT_OP</em> <em>additive_expression</em></p>
16842</dd>
16843<dt class="hdlist1"><em>relational_expression</em> : </dt>
16844<dd>
16845<p><em>shift_expression</em><br>
16846<em>relational_expression</em> <em>LEFT_ANGLE</em> <em>shift_expression</em><br>
16847<em>relational_expression</em> <em>RIGHT_ANGLE</em> <em>shift_expression</em><br>
16848<em>relational_expression</em> <em>LE_OP</em> <em>shift_expression</em><br>
16849<em>relational_expression</em> <em>GE_OP</em> <em>shift_expression</em></p>
16850</dd>
16851<dt class="hdlist1"><em>equality_expression</em> : </dt>
16852<dd>
16853<p><em>relational_expression</em><br>
16854<em>equality_expression</em> <em>EQ_OP</em> <em>relational_expression</em><br>
16855<em>equality_expression</em> <em>NE_OP</em> <em>relational_expression</em></p>
16856</dd>
16857<dt class="hdlist1"><em>and_expression</em> : </dt>
16858<dd>
16859<p><em>equality_expression</em><br>
16860<em>and_expression</em> <em>AMPERSAND</em> <em>equality_expression</em></p>
16861</dd>
16862<dt class="hdlist1"><em>exclusive_or_expression</em> : </dt>
16863<dd>
16864<p><em>and_expression</em><br>
16865<em>exclusive_or_expression</em> <em>CARET</em> <em>and_expression</em></p>
16866</dd>
16867<dt class="hdlist1"><em>inclusive_or_expression</em> : </dt>
16868<dd>
16869<p><em>exclusive_or_expression</em><br>
16870<em>inclusive_or_expression</em> <em>VERTICAL_BAR</em> <em>exclusive_or_expression</em></p>
16871</dd>
16872<dt class="hdlist1"><em>logical_and_expression</em> : </dt>
16873<dd>
16874<p><em>inclusive_or_expression</em><br>
16875<em>logical_and_expression</em> <em>AND_OP</em> <em>inclusive_or_expression</em></p>
16876</dd>
16877<dt class="hdlist1"><em>logical_xor_expression</em> : </dt>
16878<dd>
16879<p><em>logical_and_expression</em><br>
16880<em>logical_xor_expression</em> <em>XOR_OP</em> <em>logical_and_expression</em></p>
16881</dd>
16882<dt class="hdlist1"><em>logical_or_expression</em> : </dt>
16883<dd>
16884<p><em>logical_xor_expression</em><br>
16885<em>logical_or_expression</em> <em>OR_OP</em> <em>logical_xor_expression</em></p>
16886</dd>
16887<dt class="hdlist1"><em>conditional_expression</em> : </dt>
16888<dd>
16889<p><em>logical_or_expression</em><br>
16890<em>logical_or_expression</em> <em>QUESTION</em> <em>expression</em> <em>COLON</em>
16891<em>assignment_expression</em></p>
16892</dd>
16893<dt class="hdlist1"><em>assignment_expression</em> : </dt>
16894<dd>
16895<p><em>conditional_expression</em><br>
16896<em>unary_expression</em> <em>assignment_operator</em> <em>assignment_expression</em></p>
16897</dd>
16898<dt class="hdlist1"><em>assignment_operator</em> : </dt>
16899<dd>
16900<p><em>EQUAL</em><br>
16901<em>MUL_ASSIGN</em><br>
16902<em>DIV_ASSIGN</em><br>
16903<em>MOD_ASSIGN</em><br>
16904<em>ADD_ASSIGN</em><br>
16905<em>SUB_ASSIGN</em><br>
16906<em>LEFT_ASSIGN</em><br>
16907<em>RIGHT_ASSIGN</em><br>
16908<em>AND_ASSIGN</em><br>
16909<em>XOR_ASSIGN</em><br>
16910<em>OR_ASSIGN</em></p>
16911</dd>
16912<dt class="hdlist1"><em>expression</em> : </dt>
16913<dd>
16914<p><em>assignment_expression</em><br>
16915<em>expression</em> <em>COMMA</em> <em>assignment_expression</em></p>
16916</dd>
16917<dt class="hdlist1"><em>constant_expression</em> : </dt>
16918<dd>
16919<p><em>conditional_expression</em></p>
16920</dd>
16921<dt class="hdlist1"><em>declaration</em> : </dt>
16922<dd>
16923<p><em>function_prototype</em> <em>SEMICOLON</em><br>
16924<em>init_declarator_list</em> <em>SEMICOLON</em><br>
16925<em>PRECISION</em> <em>precision_qualifier</em> <em>type_specifier</em> <em>SEMICOLON</em><br>
16926<em>type_qualifier</em> <em>IDENTIFIER</em> <em>LEFT_BRACE</em> <em>struct_declaration_list</em>
16927<em>RIGHT_BRACE</em> <em>SEMICOLON</em><br>
16928<em>type_qualifier</em> <em>IDENTIFIER</em> <em>LEFT_BRACE</em> <em>struct_declaration_list</em>
16929<em>RIGHT_BRACE</em> <em>IDENTIFIER</em> <em>SEMICOLON</em><br>
16930<em>type_qualifier</em> <em>IDENTIFIER</em> <em>LEFT_BRACE</em> <em>struct_declaration_list</em>
16931<em>RIGHT_BRACE</em> <em>IDENTIFIER</em> <em>array_specifier</em> <em>SEMICOLON</em><br>
16932<em>type_qualifier</em> <em>SEMICOLON</em><br>
16933<em>type_qualifier</em> <em>IDENTIFIER</em> <em>SEMICOLON</em><br>
16934<em>type_qualifier</em> <em>IDENTIFIER</em> <em>identifier_list</em> <em>SEMICOLON</em></p>
16935</dd>
16936<dt class="hdlist1"><em>identifier_list</em> : </dt>
16937<dd>
16938<p><em>COMMA</em> <em>IDENTIFIER</em><br>
16939<em>identifier_list</em> <em>COMMA</em> <em>IDENTIFIER</em></p>
16940</dd>
16941<dt class="hdlist1"><em>function_prototype</em> : </dt>
16942<dd>
16943<p><em>function_declarator</em> <em>RIGHT_PAREN</em></p>
16944</dd>
16945<dt class="hdlist1"><em>function_declarator</em> : </dt>
16946<dd>
16947<p><em>function_header</em><br>
16948<em>function_header_with_parameters</em></p>
16949</dd>
16950<dt class="hdlist1"><em>function_header_with_parameters</em> : </dt>
16951<dd>
16952<p><em>function_header</em> <em>parameter_declaration</em><br>
16953<em>function_header_with_parameters</em> <em>COMMA</em> <em>parameter_declaration</em></p>
16954</dd>
16955<dt class="hdlist1"><em>function_header</em> : </dt>
16956<dd>
16957<p><em>fully_specified_type</em> <em>IDENTIFIER</em> <em>LEFT_PAREN</em></p>
16958</dd>
16959<dt class="hdlist1"><em>parameter_declarator</em> : </dt>
16960<dd>
16961<p><em>type_specifier</em> <em>IDENTIFIER</em><br>
16962<em>type_specifier</em> <em>IDENTIFIER</em> <em>array_specifier</em></p>
16963</dd>
16964<dt class="hdlist1"><em>parameter_declaration</em> : </dt>
16965<dd>
16966<p><em>type_qualifier</em> <em>parameter_declarator</em><br>
16967<em>parameter_declarator</em><br>
16968<em>type_qualifier</em> <em>parameter_type_specifier</em><br>
16969<em>parameter_type_specifier</em></p>
16970</dd>
16971<dt class="hdlist1"><em>parameter_type_specifier</em> : </dt>
16972<dd>
16973<p><em>type_specifier</em></p>
16974</dd>
16975<dt class="hdlist1"><em>init_declarator_list</em> : </dt>
16976<dd>
16977<p><em>single_declaration</em><br>
16978<em>init_declarator_list</em> <em>COMMA</em> <em>IDENTIFIER</em><br>
16979<em>init_declarator_list</em> <em>COMMA</em> <em>IDENTIFIER</em> <em>array_specifier</em><br>
16980<em>init_declarator_list</em> <em>COMMA</em> <em>IDENTIFIER</em> <em>array_specifier</em> <em>EQUAL</em>
16981<em>initializer</em><br>
16982<em>init_declarator_list</em> <em>COMMA</em> <em>IDENTIFIER</em> <em>EQUAL</em> <em>initializer</em></p>
16983</dd>
16984<dt class="hdlist1"><em>single_declaration</em> : </dt>
16985<dd>
16986<p><em>fully_specified_type</em><br>
16987<em>fully_specified_type</em> <em>IDENTIFIER</em><br>
16988<em>fully_specified_type</em> <em>IDENTIFIER</em> <em>array_specifier</em><br>
16989<em>fully_specified_type</em> <em>IDENTIFIER</em> <em>array_specifier</em> <em>EQUAL</em>
16990<em>initializer</em><br>
16991<em>fully_specified_type</em> <em>IDENTIFIER</em> <em>EQUAL</em> <em>initializer</em></p>
16992</dd>
16993</dl>
16994</div>
16995<div class="admonitionblock note">
16996<table>
16997<tr>
16998<td class="icon">
16999<i class="fa icon-note" title="Note"></i>
17000</td>
17001<td class="content">
17002<div class="paragraph">
17003<p>Grammar Note: No 'enum', or 'typedef'.</p>
17004</div>
17005</td>
17006</tr>
17007</table>
17008</div>
17009<div class="dlist">
17010<dl>
17011<dt class="hdlist1"><em>fully_specified_type</em> : </dt>
17012<dd>
17013<p><em>type_specifier</em><br>
17014<em>type_qualifier</em> <em>type_specifier</em></p>
17015</dd>
17016<dt class="hdlist1"><em>invariant_qualifier</em> : </dt>
17017<dd>
17018<p><em>INVARIANT</em></p>
17019</dd>
17020<dt class="hdlist1"><em>interpolation_qualifier</em> : </dt>
17021<dd>
17022<p><em>SMOOTH</em><br>
17023<em>FLAT</em><br>
17024<em>NOPERSPECTIVE</em></p>
17025</dd>
17026<dt class="hdlist1"><em>layout_qualifier</em> : </dt>
17027<dd>
17028<p><em>LAYOUT</em> <em>LEFT_PAREN</em> <em>layout_qualifier_id_list</em> <em>RIGHT_PAREN</em></p>
17029</dd>
17030<dt class="hdlist1"><em>layout_qualifier_id_list</em> : </dt>
17031<dd>
17032<p><em>layout_qualifier_id</em><br>
17033<em>layout_qualifier_id_list</em> <em>COMMA</em> <em>layout_qualifier_id</em></p>
17034</dd>
17035<dt class="hdlist1"><em>layout_qualifier_id</em> : </dt>
17036<dd>
17037<p><em>IDENTIFIER</em><br>
17038<em>IDENTIFIER</em> <em>EQUAL</em> <em>constant_expression</em><br>
17039<em>SHARED</em></p>
17040</dd>
17041<dt class="hdlist1"><em>precise_qualifier</em> : </dt>
17042<dd>
17043<p><em>PRECISE</em></p>
17044</dd>
17045<dt class="hdlist1"><em>type_qualifier</em> : </dt>
17046<dd>
17047<p><em>single_type_qualifier</em><br>
17048<em>type_qualifier</em> <em>single_type_qualifier</em></p>
17049</dd>
17050<dt class="hdlist1"><em>single_type_qualifier</em> : </dt>
17051<dd>
17052<p><em>storage_qualifier</em><br>
17053<em>layout_qualifier</em><br>
17054<em>precision_qualifier</em><br>
17055<em>interpolation_qualifier</em><br>
17056<em>invariant_qualifier</em><br>
17057<em>precise_qualifier</em></p>
17058</dd>
17059<dt class="hdlist1"><em>storage_qualifier</em> : </dt>
17060<dd>
17061<p><em>CONST</em><br>
17062<em>IN</em><br>
17063<em>OUT</em><br>
17064<em>INOUT</em><br>
17065<em>CENTROID</em><br>
17066<em>PATCH</em><br>
17067<em>SAMPLE</em><br>
17068<em>UNIFORM</em><br>
17069<em>BUFFER</em><br>
17070<em>SHARED</em><br>
17071<em>COHERENT</em><br>
17072<em>VOLATILE</em><br>
17073<em>RESTRICT</em><br>
17074<em>READONLY</em><br>
17075<em>WRITEONLY</em><br>
17076<em>SUBROUTINE</em><br>
17077<em>SUBROUTINE</em> <em>LEFT_PAREN</em> <em>type_name_list</em> <em>RIGHT_PAREN</em></p>
17078</dd>
17079<dt class="hdlist1"><em>type_name_list</em> : </dt>
17080<dd>
17081<p><em>TYPE_NAME</em><br>
17082<em>type_name_list</em> <em>COMMA</em> <em>TYPE_NAME</em></p>
17083</dd>
17084<dt class="hdlist1"><em>type_specifier</em> : </dt>
17085<dd>
17086<p><em>type_specifier_nonarray</em><br>
17087<em>type_specifier_nonarray</em> <em>array_specifier</em></p>
17088</dd>
17089<dt class="hdlist1"><em>array_specifier</em> : </dt>
17090<dd>
17091<p><em>LEFT_BRACKET</em> <em>RIGHT_BRACKET</em><br>
17092<em>LEFT_BRACKET</em> <em>conditional_expression</em> <em>RIGHT_BRACKET</em><br>
17093<em>array_specifier</em> <em>LEFT_BRACKET</em> <em>RIGHT_BRACKET</em><br>
17094<em>array_specifier</em> <em>LEFT_BRACKET</em> <em>conditional_expression</em> <em>RIGHT_BRACKET</em></p>
17095</dd>
17096<dt class="hdlist1"><em>type_specifier_nonarray</em> : </dt>
17097<dd>
17098<p><em>VOID</em><br>
17099<em>FLOAT</em><br>
17100<em>DOUBLE</em><br>
17101<em>INT</em><br>
17102<em>UINT</em><br>
17103<em>BOOL</em><br>
17104<em>VEC2</em><br>
17105<em>VEC3</em><br>
17106<em>VEC4</em><br>
17107<em>DVEC2</em><br>
17108<em>DVEC3</em><br>
17109<em>DVEC4</em><br>
17110<em>BVEC2</em><br>
17111<em>BVEC3</em><br>
17112<em>BVEC4</em><br>
17113<em>IVEC2</em><br>
17114<em>IVEC3</em><br>
17115<em>IVEC4</em><br>
17116<em>UVEC2</em><br>
17117<em>UVEC3</em><br>
17118<em>UVEC4</em><br>
17119<em>MAT2</em><br>
17120<em>MAT3</em><br>
17121<em>MAT4</em><br>
17122<em>MAT2X2</em><br>
17123<em>MAT2X3</em><br>
17124<em>MAT2X4</em><br>
17125<em>MAT3X2</em><br>
17126<em>MAT3X3</em><br>
17127<em>MAT3X4</em><br>
17128<em>MAT4X2</em><br>
17129<em>MAT4X3</em><br>
17130<em>MAT4X4</em><br>
17131<em>DMAT2</em><br>
17132<em>DMAT3</em><br>
17133<em>DMAT4</em><br>
17134<em>DMAT2X2</em><br>
17135<em>DMAT2X3</em><br>
17136<em>DMAT2X4</em><br>
17137<em>DMAT3X2</em><br>
17138<em>DMAT3X3</em><br>
17139<em>DMAT3X4</em><br>
17140<em>DMAT4X2</em><br>
17141<em>DMAT4X3</em><br>
17142<em>DMAT4X4</em><br>
17143<em>ATOMIC_UINT</em><br>
17144<em>SAMPLER2D</em><br>
17145<em>SAMPLER3D</em><br>
17146<em>SAMPLERCUBE</em><br>
17147<em>SAMPLER2DSHADOW</em><br>
17148<em>SAMPLERCUBESHADOW</em><br>
17149<em>SAMPLER2DARRAY</em><br>
17150<em>SAMPLER2DARRAYSHADOW</em><br>
17151<em>SAMPLERCUBEARRAY</em><br>
17152<em>SAMPLERCUBEARRAYSHADOW</em><br>
17153<em>ISAMPLER2D</em><br>
17154<em>ISAMPLER3D</em><br>
17155<em>ISAMPLERCUBE</em><br>
17156<em>ISAMPLER2DARRAY</em><br>
17157<em>ISAMPLERCUBEARRAY</em><br>
17158<em>USAMPLER2D</em><br>
17159<em>USAMPLER3D</em><br>
17160<em>USAMPLERCUBE</em><br>
17161<em>USAMPLER2DARRAY</em><br>
17162<em>USAMPLERCUBEARRAY</em><br>
17163<em>SAMPLER1D</em><br>
17164<em>SAMPLER1DSHADOW</em><br>
17165<em>SAMPLER1DARRAY</em><br>
17166<em>SAMPLER1DARRAYSHADOW</em><br>
17167<em>ISAMPLER1D</em><br>
17168<em>ISAMPLER1DARRAY</em><br>
17169<em>USAMPLER1D</em><br>
17170<em>USAMPLER1DARRAY</em><br>
17171<em>SAMPLER2DRECT</em><br>
17172<em>SAMPLER2DRECTSHADOW</em><br>
17173<em>ISAMPLER2DRECT</em><br>
17174<em>USAMPLER2DRECT</em><br>
17175<em>SAMPLERBUFFER</em><br>
17176<em>ISAMPLERBUFFER</em><br>
17177<em>USAMPLERBUFFER</em><br>
17178<em>SAMPLER2DMS</em><br>
17179<em>ISAMPLER2DMS</em><br>
17180<em>USAMPLER2DMS</em><br>
17181<em>SAMPLER2DMSARRAY</em><br>
17182<em>ISAMPLER2DMSARRAY</em><br>
17183<em>USAMPLER2DMSARRAY</em><br>
17184<em>IMAGE2D</em><br>
17185<em>IIMAGE2D</em><br>
17186<em>UIMAGE2D</em><br>
17187<em>IMAGE3D</em><br>
17188<em>IIMAGE3D</em><br>
17189<em>UIMAGE3D</em><br>
17190<em>IMAGECUBE</em><br>
17191<em>IIMAGECUBE</em><br>
17192<em>UIMAGECUBE</em><br>
17193<em>IMAGEBUFFER</em><br>
17194<em>IIMAGEBUFFER</em><br>
17195<em>UIMAGEBUFFER</em><br>
17196<em>IMAGE1D</em><br>
17197<em>IIMAGE1D</em><br>
17198<em>UIMAGE1D</em><br>
17199<em>IMAGE1DARRAY</em><br>
17200<em>IIMAGE1DARRAY</em><br>
17201<em>UIMAGE1DARRAY</em><br>
17202<em>IMAGE2DRECT</em><br>
17203<em>IIMAGE2DRECT</em><br>
17204<em>UIMAGE2DRECT</em><br>
17205<em>IMAGE2DARRAY</em><br>
17206<em>IIMAGE2DARRAY</em><br>
17207<em>UIMAGE2DARRAY</em><br>
17208<em>IMAGECUBEARRAY</em><br>
17209<em>IIMAGECUBEARRAY</em><br>
17210<em>UIMAGECUBEARRAY</em><br>
17211<em>IMAGE2DMS</em><br>
17212<em>IIMAGE2DMS</em><br>
17213<em>UIMAGE2DMS</em><br>
17214<em>IMAGE2DMSARRAY</em><br>
17215<em>IIMAGE2DMSARRAY</em><br>
17216<em>UIMAGE2DMSARRAY</em><br>
17217<em>struct_specifier</em><br>
17218<em>TYPE_NAME</em></p>
17219</dd>
17220<dt class="hdlist1"><em>precision_qualifier</em> : </dt>
17221<dd>
17222<p><em>HIGH_PRECISION</em><br>
17223<em>MEDIUM_PRECISION</em><br>
17224<em>LOW_PRECISION</em></p>
17225</dd>
17226<dt class="hdlist1"><em>struct_specifier</em> : </dt>
17227<dd>
17228<p><em>STRUCT</em> <em>IDENTIFIER</em> <em>LEFT_BRACE</em> <em>struct_declaration_list</em>
17229<em>RIGHT_BRACE</em><br>
17230<em>STRUCT</em> <em>LEFT_BRACE</em> <em>struct_declaration_list</em> <em>RIGHT_BRACE</em></p>
17231</dd>
17232<dt class="hdlist1"><em>struct_declaration_list</em> : </dt>
17233<dd>
17234<p><em>struct_declaration</em><br>
17235<em>struct_declaration_list</em> <em>struct_declaration</em></p>
17236</dd>
17237<dt class="hdlist1"><em>struct_declaration</em> : </dt>
17238<dd>
17239<p><em>type_specifier</em> <em>struct_declarator_list</em> <em>SEMICOLON</em><br>
17240<em>type_qualifier</em> <em>type_specifier</em> <em>struct_declarator_list</em> <em>SEMICOLON</em></p>
17241</dd>
17242<dt class="hdlist1"><em>struct_declarator_list</em> : </dt>
17243<dd>
17244<p><em>struct_declarator</em><br>
17245<em>struct_declarator_list</em> <em>COMMA</em> <em>struct_declarator</em></p>
17246</dd>
17247<dt class="hdlist1"><em>struct_declarator</em> : </dt>
17248<dd>
17249<p><em>IDENTIFIER</em><br>
17250<em>IDENTIFIER</em> <em>array_specifier</em></p>
17251</dd>
17252<dt class="hdlist1"><em>initializer</em> : </dt>
17253<dd>
17254<p><em>assignment_expression</em><br>
17255<em>LEFT_BRACE</em> <em>initializer_list</em> <em>RIGHT_BRACE</em><br>
17256<em>LEFT_BRACE</em> <em>initializer_list</em> <em>COMMA</em> <em>RIGHT_BRACE</em></p>
17257</dd>
17258<dt class="hdlist1"><em>initializer_list</em> : </dt>
17259<dd>
17260<p><em>initializer</em><br>
17261<em>initializer_list</em> <em>COMMA</em> <em>initializer</em></p>
17262</dd>
17263<dt class="hdlist1"><em>declaration_statement</em> : </dt>
17264<dd>
17265<p><em>declaration</em></p>
17266</dd>
17267<dt class="hdlist1"><em>statement</em> : </dt>
17268<dd>
17269<p><em>compound_statement</em><br>
17270<em>simple_statement</em></p>
17271</dd>
17272</dl>
17273</div>
17274<div class="admonitionblock note">
17275<table>
17276<tr>
17277<td class="icon">
17278<i class="fa icon-note" title="Note"></i>
17279</td>
17280<td class="content">
17281<div class="paragraph">
17282<p>Grammar Note: labeled statements for SWITCH only; 'goto' is not supported.</p>
17283</div>
17284</td>
17285</tr>
17286</table>
17287</div>
17288<div class="dlist">
17289<dl>
17290<dt class="hdlist1"><em>simple_statement</em> : </dt>
17291<dd>
17292<p><em>declaration_statement</em><br>
17293<em>expression_statement</em><br>
17294<em>selection_statement</em><br>
17295<em>switch_statement</em><br>
17296<em>case_label</em><br>
17297<em>iteration_statement</em><br>
17298<em>jump_statement</em></p>
17299</dd>
17300<dt class="hdlist1"><em>compound_statement</em> : </dt>
17301<dd>
17302<p><em>LEFT_BRACE</em> <em>RIGHT_BRACE</em><br>
17303<em>LEFT_BRACE</em> <em>statement_list</em> <em>RIGHT_BRACE</em></p>
17304</dd>
17305<dt class="hdlist1"><em>statement_no_new_scope</em> : </dt>
17306<dd>
17307<p><em>compound_statement_no_new_scope</em><br>
17308<em>simple_statement</em></p>
17309</dd>
17310<dt class="hdlist1"><em>compound_statement_no_new_scope</em> : </dt>
17311<dd>
17312<p><em>LEFT_BRACE</em> <em>RIGHT_BRACE</em><br>
17313<em>LEFT_BRACE</em> <em>statement_list</em> <em>RIGHT_BRACE</em></p>
17314</dd>
17315<dt class="hdlist1"><em>statement_list</em> : </dt>
17316<dd>
17317<p><em>statement</em><br>
17318<em>statement_list</em> <em>statement</em></p>
17319</dd>
17320<dt class="hdlist1"><em>expression_statement</em> : </dt>
17321<dd>
17322<p><em>SEMICOLON</em><br>
17323<em>expression</em> <em>SEMICOLON</em></p>
17324</dd>
17325<dt class="hdlist1"><em>selection_statement</em> : </dt>
17326<dd>
17327<p><em>IF</em> <em>LEFT_PAREN</em> <em>expression</em> <em>RIGHT_PAREN</em> <em>selection_rest_statement</em></p>
17328</dd>
17329<dt class="hdlist1"><em>selection_rest_statement</em> : </dt>
17330<dd>
17331<p><em>statement</em> <em>ELSE</em> <em>statement</em><br>
17332<em>statement</em></p>
17333</dd>
17334<dt class="hdlist1"><em>condition</em> : </dt>
17335<dd>
17336<p><em>expression</em><br>
17337<em>fully_specified_type</em> <em>IDENTIFIER</em> <em>EQUAL</em> <em>initializer</em></p>
17338</dd>
17339<dt class="hdlist1"><em>switch_statement</em> : </dt>
17340<dd>
17341<p><em>SWITCH</em> <em>LEFT_PAREN</em> <em>expression</em> <em>RIGHT_PAREN</em> <em>LEFT_BRACE</em>
17342<em>switch_statement_list</em><br>
17343<em>RIGHT_BRACE</em></p>
17344</dd>
17345<dt class="hdlist1"><em>switch_statement_list</em> : </dt>
17346<dd>
17347<p>/* <em>nothing</em> */<br>
17348<em>statement_list</em></p>
17349</dd>
17350<dt class="hdlist1"><em>case_label</em> : </dt>
17351<dd>
17352<p><em>CASE</em> <em>expression</em> <em>COLON</em><br>
17353<em>DEFAULT</em> <em>COLON</em></p>
17354</dd>
17355<dt class="hdlist1"><em>iteration_statement</em> : </dt>
17356<dd>
17357<p><em>WHILE</em> <em>LEFT_PAREN</em> <em>condition</em> <em>RIGHT_PAREN</em> <em>statement_no_new_scope</em><br>
17358<em>DO</em> <em>statement</em> <em>WHILE</em> <em>LEFT_PAREN</em> <em>expression</em> <em>RIGHT_PAREN</em>
17359<em>SEMICOLON</em><br>
17360<em>FOR</em> <em>LEFT_PAREN</em> <em>for_init_statement</em> <em>for_rest_statement</em>
17361<em>RIGHT_PAREN</em> <em>statement_no_new_scope</em></p>
17362</dd>
17363<dt class="hdlist1"><em>for_init_statement</em> : </dt>
17364<dd>
17365<p><em>expression_statement</em><br>
17366<em>declaration_statement</em></p>
17367</dd>
17368<dt class="hdlist1"><em>conditionopt</em> : </dt>
17369<dd>
17370<p><em>condition</em><br>
17371/* <em>empty</em> */</p>
17372</dd>
17373<dt class="hdlist1"><em>for_rest_statement</em> : </dt>
17374<dd>
17375<p><em>conditionopt</em> <em>SEMICOLON</em><br>
17376<em>conditionopt</em> <em>SEMICOLON</em> <em>expression</em></p>
17377</dd>
17378<dt class="hdlist1"><em>jump_statement</em> : </dt>
17379<dd>
17380<p><em>CONTINUE</em> <em>SEMICOLON</em><br>
17381<em>BREAK</em> <em>SEMICOLON</em><br>
17382<em>RETURN</em> <em>SEMICOLON</em><br>
17383<em>RETURN</em> <em>expression</em> <em>SEMICOLON</em><br>
17384<em>DISCARD</em> <em>SEMICOLON</em> // Fragment shader only.</p>
17385</dd>
17386</dl>
17387</div>
17388<div class="admonitionblock note">
17389<table>
17390<tr>
17391<td class="icon">
17392<i class="fa icon-note" title="Note"></i>
17393</td>
17394<td class="content">
17395<div class="paragraph">
17396<p>Grammar Note: No 'goto'.
17397Gotos are not supported.</p>
17398</div>
17399</td>
17400</tr>
17401</table>
17402</div>
17403<div class="dlist">
17404<dl>
17405<dt class="hdlist1"><em>translation_unit</em> : </dt>
17406<dd>
17407<p><em>external_declaration</em><br>
17408<em>translation_unit</em> <em>external_declaration</em></p>
17409</dd>
17410<dt class="hdlist1"><em>external_declaration</em> : </dt>
17411<dd>
17412<p><em>function_definition</em><br>
17413<em>declaration</em><br>
17414<em>SEMICOLON</em></p>
17415</dd>
17416<dt class="hdlist1"><em>function_definition</em> : </dt>
17417<dd>
17418<p><em>function_prototype</em> <em>compound_statement_no_new_scope</em></p>
17419</dd>
17420</dl>
17421</div>
17422</div>
17423</div>
17424<div class="paragraph">
17425<p>In general the above grammar describes a super set of the OpenGL Shading Language.
17426Certain constructs that are valid purely in terms of the grammar are
17427disallowed by statements elsewhere in this specification.</p>
17428</div>
17429</div>
17430</div>
17431<div class="sect1">
17432<h2 id="acknowledgments">10. Acknowledgments</h2>
17433<div class="sectionbody">
17434<div class="paragraph">
17435<p>This specification is based on the work of those who contributed to past
17436versions of the Open GL and Open GL ES Language Specifications and the
17437following contributors to this version:</p>
17438</div>
17439<div class="paragraph">
17440<p>Pat Brown, NVIDIA<br>
17441Jeff Bolz, NVIDIA<br>
17442Frank Chen<br>
17443Pierre Boudier, AMD<br>
17444Piers Daniell, NVIDIA<br>
17445Chris Dodd, NVIDIA<br>
17446Nick Haemel, NVIDIA<br>
17447Jason Green, Transgaming<br>
17448Brent Insko, Intel<br>
17449Jon Leech<br>
17450Bill Licea-Kane, Qualcomm<br>
17451Daniel Koch, NVIDIA<br>
17452Graeme Leese, Broadcom<br>
17453Barthold Lichtenbelt, NVIDIA<br>
17454Bruce Merry, ARM<br>
17455Robert Ohannessian<br>
17456Tom Olson, ARM<br>
17457Brian Paul, VMware<br>
17458Acorn Pooley, NVIDIA<br>
17459Daniel Rakos, AMD<br>
17460Christophe Riccio, AMD<br>
17461Kevin Rogovin<br>
17462Ian Romanick, Intel<br>
17463Greg Roth, NVIDIA<br>
17464Graham Sellers, AMD<br>
17465Dave Shreiner, ARM<br>
17466Jeremy Sandmel, Apple<br>
17467Robert Simpson, Qualcomm<br>
17468Eric Werness, NVIDIA<br>
17469Mark Young, AMD</p>
17470</div>
17471</div>
17472</div>
17473<div class="sect1">
17474<h2 id="references">11. Normative References</h2>
17475<div class="sectionbody">
17476<div class="olist arabic">
17477<ol class="arabic">
17478<li>
17479<p>International Standard ISO/IEC 14882:1998(E).
17480Programming Languages - C++. Referenced for preprocessor only</p>
17481</li>
17482<li>
17483<p>&#8220;OpenGL<sup>R</sup> ES, Version 3.2&#8221;,
17484<a href="https://www.khronos.org/registry/OpenGL/index_es.php" class="bare">https://www.khronos.org/registry/OpenGL/index_es.php</a>, November 3, 2016.</p>
17485</li>
17486<li>
17487<p>&#8220;The OpenGL<sup>R</sup> Graphics System: A Specification, Version 4.6 (Core
17488Profile)&#8221;, <a href="https://www.khronos.org/registry/OpenGL/index_gl.php" class="bare">https://www.khronos.org/registry/OpenGL/index_gl.php</a>, June
174891, 2016.</p>
17490</li>
17491<li>
17492<p>IEEE 754-2008.
17493<em>IEEE Standard for Floating-Point Arithmetic</em></p>
17494</li>
17495<li>
17496<p>&#8220;SPIR-V Specification, Version 1.3, Revision 7&#8221; ,
17497<a href="https://www.khronos.org/registry/spir-v/" class="bare">https://www.khronos.org/registry/spir-v/</a>.</p>
17498</li>
17499<li>
17500<p>&#8220;Vulkan<sup>R</sup> 1.1.105 - A Specification&#8221;,
17501<a href="https://www.khronos.org/registry/vulkan/" class="bare">https://www.khronos.org/registry/vulkan/</a>,
17502March 19, 2019.</p>
17503</li>
17504</ol>
17505</div>
17506</div>
17507</div>
17508<div class="sect1">
17509<h2 id="_non_normative_spir_v_mappings">12. Non-Normative SPIR-V Mappings</h2>
17510<div class="sectionbody">
17511<div class="paragraph">
17512<p>This appendix includes:</p>
17513</div>
17514<div class="ulist">
17515<ul>
17516<li>
17517<p>a comparision of feature differences with SPIR-V versus without, for both Vulkan and OpenGL</p>
17518</li>
17519<li>
17520<p>a discussion of how GLSL features logically map to SPIR-V features.</p>
17521</li>
17522</ul>
17523</div>
17524<div class="sect2">
17525<h3 id="_feature_comparisons">12.1. Feature Comparisons</h3>
17526<div class="paragraph">
17527<p>The following features are removed for both OpenGL and Vulkan:</p>
17528</div>
17529<div class="ulist">
17530<ul>
17531<li>
17532<p>subroutines</p>
17533</li>
17534<li>
17535<p>shared and packed block layouts</p>
17536</li>
17537<li>
17538<p>the already deprecated texturing functions (e.g., <code>texture2D()</code>)</p>
17539</li>
17540<li>
17541<p>the already deprecated noise functions (e.g., <code>noise1()</code>)</p>
17542</li>
17543<li>
17544<p>compatibility-profile features</p>
17545</li>
17546<li>
17547<p><em>gl_DepthRangeParameters</em> and <em>gl_NumSamples</em></p>
17548</li>
17549</ul>
17550</div>
17551<div class="paragraph">
17552<p>Vulkan removed the following features, which are still present for OpenGL:</p>
17553</div>
17554<div class="ulist">
17555<ul>
17556<li>
17557<p>Default uniforms, for non-opaque types:
17558The <strong>UniformConstant</strong> storage class can be used on individual
17559variables at global scope. (That is, uniforms don&#8217;t have to be in a
17560block, unless they are built-in members that are in block in GLSL
17561version 4.5 or above.)</p>
17562</li>
17563<li>
17564<p>GLSL atomic-counter bindings have the <em>offset</em> layout qualifier &#8594;
17565SPIR-V <strong>AtomicCounter</strong> storage class using the <strong>Offset</strong> decoration</p>
17566</li>
17567<li>
17568<p>GLSL <em>origin_lower_left</em> &#8594; SPIR-V <strong>OriginLowerLeft</strong></p>
17569</li>
17570<li>
17571<p>special rules for locations for input doubles in the vertex shader</p>
17572</li>
17573<li>
17574<p><em>gl_VertexID</em> and <em>gl_InstanceID</em> (more detail follows)</p>
17575</li>
17576</ul>
17577</div>
17578<div class="paragraph">
17579<p>The following features are added for both OpenGL and Vulkan:</p>
17580</div>
17581<div class="ulist">
17582<ul>
17583<li>
17584<p>specialization constants</p>
17585</li>
17586<li>
17587<p><em>offset</em> can organize members in a different order than declaration order</p>
17588</li>
17589<li>
17590<p><em>offset</em> and <em>align</em> layout qualifiers for uniform/buffer blocks for
17591versions that did not support them</p>
17592</li>
17593</ul>
17594</div>
17595<div class="paragraph">
17596<p>Vulkan Only: The following features are added:</p>
17597</div>
17598<div class="ulist">
17599<ul>
17600<li>
17601<p>push-constant buffers</p>
17602</li>
17603<li>
17604<p>shader combining of separate textures and samplers (SPIR-V <strong>OpTypeSampler</strong>)</p>
17605</li>
17606<li>
17607<p>descriptor sets (<strong>DescriptorSet</strong> must be 0, if present)</p>
17608</li>
17609<li>
17610<p><em>gl_VertexIndex</em> and <em>gl_InstanceIndex</em></p>
17611</li>
17612<li>
17613<p>subpass-input targets and input attachments (<em>input_attachment_index</em>)</p>
17614</li>
17615</ul>
17616</div>
17617<div class="paragraph">
17618<p>The following features are changed in both OpenGL and Vulkan:</p>
17619</div>
17620<div class="ulist">
17621<ul>
17622<li>
17623<p><em>gl_FragColor</em> will no longer indicate an implicit broadcast</p>
17624</li>
17625</ul>
17626</div>
17627<div class="paragraph">
17628<p>Vulkan Only: The following features are changed:</p>
17629</div>
17630<div class="ulist">
17631<ul>
17632<li>
17633<p>precision qualifiers (<strong>mediump</strong> and <strong>lowp</strong>) will be respected for all
17634versions, not dropped for desktop versions (default precision for
17635desktop versions is <strong>highp</strong> for all types)</p>
17636</li>
17637<li>
17638<p>arrays of uniforms and buffer blocks take only one binding number for
17639the entire object, not one per array element</p>
17640</li>
17641<li>
17642<p>the default origin is <em>origin_upper_left</em> instead of <em>origin_lower_left</em></p>
17643</li>
17644</ul>
17645</div>
17646<div class="paragraph">
17647<p>Vulkan does not allow multi-dimensional arrays of resources like
17648UBOs and SSBOs in its SPIR-V environment spec. SPIR-V supports
17649it and OpenGL already allows this for GLSL shaders. SPIR-V
17650for OpenGL also allows it.</p>
17651</div>
17652</div>
17653<div class="sect2">
17654<h3 id="_mapping_from_glsl_to_spir_v">12.2. Mapping from GLSL to SPIR-V</h3>
17655<div class="sect3">
17656<h4 id="_specialization_constants">12.2.1. Specialization Constants</h4>
17657<div class="paragraph">
17658<p>SPIR-V specialization constants, which can be set later by the client API,
17659can be declared using <code>layout(constant_id=&#8230;&#8203;)</code>. For example, to make a
17660specialization constant with a default value of 12:</p>
17661</div>
17662<div class="literalblock">
17663<div class="content">
17664<pre>layout(constant_id = 17) const int arraySize = 12;</pre>
17665</div>
17666</div>
17667<div class="paragraph">
17668<p>Above, <code>17</code> is the ID by which the API or other tools can later refer to
17669this specific specialization constant.  The API or an intermediate tool can
17670then change its value to another constant integer before it is fully
17671lowered to executable code.  If it is never changed before final lowering,
17672it will retain the value of 12.</p>
17673</div>
17674<div class="paragraph">
17675<p>Specialization constants have const semantics, except they don&#8217;t fold.
17676Hence, an array can be declared with <code>arraySize</code> from above:</p>
17677</div>
17678<div class="literalblock">
17679<div class="content">
17680<pre>vec4 data[arraySize];  // legal, even though arraySize might change</pre>
17681</div>
17682</div>
17683<div class="paragraph">
17684<p>Specialization constants can be in expressions:</p>
17685</div>
17686<div class="literalblock">
17687<div class="content">
17688<pre>vec4 data2[arraySize + 2];</pre>
17689</div>
17690</div>
17691<div class="paragraph">
17692<p>This will make <code>data2</code> be sized by 2 more than whatever constant value
17693<code>arraySize</code> has when it is time to lower the shader to executable code.</p>
17694</div>
17695<div class="paragraph">
17696<p>An expression formed with specialization constants also behaves in the
17697shader like a specialization constant, not a like a constant.</p>
17698</div>
17699<div class="literalblock">
17700<div class="content">
17701<pre>arraySize + 2       // a specialization constant (with no constant_id)</pre>
17702</div>
17703</div>
17704<div class="paragraph">
17705<p>Such expressions can be used in the same places as a constant.</p>
17706</div>
17707<div class="paragraph">
17708<p>The <em>constant_id</em> can only be applied to a scalar integer, a scalar floating-point
17709or a scalar Boolean.</p>
17710</div>
17711<div class="paragraph">
17712<p>Only basic operators and constructors can be applied to a specialization
17713constant and still result in a specialization constant:</p>
17714</div>
17715<div class="literalblock">
17716<div class="content">
17717<pre>layout(constant_id = 17) const int arraySize = 12;
17718sin(float(arraySize));    // result is not a specialization constant</pre>
17719</div>
17720</div>
17721<div class="paragraph">
17722<p>While SPIR-V specialization constants are only for scalars, a vector
17723can be made by operations on scalars:</p>
17724</div>
17725<div class="literalblock">
17726<div class="content">
17727<pre>layout(constant_id = 18) const int scX = 1;
17728layout(constant_id = 19) const int scZ = 1;
17729const vec3 scVec = vec3(scX, 1, scZ);  // partially specialized vector</pre>
17730</div>
17731</div>
17732<div class="paragraph">
17733<p>A built-in variable can have a <em>constant_id</em> attached to it:</p>
17734</div>
17735<div class="literalblock">
17736<div class="content">
17737<pre>layout(constant_id = 18) gl_MaxImageUnits;</pre>
17738</div>
17739</div>
17740<div class="paragraph">
17741<p>This makes it behave as a specialization constant.  It is not a full
17742redeclaration; all other characteristics are left intact from the
17743original built-in declaration.</p>
17744</div>
17745<div class="paragraph">
17746<p>The built-in vector <em>gl_WorkGroupSize</em> can be specialized using special
17747layout <code>local_size_{xyz}_id</code> applied to the <strong>in</strong> qualifier.  For example:</p>
17748</div>
17749<div class="literalblock">
17750<div class="content">
17751<pre>layout(local_size_x_id = 18, local_size_z_id = 19) in;</pre>
17752</div>
17753</div>
17754<div class="paragraph">
17755<p>This leaves <em>gl_WorkGroupSize.y</em> as a non-specialization constant, with
17756<em>gl_WorkGroupSize</em> being a partially specialized vector.  Its <em>x</em> and <em>z</em>
17757components can be later specialized using the ID&#8217;s 18 and 19.</p>
17758</div>
17759</div>
17760<div class="sect3">
17761<h4 id="_vulkan_only_push_constants">12.2.2. Vulkan Only: Push Constants</h4>
17762<div class="paragraph">
17763<p>Push constants reside in a uniform block declared using the new
17764layout-qualifier-id <em>push_constant</em> applied to a uniform-block declaration.
17765The API writes a set of constants to a push-constant buffer, and the shader
17766reads them from a <em>push_constant</em> block:</p>
17767</div>
17768<div class="literalblock">
17769<div class="content">
17770<pre>layout(push_constant) uniform BlockName {
17771    int member1;
17772    float member2;
17773    ...
17774} InstanceName; // optional instance name
17775... = InstanceName.member2; // read a push constant</pre>
17776</div>
17777</div>
17778<div class="paragraph">
17779<p>The memory accounting used for the <em>push_constant</em> uniform block is different
17780than for other uniform blocks:  There is a separate small pool of memory
17781it must fit within.  By default, a <em>push_constant</em> buffer follows the std430
17782packing rules.</p>
17783</div>
17784</div>
17785<div class="sect3">
17786<h4 id="_vulkan_only_descriptor_sets">12.2.3. Vulkan Only: Descriptor Sets</h4>
17787<div class="paragraph">
17788<p>Each shader resource in a descriptor set is assigned a tuple of (set
17789number, binding number, array element) that defines its location within
17790a descriptor set layout.
17791In GLSL, the set number and binding number are assigned via the <em>set</em>
17792and <em>binding</em> layout qualifiers respectively, and the array element is
17793implicitly assigned consecutively starting with index equal to zero for
17794the first element of an array (and array element is zero for non-array
17795variables):</p>
17796</div>
17797<div class="literalblock">
17798<div class="content">
17799<pre>// Assign set number = M, binding number = N, array element = 0
17800layout (set=M, binding=N) uniform sampler2D variableName;</pre>
17801</div>
17802</div>
17803<div class="literalblock">
17804<div class="content">
17805<pre>// Assign set number = M, binding number = N for all array elements,
17806// and array element = i for the ith member of an array of size I.
17807layout (set=M, binding=N) uniform sampler2D variableNameArray[I];</pre>
17808</div>
17809</div>
17810<div class="paragraph">
17811<p>For example, two combined texture/sampler objects can be declared in two
17812different descriptor sets as follows</p>
17813</div>
17814<div class="literalblock">
17815<div class="content">
17816<pre>layout(set = 0, binding = 0) uniform sampler2D ts3;
17817layout(set = 1, binding = 0) uniform sampler2D ts4;</pre>
17818</div>
17819</div>
17820<div class="paragraph">
17821<p>See the API documentation for more detail on the operation model of
17822descriptor sets.</p>
17823</div>
17824</div>
17825<div class="sect3">
17826<h4 id="_vulkan_only_samplers_images_textures_and_buffers">12.2.4. Vulkan Only: Samplers, Images, Textures, and Buffers</h4>
17827<div class="sect4">
17828<h5 id="_storage_images">Storage Images</h5>
17829<div class="paragraph">
17830<p>Storage images are declared in GLSL shader source using uniform image
17831variables of the appropriate dimensionality as well as a format layout
17832qualifier (if necessary):</p>
17833</div>
17834<div class="literalblock">
17835<div class="content">
17836<pre>layout (set=m, binding=n, r32f) uniform image2D myStorageImage;</pre>
17837</div>
17838</div>
17839<div class="paragraph">
17840<p>Which maps to the following SPIR-V:</p>
17841</div>
17842<div class="literalblock">
17843<div class="content">
17844<pre>        ...
17845%1 = OpExtInstImport "GLSL.std.450"
17846        ...
17847        OpName %9 "myStorageImage"
17848        OpDecorate %9 DescriptorSet m
17849        OpDecorate %9 Binding n
17850%2 = OpTypeVoid
17851%3 = OpTypeFunction %2
17852%6 = OpTypeFloat 32
17853%7 = OpTypeImage %6 2D 0 0 0 2 R32f
17854%8 = OpTypePointer UniformConstant %7
17855%9 = OpVariable %8 UniformConstant
17856        ...</pre>
17857</div>
17858</div>
17859</div>
17860<div class="sect4">
17861<h5 id="_samplers">Samplers</h5>
17862<div class="paragraph">
17863<p>SPIR-V samplers are declared in GLSL shader source using uniform <strong>sampler</strong> and
17864<strong>samplerShadow</strong> types:</p>
17865</div>
17866<div class="literalblock">
17867<div class="content">
17868<pre>layout (set=m, binding=n) uniform sampler mySampler;</pre>
17869</div>
17870</div>
17871<div class="paragraph">
17872<p>Which maps to the following SPIR-V:</p>
17873</div>
17874<div class="literalblock">
17875<div class="content">
17876<pre>        ...
17877%1 = OpExtInstImport "GLSL.std.450"
17878        ...
17879        OpName %8 "mySampler"
17880        OpDecorate %8 DescriptorSet m
17881        OpDecorate %8 Binding n
17882%2 = OpTypeVoid
17883%3 = OpTypeFunction %2
17884%6 = OpTypeSampler
17885%7 = OpTypePointer UniformConstant %6
17886%8 = OpVariable %7 UniformConstant
17887        ...</pre>
17888</div>
17889</div>
17890</div>
17891<div class="sect4">
17892<h5 id="_textures_sampled_images">Textures (Sampled Images)</h5>
17893<div class="paragraph">
17894<p>Textures are declared in GLSL shader source using uniform texture
17895variables of the appropriate dimensionality:</p>
17896</div>
17897<div class="literalblock">
17898<div class="content">
17899<pre>layout (set=m, binding=n) uniform texture2D mySampledImage;</pre>
17900</div>
17901</div>
17902<div class="paragraph">
17903<p>Which maps to the following SPIR-V:</p>
17904</div>
17905<div class="literalblock">
17906<div class="content">
17907<pre>        ...
17908%1 = OpExtInstImport "GLSL.std.450"
17909        ...
17910        OpName %9 "mySampledImage"
17911        OpDecorate %9 DescriptorSet m
17912        OpDecorate %9 Binding n
17913%2 = OpTypeVoid
17914%3 = OpTypeFunction %2
17915%6 = OpTypeFloat 32
17916%7 = OpTypeImage %6 2D 0 0 0 1 Unknown
17917%8 = OpTypePointer UniformConstant %7
17918%9 = OpVariable %8 UniformConstant
17919        ...</pre>
17920</div>
17921</div>
17922</div>
17923<div class="sect4">
17924<h5 id="_combined_texture_and_samplers">Combined Texture and Samplers</h5>
17925<div class="paragraph">
17926<p>Combined textures and samplers are declared in GLSL shader source using
17927uniform texture-combined sampler variables of the appropriate dimensionality:</p>
17928</div>
17929<div class="literalblock">
17930<div class="content">
17931<pre>layout (set=m, binding=n) uniform sampler2D myCombinedImageSampler;</pre>
17932</div>
17933</div>
17934<div class="paragraph">
17935<p>Which maps to the following SPIR-V:</p>
17936</div>
17937<div class="literalblock">
17938<div class="content">
17939<pre>        ...
17940%1 = OpExtInstImport "GLSL.std.450"
17941        ...
17942        OpName %10 "myCombinedImageSampler"
17943        OpDecorate %10 DescriptorSet m
17944        OpDecorate %10 Binding n
17945%2 = OpTypeVoid
17946%3 = OpTypeFunction %2
17947%6 = OpTypeFloat 32
17948%7 = OpTypeImage %6 2D 0 0 0 1 Unknown
17949%8 = OpTypeSampledImage %7
17950%9 = OpTypePointer UniformConstant %8
17951%10 = OpVariable %9 UniformConstant
17952        ...</pre>
17953</div>
17954</div>
17955<div class="paragraph">
17956<p>Note that a combined image sampler descriptor can be referred to as just
17957an image or sampler in the shader as per the above sections.</p>
17958</div>
17959</div>
17960<div class="sect4">
17961<h5 id="_combining_separate_samplers_and_textures">Combining Separate Samplers and Textures</h5>
17962<div class="paragraph">
17963<p>A sampler, declared with the keyword <strong>sampler</strong>, contains just filtering
17964information, containing neither a texture nor an image:</p>
17965</div>
17966<div class="literalblock">
17967<div class="content">
17968<pre>uniform sampler s;    // a handle to filtering information</pre>
17969</div>
17970</div>
17971<div class="paragraph">
17972<p>A texture, declared with keywords like <strong>texture2D</strong>, contains just image
17973information, not filtering information:</p>
17974</div>
17975<div class="literalblock">
17976<div class="content">
17977<pre>uniform texture2D t;  // a handle to a texture (an image in SPIR-V)</pre>
17978</div>
17979</div>
17980<div class="paragraph">
17981<p>Constructors can then be used to combine a sampler and a texture at the
17982point of making a texture lookup call:</p>
17983</div>
17984<div class="literalblock">
17985<div class="content">
17986<pre>texture(sampler2D(t, s), ...);</pre>
17987</div>
17988</div>
17989<div class="paragraph">
17990<p>Note, <code>layout()</code> information is omitted above for clarity of this feature.</p>
17991</div>
17992</div>
17993<div class="sect4">
17994<h5 id="_texture_buffers_uniform_texel_buffers">Texture Buffers (Uniform Texel Buffers)</h5>
17995<div class="paragraph">
17996<p>Texture buffers are declared in GLSL shader source using uniform
17997textureBuffer variables:</p>
17998</div>
17999<div class="literalblock">
18000<div class="content">
18001<pre>layout (set=m, binding=n) uniform textureBuffer myUniformTexelBuffer;</pre>
18002</div>
18003</div>
18004<div class="paragraph">
18005<p>Which maps to the following SPIR-V:</p>
18006</div>
18007<div class="literalblock">
18008<div class="content">
18009<pre>        ...
18010%1 = OpExtInstImport "GLSL.std.450"
18011        ...
18012        OpName %9 "myUniformTexelBuffer"
18013        OpDecorate %9 DescriptorSet m
18014        OpDecorate %9 Binding n
18015%2 = OpTypeVoid
18016%3 = OpTypeFunction %2
18017%6 = OpTypeFloat 32
18018%7 = OpTypeImage %6 Buffer 0 0 0 1 Unknown
18019%8 = OpTypePointer UniformConstant %7
18020%9 = OpVariable %8 UniformConstant
18021        ...</pre>
18022</div>
18023</div>
18024</div>
18025<div class="sect4">
18026<h5 id="_image_buffers_storage_texel_buffers">Image Buffers (Storage Texel Buffers)</h5>
18027<div class="paragraph">
18028<p>Image buffers are declared in GLSL shader source using uniform
18029imageBuffer variables:</p>
18030</div>
18031<div class="literalblock">
18032<div class="content">
18033<pre>layout (set=m, binding=n, r32f) uniform imageBuffer myStorageTexelBuffer;</pre>
18034</div>
18035</div>
18036<div class="paragraph">
18037<p>Which maps to the following SPIR-V:</p>
18038</div>
18039<div class="literalblock">
18040<div class="content">
18041<pre>        ...
18042%1 = OpExtInstImport "GLSL.std.450"
18043        ...
18044        OpName %9 "myStorageTexelBuffer"
18045        OpDecorate %9 DescriptorSet m
18046        OpDecorate %9 Binding n
18047%2 = OpTypeVoid
18048%3 = OpTypeFunction %2
18049%6 = OpTypeFloat 32
18050%7 = OpTypeImage %6 Buffer 0 0 0 2 R32f
18051%8 = OpTypePointer UniformConstant %7
18052%9 = OpVariable %8 UniformConstant
18053        ...</pre>
18054</div>
18055</div>
18056</div>
18057<div class="sect4">
18058<h5 id="_storage_buffers">Storage Buffers</h5>
18059<div class="paragraph">
18060<p>Storage buffers are declared in GLSL shader source using buffer storage
18061qualifier and block syntax:</p>
18062</div>
18063<div class="literalblock">
18064<div class="content">
18065<pre>layout (set=m, binding=n) buffer myStorageBuffer
18066{
18067    vec4 myElement[];
18068};</pre>
18069</div>
18070</div>
18071<div class="paragraph">
18072<p>Which maps to the following SPIR-V:</p>
18073</div>
18074<div class="literalblock">
18075<div class="content">
18076<pre>        ...
18077%1 = OpExtInstImport "GLSL.std.450"
18078        ...
18079        OpName %9 "myStorageBuffer"
18080        OpMemberName %9 0 "myElement"
18081        OpName %11 ""
18082        OpDecorate %8 ArrayStride 16
18083        OpMemberDecorate %9 0 Offset 0
18084        OpDecorate %9 BufferBlock
18085        OpDecorate %11 DescriptorSet m
18086        OpDecorate %11 Binding n
18087%2 = OpTypeVoid
18088%3 = OpTypeFunction %2
18089%6 = OpTypeFloat 32
18090%7 = OpTypeVector %6 4
18091%8 = OpTypeRuntimeArray %7
18092%9 = OpTypeStruct %8
18093%10 = OpTypePointer Uniform %9
18094%11 = OpVariable %10 Uniform
18095        ...</pre>
18096</div>
18097</div>
18098</div>
18099<div class="sect4">
18100<h5 id="_uniform_buffers">Uniform Buffers</h5>
18101<div class="paragraph">
18102<p>Uniform buffers are declared in GLSL shader source using the uniform storage
18103qualifier and block syntax:</p>
18104</div>
18105<div class="literalblock">
18106<div class="content">
18107<pre>layout (set=m, binding=n) uniform myUniformBuffer
18108{
18109    vec4 myElement[32];
18110};</pre>
18111</div>
18112</div>
18113<div class="paragraph">
18114<p>Which maps to the following SPIR-V:</p>
18115</div>
18116<div class="literalblock">
18117<div class="content">
18118<pre>        ...
18119%1 = OpExtInstImport "GLSL.std.450"
18120        ...
18121        OpName %11 "myUniformBuffer"
18122        OpMemberName %11 0 "myElement"
18123        OpName %13 ""
18124        OpDecorate %10 ArrayStride 16
18125        OpMemberDecorate %11 0 Offset 0
18126        OpDecorate %11 Block
18127        OpDecorate %13 DescriptorSet m
18128        OpDecorate %13 Binding n
18129%2 = OpTypeVoid
18130%3 = OpTypeFunction %2
18131%6 = OpTypeFloat 32
18132%7 = OpTypeVector %6 4
18133%8 = OpTypeInt 32 0
18134%9 = OpConstant %8 32
18135%10 = OpTypeArray %7 %9
18136%11 = OpTypeStruct %10
18137%12 = OpTypePointer Uniform %11
18138%13 = OpVariable %12 Uniform
18139        ...</pre>
18140</div>
18141</div>
18142</div>
18143<div class="sect4">
18144<h5 id="_subpass_inputs_2">Subpass Inputs</h5>
18145<div class="paragraph">
18146<p>Within a rendering pass, a subpass can write results to an output target
18147that can then be read by the next subpass as an input subpass.  The
18148"Subpass Input" feature regards the ability to read an output target.</p>
18149</div>
18150<div class="paragraph">
18151<p>Subpass inputs are read through a new set of types, available only
18152to fragment shaders:</p>
18153</div>
18154<div class="literalblock">
18155<div class="content">
18156<pre>subpassInput
18157subpassInputMS
18158isubpassInput
18159isubpassInputMS
18160usubpassInput
18161usubpassInputMS</pre>
18162</div>
18163</div>
18164<div class="paragraph">
18165<p>Unlike sampler and image objects, subpass inputs are implicitly addressed
18166by the fragment&#8217;s (<em>x</em>, <em>y</em>, <em>layer</em>) coordinate.</p>
18167</div>
18168<div class="paragraph">
18169<p>Input attachments are decorated with their input attachment index in
18170addition to descriptor set and binding numbers.</p>
18171</div>
18172<div class="literalblock">
18173<div class="content">
18174<pre>layout (input_attachment_index=i, set=m, binding=n) uniform subpassInput myInputAttachment;</pre>
18175</div>
18176</div>
18177<div class="paragraph">
18178<p>Which maps to the following SPIR-V:</p>
18179</div>
18180<div class="literalblock">
18181<div class="content">
18182<pre>        ...
18183%1 = OpExtInstImport "GLSL.std.450"
18184        ...
18185        OpName %9 "myInputAttachment"
18186        OpDecorate %9 DescriptorSet m
18187        OpDecorate %9 Binding n
18188        OpDecorate %9 InputAttachmentIndex i
18189%2 = OpTypeVoid
18190%3 = OpTypeFunction %2
18191%6 = OpTypeFloat 32
18192%7 = OpTypeImage %6 SubpassData 0 0 0 2 Unknown
18193%8 = OpTypePointer UniformConstant %7
18194%9 = OpVariable %8 UniformConstant
18195        ...</pre>
18196</div>
18197</div>
18198<div class="paragraph">
18199<p>An <em>input_attachment_index</em> of i selects the ith entry in the input pass
18200list. (See API specification for more information.)</p>
18201</div>
18202<div class="paragraph">
18203<p>These objects support reading the subpass input through the following
18204functions:</p>
18205</div>
18206<div class="literalblock">
18207<div class="content">
18208<pre>gvec4 subpassLoad(gsubpassInput   subpass);
18209gvec4 subpassLoad(gsubpassInputMS subpass, int sample);</pre>
18210</div>
18211</div>
18212</div>
18213</div>
18214<div class="sect3">
18215<h4 id="_mapping_variables">12.2.5. Mapping Variables</h4>
18216<div class="sect4">
18217<h5 id="_gl_fragcolor"><em>gl_FragColor</em></h5>
18218<div class="paragraph">
18219<p>The fragment-stage built-in <em>gl_FragColor</em>, which implies a broadcast to all
18220outputs, is not present in SPIR-V. Shaders where writing to <em>gl_FragColor</em>
18221is allowed can still write to it, but it only means to write to an output:</p>
18222</div>
18223<div class="ulist">
18224<ul>
18225<li>
18226<p>of the same type as <em>gl_FragColor</em></p>
18227</li>
18228<li>
18229<p>decorated with location 0</p>
18230</li>
18231<li>
18232<p>not decorated as a built-in variable.</p>
18233</li>
18234</ul>
18235</div>
18236<div class="paragraph">
18237<p>There is no implicit broadcast.</p>
18238</div>
18239</div>
18240<div class="sect4">
18241<h5 id="_vulkan_gl_vertexindex_and_gl_instanceindex">Vulkan <em>gl_VertexIndex</em> and <em>gl_InstanceIndex</em></h5>
18242<div class="paragraph">
18243<p>Adds two new built-in variables, <em>gl_VertexIndex</em> and <em>gl_InstanceIndex</em> to
18244replace the existing built-in variables <em>gl_VertexID</em> and <em>gl_InstanceID</em>.</p>
18245</div>
18246<div class="paragraph">
18247<p>In the situations where the indexing is relative to some base offset,
18248these built-in variables are defined, for Vulkan, to take on values as
18249follows:</p>
18250</div>
18251<div class="literalblock">
18252<div class="content">
18253<pre>gl_VertexIndex             base, base+1, base+2, ...
18254gl_InstanceIndex           base, base+1, base+2, ...</pre>
18255</div>
18256</div>
18257<div class="paragraph">
18258<p>Where it depends on the situation what the base actually is.</p>
18259</div>
18260</div>
18261<div class="sect4">
18262<h5 id="_storage_classes">Storage Classes:</h5>
18263<div class="literalblock">
18264<div class="content">
18265<pre>uniform sampler2D...;        -&gt; UniformConstant
18266uniform blockN { ... } ...;  -&gt; Uniform, with Block decoration
18267in / out variable            -&gt; Input/Output, possibly with block (below)
18268in / out block...            -&gt; Input/Output, with Block decoration
18269buffer  blockN { ... } ...;  -&gt; Uniform, with BufferBlock decoration
18270shared                       -&gt; Workgroup
18271&lt;normal global&gt;              -&gt; Private</pre>
18272</div>
18273</div>
18274<div class="literalblock">
18275<div class="content">
18276<pre>Vulkan Only: buffer  blockN { ... } ...;  -&gt; StorageBuffer, when requested
18277OpenGL Only: uniform variable (non-block) -&gt; UniformConstant
18278OpenGL Only: ... uniform atomic_uint ...  -&gt; AtomicCounter</pre>
18279</div>
18280</div>
18281</div>
18282<div class="sect4">
18283<h5 id="_inputoutput">Input/Output</h5>
18284<div class="paragraph">
18285<p>Mapping of input/output blocks or variables is the same for all versions
18286of GLSL or ESSL. To the extent variables or members are available in a
18287version, its location is as follows:</p>
18288</div>
18289<div class="paragraph">
18290<p>These are mapped to SPIR-V individual variables, with similarly spelled
18291built-in decorations (except as noted):</p>
18292</div>
18293<div class="paragraph">
18294<p>Any stage:</p>
18295</div>
18296<div class="literalblock">
18297<div class="content">
18298<pre>in gl_VertexIndex          (Vulkan only)
18299in gl_VertexID             (OpenGL only)
18300in gl_InstanceIndex        (Vulkan only)
18301in gl_InstanceID           (OpenGL only)
18302in gl_InvocationID
18303in gl_PatchVerticesIn      (PatchVertices)
18304in gl_PrimitiveIDIn        (PrimitiveID)
18305in/out gl_PrimitiveID      (in/out based only on storage qualifier)
18306in gl_TessCoord</pre>
18307</div>
18308</div>
18309<div class="literalblock">
18310<div class="content">
18311<pre>in/out gl_Layer
18312in/out gl_ViewportIndex</pre>
18313</div>
18314</div>
18315<div class="literalblock">
18316<div class="content">
18317<pre>patch in/out gl_TessLevelOuter  (uses Patch decoration)
18318patch in/out gl_TessLevelInner  (uses Patch decoration)</pre>
18319</div>
18320</div>
18321<div class="paragraph">
18322<p>Compute stage only:</p>
18323</div>
18324<div class="literalblock">
18325<div class="content">
18326<pre>in gl_NumWorkGroups
18327in gl_WorkGroupSize
18328in gl_WorkGroupID
18329in gl_LocalInvocationID
18330in gl_GlobalInvocationID
18331in gl_LocalInvocationIndex</pre>
18332</div>
18333</div>
18334<div class="paragraph">
18335<p>Fragment stage only:</p>
18336</div>
18337<div class="literalblock">
18338<div class="content">
18339<pre>in gl_FragCoord
18340in gl_FrontFacing
18341in gl_ClipDistance
18342in gl_CullDistance
18343in gl_PointCoord
18344in gl_SampleID
18345in gl_SamplePosition
18346in gl_HelperInvocation
18347out gl_FragDepth
18348in gl_SampleMaskIn        (SampleMask)
18349out gl_SampleMask         (in/out based only on storage qualifier)</pre>
18350</div>
18351</div>
18352<div class="paragraph">
18353<p>These are mapped to SPIR-V blocks, as implied by the pseudo code, with
18354the members decorated with similarly spelled built-in decorations:</p>
18355</div>
18356<div class="paragraph">
18357<p>Non-fragment stage:</p>
18358</div>
18359<div class="literalblock">
18360<div class="content">
18361<pre>in/out gl_PerVertex {   // some subset of these members will be used
18362    gl_Position
18363    gl_PointSize
18364    gl_ClipDistance
18365    gl_CullDistance
18366}                       // name of block is for debug only</pre>
18367</div>
18368</div>
18369<div class="paragraph">
18370<p>There is at most one input and one output block per stage in SPIR-V.
18371The subset and order of members will match between stages sharing an
18372interface.</p>
18373</div>
18374</div>
18375</div>
18376<div class="sect3">
18377<h4 id="_vulkan_only_mapping_of_precision_qualifiers">12.2.6. Vulkan Only: Mapping of Precision Qualifiers</h4>
18378<div class="literalblock">
18379<div class="content">
18380<pre>lowp     -&gt; RelaxedPrecision, on storage variable and operation
18381mediump  -&gt; RelaxedPrecision, on storage variable and operation
18382highp    -&gt; 32-bit, same as int or float</pre>
18383</div>
18384</div>
18385<div class="literalblock">
18386<div class="content">
18387<pre>portability tool/mode  -&gt; OpQuantizeToF16</pre>
18388</div>
18389</div>
18390</div>
18391<div class="sect3">
18392<h4 id="_mapping_of_precise">12.2.7. Mapping of <strong>precise</strong>:</h4>
18393<div class="literalblock">
18394<div class="content">
18395<pre>precise -&gt; NoContraction</pre>
18396</div>
18397</div>
18398</div>
18399<div class="sect3">
18400<h4 id="_opengl_mapping_of_atomic_uint_offset_layout_qualifier">12.2.8. OpenGL Mapping of <strong>atomic_uint</strong> <em>offset</em> layout qualifier</h4>
18401<div class="literalblock">
18402<div class="content">
18403<pre>offset         -&gt;  Offset (decoration)</pre>
18404</div>
18405</div>
18406</div>
18407<div class="sect3">
18408<h4 id="_mapping_of_images">12.2.9. Mapping of Images</h4>
18409<div class="literalblock">
18410<div class="content">
18411<pre>imageLoad()   -&gt; OpImageRead
18412imageStore()  -&gt; OpImageWrite
18413texelFetch()  -&gt; OpImageFetch
18414subpassInput  -&gt; OpTypeImage with Dim of SubpassData (Vulkan only)
18415subpassLoad() -&gt; OpImageRead                         (Vulkan only)</pre>
18416</div>
18417</div>
18418<div class="literalblock">
18419<div class="content">
18420<pre>imageAtomicXXX(params, data)  -&gt; %ptr = OpImageTexelPointer params
18421                                        OpAtomicXXX %ptr, data</pre>
18422</div>
18423</div>
18424<div class="literalblock">
18425<div class="content">
18426<pre>XXXQueryXXX(combined) -&gt; %image = OpImage combined
18427                                OpXXXQueryXXX %image</pre>
18428</div>
18429</div>
18430</div>
18431<div class="sect3">
18432<h4 id="_mapping_of_layouts">12.2.10. Mapping of Layouts</h4>
18433<div class="literalblock">
18434<div class="content">
18435<pre>std140/std430  -&gt;  explicit Offset, ArrayStride, and MatrixStride
18436                    Decoration on struct members
18437shared/packed  -&gt;  not allowed
18438&lt;default&gt;      -&gt;  not shared, but std140 or std430
18439xfb_offset     -&gt;  Offset Decoration on the object or struct member
18440xfb_buffer     -&gt;  XfbBuffer Decoration on the object
18441xfb_stride     -&gt;  XfbStride Decoration on the object
18442any xfb_*      -&gt;  the Xfb Execution Mode is set
18443captured XFB   -&gt;  has both XfbBuffer and Offset
18444non-captured   -&gt;  lacking XfbBuffer or Offset</pre>
18445</div>
18446</div>
18447<div class="literalblock">
18448<div class="content">
18449<pre>max_vertices   -&gt;  OutputVertices</pre>
18450</div>
18451</div>
18452</div>
18453<div class="sect3">
18454<h4 id="_mapping_of_barriers">12.2.11. Mapping of barriers</h4>
18455<div class="literalblock">
18456<div class="content">
18457<pre>barrier() (compute) -&gt; OpControlBarrier(/*Execution*/Workgroup,
18458                                        /*Memory*/Workgroup,
18459                                        /*Semantics*/AcquireRelease |
18460                                                    WorkgroupMemory)</pre>
18461</div>
18462</div>
18463<div class="literalblock">
18464<div class="content">
18465<pre>barrier() (tess control) -&gt; OpControlBarrier(/*Execution*/Workgroup,
18466                                            /*Memory*/Invocation,
18467                                            /*Semantics*/None)</pre>
18468</div>
18469</div>
18470<div class="literalblock">
18471<div class="content">
18472<pre>memoryBarrier() -&gt; OpMemoryBarrier(/*Memory*/Device,
18473                                    /*Semantics*/AcquireRelease |
18474                                                UniformMemory |
18475                                                WorkgroupMemory |
18476                                                ImageMemory)</pre>
18477</div>
18478</div>
18479<div class="literalblock">
18480<div class="content">
18481<pre>memoryBarrierBuffer() -&gt; OpMemoryBarrier(/*Memory*/Device,
18482                                        /*Semantics*/AcquireRelease |
18483                                                    UniformMemory)</pre>
18484</div>
18485</div>
18486<div class="literalblock">
18487<div class="content">
18488<pre>memoryBarrierShared() -&gt; OpMemoryBarrier(/*Memory*/Device,
18489                                        /*Semantics*/AcquireRelease |
18490                                                    WorkgroupMemory)</pre>
18491</div>
18492</div>
18493<div class="literalblock">
18494<div class="content">
18495<pre>memoryBarrierImage() -&gt; OpMemoryBarrier(/*Memory*/Device,
18496                                        /*Semantics*/AcquireRelease |
18497                                                    ImageMemory)</pre>
18498</div>
18499</div>
18500<div class="literalblock">
18501<div class="content">
18502<pre>groupMemoryBarrier() -&gt; OpMemoryBarrier(/*Memory*/Workgroup,
18503                                        /*Semantics*/AcquireRelease |
18504                                                    UniformMemory |
18505                                                    WorkgroupMemory |
18506                                                    ImageMemory)</pre>
18507</div>
18508</div>
18509</div>
18510<div class="sect3">
18511<h4 id="_mapping_of_atomics">12.2.12. Mapping of atomics</h4>
18512<div class="literalblock">
18513<div class="content">
18514<pre>all atomic builtin functions -&gt; Semantics = None(Relaxed)</pre>
18515</div>
18516</div>
18517<div class="literalblock">
18518<div class="content">
18519<pre>atomicExchange()             -&gt; OpAtomicExchange
18520imageAtomicExchange()        -&gt; OpAtomicExchange
18521atomicCompSwap()             -&gt; OpAtomicCompareExchange
18522imageAtomicCompSwap()        -&gt; OpAtomicCompareExchange
18523N/A                          -&gt; OpAtomicCompareExchangeWeak</pre>
18524</div>
18525</div>
18526</div>
18527<div class="sect3">
18528<h4 id="_opengl_only_mapping_of_atomics">12.2.13. OpenGL Only: Mapping of Atomics</h4>
18529<div class="literalblock">
18530<div class="content">
18531<pre>atomicCounterIncrement -&gt; OpAtomicIIncrement
18532atomicCounterDecrement -&gt; OpAtomicIDecrement
18533atomicCounter          -&gt; OpAtomicLoad</pre>
18534</div>
18535</div>
18536</div>
18537<div class="sect3">
18538<h4 id="_mapping_of_other_instructions">12.2.14. Mapping of other instructions</h4>
18539<div class="literalblock">
18540<div class="content">
18541<pre>%     -&gt; OpUMod/OpSMod
18542mod() -&gt; OpFMod
18543N/A   -&gt; OpSRem/OpFRem</pre>
18544</div>
18545</div>
18546<div class="literalblock">
18547<div class="content">
18548<pre>pack/unpack (conversion)    -&gt; pack/unpack in GLSL extended instructions
18549pack/unpack (no conversion) -&gt; OpBitcast</pre>
18550</div>
18551</div>
18552</div>
18553</div>
18554</div>
18555</div>
18556</div>
18557<div id="footer">
18558<div id="footer-text">
18559Version 4.60.7<br>
18560Last updated 2019-07-10 14:42:53 MDT
18561</div>
18562</div>
18563
18564<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-MML-AM_HTMLorMML"></script>
18565</body>
18566</html>