Skip to content

Commit

Permalink
using Renderlet and renderlet_* shaders, fixed wrapping addition bug …
Browse files Browse the repository at this point in the history
…in crabslab
  • Loading branch information
schell committed Apr 5, 2024
1 parent 63d88c8 commit 71554b3
Show file tree
Hide file tree
Showing 71 changed files with 1,943 additions and 1,047 deletions.
305 changes: 293 additions & 12 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ resolver = "2"
assert_approx_eq = "1.1.0"
async-channel = "1.8"
bytemuck = { version = "1.13.0", features = ["derive"] }
crabslab = { version = "0.4.1", default-features = false }
crabslab = { version = "0.4.5", path = "../crabslab/crates/crabslab", default-features = false }
env_logger = "0.10.0"
futures-lite = "1.13"
gltf = { git = 'https://github.com/gltf-rs/gltf.git', features = ["KHR_lights_punctual", "KHR_materials_unlit", "KHR_materials_emissive_strength", "extras"] }
image = "0.24"
log = "0.4"
naga = { version = "0.19", features = ["spv-in", "wgsl-out", "wgsl-in", "msl-out"] }
plotters = "0.3"
pretty_assertions = "1.4.0"
proc-macro2 = { version = "1.0", features = ["span-locations"] }
glam = { version = "0.24.2", default-features = false }
Expand Down
92 changes: 92 additions & 0 deletions DEVLOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,97 @@
# devlog

## Sat Apr 10, 2024

### Finishing the debugging session

It WAS `crabslab`! Specifically it was `Slab::contains`, which is used to check that
a type with an `Id` _can be read_.

Previously the definition was:

```rust
fn contains<T: SlabItem>(&self, id: Id<T>) -> bool {
id.index() + T::SLAB_SIZE <= self.len()
}
```

Which seems correct, and it functions correctly on the CPU.
But on the GPU (meaning `target_arch = "spirv"``) `usize` is a 32bit `u32`,
and so the `id.index() + T::SLAB_SIZE` will overflow if the id is `Id::NONE`,
because `Id::NONE = u32::MAX;`.

Indeed, the id is often `Id::NONE`, as that is the default!
This was causing a silent panic in my shader, which then produced no output.

Now the definition is this:
```rust
fn contains<T: SlabItem>(&self, id: Id<T>) -> bool {
self.len() >= T::SLAB_SIZE && id.index() <= self.len() - T::SLAB_SIZE
}
```

What a hard-to-diagnose bug! I really need trace statements on GPU.

## Fri Apr 9, 2024

I have bugs after removing the SDF raymarching stuff.

Primarily I can't get any of my `stage_vertex`+`stage_fragment` tests passing.
Everything is blank.

### Debug with me!

* it's not crabslab: I fixed some bugs in it and after testing through the `tutorial`
shaders I'm 80% certain it's not a (de)serialization problem.
* NOTHING is being written to the depth texture...
- depth is cleared to 1.0
- pipeline depth function is set to ALWAYS (always succeed) and still nothing is written
- face culling is off and still nothing is written
- running the vertex shader on CPU and printing out clip positions shows:
```
clips: [
Vec4(
-1.0,
1.0,
0.25,
1.0,
),
Vec4(
-1.0,
-1.0,
0.25,
1.0,
),
Vec4(
1.0,
1.0,
0.25,
1.0,
),
]
```
Which is a CCW triangle up in the top left of the clip space.
So we should see SOMETHING in the depth texture at least, but we don't.
Why do we not? Is the render even happening on the GPU? Let's check logging
to see if we're issuing the calls..
- `stage_render` prints `drawing vertices 0..3 and instances 147..148`
so I'm certain we're actually rendering.
At this point I'm a bit at a loss. The difference between the tutorial shaders (which are working)
and my stage shader is mainly that the stage shader first writes to an HDR surface and then
runs tonemapping and writes the result to the frame surface. I can't see any other course of action
than removing HDR and tonemapping to see if that works.
I'm going to try rendering the `gltf_cmy_tri` slab with the `tutorial` shaders.
We'll see what happens.
NOTHING! No rendering. No depth values. So this must have something to do with the data.
### What to do about the wacky GLTF stage shaders
I'm going to go back to a much simpler "renderlet" pbr shader program. The entire GLTF document can
still live on the GPU, but GLTF is too complicated a structure to use for the internal representation.
## Mon Feb 26, 2024
### SDF stack lang on GPU considered harmful
Expand Down
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

# renderling 🍖

This aspires to be a modern "GPU-driven" renderer. It is alpha software. I'm still learning, but quickly!
Renderling is an innovative, GPU-driven renderer designed for efficient scene rendering with a focus on leveraging
GPU capabilities for nearly all rendering operations.
Utilizing Rust for shader development, it ensures memory safety and cross-platform compatibility, including web platforms.
The project, currently in the alpha stage, aims for rapid loading of GLTF files, handling large scenes, and supporting numerous lights.
Development emphasizes performance, configurability, observability and the use of modern rendering techniques like forward+ rendering and
physically based shading.

<img width="912" alt="ibl_environment_test" src="https://github.com/schell/renderling/assets/24942/297d6150-64b2-45b8-9760-12b27dc8cc3e">

Expand Down Expand Up @@ -155,10 +160,27 @@ RUSTFLAGS=--cfg=web_sys_unstable_apis trunk build crates/example-wasm/index.html

## 🫶 Sponsor this!

This work will always be free and open source. If you use it (outright or for inspiration), please consider donating.
This work will always be free and open source.
If you use it (outright or for inspiration), please consider donating.

[💰 Sponsor 💝](https://github.com/sponsors/schell)

### Related work & spin-off projects

Many projects were born from first solving a need within `renderling`.
Some of these solutions were then spun off into their own projects.

- [`crabslab`](https://github.com/schell/crabslab)
A slab allocator for working across CPU/GPU boundaries.
- [`loading-bytes`](crates/loading-bytes)
A cross-platform (including the web) way of loading files to bytes.
- [`moongraph`](https://github.com/schell/moongraph)
A DAG and resource graph runner.
- Contributions to [`naga`](https://github.com/gfx-rs/wgpu/issues/4489)
* Adding atomics support to the SPIR-V frontend (in progress)

Sponsoring this project contributes to the ecosystem.

## License
Renderling is free and open source. All code in this repository is dual-licensed under either:

Expand Down
5 changes: 4 additions & 1 deletion crates/img-diff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ fn get_results(
pub fn save(filename: &str, seen: impl Into<DynamicImage>) {
let path = Path::new(TEST_OUTPUT_DIR).join(filename);
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
seen.into().save(path).unwrap();
let img: DynamicImage = seen.into();
let img_buffer = img.into_rgba8();
let img = DynamicImage::from(img_buffer);
img.save(path).unwrap();
}

pub fn assert_eq_cfg(
Expand Down
36 changes: 25 additions & 11 deletions 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", "gltf", "sdf", "shaders"]
default = ["winit", "sdf", "shaders", "tutorial"]
shaders = [
"array_test",
"brdf_lut_convolution_fragment",
Expand All @@ -25,18 +25,25 @@ shaders = [
"pbr_fragment",
"prefilter_environment_cubemap_fragment",
"prefilter_environment_cubemap_vertex",
"renderlet_fragment",
"renderlet_vertex",
"skybox_cubemap_fragment",
"skybox_cubemap_vertex",
"skybox_equirectangular_fragment",
"skybox_vertex",
"stage_fragment",
"stage_vertex",
"test_i8_i16_extraction",
"tonemapping_fragment",
"tonemapping_vertex"
]
gltf = ["dep:gltf"]
sdf = []
tutorial = [
"tutorial_passthru_fragment",
"tutorial_implicit_isosceles_vertex",
"tutorial_slabbed_vertices_no_instance",
"tutorial_slabbed_vertices",
"tutorial_slabbed_renderlet"
]
# shaders
array_test = []
brdf_lut_convolution_fragment = []
Expand All @@ -46,21 +53,27 @@ generate_mipmap_vertex = []
pbr_fragment = []
prefilter_environment_cubemap_fragment = []
prefilter_environment_cubemap_vertex = []
raymarch_fragment = []
raymarch_rays_fragment = []
raymarch_vertex = []
sdf_shape_fragment = []
sdf_shape_vertex = []
sdf_prim_fragment_test = []
#raymarch_fragment = []
#raymarch_rays_fragment = []
#raymarch_vertex = []
#sdf_shape_fragment = []
#sdf_shape_vertex = []
#sdf_prim_fragment_test = []
renderlet_fragment = []
renderlet_vertex = []
skybox_cubemap_fragment = []
skybox_cubemap_vertex = []
skybox_equirectangular_fragment = []
skybox_vertex = []
stage_fragment = []
stage_vertex = []
test_i8_i16_extraction = []
tonemapping_fragment = []
tonemapping_vertex = []
tutorial_passthru_fragment = []
tutorial_implicit_isosceles_vertex = []
tutorial_slabbed_vertices_no_instance = []
tutorial_slabbed_vertices = []
tutorial_slabbed_renderlet = []

wasm = ["wgpu/fragile-send-sync-non-atomic-wasm"]

# dependencies for CPU and GPU code
Expand Down Expand Up @@ -103,6 +116,7 @@ env_logger = {workspace = true}
icosahedron = "0.1"
img-diff = { path = "../img-diff" }
naga.workspace = true
plotters.workspace = true
pretty_assertions.workspace = true
ttf-parser = "0.20.0"

Expand Down
Binary file added crates/renderling/aoeu-clip-plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 71554b3

Please sign in to comment.