Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into gpu-culling
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Aug 12, 2023
2 parents ea2a1c2 + 14b0021 commit d36199f
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 10 deletions.
2 changes: 1 addition & 1 deletion rend3-test/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl TestRunner {
],
rend3::types::Handedness::Left,
)
.with_indices(vec![0, 1, 2, 0, 2, 3])
.with_indices(vec![0, 2, 1, 0, 3, 2])
.build()
.unwrap();

Expand Down
23 changes: 15 additions & 8 deletions rend3-test/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use wgpu::{

use crate::{helpers::CaptureDropGuard, ThresholdSet};

#[derive(Clone)]
pub struct FrameRenderSettings {
size: u32,
samples: SampleCount,
Expand Down Expand Up @@ -129,14 +130,7 @@ impl TestRunner {
TestRunnerBuilder::new()
}

pub async fn render_frame(&self, settings: FrameRenderSettings) -> Result<image::RgbaImage> {
let buffer = self.renderer.device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Test output buffer"),
size: (settings.size * settings.size * 4) as u64,
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ,
mapped_at_creation: false,
});

pub fn process_events(&self, settings: FrameRenderSettings) -> wgpu::Texture {
let texture = self.renderer.device.create_texture(&TextureDescriptor {
label: Some("Test output image"),
size: Extent3d {
Expand Down Expand Up @@ -179,6 +173,19 @@ impl TestRunner {

graph.execute(&self.renderer, &mut eval_output);

texture
}

pub async fn render_frame(&self, settings: FrameRenderSettings) -> Result<image::RgbaImage> {
let buffer = self.renderer.device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Test output buffer"),
size: (settings.size * settings.size * 4) as u64,
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ,
mapped_at_creation: false,
});

let texture = self.process_events(settings.clone());

let mut encoder = self
.renderer
.device
Expand Down
45 changes: 45 additions & 0 deletions rend3-test/tests/msaa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,48 @@ pub async fn triangle() -> anyhow::Result<()> {

Ok(())
}

#[test_attr]
pub async fn sample_coverage() -> anyhow::Result<()> {
let iad = no_gpu_return!(rend3::create_iad(None, None, None, None).await)
.context("InstanceAdapterDevice creation failed")?;

let Ok(runner) = TestRunner::builder().iad(iad.clone()).handedness(Handedness::Left).build().await else {
return Ok(());
};

let material = runner.add_unlit_material(Vec4::ONE);

// Make a plane whose (0, 0) is at the top left, and is 1 unit large.
let base_matrix = Mat4::from_translation(Vec3::new(0.5, 0.5, 0.0)) * Mat4::from_scale(Vec3::new(0.5, 0.5, 1.0));
// 64 x 64 grid of planes
let mut planes = Vec::with_capacity(64 * 64);
for x in 0..64 {
for y in 0..64 {
planes.push(runner.plane(
material.clone(),
Mat4::from_translation(Vec3::new(x as f32, y as f32, 0.0))
* Mat4::from_scale(Vec3::new(1.0 - (x as f32 / 63.0), 1.0 - (y as f32 / 63.0), 1.0))
* base_matrix,
));
}
runner.process_events(FrameRenderSettings::new());
}

runner.set_camera_data(Camera {
projection: rend3::types::CameraProjection::Raw(Mat4::orthographic_lh(0.0, 64.0, 64.0, 0.0, 0.0, 1.0)),
view: Mat4::IDENTITY,
});

for samples in SampleCount::ARRAY {
runner
.render_and_compare(
FrameRenderSettings::new().samples(samples),
&format!("tests/results/msaa/sample-coverage-{}.png", samples as u8),
0.0,
)
.await?;
}

Ok(())
}
Binary file added rend3-test/tests/results/msaa/sample-coverage-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rend3-test/tests/results/msaa/sample-coverage-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion rend3-test/tests/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub async fn shadows() -> anyhow::Result<()> {

let material1 = runner.add_lit_material(Vec4::new(0.25, 0.5, 0.75, 1.0));

let _plane = runner.plane(material1, Mat4::from_rotation_x(FRAC_PI_2));
let _plane = runner.plane(material1, Mat4::from_rotation_x(-FRAC_PI_2));

runner.set_camera_data(Camera {
projection: rend3::types::CameraProjection::Orthographic {
Expand Down
2 changes: 2 additions & 0 deletions rend3-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,8 @@ impl TryFrom<u8> for SampleCount {
}

impl SampleCount {
pub const ARRAY: [Self; 2] = [Self::One, Self::Four];

/// Determines if a resolve texture is needed for this texture.
pub fn needs_resolve(self) -> bool {
self != Self::One
Expand Down

0 comments on commit d36199f

Please sign in to comment.