Skip to content

Commit

Permalink
Update to some demos/examples
Browse files Browse the repository at this point in the history
  • Loading branch information
aclysma committed Apr 11, 2024
1 parent 295c336 commit 5640028
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
12 changes: 6 additions & 6 deletions demo-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ pub fn update_loop(
// the uniform instead of the vertex buffer. Buffers also need to be immutable while
// processed, so we need one per swapchain image
//
let mut command_pools = Vec::with_capacity(swapchain_helper.image_count());
let mut command_buffers = Vec::with_capacity(swapchain_helper.image_count());
let mut vertex_buffers = Vec::with_capacity(swapchain_helper.image_count());
let mut uniform_buffers = Vec::with_capacity(swapchain_helper.image_count());
let mut command_pools = Vec::with_capacity(swapchain_helper.rotating_frame_count());
let mut command_buffers = Vec::with_capacity(swapchain_helper.rotating_frame_count());
let mut vertex_buffers = Vec::with_capacity(swapchain_helper.rotating_frame_count());
let mut uniform_buffers = Vec::with_capacity(swapchain_helper.rotating_frame_count());

for _ in 0..swapchain_helper.image_count() {
for _ in 0..swapchain_helper.rotating_frame_count() {
log::trace!("Creating command pool");
let mut command_pool =
graphics_queue.create_command_pool(&RafxCommandPoolDef { transient: true })?;
Expand Down Expand Up @@ -302,7 +302,7 @@ pub fn update_loop(

// Initialize them all at once here.. this can be done per-frame as well.
log::trace!("Set up descriptor sets");
for i in 0..swapchain_helper.image_count() {
for i in 0..swapchain_helper.rotating_frame_count() {
descriptor_set_array.update_descriptor_set(&[
RafxDescriptorUpdate {
array_index: i as u32,
Expand Down
4 changes: 4 additions & 0 deletions rafx-api/src/extra/swapchain_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ impl RafxSwapchainHelper {
self.color_space
}

pub fn rotating_frame_count(&self) -> usize {
crate::MAX_FRAMES_IN_FLIGHT + 1
}

pub fn swapchain_def(&self) -> &RafxSwapchainDef {
&self.swapchain_def
}
Expand Down
12 changes: 6 additions & 6 deletions rafx/examples/api_triangle/api_triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ fn run() -> RafxResult<()> {
// the uniform instead of the vertex buffer. Buffers also need to be immutable while
// processed, so we need one per swapchain image
//
let mut command_pools = Vec::with_capacity(swapchain_helper.image_count());
let mut command_buffers = Vec::with_capacity(swapchain_helper.image_count());
let mut vertex_buffers = Vec::with_capacity(swapchain_helper.image_count());
let mut uniform_buffers = Vec::with_capacity(swapchain_helper.image_count());
let mut command_pools = Vec::with_capacity(swapchain_helper.rotating_frame_count());
let mut command_buffers = Vec::with_capacity(swapchain_helper.rotating_frame_count());
let mut vertex_buffers = Vec::with_capacity(swapchain_helper.rotating_frame_count());
let mut uniform_buffers = Vec::with_capacity(swapchain_helper.rotating_frame_count());

for _ in 0..swapchain_helper.image_count() {
for _ in 0..swapchain_helper.rotating_frame_count() {
let mut command_pool =
graphics_queue.create_command_pool(&RafxCommandPoolDef { transient: true })?;

Expand Down Expand Up @@ -238,7 +238,7 @@ fn run() -> RafxResult<()> {
})?;

// Initialize them all at once here.. this can be done per-frame as well.
for i in 0..swapchain_helper.image_count() {
for i in 0..swapchain_helper.rotating_frame_count() {
descriptor_set_array.update_descriptor_set(&[RafxDescriptorUpdate {
array_index: i as u32,
descriptor_key: RafxDescriptorKey::Name("color"),
Expand Down

0 comments on commit 5640028

Please sign in to comment.