On Thu, Feb 02, 2017 at 05:19:58PM +0100, Volker Vogelhuber wrote:
Hi,
I'm currently trying to mmap the memory of an OpenGL texture I've created by doing the following:
std::vector<EGLint> image_attribs = { EGL_WIDTH, static_cast<int>(m_texWidth & 0x7FFFFFFF), EGL_HEIGHT, static_cast<int>(m_texHeight & 0x7FFFFFFF), EGL_DRM_BUFFER_USE_MESA, EGL_DRM_BUFFER_USE_SCANOUT_MESA, EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA EGL_NONE }; glGenTextures( 1, &texID ); glBindTexture( GL_TEXTURE_2D, texID ); eglImage = eglCreateDRMImageMESA( eglGetCurrentDisplay(), &image_attribs[0] ); glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, eglmage); eglExportDMABUFImageQueryMESA(eglGetCurrentDisplay(), eglImage, &fourcc, &nplanes, &modifiers) eglExportDMABUFImageMESA(eglGetCurrentDisplay(), eglImage, &fd, strides, offsets)
struct dma_buf_sync sync_args = { .flags = DMA_BUF_SYNC_START }; ioctl( fd, DMA_BUF_IOCTL_SYNC, sync_args); mmap( NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
For some reason mmap returns MAP_FAILED when using the PROT_WRITE flag, while using only PROT_READ seems to be fine. I'm currently using kernel 4.9.6 on an Intel CherryTrail (i915).
Is there an obvious reason why I'm not able to mmap the texture FD with PROT_WRITE flags? Reading https://01.org/blogs/2016/sharing-cpu-and-gpu-buffers-linux I would have guessed that this should be possible. Or is it only true for specific GEM buffers not textures created using eglCreateDRMImageMESA?
From a quick look the mesa/libdrm (depending upon driver) handle2fd
implementations don't set the DRM_RDWR flag when asking PRIME for a dma-buf fd, which means you fd doesn't have write permissions. Which means mmap with writing allowed will fail.
Not sure how to fix that. -Daniel