1

I am getting an error from the graphics driver while converting the EnvironmentTexture(from ARKIT.AREnvironmentProbeAnchor) to CVPixelBuffer. The EnvironmentTexture is an IMTLTexture. I am using Xamarin.iOS.

This is the code that I use to convert the IMTLTexture to CVPixelBuffer.

buffers[i] = new CVPixelBuffer((nint)epAnchor.EnvironmentTexture.Width, (nint)epAnchor.EnvironmentTexture.Height, CVPixelFormatType.CV32RGBA);
GetEnvironmentTextureSlice(buffers[i], epAnchor.EnvironmentTexture, i);

public void GetEnvironmentTextureSlice(CVPixelBuffer pixelBuffer, Metal.IMTLTexture texture, int id)
{
  Metal.MTLRegion mtlRegion = Metal.MTLRegion.Create2D((nuint)0, 0, 256, 256);
    
  nuint bytesPerPixel = 4;
  nuint bytesPerRow = bytesPerPixel * (nuint)mtlRegion.Size.Width; // (nuint)pixelBuffer.BytesPerRow;
  nuint bytesPerImage = bytesPerRow * (nuint)mtlRegion.Size.Height;

  pixelBuffer.Lock(CVPixelBufferLock.None);
  texture.GetBytes(pixelBuffer.BaseAddress, (nuint)pixelBuffer.BytesPerRow, mtlRegion, 0);
  pixelBuffer.Unlock(CVPixelBufferLock.None);
}

The error I am getting from the driver is AGX: Texture read/write assertion failed: bytes_per_row >= used_bytes_per_row

I tried with different values of pixelBuffer.BytesPerRow but still getting the error.

Can someone help me?

fatihyildizhan
  • 8,614
  • 7
  • 64
  • 88
bonnie m
  • 11
  • 2
  • Hmm, I'm pretty sure you have to pass the bytes-per-row of the _texture_, not the pixel buffer. And yes, those need to match if you want to copy the data over. Maybe you can also show how you set up the texture? – Frank Rupprecht Apr 30 '21 at 06:35
  • I am getting that Texture from the ARKit. I am setting up few ARKitEnvironmentProbes. Each probe gives a EnvironmentTexture as MTLTexture. I am trying to convert this MTLTexture to an Open GL Texture. MTLTexture > CVPixelBuffer > GL Texture – bonnie m May 06 '21 at 14:56
  • Hey @bonniem, Is there any update until now? – Jenny Tran Dec 30 '21 at 02:31
  • @JennyTran Nothing. I dropped that work. – bonnie m Jan 18 '22 at 08:13

0 Answers0