This commit is contained in:
marc0246 2024-11-04 11:51:36 +01:00 committed by GitHub
parent b9ac687d59
commit 82db4298fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 179 additions and 71 deletions

View File

@ -4,7 +4,7 @@ use vulkano::{
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, BlitImageInfo,
BufferImageCopy, ClearColorImageInfo, CommandBufferUsage, CopyBufferToImageInfo,
CopyImageInfo, ImageBlit, ImageCopy, RenderPassBeginInfo,
CopyImageInfo, ImageBlit, ImageCopy, PrimaryCommandBufferAbstract, RenderPassBeginInfo,
},
descriptor_set::{
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,

View File

@ -3,7 +3,7 @@ use vulkano::{
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
CopyBufferToImageInfo, RenderPassBeginInfo,
CopyBufferToImageInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo,
},
descriptor_set::{
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,

View File

@ -12,7 +12,7 @@ use vulkano::{
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
CopyBufferToImageInfo, RenderPassBeginInfo,
CopyBufferToImageInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo,
},
descriptor_set::{
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,

View File

@ -5,6 +5,7 @@ use vulkano::{
buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
PrimaryCommandBufferAbstract,
},
descriptor_set::{
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,

View File

@ -58,7 +58,7 @@ use vulkano::{
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
CopyImageToBufferInfo, RenderPassBeginInfo,
CopyImageToBufferInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo,
},
device::{
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,

View File

@ -6,7 +6,8 @@ use vulkano::{
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
CopyImageToBufferInfo, RenderPassBeginInfo, SubpassBeginInfo, SubpassContents,
CopyImageToBufferInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo, SubpassBeginInfo,
SubpassContents,
},
device::{physical::PhysicalDeviceType, Device, DeviceCreateInfo, QueueCreateInfo, QueueFlags},
format::Format,

View File

@ -3,7 +3,7 @@ use vulkano::{
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
CopyBufferToImageInfo, RenderPassBeginInfo,
CopyBufferToImageInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo,
},
descriptor_set::{layout::DescriptorSetLayoutCreateFlags, WriteDescriptorSet},
device::{

View File

@ -3,7 +3,7 @@ use vulkano::{
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
CopyBufferToImageInfo, RenderPassBeginInfo,
CopyBufferToImageInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo,
},
descriptor_set::{
allocator::StandardDescriptorSetAllocator, layout::DescriptorBindingFlags, DescriptorSet,

View File

@ -8,7 +8,7 @@ use vulkano::{
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
CopyBufferInfo, RenderPassBeginInfo,
CopyBufferInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo,
},
descriptor_set::{
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,

View File

@ -3,7 +3,7 @@ use vulkano::{
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
CopyBufferToImageInfo, RenderPassBeginInfo,
CopyBufferToImageInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo,
},
descriptor_set::{
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,

View File

@ -78,7 +78,9 @@ const MAX_ARENAS: usize = 32;
/// allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo},
/// BufferUsage,
/// },
/// command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage},
/// command_buffer::{
/// AutoCommandBufferBuilder, CommandBufferUsage, PrimaryCommandBufferAbstract,
/// },
/// memory::allocator::MemoryTypeFilter,
/// sync::GpuFuture,
/// };

View File

@ -121,7 +121,10 @@ pub mod view;
/// ```
/// use vulkano::{
/// buffer::{BufferUsage, Buffer, BufferCreateInfo},
/// command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage, CopyBufferInfo},
/// command_buffer::{
/// AutoCommandBufferBuilder, CommandBufferUsage, CopyBufferInfo,
/// PrimaryCommandBufferAbstract,
/// },
/// memory::allocator::{AllocationCreateInfo, MemoryTypeFilter},
/// sync::GpuFuture,
/// DeviceSize,

View File

@ -65,8 +65,8 @@ pub(in crate::command_buffer) use self::builder::{
use super::{
sys::{CommandBuffer, RecordingCommandBuffer},
CommandBufferInheritanceInfo, CommandBufferResourcesUsage, CommandBufferState,
CommandBufferUsage, ResourceInCommand, SecondaryCommandBufferResourcesUsage,
SecondaryResourceUseRef,
CommandBufferUsage, PrimaryCommandBufferAbstract, ResourceInCommand,
SecondaryCommandBufferAbstract, SecondaryCommandBufferResourcesUsage, SecondaryResourceUseRef,
};
use crate::{
buffer::Subbuffer,
@ -118,30 +118,27 @@ impl Debug for PrimaryAutoCommandBuffer {
}
}
impl PrimaryAutoCommandBuffer {
/// Returns the inner raw command buffer.
unsafe impl PrimaryCommandBufferAbstract for PrimaryAutoCommandBuffer {
#[inline]
pub fn inner(&self) -> &CommandBuffer {
fn as_raw(&self) -> &CommandBuffer {
&self.inner
}
/// Returns the queue family index of this command buffer.
#[inline]
pub fn queue_family_index(&self) -> u32 {
fn queue_family_index(&self) -> u32 {
self.inner.queue_family_index()
}
/// Returns the usage of this command buffer.
#[inline]
pub fn usage(&self) -> CommandBufferUsage {
fn usage(&self) -> CommandBufferUsage {
self.inner.usage()
}
pub(crate) fn state(&self) -> MutexGuard<'_, CommandBufferState> {
fn state(&self) -> MutexGuard<'_, CommandBufferState> {
self.state.lock()
}
pub(crate) fn resources_usage(&self) -> &CommandBufferResourcesUsage {
fn resources_usage(&self) -> &CommandBufferResourcesUsage {
&self.resources_usage
}
}
@ -177,36 +174,23 @@ impl Debug for SecondaryAutoCommandBuffer {
}
}
impl SecondaryAutoCommandBuffer {
/// Returns the inner raw command buffer.
unsafe impl SecondaryCommandBufferAbstract for SecondaryAutoCommandBuffer {
#[inline]
pub fn inner(&self) -> &CommandBuffer {
fn as_raw(&self) -> &CommandBuffer {
&self.inner
}
/// Returns the queue family index of this command buffer.
#[inline]
pub fn queue_family_index(&self) -> u32 {
self.inner.queue_family_index()
}
/// Returns the usage of this command buffer.
#[inline]
pub fn usage(&self) -> CommandBufferUsage {
fn usage(&self) -> CommandBufferUsage {
self.inner.usage()
}
/// Returns the inheritance info of the command buffer.
#[inline]
pub fn inheritance_info(&self) -> &CommandBufferInheritanceInfo {
fn inheritance_info(&self) -> &CommandBufferInheritanceInfo {
self.inner.inheritance_info().unwrap()
}
/// Checks whether this command buffer is allowed to be recorded to a command buffer,
/// and if so locks it.
///
/// If you call this function, then you should call `unlock` afterwards.
pub fn lock_record(&self) -> Result<(), Box<ValidationError>> {
fn lock_record(&self) -> Result<(), Box<ValidationError>> {
match self.submit_state {
SubmitState::OneTime {
ref already_submitted,
@ -242,12 +226,7 @@ impl SecondaryAutoCommandBuffer {
Ok(())
}
/// Unlocks the command buffer. Should be called once for each call to `lock_record`.
///
/// # Safety
///
/// Must not be called if you haven't called `lock_record` before.
pub unsafe fn unlock(&self) {
unsafe fn unlock(&self) {
match self.submit_state {
SubmitState::OneTime {
ref already_submitted,
@ -262,7 +241,7 @@ impl SecondaryAutoCommandBuffer {
};
}
pub(crate) fn resources_usage(&self) -> &SecondaryCommandBufferResourcesUsage {
fn resources_usage(&self) -> &SecondaryCommandBufferResourcesUsage {
&self.resources_usage
}
}
@ -347,6 +326,7 @@ mod tests {
command_buffer::{
allocator::{StandardCommandBufferAllocator, StandardCommandBufferAllocatorCreateInfo},
AutoCommandBufferBuilder, BufferCopy, CommandBufferUsage, CopyBufferInfoTyped,
PrimaryCommandBufferAbstract,
},
descriptor_set::{
allocator::StandardDescriptorSetAllocator,

View File

@ -3,7 +3,7 @@ use crate::{
auto::{RenderPassStateType, Resource, ResourceUseRef2},
sys::{CommandBuffer, RecordingCommandBuffer},
AutoCommandBufferBuilder, CommandBufferInheritanceRenderPassType, CommandBufferLevel,
ResourceInCommand, SecondaryAutoCommandBuffer, SecondaryCommandBufferBufferUsage,
ResourceInCommand, SecondaryCommandBufferAbstract, SecondaryCommandBufferBufferUsage,
SecondaryCommandBufferImageUsage, SecondaryCommandBufferResourcesUsage, SubpassContents,
},
device::{DeviceOwned, QueueFlags},
@ -25,7 +25,7 @@ impl<L> AutoCommandBufferBuilder<L> {
/// with `Flags::OneTimeSubmit` will set `self`'s flags to `Flags::OneTimeSubmit` also.
pub fn execute_commands(
&mut self,
command_buffer: Arc<SecondaryAutoCommandBuffer>,
command_buffer: Arc<dyn SecondaryCommandBufferAbstract>,
) -> Result<&mut Self, Box<ValidationError>> {
let command_buffer = DropUnlockCommandBuffer::new(command_buffer)?;
self.validate_execute_commands(iter::once(&**command_buffer))?;
@ -41,7 +41,7 @@ impl<L> AutoCommandBufferBuilder<L> {
// TODO ^ would be nice if this just worked without errors
pub fn execute_commands_from_vec(
&mut self,
command_buffers: Vec<Arc<SecondaryAutoCommandBuffer>>,
command_buffers: Vec<Arc<dyn SecondaryCommandBufferAbstract>>,
) -> Result<&mut Self, Box<ValidationError>> {
let command_buffers: SmallVec<[_; 4]> = command_buffers
.into_iter()
@ -55,10 +55,10 @@ impl<L> AutoCommandBufferBuilder<L> {
fn validate_execute_commands<'a>(
&self,
command_buffers: impl Iterator<Item = &'a SecondaryAutoCommandBuffer> + Clone,
command_buffers: impl Iterator<Item = &'a dyn SecondaryCommandBufferAbstract> + Clone,
) -> Result<(), Box<ValidationError>> {
self.inner
.validate_execute_commands(command_buffers.clone().map(|cb| cb.inner()))?;
.validate_execute_commands(command_buffers.clone().map(|cb| cb.as_raw()))?;
if let Some(render_pass_state) = &self.builder_state.render_pass {
if render_pass_state.contents != SubpassContents::SecondaryCommandBuffers {
@ -459,7 +459,7 @@ impl<L> AutoCommandBufferBuilder<L> {
#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
pub unsafe fn execute_commands_unchecked(
&mut self,
command_buffers: SmallVec<[Arc<SecondaryAutoCommandBuffer>; 4]>,
command_buffers: SmallVec<[Arc<dyn SecondaryCommandBufferAbstract>; 4]>,
) -> &mut Self {
self.execute_commands_locked(
command_buffers
@ -670,17 +670,19 @@ impl RecordingCommandBuffer {
}
}
struct DropUnlockCommandBuffer(Arc<SecondaryAutoCommandBuffer>);
struct DropUnlockCommandBuffer(Arc<dyn SecondaryCommandBufferAbstract>);
impl DropUnlockCommandBuffer {
fn new(command_buffer: Arc<SecondaryAutoCommandBuffer>) -> Result<Self, Box<ValidationError>> {
fn new(
command_buffer: Arc<dyn SecondaryCommandBufferAbstract>,
) -> Result<Self, Box<ValidationError>> {
command_buffer.lock_record()?;
Ok(Self(command_buffer))
}
}
impl std::ops::Deref for DropUnlockCommandBuffer {
type Target = Arc<SecondaryAutoCommandBuffer>;
type Target = Arc<dyn SecondaryCommandBufferAbstract>;
fn deref(&self) -> &Self::Target {
&self.0

View File

@ -52,7 +52,10 @@
//! on the GPU.
//!
//! ```
//! use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage, SubpassContents};
//! use vulkano::command_buffer::{
//! AutoCommandBufferBuilder, CommandBufferUsage, PrimaryCommandBufferAbstract,
//! SubpassContents,
//! };
//!
//! # let device: std::sync::Arc<vulkano::device::Device> = return;
//! # let queue: std::sync::Arc<vulkano::device::Queue> = return;
@ -97,7 +100,10 @@ pub use self::commands::{
pub use self::{
auto::{AutoCommandBufferBuilder, PrimaryAutoCommandBuffer, SecondaryAutoCommandBuffer},
sys::{CommandBuffer, CommandBufferBeginInfo, RecordingCommandBuffer},
traits::{CommandBufferExecError, CommandBufferExecFuture},
traits::{
CommandBufferExecError, CommandBufferExecFuture, PrimaryCommandBufferAbstract,
SecondaryCommandBufferAbstract,
},
};
use crate::{
buffer::{Buffer, Subbuffer},
@ -1185,7 +1191,7 @@ pub struct CommandBufferSubmitInfo {
/// The command buffer to execute.
///
/// There is no default value.
pub command_buffer: Arc<PrimaryAutoCommandBuffer>,
pub command_buffer: Arc<dyn PrimaryCommandBufferAbstract>,
pub _ne: crate::NonExhaustive,
}
@ -1193,7 +1199,7 @@ pub struct CommandBufferSubmitInfo {
impl CommandBufferSubmitInfo {
/// Returns a `CommandBufferSubmitInfo` with the specified `command_buffer`.
#[inline]
pub fn new(command_buffer: Arc<PrimaryAutoCommandBuffer>) -> Self {
pub fn new(command_buffer: Arc<dyn PrimaryCommandBufferAbstract>) -> Self {
Self {
command_buffer,
_ne: crate::NonExhaustive(()),

View File

@ -1,4 +1,8 @@
use super::{CommandBufferSubmitInfo, PrimaryAutoCommandBuffer, SemaphoreSubmitInfo, SubmitInfo};
use super::{
CommandBuffer, CommandBufferInheritanceInfo, CommandBufferResourcesUsage, CommandBufferState,
CommandBufferSubmitInfo, CommandBufferUsage, SecondaryCommandBufferResourcesUsage,
SemaphoreSubmitInfo, SubmitInfo,
};
use crate::{
buffer::Buffer,
device::{Device, DeviceOwned, Queue},
@ -11,9 +15,9 @@ use crate::{
},
PipelineStages,
},
DeviceSize, Validated, VulkanError, VulkanObject,
DeviceSize, SafeDeref, Validated, ValidationError, VulkanError, VulkanObject,
};
use parking_lot::Mutex;
use parking_lot::{Mutex, MutexGuard};
use std::{
borrow::Cow,
error::Error,
@ -26,7 +30,18 @@ use std::{
thread,
};
impl PrimaryAutoCommandBuffer {
pub unsafe trait PrimaryCommandBufferAbstract:
VulkanObject<Handle = ash::vk::CommandBuffer> + DeviceOwned + Send + Sync
{
/// Returns the underlying raw command buffer.
fn as_raw(&self) -> &CommandBuffer;
/// Returns the queue family index of this command buffer.
fn queue_family_index(&self) -> u32;
/// Returns the usage of this command buffer.
fn usage(&self) -> CommandBufferUsage;
/// Executes this command buffer on a queue.
///
/// This function returns an object that implements the [`GpuFuture`] trait. See the
@ -50,7 +65,7 @@ impl PrimaryAutoCommandBuffer {
///
/// - Panics if the device of the command buffer is not the same as the device of the future.
#[inline]
pub fn execute(
fn execute(
self: Arc<Self>,
queue: Arc<Queue>,
) -> Result<CommandBufferExecFuture<NowFuture>, CommandBufferExecError>
@ -87,7 +102,7 @@ impl PrimaryAutoCommandBuffer {
/// # Panics
///
/// - Panics if the device of the command buffer is not the same as the device of the future.
pub fn execute_after<F>(
fn execute_after<F>(
self: Arc<Self>,
future: F,
queue: Arc<Queue>,
@ -110,6 +125,104 @@ impl PrimaryAutoCommandBuffer {
finished: AtomicBool::new(false),
})
}
#[doc(hidden)]
fn state(&self) -> MutexGuard<'_, CommandBufferState>;
#[doc(hidden)]
fn resources_usage(&self) -> &CommandBufferResourcesUsage;
}
impl Debug for dyn PrimaryCommandBufferAbstract {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
Debug::fmt(&self.handle(), f)
}
}
unsafe impl<T> PrimaryCommandBufferAbstract for T
where
T: VulkanObject<Handle = ash::vk::CommandBuffer> + SafeDeref + Send + Sync,
T::Target: PrimaryCommandBufferAbstract,
{
fn as_raw(&self) -> &CommandBuffer {
(**self).as_raw()
}
fn queue_family_index(&self) -> u32 {
(**self).queue_family_index()
}
fn usage(&self) -> CommandBufferUsage {
(**self).usage()
}
fn state(&self) -> MutexGuard<'_, CommandBufferState> {
(**self).state()
}
fn resources_usage(&self) -> &CommandBufferResourcesUsage {
(**self).resources_usage()
}
}
pub unsafe trait SecondaryCommandBufferAbstract:
VulkanObject<Handle = ash::vk::CommandBuffer> + DeviceOwned + Send + Sync
{
/// Returns the underlying raw command buffer.
fn as_raw(&self) -> &CommandBuffer;
/// Returns the usage of this command buffer.
fn usage(&self) -> CommandBufferUsage;
/// Returns a `CommandBufferInheritance` value describing the properties that the command
/// buffer inherits from its parent primary command buffer.
fn inheritance_info(&self) -> &CommandBufferInheritanceInfo;
/// Checks whether this command buffer is allowed to be recorded to a command buffer,
/// and if so locks it.
///
/// If you call this function, then you should call `unlock` afterwards.
fn lock_record(&self) -> Result<(), Box<ValidationError>>;
/// Unlocks the command buffer. Should be called once for each call to `lock_record`.
///
/// # Safety
///
/// Must not be called if you haven't called `lock_record` before.
unsafe fn unlock(&self);
#[doc(hidden)]
fn resources_usage(&self) -> &SecondaryCommandBufferResourcesUsage;
}
unsafe impl<T> SecondaryCommandBufferAbstract for T
where
T: VulkanObject<Handle = ash::vk::CommandBuffer> + SafeDeref + Send + Sync,
T::Target: SecondaryCommandBufferAbstract,
{
fn as_raw(&self) -> &CommandBuffer {
(**self).as_raw()
}
fn usage(&self) -> CommandBufferUsage {
(**self).usage()
}
fn inheritance_info(&self) -> &CommandBufferInheritanceInfo {
(**self).inheritance_info()
}
fn lock_record(&self) -> Result<(), Box<ValidationError>> {
(**self).lock_record()
}
unsafe fn unlock(&self) {
(**self).unlock();
}
fn resources_usage(&self) -> &SecondaryCommandBufferResourcesUsage {
(**self).resources_usage()
}
}
/// Represents a command buffer being executed by the GPU and the moment when the execution
@ -121,7 +234,7 @@ where
F: GpuFuture,
{
previous: F,
command_buffer: Arc<PrimaryAutoCommandBuffer>,
command_buffer: Arc<dyn PrimaryCommandBufferAbstract>,
queue: Arc<Queue>,
// True if the command buffer has already been submitted.
// If flush is called multiple times, we want to block so that only one flushing is executed.

View File

@ -92,8 +92,8 @@ use crate::{
buffer::{Buffer, BufferState},
command_buffer::{
CommandBufferExecError, CommandBufferExecFuture, CommandBufferResourcesUsage,
CommandBufferState, CommandBufferSubmitInfo, CommandBufferUsage, PrimaryAutoCommandBuffer,
SubmitInfo,
CommandBufferState, CommandBufferSubmitInfo, CommandBufferUsage,
PrimaryCommandBufferAbstract, SubmitInfo,
},
device::{DeviceOwned, Queue},
image::{Image, ImageLayout, ImageState},
@ -242,7 +242,7 @@ pub unsafe trait GpuFuture: DeviceOwned {
fn then_execute(
self,
queue: Arc<Queue>,
command_buffer: Arc<PrimaryAutoCommandBuffer>,
command_buffer: Arc<impl PrimaryCommandBufferAbstract + 'static>,
) -> Result<CommandBufferExecFuture<Self>, CommandBufferExecError>
where
Self: Sized,
@ -256,7 +256,7 @@ pub unsafe trait GpuFuture: DeviceOwned {
/// > `CommandBuffer` trait.
fn then_execute_same_queue(
self,
command_buffer: Arc<PrimaryAutoCommandBuffer>,
command_buffer: Arc<impl PrimaryCommandBufferAbstract + 'static>,
) -> Result<CommandBufferExecFuture<Self>, CommandBufferExecError>
where
Self: Sized,