Skip vertices vs rebuild geometry (shader optimization)

Hi everyone,

I working on some kind of editor which displays large numbers of simple objects and provides basic modifications (move, size, color etc). Attributes are located inside the InstancedBufferGeometry to keep render time low. But each time user adds item I have to create new InstancedBufferGeometry (in worst case).
The partial solution is to declare buffer with extra space and attribute “visible”. If “visible” is “false” then gl_Position set somewhere outside camera therefore item not displayed and fragment shader is not called.
But if number of visible items is low (less than 10%) then vertex shader will have to do much extra work.
My question: is it possible somehow to detect how much GPU power spent inside vertex shader and how much GPU power spent inside fragment shader? This could be helpful for optimal design of high loaded 3D applications.
upd: I know about geometry.setDrawRange() method. This could be good solution actually. But I am also interesting is it possible to measture GPU power distribution between vertex and fragment shaders.

Instead of allocating a new instancedBuffer each time, you could double its size each time, and only set its .count to the actual number of instances you are using, leaving you room to add more, until it fills up, at which point you double it again.

I do that kind of allocation in the InstanceGroup class in here:

1 Like

Thank you for reply. Your proposal is definitely one of options.
But in case when user deletes big number of objects InstanceBufferArray could become almost empty. In this case GPU will have to perform extra work during rendering which could be avoided. Also every time when user edits single item then large buffer array with empty data will be passed to the GPU.
If to shrink InstanceBufferArray then this performance problems will be solved. But this is also costly operation. This is why I trying to get any way to actually measure performance details of fragment and vertex shaders.

I just realized that I could measure this by setting complex geometries with very small visible size. Changing visible size will change part of fragment shader load.
Then I could calculate GPU power distribution between shaders.
But this is an implicit way so I would really appreciate if someone helps with direct way to measure GPU power distribution.

I’d love to know how to profile individual shaders too. I wish you luck but I think this is hard to do well.

My advice would be what @manthrax suggests – allocate 1.5-2x more instances than you need, reduce the draw range or count to what is currently needed. You’re using a bit of extra VRAM for the allocated memory, but it’s not being processed each frame, this will be better for performance than trying to detect vertex or instance attributes and discard in the shader.

1 Like