Does gbm_bo_map() implicitly synchronise?

Pierre Ossman ossman at cendio.se
Mon Jun 17 10:29:14 UTC 2024


On 17/06/2024 10:13, Christian König wrote:
> 
> Let me try to clarify a couple of things:
> 
> The DMA_BUF_IOCTL_SYNC function is to flush and invalidate caches so 
> that the GPU can see values written by the CPU and the CPU can see 
> values written by the GPU. But that IOCTL does *not* wait for any async 
> GPU operation to finish.
> 
> If you want to wait for async GPU operations you either need to call the 
> OpenGL functions to read pixels or do a select() (or poll, epoll etc...) 
> call on the DMA-buf file descriptor.
> 

Thanks for the clarification!

Just to avoid any uncertainty, are both of these things done implicitly 
by gbm_bo_map()/gbm_bo_unmap()?

I did test adding those steps just in case, but unfortunately did not 
see an improvement. My order was:

1. gbm_bo_import(GBM_BO_USE_RENDERING)
2. gbm_bo_get_fd()
3. Wait for client to request displaying the buffer
4. gbm_bo_map(GBM_BO_TRANSFER_READ)
5. select(fd+1, &fds, NULL, NULL, NULL)
6. ioctl(DMA_BUF_IOCTL_SYNC, &{ .flags = DMA_BUF_SYNC_START | 
DMA_BUF_SYNC_READ })
7. pixman_blt()
8. gbm_bo_unmap()

> So if you want to do some rendering with OpenGL and then see the result 
> in a buffer memory mapping the correct sequence would be the following:
> 
> 1. Issue OpenGL rendering commands.
> 2. Call glFlush() to make sure the hw actually starts working on the 
> rendering.
> 3. Call select() on the DMA-buf file descriptor to wait for the 
> rendering to complete.
> 4. Use DMA_BUF_IOCTL_SYNC to make the rendering result CPU visible.
> 

What I want to do is implement the X server side of DRI3 in just CPU. It 
works for every application I've tested except gnome-shell.

I would assume that 1. and 2. are supposed to be done by the X client, 
i.e. gnome-shell?

What I need to be able to do is access the result of that, once the X 
client tries to draw using that GBM backed pixmap (e.g. using 
PresentPixmap).

So far, we've only tested Intel GPUs, but we are setting up Nvidia and 
AMD GPUs at the moment. It will be interesting to see if the issue 
remains on those or not.

Regards
-- 
Pierre Ossman           Software Development
Cendio AB               https://cendio.com
Teknikringen 8          https://twitter.com/ThinLinc
583 30 Linköping        https://facebook.com/ThinLinc
Phone: +46-13-214600

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?



More information about the mesa-dev mailing list