GPU-only triple-buffered texture sharing between two QRhi instances in different threads. More...
Detailed Description
GPU-only triple-buffered texture sharing between two QRhi instances in different threads.
Classes | |
| struct | Impl |
Public Member Functions | |
| TextureShare (const TextureShare &)=delete | |
| TextureShare & | operator= (const TextureShare &)=delete |
| TextureShare (TextureShare &&)=delete | |
| TextureShare & | operator= (TextureShare &&)=delete |
| bool | setup (QRhi *producer, QRhi *consumer, QSize size, QRhiTexture::Format format=QRhiTexture::RGBA8) |
| Initialize the texture sharing system (single-thread convenience method). | |
| bool | setupProducer (QRhi *producer, QSize size, QRhiTexture::Format format=QRhiTexture::RGBA8) |
| Initialize producer-side resources (call from producer thread). | |
| bool | setupConsumer (QRhi *consumer) |
| Initialize consumer-side resources (call from consumer thread). | |
| void | resize (QSize newSize) |
| Resize the shared textures. | |
| void | cleanup () |
| Clean up all resources. | |
| bool | isValid () const noexcept |
| QSize | size () const noexcept |
| QRhiTextureRenderTarget * | beginProducerFrame () |
| Begin a producer frame. | |
| QRhiTexture * | currentProducerTexture () |
| Get the current producer texture. | |
| void | endProducerFrame (QRhiCommandBuffer *cb) |
| End a producer frame and submit GPU copy to shared buffer. | |
| QRhiRenderPassDescriptor * | producerRenderPassDescriptor () const noexcept |
| Get a render pass descriptor compatible with producer textures. | |
| QRhiTexture * | acquireConsumerTexture (QRhiCommandBuffer *cb) |
| Acquire a texture for consumption/display. | |
| bool | hasNewFrame () const noexcept |
Member Function Documentation
◆ acquireConsumerTexture()
| QRhiTexture * score::gfx::TextureShare::acquireConsumerTexture | ( | QRhiCommandBuffer * | cb | ) |
Acquire a texture for consumption/display.
- Parameters
-
cb The command buffer for any required GPU synchronization/copy.
- Returns
- The most recently completed texture, or nullptr if none ready.
The texture remains valid until the next call to acquireConsumerTexture().
Must be called from the consumer thread.
◆ beginProducerFrame()
| QRhiTextureRenderTarget * score::gfx::TextureShare::beginProducerFrame | ( | ) |
Begin a producer frame.
- Returns
- The render target to render to, or nullptr if not ready.
The returned render target is owned by TextureShare. Call endProducerFrame() when rendering is complete.
Must be called from the producer thread.
◆ cleanup()
| void score::gfx::TextureShare::cleanup | ( | ) |
Clean up all resources.
Must be called before destroying the QRhi instances.
◆ currentProducerTexture()
| QRhiTexture * score::gfx::TextureShare::currentProducerTexture | ( | ) |
Get the current producer texture.
- Returns
- The texture being rendered to, or nullptr if not in a frame.
Must be called after beginProducerFrame() and before endProducerFrame().
◆ endProducerFrame()
| void score::gfx::TextureShare::endProducerFrame | ( | QRhiCommandBuffer * | cb | ) |
End a producer frame and submit GPU copy to shared buffer.
- Parameters
-
cb The command buffer to record the copy command into.
This records a GPU-to-GPU copy from the render target to the shared intermediate texture.
Must be called from the producer thread.
◆ resize()
| void score::gfx::TextureShare::resize | ( | QSize | newSize | ) |
Resize the shared textures.
Must be called when both threads are synchronized.
◆ setup()
| bool score::gfx::TextureShare::setup | ( | QRhi * | producer, |
| QRhi * | consumer, | ||
| QSize | size, | ||
| QRhiTexture::Format | format = QRhiTexture::RGBA8 |
||
| ) |
Initialize the texture sharing system (single-thread convenience method).
- Parameters
-
producer The QRhi instance that will produce/render textures consumer The QRhi instance that will consume/display textures size The texture size format The texture format (default RGBA8)
- Returns
- true if setup succeeded
Both QRhi instances must use the same graphics backend.
WARNING: This method calls both QRhi instances from the calling thread. Per QRhi threading rules, each QRhi should only be used from the thread that created it. Use setupProducer() and setupConsumer() for correct multi-threaded operation.
◆ setupConsumer()
| bool score::gfx::TextureShare::setupConsumer | ( | QRhi * | consumer | ) |
Initialize consumer-side resources (call from consumer thread).
- Parameters
-
consumer The QRhi instance that will consume/display textures
- Returns
- true if consumer setup succeeded
Must be called after setupProducer() has completed.
Thread Safety: Must be called from the consumer thread (the thread that created the consumer QRhi instance).
◆ setupProducer()
| bool score::gfx::TextureShare::setupProducer | ( | QRhi * | producer, |
| QSize | size, | ||
| QRhiTexture::Format | format = QRhiTexture::RGBA8 |
||
| ) |
Initialize producer-side resources (call from producer thread).
- Parameters
-
producer The QRhi instance that will produce/render textures size The texture size format The texture format (default RGBA8)
- Returns
- true if producer setup succeeded
After this returns, call setupConsumer() from the consumer thread.
Thread Safety: Must be called from the producer thread (the thread that created the producer QRhi instance).
The documentation for this class was generated from the following files:
- TextureShare.hpp
- TextureShare.cpp