Remove RendetTarget from recorder due to lifetimes

This commit is contained in:
hodasemi 2023-01-21 09:34:24 +01:00
parent 419c044413
commit dca9ab20be
2 changed files with 15 additions and 28 deletions

View file

@ -75,7 +75,7 @@ pub struct CommandBuffer {
#[derive(Debug)]
pub struct CommandBufferRecorder<'a> {
device: Arc<Device>,
render_target: Option<&'a RenderTarget>,
sub_pass: u32,
pipeline: Option<Arc<Pipeline>>,
calls: Arc<AtomicUsize>,
@ -118,7 +118,7 @@ impl CommandBuffer {
Ok(CommandBufferRecorder {
device: self.device.clone(),
render_target: None,
sub_pass: 0,
pipeline: None,
calls: self.calls.clone(),
@ -321,22 +321,16 @@ impl<'a> CommandBufferRecorder<'a> {
}
pub fn begin_render_pass(
&self,
&mut self,
renderpass_begin_info: VkRenderPassBeginInfo,
subpass_contents: VkSubpassContents,
) {
self.sub_pass = 0;
self.device
.cmd_begin_render_pass(self.buffer, &renderpass_begin_info, subpass_contents);
}
pub(crate) fn set_render_target(&'a mut self, render_target: &'a RenderTarget) {
self.render_target = Some(render_target);
}
pub(crate) fn clear_render_target(&'a mut self) {
self.render_target = None;
}
pub fn begin_render_pass_full(
&mut self,
render_pass: &Arc<RenderPass>,
@ -347,6 +341,8 @@ impl<'a> CommandBufferRecorder<'a> {
self.handles_lock.push(render_pass.clone());
self.handles_lock.push(framebuffer.clone());
self.sub_pass = 0;
let render_pass_begin_info = VkRenderPassBeginInfo::new(
render_pass.vk_handle(),
framebuffer.vk_handle(),
@ -364,7 +360,8 @@ impl<'a> CommandBufferRecorder<'a> {
.cmd_begin_render_pass(self.buffer, &render_pass_begin_info, subpass_contents);
}
pub fn next_subpass(&self, subpass_contents: VkSubpassContents) {
pub fn next_subpass(&mut self, subpass_contents: VkSubpassContents) {
self.sub_pass += 1;
self.device.cmd_next_subpass(self.buffer, subpass_contents);
}
@ -377,11 +374,7 @@ impl<'a> CommandBufferRecorder<'a> {
match pipeline.pipeline_type() {
PipelineType::Graphics => {
if cfg!(debug_assertions) {
if let Some(render_target) = &self.render_target {
assert_eq!(render_target.subpass_index(), pipeline.sub_pass());
}
}
debug_assert_eq!(self.sub_pass, pipeline.sub_pass());
self.device.cmd_bind_pipeline(
self.buffer,

View file

@ -271,10 +271,6 @@ impl RenderTarget {
self.extent.height
}
pub(crate) fn subpass_index(&self) -> u32 {
self.current_subpass.load(SeqCst)
}
pub fn inheritance_info(&self) -> VkCommandBufferInheritanceInfo {
CommandBuffer::inheritance_info(
Some(&self.render_pass),
@ -284,9 +280,9 @@ impl RenderTarget {
)
}
pub fn begin<'a>(
&'a self,
buffer_recorder: &'a mut CommandBufferRecorder<'a>,
pub fn begin(
&self,
buffer_recorder: &mut CommandBufferRecorder<'_>,
subpass_content: VkSubpassContents,
framebuffer_index: usize,
) {
@ -301,7 +297,6 @@ impl RenderTarget {
);
buffer_recorder.begin_render_pass(renderpass_begin, subpass_content);
buffer_recorder.set_render_target(self);
self.framebuffer_index.store(framebuffer_index, SeqCst);
self.current_subpass.store(0, SeqCst);
@ -309,16 +304,15 @@ impl RenderTarget {
pub fn next_subpass(
&self,
buffer_recorder: &CommandBufferRecorder<'_>,
buffer_recorder: &mut CommandBufferRecorder<'_>,
subpass_content: VkSubpassContents,
) {
buffer_recorder.next_subpass(subpass_content);
self.current_subpass.fetch_add(1, SeqCst);
}
pub fn end<'a>(&self, buffer_recorder: &'a mut CommandBufferRecorder<'a>) {
pub fn end(&self, buffer_recorder: &mut CommandBufferRecorder<'_>) {
buffer_recorder.end_render_pass();
buffer_recorder.clear_render_target();
}
}