mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-22 14:56:42 +00:00
Change FramebufferAbstract trait to be faster
This commit is contained in:
parent
b1abbbd7cd
commit
572ace793a
@ -613,14 +613,14 @@ impl<P> SyncCommandBufferBuilder<P> {
|
||||
where F: FramebufferAbstract + Send + Sync + 'static
|
||||
{
|
||||
fn image(&self, num: usize) -> &ImageAccess {
|
||||
self.0.attachments()[num].parent() // TODO: slow
|
||||
self.0.attached_image_view(num).unwrap().parent()
|
||||
}
|
||||
}
|
||||
Box::new(Fin(self.framebuffer))
|
||||
}
|
||||
|
||||
fn image(&self, num: usize) -> &ImageAccess {
|
||||
self.framebuffer.attachments()[num].parent() // TODO: slow
|
||||
self.framebuffer.attached_image_view(num).unwrap().parent()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
// at your option. All files in the project carrying such
|
||||
// notice may not be copied, modified, or distributed except
|
||||
// according to those terms.
|
||||
|
||||
|
||||
use SafeDeref;
|
||||
use image::ImageViewAccess;
|
||||
use std::sync::Arc;
|
||||
@ -16,8 +16,9 @@ use std::sync::Arc;
|
||||
/// A list of attachments.
|
||||
// TODO: rework this trait
|
||||
pub unsafe trait AttachmentsList {
|
||||
// TODO: meh for API
|
||||
fn as_image_view_accesses(&self) -> Vec<&ImageViewAccess>;
|
||||
fn num_attachments(&self) -> usize;
|
||||
|
||||
fn as_image_view_access(&self, index: usize) -> Option<&ImageViewAccess>;
|
||||
}
|
||||
|
||||
unsafe impl<T> AttachmentsList for T
|
||||
@ -25,22 +26,37 @@ unsafe impl<T> AttachmentsList for T
|
||||
T::Target: AttachmentsList
|
||||
{
|
||||
#[inline]
|
||||
fn as_image_view_accesses(&self) -> Vec<&ImageViewAccess> {
|
||||
(**self).as_image_view_accesses()
|
||||
fn num_attachments(&self) -> usize {
|
||||
(**self).num_attachments()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn as_image_view_access(&self, index: usize) -> Option<&ImageViewAccess> {
|
||||
(**self).as_image_view_access(index)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl AttachmentsList for () {
|
||||
#[inline]
|
||||
fn as_image_view_accesses(&self) -> Vec<&ImageViewAccess> {
|
||||
vec![]
|
||||
fn num_attachments(&self) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn as_image_view_access(&self, _: usize) -> Option<&ImageViewAccess> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl AttachmentsList for Vec<Arc<ImageViewAccess + Send + Sync>> {
|
||||
#[inline]
|
||||
fn as_image_view_accesses(&self) -> Vec<&ImageViewAccess> {
|
||||
self.iter().map(|p| &**p as &ImageViewAccess).collect()
|
||||
fn num_attachments(&self) -> usize {
|
||||
self.len()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn as_image_view_access(&self, index: usize) -> Option<&ImageViewAccess> {
|
||||
self.get(index).map(|v| &**v as &_)
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,9 +65,16 @@ unsafe impl<A, B> AttachmentsList for (A, B)
|
||||
B: ImageViewAccess
|
||||
{
|
||||
#[inline]
|
||||
fn as_image_view_accesses(&self) -> Vec<&ImageViewAccess> {
|
||||
let mut list = self.0.as_image_view_accesses();
|
||||
list.push(&self.1);
|
||||
list
|
||||
fn num_attachments(&self) -> usize {
|
||||
self.0.num_attachments() + 1
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn as_image_view_access(&self, index: usize) -> Option<&ImageViewAccess> {
|
||||
if index == self.0.num_attachments() {
|
||||
Some(&self.1)
|
||||
} else {
|
||||
self.0.as_image_view_access(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -376,8 +376,8 @@ unsafe impl<Rp, A> FramebufferAbstract for Framebuffer<Rp, A>
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn attachments(&self) -> Vec<&ImageViewAccess> {
|
||||
self.resources.as_image_view_accesses()
|
||||
fn attached_image_view(&self, index: usize) -> Option<&ImageViewAccess> {
|
||||
self.resources.as_image_view_access(index)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,9 +28,10 @@ pub unsafe trait FramebufferAbstract: RenderPassAbstract {
|
||||
/// Returns the width, height and array layers of the framebuffer.
|
||||
fn dimensions(&self) -> [u32; 3];
|
||||
|
||||
/// Returns all the attachments of the framebuffer.
|
||||
// TODO: meh for trait object
|
||||
fn attachments(&self) -> Vec<&ImageViewAccess>;
|
||||
/// Returns the attachment of the framebuffer with the given index.
|
||||
///
|
||||
/// If the `index` is not between `0` and `num_attachments`, then `None` should be returned.
|
||||
fn attached_image_view(&self, index: usize) -> Option<&ImageViewAccess>;
|
||||
|
||||
/// Returns the width of the framebuffer in pixels.
|
||||
#[inline]
|
||||
@ -66,8 +67,8 @@ unsafe impl<T> FramebufferAbstract for T
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn attachments(&self) -> Vec<&ImageViewAccess> {
|
||||
FramebufferAbstract::attachments(&**self)
|
||||
fn attached_image_view(&self, index: usize) -> Option<&ImageViewAccess> {
|
||||
(**self).attached_image_view(index)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user