Skip to content

Commit

Permalink
Lehel patches (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
aedm authored Sep 23, 2024
1 parent 7120aba commit dfd5e7f
Show file tree
Hide file tree
Showing 8 changed files with 494 additions and 454 deletions.
2 changes: 1 addition & 1 deletion crates/bitang/src/render/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Camera {
globals.pixel_size = Vec2::new(1.0 / viewport_size[0], 1.0 / viewport_size[1]);
globals.aspect_ratio = viewport_size[0] / viewport_size[1];
globals.field_of_view = self.field_of_view.as_float();
globals.z_near = 0.1;
globals.z_near = 0.05;

// Vulkan uses a [0,1] depth range, ideal for infinite far plane
globals.projection_from_camera = Mat4::perspective_infinite_lh(
Expand Down
3 changes: 0 additions & 3 deletions crates/bitang/src/render/chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ impl Chart {
genmips.execute(context)?;
}
}
if let ChartStep::Draw(draw) = step {
draw.render(context, &self.camera)?;
}
}
Ok(())
}
Expand Down
14 changes: 14 additions & 0 deletions crates/bitang/src/render/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ impl Draw {
contents: SubpassContents::Inline,
..Default::default()
};

// TODO: implement debug flag
// context
// .command_builder
// .begin_debug_utils_label(DebugUtilsLabel {
// label_name: self.id.clone(),
// ..Default::default()
// })?;

context
.command_builder
.begin_render_pass(render_pass_begin_info, subpass_begin_info)?
Expand All @@ -124,6 +133,11 @@ impl Draw {
.command_builder
.end_render_pass(Default::default())?;

// TODO: implement debug flag
// unsafe {
// context.command_builder.end_debug_utils_label()?;
// }

// Propagate error
render_result?;
}
Expand Down
12 changes: 8 additions & 4 deletions crates/bitang/src/render/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ impl MaterialPass {
let depth_stencil_state = if subpass.subpass_desc().depth_stencil_attachment.is_none() {
None
} else {
let compare_op = if props.depth_test { CompareOp::Less } else { CompareOp::Always };
let compare_op =
if props.depth_test { CompareOp::LessOrEqual } else { CompareOp::Always };
Some(DepthStencilState {
depth: Some(DepthState {
compare_op,
Expand Down Expand Up @@ -180,9 +181,12 @@ impl MaterialPass {
self.fragment_shader.bind(context, pipeline_layout)?;
match &mesh.index_buffer {
None => {
context
.command_builder
.draw(mesh.vertex_buffer.len() as u32, instance_count, 0, 0)?;
context.command_builder.draw(
mesh.vertex_buffer.len() as u32,
instance_count,
0,
0,
)?;
}
Some(index_buffer) => {
context
Expand Down
44 changes: 28 additions & 16 deletions crates/bitang/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ pub struct Mesh {
}

impl Mesh {
pub fn try_new(context: &Arc<VulkanContext>, vertices: Vec<Vertex3>, indices: Option<Vec<u32>>) -> Result<Mesh> {
pub fn try_new(
context: &Arc<VulkanContext>,
vertices: Vec<Vertex3>,
indices: Option<Vec<u32>>,
) -> Result<Mesh> {
let vertex_buffer = Buffer::from_iter(
context.memory_allocator.clone(),
BufferCreateInfo {
Expand All @@ -29,20 +33,28 @@ impl Mesh {
vertices,
)?;
let index_buffer = if let Some(indices) = indices {
Some(Buffer::from_iter(
context.memory_allocator.clone(),
BufferCreateInfo {
usage: BufferUsage::INDEX_BUFFER,
..Default::default()
},
AllocationCreateInfo {
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
indices,
)?.into())
} else { None };
Ok(Mesh { vertex_buffer, index_buffer })
Some(
Buffer::from_iter(
context.memory_allocator.clone(),
BufferCreateInfo {
usage: BufferUsage::INDEX_BUFFER,
..Default::default()
},
AllocationCreateInfo {
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
indices,
)?
.into(),
)
} else {
None
};
Ok(Mesh {
vertex_buffer,
index_buffer,
})
}
}
14 changes: 13 additions & 1 deletion crates/bitang/src/tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ use crate::render::SCREEN_COLOR_FORMAT;
use crate::tool::runners::frame_dump_runner::FrameDumpRunner;
use crate::tool::runners::window_runner::WindowRunner;
use anyhow::Result;
use std::default::Default;
use std::sync::Arc;
use vulkano::command_buffer::allocator::StandardCommandBufferAllocator;
use vulkano::command_buffer::{AutoCommandBufferBuilder, PrimaryAutoCommandBuffer};
use vulkano::descriptor_set::allocator::StandardDescriptorSetAllocator;
use vulkano::device::{Device, Queue};
use vulkano::format::Format;
use vulkano::instance::{InstanceCreateInfo, InstanceExtensions};
use vulkano::memory::allocator::StandardMemoryAllocator;
use vulkano::pipeline::graphics::viewport::Viewport;
use vulkano_util::context::{VulkanoConfig, VulkanoContext};
Expand Down Expand Up @@ -73,7 +75,17 @@ pub struct RenderContext<'a> {
}

pub fn run_app() -> Result<()> {
let vulkano_context = Arc::new(VulkanoContext::new(VulkanoConfig::default()));
let vulkano_context = Arc::new(VulkanoContext::new(VulkanoConfig {
instance_create_info: InstanceCreateInfo {
enabled_extensions: InstanceExtensions {
// TODO: implement debug flag
// ext_debug_utils: true,
..InstanceExtensions::empty()
},
..InstanceCreateInfo::default()
},
..Default::default()
}));

let command_buffer_allocator =
StandardCommandBufferAllocator::new(vulkano_context.device().clone(), Default::default());
Expand Down
3 changes: 2 additions & 1 deletion crates/bitang/src/tool/runners/frame_dump_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl FrameDumpRunner {
let runtime = tokio::runtime::Runtime::new().unwrap();
let job_count: Arc<AtomicUsize> = Arc::new(AtomicUsize::new(0));
let cpu_count = num_cpus::get();
info!("Rendering demo using {cpu_count} CPUs");
let project_length = self.app.app_state.project.as_ref().unwrap().length;
let mut frame_count = 0;

Expand All @@ -87,7 +88,7 @@ impl FrameDumpRunner {
let content = self.get_frame_content();

// If we're rendering too fast, wait a bit
while job_count.load(Ordering::Relaxed) >= cpu_count + 10 {
while job_count.load(Ordering::Relaxed) >= cpu_count + 20 {
sleep(Duration::from_millis(1));
}

Expand Down
Loading

0 comments on commit dfd5e7f

Please sign in to comment.