问题
I want to transfer contents of a very large memory chunk to a sufficiently large GPU buffer and then immediately alter the contents of memory on CPU. Something like this in pseudo-code:
glBindBuffer(/*very_large_buffer*/);
glBufferSubData(/*very_large_memory_chunk*/);
memset(/*zeros*/, /*very_large_memory_chunk*/);
In this code, what does glBufferSubData
actually do? Does it transfer very_large_memory_chunk somewhere before return or just schedules the transfer operation for possibly later execution? So if I start altering the CPU buffer immediately, is it possible that partially altered memory will be transfered, yielding garbage in GPU's very_large_buffer?
Note that I'm not asking about rendering calls. I know that if the buffer is used for rendering, transfer operations will wait until rendering is complete and vice versa. I want to know if OpenGL behaves the alike way in CPU-to-GPU transfer operations.
回答1:
OpenGL doesn't define how glBufferSubData
has to be implemented: It can either copy the data immediately to GPU memory or it may defer the copy operation to a later point.
What OpenGL guarantees (OpenGL 4.5 Specification, Section 5.3) is that one can assume a call to glBufferSubData
to be completed when the method returns. This means that every implementation that defers the CPU->GPU copy operation has to make sure that the CPU memory is copied before returning.
In conclusion: You can change the content of the pointer immediately after the glBufferSubData
returns without modifying/destroying the buffers content.
来源:https://stackoverflow.com/questions/44667194/when-does-glbuffersubdata-return