mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-09 20:31:29 +11:00
Add HAL method to update buffer descriptor
This is WIP because only the Metal implementation is added. Part of the work for #175
This commit is contained in:
parent
60d197bb4e
commit
95081971fe
|
@ -98,6 +98,36 @@ pub trait Device: Sized {
|
|||
builder.build(self, pipeline)
|
||||
}
|
||||
|
||||
/// Update a descriptor in a descriptor set.
|
||||
///
|
||||
/// The index is the same as the binding number in Vulkan.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The descriptor set must not be used in any in-flight command buffer. The index must be valid.
|
||||
/// The resource type must match that at descriptor set creation time.
|
||||
unsafe fn update_buffer_descriptor(
|
||||
&self,
|
||||
ds: &mut Self::DescriptorSet,
|
||||
index: u32,
|
||||
buf: &Self::Buffer,
|
||||
);
|
||||
|
||||
/// Update a descriptor in a descriptor set.
|
||||
///
|
||||
/// The index is the same as the binding number in Vulkan.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The descriptor set must not be used in any in-flight command buffer. The index must be valid.
|
||||
/// The resource type must match that at descriptor set creation time.
|
||||
unsafe fn update_image_descriptor(
|
||||
&self,
|
||||
ds: &mut Self::DescriptorSet,
|
||||
index: u32,
|
||||
image: &Self::Image,
|
||||
);
|
||||
|
||||
fn create_cmd_buf(&self) -> Result<Self::CmdBuf, Error>;
|
||||
|
||||
/// If the command buffer was submitted, it must complete before this is called.
|
||||
|
|
|
@ -366,6 +366,30 @@ impl Session {
|
|||
DescriptorSetBuilder(self.0.device.descriptor_set_builder())
|
||||
}
|
||||
|
||||
/// Update a buffer in a descriptor set.
|
||||
pub unsafe fn update_buffer_descriptor(
|
||||
&self,
|
||||
ds: &mut DescriptorSet,
|
||||
index: u32,
|
||||
buffer: &Buffer,
|
||||
) {
|
||||
self.0
|
||||
.device
|
||||
.update_buffer_descriptor(ds, index, &buffer.0.buffer)
|
||||
}
|
||||
|
||||
/// Update an image in a descriptor set.
|
||||
pub unsafe fn update_image_descriptor(
|
||||
&self,
|
||||
ds: &mut DescriptorSet,
|
||||
index: u32,
|
||||
image: &Image,
|
||||
) {
|
||||
self.0
|
||||
.device
|
||||
.update_image_descriptor(ds, index, &image.0.image)
|
||||
}
|
||||
|
||||
/// Create a query pool for timestamp queries.
|
||||
pub fn create_query_pool(&self, n_queries: u32) -> Result<QueryPool, Error> {
|
||||
self.0.device.create_query_pool(n_queries)
|
||||
|
|
|
@ -385,6 +385,24 @@ impl crate::backend::Device for MtlDevice {
|
|||
DescriptorSetBuilder::default()
|
||||
}
|
||||
|
||||
unsafe fn update_buffer_descriptor(
|
||||
&self,
|
||||
ds: &mut Self::DescriptorSet,
|
||||
index: u32,
|
||||
buf: &Self::Buffer,
|
||||
) {
|
||||
ds.buffers[index as usize] = buf.clone();
|
||||
}
|
||||
|
||||
unsafe fn update_image_descriptor(
|
||||
&self,
|
||||
ds: &mut Self::DescriptorSet,
|
||||
index: u32,
|
||||
image: &Self::Image,
|
||||
) {
|
||||
ds.images[index as usize - ds.buffers.len()] = image.clone();
|
||||
}
|
||||
|
||||
fn create_cmd_buf(&self) -> Result<Self::CmdBuf, Error> {
|
||||
let cmd_queue = self.cmd_queue.lock().unwrap();
|
||||
// A discussion about autorelease pools.
|
||||
|
|
|
@ -391,6 +391,32 @@ impl Device {
|
|||
}
|
||||
}
|
||||
|
||||
pub unsafe fn update_buffer_descriptor(
|
||||
&self,
|
||||
ds: &mut DescriptorSet,
|
||||
index: u32,
|
||||
buffer: &Buffer,
|
||||
) {
|
||||
mux_match! { self;
|
||||
Device::Vk(d) => d.update_buffer_descriptor(ds.vk_mut(), index, buffer.vk()),
|
||||
Device::Dx12(d) => d.update_buffer_descriptor(ds.dx12_mut(), index, buffer.dx12()),
|
||||
Device::Mtl(d) => d.update_buffer_descriptor(ds.mtl_mut(), index, buffer.mtl()),
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn update_image_descriptor(
|
||||
&self,
|
||||
ds: &mut DescriptorSet,
|
||||
index: u32,
|
||||
image: &Image,
|
||||
) {
|
||||
mux_match! { self;
|
||||
Device::Vk(d) => d.update_image_descriptor(ds.vk_mut(), index, image.vk()),
|
||||
Device::Dx12(d) => d.update_image_descriptor(ds.dx12_mut(), index, image.dx12()),
|
||||
Device::Mtl(d) => d.update_image_descriptor(ds.mtl_mut(), index, image.mtl()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_cmd_buf(&self) -> Result<CmdBuf, Error> {
|
||||
mux_match! { self;
|
||||
Device::Vk(d) => d.create_cmd_buf().map(CmdBuf::Vk),
|
||||
|
|
Loading…
Reference in a new issue