Hi Julien,
>> [1]
>> article, dmabuf and zwp_linux_dmabuf extension can be used as a way
>> to
>> share buffers between client and server in a zero-copy manner. But
>> we
>> extend this a bit, and, by creating a gbm buffer on a gpu process
>> (and
>> sharing its fd with the browser process for importing wl_buffer and
>> attaching it to a surface) we are able to read and write to the
>> buffer
>> without using mmap (which is not needed in this case). That's a
>> regular
>> case and it works. I can use chromium without issues (webgl, youtube
>> and
>> etc). This is the case when chromium requests to create a scanout
>> buffer.
>
> We are saying the sane thing, i.e. this fd is read only as expected so
> you cannot
> do mmap but still an importer can write to it using special api after
> importation
> but it requires passing more info/params (like context, device) as
> opposed to a
> the generic unix system call 'mmap'.
It's read only for the process, which gets the fd of it. Let me explain
once again as I understand it:
there are two ways how a client and a compositor can allocate buffers -
it can be the client, who allocates it and the compositor exports a
wl_buffer out of the fd allowing client to attach it to a surface, or
the compositor, which allocates buffers and shares them with the client
for importing. In order to meet our goals, where the GPU process of the
Chromium browser can create a buffer for read/write, gbm API are used in
order to avoid supporting as much dmabuf apis as possible. That is, the
GPU process creates a NativePixmapHandle and uses
the gl apis to write to them without any problems, but when the
--enable-native-gpu-memory-buffers is enabled (ClientNativePixmapDmabuf
is created), this case fails and chromium crashes.
>
>> The second case is a buffer created for raster (gpu read cpu read
>> write), which is impossible to achieve, when the buffer is created
>> on
>> the gpu process. Instead, it must be created on a browser process to
>> be
>> able to mmap it by using gbm_bo_map and the fd can be shared with
>> the
>> gpu process for reading.
>
> Can you provide more details on that second case which one is not
> working ?
> Especially:
> - can you provide a concrete example of that which describes what the
> 2 processes are trying
> to draw on screen. (for example with 2 colored rectangles or a real
> case on the app)
This case involves cpu rasterization with zero or one copy.
Here is the stack -
#4 0x7f72a08644c0 SkDraw::drawPaint()
#5 0x7f72a08124bb SkBitmapDevice::drawPaint()
#6 0x7f72a083d819 SkCanvas::internalDrawPaint()
#7 0x7f72a083b76f SkCanvas::drawPaint()
#8 0x7f72a0857656 SkColorSpaceXformCanvas::onDrawPaint()
#9 0x7f72a083b76f SkCanvas::drawPaint()
#10 0x7f72a08439ae SkCanvas::drawColor()
#11 0x7f72930da8a2 cc::RasterSource::ClearForOpaqueRaster()
#12 0x7f72930da217 cc::RasterSource::PlaybackToCanvas()
#13 0x7f72930d9005 cc::RasterBufferProvider::PlaybackToMemory()
#14 0x7f729313571c cc::(anonymous
namespace)::ZeroCopyRasterBufferImpl::Playback()
#15 0x7f729313f89e cc::(anonymous
namespace)::RasterTaskImpl::RunOnWorkerThread()
zero copy mmap case happens here -
https://cs.chromium.org/chromium/src/cc/raster/zero_copy_raster_buffer_provider.cc?type=cs&q=ZeroCopyRasterBufferImpl::Playback&sq=package:chromium&g=0&l=175
.
and one-copy
#4 0x7fc5e1d514c0 SkDraw::drawPaint()
#5 0x7fc5e1cff4bb SkBitmapDevice::drawPaint()
#6 0x7fc5e1d2a819 SkCanvas::internalDrawPaint()
#7 0x7fc5e1d2876f SkCanvas::drawPaint()
#8 0x7fc5e1d44656 SkColorSpaceXformCanvas::onDrawPaint()
#9 0x7fc5e1d2876f SkCanvas::drawPaint()
#10 0x7fc5e1d309ae SkCanvas::drawColor()
#11 0x7fc5d45c78a2 cc::RasterSource::ClearForOpaqueRaster()
#12 0x7fc5d45c7217 cc::RasterSource::PlaybackToCanvas()
#13 0x7fc5d45c6005 cc::RasterBufferProvider::PlaybackToMemory()
#14 0x7fc5d45c563b
cc::OneCopyRasterBufferProvider::PlaybackToStagingBuffer()
#15 0x7fc5d45c36a8
cc::OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread()
#16 0x7fc5d45c3491
cc::OneCopyRasterBufferProvider::RasterBufferImpl::Playback()
#17 0x7fc5d462c89e cc::(anonymous
namespace)::RasterTaskImpl::RunOnWorkerThread()
One copy mmap failure happens after this call -
https://cs.chromium.org/chromium/src/cc/raster/one_copy_raster_buffer_provider.cc?type=cs&q=OneCopyRasterBufferProvider::PlaybackToStagingBuffer&sq=package:chromium&g=0&l=345
PS The crash happens immediately on mmap calls and doesn't reach the
SkDraw::drawPaint call. I've just removed mmap from the
client_native_pixmap_dmabuf to be able reach there and have a stack
trace.
PPS but as I've said it's only the case when the
--enable-native-gpu-memory-buffers is used, otherwise chromium creates a
shared memory for rasterization and the flow goes ok.
> - why you cannot just use wl_shm on the browser process ?
wl_shm is bad for accelerated graphics. This is the memory not suitable
for GPU read. It is going to involve two copies during glReadPixels call
and glTexImage2D call on the server side to make the buffer copied for
GPU read.
> - if browser process needs to draw on top of the result of the gpu
> process,
> the browser should just request the gpu process to draw that data
> too, why not ?
> - maybe you can ask on #wayland to add something similar to
> gbm_bo_map,
> i.e. wl_buffer_map, so calling it after you import the fd as you do
> now into a wl_buffer.
> Or wl_buffer attached to another so one is backed by shm and the other
> backed by dmabuf.
>
>>>
>>> Note that gbm_bo_map/unmap works on intel since quite recently :)
>> :
>>>
>>
>
https://cgit.freedesktop.org/mesa/mesa/commit/?id=b904ad7d21a5d0472ffb80b81abe24afb2da3289
>> [2]
>> [3]
>> [4]
>> [5]
>> [6]
>>>> [4]
>>>>> [2]
>>>>>
>>>>
>>>
>>
>
https://github.com/msisov/chromium/commit/f8f085c7afd7c0b9302883021d11851b576ed574#diff-a09cf9084313de86ce51fed0260bb750R151
>> [7]
>>>> [5]
>>>>> [3]
>>>>>
>>>>
>>>
>>
>
https://github.com/msisov/chromium/commit/f8f085c7afd7c0b9302883021d11851b576ed574#diff-506229ebf99d76a41b204dde8c823ab9R86
>> [8]
>> [9]
>>>> send an email to
ozone-dev+...@chromium.org.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Ozone-Dev" group.
>>> To unsubscribe from this group and stop receiving emails from it,
>> send
>>> an email to
ozone-dev+...@chromium.org.
>> [3]
>> [10]
>>> [3]
>>>
>>
>
https://github.com/wayland-project/weston/blob/master/clients/simple-dmabuf-drm.c
>> [5]
>>> [4]
>>>
>>
>
https://github.com/msisov/chromium/commit/f8f085c7afd7c0b9302883021d11851b576ed574#diff-8ff0ff4054d16b40c5ab6a24bf34bff6
>> [6]
>>> [5]
>>>
>>
>
https://github.com/msisov/chromium/commit/f8f085c7afd7c0b9302883021d11851b576ed574#diff-a09cf9084313de86ce51fed0260bb750R151
>> [7]
>>> [6]
>>>
>>
>
https://github.com/msisov/chromium/commit/f8f085c7afd7c0b9302883021d11851b576ed574#diff-506229ebf99d76a41b204dde8c823ab9R86
>> [8]
>> [11]
>>> [8]
>>>
>>
>
https://cgit.freedesktop.org/mesa/mesa/commit/?id=b904ad7d21a5d0472ffb80b81abe24afb2da3289
>> [2]
>>
>> --
>> Best Regards,
>> Maksim Sisov
>
> --
> You received this message because you are subscribed to the Google
> Groups "Ozone-Dev" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
ozone-dev+...@chromium.org.
>
>
> Links:
> ------
> [1]
http://ppaalanen.blogspot.com/2012/03/what-does-egl-do-in-wayland-stack.html
> [2]
>
https://cgit.freedesktop.org/mesa/mesa/commit/?id=b904ad7d21a5d0472ffb80b81abe24afb2da3289
> [3]
>
https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/323990
> [4]
> [5]
>
https://github.com/wayland-project/weston/blob/master/clients/simple-dmabuf-drm.c
> [6]
>
https://github.com/msisov/chromium/commit/f8f085c7afd7c0b9302883021d11851b576ed574#diff-8ff0ff4054d16b40c5ab6a24bf34bff6
> [7]
>
https://github.com/msisov/chromium/commit/f8f085c7afd7c0b9302883021d11851b576ed574#diff-a09cf9084313de86ce51fed0260bb750R151
> [8]
>
https://github.com/msisov/chromium/commit/f8f085c7afd7c0b9302883021d11851b576ed574#diff-506229ebf99d76a41b204dde8c823ab9R86
> [9]
> [10]
>
https://cs.chromium.org/chromium/src/ui/gl/gl_image_native_pixmap.cc?type=cs&q=ui/gl/gl_image_native_pixmap.cc&sq=package:chromium&g=0&l=149
> [11]
>
https://cs.chromium.org/chromium/src/ui/gfx/linux/client_native_pixmap_dmabuf.cc?sq=package:chromium&g=0&l=81