Skip to content

Commit

Permalink
Remove gl_BaseVertex/gl_BaseInstance from WEBGL_draw_instanced_base_v…
Browse files Browse the repository at this point in the history
…ertex_base_instance. (KhronosGroup#3278)

Update associated multi-draw extension spec, and test, as well.
Expand test with easy-to-debug 1x1 expected value tests.
  • Loading branch information
kdashg authored May 26, 2021
1 parent 6eafd07 commit 7e38e87
Show file tree
Hide file tree
Showing 4 changed files with 290 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
This extension exposes the <code>DrawArraysInstancedBaseInstanceANGLE</code> and
<code>DrawElementsInstancedBaseVertexBaseInstanceANGLE</code> entrypoints as
<code>drawArraysInstancedBaseInstanceWEBGL</code> and
<code>drawElementsInstancedBaseVertexBaseInstanceWEBGL</code>. In addition the vertex
shader builtin <code>gl_BaseVertex</code> and <code>gl_BaseInstance</code> are added.
<code>drawElementsInstancedBaseVertexBaseInstanceWEBGL</code>.
</addendum>
<addendum>
The vertex shader extension GL_ANGLE_base_vertex_base_instance is not added.
The vertex shader builtins <code>gl_BaseVertex</code> and <code>gl_BaseInstance</code> are not added.
</addendum>
<addendum>
The implementation must validate the arrays and indices referenced by
Expand All @@ -38,16 +41,6 @@
Range Checking
</a> of the WebGL specification.
</addendum>
<addendum>
Although the extension name is named WEBGL_draw_instanced_base_vertex_base_instance, the
extension must be enabled with the
<code>#extension GL_ANGLE_base_vertex_base_instance</code> directive, as shown in the
sample code, to use the extension in a shader.

Likewise the shading language preprocessor
<code>#define GL_ANGLE_base_vertex_base_instance</code> will be defined to 1 if the
extension is supported.
</addendum>

<div class="nonnormative">
<p>
Expand All @@ -73,28 +66,6 @@
driver is <code>baseVertex</code> instead of zero, and that the first element within those
instanced vertex attributes is specified in <code>baseInstance</code>.
</feature>

<feature>
The <code>gl_BaseVertex</code> and <code>gl_BaseInstance</code> builtins are added to the
shading language. For any *BaseVertex* draw call variant, the <code>baseVertex</code> of
the draw may be read by the vertex shader as <code>gl_BaseVertex</code>. For non
*BaseVertex* calls, the value of <code>gl_BaseVertex</code> is 0. For any *BaseInstance
draw call variant, the <code>baseInstance</code> of the draw may be read by the vertex
shader as <code>gl_BaseInstance</code>. For non *BaseInstance calls, the value of
<code>gl_BaseInstance</code> is 0.
</feature>

<feature>
Notice that the value of <code>gl_BaseVertex</code> is added into <code>gl_VertexID</code>,
while the value of <code>gl_BaseInstance</code> is not added into
<code>gl_InstanceID</code>.
</feature>

<glsl extname="GL_ANGLE_base_vertex_base_instance">
<stage type="vertex"/>
<input name="gl_BaseVertex" type="int" />
<input name="gl_BaseInstance" type="int" />
</glsl>
</features>
</overview>

Expand Down Expand Up @@ -146,6 +117,8 @@ var ext = gl.getExtension("WEBGL_draw_instanced_base_vertex_base_instance");
let count = 3;
let instanceCount = 2;
let baseInstance = 1;
gl.uniform1i(u_BaseVertex_location, 0);
gl.uniform1i(u_BaseInstance_location, baseInstance);
ext.drawArraysInstancedBaseInstanceWEBGL(
gl.TRIANGLES, first, count, instanceCount, baseInstance);
}
Expand All @@ -157,17 +130,20 @@ var ext = gl.getExtension("WEBGL_draw_instanced_base_vertex_base_instance");
let count = 3;
let offset = 0;
let instanceCount = 2;
let baseVertice = 3;
let baseVertex = 3;
let baseInstance = 1;
gl.uniform1i(u_BaseVertex_location, baseVertex);
gl.uniform1i(u_BaseInstance_location, baseInstance);
ext.drawElementsInstancedBaseVertexBaseInstanceWEBGL(
gl.TRIANGLES, count, gl.UNSIGHNED_SHORT, offset, instanceCount, baseVertex, baseInstance);
}
</pre>
<pre>
#version 300 es
#extension GL_ANGLE_base_vertex_base_instance : require
uniform int u_BaseVertex;
uniform int u_BaseInstance;
void main() {
gl_Position = vec4(gl_BaseVertex, gl_InstanceID + gl_BaseInstance, 0, 1);
gl_Position = vec4(u_BaseVertex, gl_InstanceID + u_BaseInstance, 0, 1);
}
</pre>
</samplecode>
Expand All @@ -183,5 +159,8 @@ void main() {
<revision date="2019/09/25">
<change>Move to draft.</change>
</revision>
<revision date="2021/05/26">
<change>Removed GLSL extension and builtins.</change>
</revision>
</history>
</draft>
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
This extension exposes the <code>MultiDrawArraysInstancedBaseInstanceANGLE</code> and
<code>MultiDrawElementsInstancedBaseVertexBaseInstanceANGLE</code> entrypoints as
<code>multiDrawArraysInstancedBaseInstanceWEBGL</code> and
<code>multiDrawElementsInstancedBaseVertexBaseInstanceWEBGL</code>. In addition the vertex
shader builtins <code>gl_BaseVertex</code> and <code>gl_BaseInstance</code> are added.
<code>multiDrawElementsInstancedBaseVertexBaseInstanceWEBGL</code>.
</addendum>
<addendum>
The implementation must validate the arrays and indices referenced by
Expand All @@ -42,16 +41,6 @@
Range Checking
</a> of the WebGL specification.
</addendum>
<addendum>
Although the extension is named WEBGL_multi_draw_instanced_base_vertex_base_instance, the
extension must be enabled with the
<code>#extension GL_ANGLE_base_vertex_base_instance</code> directive, as shown in the sample
code, to use the extension in a shader.

Likewise the shading language preprocessor
<code>#define GL_ANGLE_base_vertex_base_instance</code> will be defined to 1 if the
extension is supported.
</addendum>

<div class="nonnormative">
<p>The baseVertex functionality could effectly help reduce CPU overhead with static batching
Expand Down Expand Up @@ -180,9 +169,8 @@ var ext = gl.getExtension("WEBGL_multi_draw_instanced_base_vertex_base_instance"
</pre>
<pre>
#version 300 es
#extension GL_ANGLE_base_vertex_base_instance : require
void main() {
gl_Position = vec4(gl_BaseVertex, gl_InstanceID + gl_BaseInstance, 0, 1);
gl_Position = vec4(gl_VertexID, gl_InstanceID, 0, 1);
}
</pre>
</samplecode>
Expand Down Expand Up @@ -212,5 +200,8 @@ void main() {
<revision date="2021/05/18">
<change>Add [AllowShared] to all typed array arguments for compatibility with multi-threaded WebAssembly.</change>
</revision>
<revision date="2021/05/26">
<change>Removed GLSL extension and builtins.</change>
</revision>
</history>
</draft>
Loading

0 comments on commit 7e38e87

Please sign in to comment.