Closed sayan1an closed 2 years ago
Hey, the solution for this is to allocate 2 buffers the size of your texture:
buffer1
with kGfxCpuAccess_None
,buffer2
with kGfxCpuAccess_Read
.Now, write a shader that reads from your texture and writes to buffer1
as a RWBuffer<...>
.
Then, perform a copy from buffer1
to buffer2
using gfxCommandCopyBuffer(gfx, buffer2, buffer1)
.
You can now read the data on the CPU by calling gfxBufferGetData(gfx, buffer2)
.
Note however that you'll need to ensure that the GPU has completed the copy.
Meaning you'll either need to wait for at least 3 frames to complete (i.e., kGfxConstant_BackBufferCount
) or call gfxFinish()
, which will stall the CPU until the GPU has completed its queued commands.
Oops, read a bit too quickly but you're already describing the solution in your post 🙂
This is the best option indeed.
Thank you for the detailed confirmation. I didn't think about the frame queuing issue, so thanks again :)
Well, what are my options here?
I don't see a gfxCommandCopyTextureToBuffer(), but I can copy Gpu-Buffers to Cpu memory and access it for processing.
Maybe this is an option - copy texture (gpu) to gpu-buffer with a shader, then copy gpu-buffer to mapped cpu-memory?
Is there a better option?