Skip to content

Commit

Permalink
clean up warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
schell committed Apr 9, 2024
1 parent 2df672e commit 1cb5fec
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 77 deletions.
2 changes: 1 addition & 1 deletion crates/renderling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ readme = "../../README.md"
crate-type = ["lib", "dylib"]

[features]
default = ["winit", "sdf", "shaders", "tutorial"]
default = ["gltf", "sdf", "shaders", "tutorial", "winit"]
shaders = [
"array_test",
"brdf_lut_convolution_fragment",
Expand Down
10 changes: 7 additions & 3 deletions crates/renderling/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
//! A few "GPU driven" renderers with a focus on simplicity and ease of use.
//! Backed by WebGPU.
//! Shaders are written in Rust using `rust-gpu` (mostly).
//!
//! Shaders are written in Rust using `rust-gpu`.
//!
//! Data is staged on the GPU using [`crabslab`], a slab allocator.
//!
//! # WARNING
//!
//! This is very much a work in progress.
//! YMMV.
//! PRs are very welcomed :)
//!
//! Your mileage may vary, and your PRs are welcomed :)
#![cfg_attr(target_arch = "spirv", no_std)]
#![deny(clippy::disallowed_methods)]

Expand Down
4 changes: 0 additions & 4 deletions crates/renderling/src/pbr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
use crabslab::{Array, Id, Slab, SlabItem};
use glam::{Vec2, Vec3, Vec4, Vec4Swizzles};
use light::Light;
use spirv_std::{
image::{Cubemap, Image2d},
spirv, Sampler,
};

#[cfg(target_arch = "spirv")]
use spirv_std::num_traits::Float;
Expand Down
2 changes: 1 addition & 1 deletion crates/renderling/src/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! The `Stage` object contains a slab buffer and a render pipeline.
//! It is used to stage objects for rendering.
use crabslab::{Array, Id, Offset, Slab, SlabItem};
use crabslab::{Array, Id, Slab, SlabItem};
use glam::{Mat4, UVec2, Vec2, Vec3, Vec4, Vec4Swizzles};
use spirv_std::{
image::{Cubemap, Image2d},
Expand Down
4 changes: 2 additions & 2 deletions crates/renderling/src/stage/cpu.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! GPU staging area.
//!
//! The `Stage` object contains a slab buffer and a render pipeline.
//! It is used to stage objects for rendering.
//! It is used to stage [`Renderlet`]s for rendering.
use std::{
ops::{Deref, DerefMut},
sync::{atomic::AtomicBool, Arc, Mutex, RwLock},
Expand Down Expand Up @@ -832,7 +832,7 @@ mod test {
use crabslab::{Array, GrowableSlab, Slab};
use glam::{Vec2, Vec3};

use crate::{Camera, Renderlet, RenderletFragmentLog, RenderletVertexLog, Renderling, Vertex};
use crate::{Camera, Renderlet, RenderletVertexLog, Renderling, Vertex};

#[test]
fn vertex_slab_roundtrip() {
Expand Down
70 changes: 9 additions & 61 deletions crates/renderling/src/stage/gltf_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ impl Stage {
camera_id: Id<Camera>,
node: gltf::Node<'a>,
parents: Vec<Id<GltfNode>>,
) -> Vec<Id<GltfRendering>> {
) -> Vec<Id<Renderlet>> {
if let Some(_light) = node.light() {
// TODO: Support transforming lights based on node transforms
////let light = gpu_doc.lights.at(light.index());
Expand Down Expand Up @@ -1095,7 +1095,7 @@ impl Stage {
gpu_doc: &GltfDocument,
camera_id: Id<Camera>,
node: gltf::Node<'_>,
) -> Vec<Id<GltfRendering>> {
) -> Vec<Id<Renderlet>> {
self.draw_gltf_node_with(gpu_doc, camera_id, node, vec![])
}

Expand All @@ -1106,7 +1106,7 @@ impl Stage {
gpu_doc: &GltfDocument,
camera_id: Id<Camera>,
scene: gltf::Scene<'_>,
) -> Vec<Id<GltfRendering>> {
) -> Vec<Id<Renderlet>> {
scene
.nodes()
.flat_map(|node| self.draw_gltf_node(gpu_doc, camera_id, node))
Expand Down Expand Up @@ -1342,7 +1342,7 @@ impl<'a, T: GrowableSlab> GltfMeshBuilder<'a, T> {
mod test {
use crate::{gltf::*, pbr::Material, stage::Vertex, Camera, Renderling, Stage, Transform};
use crabslab::{Array, GrowableSlab, Id, Slab, SlabItem};
use glam::{Vec2, Vec3, Vec4, Vec4Swizzles};
use glam::{UVec2, Vec2, Vec3, Vec4, Vec4Swizzles};

#[test]
fn get_vertex_count_primitive_sanity() {
Expand Down Expand Up @@ -1428,7 +1428,7 @@ mod test {
let projection = crate::camera::perspective(100.0, 50.0);
let position = Vec3::new(1.0, 0.5, 1.5);
let view = crate::camera::look_at(position, Vec3::new(1.0, 0.5, 0.0), Vec3::Y);
let mut stage = Stage::new(device.clone(), queue.clone()).with_lighting(false);
let mut stage = r.new_stage().with_lighting(false);
stage.configure_graph(&mut r, true);
let gpu_doc = stage
.load_gltf_document(&document, buffers.clone(), images)
Expand All @@ -1454,7 +1454,7 @@ mod test {
let mut r =
Renderling::headless(20, 20).with_background_color(Vec3::splat(0.0).extend(1.0));
let (device, queue) = r.get_device_and_queue_owned();
let mut stage = Stage::new(device, queue).with_lighting(false);
let mut stage = r.new_stage().with_lighting(false);
stage.configure_graph(&mut r, true);
let (document, buffers, images) =
::gltf::import("../../gltf/gltfTutorial_003_MinimalGltfFile.gltf").unwrap();
Expand All @@ -1477,67 +1477,14 @@ mod test {
img_diff::assert_img_eq("gltf_minimal_mesh.png", img);
}

#[test]
// Test that the top-level transform on `RenderUnit` transforms their
// child primitive's geometry correctly.
fn render_unit_transforms_primitive_geometry() {
let mut r = Renderling::headless(50, 50).with_background_color(Vec4::splat(1.0));
let mut stage = r.new_stage().with_lighting(false);
stage.configure_graph(&mut r, true);
let (projection, view) = crate::camera::default_ortho2d(50.0, 50.0);
let camera = stage.append(&Camera::new(projection, view));
let cyan = [0.0, 1.0, 1.0, 1.0];
let magenta = [1.0, 0.0, 1.0, 1.0];
let yellow = [1.0, 1.0, 0.0, 1.0];
let white = [1.0, 1.0, 1.0, 1.0];
let vertices = [
Vertex::default()
.with_position([0.0, 0.0, 0.0])
.with_color(cyan),
Vertex::default()
.with_position([1.0, 0.0, 0.0])
.with_color(magenta),
Vertex::default()
.with_position([1.0, 1.0, 0.0])
.with_color(yellow),
Vertex::default()
.with_position([0.0, 1.0, 0.0])
.with_color(white),
];
let primitive = stage.new_primitive(vertices, [0, 3, 2, 0, 2, 1], Id::NONE);
let primitives = stage.append_array(&[primitive]);
let mesh = stage.append(&GltfMesh {
primitives,
..Default::default()
});
let node = stage.append(&GltfNode {
mesh,
..Default::default()
});
let node_path = stage.append_array(&[node]);
let transform = stage.append(&Transform {
scale: Vec3::new(50.0, 50.0, 1.0),
..Default::default()
});
let _unit_id = stage.draw(&GltfRendering {
camera,
transform,
vertex_count: primitive.vertex_count,
node_path,
..Default::default()
});
let img = r.render_linear_image().unwrap();
img_diff::assert_img_eq("gltf/render_unit_transforms_primitive_geometry.png", img);
}

#[test]
// Tests importing a gltf file and rendering the first image as a 2d object.
//
// This ensures we are decoding images correctly.
fn gltf_images() {
let mut r = Renderling::headless(100, 100).with_background_color(Vec4::splat(1.0));
let (device, queue) = r.get_device_and_queue_owned();
let mut stage = Stage::new(device.clone(), queue.clone()).with_lighting(false);
let mut stage = r.new_stage().with_lighting(false);
stage.configure_graph(&mut r, true);
let (document, buffers, images) = gltf::import("../../gltf/cheetah_cone.glb").unwrap();
let gpu_doc = stage
Expand Down Expand Up @@ -1606,7 +1553,8 @@ mod test {
let mut r =
Renderling::headless(size, size).with_background_color(Vec3::splat(0.0).extend(1.0));
let (device, queue) = r.get_device_and_queue_owned();
let mut stage = Stage::new(device.clone(), queue.clone())
let mut stage = r
.new_stage()
// There are no lights in the scene and the material isn't marked as "unlit", so
// let's force it to be unlit.
.with_lighting(false);
Expand Down
7 changes: 2 additions & 5 deletions crates/renderling/src/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,11 @@ pub fn tutorial_slabbed_renderlet(
mod test {
use crabslab::*;
use glam::{Vec3, Vec4, Vec4Swizzles};
use moongraph::NoDefault;

use crate::{
frame::FrameTextureView,
graph::{graph, Graph, GraphError, View},
pbr::PbrConfig,
Camera, CpuCubemap, CpuTexture2d, DepthTexture, Device, Queue, Renderlet, Renderling,
Sample2d, Transform, Vertex,
graph::{graph, Graph, GraphError, NoDefault, View},
Camera, DepthTexture, Device, Queue, Renderlet, Renderling, Transform, Vertex,
};

#[test]
Expand Down

0 comments on commit 1cb5fec

Please sign in to comment.