wgpu: Fix buffer bug detection

This commit is contained in:
Nathan Adams 2023-01-15 22:38:32 +01:00
parent e6a44e2584
commit 6138714fa7
2 changed files with 74 additions and 72 deletions

View File

@ -5,7 +5,6 @@ use crate::surface::Surface;
use crate::target::RenderTargetFrame;
use crate::target::TextureTarget;
use crate::uniform_buffer::BufferStorage;
use crate::utils::detect_buffer_bug;
use crate::{
as_texture, format_list, get_backend_names, ColorAdjustments, Descriptors, Error,
QueueSyncHandle, RenderTarget, SwapChainTarget, Texture, Transforms,
@ -210,9 +209,8 @@ impl<T: RenderTarget> WgpuRenderBackend<T> {
let (device, queue) = request_device(&adapter, trace_path).await?;
if cfg!(target_arch = "wasm") && device.limits().max_push_constant_size == 0 {
detect_buffer_bug(&device, &queue)?;
}
#[cfg(target_family = "wasm")]
crate::utils::detect_buffer_bug(&device, &queue)?;
Ok(Descriptors::new(adapter, device, queue))
}

View File

@ -161,10 +161,11 @@ pub fn buffer_to_image(
#[allow(dead_code)]
// https://github.com/gfx-rs/wgpu/issues/3371
pub fn detect_buffer_bug(device: &wgpu::Device, queue: &wgpu::Queue) -> Result<(), Error> {
let expected_color: [f32; 4] = [1.0, 0.5, 0.25, 1.0];
let expected_rgba = image::Rgba([50, 100, 200, 255]);
let expected_color: [f32; 4] = expected_rgba.0.map(|c| (c as f32) / 255.0);
let size = wgpu::Extent3d {
width: 32,
height: 32,
width: 8,
height: 8,
depth_or_array_layers: 1,
};
let format = wgpu::TextureFormat::Rgba8Unorm;
@ -210,6 +211,7 @@ pub fn detect_buffer_bug(device: &wgpu::Device, queue: &wgpu::Queue) -> Result<(
}),
multiview: None,
});
for i in 0..size.width {
let texture = device.create_texture(&wgpu::TextureDescriptor {
label: None,
size,
@ -272,13 +274,15 @@ pub fn detect_buffer_bug(device: &wgpu::Device, queue: &wgpu::Queue) -> Result<(
);
let index = queue.submit(Some(encoder.finish()));
let image = buffer_to_image(device, &result, &buffer_dimensions, Some(index), size, true);
let expected_rgba = image::Rgba(expected_color.map(|c| (c * 256.0) as u8));
if image.get_pixel(0, 0) != &expected_rgba {
if image.get_pixel(i, i) != &expected_rgba {
tracing::error!(
"Buffer test failed, expected {expected_rgba:?} but found {:?}",
image.get_pixel(0, 0)
"Buffer test failed on pass {i}, expected {expected_rgba:?} but found {:?}",
image.get_pixel(i, i)
);
return Err("Buffer test failed".to_string().into());
} else {
tracing::info!("Buffer test success on pass {i}");
}
}
Ok(())
}