Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/docs/EMSCRIPTEN_explicit_uniform_binding.txt
4128 views
1
Name
2
3
EMSCRIPTEN_explicit_uniform_binding
4
5
Name Strings
6
7
GL_EMSCRIPTEN_explicit_uniform_binding
8
9
Contributors
10
11
Jukka Jylänki, Unity Technologies
12
Brendan Duncan, Unity Technologies
13
14
Contact
15
16
Jukka Jylänki, Unity Technologies (jukkaj 'at' unity3d.com)
17
Brendan Duncan, Unity Technologies (brendan.duncan 'at' unity3d.com)
18
19
Status
20
21
Implemented in Emscripten 2.0.18 and newer for OpenGL ES 2 and
22
OpenGL ES 3 contexts. (April 2021)
23
24
Version
25
26
Date: April 13, 2021
27
Revision: 1
28
29
Dependencies
30
31
Emscripten 2.0.18 compiler targeting OpenGL ES 2.0 or OpenGL ES 3.0
32
versions.
33
34
Written against the OpenGL ES 2.0.25 and WebGL 1 specifications.
35
36
Overview
37
38
WebGL 1 API provides a special type of uniforms called texture samplers.
39
The organization of these samplers is designed around the concept of
40
a file of device global multitexturing binding points. This provides a
41
layer of indirection: instead of directly connecting texture objects to
42
sampler uniforms in the shader, textures are set active in multitexturing
43
binding points, and samplers uniforms then each select a binding point to
44
sample from.
45
46
WebGL 2 API provides support for Uniform Buffer Objects (UBOs). Again,
47
instead of directly connecting a GPU buffer to a uniform block in the
48
shader, each UBO variable is connected to a slot in a file of uniform
49
block binding points, and the uniform block variables are assigned to
50
read from one of these uniform block binding points.
51
52
Sampler uniforms are assigned a multitexturing unit by calling the
53
function gl.uniform1i(). Uniform blocks are assigned a uniform block
54
binding point by calling the function gl.uniformBlockBinding().
55
56
By default after a successful shader link, all samplers and uniform blocks
57
are initially assigned the binding point zero. Instead of programmatically
58
reassigning the binding points in Wasm/JS code, it can be useful to specify
59
the default binding point to use in GLSL shader code. This allows a shader
60
compilation backend to generate multiple shader programs that have mutually
61
compatible layouts, without needing further coordination in application
62
code.
63
64
This extension adds support for specifying the initial multitexturing and
65
uniform block binding points for texture samplers and uniform blocks. This
66
is achieved via the same syntax that is available in Desktop OpenGL 4.2 and
67
the extension ARB_shading_language_420pack. There, a programmer may choose
68
to specify the integer binding point of a texture sampler or a uniform
69
block in advance directly in the submitted shader code. The GLSL directive
70
71
layout(binding = x) uniform sampler2D diffuse;
72
73
specifies that the sampler 'diffuse' should sample a texture located in
74
multitexturing unit 'x'.
75
76
Likewise, specifying
77
78
layout(binding = x) uniform myBlock { vec4 color; }
79
80
specifies that the uniform block 'myBlock' should read from the Uniform
81
Buffer Object located at uniform block binding point 'x'.
82
83
In sibling specifications, support for explicit binding points exist in
84
Desktop OpenGL 4.2 core specification and in the extension
85
ARB_shading_language_420pack.
86
87
New Procedures and Functions
88
89
None.
90
91
New Tokens
92
93
None.
94
95
Additions to OpenGL ES Shading Language 1.00 Specification
96
97
Add to sampler qualifiers:
98
99
The qualifier "layout(binding = x)" can be prepended to a texture sampler
100
variable directive to bind the integer multitexturing unit that the given
101
sampler reads from:
102
103
layout(binding = x) uniform sampler2D diffuse;
104
105
Only one layout qualifier may appear in a single declaration.
106
107
Any sampler declared without a binding identifier is initially assigned to
108
sample from multitexturing unit zero. After a program is linked, the binding
109
points used for samplers with or without a binding identifier can be updated
110
by the OpenGL API.
111
112
If the binding identifier is used with an array, the first element of the
113
array takes the specified unit and each subsequent element takes the next
114
consecutive unit.
115
116
If the binding is less than zero, or greater than or equal to the
117
implementation-dependent maximum supported number of units, a compilation
118
error will occur. When the binding identifier is used with an array of size
119
N, all elements of the array from binding through binding + N - 1 must be
120
within this range.
121
122
Additions to OpenGL ES Shading Language 3.00 Specification
123
124
Add to Layout Qualifiers:
125
126
The qualifier "layout(binding = x)" can be prepended to a uniform block
127
variable directive:
128
129
layout(binding = x) uniform myBlock { vec4 color; }
130
131
The binding identifier specifies the uniform buffer binding point
132
corresponding to the uniform block, which will be used to obtain the
133
values of the member variables of the block.
134
135
Only one layout qualifier may appear in a single declaration.
136
137
Any uniform block declared without a binding identifier is initially
138
assigned to block binding point zero. After a program is linked, the
139
binding points used for uniform blocks declared with or without a binding
140
identifier can be updated by the OpenGL API.
141
142
If the binding identifier is used with a uniform block instanced as an
143
array then the first element of the array takes the specified block binding
144
and each subsequent element takes the next consecutive uniform block
145
binding point.
146
147
If the binding point for any uniform block instance is less than zero, or
148
greater than or equal to the implementation-dependent maximum number of
149
uniform buffer bindings, a compilation error will occur. When the binding
150
identifier is used with a uniform block instanced as an array of size N,
151
all elements of the array from binding through binding + N - 1 must be
152
within this range.
153
154
Additions to Emscripten compiler
155
156
Instead of utilizing the runtime method WebGLRenderingContext.getExtension()
157
to coordinate enabling the extension, EMSCRIPTEN_explicit_uniform_binding
158
activation is controlled at compile time by specifying the flag
159
160
-sGL_EXPLICIT_UNIFORM_BINDING
161
162
to 'emcc' or 'em++' linker command line in the Emscripten compiler.
163
164
When this flag is passed, the extension EMSCRIPTEN_explicit_uniform_binding
165
is enabled for all contexts created in the application.
166
167
The choice of compile time activation is due to the considerable increase in
168
code size that is involved in enabling this extension.
169
170
Revision History
171
172
Revision 1.0, April 13, 2021: juj
173
- First version
174
175