gl_BaseVertex and gl_BaseInstance vertex shader builtins

362 views
Skip to first unread message

Ken Russell

unread,
Apr 22, 2021, 3:48:23 PM4/22/21
to WebGL Dev List
Dear WebGL community,

The browser implementers are finishing these two extensions, which provide control over the BaseVertex and BaseInstance for instanced draw calls:


There's one outstanding question: how important are the gl_BaseVertex and gl_BaseInstance vertex shader variables for your use cases?

These can be easily emulated at the application level - just create two uniform variables and set them before issuing the draw or multi-draw call. These extensions can likely be shipped more quickly if we split off the gl_BaseVertex and gl_BaseInstance shader builtins into a separate extension, or just don't include them in WebGL's version of these extensions at all.

Thanks,

-Ken


--
I support flexible work schedules, and I’m sending this email now because it is within the hours I’m working today.  Please do not feel obliged to reply straight away - I understand that you will reply during the hours you work, which may not match mine. (credit: jparent@)

Philip Taylor

unread,
Apr 22, 2021, 7:52:04 PM4/22/21
to webgl-d...@googlegroups.com
I personally have trouble understanding where I could use these particular calls, or at least where they eliminate some limitations in WebGL today.
" The baseVertex functionality could effectively help reduce CPU overhead with static batching and text rendering in game engine implementations."
I can imagine some mesh font atlas where we can draw each letter by specifying its first vertex, and draw the number of elements for that letter. 
We get the same ability now with multi-draw, but a lot more versatile, so I'm  not sure what this adds. 
Maybe someone can enlighten me...


--
You received this message because you are subscribed to the Google Groups "WebGL Dev List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webgl-dev-lis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/webgl-dev-list/CAMYvS2fTv36kLcDmQhQqKpUUE_NAUAU8EGW%2BYyCvEDMODozFSA%40mail.gmail.com.

Ib Green

unread,
Apr 22, 2021, 8:25:55 PM4/22/21
to WebGL Dev List
Hi Ken,
 
From luma.gl/deck.gl perspective, without thinking through things too deeply, this could be potentially useful extensions as we continue to improve our filtering support for instanced tables.

About your question concerning the new GLSL variables, we currently use instance ids in shaders primarily for our color based picking where we do a separate render pass - we "RGBA color code" instances into our "picking texture", and then determine the instance under the pixel by decoding the color in the selected pixel(s).

Having the base offsets available in the shader would be convenient, but as you say it is not hard to work around, adding it as a uniform, or offsetting the result on the CPU after read back doesn't seem very onerous. 

In fact, we are already in effect emulating vertex instances with a separate attribute array (needed on WebGL 1), so we are already going through some ugly hoops.

PS - What we would really love would be to be able to specify a counterpart to the ELEMENT buffer (indices) for the instance array so that we could cheaply "filter" instances but I assume GPUs don't support that...

Ken Russell

unread,
Jun 11, 2021, 6:44:45 PM6/11/21
to WebGL Dev List
Hi Philip, Ib,

Sorry for the long delay coming back to this. Couple of inline comments:

On Thu, Apr 22, 2021 at 5:25 PM Ib Green <i...@unfolded.ai> wrote:
Hi Ken,
 
From luma.gl/deck.gl perspective, without thinking through things too deeply, this could be potentially useful extensions as we continue to improve our filtering support for instanced tables.

About your question concerning the new GLSL variables, we currently use instance ids in shaders primarily for our color based picking where we do a separate render pass - we "RGBA color code" instances into our "picking texture", and then determine the instance under the pixel by decoding the color in the selected pixel(s).

Having the base offsets available in the shader would be convenient, but as you say it is not hard to work around, adding it as a uniform, or offsetting the result on the CPU after read back doesn't seem very onerous. 

In fact, we are already in effect emulating vertex instances with a separate attribute array (needed on WebGL 1), so we are already going through some ugly hoops.

OK, thanks for this input. We're going to proceed with removing the gl_BaseVertex and gl_BaseInstance GLSL variables from the WebGL specifications because they can be easily emulated by the application if needed. Being able to specify BaseVertex/BaseInstance is probably still marginally useful even for the multi-draw calls, so we'll proceed with exposing these.
 
PS - What we would really love would be to be able to specify a counterpart to the ELEMENT buffer (indices) for the instance array so that we could cheaply "filter" instances but I assume GPUs don't support that...

Are you referring to the regular drawArraysInstanced calls, or the per-draw instance counts in WEBGL_multi_draw?

If the former - yes, the hardware doesn't support that. You might be able to emulate this by passing in a uniform buffer object containing an array of the instances you want to filter out, and then if gl_InstanceID matches one of those, you could make all the triangles degenerate in the vertex shader - move the vertices to (0,0,0).

If the latter - it should be possible to just change the instanceCount for one of the draw calls to 0.

 
On Thursday, April 22, 2021 at 4:52:04 PM UTC-7 Philip Taylor wrote:
I personally have trouble understanding where I could use these particular calls, or at least where they eliminate some limitations in WebGL today.
" The baseVertex functionality could effectively help reduce CPU overhead with static batching and text rendering in game engine implementations."
I can imagine some mesh font atlas where we can draw each letter by specifying its first vertex, and draw the number of elements for that letter. 
We get the same ability now with multi-draw, but a lot more versatile, so I'm  not sure what this adds. 
Maybe someone can enlighten me...

My limited understanding is that this functionality allows better reuse of the element arrays for rendering many of the same-sized pieces of geometry. People writing UI libraries and drawing lots of quads submitted the initial requests for these extensions.

Multi-draw is pretty handy - we're hoping it enables much better scaling of WebGL apps drawing a lot of geometry.

-Ken


On Thu., Apr. 22, 2021, 3:48 p.m. 'Ken Russell' via WebGL Dev List, <webgl-d...@googlegroups.com> wrote:
Dear WebGL community,

The browser implementers are finishing these two extensions, which provide control over the BaseVertex and BaseInstance for instanced draw calls:


There's one outstanding question: how important are the gl_BaseVertex and gl_BaseInstance vertex shader variables for your use cases?

These can be easily emulated at the application level - just create two uniform variables and set them before issuing the draw or multi-draw call. These extensions can likely be shipped more quickly if we split off the gl_BaseVertex and gl_BaseInstance shader builtins into a separate extension, or just don't include them in WebGL's version of these extensions at all.

Thanks,

-Ken


--
I support flexible work schedules, and I’m sending this email now because it is within the hours I’m working today.  Please do not feel obliged to reply straight away - I understand that you will reply during the hours you work, which may not match mine. (credit: jparent@)

--
You received this message because you are subscribed to the Google Groups "WebGL Dev List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webgl-dev-lis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/webgl-dev-list/CAMYvS2fTv36kLcDmQhQqKpUUE_NAUAU8EGW%2BYyCvEDMODozFSA%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "WebGL Dev List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webgl-dev-lis...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages