Browse Source

rebuild command buffer each frame

master
Alison Watson 11 months ago
parent
commit
2440098441
  1. 126
      fw/render.rs

126
fw/render.rs

@ -658,74 +658,6 @@ impl StaticData {
let cmd_bufs =
unsafe { self.dev.allocate_command_buffers(&create_info)? };
let clear_values = [
vk::ClearValue {
color: vk::ClearColorValue { float32: [0.101, 0.078, 0.113, 1.0] },
},
vk::ClearValue {
depth_stencil: vk::ClearDepthStencilValue {
depth: 1.0,
stencil: 0,
},
},
];
for (&buf, &framebuffer, &set) in crate::types::iter::ClosedZip((
cmd_bufs.iter(),
framebuffers.iter(),
desc_sets.iter(),
)) {
let begin_info = vk::RenderPassBeginInfo {
render_pass,
framebuffer,
render_area: vk::Rect2D {
extent: sc_extent,
..Default::default()
},
clear_value_count: clear_values.len().cast(),
p_clear_values: clear_values.as_ptr(),
..Default::default()
};
unsafe {
self.dev.begin_command_buffer(
buf,
&vk::CommandBufferBeginInfo::default(),
)?;
self.dev.cmd_begin_render_pass(
buf,
&begin_info,
vk::SubpassContents::INLINE,
);
self.dev.cmd_bind_pipeline(
buf,
vk::PipelineBindPoint::GRAPHICS,
pipeline,
);
self.dev.cmd_bind_descriptor_sets(
buf,
vk::PipelineBindPoint::GRAPHICS,
self.pipe_layout,
0,
&[set],
&[],
);
/*
for which in sc_info.model.model().keys() {
sc_info.model.draw(buf, which).unwrap();
}
*/
self.dev.cmd_end_render_pass(buf);
self.dev.end_command_buffer(buf)?;
}
}
Ok(SwapchainData {
cmd_bufs,
@ -818,6 +750,18 @@ impl Renderer {
unsafe fn draw_frame_raw(&mut self) -> Result<(), vk::Result> {
use crate::math::*;
const CLEAR_VALUES: [vk::ClearValue; 2] = [
vk::ClearValue {
color: vk::ClearColorValue { float32: [0.101, 0.078, 0.113, 1.0] },
},
vk::ClearValue {
depth_stencil: vk::ClearDepthStencilValue {
depth: 1.0,
stencil: 0,
},
},
];
// synchronize and set up this fence
let sem_img = self.st.sem_img[self.cur_c_frame];
let sem_ren = self.st.sem_ren[self.cur_c_frame];
@ -892,8 +836,54 @@ impl Renderer {
*/
// write command buffer
let framebuffer = self.sc.framebuffers[image_index];
let desc_set = self.sc.desc_sets[image_index];
let cmd_buf = self.sc.cmd_bufs[image_index];
let begin_info = vk::RenderPassBeginInfo {
framebuffer,
render_pass: self.sc.render_pass,
render_area: vk::Rect2D {
extent: self.sc.sc_extent,
..Default::default()
},
clear_value_count: CLEAR_VALUES.len().cast(),
p_clear_values: CLEAR_VALUES.as_ptr(),
..Default::default()
};
unsafe {
self.st.dev.begin_command_buffer(
cmd_buf,
&vk::CommandBufferBeginInfo::default(),
)?;
self.st.dev.cmd_begin_render_pass(
cmd_buf,
&begin_info,
vk::SubpassContents::INLINE,
);
self.st.dev.cmd_bind_pipeline(
cmd_buf,
vk::PipelineBindPoint::GRAPHICS,
self.sc.pipeline,
);
self.st.dev.cmd_bind_descriptor_sets(
cmd_buf,
vk::PipelineBindPoint::GRAPHICS,
self.st.pipe_layout,
0,
&[desc_set],
&[],
);
self.st.dev.cmd_end_render_pass(cmd_buf);
self.st.dev.end_command_buffer(cmd_buf)?;
}
// submit
let wait_stg = vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT;

Loading…
Cancel
Save