pub struct WgpuRenderer { /* private fields */ }Expand description
自研轻量级 wgpu 2D SDF 渲染管线核心(绑定任意目标 TextureView 即可渲染)。
Implementations§
Source§impl WgpuRenderer
impl WgpuRenderer
Sourcepub fn new(device: &Device, target_format: TextureFormat) -> Self
pub fn new(device: &Device, target_format: TextureFormat) -> Self
基于已有 wgpu::Device 与目标表面像素格式创建 2D SDF 渲染管线。
Sourcepub fn last_primitive_count(&self) -> usize
pub fn last_primitive_count(&self) -> usize
返回最近一帧合批提交的 GpuPrimitive 实例数量。
Sourcepub const fn atlas_sizes(&self) -> (u32, u32)
pub const fn atlas_sizes(&self) -> (u32, u32)
返回当前字形图集与精灵图集的物理像素边长 (glyph_size, sprite_size)。
Sourcepub const fn sprite_cache_hits(&self) -> u64
pub const fn sprite_cache_hits(&self) -> u64
返回静态精灵跨帧驻留缓存累计命中次数。
Sourcepub const fn text_layout_cache_hits(&self) -> u64
pub const fn text_layout_cache_hits(&self) -> u64
返回跨帧文本行排版缓存(TextLayoutCache)累计命中次数。
Sourcepub fn text_layout_cache_len(&self) -> usize
pub fn text_layout_cache_len(&self) -> usize
返回跨帧文本行排版缓存当前驻留条目数。
Sourcepub fn register_external_texture(
&mut self,
view: TextureView,
sampler: Option<Sampler>,
) -> ExternalTextureId
pub fn register_external_texture( &mut self, view: TextureView, sampler: Option<Sampler>, ) -> ExternalTextureId
注册一张外部零拷贝 GPU 纹理(如海图、雷达、视频解码器或 3D 视口产出的 wgpu::TextureView),
返回可供 div().external_texture(id) 或 SurfaceCanvas 引用的句柄 ID。
Sourcepub fn register_external_texture_with_id(
&mut self,
id: ExternalTextureId,
view: TextureView,
sampler: Option<Sampler>,
)
pub fn register_external_texture_with_id( &mut self, id: ExternalTextureId, view: TextureView, sampler: Option<Sampler>, )
按显式 ID 注册或替换外部零拷贝 GPU 纹理(便于固定槽位号与跨语言 FFI 绑定)。
Sourcepub fn update_external_texture(
&mut self,
id: ExternalTextureId,
view: TextureView,
) -> bool
pub fn update_external_texture( &mut self, id: ExternalTextureId, view: TextureView, ) -> bool
原地更新已注册外部纹理的 wgpu::TextureView(如外部引擎 Resize 或双缓冲翻页时调用)。
Sourcepub fn unregister_external_texture(&mut self, id: ExternalTextureId) -> bool
pub fn unregister_external_texture(&mut self, id: ExternalTextureId) -> bool
注销外部零拷贝纹理槽位并释放 TextureView 引用。
Sourcepub fn external_texture_count(&self) -> usize
pub fn external_texture_count(&self) -> usize
返回当前已注册的外部零拷贝 GPU 纹理数量。
Sourcepub fn layer_pool_bytes(&self) -> usize
pub fn layer_pool_bytes(&self) -> usize
返回当前离屏图层纹理池占用的估算 GPU 显存字节数(无特效子引擎时为 0)。
Sourcepub fn layer_pool_target_count(&self) -> usize
pub fn layer_pool_target_count(&self) -> usize
返回当前离屏图层纹理池中驻留的纹理数量。
Sourcepub fn layer_mask_cache_bytes(&self) -> usize
pub fn layer_mask_cache_bytes(&self) -> usize
返回当前 SVG Path 遮罩缓存占用的估算 GPU 显存字节数。
Sourcepub fn layer_mask_cache_count(&self) -> usize
pub fn layer_mask_cache_count(&self) -> usize
返回当前 SVG Path 遮罩缓存驻留的条目数量。
Sourcepub fn pso_cache_loaded_from_disk(&self) -> bool
pub fn pso_cache_loaded_from_disk(&self) -> bool
返回内部已加载的持久化磁盘 PSO 缓存是否命中(仅在支持 Features::PIPELINE_CACHE 的后端上为 true)。
Sourcepub fn spawn_background_pipeline_warmup(
&mut self,
device: &Device,
queue: &Queue,
)
pub fn spawn_background_pipeline_warmup( &mut self, device: &Device, queue: &Queue, )
在低优先级后台线程异步预编译 GpuEffectsEngine(Dual Kawase / 混合模式)与 CanvasGpuEngine PSO,
首屏不阻塞且消除首次切换至特效或交互画布页时的主线程同步编译卡顿。
Sourcepub fn wait_background_pipeline_warmup(&mut self)
pub fn wait_background_pipeline_warmup(&mut self)
等待后台子管线预热线程完成并收割结果(主要用于测试基准验证或应用显式预热屏障)。
Sourcepub fn backdrop_blur_cache_stats(&self) -> (u64, u64)
pub fn backdrop_blur_cache_stats(&self) -> (u64, u64)
返回跨帧毛玻璃(backdrop-filter)模糊小纹理缓存命中与未命中统计 (hits, misses)。
Sourcepub fn set_slug_text_threshold_px(&mut self, threshold_px: f32)
pub fn set_slug_text_threshold_px(&mut self, threshold_px: f32)
配置全局 UI text() 自动路由至 Slug 2.0 矢量字形的物理像素字号阈值(默认 28.0 px)。
- 默认
28.0:大字号标题(>= 28px)走零图集 Slug 2.0 曲线管线,小字号正文保留GlyphAtlas; - 设为
0.0:全部常规 UItext()走 Slug 2.0 渲染(便于全量矢量 A/B 对比); - 设为
f32::INFINITY:全部回退至位图图集。
Sourcepub const fn slug_text_threshold_px(&self) -> f32
pub const fn slug_text_threshold_px(&self) -> f32
查询当前全局 UI text() 路由至 Slug 2.0 矢量字形的物理字号阈值(像素)。
Sourcepub fn memory_stats(&self) -> WgpuMemoryStats
pub fn memory_stats(&self) -> WgpuMemoryStats
返回当前 WgpuRenderer 各子池(字形/精灵/渐变图集、实例缓冲、离屏图层池、Canvas 场景缓冲与共享 Slug 曲线池)完整内存快照。
Sourcepub fn set_layer_pool_idle_budget(&mut self, bytes: usize)
pub fn set_layer_pool_idle_budget(&mut self, bytes: usize)
配置离屏图层纹理池的空闲字节预算(超出时在帧末按 LRU 立即回收)。
Sourcepub fn set_layer_pool_idle_max_age_frames(&mut self, frames: u64)
pub fn set_layer_pool_idle_max_age_frames(&mut self, frames: u64)
配置离屏图层纹理池的最大闲置帧数(切回普通页超过该帧数后自动回收)。
Sourcepub fn set_layer_mask_cache_budget(&mut self, bytes: usize)
pub fn set_layer_mask_cache_budget(&mut self, bytes: usize)
配置 SVG Path 遮罩缓存的显存字节预算。
Sourcepub fn on_viewport_resized(&mut self, phys_width: u32, phys_height: u32)
pub fn on_viewport_resized(&mut self, phys_width: u32, phys_height: u32)
视口尺寸缩小或变更时调用,立即回收远大于新视口的空闲离屏大纹理。
Sourcepub fn trim_gpu_memory(&mut self)
pub fn trim_gpu_memory(&mut self)
后台化或收到内存警告时主动回收全部空闲 GPU 离屏纹理、SVG 遮罩缓存与 Canvas 场景缓冲。
Sourcepub fn last_uploaded_instance_bytes(&self) -> usize
pub fn last_uploaded_instance_bytes(&self) -> usize
返回最近一帧增量上传至 GPU instance_buf 的实际字节数(用于观测增量上传收益)。
Sourcepub fn remove_canvas_scene(&mut self, scene_id: StaticSceneId) -> bool
pub fn remove_canvas_scene(&mut self, scene_id: StaticSceneId) -> bool
显式移除并释放指定 SceneCanvas 场景的 GPU 显存缓冲。
Sourcepub fn canvas_cache_bytes(&self) -> usize
pub fn canvas_cache_bytes(&self) -> usize
返回 CanvasGpuEngine 当前缓存的所有场景 GPU 显存总字节数。
Sourcepub fn canvas_scene_count(&self) -> usize
pub fn canvas_scene_count(&self) -> usize
返回 CanvasGpuEngine 当前缓存的场景数量。
Sourcepub fn canvas_last_state_upload_bytes(&self) -> usize
pub fn canvas_last_state_upload_bytes(&self) -> usize
返回最近一次 SceneCanvas 动态状态增量上传的实际字节数。
Sourcepub fn set_canvas_idle_budget(&mut self, bytes: usize)
pub fn set_canvas_idle_budget(&mut self, bytes: usize)
配置 CanvasGpuEngine 空闲场景显存预算(超出时按 LRU 淘汰切走的旧场景)。
Sourcepub fn set_canvas_idle_max_age_frames(&mut self, frames: u64)
pub fn set_canvas_idle_max_age_frames(&mut self, frames: u64)
配置 CanvasGpuEngine 空闲场景最大存活帧数。
Sourcepub fn render_to_view(
&mut self,
device: &Device,
queue: &Queue,
ops: &[DrawOp<'_>],
viewport: Region,
scale_factor: f32,
target_view: &TextureView,
phys_width: u32,
phys_height: u32,
clear_color: Color,
)
pub fn render_to_view( &mut self, device: &Device, queue: &Queue, ops: &[DrawOp<'_>], viewport: Region, scale_factor: f32, target_view: &TextureView, phys_width: u32, phys_height: u32, clear_color: Color, )
将当前帧 ops 直接渲染至目标 target_view:
- 无图层/混合模式时走单 RenderPass / 单 Draw Call 直出快路径(0 离屏拷贝);
- 含
PushLayer/ 混合 / 毛玻璃 / 滤镜时自动通过GpuEffectsEngine在单CommandEncoder内完成多 Pass 离屏合成。
Sourcepub fn render_to_view_with_damage_hints(
&mut self,
device: &Device,
queue: &Queue,
ops: &[DrawOp<'_>],
viewport: Region,
scale_factor: f32,
target_view: &TextureView,
phys_width: u32,
phys_height: u32,
clear_color: Color,
damage_hints: Option<&[Region]>,
)
pub fn render_to_view_with_damage_hints( &mut self, device: &Device, queue: &Queue, ops: &[DrawOp<'_>], viewport: Region, scale_factor: f32, target_view: &TextureView, phys_width: u32, phys_height: u32, clear_color: Color, damage_hints: Option<&[Region]>, )
面向 Swapchain 整帧清屏呈现的入口,同时接受可选的 damage_hints 脏区切片供多 Pass 毛玻璃
执行外扩采样框交集剪枝与模糊小纹理跨帧复用(绝不跳过 Swapchain 整屏清屏)。
Sourcepub fn render_to_view_dirty(
&mut self,
device: &Device,
queue: &Queue,
ops: &[DrawOp<'_>],
viewport: Region,
scale_factor: f32,
target_view: &TextureView,
phys_width: u32,
phys_height: u32,
dirty_regions: &[Region],
clear_color: Color,
)
pub fn render_to_view_dirty( &mut self, device: &Device, queue: &Queue, ops: &[DrawOp<'_>], viewport: Region, scale_factor: f32, target_view: &TextureView, phys_width: u32, phys_height: u32, dirty_regions: &[Region], clear_color: Color, )
面向持久离屏画布的 GPU 硬件脏区 Scissor 局部增量渲染(仅重绘 dirty_regions 覆盖的物理像素,保留未脏区域以压低 4K 功耗)。
若本帧包含复杂离屏图层/毛玻璃或 dirty_regions 为空,自动无缝回退至标准整帧 render_to_view。
Sourcepub fn render_to_view_dirty_with_copy(
&mut self,
device: &Device,
queue: &Queue,
ops: &[DrawOp<'_>],
viewport: Region,
scale_factor: f32,
target_view: &TextureView,
phys_width: u32,
phys_height: u32,
dirty_regions: &[Region],
clear_color: Color,
post_copy: Option<(&Texture, &Texture)>,
) -> bool
pub fn render_to_view_dirty_with_copy( &mut self, device: &Device, queue: &Queue, ops: &[DrawOp<'_>], viewport: Region, scale_factor: f32, target_view: &TextureView, phys_width: u32, phys_height: u32, dirty_regions: &[Region], clear_color: Color, post_copy: Option<(&Texture, &Texture)>, ) -> bool
面向持久渲染目标的局部 Scissor 渲染 + 同 CommandEncoder 硬件纹理拷贝上屏(单次 queue.submit)。
- 返回
true表示本次实际命中了LoadOp::Load + set_scissor_rect局部增量重绘(并跳过非脏区图元 CPU 编码); - 返回
false表示因透明底、多 Pass 图层或SceneCanvas退化为整屏重绘(若传入post_copy,同样在提交后完成拷贝上屏)。
Auto Trait Implementations§
impl !RefUnwindSafe for WgpuRenderer
impl !Sync for WgpuRenderer
impl !UnwindSafe for WgpuRenderer
impl Forget for WgpuRenderer
impl Freeze for WgpuRendererwhere
*const ArcInner<CoreRenderPipeline> is !null: Freeze,
PhantomData<ArcInner<CoreRenderPipeline>>: Freeze,
*const ArcInner<CoreBindGroupLayout> is !null: Freeze,
PhantomData<ArcInner<CoreBindGroupLayout>>: Freeze,
*const ArcInner<CoreBindGroup> is !null: Freeze,
PhantomData<ArcInner<CoreBindGroup>>: Freeze,
*const ArcInner<CoreBuffer> is !null: Freeze,
PhantomData<ArcInner<CoreBuffer>>: Freeze,
*const ArcInner<Mutex<MapContext>> is !null: Freeze,
PhantomData<ArcInner<Mutex<MapContext>>>: Freeze,
InternalBitFlags: Freeze,
*const u8 is !null: Freeze,
PhantomData<AlignedViewportSlot>: Freeze,
*const ArcInner<CoreSampler> is !null: Freeze,
PhantomData<ArcInner<CoreSampler>>: Freeze,
*const ArcInner<CoreTexture> is !null: Freeze,
PhantomData<ArcInner<CoreTexture>>: Freeze,
&'static str: Freeze,
InternalBitFlags: Freeze,
&'static [TextureFormat]: Freeze,
*const ArcInner<CoreTextureView> is !null: Freeze,
PhantomData<ArcInner<CoreTextureView>>: Freeze,
PhantomData<[u32; 4]>: Freeze,
PhantomData<((char, u16), GlyphAtlasEntry)>: Freeze,
PhantomData<(SpriteCacheKey, [f32; 4])>: Freeze,
PhantomData<(u64, u32)>: Freeze,
PhantomData<((u64, u64, u64, u64), BindGroup)>: Freeze,
PhantomData<((u64, u64, u64), BindGroup)>: Freeze,
PhantomData<PooledTarget>: Freeze,
PhantomData<(u64, CachedPathMask)>: Freeze,
PhantomData<EffectUniform>: Freeze,
PhantomData<GpuPassStep>: Freeze,
PhantomData<CanvasUniformData>: Freeze,
PhantomData<(StaticSceneId, CachedGpuScene)>: Freeze,
PhantomData<SlugCurve>: Freeze,
PhantomData<u32>: Freeze,
PhantomData<SlugBand>: Freeze,
PhantomData<SlugGlyphInstance>: Freeze,
PhantomData<((u64, u16, u64), CachedSlugGlyph)>: Freeze,
PhantomData<(u32, u32, u32, u32)>: Freeze,
*const ArcInner<DiskPipelineCache> is !null: Freeze,
PhantomData<ArcInner<DiskPipelineCache>>: Freeze,
*mut Counter<Channel<GpuEffectsEngine>>: Freeze,
*mut Counter<Channel<GpuEffectsEngine>>: Freeze,
*mut Counter<Channel<GpuEffectsEngine>>: Freeze,
*mut Counter<Channel<CanvasGpuEngine>>: Freeze,
*mut Counter<Channel<CanvasGpuEngine>>: Freeze,
*mut Counter<Channel<CanvasGpuEngine>>: Freeze,
PhantomData<(ExternalTextureId, ExternalTextureEntry)>: Freeze,
PhantomData<GpuPrimitive>: Freeze,
PhantomData<Rgba8888>: Freeze,
PhantomData<(TextLayoutKey, Arc<CachedTextLayout>)>: Freeze,
impl Move for WgpuRenderer
impl Send for WgpuRendererwhere
Arc<CoreRenderPipeline>: Send,
Arc<CoreBindGroupLayout>: Send,
Arc<CoreBindGroup>: Send,
Arc<CoreBuffer>: Send,
Arc<Mutex<MapContext>>: Send,
InternalBitFlags: Send,
RawVecInner: Send,
Arc<CoreSampler>: Send,
Arc<CoreTexture>: Send,
&'static str: Send,
InternalBitFlags: Send,
&'static [TextureFormat]: Send,
Arc<CoreTextureView>: Send,
RawTable<((char, u16), GlyphAtlasEntry)>: Send,
RawTable<(SpriteCacheKey, [f32; 4])>: Send,
RawTable<(u64, u32)>: Send,
GpuEffectsEngine: Send,
CanvasGpuEngine: Send,
SlugTextEngine: Send,
Arc<DiskPipelineCache>: Send,
Receiver<GpuEffectsEngine>: Send,
Receiver<CanvasGpuEngine>: Send,
RawTable<(ExternalTextureId, ExternalTextureEntry)>: Send,
RawTable<(TextLayoutKey, Arc<CachedTextLayout>)>: Send,
impl Unpin for WgpuRendererwhere
Arc<CoreRenderPipeline>: Unpin,
Arc<CoreBindGroupLayout>: Unpin,
Arc<CoreBindGroup>: Unpin,
Arc<CoreBuffer>: Unpin,
Arc<Mutex<MapContext>>: Unpin,
InternalBitFlags: Unpin,
*const u8 is !null: Unpin,
Arc<CoreSampler>: Unpin,
Arc<CoreTexture>: Unpin,
&'static str: Unpin,
InternalBitFlags: Unpin,
&'static [TextureFormat]: Unpin,
Arc<CoreTextureView>: Unpin,
Arc<DiskPipelineCache>: Unpin,
*mut Counter<Channel<GpuEffectsEngine>>: Unpin,
*mut Counter<Channel<GpuEffectsEngine>>: Unpin,
*mut Counter<Channel<GpuEffectsEngine>>: Unpin,
*mut Counter<Channel<CanvasGpuEngine>>: Unpin,
*mut Counter<Channel<CanvasGpuEngine>>: Unpin,
*mut Counter<Channel<CanvasGpuEngine>>: Unpin,
Arc<CachedTextLayout>: Unpin,
impl UnsafeUnpin for WgpuRendererwhere
*const ArcInner<CoreRenderPipeline> is !null: UnsafeUnpin,
PhantomData<ArcInner<CoreRenderPipeline>>: UnsafeUnpin,
*const ArcInner<CoreBindGroupLayout> is !null: UnsafeUnpin,
PhantomData<ArcInner<CoreBindGroupLayout>>: UnsafeUnpin,
*const ArcInner<CoreBindGroup> is !null: UnsafeUnpin,
PhantomData<ArcInner<CoreBindGroup>>: UnsafeUnpin,
*const ArcInner<CoreBuffer> is !null: UnsafeUnpin,
PhantomData<ArcInner<CoreBuffer>>: UnsafeUnpin,
*const ArcInner<Mutex<MapContext>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<MapContext>>>: UnsafeUnpin,
InternalBitFlags: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<AlignedViewportSlot>: UnsafeUnpin,
*const ArcInner<CoreSampler> is !null: UnsafeUnpin,
PhantomData<ArcInner<CoreSampler>>: UnsafeUnpin,
*const ArcInner<CoreTexture> is !null: UnsafeUnpin,
PhantomData<ArcInner<CoreTexture>>: UnsafeUnpin,
&'static str: UnsafeUnpin,
InternalBitFlags: UnsafeUnpin,
&'static [TextureFormat]: UnsafeUnpin,
*const ArcInner<CoreTextureView> is !null: UnsafeUnpin,
PhantomData<ArcInner<CoreTextureView>>: UnsafeUnpin,
PhantomData<[u32; 4]>: UnsafeUnpin,
PhantomData<((char, u16), GlyphAtlasEntry)>: UnsafeUnpin,
PhantomData<(SpriteCacheKey, [f32; 4])>: UnsafeUnpin,
PhantomData<(u64, u32)>: UnsafeUnpin,
PhantomData<((u64, u64, u64, u64), BindGroup)>: UnsafeUnpin,
PhantomData<((u64, u64, u64), BindGroup)>: UnsafeUnpin,
PhantomData<PooledTarget>: UnsafeUnpin,
PhantomData<(u64, CachedPathMask)>: UnsafeUnpin,
PhantomData<EffectUniform>: UnsafeUnpin,
PhantomData<GpuPassStep>: UnsafeUnpin,
PhantomData<CanvasUniformData>: UnsafeUnpin,
PhantomData<(StaticSceneId, CachedGpuScene)>: UnsafeUnpin,
PhantomData<SlugCurve>: UnsafeUnpin,
PhantomData<u32>: UnsafeUnpin,
PhantomData<SlugBand>: UnsafeUnpin,
PhantomData<SlugGlyphInstance>: UnsafeUnpin,
PhantomData<((u64, u16, u64), CachedSlugGlyph)>: UnsafeUnpin,
PhantomData<(u32, u32, u32, u32)>: UnsafeUnpin,
*const ArcInner<DiskPipelineCache> is !null: UnsafeUnpin,
PhantomData<ArcInner<DiskPipelineCache>>: UnsafeUnpin,
*mut Counter<Channel<GpuEffectsEngine>>: UnsafeUnpin,
*mut Counter<Channel<GpuEffectsEngine>>: UnsafeUnpin,
*mut Counter<Channel<GpuEffectsEngine>>: UnsafeUnpin,
*mut Counter<Channel<CanvasGpuEngine>>: UnsafeUnpin,
*mut Counter<Channel<CanvasGpuEngine>>: UnsafeUnpin,
*mut Counter<Channel<CanvasGpuEngine>>: UnsafeUnpin,
PhantomData<(ExternalTextureId, ExternalTextureEntry)>: UnsafeUnpin,
PhantomData<GpuPrimitive>: UnsafeUnpin,
PhantomData<Rgba8888>: UnsafeUnpin,
PhantomData<(TextLayoutKey, Arc<CachedTextLayout>)>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FluentBuilder for T
impl<T> FluentBuilder for T
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
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
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
fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self
option 为 Some(value) 时执行闭包修饰自身,否则原样返回。