4

I don't quite have a 100% clear picture how the Draw Instanced/Draw Indirect family of functions all the way down to glDrawElementsInstancedBaseVertexBaseInstance work together.

Using OpenGL 4.0+ & OpenCL interop capable hardware and drivers, how (if possible) can we leverage tools like draw indirect (now also multi draw indirect) to draw an instanced geometry across multiple frames while changing geometry on the GPU?

For example, could one tessellate a shape then apply some filter to the shape via opencl all while referring to geometries the CPU will only need to cull out when needed?

*Original post has been heavily edited

1 Answers1

4

It's not clear what you're asking here. The CL/GL interop defined by Khronos is thus far limited to shared buffers/textures and some event handling stuff, none of which seems related to tessellation. Since tessellation is a task specific to rasterization of polygon-based models, it is unlikely to ever be relevant enough to warrant a mention in the CL spec. If you're wondering whether tessellation hardware will be used by a CL implementation, then that depends entirely on the specific hardware capabilities and the CL implementation.

Update:

There are two kinds of tessellation shaders. Tessellation Control Shaders take in a patch (collection of triangles or quads) and compute some per-vertex attributes, most importantly, a number that controls the amount of subdivision that should be performed.

After the tessellation control shader runs, the resulting patch is passed to a fixed-function hardware unit that performs the actual subdivision to generate a new patch with more polygons.

After the subdivision, a Tessellation Evaluation Shader can compute attributes for each of the vertices in the patch generated by the subdivision process. This is the step in the process where you would, for example, lookup information in a displacement map stored as a texture.

Since the CL/GL interop only allows for buffer-based data exchange, in order to use CL for tessellation you would have to implement the entire tessellation process as essentially a preprocessor for your vertex data, and you would not be able to access from CL any dedicated hardware for the subdivision step. Since current hardware does (as far as I know) include a fixed-function subdivider instead of using general-purpose compute units, a tessellator implemented in CL would almost certainly be at a disadvantage for performance.

user57368
  • 5,675
  • 28
  • 39
  • In reference to the OpenGL 4 spec I read that there is improved interop with OpenCL. Usually the only explanation I can find is that there are additional programmable shaders along with draw_indirect. I've done some OpenCL work but my concept of the interop is fuzzy at best. – That Realty Programmer Guy Mar 09 '11 at 04:12
  • 1
    The draw_indirect extension (mandatory as of GL 4.0) is useful in tandem with CL interop because it allows the arguments to `DrawArraysInstanced` and `DrawElementsInstancedBaseVertex` to come from a buffer on the GPU instead of coming from the CPU, and CL interop allows that GL buffer to be shared with (and thus filled by) CL kernels. Basically, it means that code running on the GPU can do more things with/to vertex arrays with less decision-making performed on the CPU. The overall goal seems to be to offload everything but the synchronization and memory allocation to the GPU. – user57368 Mar 09 '11 at 07:20
  • So, can I use OpenCL to tesselate geometry data within a given buffer (of sufficient size to expand the data..) even if this is not part of the 'tesselation shader' phase? – That Realty Programmer Guy Mar 09 '11 at 07:25
  • 1
    you can do whatever you want with a buffer in OpenCL. if it is shared with GL you can render it (a VBO, texture etc). So yes you can use CL for tessellation if you really want to. – mbien Mar 10 '11 at 14:22
  • 1
    As @mbien says, you can create whatever data you want using OpenCL and put it in a VBO. I've tessellated geometry this way. It works. It's fast. It's not, strictly speaking, a "shader". But it does the same job. – sigfpe Mar 16 '11 at 22:42