Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering Optimisations - Part 2 #415

Merged
merged 74 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
a16d170
WIP - Asset hot reloading
kanerogers Oct 25, 2022
9b13bf7
Merge branch 'main' into kanerogers/issue386
kanerogers Oct 26, 2022
4a99da8
Add stupid shader
kanerogers Nov 15, 2022
ac0e0a9
wip
kanerogers Nov 16, 2022
cbf3d5c
WIP
kanerogers Nov 16, 2022
578dc62
WIP
kanerogers Nov 17, 2022
c61395d
WIP - filament f16
kanerogers Nov 18, 2022
8508359
WIP
kanerogers Nov 18, 2022
b3ee84c
WIP
kanerogers Nov 20, 2022
5bc1ad2
WIP
kanerogers Nov 21, 2022
9c350e8
WIP
kanerogers Nov 21, 2022
89902d2
WIP - fix mipmap loading
kanerogers Nov 22, 2022
c613cb1
WIP
kanerogers Nov 23, 2022
76cbc8e
Merge branch 'kanerogers/issue386' into krperf
kanerogers Nov 23, 2022
1be839d
WIP
kanerogers Nov 23, 2022
5e41914
WIP
kanerogers Nov 23, 2022
d1aad8a
WIP
kanerogers Nov 23, 2022
41ad353
WIP
kanerogers Nov 24, 2022
c654b1f
Clear up validation issues
kanerogers Nov 24, 2022
241f8e7
Eradicate GL_EXT_nonuniform
kanerogers Nov 24, 2022
99be4cb
WIP - move towards device local memory
kanerogers Nov 29, 2022
ca5db08
WIP - vertex streaming
kanerogers Nov 29, 2022
467abed
WIP
kanerogers Nov 30, 2022
5f87046
WIP - ffr
kanerogers Dec 1, 2022
732cf3f
WIP - ffr
kanerogers Dec 1, 2022
59cf3a8
WIP
kanerogers Dec 2, 2022
0d748ba
WIP
kanerogers Dec 7, 2022
b36e8fc
WIP
kanerogers Dec 8, 2022
83c62f7
wip
kanerogers Dec 13, 2022
1e678a3
WIP
kanerogers Dec 13, 2022
f66e8b7
Fix up some warnings
kanerogers Dec 13, 2022
2f3d527
Add angular velocity to rigid body
kanerogers Dec 13, 2022
2f723fc
Merge branch 'main' into krperf
kanerogers Jan 19, 2023
4cea0dd
Write to position buffer in stress test
kanerogers Jan 19, 2023
55a4fd1
Only add FFR to Swapchain on Android
kanerogers Jan 19, 2023
5ac8eb1
Split out Android / Desktop ktx2 files
kanerogers Jan 19, 2023
79f14a2
Use correct roughness variable in fragment shader
kanerogers Jan 19, 2023
063a8d3
Begin merging main into krperf
kanerogers Jan 24, 2023
6d95949
Cleanup warnings
kanerogers Jan 24, 2023
8270344
Cleanup Vulkan device creation some more
kanerogers Jan 24, 2023
f398c8d
More cleanly separate FFR code
kanerogers Jan 24, 2023
b59514e
Begin merging fragment shader
kanerogers Jan 24, 2023
ab91a18
Handle edge case where there are no lights in a scene
kanerogers Jan 24, 2023
8c570fe
Update test images
kanerogers Jan 24, 2023
70e5330
Get rid of alphaMaskCutoff in shader
kanerogers Jan 24, 2023
46930fa
Clean up performance timers
kanerogers Jan 24, 2023
8effa09
Clean up fragment shader:
kanerogers Jan 24, 2023
8af035c
Appease clippy
kanerogers Jan 24, 2023
ecab531
Add android specific ktx2 files
kanerogers Jan 24, 2023
89d83e2
Fix broken Android code
kanerogers Jan 24, 2023
f30545a
Merge branch 'krperf' of https://github.com/leetvr/hotham into krperf
kanerogers Jan 24, 2023
77d44b5
Merge branch 'krperf' of https://github.com/leetvr/hotham into krperf
kanerogers Jan 24, 2023
3c9116d
Merge branch 'krperf' of https://github.com/leetvr/hotham into krperf
kanerogers Jan 24, 2023
98f51c7
Merge branch 'krperf' of https://github.com/leetvr/hotham into krperf
kanerogers Jan 24, 2023
ea06d39
Fix unused import on Android
kanerogers Jan 24, 2023
b7dc1e9
Merge branch 'krperf' of https://github.com/leetvr/hotham into krperf
kanerogers Jan 24, 2023
6d27c6d
Spawn more cubes at startup to avoid running out
kanerogers Jan 25, 2023
0c1a7d5
Update render_draw_gui tests
kanerogers Jan 26, 2023
6a67a91
Remove useless test files
kanerogers Jan 27, 2023
5c1b0a6
Further cleanup
kanerogers Jan 27, 2023
6858a47
Appease Clippy
kanerogers Jan 27, 2023
a545847
Appease Clippy... again
kanerogers Jan 27, 2023
f081c1f
Update known good draw_gui
kanerogers Jan 27, 2023
8ff5ee2
Make custom-rendering example compile
kanerogers Jan 27, 2023
a9ecb7d
Clippy once again complains
kanerogers Jan 27, 2023
b240c2f
Apply clippy fix for uninlined_format_args
kanerogers Jan 27, 2023
2748854
Apply cargo fmt
kanerogers Jan 27, 2023
71b4729
Fix format args in more places
kanerogers Jan 27, 2023
5344e75
Try once again to appease the Clippy Demons
kanerogers Jan 27, 2023
5340cfd
Run rustfmt again
kanerogers Jan 27, 2023
aa9c9f9
One more clippy fix..
kanerogers Jan 27, 2023
08882c3
Sort and deduplicate workspace members
rasmusgo Jan 28, 2023
f3f70af
Restore collision events using rapier3d::crossbeam
rasmusgo Jan 28, 2023
d0b93c2
Fix custom rendering example
rasmusgo Jan 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ sponza*

# Don't ignore images from rendering tests
!render_*.jpg

# Ignore compiled shaders
*.spv
23 changes: 21 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"label": "Run a specific test",
"group": {
"kind": "test",
"isDefault": true
"isDefault": false
}
},
{
Expand Down Expand Up @@ -81,6 +81,25 @@
"kind": "test",
"isDefault": false,
}
}
},
{
"type": "cargo",
"command": "run",
"args": [
"--bin",
"hotham_asset_server",
],
"env": {
"RUST_BACKTRACE": "1"
},
"problemMatcher": [
"$rustc"
],
"label": "Run Hotham simple scene on the simulator",
"group": {
"kind": "test",
"isDefault": true,
}
},
]
}
18 changes: 10 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
[workspace]
members = [
"hotham",
"hotham-simulator",
"examples/shared",
"examples/simple-scene",
"examples/complex-scene",
"examples/custom-rendering",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom rendering example was removed by mistake here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And doesn't compile if added...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm, let me fix that up.

"examples/crab-saber",
"benchmarks/stress-test",
"benchmarks/stress-test",
"examples/complex-scene",
"examples/crab-saber",
"examples/custom-rendering",
"examples/shared",
"examples/simple-scene",
"hotham-asset-client",
"hotham-asset-server",
"hotham-simulator",
"hotham",
]

# Make performance critical packages compile with optimizations
Expand Down
15 changes: 7 additions & 8 deletions benchmarks/stress-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use hotham::{
material::Material,
mesh_data::MeshData,
primitive::{calculate_bounding_sphere, Primitive},
vertex::Vertex,
},
systems::{
animation_system, debug::debug_system, grabbing_system, hands_system, physics_system,
Expand Down Expand Up @@ -327,7 +326,7 @@ fn rearrange_models(world: &mut World) {
column += 1;
}

println!("[HOTHAM_STRESS_TEST] There are now {} models", num_models);
println!("[HOTHAM_STRESS_TEST] There are now {num_models} models");
}

fn create_mesh(render_context: &mut RenderContext, world: &mut World) {
Expand Down Expand Up @@ -402,7 +401,10 @@ fn update_mesh(step: usize, mesh: &Mesh, render_context: &mut RenderContext) {
// DON'T DO THIS in a real application!
unsafe {
render_context.resources.index_buffer.overwrite(&indices);
render_context.resources.vertex_buffer.overwrite(&vertices);
render_context
.resources
.position_buffer
.overwrite(&vertices);
}

println!(
Expand All @@ -412,9 +414,6 @@ fn update_mesh(step: usize, mesh: &Mesh, render_context: &mut RenderContext) {
);
}

fn vertex(x: f32, y: f32) -> Vertex {
Vertex {
position: [x, y, -1.0].into(),
..Default::default()
}
fn vertex(x: f32, y: f32) -> Vec3 {
[x, y, -1.0].into()
}
4 changes: 2 additions & 2 deletions examples/crab-saber/src/game_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl GameContext {
let sabers = [Color::Blue, Color::Red].map(|color| add_saber(color, &models, world));

// Spawn cubes
for _ in 0..20 {
for _ in 0..30 {
pre_spawn_cube(world, &models);
}

Expand Down Expand Up @@ -121,7 +121,7 @@ impl GameContext {
red_saber: sabers[1],
songs: Default::default(),
models,
last_spawn_time: Instant::now() - Duration::new(100, 0),
last_spawn_time: Instant::now().checked_sub(Duration::new(100, 0)).unwrap(),
sound_effects: Default::default(),
}
}
Expand Down
5 changes: 1 addition & 4 deletions examples/crab-saber/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ fn init(engine: &mut Engine) -> GameContext {

fn hide(world: &mut World, entity: Entity) {
if world.remove_one::<Visible>(entity).is_err() {
println!(
"[STATE_CHANGE] Tried to make {:?} hidden but it had no Visible component",
entity
)
println!("[STATE_CHANGE] Tried to make {entity:?} hidden but it had no Visible component")
}
}

Expand Down
12 changes: 6 additions & 6 deletions examples/crab-saber/src/systems/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn transition(
.get::<&mut UIPanel>(game_context.main_menu_panel)
.unwrap();

panel.text = format!("Game Over\n{}", message);
panel.text = format!("Game Over\n{message}");
panel.buttons = vec![UIPanelButton::new("Back to main menu")];
}
_ => panic!(
Expand Down Expand Up @@ -249,7 +249,7 @@ fn check_for_hits(
}
}
haptic_context.request_haptic_feedback(1., Handedness::Right);
println!("Hit BLUE: Adding cube to dispose list: {:?}", c);
println!("Hit BLUE: Adding cube to dispose list: {c:?}");
cubes_to_dispose.push(*c);
}
}
Expand All @@ -274,7 +274,7 @@ fn check_for_hits(
}
}
haptic_context.request_haptic_feedback(1., Handedness::Left);
println!("Hit RED: Adding cube to dispose list: {:?}", c);
println!("Hit RED: Adding cube to dispose list: {c:?}");
cubes_to_dispose.push(*c);
}
}
Expand All @@ -290,7 +290,7 @@ fn check_for_hits(
if e.get::<&Cube>().is_some() {
game_context.current_score -= 1;
pending_sound_effects.push((*c, "Miss"));
println!("MISSED: Adding cube to dispose list: {:?}", c);
println!("MISSED: Adding cube to dispose list: {c:?}");
cubes_to_dispose.push(*c);
}
}
Expand All @@ -306,7 +306,7 @@ fn is_cube(e: hotham::hecs::EntityRef) -> bool {

fn dispose_of_cubes(cubes_to_dispose: Vec<Entity>, world: &mut World) {
for e in cubes_to_dispose.into_iter() {
println!("Removing visibilty of cube: {:?}", e);
println!("Removing visibilty of cube: {e:?}");
world.remove_one::<Visible>(e).unwrap();
world.get::<&mut RigidBody>(e).unwrap().linear_velocity = glam::Vec3::ZERO;
}
Expand Down Expand Up @@ -712,7 +712,7 @@ mod tests {
.get::<&UIPanel>(game_context.score_panel)
.unwrap()
.text,
format!("Score: {}", score)
format!("Score: {score}")
);
}
}
11 changes: 8 additions & 3 deletions examples/custom-rendering/src/custom_render_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use hotham::{
anyhow::Result,
ash,
contexts::{render_context::create_shader, VulkanContext},
glam::{Affine3A, Mat4, Vec4},
glam::{Affine3A, Mat4, Vec3, Vec4},
rendering::{buffer::Buffer, primitive::Primitive, vertex::Vertex},
vk,
vk_shader_macros::include_glsl,
Expand Down Expand Up @@ -158,12 +158,17 @@ fn create_quadrics_pipeline(
let stages = [vertex_stage, fragment_stage];

// Vertex input state
let vertex_binding_description = vk::VertexInputBindingDescription::builder()
let position_binding_description = vk::VertexInputBindingDescription::builder()
.binding(0)
.stride(size_of::<Vec3>() as _)
.input_rate(vk::VertexInputRate::VERTEX)
.build();
let vertex_binding_description = vk::VertexInputBindingDescription::builder()
.binding(1)
.stride(size_of::<Vertex>() as _)
.input_rate(vk::VertexInputRate::VERTEX)
.build();
let vertex_binding_descriptions = [vertex_binding_description];
let vertex_binding_descriptions = [position_binding_description, vertex_binding_description];
let vertex_attribute_descriptions = Vertex::attribute_descriptions();

let vertex_input_state = vk::PipelineVertexInputStateCreateInfo::builder()
Expand Down
40 changes: 16 additions & 24 deletions examples/custom-rendering/src/shaders/quadric.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#version 460

#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require
#extension GL_EXT_shader_explicit_arithmetic_types_float16 : require
#extension GL_EXT_shader_16bit_storage : require

#include "../../../../hotham/src/shaders/common.glsl"
#include "../../../../hotham/src/shaders/lights.glsl"
#include "../../../../hotham/src/shaders/brdf.glsl"
Expand Down Expand Up @@ -77,8 +82,8 @@ void main() {
gl_FragDepth = v_clip_coord.z / v_clip_coord.w;

// Set globals that are read inside functions for lighting etc.
p = hitPoint.xyz;
v = normalize(sceneData.cameraPosition[gl_ViewIndex].xyz - p);
pos = hitPoint.xyz;
v = normalize(sceneData.cameraPosition[gl_ViewIndex].xyz - pos);

// Compute normal from gradient of surface quadric
n = normalize((d.surfaceQ * hitPoint).xyz);
Expand All @@ -89,62 +94,49 @@ void main() {
// Unpack the material parameters
materialFlags = material.flagsAndBaseTextureID & 0xFFFF;
baseTextureID = material.flagsAndBaseTextureID >> 16;
metallicRoughnessAlphaMaskCutoff = unpackUnorm4x8(
material.packedMetallicRoughnessFactorAlphaMaskCutoff).xyz;

// Determine the base color
vec4 baseColor = unpackUnorm4x8(material.packedBaseColor);

if ((materialFlags & HAS_BASE_COLOR_TEXTURE) != 0) {
baseColor *= texture(textures[baseTextureID], uv);
}
f16vec3 baseColor = V16(unpackUnorm4x8(material.packedBaseColor));

// Handle transparency
if (metallicRoughnessAlphaMaskCutoff.z > 0.0f) {
if (baseColor.a < metallicRoughnessAlphaMaskCutoff.z) {
// TODO: Apparently Adreno GPUs don't like discarding.
discard;
}
if ((materialFlags & MATERIAL_FLAG_HAS_BASE_COLOR_TEXTURE) != 0) {
baseColor *= V16(texture(textures[baseTextureID], uv));
}

// Choose the correct workflow for this material
if ((materialFlags & PBR_WORKFLOW_UNLIT) == 0) {
outColor.rgb = getPBRMetallicRoughnessColor(baseColor);
} else {
outColor = baseColor;
outColor.rgb = tonemap(baseColor);
}

// Finally, tonemap the color.
outColor.rgb = tonemap(outColor.rgb);

// Debugging
// Shader inputs debug visualization
if (sceneData.params.z > 0.0) {
int index = int(sceneData.params.z);
switch (index) {
// Base Color Texture
case 1:
outColor.rgba = baseColor;
outColor.rgb = baseColor;
break;
// Normal
case 2:
outColor.rgb = n * 0.5 + 0.5;
break;
// Occlusion
case 3:
outColor.rgb = ((materialFlags & TEXTURE_FLAG_HAS_AO_TEXTURE) != 0) ? ERROR_MAGENTA.rgb : texture(textures[baseTextureID + 1], uv).rrr;
outColor.rgb = ((materialFlags & MATERIAL_FLAG_HAS_AO_TEXTURE) != 0) ? ERROR_MAGENTA.rgb : texture(textures[baseTextureID + 1], uv).rrr;
break;
// Emission
case 4:
outColor.rgb = ((materialFlags & TEXTURE_FLAG_HAS_EMISSION_TEXTURE) != 0) ? ERROR_MAGENTA.rgb : texture(textures[baseTextureID + 3], uv).rgb;
outColor.rgb = ((materialFlags & MATERIAL_FLAG_HAS_EMISSION_TEXTURE) != 0) ? ERROR_MAGENTA.rgb : texture(textures[baseTextureID + 3], uv).rgb;
break;
// Roughness
case 5:
outColor.rgb = ((materialFlags & HAS_METALLIC_ROUGHNESS_TEXTURE) != 0) ? ERROR_MAGENTA.rgb : texture(textures[baseTextureID + 1], uv).ggg;
outColor.rgb = ((materialFlags & MATERIAL_FLAG_HAS_METALLIC_ROUGHNESS_TEXTURE) != 0) ? ERROR_MAGENTA.rgb : texture(textures[baseTextureID + 1], uv).ggg;
break;
// Metallic
case 6:
outColor.rgb = ((materialFlags & HAS_METALLIC_ROUGHNESS_TEXTURE) != 0) ? ERROR_MAGENTA.rgb : texture(textures[baseTextureID + 1], uv).bbb;
outColor.rgb = ((materialFlags & MATERIAL_FLAG_HAS_METALLIC_ROUGHNESS_TEXTURE) != 0) ? ERROR_MAGENTA.rgb : texture(textures[baseTextureID + 1], uv).bbb;
break;
}
outColor = outColor;
Expand Down
7 changes: 5 additions & 2 deletions examples/simple-scene/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ fn init(engine: &mut Engine) -> Result<(), hotham::HothamError> {
include_bytes!("../../../test_assets/left_hand.glb"),
include_bytes!("../../../test_assets/right_hand.glb"),
];
let models =
asset_importer::load_models_from_glb(&glb_buffers, vulkan_context, render_context)?;
add_hand(&models, Handedness::Left, world);
add_hand(&models, Handedness::Right, world);

#[cfg(target_os = "android")]
glb_buffers.push(include_bytes!(
Expand All @@ -72,8 +76,7 @@ fn init(engine: &mut Engine) -> Result<(), hotham::HothamError> {
let models =
asset_importer::load_models_from_glb(&glb_buffers, vulkan_context, render_context)?;
add_helmet(&models, world);
add_hand(&models, Handedness::Left, world);
add_hand(&models, Handedness::Right, world);
add_model_to_world("Cube", &models, world, None);

Ok(())
}
Expand Down
16 changes: 16 additions & 0 deletions hotham-asset-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
edition = "2021"
name = "hotham-asset-client"
version = "0.1.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0"
futures-util = {version = "0.3.11", default-features = false}
quinn = {version = "0.8.5", features = ["tls-rustls"]}
rustls = {version = "0.20.3", features = ["dangerous_configuration", "quic"]}
tokio = {version = "1.0.1", default-features = false, features = ["sync"]}

[dev-dependencies]
tokio = {version = "1.0.1", default-features = false, features = ["rt"]}
Loading