![]() |
Vireo
0.0
Vireo 3D Rendering Hardware Interface
|
The Image class represent multidimensional arrays of data which can be used for various purposes (e.g. attachments, textures), by binding them to a graphics or compute pipeline via descriptor sets, or by directly specifying them as parameters to certain commands.
An image have a pixel format. Vireo supports images formats that are commons to both Vulkan and DirectX, so it's safe to use any of theses formats without compromising portability.
They are created with vireo::Vireo::createImage. You need to provide the format, the width and height in number of pixels, the number of mips level (e.g. for mipmaps) and the size of the image array (e.g. 6 for a cubemap) :
The last parameter is the resource name used when you debug the rendering process with tools like RenderDoc.
To be accessible by the GPU and the shader an image needs to be uploaded into video memory (VRAM).
Like for memory buffers there is two methods to upload an image into the GPU memory :
upload()
: the easy waycopy()
: the flexible wayBy using the vireo::CommandList::upload or vireo::CommandList::uploadArray methods you can easily upload data into a buffer. The upload
methods will take care of the staging buffer and temporary copy of the data for you, which can be tricky if you have multiple mip levels or multiples image layers.
The GPU commands recorded with a CommandList are executed asynchronously by the GPU. Once you have uploaded all of the data using oneCommandList
you need to call vireo::CommandList::cleanup on this CommandList
to clear the temporary (staging) buffers used for the host-to-device transfers. The asynchronous nature of the operation means that we have to wait for the end of the operation to free the host-visible allocated memory, which mean you have to call cleanup
only after the submit queue have finished the commands execution by blocking the CPU-side with vireo::SubmitQueue::waitIdle.
cleanup
is done automatically in the command list destructor, you only have to call it explicitly on non-temporary command lists.copy()
method below.This method can be useful if you want, for example, to write data directly into the staging buffer to avoid a CPU-to-CPU transfer or if you need to copy one mip level independently from the others.
When using vireo::CommandList::copy you need to copy the image data into a temporary, host-accessible (staging) buffer, then you ask the GPU to copy the data to the image in device-only memory (memory only accessible by the GPU). Remember that you have to keep the staging buffer alive until the copy command have been executed (you may need to wait on the CPU side for the completion of the commands on the submit queue).
Downloading an image to save the result of a rendering or the result of a compute shader is similar to uploading with copy
:
map()
to access the memoryThe main difference is that you have to take care of the memory alignment of the rows of the image imposed by the graphic API :