0

Suppose I have a one big shader program and want only specific ranges of vertices/triangles rendered.

What are some performant ways of doing this? Which one looks most promising?

I came up with 3 methods, are there some more?

  1. Batching draw calls Draw(position, count) using command lists. (Opengl has glMultiDrawArrays.)

If the ranges are known ahead of time, we don't need to worry about the time spent constructing them. However, since some ranges change unpredictably, it is probably unrealistic to keep command lists for all possibilities.

This method obviously reduces the time spent constructing the draw calls on CPU side and I assume that these calls already tell the GPU that it does not need to do any state changes.

  1. Call Draw on the whole buffer and keep updating a boolean per-vertex float buffer which would just multiply the output positions by 0/1 in inactive/active ranges.

The benefit here is only one draw call. However, we need to update the buffer and it seems like the buffer needs to be locked while we update it...

  1. Powerset defined in a constant buffer. For n ranges, we can use one n-bit constant mask compared against a static n-bit per_vertex_mask. Vertex is visible if mask & per_vertex_mask != 0.

Constant buffers are probably cheaper to update than a whole vertex buffer. The number of ranges may however be too large for this method.

thehorseisbrown
  • 390
  • 2
  • 14
  • You likely already know that you should try various approaches and evaluate them objectively. Have you identified a bottleneck in your application? – Wyck Oct 06 '20 at 00:50
  • I don’t think the question can be answered. “ranges of vertices/triangles” vertices or triangles? Indexed or not? Instanced or not? How many ranges? How long are ranges typically? Where’s source data for the ranges, in system RAM or in VRAM e.g. made by a compute shader? – Soonts Oct 10 '20 at 15:42

0 Answers0