2
$\begingroup$

On CPU dynamic arrays are often used to store data of dynamic size, and often implemented by doubling the size when the array is full and copying the data over. The data structure has amortized O(1) performance.

But is similar approach ever used and is practical GPU? Specifically for a similar scenario to when it is useful on CPU, for dynamically adding data into it?

On GPU we allocate a buffer and upload data to the buffer. We could make the buffer "dynamic" by reallocating double the size when it gets full, and copying the old data over to the new buffer. But how performance effective would this be?

$\endgroup$

1 Answer 1

2
$\begingroup$

This is a perfectly reasonable thing to do. GPU to GPU copies are fast. This is best suited to API's like Vulkan or DX12 but I don't see any reason why doing it under OpenGL/DX11 wouldn't work.

How big are these buffers? Allocating a large chunk of memory from OpenGL could set off a memory management event that causes it to move memory all over the place which could take a "long" time. Also if the buffers grow repeatedly it could cause fragmentation. But if the buffers are relatively small like a few MIBS in size then it really shouldn't be an issue.

I guess the other question is..."where" is this memory being allocated? If this is for buffers that are CPU visible then it becomes a lot more "sketchy" just because this is a limited resource.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.