AsyncGPUReadbackRequest.getData returns array that is too big

I’m experimenting with AsyncGPUReadbackRequest and have pulled the code from AsyncCaptureTest/Assets/AsyncCapture.cs at master · keijiro/AsyncCaptureTest · GitHub
The request is pulled out of a queue like this:

var req = _requests.Peek();
var buffer = req.GetData();

When I try to use the buffer to populate a texture, I get this:
SetPixels32 called with invalid number of pixels in the array
UnityEngine.Texture2D:SetPixels32(Color32[ ])
Capture:SaveBitmap(NativeArray`1, Int32, Int32, Int32, String, Int32) (at Assets/Capture.cs:113)
Capture:Update() (at Assets/Capture.cs:64)

and when I check the sizes:
buffer size is 1425424 texture size is 712712

In other words, the NativeArray buffer returned by the request is twice as big as the texture I created to hold it (the texture is the expected size)

If I trim the array to the right size then go ahead and encode it to a png, when I look at it the image it looks vaguely correct but as though every pixel has been interleaved with some other data.
I’m on 2018.2 - any ideas?

OK, Solved it using the GIGO principle.
The request was returning some unknown texture format because I wasn’t setting the target format at the point where the request was made.
setting it to AsyncGPUReadback.Request(source,0,TextureFormat.RGBA32) solved the problem.

1 Like

I’m noticing the same issue where the size of the GetData result is twice the size of the buffer given to AsyncGPUReadback.Request. That’s worrisome from a performance perspective.