I need to extract all textures from an application at the driver level, similar to GFXR and RenderDocs, but I am unclear on the main methodology. In Vulkan, texture data is transferred to GPU memory by the application rather than the driver. Based on my understanding and testing, the typical process appears to be:
-
Create a staging buffer.
-
The application copies pixel data to the staging buffer:
void* hostData;
vkMapMemory(device, stagingBufferMemory, 0, imageSize, 0, &data); // Map GPU memory to host and copy data
memcpy(data, srcPixels, static_cast<size_t>(imageSize));
vkUnmapMemory(device, stagingBufferMemory);
-
Create a VkImage (another VkDeviceMemory).
-
Transition the VkImage layout to a GPU optimal layout.
-
Copy the staging buffer (linear data) to the VkImage using:
vkCmdCopyBufferToImage(commandBuffer, stagingBuffer, VkImage, etc...)
- Transition the VkImage layout to a GPU optimal layout.
One approach to obtaining the texture data is to dump it before calling vkUnmapMemory. However, there is no guarantee the application will call vkUnmapMemory as it may keep it mapped indefinitely. Another potential method is to intercept vkCmdCopyBufferToImage, but if the application does not use a staging buffer and has pixels in a GPU-friendly format, this approach would also fail, resulting in swizzled pixel data that is difficult to recompose.
Could anyone familiar with GFXR or RenderDoc explain their general methodology for this process?
Thank you for your time.
Best regards,