Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Tags in this Discussion

OptiX rendering to FBO possible?
  • The OptiX docs say that OptiX can interop with OpenGL "buffer objects" for read/write operations and it names VBO and PBO as examples. However, nothing is said about FBO as far as I can see.

    Is it possible to use an FBO with a RENDER_BUFFER attachment as output buffer for Optix? I have tried that but I do not receive the correct image. My FBO usage might be missing something, though. But before I start investigating this in depth I would like to have confirmed whether or not OptiX can do this at all. Since rendering to a RENDER_BUFFER directly is mentioned as being unsupported.

    Thanks,
    Stefan
  • 4 Comments sorted by
  • Vote Up0Vote Down Detlef Roettger
    Posts: 330 Accepted Answer
    With my former OpenGL driver developer hat on: You're mixing two totally different things. It's getting clearer when you write these three letter acronyms in their explicit meaning:
    Vertex-Bufferobject
    Pixel-Bufferobject
    Framebuffer-Object
    The first two are real memory, the third is just an OpenGL object managing framebuffer attachments, it's just coincidence that there is a "buffer" in its name.

    For example, in SceniX we can render with OptiX to an OpenGL interop PBO which has been created with rtBufferCreateFromGLBO() (mind the BO = Bufferobject notation from above) and transfer it to an OpenGL texture by binding that PBO and using glTexImage2D() which is a fast GPU-to-GPU memory transfer then. Finally that texture is rendered to an FBO attachment with a full viewport quad if that is set as the render target.

    So the answer is like the OptiX docs say, no direct rendering to render buffers.
  • I was afraid of that being so, just wanted to be sure. I'd just hoped we would be able to bypass the texture step by getting directly into the FBO color attachment.

    So I take it that the fastest way to get the OptiX image is to raytrace to a V/PBO, copy the image to a texture and then render a fs quad (whether to FBO or directly to the back buffer, whereever we actually want it to be)?

    This seems to be overcomplicated. Maybe you can put your driver developer hat back on once again and explain (guess) with a couple of words why there is no support to raytrace directly into a RENDER_BUFFER such as an FBO attachment with Optix? While they might represent totally different things as opposed to V/PBO the RENDER_BUFFERs are also just a bunch of memory in the vram I would argue :)

    Thanks,
    Stefan
  • Yes, the PBO to texture method is what we use.
    Performance tips: For GL_RGBA format and GL_UNSIGNED_BYTE type use GL_BGRA8 as internalFormat of the texture for best transfer rates.
    For GL_RGBA and GL_FLOAT OptiX output_buffer data, use GL_RGBA32F as texture internalFormat parameter.
    And simply avoid float3 output_buffers!

    Well, while render buffers are just an abstraction for some GPU storage with an interface to specify its format and rectangular size, its memory layout is completely internal to the OpenGL implementation, means there is no easy array-like access to this like for buffer objects. You also cannot access their contents in OpenGL if they are not attached to FBOs. I'm not aware of ways to circumvent that.

    Getting the PBO into a texture is five lines of code:
    glBindTexture( target, id)
    glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, pbo );
    glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
    glTexImage2D( target, 0, internalFormat, width, height, 0, format, type, 0 );
    glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, 0 );

    Rendering a full viewport quad is like 1 to 21 lines of more OpenGL code. ;-)
    I don't consider that as complicated. Also you need to get it into a texture anyway when you start applying post-processing effects onto the output buffer (tone mapping HDR output, noise filters on Monte Carlo results, etc.).
  • Thanks for the tips.

    Sure its not many lines of code to copy the image from V/PBO to texture and to FBO or backbuffer from there. With "complicated" I was just pointing out that this seems to be an unneccessary step. We are rendering all of our data into an FBO and apply various effects there, o using a texture is, at least for us, an intermediate step we could do without.

    Thanks again for providing the technical infos so fast :)

    regards,
    Stefan