AnsweredAssumed Answered

Simultaneous texture upload and rendering in OpenGL

Question asked by ljbade on Nov 17, 2012
Latest reply on Nov 17, 2012 by ljbade

I am currently experimenting to figure out the best way load textures in OpenGL using multiple threads. My final project will be doing a lot of texture streaming so I wanted to figure out the optimal design first.

 

I have created a simple application that uses two threads, one does some simple rendering in a loop, and the other loads a large texture ~100MB (to make any stalls obvious).

 

I followed the design recommended by NVIDIA: http://developer.download.nvidia.com/GTC/PDF/GTC2012/PresentationPDF/S0356-GTC2012-Texture-Transfers.pdf

 

Basically the render thread creates two shared GL contexts and assigns one to each thread.

 

The upload thread creates a pixel buffer and a texture object, reads the image data directly from disc into the buffer via glMapBufferRange with the write only and invalidate data flags, uses glTexSubImage2D to load the data, and inserts a GPU glFenceSync and the handle is passed back to the render thread.

 

The render thread runs in a loop and every frame uses glGetsynciv to test if the upload sync has been signalled. If it has not it simply renders another frame. but if it has it then binds the texture and renders with it.

 

The problem I am having is that glTexSubImage2D always stalls the render thread in SwapBuffers until it finishes. It even does this if the render thread never binds the texture (so there is no rendering dependant on it).

 

I even tried using the AMD_pinned_memory extension the same way as shown in the example for the extension but it did not change anything.

 

What is the correct way to perform simultaneous texture loading and rendering on a AMD GPU that doesn't cause any rendering stalls?

Is there a good example somewhere?

 

I notice that Rage on my laptop is very smooth and fluid despite loading significant amounts of texture data on the fly so it must be possible.

Outcomes