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()));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue