more barriers
This commit is contained in:
parent
7acda4d1fb
commit
555244b221
|
|
@ -479,6 +479,16 @@ impl<T: IsDrawData> Command for Draw<T> {
|
||||||
fn apply(self, _recorder: &mut CommandRecorder) {}
|
fn apply(self, _recorder: &mut CommandRecorder) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct PipelineBarrier;
|
||||||
|
|
||||||
|
impl Command for PipelineBarrier {
|
||||||
|
fn side_effects(&self, _map: SideEffectMap) {}
|
||||||
|
|
||||||
|
fn apply(self, _recorder: &mut CommandRecorder) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Command: Sized {
|
pub trait Command: Sized {
|
||||||
fn side_effects(&self, map: SideEffectMap);
|
fn side_effects(&self, map: SideEffectMap);
|
||||||
fn apply(self, recorder: &mut CommandRecorder);
|
fn apply(self, recorder: &mut CommandRecorder);
|
||||||
|
|
@ -498,14 +508,20 @@ impl IsDrawData for DrawData {}
|
||||||
impl IsDrawData for DrawIndexedData {}
|
impl IsDrawData for DrawIndexedData {}
|
||||||
impl IsDrawData for DrawIndirectData {
|
impl IsDrawData for DrawIndirectData {
|
||||||
fn side_effects(&self, mut map: SideEffectMap) {
|
fn side_effects(&self, mut map: SideEffectMap) {
|
||||||
self.indirect_buffer
|
self.indirect_buffer.side_effect(
|
||||||
.side_effect(map.reborrow(), vk::AccessFlags2::INDIRECT_COMMAND_READ);
|
map.reborrow(),
|
||||||
|
vk::AccessFlags2::INDIRECT_COMMAND_READ,
|
||||||
|
None,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl IsDrawData for DrawIndexedIndirectData {
|
impl IsDrawData for DrawIndexedIndirectData {
|
||||||
fn side_effects(&self, mut map: SideEffectMap) {
|
fn side_effects(&self, mut map: SideEffectMap) {
|
||||||
self.indirect_buffer
|
self.indirect_buffer.side_effect(
|
||||||
.side_effect(map.reborrow(), vk::AccessFlags2::INDIRECT_COMMAND_READ);
|
map.reborrow(),
|
||||||
|
vk::AccessFlags2::INDIRECT_COMMAND_READ,
|
||||||
|
None,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, BTreeSet, HashMap},
|
collections::{BTreeMap, BTreeSet},
|
||||||
mem::{MaybeUninit, size_of},
|
mem::{MaybeUninit, size_of},
|
||||||
ptr::NonNull,
|
ptr::NonNull,
|
||||||
};
|
};
|
||||||
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
images::ImageDesc,
|
images::ImageDesc,
|
||||||
render_graph::{
|
render_graph::{
|
||||||
commands::{Command, InsideRenderPass, OutsideRenderPass},
|
commands::{Command, InsideRenderPass, OutsideRenderPass},
|
||||||
resources::{ResourceAccess, ResourceId, TextureRegion, Write, access_flag_is_read},
|
resources::{ResourceAccess, ResourceId, TextureRegion, Write},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -180,7 +180,7 @@ impl CommandList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_side_effects(&mut self) {
|
fn fold_side_effects(&self) -> Vec<(u32, super::commands::PipelineBarrier)> {
|
||||||
// Buffer accesses can be granularly tracked by their offset and size;
|
// Buffer accesses can be granularly tracked by their offset and size;
|
||||||
// Image accesses are tracked by their subresource range, which means all regions of the same mip/array layer are considered the same subresource for the purposes of ImageMemoryBarriers
|
// Image accesses are tracked by their subresource range, which means all regions of the same mip/array layer are considered the same subresource for the purposes of ImageMemoryBarriers
|
||||||
|
|
||||||
|
|
@ -284,11 +284,22 @@ impl CommandList {
|
||||||
for barrier in barriers {
|
for barrier in barriers {
|
||||||
// stuff
|
// stuff
|
||||||
}
|
}
|
||||||
|
|
||||||
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn record_commands(&self, recorder: &mut CommandRecorder) {
|
fn record_commands(&self, recorder: &mut CommandRecorder) {
|
||||||
let mut cursor = 0;
|
let mut cursor = 0;
|
||||||
|
let mut barriers = self.fold_side_effects();
|
||||||
|
let mut command_index = 0;
|
||||||
|
|
||||||
while cursor < self.command_bytes.len() {
|
while cursor < self.command_bytes.len() {
|
||||||
|
barriers
|
||||||
|
.drain(barriers.partition_point(|(idx, _)| *idx <= command_index)..)
|
||||||
|
.for_each(|(_, barrier)| {
|
||||||
|
barrier.apply(recorder);
|
||||||
|
});
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let meta_ptr = self
|
let meta_ptr = self
|
||||||
.command_bytes
|
.command_bytes
|
||||||
|
|
@ -299,6 +310,8 @@ impl CommandList {
|
||||||
let command_ptr = meta_ptr.add(1).cast::<()>().cast_mut();
|
let command_ptr = meta_ptr.add(1).cast::<()>().cast_mut();
|
||||||
(meta.apply_command)(recorder, NonNull::new_unchecked(command_ptr), &mut cursor);
|
(meta.apply_command)(recorder, NonNull::new_unchecked(command_ptr), &mut cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
command_index += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,7 @@ use std::ops::Deref;
|
||||||
|
|
||||||
use ash::vk;
|
use ash::vk;
|
||||||
|
|
||||||
use crate::{
|
use crate::{images::MipRange, render_graph::recorder::SideEffectMap};
|
||||||
images::{Extent, MipRange, Offset},
|
|
||||||
render_graph::recorder::SideEffectMap,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub trait Resource: Sized {
|
pub trait Resource: Sized {
|
||||||
fn id(&self) -> ResourceId;
|
fn id(&self) -> ResourceId;
|
||||||
|
|
@ -196,6 +193,26 @@ mod impls {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl Resource for TextureView {
|
||||||
|
fn id(&self) -> ResourceId {
|
||||||
|
self.texture.id()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn side_effect(
|
||||||
|
&self,
|
||||||
|
mut map: SideEffectMap,
|
||||||
|
access: vk::AccessFlags2,
|
||||||
|
layout: Option<vk::ImageLayout>,
|
||||||
|
) {
|
||||||
|
map.insert(
|
||||||
|
self.id(),
|
||||||
|
ResourceAccess {
|
||||||
|
range: (self.range, layout.unwrap_or_default()).into(),
|
||||||
|
access,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Resource> Resource for Read<T> {
|
impl<T: Resource> Resource for Read<T> {
|
||||||
fn id(&self) -> ResourceId {
|
fn id(&self) -> ResourceId {
|
||||||
|
|
@ -513,6 +530,13 @@ pub struct TextureRegions {
|
||||||
pub ranges: Vec<TextureRange>,
|
pub ranges: Vec<TextureRange>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct TextureView {
|
||||||
|
pub texture: Texture,
|
||||||
|
pub format: vk::Format,
|
||||||
|
pub mapping: vk::ComponentMapping,
|
||||||
|
pub range: TextureRange,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Read<T>(pub T);
|
pub struct Read<T>(pub T);
|
||||||
pub struct Write<T>(pub T);
|
pub struct Write<T>(pub T);
|
||||||
pub struct ReadWrite<T>(pub T);
|
pub struct ReadWrite<T>(pub T);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue