use super::{
CommandBuffer, Device, Fence, Origin, Region, RenderCommandEncoder, RenderPassDescriptor,
ResourceStatePassDescriptor, SparseTextureMappingMode, StoreAction, StoreActionOptions,
Texture,
};
use crate::Error;
pub use metal_rust_ffi::PassSampleBufferAttachmentIndex;
impl super::BlitPassSampleBufferAttachmentDescriptorArray {
pub fn attachment(
&self,
index: PassSampleBufferAttachmentIndex,
) -> Result<super::BlitPassSampleBufferAttachmentDescriptor, Error> {
self.inner
.attachment(index)
.map(super::BlitPassSampleBufferAttachmentDescriptor::from_ffi)
.map_err(Error::from_ffi)
}
pub fn set_attachment(
&self,
index: PassSampleBufferAttachmentIndex,
attachment: Option<&super::BlitPassSampleBufferAttachmentDescriptor>,
) -> Result<(), Error> {
self.inner
.set_attachment(index, attachment.map(|value| &value.inner))
.map_err(Error::from_ffi)
}
}
impl super::ResourceStatePassSampleBufferAttachmentDescriptorArray {
pub fn attachment(
&self,
index: PassSampleBufferAttachmentIndex,
) -> Result<super::ResourceStatePassSampleBufferAttachmentDescriptor, Error> {
self.inner
.attachment(index)
.map(super::ResourceStatePassSampleBufferAttachmentDescriptor::from_ffi)
.map_err(Error::from_ffi)
}
pub fn set_attachment(
&self,
index: PassSampleBufferAttachmentIndex,
attachment: Option<&super::ResourceStatePassSampleBufferAttachmentDescriptor>,
) -> Result<(), Error> {
self.inner
.set_attachment(index, attachment.map(|value| &value.inner))
.map_err(Error::from_ffi)
}
}
impl super::CommandEncoder {
pub fn barrier_after_queue_stages(
&self,
after_queue_stages: super::Stages,
before_stages: super::Stages,
) -> Result<(), Error> {
self.inner
.barrier_after_queue_stages(after_queue_stages, before_stages)
.map_err(Error::from_ffi)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct SparseTextureMapping {
pub region: Region,
pub mip_level: usize,
pub slice: usize,
}
impl SparseTextureMapping {
const fn as_ffi(self) -> metal_rust_ffi::SparseTextureMapping {
metal_rust_ffi::SparseTextureMapping {
region: self.region,
mip_level: self.mip_level,
slice: self.slice,
}
}
}
pub struct ParallelRenderCommandEncoder<'a> {
pub(crate) inner: metal_rust_ffi::ParallelRenderCommandEncoder<'a>,
}
impl ParallelRenderCommandEncoder<'_> {
pub fn render_encoder(&mut self) -> Result<RenderCommandEncoder<'_>, Error> {
self.inner
.render_encoder()
.map(|inner| RenderCommandEncoder { inner })
.map_err(Error::from_ffi)
}
#[must_use]
pub fn device(&self) -> Device {
Device::from_ffi(self.inner.device())
}
pub fn insert_debug_signpost(&self, value: &str) {
self.inner.insert_debug_signpost(value);
}
pub fn push_debug_group(&self, value: &str) {
self.inner.push_debug_group(value);
}
pub fn pop_debug_group(&self) {
self.inner.pop_debug_group();
}
pub fn set_color_store_action(&self, index: usize, action: StoreAction) -> Result<(), Error> {
self.inner
.set_color_store_action(index, action)
.map_err(Error::from_ffi)
}
pub fn set_depth_store_action(&self, action: StoreAction) -> Result<(), Error> {
self.inner
.set_depth_store_action(action)
.map_err(Error::from_ffi)
}
pub fn set_stencil_store_action(&self, action: StoreAction) -> Result<(), Error> {
self.inner
.set_stencil_store_action(action)
.map_err(Error::from_ffi)
}
pub fn set_color_store_action_options(
&self,
index: usize,
options: StoreActionOptions,
) -> Result<(), Error> {
self.inner
.set_color_store_action_options(index, options)
.map_err(Error::from_ffi)
}
pub fn set_depth_store_action_options(&self, options: StoreActionOptions) -> Result<(), Error> {
self.inner
.set_depth_store_action_options(options)
.map_err(Error::from_ffi)
}
pub fn set_stencil_store_action_options(
&self,
options: StoreActionOptions,
) -> Result<(), Error> {
self.inner
.set_stencil_store_action_options(options)
.map_err(Error::from_ffi)
}
pub fn end_encoding(self) {
self.inner.end_encoding();
}
}
pub struct ResourceStateCommandEncoder<'a> {
pub(crate) inner: metal_rust_ffi::ResourceStateCommandEncoder<'a>,
}
impl ResourceStateCommandEncoder<'_> {
#[must_use]
pub fn device(&self) -> Device {
Device::from_ffi(self.inner.device())
}
pub fn insert_debug_signpost(&self, value: &str) {
self.inner.insert_debug_signpost(value);
}
pub fn push_debug_group(&self, value: &str) {
self.inner.push_debug_group(value);
}
pub fn pop_debug_group(&self) {
self.inner.pop_debug_group();
}
pub fn update_texture_mapping(
&self,
texture: &Texture,
mode: SparseTextureMappingMode,
mapping: SparseTextureMapping,
) -> Result<(), Error> {
self.inner
.update_texture_mapping(&texture.inner, mode, mapping.as_ffi())
.map_err(Error::from_ffi)
}
pub fn update_texture_mappings(
&self,
texture: &Texture,
mode: SparseTextureMappingMode,
mappings: &[SparseTextureMapping],
) -> Result<(), Error> {
let mappings = mappings
.iter()
.copied()
.map(SparseTextureMapping::as_ffi)
.collect::<Vec<_>>();
self.inner
.update_texture_mappings(&texture.inner, mode, &mappings)
.map_err(Error::from_ffi)
}
pub fn update_texture_mapping_indirect(
&self,
texture: &Texture,
mode: SparseTextureMappingMode,
mappings: &[SparseTextureMapping],
) -> Result<(), Error> {
let mappings = mappings
.iter()
.copied()
.map(SparseTextureMapping::as_ffi)
.collect::<Vec<_>>();
self.inner
.update_texture_mapping_indirect(&texture.inner, mode, &mappings)
.map_err(Error::from_ffi)
}
#[allow(clippy::too_many_arguments)]
pub fn move_texture_mappings(
&self,
source: &Texture,
source_slice: usize,
source_level: usize,
source_region: Region,
destination: &Texture,
destination_slice: usize,
destination_level: usize,
destination_origin: Origin,
) -> Result<(), Error> {
self.inner
.move_texture_mappings(
&source.inner,
source_slice,
source_level,
source_region,
&destination.inner,
destination_slice,
destination_level,
destination_origin,
)
.map_err(Error::from_ffi)
}
pub fn update_fence(&self, fence: &Fence) -> Result<(), Error> {
self.inner
.update_fence(&fence.inner)
.map_err(Error::from_ffi)
}
pub fn wait_for_fence(&self, fence: &Fence) -> Result<(), Error> {
self.inner
.wait_for_fence(&fence.inner)
.map_err(Error::from_ffi)
}
pub fn end_encoding(self) {
self.inner.end_encoding();
}
}
impl CommandBuffer {
pub fn parallel_render_encoder<'a>(
&'a mut self,
descriptor: &RenderPassDescriptor,
) -> Result<ParallelRenderCommandEncoder<'a>, Error> {
self.inner
.parallel_render_encoder(&descriptor.inner)
.map(|inner| ParallelRenderCommandEncoder { inner })
.map_err(Error::from_ffi)
}
pub fn resource_state_encoder<'a>(
&'a mut self,
) -> Result<ResourceStateCommandEncoder<'a>, Error> {
self.inner
.resource_state_encoder()
.map(|inner| ResourceStateCommandEncoder { inner })
.map_err(Error::from_ffi)
}
pub fn resource_state_encoder_with_descriptor<'a>(
&'a mut self,
descriptor: &ResourceStatePassDescriptor,
) -> Result<ResourceStateCommandEncoder<'a>, Error> {
self.inner
.resource_state_encoder_with_descriptor(&descriptor.inner)
.map(|inner| ResourceStateCommandEncoder { inner })
.map_err(Error::from_ffi)
}
}