Small improvements to cache (#130)
* Remove `Arc` around `RenderPipeline` It is not necessary anymore in last `wgpu` version. * Replace `RwLock` with `Mutex` It was only used for writing.
This commit is contained in:
parent
114cfa3e02
commit
505f12f6ce
3 changed files with 13 additions and 14 deletions
19
src/cache.rs
19
src/cache.rs
|
@ -1,5 +1,4 @@
|
|||
use crate::{GlyphToRender, Params};
|
||||
|
||||
use wgpu::{
|
||||
BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutEntry,
|
||||
BindingResource, BindingType, BlendState, Buffer, BufferBindingType, ColorTargetState,
|
||||
|
@ -14,7 +13,7 @@ use std::borrow::Cow;
|
|||
use std::mem;
|
||||
use std::num::NonZeroU64;
|
||||
use std::ops::Deref;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Cache(Arc<Inner>);
|
||||
|
@ -27,12 +26,12 @@ struct Inner {
|
|||
atlas_layout: BindGroupLayout,
|
||||
uniforms_layout: BindGroupLayout,
|
||||
pipeline_layout: PipelineLayout,
|
||||
cache: RwLock<
|
||||
cache: Mutex<
|
||||
Vec<(
|
||||
TextureFormat,
|
||||
MultisampleState,
|
||||
Option<DepthStencilState>,
|
||||
Arc<RenderPipeline>,
|
||||
RenderPipeline,
|
||||
)>,
|
||||
>,
|
||||
}
|
||||
|
@ -150,7 +149,7 @@ impl Cache {
|
|||
uniforms_layout,
|
||||
atlas_layout,
|
||||
pipeline_layout,
|
||||
cache: RwLock::new(Vec::new()),
|
||||
cache: Mutex::new(Vec::new()),
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -197,7 +196,7 @@ impl Cache {
|
|||
format: TextureFormat,
|
||||
multisample: MultisampleState,
|
||||
depth_stencil: Option<DepthStencilState>,
|
||||
) -> Arc<RenderPipeline> {
|
||||
) -> RenderPipeline {
|
||||
let Inner {
|
||||
cache,
|
||||
pipeline_layout,
|
||||
|
@ -206,14 +205,14 @@ impl Cache {
|
|||
..
|
||||
} = self.0.deref();
|
||||
|
||||
let mut cache = cache.write().expect("Write pipeline cache");
|
||||
let mut cache = cache.lock().expect("Write pipeline cache");
|
||||
|
||||
cache
|
||||
.iter()
|
||||
.find(|(fmt, ms, ds, _)| fmt == &format && ms == &multisample && ds == &depth_stencil)
|
||||
.map(|(_, _, _, p)| Arc::clone(p))
|
||||
.map(|(_, _, _, p)| p.clone())
|
||||
.unwrap_or_else(|| {
|
||||
let pipeline = Arc::new(device.create_render_pipeline(&RenderPipelineDescriptor {
|
||||
let pipeline = device.create_render_pipeline(&RenderPipelineDescriptor {
|
||||
label: Some("glyphon pipeline"),
|
||||
layout: Some(pipeline_layout),
|
||||
vertex: VertexState {
|
||||
|
@ -240,7 +239,7 @@ impl Cache {
|
|||
multisample,
|
||||
multiview: None,
|
||||
cache: None,
|
||||
}));
|
||||
});
|
||||
|
||||
cache.push((format, multisample, depth_stencil, pipeline.clone()));
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
|||
use etagere::{size2, Allocation, BucketedAtlasAllocator};
|
||||
use lru::LruCache;
|
||||
use rustc_hash::FxHasher;
|
||||
use std::{collections::HashSet, hash::BuildHasherDefault, sync::Arc};
|
||||
use std::{collections::HashSet, hash::BuildHasherDefault};
|
||||
use wgpu::{
|
||||
BindGroup, DepthStencilState, Device, Extent3d, MultisampleState, Origin3d, Queue,
|
||||
RenderPipeline, TexelCopyBufferLayout, TexelCopyTextureInfo, Texture, TextureAspect,
|
||||
|
@ -329,7 +329,7 @@ impl TextAtlas {
|
|||
device: &Device,
|
||||
multisample: MultisampleState,
|
||||
depth_stencil: Option<DepthStencilState>,
|
||||
) -> Arc<RenderPipeline> {
|
||||
) -> RenderPipeline {
|
||||
self.cache
|
||||
.get_or_create_pipeline(device, self.format, multisample, depth_stencil)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
|||
ColorMode, FontSystem, GlyphDetails, GlyphToRender, GpuCacheStatus, PrepareError, RenderError,
|
||||
SwashCache, SwashContent, TextArea, TextAtlas, Viewport,
|
||||
};
|
||||
use std::{num::NonZeroU64, slice, sync::Arc};
|
||||
use std::{num::NonZeroU64, slice};
|
||||
use wgpu::util::StagingBelt;
|
||||
use wgpu::{
|
||||
Buffer, BufferDescriptor, BufferUsages, CommandEncoder, DepthStencilState, Device, Extent3d,
|
||||
|
@ -15,7 +15,7 @@ pub struct TextRenderer {
|
|||
staging_belt: StagingBelt,
|
||||
vertex_buffer: Buffer,
|
||||
vertex_buffer_size: u64,
|
||||
pipeline: Arc<RenderPipeline>,
|
||||
pipeline: RenderPipeline,
|
||||
glyph_vertices: Vec<GlyphToRender>,
|
||||
glyphs_to_render: u32,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue