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:
- Begin a frame (
crate::RenderSender::begin_owned_frame,crate::RenderSender::try_begin_owned_frame, …). crate::OwnedFrame::d3d11_frame: the views (D3D11Frame::view_indexfinds each eye’s color and depth view) and the shared textures they lie on.- When the sender was created with
acquire_keyed_mutex_syncfalse: acquire each texture’s keyed mutex with its acquire key (D3D11Frame::keyed_mutexes). - Render each eye into its view’s rectangle with the frame’s view pose and field of view.
- With
acquire_keyed_mutex_syncfalse: release each keyed mutex with its release key. 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::newtakes 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_rawtakes 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 (everyqaroshandle 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::textureandD3D11KeyedMutex::mutexlend them for the borrow of the frame, withoutAddReforRelease; 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_synctrue (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§
- D3D11
Frame - A copy of the sender’s D3D11 frame record (
qar_render_sender_frame_d3d11): its views, its shared textures and their keyed-mutex synchronization. Fromcrate::OwnedFrame::d3d11_frameorcrate::Frame::d3d11_frameinside a frame cycle, orcrate::RenderSender::d3d11_frame_stateoutside one. The textures it lends live as long as the borrow it was taken from. - D3D11
Keyed Mutex - The keyed mutex of one shared texture and the keys of its acquire and release
(
QarDXGIKeyedMutexSync), for an application that drives the chain itself. - D3D11
Stream Params 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.- D3D11
Texture - One shared texture of the frame (
QarVideoTextureD3D11), lent for the borrow of the frame.