Skip to main content
QAROS Rust API Dev (main) · versions: Dev (main) · Developer Guide

Module d3d11

Module d3d11 

Source
Expand description

The D3D11 render sender path (feature d3d11).

The application creates a D3D11.1 device and immediate context on the adapter the session uses (crate::Session::graphics_adapter) and hands both to QAROS (D3D11StreamParams, chained into QarRenderSenderInit as QarStreamParamsD3D11). QAROS then creates the frame’s shared textures on that device and hands them out with the views laid out on them, as QarVideoFrameD3D11.

One frame, in the order of QuaternAR’s d3d11_render_sender.c:

  1. Begin a frame (crate::RenderSender::begin_owned_frame, crate::RenderSender::try_begin_owned_frame, …).
  2. crate::OwnedFrame::d3d11_frame: the views (D3D11Frame::view_index finds each eye’s color and depth view) and the shared textures they lie on.
  3. When the sender was created with acquire_keyed_mutex_sync false: acquire each texture’s keyed mutex with its acquire key (D3D11Frame::keyed_mutexes).
  4. Render each eye into its view’s rectangle with the frame’s view pose and field of view.
  5. With acquire_keyed_mutex_sync false: release each keyed mutex with its release key.
  6. crate::OwnedFrame::show.

§Safety rules

These come from the header (QarStreamParamsD3D11, QarSyncFrameD3D11, qar_render_sender_frame_d3d11) and the C sample; the wrapper enforces what a borrow or a reference count can express and documents the rest.

Items that take or lend windows crate types (D3D11StreamParams::new, D3D11Texture::texture, D3D11KeyedMutex::mutex) exist on Windows only; macOS builds the rest against qaros-stub, with raw pointers.

  • Device lifetime. D3D11StreamParams::new takes a reference on the device and the context (AddRef), and the sender keeps both until it is destroyed, and its session with it when the sender held the session’s last reference. A creation dropped before its callback keeps them until the callback has come. D3D11StreamParams::from_raw takes no reference; the caller then keeps both valid that long.
  • The immediate context. QAROS uses the context it is given. When and on which thread is not documented, and a D3D11 immediate context is not thread-safe. That is why sender creation is unsafe: use the context only on the thread that drives the sender (every qaros handle stays on one thread), or turn on the device’s multithread protection (ID3D11Multithread::SetMultithreadProtected).
  • Ownership of the textures. The shared textures and their keyed mutexes are the sender’s. D3D11Texture::texture and D3D11KeyedMutex::mutex lend them for the borrow of the frame, without AddRef or Release; clone the interface to keep one longer. Read the frame every cycle: the header does not say the textures stay the same.
  • Writes only inside a frame cycle. The frame record is readable from creation (crate::RenderSender::d3d11_frame_state, for creating views up front); the textures may be rendered to only between a begin and its show (the header’s “writable only inside a frame cycle”). The wrapper cannot see GPU work, so this rule is the caller’s.
  • Keyed mutexes. With acquire_keyed_mutex_sync true (the header’s default) the library acquires and releases them around the cycle; do not touch them. With it false the application drives the chain with the record’s keys; the header gives the keys and says the entries match the textures, an empty list meaning no external synchronization.
  • Device. D3D11.1 (ID3D11Device1, ID3D11DeviceContext1), on the session’s adapter: the header creates the session’s devices, and with them every sender’s frame textures, there.

Structs§

D3D11Frame
A copy of the sender’s D3D11 frame record (qar_render_sender_frame_d3d11): its views, its shared textures and their keyed-mutex synchronization. From crate::OwnedFrame::d3d11_frame or crate::Frame::d3d11_frame inside a frame cycle, or crate::RenderSender::d3d11_frame_state outside one. The textures it lends live as long as the borrow it was taken from.
D3D11KeyedMutex
The keyed mutex of one shared texture and the keys of its acquire and release (QarDXGIKeyedMutexSync), for an application that drives the chain itself.
D3D11StreamParams
QarStreamParamsD3D11: the application’s D3D11.1 device and immediate context, on which QAROS creates the frame’s shared textures, and how it creates and synchronizes them.
D3D11Texture
One shared texture of the frame (QarVideoTextureD3D11), lent for the borrow of the frame.