diff --git a/src/cache.rs b/src/cache.rs index e3a6167..2aceca1 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -4,7 +4,7 @@ use std::{ mem, num::NonZeroU64, ops::Deref, - sync::{Arc, RwLock}, + sync::{Arc, Mutex}, }; use wgpu::{ BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutEntry, @@ -29,12 +29,12 @@ struct Inner { atlas_layout: BindGroupLayout, uniforms_layout: BindGroupLayout, pipeline_layout: PipelineLayout, - cache: RwLock< + cache: Mutex< Vec<( TextureFormat, MultisampleState, Option, - Arc, + RenderPipeline, )>, >, } @@ -153,7 +153,7 @@ impl Cache { uniforms_layout, atlas_layout, pipeline_layout, - cache: RwLock::new(Vec::new()), + cache: Mutex::new(Vec::new()), })) } @@ -200,7 +200,7 @@ impl Cache { format: TextureFormat, multisample: MultisampleState, depth_stencil: Option, - ) -> Arc { + ) -> RenderPipeline { let Inner { cache, pipeline_layout, @@ -209,14 +209,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 { @@ -243,7 +243,7 @@ impl Cache { multisample, multiview: None, cache: None, - })); + }); cache.push((format, multisample, depth_stencil, pipeline.clone())); diff --git a/src/text_atlas.rs b/src/text_atlas.rs index 2c9f28c..2d73893 100644 --- a/src/text_atlas.rs +++ b/src/text_atlas.rs @@ -1,15 +1,16 @@ use crate::{ - text_render::GlyphonCacheKey, Cache, ContentType, RasterizeCustomGlyphRequest, FontSystem, - GlyphDetails, GpuCacheStatus, RasterizedCustomGlyph, SwashCache, + text_render::GlyphonCacheKey, Cache, ContentType, FontSystem, GlyphDetails, GpuCacheStatus, + RasterizeCustomGlyphRequest, RasterizedCustomGlyph, SwashCache, }; 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, TexelCopyTextureInfo, TexelCopyBufferLayout, - MultisampleState, Origin3d, Queue, RenderPipeline, Texture, TextureAspect, TextureDescriptor, - TextureDimension, TextureFormat, TextureUsages, TextureView, TextureViewDescriptor, + BindGroup, DepthStencilState, Device, Extent3d, MultisampleState, Origin3d, Queue, + RenderPipeline, TexelCopyBufferLayout, TexelCopyTextureInfo, Texture, TextureAspect, + TextureDescriptor, TextureDimension, TextureFormat, TextureUsages, TextureView, + TextureViewDescriptor, }; type Hasher = BuildHasherDefault; @@ -344,9 +345,7 @@ impl TextAtlas { cache: &mut SwashCache, content_type: ContentType, scale_factor: f32, - rasterize_custom_glyph: impl FnMut( - RasterizeCustomGlyphRequest, - ) -> Option, + rasterize_custom_glyph: impl FnMut(RasterizeCustomGlyphRequest) -> Option, ) -> bool { let did_grow = match content_type { ContentType::Mask => self.mask_atlas.grow( @@ -386,7 +385,7 @@ impl TextAtlas { device: &Device, multisample: MultisampleState, depth_stencil: Option, - ) -> Arc { + ) -> RenderPipeline { self.cache .get_or_create_pipeline(device, self.format, multisample, depth_stencil) } diff --git a/src/text_render.rs b/src/text_render.rs index 3189ab3..019b14a 100644 --- a/src/text_render.rs +++ b/src/text_render.rs @@ -4,18 +4,18 @@ use crate::{ RasterizedCustomGlyph, RenderError, SwashCache, SwashContent, TextArea, TextAtlas, Viewport, }; use cosmic_text::{Color, SubpixelBin}; -use std::{slice, sync::Arc}; +use std::slice; use wgpu::{ - Buffer, BufferDescriptor, BufferUsages, DepthStencilState, Device, Extent3d, TexelCopyTextureInfo, - TexelCopyBufferLayout, MultisampleState, Origin3d, Queue, RenderPass, RenderPipeline, TextureAspect, - COPY_BUFFER_ALIGNMENT, + Buffer, BufferDescriptor, BufferUsages, DepthStencilState, Device, Extent3d, MultisampleState, + Origin3d, Queue, RenderPass, RenderPipeline, TexelCopyBufferLayout, TexelCopyTextureInfo, + TextureAspect, COPY_BUFFER_ALIGNMENT, }; /// A text renderer that uses cached glyphs to render text into an existing render pass. pub struct TextRenderer { vertex_buffer: Buffer, vertex_buffer_size: u64, - pipeline: Arc, + pipeline: RenderPipeline, glyph_vertices: Vec, }