Skip to main content

PreparedWgpuContext

Struct PreparedWgpuContext 

Source
pub struct PreparedWgpuContext { /* private fields */ }
Expand description

后台线程无头预初始化的 wgpu 设备与预编译 2D SDF 渲染管线上下文(可跨线程 Send 移交主线程)。

用于实现「秒开首屏 + 异步后台 GPU 无缝热升舱」: 后台线程并发执行最耗时的图形驱动加载、request_adapter、request_device 与着色器管线编译, 就绪后主线程仅需 ~10ms 绑定窗口 Surface 即可零闪烁接管至硬件加速渲染。

Implementations§

Source§

impl PreparedWgpuContext

Source

pub fn init_headless() -> Option<Self>

在无窗口句柄的独立后台线程中完成 wgpu 驱动加载、设备创建与着色器管线预编译。

Source

pub fn from_shared_device( device: Device, queue: Queue, adapter: Option<Adapter>, instance: Option<Instance>, preferred_format: TextureFormat, adapter_name: impl Into<String>, backend_name: &'static str, ) -> Self

直接复用外部引擎(如海图/3D/视频渲染器)已创建的 wgpu::Device 与 wgpu::Queue 构建共享上下文。

外部引擎与 Velox 共享同一物理 GPU 与命令队列后,可将外部 wgpu::TextureView 通过 WgpuRenderer::register_external_texture 零拷贝嵌入 Velox UI,无需任何跨 API 句柄转换或 CPU 回读。

Source

pub fn from_host_adapter_id( adapter_luid: Option<[u8; 8]>, device_uuid: Option<[u8; 16]>, ) -> Option<Self>

按宿主物理显卡标识(Windows DX12 LUID 或 Linux/Android Vulkan deviceUUID)对齐并创建上下文。

  • 启用 gpu-interop feature 时,通过底层 wgpu-hal 精确匹配与宿主 Qt/GTK4/WPF/WinUI 相同的物理 GPU 并激活跨进程/跨 API 外部显存与信号量扩展;
  • 未启用 gpu-interop 或参数均为 None 时自动退化为默认硬件无头初始化。
Source

pub fn device(&self) -> &Device

返回底层 wgpu::Device 句柄引用(供外部渲染器同设备创建共享纹理)。

Source

pub fn queue(&self) -> &Queue

返回底层 wgpu::Queue 句柄引用。

Source

pub fn adapter(&self) -> Option<&Adapter>

返回可选 wgpu::Adapter 引用。

Source

pub fn instance(&self) -> Option<&Instance>

返回可选 wgpu::Instance 引用。

Source

pub fn adapter_name(&self) -> &str

返回适配器名称。

Source

pub const fn backend_name(&self) -> &'static str

返回后端图形 API 名称。

Source

pub const fn adapter_luid(&self) -> Option<[u8; 8]>

返回匹配到的 Windows DX12 适配器 LUID(若可用)。

Source

pub const fn device_uuid(&self) -> Option<[u8; 16]>

返回匹配到的 Vulkan 物理设备 UUID(若可用)。

Source

pub fn take_or_create_renderer(&mut self, format: TextureFormat) -> WgpuRenderer

取出预编译的 WgpuRenderer(若格式一致)或按指定像素格式即时构建。

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> FluentBuilder for T

Source§

fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self

当 condition 为 true 时执行闭包修饰自身,否则原样返回。
Source§

fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self

根据 condition 在两个修饰分支之间二选一。
Source§

fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self

当 option 为 Some(value) 时执行闭包修饰自身,否则原样返回。
Source§

fn when_none<O>( self, option: &Option<O>, then: impl FnOnce(Self) -> Self, ) -> Self

当 option 为 None 时执行闭包修饰自身,否则原样返回。
Source§

fn apply<U>(self, f: impl FnOnce(Self) -> U) -> U

通用管道映射变换(避免与 Iterator::map / Option::map 重名)。
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,