简体   繁体   English

无法理解有助于异步显示的BufferQueue同步逻辑

[英]Unable to understand BufferQueue sync logic that helps for async display

I am reading android architecture from this link. 我从阅读的android架构这个环节。

At the very first attempt i could not understand everything but bits and pieces here and there. 第一次尝试时,我什么都不明白,但到处都是零零碎碎。

What i understand? 我懂什么?

1) 1)

There something called 'sync framework'. 有一种叫做“同步框架”的东西。 - OK - 好

2) 2)

This sync framework can be used between processes and between user space and kernel space. 可以在进程之间以及用户空间和内核空间之间使用此同步框架。 - OK - 好

3) 3)

Used for Asynchronous mechanism. 用于异步机制。 - OK. - 好。

4) 4)

Assuming there is no Sync framework. 假设没有同步框架。

   void display_buffer(struct dma_buf *buf);

There is a display system which displays the given buffer. 有一个显示系统,可以显示给定的缓冲区。

 while (1) {
    -> Fill the buffer( buf)
    -> call display_buffer(buf);  -> Displays into the screen.
  }

There could be a latency because, it is synchronous . 可能会有延迟,因为它是同步的

5) 5)

Assuming we have sync framework support. 假设我们有同步框架支持。 It is something like: I will give display system the buffer, and startfence, you need to display the buffer when you get signal on startfence. 就像这样:我将为显示系统提供缓冲区和startfence,当您收到关于startfence的信号时,您需要显示缓冲区。 At the same time, when you are done, you need to intimate me with donefence. 同时,完成后,您需要使我与dofence保持亲密关系。 which the display system provided me. 显示系统为我提供了什么。 [ i understood not completely but, i can feel it helps for async model], so that i can fill the buffer while the system is rendering. [我不完全了解,但是我可以感觉到它对异步模型有所帮助],这样我就可以在渲染系统时填充缓冲区。

struct sync_fence* display_buffer(struct dma_buf *buf,
    struct sync_fence *fence);

Gray Area: But still, i could not able to write a pseudo code for how could display_buffer on async mode be used? 灰色区域:但是,我仍然无法编写伪代码,说明如何在异步模式下使用display_buffer?

Reading paragraph from the android official link. 从android官方链接阅读段落。

" Most recent Android devices support the "sync framework". This allows the system to do some nifty thing when combined with hardware components that can manipulate graphics data asynchronously. For example, a producer can submit a series of OpenGL ES drawing commands and then enqueue the output buffer before rendering completes. The buffer is accompanied by a fence that signals when the contents are ready. A second fence accompanies the buffer when it is returned to the free list, so that the consumer can release the buffer while the contents are still in use. This approach improves latency and throughput as the buffers move through the system. " 最新的Android设备支持“同步框架”。当与可以异步处理图形数据的硬件组件结合使用时,系统可以做一些漂亮的事情。例如,生产者可以提交一系列OpenGL ES绘图命令,然后排队渲染完成之前的输出缓冲区。缓冲区附带有一个栅栏,该栅栏会在内容准备就绪时发出信号。当缓冲区返回到空闲列表时,第二道栅栏会伴随该缓冲区,以便使用者可以在内容仍为空白时释放该缓冲区这种方法改善了缓冲区在系统中移动时的延迟和吞吐量。

QUESTION: 题:

I am confused particularly with this statement. 我对此声明特别困惑。

"A second fence accompanies the buffer when it is returned to the free list, so that the consumer can release the buffer while the contents are still in use. This approach improves latency and throughput as the buffers move through the system." “当缓冲区返回到空闲列表时,缓冲区会附带第二个屏障,以便消费者可以在内容仍在使用时释放缓冲区。这种方法可在缓冲区通过系统时提高延迟和吞吐量。”

A second fence on the same buffer?. 同一缓冲区上还有第二个栅栏? or different buffer?. 或其他缓冲区? as i see there are two buffer queues one is filled list, and the other one is empty list. 如我所见,有两个缓冲区队列,一个是填充列表,另一个是空列表。

If you want to get deeper into the sync framework, you should also read this document and especially the "explicit synchronization" section of this document . 如果你想更深入地同步框架,你也应该阅读本文件特别是“显式同步”的部分, 这个文件

Your description is close but not quite right. 您的描述很接近,但不太正确。 Each buffer has an "acquire" fence and a "release" fence. 每个缓冲区都有一个“获取”围栏和一个“释放”围栏。 The "acquire" fence indicates when the producer, such as OpenGL ES, has finished rendering. “获取”围栏指示生产者(例如OpenGL ES)何时完成渲染。 It doesn't tell the consumer (HardwareComposer, which feeds the display) that it needs to display the buffer, but rather that it is now allowed to display the buffer because rendering has completed. 它不会告诉使用者(为显示器提供数据的HardComposer)它需要显示缓冲区,而是因为渲染已完成,现在允许它显示缓冲区。 The "release" fence is signaled by the HWC when the buffer is no longer being accessed by the display hardware, which means a consumer is again allowed to write to it. 当缓冲区不再被显示硬件访问时,HWC会发出“释放”栅栏的信号,这意味着再次允许使用者对其进行写入。

The latency reduction is the result of not tying the buffer's state to its state in the queue. 延迟减少是未将缓冲区的状态绑定到队列中的状态的结果。 The BufferQueue can consider you to be full of data before rendering completes, and can have you on the "free" list before the display is done showing the buffer. 在渲染完成之前,BufferQueue可以认为您已经充满了数据,并且可以在完成显示缓冲区之前让您进入“空闲”列表。 This allows the IPC queue mechanisms to do their thing without blocking on the GPU or display. 这使IPC队列机制可以在不阻塞GPU或显示器的情况下完成其工作。

Once a fence is signaled, it never becomes un-signaled, so you can't use a single fence for multiple events. 一旦指示了隔离栅,它就永远不会成为无信号,因此您不能将单个隔离栅用于多个事件。 That's why you need two different fences for "data is ready" and "data is no longer needed". 这就是为什么您需要两个不同的围栏来存储“数据就绪”和“不再需要数据”的原因。

FWIW, the name "BufferQueue" is slightly misleading. FWIW,名称“ BufferQueue”有点误导。 Filled buffers are in a queue, empty buffers are in a pool. 填充的缓冲区在队列中,空的缓冲区在池中。 (The pool has a FIFO policy, so it's essentially a queue, but that's not guaranteed.) (该池具有FIFO策略,因此它本质上是一个队列,但是不能保证。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM