openxr runtime Monado 源码解析 源码分析:整体介绍 模块架构 模块作用 进程 线程模型 整体流程

monado系列文章索引汇总:
openxr runtime Monado 源码解析 源码分析:源码编译 准备工作说明 hello_xr解读
openxr runtime Monado 源码解析 源码分析:整体介绍 模块架构 模块作用 进程 线程模型 整体流程
openxr runtime Monado 源码解析 源码分析:CreateInstance流程(设备系统和合成器系统)Compositor comp_main client compositor
openxr runtime Monado 源码解析 源码分析:Prober设备发现和管理 system device HMD target instance
openxr runtime Monado 源码解析 源码分析:InitializeSession client native multi_compositor client_compositor
openxr runtime Monado 源码解析 源码分析:CreateSwapchain 画布 HardwareBuffer共享纹理 渲染线程 xrEndeFrame comp_renderer

目录

简介

Implements Khronos OpenXR™

Open Source

Create your XR device

Your XR laboratory

源码目录和功能概要

src/xrt/compositor 合成器系统

src/xrt/ipc

src/xrt/state_trackers/oxr

src/xrt/include

src/xrt/targets

src/xrt/state_trackers/prober

src/xrt/drivers

src/xrt/auxiliary

src/external

so库和组织关系

按照源码目录产生的so库

按照进程维度so组合方式

三个重要线程

接口层次图

总流程


简介

Monado的功能和介绍,官方定义非常精确和全面,我做下概述:

  • 开源的,模块化设计,非常容易定制和扩展,如更优性能的主合成器系统Compositor。
  • 实现了Khronos定义的OpenXR API规范
  • 支持移动、PC等多种设备。

具体参见官网:

https://monado.dev/

https://gitlab.freedesktop.org/monado/monado

Implements Khronos OpenXR™

Monado is the first OpenXR™ runtime for GNU/Linux. Monado aims to jump-start development of an open source XR ecosystem and provide the fundamental building blocks for device vendors to target the GNU/Linux platform.

Open Source

Monado is fully open source and under a convenient license. This means the entire ecosystem can collaborate beyond the open standard and on a common code base.

Create your XR device

Monado enables XR hardware developers to focus on their product development. Simply develop and deploy with Monado without having to worry about the software.

Your XR laboratory

With its modular and open design, Monado is the perfect place to try out new XR technologies. With Monado you can, on your own or with the community, optimize your new SLAM algorithm, experiment new XR UX concepts, test your new controller, and much more.

源码目录和功能概要

在详细阅读代码之前,需要了解每个模块的功能,知道每个模块的目的:

src/xrt/compositor 合成器系统

非常重要的模块:合成器系统。每个部分都是要点!分为3个重要模块,2个辅助模块。

  • main(重要模块1):Runtime核心模块,用Vulkan渲染。App侧来的渲染多层画面(Layer)最终在这里合成处理;distortion等算法也在这里使用。
  • client(重要模块2):客户端(App侧)可以用GL GLES VK D3D等不同图形库渲染,client模块负责与APP侧绘制同步,接收App侧渲染结果(通过HardwareBuffer跨进程共享纹理实现)。
  • multi(重要模块3):Runtime的合成器管理系统,包括三个重要功能:(1)响应App渲染环境请求,建立并记录与之对应的Compositor;(2)创建一个主渲染线程,用于主Compositor合成多个Layer;(3)创建一个线程,监听App层Layer提交,并把Layer流转到主渲染线程。
  • render(辅助模块1):主合成器vk使用辅助工具,Buffer Memory Image Pipeline等赋值和使用。
  • shaders(辅助模块2):主合成器绘制元素时使用的shader,如cube, distortion, equirect等。

src/xrt/ipc

Monado支持inProcess和outOfProcess两种进程运行模式,IPC用于outOfProcess独立进程运行时与App侧(client)通信服务。

src/xrt/state_trackers/oxr

OpenXR API的标准实现。

src/xrt/include

出于抽象、隔离的目的,Monado定义了一套xrt_开头的对象,与标准定义对应。用于各种对象资源的管理和维护。

src/xrt/targets

glue code and build logic to produce final binaries。通过openxr_android工程打包成runtime.apk。inProcess模式生成一个库(libopenxr_monado.so),outOfProcess模式生成两个库(libopenxr_monado.so libmonado_service.so)

src/xrt/state_trackers/prober

设备发现和管理

src/xrt/drivers

支持的各种设备驱动,如android, psvr rift vive等。

src/xrt/auxiliary

辅助工具库,为主业务逻辑封装设计的、功能相对独立的功能模块,如

  • android:安卓系统一些相关操作,包含几个重要知识点:
    • HardwareBuffer跨进程共享纹理内存管理,用于client绘制内容与主合成器(Compositor)合成,后续博文会详解。
    • 主合成器Vulkan渲染环境创建所依赖的资源管理:Window View Surface结合JNI创建管理。
  • bindings:默认支持的controller配置生成管理(未深入研究)
  • ogl:OpenGL ES相关API,实际调用的是srx/external/glad库
  • vk:Vulkan使用简单封装,vulkan太繁琐,常规操作一般都会封着起来,与业务逻辑隔离
  • d3d:Windows平台图形API简单封装,我们研究安卓平台,读代码时,这个目录可以删掉
  • vive:vive配置读取相关操作(未深入研究)
  • math:各种数学相关的对象、算法封装(未深入研究)
  • gstreamer:音视频处理的库(未深入研究)
  • os:操作系统相关隔离,如time读取,线程操作等(未深入研究)

src/external

使用到的第三方库,不影响主业务逻辑理解,如:

  • cjson:json文件读写库
  • glad:gl/egl api加载库
  • imgui:游戏领域常用的UI库

so库和组织关系

如前所述,monado不仅实现了OpenXR API规范,在结构上采用模块化设计,各模块可以灵活组装和扩展,方便不同目的的定制和扩展,如提供新硬件接入,针对特定平台优化Compositor等。

按照源码目录产生的so库

每个源码目录按照不同模块细分,分别生成多个so库,从每个so库的名称,结合“源码目录和功能概要”的介绍,基本能看出模块的功能,非常容易理解,下图按照从上到下的顺序组织so关系(不是很严格的上下关系),所有so按照进程方式最终被组合成libopenxr_monado.so和libmonado_service.so,对于重要so库,用黑色加粗表示。

按照进程维度so组合方式

Monado编译生成的runtime库有两种运行模式:inProcess和outOfProcess。

inProcess:libopenxr_monado.so最终被加载Application进程空间。

outOfProcess:分成libopenxr_monado.so和libmonado_service.so。前者被加载到Application进程空间,后者在独立进程空间运行,两者通过IPC通信,独立进程模式是常用模式。

注意:comp_main模块主合成器模块在两种进程模式下归属区别。

三个重要线程

接口层次图

总流程

关键词 OpenXR Runtime Monado Compositor Vulkan OpenGL ES Swapchain hello_xr VR AR instance prober system device session swapchain

猜你喜欢

转载自blog.csdn.net/xuer_07/article/details/127953570