Skip to content

Commit

Permalink
chore(gpu): 🤖 remove lock for gpu test
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Adoo committed Apr 25, 2024
1 parent 27cf301 commit 6654c37
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 26 deletions.
8 changes: 0 additions & 8 deletions dev-helper/src/painter_backend_eq_image_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,6 @@ pub fn assert_texture_eq_png(img: PixelImage, file_path: &std::path::Path) {
}
}

// todo: Fix me, it looks like a wgpu bug? Windows systems may hang threads when
// using multiple WgpuImpl in tests.
// it's a temporary solution: manually lock SINGLETON_WGPU_GUARD to prevent
// multiple WgpuImpl in your tests.
pub static SINGLETON_WGPU_GUARD: once_cell::sync::Lazy<std::sync::Mutex<()>> =
once_cell::sync::Lazy::new(|| std::sync::Mutex::new(()));

/// Render painter by wgpu backend, and return the image.
pub fn wgpu_render_commands(
commands: Vec<ribir_painter::PaintCommand>, viewport: ribir_geom::DeviceRect,
Expand All @@ -127,7 +120,6 @@ pub fn wgpu_render_commands(
use ribir_gpu::{GPUBackend, GPUBackendImpl, Texture};
use ribir_painter::{AntiAliasing, PainterBackend};

let _guard = SINGLETON_WGPU_GUARD.lock().unwrap();
let mut gpu_impl = block_on(ribir_gpu::WgpuImpl::headless());

let rect = DeviceRect::from_size(DeviceSize::new(viewport.max_x() + 2, viewport.max_y() + 2));
Expand Down
8 changes: 0 additions & 8 deletions gpu/src/gpu_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,14 +546,6 @@ mod tests {
use ribir_painter::{Brush, Painter, Path, Svg};

use super::*;
use crate::WgpuImpl;

pub fn headless() -> (WgpuImpl, std::sync::MutexGuard<'static, ()>) {
use futures::executor::block_on;
let _guard = SINGLETON_WGPU_GUARD.lock().unwrap();
let gpu_impl = block_on(WgpuImpl::headless());
(gpu_impl, _guard)
}

fn painter(bounds: Size) -> Painter { Painter::new(Rect::from_size(bounds)) }

Expand Down
10 changes: 5 additions & 5 deletions gpu/src/gpu_backend/atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ mod tests {
use futures::executor::block_on;

use super::*;
use crate::{gpu_backend::tests::headless, WgpuTexture};
use crate::{WgpuImpl, WgpuTexture};
#[test]
fn atlas_grow_to_alloc() {
let (mut gpu_impl, _guard) = headless();
let mut gpu_impl = block_on(WgpuImpl::headless());
let mut atlas =
Atlas::<WgpuTexture, _, _>::new("_", ColorFormat::Alpha8, AntiAliasing::None, &mut gpu_impl);
let size = DeviceSize::new(ATLAS_MIN_SIZE.width + 1, 16);
Expand All @@ -212,7 +212,7 @@ mod tests {

#[test]
fn resource_clear() {
let (mut wgpu, _guard) = headless();
let mut wgpu = block_on(WgpuImpl::headless());
let mut atlas =
Atlas::<WgpuTexture, _, _>::new("_", ColorFormat::Rgba8, AntiAliasing::None, &mut wgpu);
atlas.allocate(1, (), DeviceSize::new(32, 32), &mut wgpu);
Expand All @@ -227,7 +227,7 @@ mod tests {

#[test]
fn fix_scale_path_cache_miss() {
let (mut wgpu, _guard) = headless();
let mut wgpu = block_on(WgpuImpl::headless());
let mut atlas =
Atlas::<WgpuTexture, _, _>::new("_", ColorFormat::Rgba8, AntiAliasing::None, &mut wgpu);
atlas.allocate(1, (), DeviceSize::new(32, 32), &mut wgpu);
Expand All @@ -250,7 +250,7 @@ mod tests {

#[test]
fn fix_atlas_expand_overlap() {
let (mut wgpu, _guard) = headless();
let mut wgpu = block_on(WgpuImpl::headless());
let mut atlas =
Atlas::<WgpuTexture, _, _>::new("_", ColorFormat::Alpha8, AntiAliasing::None, &mut wgpu);
let icon = DeviceSize::new(32, 32);
Expand Down
10 changes: 5 additions & 5 deletions gpu/src/gpu_backend/textures_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ pub mod tests {
use ribir_painter::Color;

use super::*;
use crate::{gpu_backend::tests::headless, WgpuImpl, WgpuTexture};
use crate::{WgpuImpl, WgpuTexture};

pub fn color_image(color: Color, width: u32, height: u32) -> ShareResource<PixelImage> {
let data = std::iter::repeat(color.into_components())
Expand All @@ -552,7 +552,7 @@ pub mod tests {

#[test]
fn smoke_store_image() {
let (mut wgpu, _guard) = headless();
let mut wgpu = block_on(WgpuImpl::headless());
let mut mgr = TexturesMgr::new(&mut wgpu, AntiAliasing::None);

let red_img = color_image(Color::RED, 32, 32);
Expand Down Expand Up @@ -598,7 +598,7 @@ pub mod tests {

#[test]
fn transform_path_share_cache() {
let (mut wgpu, _guard) = headless();
let mut wgpu = block_on(WgpuImpl::headless());
let mut mgr = TexturesMgr::<WgpuTexture>::new(&mut wgpu, AntiAliasing::None);

let path1 = Path::rect(&rect(0., 0., 300., 300.));
Expand All @@ -615,7 +615,7 @@ pub mod tests {

#[test]
fn store_clipped_path() {
let (mut wgpu, _guard) = headless();
let mut wgpu = block_on(WgpuImpl::headless());
let mut mgr = TexturesMgr::<WgpuTexture>::new(&mut wgpu, AntiAliasing::None);

let path = PaintPath::new(
Expand All @@ -637,7 +637,7 @@ pub mod tests {
// because the next resource may allocate at same address of a deallocated
// address.

let (mut wgpu, _guard) = headless();
let mut wgpu = block_on(WgpuImpl::headless());
let mut mgr = TexturesMgr::<WgpuTexture>::new(&mut wgpu, AntiAliasing::None);
{
let red_img = color_image(Color::RED, 32, 32);
Expand Down

0 comments on commit 6654c37

Please sign in to comment.