Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
348
third-party/vendor/metal/src/accelerator_structure.rs
vendored
Normal file
348
third-party/vendor/metal/src/accelerator_structure.rs
vendored
Normal file
|
|
@ -0,0 +1,348 @@
|
|||
// Copyright 2023 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
|
||||
bitflags! {
|
||||
#[derive(Copy, Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct MTLAccelerationStructureInstanceOptions: u32 {
|
||||
const None = 0;
|
||||
const DisableTriangleCulling = (1 << 0);
|
||||
const TriangleFrontFacingWindingCounterClockwise = (1 << 1);
|
||||
const Opaque = (1 << 2);
|
||||
const NonOpaque = (1 << 3);
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlaccelerationstructureinstancedescriptortype>
|
||||
#[repr(u64)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
||||
pub enum MTLAccelerationStructureInstanceDescriptorType {
|
||||
Default = 0,
|
||||
UserID = 1,
|
||||
Motion = 2,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Debug, Default)]
|
||||
#[repr(C)]
|
||||
pub struct MTLAccelerationStructureInstanceDescriptor {
|
||||
pub transformation_matrix: [[f32; 3]; 4],
|
||||
pub options: MTLAccelerationStructureInstanceOptions,
|
||||
pub mask: u32,
|
||||
pub intersection_function_table_offset: u32,
|
||||
pub acceleration_structure_index: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Debug, Default)]
|
||||
#[repr(C)]
|
||||
pub struct MTLAccelerationStructureUserIDInstanceDescriptor {
|
||||
pub transformation_matrix: [[f32; 3]; 4],
|
||||
pub options: MTLAccelerationStructureInstanceOptions,
|
||||
pub mask: u32,
|
||||
pub intersection_function_table_offset: u32,
|
||||
pub acceleration_structure_index: u32,
|
||||
pub user_id: u32,
|
||||
}
|
||||
|
||||
pub enum MTLAccelerationStructureDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLAccelerationStructureDescriptor;
|
||||
pub struct AccelerationStructureDescriptor;
|
||||
type ParentType = NsObject;
|
||||
}
|
||||
|
||||
pub enum MTLPrimitiveAccelerationStructureDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLPrimitiveAccelerationStructureDescriptor;
|
||||
pub struct PrimitiveAccelerationStructureDescriptor;
|
||||
type ParentType = AccelerationStructureDescriptor;
|
||||
}
|
||||
|
||||
impl PrimitiveAccelerationStructureDescriptor {
|
||||
pub fn descriptor() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLPrimitiveAccelerationStructureDescriptor);
|
||||
msg_send![class, descriptor]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PrimitiveAccelerationStructureDescriptorRef {
|
||||
pub fn set_geometry_descriptors(
|
||||
&self,
|
||||
descriptors: &ArrayRef<AccelerationStructureGeometryDescriptor>,
|
||||
) {
|
||||
unsafe { msg_send![self, setGeometryDescriptors: descriptors] }
|
||||
}
|
||||
}
|
||||
|
||||
pub enum MTLAccelerationStructure {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLAccelerationStructure;
|
||||
pub struct AccelerationStructure;
|
||||
type ParentType = Resource;
|
||||
}
|
||||
|
||||
pub enum MTLAccelerationStructureGeometryDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLAccelerationStructureGeometryDescriptor;
|
||||
pub struct AccelerationStructureGeometryDescriptor;
|
||||
type ParentType = NsObject;
|
||||
}
|
||||
|
||||
impl AccelerationStructureGeometryDescriptorRef {
|
||||
pub fn set_opaque(&self, opaque: bool) {
|
||||
unsafe { msg_send![self, setOpaque: opaque] }
|
||||
}
|
||||
pub fn set_primitive_data_buffer(&self, buffer: Option<&BufferRef>) {
|
||||
unsafe { msg_send![self, setPrimitiveDataBuffer: buffer] }
|
||||
}
|
||||
|
||||
pub fn set_primitive_data_stride(&self, stride: NSUInteger) {
|
||||
unsafe { msg_send![self, setPrimitiveDataStride: stride] }
|
||||
}
|
||||
|
||||
pub fn set_primitive_data_element_size(&self, size: NSUInteger) {
|
||||
unsafe { msg_send![self, setPrimitiveDataElementSize: size] }
|
||||
}
|
||||
|
||||
pub fn set_intersection_function_table_offset(&self, offset: NSUInteger) {
|
||||
unsafe { msg_send![self, setIntersectionFunctionTableOffset: offset] }
|
||||
}
|
||||
}
|
||||
|
||||
pub enum MTLAccelerationStructureTriangleGeometryDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLAccelerationStructureTriangleGeometryDescriptor;
|
||||
pub struct AccelerationStructureTriangleGeometryDescriptor;
|
||||
type ParentType = AccelerationStructureGeometryDescriptor;
|
||||
}
|
||||
|
||||
impl AccelerationStructureTriangleGeometryDescriptor {
|
||||
pub fn descriptor() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLAccelerationStructureTriangleGeometryDescriptor);
|
||||
msg_send![class, descriptor]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AccelerationStructureTriangleGeometryDescriptorRef {
|
||||
pub fn set_index_buffer(&self, buffer: Option<&BufferRef>) {
|
||||
unsafe { msg_send![self, setIndexBuffer: buffer] }
|
||||
}
|
||||
|
||||
pub fn set_index_buffer_offset(&self, offset: NSUInteger) {
|
||||
unsafe { msg_send![self, setIndexBufferOffset: offset] }
|
||||
}
|
||||
|
||||
pub fn set_index_type(&self, t: MTLIndexType) {
|
||||
unsafe { msg_send![self, setIndexType: t] }
|
||||
}
|
||||
|
||||
pub fn set_vertex_buffer(&self, buffer: Option<&BufferRef>) {
|
||||
unsafe { msg_send![self, setVertexBuffer: buffer] }
|
||||
}
|
||||
|
||||
pub fn set_vertex_buffer_offset(&self, offset: NSUInteger) {
|
||||
unsafe { msg_send![self, setVertexBufferOffset: offset] }
|
||||
}
|
||||
|
||||
pub fn set_vertex_stride(&self, stride: NSUInteger) {
|
||||
unsafe { msg_send![self, setVertexStride: stride] }
|
||||
}
|
||||
|
||||
pub fn set_triangle_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setTriangleCount: count] }
|
||||
}
|
||||
|
||||
pub fn set_vertex_format(&self, format: MTLAttributeFormat) {
|
||||
unsafe { msg_send![self, setVertexFormat: format] }
|
||||
}
|
||||
|
||||
pub fn set_transformation_matrix_buffer(&self, buffer: Option<&BufferRef>) {
|
||||
unsafe { msg_send![self, setTransformationMatrixBuffer: buffer] }
|
||||
}
|
||||
|
||||
pub fn set_transformation_matrix_buffer_offset(&self, offset: NSUInteger) {
|
||||
unsafe { msg_send![self, setTransformationMatrixBufferOffset: offset] }
|
||||
}
|
||||
}
|
||||
|
||||
pub enum MTLAccelerationStructureBoundingBoxGeometryDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLAccelerationStructureBoundingBoxGeometryDescriptor;
|
||||
pub struct AccelerationStructureBoundingBoxGeometryDescriptor;
|
||||
type ParentType = AccelerationStructureGeometryDescriptor;
|
||||
}
|
||||
|
||||
impl AccelerationStructureBoundingBoxGeometryDescriptor {
|
||||
pub fn descriptor() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLAccelerationStructureBoundingBoxGeometryDescriptor);
|
||||
msg_send![class, descriptor]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AccelerationStructureBoundingBoxGeometryDescriptorRef {
|
||||
pub fn set_bounding_box_buffer(&self, buffer: Option<&BufferRef>) {
|
||||
unsafe { msg_send![self, setBoundingBoxBuffer: buffer] }
|
||||
}
|
||||
|
||||
pub fn set_bounding_box_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setBoundingBoxCount: count] }
|
||||
}
|
||||
}
|
||||
|
||||
pub enum MTLInstanceAccelerationStructureDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLInstanceAccelerationStructureDescriptor;
|
||||
pub struct InstanceAccelerationStructureDescriptor;
|
||||
type ParentType = AccelerationStructureDescriptor;
|
||||
}
|
||||
|
||||
impl InstanceAccelerationStructureDescriptor {
|
||||
pub fn descriptor() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLInstanceAccelerationStructureDescriptor);
|
||||
msg_send![class, descriptor]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl InstanceAccelerationStructureDescriptorRef {
|
||||
pub fn set_instance_descriptor_type(&self, ty: MTLAccelerationStructureInstanceDescriptorType) {
|
||||
unsafe { msg_send![self, setInstanceDescriptorType: ty] }
|
||||
}
|
||||
|
||||
pub fn set_instanced_acceleration_structures(
|
||||
&self,
|
||||
instances: &ArrayRef<AccelerationStructure>,
|
||||
) {
|
||||
unsafe { msg_send![self, setInstancedAccelerationStructures: instances] }
|
||||
}
|
||||
|
||||
pub fn set_instance_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setInstanceCount: count] }
|
||||
}
|
||||
|
||||
pub fn set_instance_descriptor_buffer(&self, buffer: &BufferRef) {
|
||||
unsafe { msg_send![self, setInstanceDescriptorBuffer: buffer] }
|
||||
}
|
||||
|
||||
pub fn set_instance_descriptor_buffer_offset(&self, offset: NSUInteger) {
|
||||
unsafe { msg_send![self, setInstanceDescriptorBufferOffset: offset] }
|
||||
}
|
||||
|
||||
pub fn set_instance_descriptor_stride(&self, stride: NSUInteger) {
|
||||
unsafe { msg_send![self, setInstanceDescriptorStride: stride] }
|
||||
}
|
||||
}
|
||||
|
||||
pub enum MTLAccelerationStructureCommandEncoder {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLAccelerationStructureCommandEncoder;
|
||||
pub struct AccelerationStructureCommandEncoder;
|
||||
type ParentType = CommandEncoder;
|
||||
}
|
||||
|
||||
impl AccelerationStructureCommandEncoderRef {
|
||||
pub fn build_acceleration_structure(
|
||||
&self,
|
||||
acceleration_structure: &self::AccelerationStructureRef,
|
||||
descriptor: &self::AccelerationStructureDescriptorRef,
|
||||
scratch_buffer: &BufferRef,
|
||||
scratch_buffer_offset: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
buildAccelerationStructure: acceleration_structure
|
||||
descriptor: descriptor
|
||||
scratchBuffer: scratch_buffer
|
||||
scratchBufferOffset: scratch_buffer_offset]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_compacted_acceleration_structure_size(
|
||||
&self,
|
||||
acceleration_structure: &AccelerationStructureRef,
|
||||
to_buffer: &BufferRef,
|
||||
offset: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
writeCompactedAccelerationStructureSize: acceleration_structure
|
||||
toBuffer: to_buffer
|
||||
offset: offset
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn copy_and_compact_acceleration_structure(
|
||||
&self,
|
||||
source: &AccelerationStructureRef,
|
||||
destination: &AccelerationStructureRef,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
copyAndCompactAccelerationStructure: source
|
||||
toAccelerationStructure: destination
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum MTLIntersectionFunctionTableDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLIntersectionFunctionTableDescriptor;
|
||||
pub struct IntersectionFunctionTableDescriptor;
|
||||
type ParentType = NsObject;
|
||||
}
|
||||
|
||||
impl IntersectionFunctionTableDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLIntersectionFunctionTableDescriptor);
|
||||
let this: *mut <Self as ForeignType>::CType = msg_send![class, alloc];
|
||||
msg_send![this, init]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntersectionFunctionTableDescriptorRef {
|
||||
pub fn set_function_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setFunctionCount: count] }
|
||||
}
|
||||
}
|
||||
|
||||
pub enum MTLIntersectionFunctionTable {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLIntersectionFunctionTable;
|
||||
pub struct IntersectionFunctionTable;
|
||||
type ParentType = Resource;
|
||||
}
|
||||
|
||||
impl IntersectionFunctionTableRef {
|
||||
pub fn set_function(&self, function: &FunctionHandleRef, index: NSUInteger) {
|
||||
unsafe { msg_send![self, setFunction: function atIndex: index] }
|
||||
}
|
||||
}
|
||||
342
third-party/vendor/metal/src/argument.rs
vendored
Normal file
342
third-party/vendor/metal/src/argument.rs
vendored
Normal file
|
|
@ -0,0 +1,342 @@
|
|||
// Copyright 2017 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::{MTLTextureType, NSUInteger};
|
||||
use objc::runtime::{NO, YES};
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtldatatype>
|
||||
#[repr(u64)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLDataType {
|
||||
None = 0,
|
||||
|
||||
Struct = 1,
|
||||
Array = 2,
|
||||
|
||||
Float = 3,
|
||||
Float2 = 4,
|
||||
Float3 = 5,
|
||||
Float4 = 6,
|
||||
|
||||
Float2x2 = 7,
|
||||
Float2x3 = 8,
|
||||
Float2x4 = 9,
|
||||
|
||||
Float3x2 = 10,
|
||||
Float3x3 = 11,
|
||||
Float3x4 = 12,
|
||||
|
||||
Float4x2 = 13,
|
||||
Float4x3 = 14,
|
||||
Float4x4 = 15,
|
||||
|
||||
Half = 16,
|
||||
Half2 = 17,
|
||||
Half3 = 18,
|
||||
Half4 = 19,
|
||||
|
||||
Half2x2 = 20,
|
||||
Half2x3 = 21,
|
||||
Half2x4 = 22,
|
||||
|
||||
Half3x2 = 23,
|
||||
Half3x3 = 24,
|
||||
Half3x4 = 25,
|
||||
|
||||
Half4x2 = 26,
|
||||
Half4x3 = 27,
|
||||
Half4x4 = 28,
|
||||
|
||||
Int = 29,
|
||||
Int2 = 30,
|
||||
Int3 = 31,
|
||||
Int4 = 32,
|
||||
|
||||
UInt = 33,
|
||||
UInt2 = 34,
|
||||
UInt3 = 35,
|
||||
UInt4 = 36,
|
||||
|
||||
Short = 37,
|
||||
Short2 = 38,
|
||||
Short3 = 39,
|
||||
Short4 = 40,
|
||||
|
||||
UShort = 41,
|
||||
UShort2 = 42,
|
||||
UShort3 = 43,
|
||||
UShort4 = 44,
|
||||
|
||||
Char = 45,
|
||||
Char2 = 46,
|
||||
Char3 = 47,
|
||||
Char4 = 48,
|
||||
|
||||
UChar = 49,
|
||||
UChar2 = 50,
|
||||
UChar3 = 51,
|
||||
UChar4 = 52,
|
||||
|
||||
Bool = 53,
|
||||
Bool2 = 54,
|
||||
Bool3 = 55,
|
||||
Bool4 = 56,
|
||||
|
||||
Texture = 58,
|
||||
Sampler = 59,
|
||||
Pointer = 60,
|
||||
R8Unorm = 62,
|
||||
R8Snorm = 63,
|
||||
R16Unorm = 64,
|
||||
R16Snorm = 65,
|
||||
RG8Unorm = 66,
|
||||
RG8Snorm = 67,
|
||||
RG16Unorm = 68,
|
||||
RG16Snorm = 69,
|
||||
RGBA8Unorm = 70,
|
||||
RGBA8Unorm_sRGB = 71,
|
||||
RGBA8Snorm = 72,
|
||||
RGBA16Unorm = 73,
|
||||
RGBA16Snorm = 74,
|
||||
RGB10A2Unorm = 75,
|
||||
RG11B10Float = 76,
|
||||
RGB9E5Float = 77,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlargumenttype>
|
||||
#[repr(u64)]
|
||||
#[deprecated(
|
||||
note = "Since: iOS 8.0–16.0, iPadOS 8.0–16.0, macOS 10.11–13.0, Mac Catalyst 13.1–16.0, tvOS 9.0–16.0"
|
||||
)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLArgumentType {
|
||||
Buffer = 0,
|
||||
ThreadgroupMemory = 1,
|
||||
Texture = 2,
|
||||
Sampler = 3,
|
||||
ImageblockData = 16,
|
||||
Imageblock = 17,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlargumentaccess>
|
||||
#[repr(u64)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLArgumentAccess {
|
||||
ReadOnly = 0,
|
||||
ReadWrite = 1,
|
||||
WriteOnly = 2,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlstructmember>
|
||||
pub enum MTLStructMember {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLStructMember;
|
||||
pub struct StructMember;
|
||||
}
|
||||
|
||||
impl StructMemberRef {
|
||||
pub fn name(&self) -> &str {
|
||||
unsafe {
|
||||
let name = msg_send![self, name];
|
||||
crate::nsstring_as_str(name)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn offset(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, offset] }
|
||||
}
|
||||
|
||||
pub fn data_type(&self) -> MTLDataType {
|
||||
unsafe { msg_send![self, dataType] }
|
||||
}
|
||||
|
||||
pub fn struct_type(&self) -> MTLStructType {
|
||||
unsafe { msg_send![self, structType] }
|
||||
}
|
||||
|
||||
pub fn array_type(&self) -> MTLArrayType {
|
||||
unsafe { msg_send![self, arrayType] }
|
||||
}
|
||||
}
|
||||
|
||||
pub enum MTLStructMemberArray {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLStructMemberArray;
|
||||
pub struct StructMemberArray;
|
||||
}
|
||||
|
||||
impl StructMemberArrayRef {
|
||||
pub fn object_at(&self, index: NSUInteger) -> Option<&StructMemberRef> {
|
||||
unsafe { msg_send![self, objectAtIndexedSubscript: index] }
|
||||
}
|
||||
|
||||
pub fn count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, count] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlstructtype>
|
||||
pub enum MTLStructType {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLStructType;
|
||||
pub struct StructType;
|
||||
}
|
||||
|
||||
impl StructTypeRef {
|
||||
pub fn members(&self) -> &StructMemberArrayRef {
|
||||
unsafe { msg_send![self, members] }
|
||||
}
|
||||
|
||||
pub fn member_from_name(&self, name: &str) -> Option<&StructMemberRef> {
|
||||
let nsname = crate::nsstring_from_str(name);
|
||||
|
||||
unsafe { msg_send![self, memberByName: nsname] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlarraytype>
|
||||
pub enum MTLArrayType {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLArrayType;
|
||||
pub struct ArrayType;
|
||||
}
|
||||
|
||||
impl ArrayTypeRef {
|
||||
pub fn array_length(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, arrayLength] }
|
||||
}
|
||||
|
||||
pub fn stride(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, stride] }
|
||||
}
|
||||
|
||||
pub fn element_type(&self) -> MTLDataType {
|
||||
unsafe { msg_send![self, elementType] }
|
||||
}
|
||||
|
||||
pub fn element_struct_type(&self) -> MTLStructType {
|
||||
unsafe { msg_send![self, elementStructType] }
|
||||
}
|
||||
|
||||
pub fn element_array_type(&self) -> MTLArrayType {
|
||||
unsafe { msg_send![self, elementArrayType] }
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://developer.apple.com/documentation/metal/mtlargument>
|
||||
#[deprecated(
|
||||
note = "Since iOS 8.0–16.0, iPadOS 8.0–16.0, macOS 10.11–13.0, Mac Catalyst 13.1–16.0, tvOS 9.0–16.0"
|
||||
)]
|
||||
pub enum MTLArgument {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLArgument;
|
||||
pub struct Argument;
|
||||
}
|
||||
|
||||
impl ArgumentRef {
|
||||
pub fn name(&self) -> &str {
|
||||
unsafe {
|
||||
let name = msg_send![self, name];
|
||||
crate::nsstring_as_str(name)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn type_(&self) -> MTLArgumentType {
|
||||
unsafe { msg_send![self, type] }
|
||||
}
|
||||
|
||||
pub fn access(&self) -> MTLArgumentAccess {
|
||||
unsafe { msg_send![self, access] }
|
||||
}
|
||||
|
||||
pub fn index(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, index] }
|
||||
}
|
||||
|
||||
pub fn is_active(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isActive] }
|
||||
}
|
||||
|
||||
pub fn buffer_alignment(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, bufferAlignment] }
|
||||
}
|
||||
|
||||
pub fn buffer_data_size(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, bufferDataSize] }
|
||||
}
|
||||
|
||||
pub fn buffer_data_type(&self) -> MTLDataType {
|
||||
unsafe { msg_send![self, bufferDataType] }
|
||||
}
|
||||
|
||||
pub fn buffer_struct_type(&self) -> &StructTypeRef {
|
||||
unsafe { msg_send![self, bufferStructType] }
|
||||
}
|
||||
|
||||
pub fn threadgroup_memory_alignment(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, threadgroupMemoryAlignment] }
|
||||
}
|
||||
|
||||
pub fn threadgroup_memory_data_size(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, threadgroupMemoryDataSize] }
|
||||
}
|
||||
|
||||
pub fn texture_type(&self) -> MTLTextureType {
|
||||
unsafe { msg_send![self, textureType] }
|
||||
}
|
||||
|
||||
pub fn texture_data_type(&self) -> MTLDataType {
|
||||
unsafe { msg_send![self, textureDataType] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlargumentdescriptor>
|
||||
pub enum MTLArgumentDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLArgumentDescriptor;
|
||||
pub struct ArgumentDescriptor;
|
||||
}
|
||||
|
||||
impl ArgumentDescriptor {
|
||||
pub fn new<'a>() -> &'a ArgumentDescriptorRef {
|
||||
unsafe {
|
||||
let class = class!(MTLArgumentDescriptor);
|
||||
msg_send![class, argumentDescriptor]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ArgumentDescriptorRef {
|
||||
pub fn set_data_type(&self, ty: MTLDataType) {
|
||||
unsafe { msg_send![self, setDataType: ty] }
|
||||
}
|
||||
|
||||
pub fn set_index(&self, index: NSUInteger) {
|
||||
unsafe { msg_send![self, setIndex: index] }
|
||||
}
|
||||
|
||||
pub fn set_access(&self, access: MTLArgumentAccess) {
|
||||
unsafe { msg_send![self, setAccess: access] }
|
||||
}
|
||||
|
||||
pub fn set_array_length(&self, length: NSUInteger) {
|
||||
unsafe { msg_send![self, setArrayLength: length] }
|
||||
}
|
||||
|
||||
pub fn set_texture_type(&self, ty: MTLTextureType) {
|
||||
unsafe { msg_send![self, setTextureType: ty] }
|
||||
}
|
||||
}
|
||||
71
third-party/vendor/metal/src/buffer.rs
vendored
Normal file
71
third-party/vendor/metal/src/buffer.rs
vendored
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
// Copyright 2016 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlbuffer>
|
||||
pub enum MTLBuffer {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLBuffer;
|
||||
pub struct Buffer;
|
||||
type ParentType = Resource;
|
||||
}
|
||||
|
||||
impl BufferRef {
|
||||
pub fn length(&self) -> u64 {
|
||||
unsafe { msg_send![self, length] }
|
||||
}
|
||||
|
||||
pub fn contents(&self) -> *mut std::ffi::c_void {
|
||||
unsafe { msg_send![self, contents] }
|
||||
}
|
||||
|
||||
pub fn did_modify_range(&self, range: crate::NSRange) {
|
||||
unsafe { msg_send![self, didModifyRange: range] }
|
||||
}
|
||||
|
||||
pub fn new_texture_with_descriptor(
|
||||
&self,
|
||||
descriptor: &TextureDescriptorRef,
|
||||
offset: u64,
|
||||
bytes_per_row: u64,
|
||||
) -> Texture {
|
||||
unsafe {
|
||||
msg_send![self,
|
||||
newTextureWithDescriptor:descriptor
|
||||
offset:offset
|
||||
bytesPerRow:bytes_per_row
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on macos(10.15), NOT available on (ios)
|
||||
pub fn remote_storage_buffer(&self) -> &BufferRef {
|
||||
unsafe { msg_send![self, remoteStorageBuffer] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.15), NOT available on (ios)
|
||||
pub fn new_remote_buffer_view_for_device(&self, device: &DeviceRef) -> Buffer {
|
||||
unsafe { msg_send![self, newRemoteBufferViewForDevice: device] }
|
||||
}
|
||||
|
||||
pub fn add_debug_marker(&self, name: &str, range: crate::NSRange) {
|
||||
unsafe {
|
||||
let name = crate::nsstring_from_str(name);
|
||||
msg_send![self, addDebugMarker:name range:range]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_all_debug_markers(&self) {
|
||||
unsafe { msg_send![self, removeAllDebugMarkers] }
|
||||
}
|
||||
|
||||
pub fn gpu_address(&self) -> u64 {
|
||||
unsafe { msg_send![self, gpuAddress] }
|
||||
}
|
||||
}
|
||||
76
third-party/vendor/metal/src/capturedescriptor.rs
vendored
Normal file
76
third-party/vendor/metal/src/capturedescriptor.rs
vendored
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
// Copyright 2020 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcapturedestination?language=objc>
|
||||
#[repr(u64)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLCaptureDestination {
|
||||
DeveloperTools = 1,
|
||||
GpuTraceDocument = 2,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcapturedescriptor>
|
||||
pub enum MTLCaptureDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLCaptureDescriptor;
|
||||
pub struct CaptureDescriptor;
|
||||
}
|
||||
|
||||
impl CaptureDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLCaptureDescriptor);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CaptureDescriptorRef {
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcapturedescriptor/3237248-captureobject>
|
||||
pub fn set_capture_device(&self, device: &DeviceRef) {
|
||||
unsafe { msg_send![self, setCaptureObject: device] }
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcapturedescriptor/3237248-captureobject>
|
||||
pub fn set_capture_scope(&self, scope: &CaptureScopeRef) {
|
||||
unsafe { msg_send![self, setCaptureObject: scope] }
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcapturedescriptor/3237248-captureobject>
|
||||
pub fn set_capture_command_queue(&self, command_queue: &CommandQueueRef) {
|
||||
unsafe { msg_send![self, setCaptureObject: command_queue] }
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcapturedescriptor/3237250-outputurl>
|
||||
pub fn output_url(&self) -> &Path {
|
||||
let url: &URLRef = unsafe { msg_send![self, outputURL] };
|
||||
Path::new(url.path())
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcapturedescriptor/3237250-outputurl>
|
||||
pub fn set_output_url<P: AsRef<Path>>(&self, output_url: P) {
|
||||
let output_url_string = String::from("file://") + output_url.as_ref().to_str().unwrap();
|
||||
let output_url = URL::new_with_string(&output_url_string);
|
||||
unsafe { msg_send![self, setOutputURL: output_url] }
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcapturedescriptor?language=objc>
|
||||
pub fn destination(&self) -> MTLCaptureDestination {
|
||||
unsafe { msg_send![self, destination] }
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcapturedescriptor?language=objc>
|
||||
pub fn set_destination(&self, destination: MTLCaptureDestination) {
|
||||
unsafe { msg_send![self, setDestination: destination] }
|
||||
}
|
||||
}
|
||||
113
third-party/vendor/metal/src/capturemanager.rs
vendored
Normal file
113
third-party/vendor/metal/src/capturemanager.rs
vendored
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
// Copyright 2018 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
use std::ffi::CStr;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcapturescope>
|
||||
pub enum MTLCaptureScope {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLCaptureScope;
|
||||
pub struct CaptureScope;
|
||||
}
|
||||
|
||||
impl CaptureScopeRef {
|
||||
pub fn begin_scope(&self) {
|
||||
unsafe { msg_send![self, beginScope] }
|
||||
}
|
||||
|
||||
pub fn end_scope(&self) {
|
||||
unsafe { msg_send![self, endScope] }
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcapturemanager>
|
||||
pub enum MTLCaptureManager {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLCaptureManager;
|
||||
pub struct CaptureManager;
|
||||
}
|
||||
|
||||
impl CaptureManager {
|
||||
pub fn shared<'a>() -> &'a CaptureManagerRef {
|
||||
unsafe {
|
||||
let class = class!(MTLCaptureManager);
|
||||
msg_send![class, sharedCaptureManager]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CaptureManagerRef {
|
||||
pub fn new_capture_scope_with_device(&self, device: &DeviceRef) -> CaptureScope {
|
||||
unsafe { msg_send![self, newCaptureScopeWithDevice: device] }
|
||||
}
|
||||
|
||||
pub fn new_capture_scope_with_command_queue(
|
||||
&self,
|
||||
command_queue: &CommandQueueRef,
|
||||
) -> CaptureScope {
|
||||
unsafe { msg_send![self, newCaptureScopeWithCommandQueue: command_queue] }
|
||||
}
|
||||
|
||||
pub fn default_capture_scope(&self) -> Option<&CaptureScopeRef> {
|
||||
unsafe { msg_send![self, defaultCaptureScope] }
|
||||
}
|
||||
|
||||
pub fn set_default_capture_scope(&self, scope: &CaptureScopeRef) {
|
||||
unsafe { msg_send![self, setDefaultCaptureScope: scope] }
|
||||
}
|
||||
|
||||
/// Starts capturing with the capture session defined by a descriptor object.
|
||||
///
|
||||
/// This function will panic if Metal capture is not enabled. Capture can be enabled by
|
||||
/// either:
|
||||
/// 1. Running from Xcode
|
||||
/// 2. Setting the environment variable `METAL_CAPTURE_ENABLED=1`
|
||||
/// 3. Adding an info.plist file containing the `MetalCaptureEnabled` key set to `YES`
|
||||
pub fn start_capture(&self, descriptor: &CaptureDescriptorRef) -> Result<(), String> {
|
||||
unsafe {
|
||||
Ok(try_objc! { err =>
|
||||
msg_send![self, startCaptureWithDescriptor: descriptor
|
||||
error: &mut err]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_capture_with_device(&self, device: &DeviceRef) {
|
||||
unsafe { msg_send![self, startCaptureWithDevice: device] }
|
||||
}
|
||||
|
||||
pub fn start_capture_with_command_queue(&self, command_queue: &CommandQueueRef) {
|
||||
unsafe { msg_send![self, startCaptureWithCommandQueue: command_queue] }
|
||||
}
|
||||
|
||||
pub fn start_capture_with_scope(&self, scope: &CaptureScopeRef) {
|
||||
unsafe { msg_send![self, startCaptureWithScope: scope] }
|
||||
}
|
||||
|
||||
pub fn stop_capture(&self) {
|
||||
unsafe { msg_send![self, stopCapture] }
|
||||
}
|
||||
|
||||
pub fn is_capturing(&self) -> bool {
|
||||
unsafe { msg_send![self, isCapturing] }
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcapturemanager/3237260-supportsdestination?language=objc>
|
||||
pub fn supports_destination(&self, destination: MTLCaptureDestination) -> bool {
|
||||
unsafe { msg_send![self, supportsDestination: destination] }
|
||||
}
|
||||
}
|
||||
178
third-party/vendor/metal/src/commandbuffer.rs
vendored
Normal file
178
third-party/vendor/metal/src/commandbuffer.rs
vendored
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
// Copyright 2016 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
|
||||
use block::Block;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcommandbufferstatus>
|
||||
#[repr(u32)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLCommandBufferStatus {
|
||||
NotEnqueued = 0,
|
||||
Enqueued = 1,
|
||||
Committed = 2,
|
||||
Scheduled = 3,
|
||||
Completed = 4,
|
||||
Error = 5,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcommandbuffererror>
|
||||
#[repr(u32)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLCommandBufferError {
|
||||
None = 0,
|
||||
Internal = 1,
|
||||
Timeout = 2,
|
||||
PageFault = 3,
|
||||
Blacklisted = 4,
|
||||
NotPermitted = 7,
|
||||
OutOfMemory = 8,
|
||||
InvalidResource = 9,
|
||||
Memoryless = 10,
|
||||
DeviceRemoved = 11,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtldispatchtype>
|
||||
#[repr(u32)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLDispatchType {
|
||||
Serial = 0,
|
||||
Concurrent = 1,
|
||||
}
|
||||
|
||||
type CommandBufferHandler<'a> = Block<(&'a CommandBufferRef,), ()>;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcommandbuffer>.
|
||||
pub enum MTLCommandBuffer {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLCommandBuffer;
|
||||
pub struct CommandBuffer;
|
||||
}
|
||||
|
||||
impl CommandBufferRef {
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: nslabel];
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enqueue(&self) {
|
||||
unsafe { msg_send![self, enqueue] }
|
||||
}
|
||||
|
||||
pub fn commit(&self) {
|
||||
unsafe { msg_send![self, commit] }
|
||||
}
|
||||
|
||||
pub fn status(&self) -> MTLCommandBufferStatus {
|
||||
unsafe { msg_send![self, status] }
|
||||
}
|
||||
|
||||
pub fn present_drawable(&self, drawable: &DrawableRef) {
|
||||
unsafe { msg_send![self, presentDrawable: drawable] }
|
||||
}
|
||||
|
||||
pub fn wait_until_completed(&self) {
|
||||
unsafe { msg_send![self, waitUntilCompleted] }
|
||||
}
|
||||
|
||||
pub fn wait_until_scheduled(&self) {
|
||||
unsafe { msg_send![self, waitUntilScheduled] }
|
||||
}
|
||||
|
||||
pub fn add_completed_handler(&self, block: &CommandBufferHandler) {
|
||||
unsafe { msg_send![self, addCompletedHandler: block] }
|
||||
}
|
||||
|
||||
pub fn add_scheduled_handler(&self, block: &CommandBufferHandler) {
|
||||
unsafe { msg_send![self, addScheduledHandler: block] }
|
||||
}
|
||||
|
||||
pub fn new_blit_command_encoder(&self) -> &BlitCommandEncoderRef {
|
||||
unsafe { msg_send![self, blitCommandEncoder] }
|
||||
}
|
||||
|
||||
pub fn new_compute_command_encoder(&self) -> &ComputeCommandEncoderRef {
|
||||
unsafe { msg_send![self, computeCommandEncoder] }
|
||||
}
|
||||
|
||||
pub fn new_render_command_encoder(
|
||||
&self,
|
||||
descriptor: &RenderPassDescriptorRef,
|
||||
) -> &RenderCommandEncoderRef {
|
||||
unsafe { msg_send![self, renderCommandEncoderWithDescriptor: descriptor] }
|
||||
}
|
||||
|
||||
pub fn new_parallel_render_command_encoder(
|
||||
&self,
|
||||
descriptor: &RenderPassDescriptorRef,
|
||||
) -> &ParallelRenderCommandEncoderRef {
|
||||
unsafe { msg_send![self, parallelRenderCommandEncoderWithDescriptor: descriptor] }
|
||||
}
|
||||
|
||||
pub fn new_acceleration_structure_command_encoder(
|
||||
&self,
|
||||
) -> &AccelerationStructureCommandEncoderRef {
|
||||
unsafe { msg_send![self, accelerationStructureCommandEncoder] }
|
||||
}
|
||||
|
||||
pub fn compute_command_encoder_with_dispatch_type(
|
||||
&self,
|
||||
ty: MTLDispatchType,
|
||||
) -> &ComputeCommandEncoderRef {
|
||||
unsafe { msg_send![self, computeCommandEncoderWithDispatchType: ty] }
|
||||
}
|
||||
|
||||
pub fn compute_command_encoder_with_descriptor(
|
||||
&self,
|
||||
descriptor: &ComputePassDescriptorRef,
|
||||
) -> &ComputeCommandEncoderRef {
|
||||
unsafe { msg_send![self, computeCommandEncoderWithDescriptor: descriptor] }
|
||||
}
|
||||
|
||||
pub fn encode_signal_event(&self, event: &EventRef, new_value: u64) {
|
||||
unsafe {
|
||||
msg_send![self,
|
||||
encodeSignalEvent: event
|
||||
value: new_value
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn encode_wait_for_event(&self, event: &EventRef, value: u64) {
|
||||
unsafe {
|
||||
msg_send![self,
|
||||
encodeWaitForEvent: event
|
||||
value: value
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push_debug_group(&self, name: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(name);
|
||||
msg_send![self, pushDebugGroup: nslabel]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pop_debug_group(&self) {
|
||||
unsafe { msg_send![self, popDebugGroup] }
|
||||
}
|
||||
}
|
||||
44
third-party/vendor/metal/src/commandqueue.rs
vendored
Normal file
44
third-party/vendor/metal/src/commandqueue.rs
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// Copyright 2016 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcommandqueue>.
|
||||
pub enum MTLCommandQueue {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLCommandQueue;
|
||||
pub struct CommandQueue;
|
||||
}
|
||||
|
||||
impl CommandQueueRef {
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: nslabel];
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_command_buffer(&self) -> &CommandBufferRef {
|
||||
unsafe { msg_send![self, commandBuffer] }
|
||||
}
|
||||
|
||||
pub fn new_command_buffer_with_unretained_references(&self) -> &CommandBufferRef {
|
||||
unsafe { msg_send![self, commandBufferWithUnretainedReferences] }
|
||||
}
|
||||
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
}
|
||||
103
third-party/vendor/metal/src/computepass.rs
vendored
Normal file
103
third-party/vendor/metal/src/computepass.rs
vendored
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
use super::*;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcomputepassdescriptor>
|
||||
pub enum MTLComputePassDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLComputePassDescriptor;
|
||||
pub struct ComputePassDescriptor;
|
||||
}
|
||||
|
||||
impl ComputePassDescriptor {
|
||||
/// Creates a default compute pass descriptor with no attachments.
|
||||
pub fn new<'a>() -> &'a ComputePassDescriptorRef {
|
||||
unsafe { msg_send![class!(MTLComputePassDescriptor), computePassDescriptor] }
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputePassDescriptorRef {
|
||||
pub fn sample_buffer_attachments(
|
||||
&self,
|
||||
) -> &ComputePassSampleBufferAttachmentDescriptorArrayRef {
|
||||
unsafe { msg_send![self, sampleBufferAttachments] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcomputepasssamplebufferattachmentdescriptorarray>
|
||||
pub enum MTLComputePassSampleBufferAttachmentDescriptorArray {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLComputePassSampleBufferAttachmentDescriptorArray;
|
||||
pub struct ComputePassSampleBufferAttachmentDescriptorArray;
|
||||
}
|
||||
|
||||
impl ComputePassSampleBufferAttachmentDescriptorArrayRef {
|
||||
pub fn object_at(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
) -> Option<&ComputePassSampleBufferAttachmentDescriptorRef> {
|
||||
unsafe { msg_send![self, objectAtIndexedSubscript: index] }
|
||||
}
|
||||
|
||||
pub fn set_object_at(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
attachment: Option<&ComputePassSampleBufferAttachmentDescriptorRef>,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self, setObject:attachment
|
||||
atIndexedSubscript:index]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcomputepasssamplebufferattachmentdescriptor>
|
||||
pub enum MTLComputePassSampleBufferAttachmentDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLComputePassSampleBufferAttachmentDescriptor;
|
||||
pub struct ComputePassSampleBufferAttachmentDescriptor;
|
||||
}
|
||||
|
||||
impl ComputePassSampleBufferAttachmentDescriptor {
|
||||
pub fn new() -> Self {
|
||||
let class = class!(MTLComputePassSampleBufferAttachmentDescriptor);
|
||||
unsafe { msg_send![class, new] }
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputePassSampleBufferAttachmentDescriptorRef {
|
||||
pub fn sample_buffer(&self) -> &CounterSampleBufferRef {
|
||||
unsafe { msg_send![self, sampleBuffer] }
|
||||
}
|
||||
|
||||
pub fn set_sample_buffer(&self, sample_buffer: &CounterSampleBufferRef) {
|
||||
unsafe { msg_send![self, setSampleBuffer: sample_buffer] }
|
||||
}
|
||||
|
||||
pub fn start_of_encoder_sample_index(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, startOfEncoderSampleIndex] }
|
||||
}
|
||||
|
||||
pub fn set_start_of_encoder_sample_index(&self, start_of_encoder_sample_index: NSUInteger) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
setStartOfEncoderSampleIndex: start_of_encoder_sample_index
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn end_of_encoder_sample_index(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, endOfEncoderSampleIndex] }
|
||||
}
|
||||
|
||||
pub fn set_end_of_encoder_sample_index(&self, end_of_encoder_sample_index: NSUInteger) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
setEndOfEncoderSampleIndex: end_of_encoder_sample_index
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
152
third-party/vendor/metal/src/constants.rs
vendored
Normal file
152
third-party/vendor/metal/src/constants.rs
vendored
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
// Copyright 2016 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlpixelformat>
|
||||
#[repr(u64)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
||||
pub enum MTLPixelFormat {
|
||||
Invalid = 0,
|
||||
A8Unorm = 1,
|
||||
R8Unorm = 10,
|
||||
R8Unorm_sRGB = 11,
|
||||
R8Snorm = 12,
|
||||
R8Uint = 13,
|
||||
R8Sint = 14,
|
||||
R16Unorm = 20,
|
||||
R16Snorm = 22,
|
||||
R16Uint = 23,
|
||||
R16Sint = 24,
|
||||
R16Float = 25,
|
||||
RG8Unorm = 30,
|
||||
RG8Unorm_sRGB = 31,
|
||||
RG8Snorm = 32,
|
||||
RG8Uint = 33,
|
||||
RG8Sint = 34,
|
||||
B5G6R5Unorm = 40,
|
||||
A1BGR5Unorm = 41,
|
||||
ABGR4Unorm = 42,
|
||||
BGR5A1Unorm = 43,
|
||||
R32Uint = 53,
|
||||
R32Sint = 54,
|
||||
R32Float = 55,
|
||||
RG16Unorm = 60,
|
||||
RG16Snorm = 62,
|
||||
RG16Uint = 63,
|
||||
RG16Sint = 64,
|
||||
RG16Float = 65,
|
||||
RGBA8Unorm = 70,
|
||||
RGBA8Unorm_sRGB = 71,
|
||||
RGBA8Snorm = 72,
|
||||
RGBA8Uint = 73,
|
||||
RGBA8Sint = 74,
|
||||
BGRA8Unorm = 80,
|
||||
BGRA8Unorm_sRGB = 81,
|
||||
RGB10A2Unorm = 90,
|
||||
RGB10A2Uint = 91,
|
||||
RG11B10Float = 92,
|
||||
RGB9E5Float = 93,
|
||||
BGR10A2Unorm = 94,
|
||||
RG32Uint = 103,
|
||||
RG32Sint = 104,
|
||||
RG32Float = 105,
|
||||
RGBA16Unorm = 110,
|
||||
RGBA16Snorm = 112,
|
||||
RGBA16Uint = 113,
|
||||
RGBA16Sint = 114,
|
||||
RGBA16Float = 115,
|
||||
RGBA32Uint = 123,
|
||||
RGBA32Sint = 124,
|
||||
RGBA32Float = 125,
|
||||
BC1_RGBA = 130,
|
||||
BC1_RGBA_sRGB = 131,
|
||||
BC2_RGBA = 132,
|
||||
BC2_RGBA_sRGB = 133,
|
||||
BC3_RGBA = 134,
|
||||
BC3_RGBA_sRGB = 135,
|
||||
BC4_RUnorm = 140,
|
||||
BC4_RSnorm = 141,
|
||||
BC5_RGUnorm = 142,
|
||||
BC5_RGSnorm = 143,
|
||||
BC6H_RGBFloat = 150,
|
||||
BC6H_RGBUfloat = 151,
|
||||
BC7_RGBAUnorm = 152,
|
||||
BC7_RGBAUnorm_sRGB = 153,
|
||||
PVRTC_RGB_2BPP = 160,
|
||||
PVRTC_RGB_2BPP_sRGB = 161,
|
||||
PVRTC_RGB_4BPP = 162,
|
||||
PVRTC_RGB_4BPP_sRGB = 163,
|
||||
PVRTC_RGBA_2BPP = 164,
|
||||
PVRTC_RGBA_2BPP_sRGB = 165,
|
||||
PVRTC_RGBA_4BPP = 166,
|
||||
PVRTC_RGBA_4BPP_sRGB = 167,
|
||||
EAC_R11Unorm = 170,
|
||||
EAC_R11Snorm = 172,
|
||||
EAC_RG11Unorm = 174,
|
||||
EAC_RG11Snorm = 176,
|
||||
EAC_RGBA8 = 178,
|
||||
EAC_RGBA8_sRGB = 179,
|
||||
ETC2_RGB8 = 180,
|
||||
ETC2_RGB8_sRGB = 181,
|
||||
ETC2_RGB8A1 = 182,
|
||||
ETC2_RGB8A1_sRGB = 183,
|
||||
ASTC_4x4_sRGB = 186,
|
||||
ASTC_5x4_sRGB = 187,
|
||||
ASTC_5x5_sRGB = 188,
|
||||
ASTC_6x5_sRGB = 189,
|
||||
ASTC_6x6_sRGB = 190,
|
||||
ASTC_8x5_sRGB = 192,
|
||||
ASTC_8x6_sRGB = 193,
|
||||
ASTC_8x8_sRGB = 194,
|
||||
ASTC_10x5_sRGB = 195,
|
||||
ASTC_10x6_sRGB = 196,
|
||||
ASTC_10x8_sRGB = 197,
|
||||
ASTC_10x10_sRGB = 198,
|
||||
ASTC_12x10_sRGB = 199,
|
||||
ASTC_12x12_sRGB = 200,
|
||||
ASTC_4x4_LDR = 204,
|
||||
ASTC_5x4_LDR = 205,
|
||||
ASTC_5x5_LDR = 206,
|
||||
ASTC_6x5_LDR = 207,
|
||||
ASTC_6x6_LDR = 208,
|
||||
ASTC_8x5_LDR = 210,
|
||||
ASTC_8x6_LDR = 211,
|
||||
ASTC_8x8_LDR = 212,
|
||||
ASTC_10x5_LDR = 213,
|
||||
ASTC_10x6_LDR = 214,
|
||||
ASTC_10x8_LDR = 215,
|
||||
ASTC_10x10_LDR = 216,
|
||||
ASTC_12x10_LDR = 217,
|
||||
ASTC_12x12_LDR = 218,
|
||||
ASTC_4x4_HDR = 222,
|
||||
ASTC_5x4_HDR = 223,
|
||||
ASTC_5x5_HDR = 224,
|
||||
ASTC_6x5_HDR = 225,
|
||||
ASTC_6x6_HDR = 226,
|
||||
ASTC_8x5_HDR = 228,
|
||||
ASTC_8x6_HDR = 229,
|
||||
ASTC_8x8_HDR = 230,
|
||||
ASTC_10x5_HDR = 231,
|
||||
ASTC_10x6_HDR = 232,
|
||||
ASTC_10x8_HDR = 233,
|
||||
ASTC_10x10_HDR = 234,
|
||||
ASTC_12x10_HDR = 235,
|
||||
ASTC_12x12_HDR = 236,
|
||||
GBGR422 = 240,
|
||||
BGRG422 = 241,
|
||||
Depth16Unorm = 250,
|
||||
Depth32Float = 252,
|
||||
Stencil8 = 253,
|
||||
Depth24Unorm_Stencil8 = 255,
|
||||
Depth32Float_Stencil8 = 260,
|
||||
X32_Stencil8 = 261,
|
||||
X24_Stencil8 = 262,
|
||||
BGRA10_XR = 552,
|
||||
BGRA10_XR_SRGB = 553,
|
||||
BGR10_XR = 554,
|
||||
BGR10_XR_SRGB = 555,
|
||||
}
|
||||
102
third-party/vendor/metal/src/counters.rs
vendored
Normal file
102
third-party/vendor/metal/src/counters.rs
vendored
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
use crate::MTLStorageMode;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcountersamplebufferdescriptor>
|
||||
pub enum MTLCounterSampleBufferDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLCounterSampleBufferDescriptor;
|
||||
pub struct CounterSampleBufferDescriptor;
|
||||
}
|
||||
|
||||
impl CounterSampleBufferDescriptor {
|
||||
pub fn new() -> Self {
|
||||
let class = class!(MTLCounterSampleBufferDescriptor);
|
||||
unsafe { msg_send![class, new] }
|
||||
}
|
||||
}
|
||||
|
||||
impl CounterSampleBufferDescriptorRef {
|
||||
pub fn counter_set(&self) -> &CounterSetRef {
|
||||
unsafe { msg_send![self, counterSet] }
|
||||
}
|
||||
|
||||
pub fn set_counter_set(&self, counter_set: &CounterSetRef) {
|
||||
unsafe { msg_send![self, setCounterSet: counter_set] }
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: nslabel];
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sample_count(&self) -> u64 {
|
||||
unsafe { msg_send![self, sampleCount] }
|
||||
}
|
||||
|
||||
pub fn set_sample_count(&self, sample_count: u64) {
|
||||
unsafe { msg_send![self, setSampleCount: sample_count] }
|
||||
}
|
||||
|
||||
pub fn storage_mode(&self) -> MTLStorageMode {
|
||||
unsafe { msg_send![self, storageMode] }
|
||||
}
|
||||
|
||||
pub fn set_storage_mode(&self, storage_mode: MTLStorageMode) {
|
||||
unsafe { msg_send![self, setStorageMode: storage_mode] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcountersamplebuffer>
|
||||
pub enum MTLCounterSampleBuffer {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLCounterSampleBuffer;
|
||||
pub struct CounterSampleBuffer;
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcounter>
|
||||
pub enum MTLCounter {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLCounter;
|
||||
pub struct Counter;
|
||||
}
|
||||
|
||||
impl CounterRef {}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcounterset>
|
||||
pub enum MTLCounterSet {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLCounterSet;
|
||||
pub struct CounterSet;
|
||||
}
|
||||
|
||||
impl CounterSetRef {
|
||||
pub fn name(&self) -> &str {
|
||||
unsafe {
|
||||
let name = msg_send![self, name];
|
||||
crate::nsstring_as_str(name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcommoncounterset>
|
||||
pub enum MTLCommonCounterSet {}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcommoncounter>
|
||||
pub enum MTLCommonCounter {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLCommonCounter;
|
||||
pub struct CommonCounter;
|
||||
}
|
||||
190
third-party/vendor/metal/src/depthstencil.rs
vendored
Normal file
190
third-party/vendor/metal/src/depthstencil.rs
vendored
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
// Copyright 2016 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use crate::DeviceRef;
|
||||
use objc::runtime::{NO, YES};
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcomparefunction>
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLCompareFunction {
|
||||
Never = 0,
|
||||
Less = 1,
|
||||
Equal = 2,
|
||||
LessEqual = 3,
|
||||
Greater = 4,
|
||||
NotEqual = 5,
|
||||
GreaterEqual = 6,
|
||||
Always = 7,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlstenciloperation>
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLStencilOperation {
|
||||
Keep = 0,
|
||||
Zero = 1,
|
||||
Replace = 2,
|
||||
IncrementClamp = 3,
|
||||
DecrementClamp = 4,
|
||||
Invert = 5,
|
||||
IncrementWrap = 6,
|
||||
DecrementWrap = 7,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlstencildescriptor>
|
||||
pub enum MTLStencilDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLStencilDescriptor;
|
||||
pub struct StencilDescriptor;
|
||||
}
|
||||
|
||||
impl StencilDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLStencilDescriptor);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StencilDescriptorRef {
|
||||
pub fn stencil_compare_function(&self) -> MTLCompareFunction {
|
||||
unsafe { msg_send![self, stencilCompareFunction] }
|
||||
}
|
||||
|
||||
pub fn set_stencil_compare_function(&self, func: MTLCompareFunction) {
|
||||
unsafe { msg_send![self, setStencilCompareFunction: func] }
|
||||
}
|
||||
|
||||
pub fn stencil_failure_operation(&self) -> MTLStencilOperation {
|
||||
unsafe { msg_send![self, stencilFailureOperation] }
|
||||
}
|
||||
|
||||
pub fn set_stencil_failure_operation(&self, operation: MTLStencilOperation) {
|
||||
unsafe { msg_send![self, setStencilFailureOperation: operation] }
|
||||
}
|
||||
|
||||
pub fn depth_failure_operation(&self) -> MTLStencilOperation {
|
||||
unsafe { msg_send![self, depthFailureOperation] }
|
||||
}
|
||||
|
||||
pub fn set_depth_failure_operation(&self, operation: MTLStencilOperation) {
|
||||
unsafe { msg_send![self, setDepthFailureOperation: operation] }
|
||||
}
|
||||
|
||||
pub fn depth_stencil_pass_operation(&self) -> MTLStencilOperation {
|
||||
unsafe { msg_send![self, depthStencilPassOperation] }
|
||||
}
|
||||
|
||||
pub fn set_depth_stencil_pass_operation(&self, operation: MTLStencilOperation) {
|
||||
unsafe { msg_send![self, setDepthStencilPassOperation: operation] }
|
||||
}
|
||||
|
||||
pub fn read_mask(&self) -> u32 {
|
||||
unsafe { msg_send![self, readMask] }
|
||||
}
|
||||
|
||||
pub fn set_read_mask(&self, mask: u32) {
|
||||
unsafe { msg_send![self, setReadMask: mask] }
|
||||
}
|
||||
|
||||
pub fn write_mask(&self) -> u32 {
|
||||
unsafe { msg_send![self, writeMask] }
|
||||
}
|
||||
|
||||
pub fn set_write_mask(&self, mask: u32) {
|
||||
unsafe { msg_send![self, setWriteMask: mask] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtldepthstencildescriptor>
|
||||
pub enum MTLDepthStencilDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLDepthStencilDescriptor;
|
||||
pub struct DepthStencilDescriptor;
|
||||
}
|
||||
|
||||
impl DepthStencilDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLDepthStencilDescriptor);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DepthStencilDescriptorRef {
|
||||
pub fn depth_compare_function(&self) -> MTLCompareFunction {
|
||||
unsafe { msg_send![self, depthCompareFunction] }
|
||||
}
|
||||
|
||||
pub fn set_depth_compare_function(&self, func: MTLCompareFunction) {
|
||||
unsafe { msg_send![self, setDepthCompareFunction: func] }
|
||||
}
|
||||
|
||||
pub fn depth_write_enabled(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isDepthWriteEnabled] }
|
||||
}
|
||||
|
||||
pub fn set_depth_write_enabled(&self, enabled: bool) {
|
||||
unsafe { msg_send![self, setDepthWriteEnabled: enabled] }
|
||||
}
|
||||
|
||||
pub fn front_face_stencil(&self) -> Option<&StencilDescriptorRef> {
|
||||
unsafe { msg_send![self, frontFaceStencil] }
|
||||
}
|
||||
|
||||
pub fn set_front_face_stencil(&self, descriptor: Option<&StencilDescriptorRef>) {
|
||||
unsafe { msg_send![self, setFrontFaceStencil: descriptor] }
|
||||
}
|
||||
|
||||
pub fn back_face_stencil(&self) -> Option<&StencilDescriptorRef> {
|
||||
unsafe { msg_send![self, backFaceStencil] }
|
||||
}
|
||||
|
||||
pub fn set_back_face_stencil(&self, descriptor: Option<&StencilDescriptorRef>) {
|
||||
unsafe { msg_send![self, setBackFaceStencil: descriptor] }
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: nslabel];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtldepthstencilstate>
|
||||
pub enum MTLDepthStencilState {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLDepthStencilState;
|
||||
pub struct DepthStencilState;
|
||||
}
|
||||
|
||||
impl DepthStencilStateRef {
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
}
|
||||
2106
third-party/vendor/metal/src/device.rs
vendored
Normal file
2106
third-party/vendor/metal/src/device.rs
vendored
Normal file
File diff suppressed because it is too large
Load diff
26
third-party/vendor/metal/src/drawable.rs
vendored
Normal file
26
third-party/vendor/metal/src/drawable.rs
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2016 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::NSUInteger;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtldrawable>
|
||||
pub enum MTLDrawable {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLDrawable;
|
||||
pub struct Drawable;
|
||||
}
|
||||
|
||||
impl DrawableRef {
|
||||
pub fn present(&self) {
|
||||
unsafe { msg_send![self, present] }
|
||||
}
|
||||
|
||||
pub fn drawable_id(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, drawableID] }
|
||||
}
|
||||
}
|
||||
1870
third-party/vendor/metal/src/encoder.rs
vendored
Normal file
1870
third-party/vendor/metal/src/encoder.rs
vendored
Normal file
File diff suppressed because it is too large
Load diff
209
third-party/vendor/metal/src/heap.rs
vendored
Normal file
209
third-party/vendor/metal/src/heap.rs
vendored
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
// Copyright 2016 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Only available on macos(10.15), ios(13.0)
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlheaptype/>
|
||||
#[repr(u64)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum MTLHeapType {
|
||||
Automatic = 0,
|
||||
Placement = 1,
|
||||
/// Only available on macos(11.0), macCatalyst(14.0)
|
||||
Sparse = 2,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlheap/>
|
||||
pub enum MTLHeap {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLHeap;
|
||||
pub struct Heap;
|
||||
}
|
||||
|
||||
impl HeapRef {
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: nslabel];
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cpu_cache_mode(&self) -> MTLCPUCacheMode {
|
||||
unsafe { msg_send![self, cpuCacheMode] }
|
||||
}
|
||||
|
||||
pub fn storage_mode(&self) -> MTLStorageMode {
|
||||
unsafe { msg_send![self, storageMode] }
|
||||
}
|
||||
|
||||
/// Only available on macos(10.15), ios(13.0)
|
||||
pub fn hazard_tracking_mode(&self) -> MTLHazardTrackingMode {
|
||||
unsafe { msg_send![self, hazardTrackingMode] }
|
||||
}
|
||||
|
||||
/// Only available on macos(10.15), ios(13.0)
|
||||
pub fn resource_options(&self) -> MTLResourceOptions {
|
||||
unsafe { msg_send![self, resourceOptions] }
|
||||
}
|
||||
|
||||
pub fn set_purgeable_state(&self, state: MTLPurgeableState) -> MTLPurgeableState {
|
||||
unsafe { msg_send![self, setPurgeableState: state] }
|
||||
}
|
||||
|
||||
pub fn size(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, size] }
|
||||
}
|
||||
|
||||
pub fn used_size(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, usedSize] }
|
||||
}
|
||||
|
||||
/// Only available on macos(10.15), ios(13.0)
|
||||
pub fn heap_type(&self) -> MTLHeapType {
|
||||
unsafe { msg_send![self, type] }
|
||||
}
|
||||
|
||||
/// Only available on macos(10.13), ios(11.0)
|
||||
pub fn current_allocated_size(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, currentAllocatedSize] }
|
||||
}
|
||||
|
||||
pub fn max_available_size_with_alignment(&self, alignment: NSUInteger) -> NSUInteger {
|
||||
unsafe { msg_send![self, maxAvailableSizeWithAlignment: alignment] }
|
||||
}
|
||||
|
||||
pub fn new_buffer(&self, length: u64, options: MTLResourceOptions) -> Option<Buffer> {
|
||||
unsafe {
|
||||
let ptr: *mut MTLBuffer = msg_send![self, newBufferWithLength:length
|
||||
options:options];
|
||||
if !ptr.is_null() {
|
||||
Some(Buffer::from_ptr(ptr))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_texture(&self, descriptor: &TextureDescriptorRef) -> Option<Texture> {
|
||||
unsafe {
|
||||
let ptr: *mut MTLTexture = msg_send![self, newTextureWithDescriptor: descriptor];
|
||||
if !ptr.is_null() {
|
||||
Some(Texture::from_ptr(ptr))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on macOS 10.15+ & iOS 13.0+
|
||||
pub fn new_buffer_with_offset(
|
||||
&self,
|
||||
length: u64,
|
||||
options: MTLResourceOptions,
|
||||
offset: u64,
|
||||
) -> Option<Buffer> {
|
||||
unsafe {
|
||||
let ptr: *mut MTLBuffer = msg_send![self, newBufferWithLength:length
|
||||
options:options
|
||||
offset:offset];
|
||||
if !ptr.is_null() {
|
||||
Some(Buffer::from_ptr(ptr))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on macOS 10.15+ & iOS 13.0+
|
||||
pub fn new_texture_with_offset(
|
||||
&self,
|
||||
descriptor: &TextureDescriptorRef,
|
||||
offset: u64,
|
||||
) -> Option<Texture> {
|
||||
unsafe {
|
||||
let ptr: *mut MTLTexture = msg_send![self, newTextureWithDescriptor:descriptor
|
||||
offset:offset];
|
||||
if !ptr.is_null() {
|
||||
Some(Texture::from_ptr(ptr))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlheapdescriptor/>
|
||||
pub enum MTLHeapDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLHeapDescriptor;
|
||||
pub struct HeapDescriptor;
|
||||
}
|
||||
|
||||
impl HeapDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLHeapDescriptor);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HeapDescriptorRef {
|
||||
pub fn cpu_cache_mode(&self) -> MTLCPUCacheMode {
|
||||
unsafe { msg_send![self, cpuCacheMode] }
|
||||
}
|
||||
|
||||
pub fn set_cpu_cache_mode(&self, mode: MTLCPUCacheMode) {
|
||||
unsafe { msg_send![self, setCpuCacheMode: mode] }
|
||||
}
|
||||
|
||||
pub fn storage_mode(&self) -> MTLStorageMode {
|
||||
unsafe { msg_send![self, storageMode] }
|
||||
}
|
||||
|
||||
pub fn set_storage_mode(&self, mode: MTLStorageMode) {
|
||||
unsafe { msg_send![self, setStorageMode: mode] }
|
||||
}
|
||||
|
||||
pub fn size(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, size] }
|
||||
}
|
||||
|
||||
pub fn set_size(&self, size: NSUInteger) {
|
||||
unsafe { msg_send![self, setSize: size] }
|
||||
}
|
||||
|
||||
/// Only available on macos(10.15), ios(13.0)
|
||||
pub fn hazard_tracking_mode(&self) -> MTLHazardTrackingMode {
|
||||
unsafe { msg_send![self, hazardTrackingMode] }
|
||||
}
|
||||
|
||||
/// Only available on macos(10.15), ios(13.0)
|
||||
pub fn resource_options(&self) -> MTLResourceOptions {
|
||||
unsafe { msg_send![self, resourceOptions] }
|
||||
}
|
||||
|
||||
/// Only available on macos(10.15), ios(13.0)
|
||||
pub fn heap_type(&self) -> MTLHeapType {
|
||||
unsafe { msg_send![self, type] }
|
||||
}
|
||||
}
|
||||
337
third-party/vendor/metal/src/indirect_encoder.rs
vendored
Normal file
337
third-party/vendor/metal/src/indirect_encoder.rs
vendored
Normal file
|
|
@ -0,0 +1,337 @@
|
|||
use super::*;
|
||||
|
||||
bitflags! {
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlindirectcommandtype/>
|
||||
#[allow(non_upper_case_globals)]
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct MTLIndirectCommandType: NSUInteger {
|
||||
const Draw = 1 << 0;
|
||||
const DrawIndexed = 1 << 1;
|
||||
const DrawPatches = 1 << 2;
|
||||
const DrawIndexedPatches = 1 << 3;
|
||||
const ConcurrentDispatch = 1 << 4;
|
||||
const ConcurrentDispatchThreads = 1 << 5;
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlindirectcommandbufferdescriptor/>
|
||||
pub enum MTLIndirectCommandBufferDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLIndirectCommandBufferDescriptor;
|
||||
pub struct IndirectCommandBufferDescriptor;
|
||||
}
|
||||
|
||||
impl IndirectCommandBufferDescriptorRef {
|
||||
pub fn command_types(&self) -> MTLIndirectCommandType {
|
||||
unsafe { msg_send![self, commandTypes] }
|
||||
}
|
||||
|
||||
pub fn set_command_types(&self, types: MTLIndirectCommandType) {
|
||||
unsafe { msg_send![self, setCommandTypes: types] }
|
||||
}
|
||||
|
||||
pub fn inherit_buffers(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, inheritBuffers] }
|
||||
}
|
||||
|
||||
pub fn set_inherit_buffers(&self, inherit: bool) {
|
||||
unsafe { msg_send![self, setInheritBuffers: inherit] }
|
||||
}
|
||||
|
||||
pub fn inherit_pipeline_state(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, inheritPipelineState] }
|
||||
}
|
||||
|
||||
pub fn set_inherit_pipeline_state(&self, inherit: bool) {
|
||||
unsafe { msg_send![self, setInheritPipelineState: inherit] }
|
||||
}
|
||||
|
||||
pub fn max_vertex_buffer_bind_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, maxVertexBufferBindCount] }
|
||||
}
|
||||
|
||||
pub fn set_max_vertex_buffer_bind_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setMaxVertexBufferBindCount: count] }
|
||||
}
|
||||
|
||||
pub fn max_fragment_buffer_bind_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, maxFragmentBufferBindCount] }
|
||||
}
|
||||
|
||||
pub fn set_max_fragment_buffer_bind_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setMaxFragmentBufferBindCount: count] }
|
||||
}
|
||||
|
||||
pub fn max_kernel_buffer_bind_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, maxKernelBufferBindCount] }
|
||||
}
|
||||
|
||||
pub fn set_max_kernel_buffer_bind_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setMaxKernelBufferBindCount: count] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlindirectcommandbuffer/>
|
||||
pub enum MTLIndirectCommandBuffer {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLIndirectCommandBuffer;
|
||||
pub struct IndirectCommandBuffer;
|
||||
type ParentType = Resource;
|
||||
}
|
||||
|
||||
impl IndirectCommandBufferRef {
|
||||
pub fn size(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, size] }
|
||||
}
|
||||
|
||||
pub fn indirect_render_command_at_index(&self, index: NSUInteger) -> &IndirectRenderCommandRef {
|
||||
unsafe { msg_send![self, indirectRenderCommandAtIndex: index] }
|
||||
}
|
||||
|
||||
pub fn indirect_compute_command_at_index(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
) -> &IndirectComputeCommandRef {
|
||||
unsafe { msg_send![self, indirectComputeCommandAtIndex: index] }
|
||||
}
|
||||
|
||||
pub fn reset_with_range(&self, range: crate::NSRange) {
|
||||
unsafe { msg_send![self, resetWithRange: range] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlindirectrendercommand/>
|
||||
pub enum MTLIndirectRenderCommand {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLIndirectRenderCommand;
|
||||
pub struct IndirectRenderCommand;
|
||||
}
|
||||
|
||||
impl IndirectRenderCommandRef {
|
||||
pub fn set_render_pipeline_state(&self, pipeline_state: &RenderPipelineStateRef) {
|
||||
unsafe { msg_send![self, setRenderPipelineState: pipeline_state] }
|
||||
}
|
||||
|
||||
pub fn set_vertex_buffer(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
buffer: Option<&BufferRef>,
|
||||
offset: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self,
|
||||
setVertexBuffer: buffer
|
||||
offset: offset
|
||||
atIndex: index
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_fragment_buffer(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
buffer: Option<&BufferRef>,
|
||||
offset: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self,
|
||||
setFragmentBuffer:buffer
|
||||
offset:offset
|
||||
atIndex:index
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_primitives(
|
||||
&self,
|
||||
primitive_type: MTLPrimitiveType,
|
||||
vertex_start: NSUInteger,
|
||||
vertex_count: NSUInteger,
|
||||
instance_count: NSUInteger,
|
||||
base_instance: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self,
|
||||
drawPrimitives: primitive_type
|
||||
vertexStart: vertex_start
|
||||
vertexCount: vertex_count
|
||||
instanceCount: instance_count
|
||||
baseInstance: base_instance
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_indexed_primitives(
|
||||
&self,
|
||||
primitive_type: MTLPrimitiveType,
|
||||
index_count: NSUInteger,
|
||||
index_type: MTLIndexType,
|
||||
index_buffer: &BufferRef,
|
||||
index_buffer_offset: NSUInteger,
|
||||
instance_count: NSUInteger,
|
||||
base_vertex: NSUInteger,
|
||||
base_instance: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self,
|
||||
drawIndexedPrimitives: primitive_type
|
||||
indexCount: index_count
|
||||
indexType: index_type
|
||||
indexBuffer: index_buffer
|
||||
indexBufferOffset: index_buffer_offset
|
||||
instanceCount: instance_count
|
||||
baseVertex: base_vertex
|
||||
baseInstance: base_instance
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_patches(
|
||||
&self,
|
||||
number_of_patch_control_points: NSUInteger,
|
||||
patch_start: NSUInteger,
|
||||
patch_count: NSUInteger,
|
||||
patch_index_buffer: &BufferRef,
|
||||
patch_index_buffer_offset: NSUInteger,
|
||||
instance_count: NSUInteger,
|
||||
base_instance: NSUInteger,
|
||||
tesselation_factor_buffer: &BufferRef,
|
||||
tesselation_factor_buffer_offset: NSUInteger,
|
||||
tesselation_factor_buffer_instance_stride: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self,
|
||||
drawPatches: number_of_patch_control_points
|
||||
patchStart: patch_start
|
||||
patchCount: patch_count
|
||||
patchIndexBuffer: patch_index_buffer
|
||||
patchIndexBufferOffset: patch_index_buffer_offset
|
||||
instanceCount: instance_count
|
||||
baseInstance: base_instance
|
||||
tessellationFactorBuffer: tesselation_factor_buffer
|
||||
tessellationFactorBufferOffset: tesselation_factor_buffer_offset
|
||||
tessellationFactorBufferInstanceStride: tesselation_factor_buffer_instance_stride
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_indexed_patches(
|
||||
&self,
|
||||
number_of_patch_control_points: NSUInteger,
|
||||
patch_start: NSUInteger,
|
||||
patch_count: NSUInteger,
|
||||
patch_index_buffer: &BufferRef,
|
||||
patch_index_buffer_offset: NSUInteger,
|
||||
control_point_index_buffer: &BufferRef,
|
||||
control_point_index_buffer_offset: NSUInteger,
|
||||
instance_count: NSUInteger,
|
||||
base_instance: NSUInteger,
|
||||
tesselation_factor_buffer: &BufferRef,
|
||||
tesselation_factor_buffer_offset: NSUInteger,
|
||||
tesselation_factor_buffer_instance_stride: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self,
|
||||
drawIndexedPatches: number_of_patch_control_points
|
||||
patchStart: patch_start
|
||||
patchCount: patch_count
|
||||
patchIndexBuffer: patch_index_buffer
|
||||
patchIndexBufferOffset: patch_index_buffer_offset
|
||||
controlPointIndexBuffer: control_point_index_buffer
|
||||
controlPointIndexBufferOffset: control_point_index_buffer_offset
|
||||
instanceCount: instance_count
|
||||
baseInstance: base_instance
|
||||
tessellationFactorBuffer: tesselation_factor_buffer
|
||||
tessellationFactorBufferOffset: tesselation_factor_buffer_offset
|
||||
tessellationFactorBufferInstanceStride: tesselation_factor_buffer_instance_stride
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset(&self) {
|
||||
unsafe { msg_send![self, reset] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlindirectcomputecommand/>
|
||||
pub enum MTLIndirectComputeCommand {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLIndirectComputeCommand;
|
||||
pub struct IndirectComputeCommand;
|
||||
}
|
||||
|
||||
impl IndirectComputeCommandRef {
|
||||
pub fn set_compute_pipeline_state(&self, state: &ComputePipelineStateRef) {
|
||||
unsafe { msg_send![self, setComputePipelineState: state] }
|
||||
}
|
||||
|
||||
pub fn set_kernel_buffer(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
buffer: Option<&BufferRef>,
|
||||
offset: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self,
|
||||
setKernelBuffer: buffer
|
||||
offset: offset
|
||||
atIndex: index
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_threadgroup_memory_length(&self, index: NSUInteger, length: NSUInteger) {
|
||||
unsafe {
|
||||
msg_send![self,
|
||||
setThreadgroupMemoryLength: length
|
||||
atIndex: index
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_stage_in_region(&self, region: MTLRegion) {
|
||||
unsafe { msg_send![self, setStageInRegion: region] }
|
||||
}
|
||||
|
||||
pub fn set_barrier(&self) {
|
||||
unsafe { msg_send![self, setBarrier] }
|
||||
}
|
||||
|
||||
pub fn clear_barrier(&self) {
|
||||
unsafe { msg_send![self, clearBarrier] }
|
||||
}
|
||||
|
||||
pub fn concurrent_dispatch_threadgroups(
|
||||
&self,
|
||||
thread_groups_per_grid: MTLSize,
|
||||
threads_per_threadgroup: MTLSize,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self,
|
||||
concurrentDispatchThreadgroups: thread_groups_per_grid
|
||||
threadsPerThreadgroup: threads_per_threadgroup
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn concurrent_dispatch_threads(
|
||||
&self,
|
||||
thread_groups_per_grid: MTLSize,
|
||||
threads_per_threadgroup: MTLSize,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self,
|
||||
concurrentDispatchThreads: thread_groups_per_grid
|
||||
threadsPerThreadgroup: threads_per_threadgroup
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset(&self) {
|
||||
unsafe { msg_send![self, reset] }
|
||||
}
|
||||
}
|
||||
652
third-party/vendor/metal/src/lib.rs
vendored
Normal file
652
third-party/vendor/metal/src/lib.rs
vendored
Normal file
|
|
@ -0,0 +1,652 @@
|
|||
// Copyright 2023 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
#![allow(deprecated)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(non_upper_case_globals)]
|
||||
|
||||
#[macro_use]
|
||||
pub extern crate bitflags;
|
||||
#[macro_use]
|
||||
pub extern crate log;
|
||||
#[macro_use]
|
||||
pub extern crate objc;
|
||||
#[macro_use]
|
||||
pub extern crate foreign_types;
|
||||
#[macro_use]
|
||||
pub extern crate paste;
|
||||
|
||||
use std::{
|
||||
borrow::{Borrow, ToOwned},
|
||||
marker::PhantomData,
|
||||
mem,
|
||||
ops::Deref,
|
||||
os::raw::c_void,
|
||||
};
|
||||
|
||||
use core_graphics_types::{base::CGFloat, geometry::CGSize};
|
||||
use foreign_types::ForeignType;
|
||||
use objc::runtime::{Object, NO, YES};
|
||||
|
||||
/// See <https://developer.apple.com/documentation/objectivec/nsinteger>
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub type NSInteger = i64;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/objectivec/nsinteger>
|
||||
#[cfg(not(target_pointer_width = "64"))]
|
||||
pub type NSInteger = i32;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/objectivec/nsuinteger>
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub type NSUInteger = u64;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/objectivec/nsuinteger>
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub type NSUInteger = u32;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/foundation/nsrange>
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct NSRange {
|
||||
pub location: NSUInteger,
|
||||
pub length: NSUInteger,
|
||||
}
|
||||
|
||||
impl NSRange {
|
||||
#[inline]
|
||||
pub fn new(location: NSUInteger, length: NSUInteger) -> NSRange {
|
||||
NSRange { location, length }
|
||||
}
|
||||
}
|
||||
|
||||
fn nsstring_as_str(nsstr: &objc::runtime::Object) -> &str {
|
||||
let bytes = unsafe {
|
||||
let bytes: *const std::os::raw::c_char = msg_send![nsstr, UTF8String];
|
||||
bytes as *const u8
|
||||
};
|
||||
let len: NSUInteger = unsafe { msg_send![nsstr, length] };
|
||||
unsafe {
|
||||
let bytes = std::slice::from_raw_parts(bytes, len as usize);
|
||||
std::str::from_utf8(bytes).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
fn nsstring_from_str(string: &str) -> *mut objc::runtime::Object {
|
||||
const UTF8_ENCODING: usize = 4;
|
||||
|
||||
let cls = class!(NSString);
|
||||
let bytes = string.as_ptr() as *const c_void;
|
||||
unsafe {
|
||||
let obj: *mut objc::runtime::Object = msg_send![cls, alloc];
|
||||
let obj: *mut objc::runtime::Object = msg_send![
|
||||
obj,
|
||||
initWithBytes:bytes
|
||||
length:string.len()
|
||||
encoding:UTF8_ENCODING
|
||||
];
|
||||
let _: *mut c_void = msg_send![obj, autorelease];
|
||||
obj
|
||||
}
|
||||
}
|
||||
|
||||
/// Define a Rust wrapper for an Objective-C opaque type.
|
||||
///
|
||||
/// This macro adapts the `foreign-types` crate's [`foreign_type!`]
|
||||
/// macro to Objective-C, defining Rust types that represent owned and
|
||||
/// borrowed forms of some underlying Objective-C type, using
|
||||
/// Objective-C's reference counting to manage its lifetime.
|
||||
///
|
||||
/// Given a use of the form:
|
||||
///
|
||||
/// ```ignore
|
||||
/// foreign_obj_type! {
|
||||
/// type CType = MTLBuffer; // underlying Objective-C type
|
||||
/// pub struct Buffer; // owned Rust type
|
||||
/// pub struct BufferRef; // borrowed Rust type
|
||||
/// type ParentType = ResourceRef; // borrowed parent class
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// This defines the types `Buffer` and `BufferRef` as owning and
|
||||
/// non-owning types, analogous to `String` and `str`, that manage
|
||||
/// some underlying `*mut MTLBuffer`:
|
||||
///
|
||||
/// - Both `Buffer` and `BufferRef` implement [`obj::Message`], indicating
|
||||
/// that they can be sent Objective-C messages.
|
||||
///
|
||||
/// - Dropping a `Buffer` sends the underlying `MTLBuffer` a `release`
|
||||
/// message, and cloning a `BufferRef` sends a `retain` message and
|
||||
/// returns a new `Buffer`.
|
||||
///
|
||||
/// - `Buffer` dereferences to `BufferRef`.
|
||||
///
|
||||
/// - `BufferRef` dereferences to its parent type `ResourceRef`. The
|
||||
/// `ParentType` component is optional; if omitted, the `Ref` type
|
||||
/// doesn't implement `Deref` or `DerefMut`.
|
||||
///
|
||||
/// - Both `Buffer` and `BufferRef` implement `std::fmt::Debug`,
|
||||
/// sending an Objective-C `debugDescription` message to the
|
||||
/// underlying `MTLBuffer`.
|
||||
///
|
||||
/// Following the `foreign_types` crate's nomenclature, the `Ref`
|
||||
/// suffix indicates that `BufferRef` and `ResourceRef` are non-owning
|
||||
/// types, used *by reference*, like `&BufferRef` or `&ResourceRef`.
|
||||
/// These types are not, themselves, references.
|
||||
macro_rules! foreign_obj_type {
|
||||
{
|
||||
type CType = $raw_ident:ident;
|
||||
pub struct $owned_ident:ident;
|
||||
type ParentType = $parent_ident:ident;
|
||||
} => {
|
||||
foreign_obj_type! {
|
||||
type CType = $raw_ident;
|
||||
pub struct $owned_ident;
|
||||
}
|
||||
|
||||
impl ::std::ops::Deref for paste!{[<$owned_ident Ref>]} {
|
||||
type Target = paste!{[<$parent_ident Ref>]};
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &Self::Target {
|
||||
unsafe { &*(self as *const Self as *const Self::Target) }
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::convert::From<$owned_ident> for $parent_ident {
|
||||
fn from(item: $owned_ident) -> Self {
|
||||
unsafe { Self::from_ptr(::std::mem::transmute(item.into_ptr())) }
|
||||
}
|
||||
}
|
||||
};
|
||||
{
|
||||
type CType = $raw_ident:ident;
|
||||
pub struct $owned_ident:ident;
|
||||
} => {
|
||||
foreign_type! {
|
||||
pub unsafe type $owned_ident: Sync + Send {
|
||||
type CType = $raw_ident;
|
||||
fn drop = crate::obj_drop;
|
||||
fn clone = crate::obj_clone;
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl ::objc::Message for $raw_ident {
|
||||
}
|
||||
unsafe impl ::objc::Message for paste!{[<$owned_ident Ref>]} {
|
||||
}
|
||||
|
||||
impl ::std::fmt::Debug for paste!{[<$owned_ident Ref>]} {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
unsafe {
|
||||
let string: *mut ::objc::runtime::Object = msg_send![self, debugDescription];
|
||||
write!(f, "{}", crate::nsstring_as_str(&*string))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::fmt::Debug for $owned_ident {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
::std::ops::Deref::deref(self).fmt(f)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! try_objc {
|
||||
{
|
||||
$err_name: ident => $body:expr
|
||||
} => {
|
||||
{
|
||||
let mut $err_name: *mut Object = ::std::ptr::null_mut();
|
||||
let value = $body;
|
||||
if !$err_name.is_null() {
|
||||
let desc: *mut Object = msg_send![$err_name, localizedDescription];
|
||||
let compile_error: *const std::os::raw::c_char = msg_send![desc, UTF8String];
|
||||
let message = CStr::from_ptr(compile_error).to_string_lossy().into_owned();
|
||||
return Err(message);
|
||||
}
|
||||
value
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! msg_send_bool {
|
||||
($obj:expr, $name:ident) => {{
|
||||
match msg_send![$obj, $name] {
|
||||
YES => true,
|
||||
NO => false,
|
||||
#[cfg(not(target_arch = "aarch64"))]
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}};
|
||||
($obj:expr, $name:ident : $arg:expr) => {{
|
||||
match msg_send![$obj, $name: $arg] {
|
||||
YES => true,
|
||||
NO => false,
|
||||
#[cfg(not(target_arch = "aarch64"))]
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! msg_send_bool_error_check {
|
||||
($obj:expr, $name:ident: $arg:expr) => {{
|
||||
let mut err: *mut Object = ptr::null_mut();
|
||||
let result: BOOL = msg_send![$obj, $name:$arg
|
||||
error:&mut err];
|
||||
if !err.is_null() {
|
||||
let desc: *mut Object = msg_send![err, localizedDescription];
|
||||
let c_msg: *const c_char = msg_send![desc, UTF8String];
|
||||
let message = CStr::from_ptr(c_msg).to_string_lossy().into_owned();
|
||||
Err(message)
|
||||
} else {
|
||||
match result {
|
||||
YES => Ok(true),
|
||||
NO => Ok(false),
|
||||
#[cfg(not(target_arch = "aarch64"))]
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/foundation/nsarray>
|
||||
pub struct NSArray<T> {
|
||||
_phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
pub struct Array<T>(*mut NSArray<T>)
|
||||
where
|
||||
T: ForeignType + 'static,
|
||||
T::Ref: objc::Message + 'static;
|
||||
|
||||
pub struct ArrayRef<T>(foreign_types::Opaque, PhantomData<T>)
|
||||
where
|
||||
T: ForeignType + 'static,
|
||||
T::Ref: objc::Message + 'static;
|
||||
|
||||
impl<T> Drop for Array<T>
|
||||
where
|
||||
T: ForeignType + 'static,
|
||||
T::Ref: objc::Message + 'static,
|
||||
{
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
let () = msg_send![self.0, release];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for Array<T>
|
||||
where
|
||||
T: ForeignType + 'static,
|
||||
T::Ref: objc::Message + 'static,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
unsafe { Array(msg_send![self.0, retain]) }
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T> objc::Message for NSArray<T>
|
||||
where
|
||||
T: ForeignType + 'static,
|
||||
T::Ref: objc::Message + 'static,
|
||||
{
|
||||
}
|
||||
|
||||
unsafe impl<T> objc::Message for ArrayRef<T>
|
||||
where
|
||||
T: ForeignType + 'static,
|
||||
T::Ref: objc::Message + 'static,
|
||||
{
|
||||
}
|
||||
|
||||
impl<T> Array<T>
|
||||
where
|
||||
T: ForeignType + 'static,
|
||||
T::Ref: objc::Message + 'static,
|
||||
{
|
||||
pub fn from_slice<'a>(s: &[&T::Ref]) -> &'a ArrayRef<T> {
|
||||
unsafe {
|
||||
let class = class!(NSArray);
|
||||
msg_send![class, arrayWithObjects: s.as_ptr() count: s.len()]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_owned_slice<'a>(s: &[T]) -> &'a ArrayRef<T> {
|
||||
unsafe {
|
||||
let class = class!(NSArray);
|
||||
msg_send![class, arrayWithObjects: s.as_ptr() count: s.len()]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T> foreign_types::ForeignType for Array<T>
|
||||
where
|
||||
T: ForeignType + 'static,
|
||||
T::Ref: objc::Message + 'static,
|
||||
{
|
||||
type CType = NSArray<T>;
|
||||
type Ref = ArrayRef<T>;
|
||||
|
||||
unsafe fn from_ptr(p: *mut NSArray<T>) -> Self {
|
||||
Array(p)
|
||||
}
|
||||
|
||||
fn as_ptr(&self) -> *mut NSArray<T> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T> foreign_types::ForeignTypeRef for ArrayRef<T>
|
||||
where
|
||||
T: ForeignType + 'static,
|
||||
T::Ref: objc::Message + 'static,
|
||||
{
|
||||
type CType = NSArray<T>;
|
||||
}
|
||||
|
||||
impl<T> Deref for Array<T>
|
||||
where
|
||||
T: ForeignType + 'static,
|
||||
T::Ref: objc::Message + 'static,
|
||||
{
|
||||
type Target = ArrayRef<T>;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &ArrayRef<T> {
|
||||
unsafe { mem::transmute(self.as_ptr()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Borrow<ArrayRef<T>> for Array<T>
|
||||
where
|
||||
T: ForeignType + 'static,
|
||||
T::Ref: objc::Message + 'static,
|
||||
{
|
||||
fn borrow(&self) -> &ArrayRef<T> {
|
||||
unsafe { mem::transmute(self.as_ptr()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ToOwned for ArrayRef<T>
|
||||
where
|
||||
T: ForeignType + 'static,
|
||||
T::Ref: objc::Message + 'static,
|
||||
{
|
||||
type Owned = Array<T>;
|
||||
|
||||
fn to_owned(&self) -> Array<T> {
|
||||
unsafe { Array::from_ptr(msg_send![self, retain]) }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/quartzcore/cametaldrawable>
|
||||
pub enum CAMetalDrawable {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = CAMetalDrawable;
|
||||
pub struct MetalDrawable;
|
||||
type ParentType = Drawable;
|
||||
}
|
||||
|
||||
impl MetalDrawableRef {
|
||||
pub fn texture(&self) -> &TextureRef {
|
||||
unsafe { msg_send![self, texture] }
|
||||
}
|
||||
}
|
||||
|
||||
pub enum NSObject {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = NSObject;
|
||||
pub struct NsObject;
|
||||
}
|
||||
|
||||
impl NsObjectRef {
|
||||
pub fn conforms_to_protocol<T>(&self) -> Result<bool, String> {
|
||||
let name = ::std::any::type_name::<T>();
|
||||
if let Some(name) = name.split("::").last() {
|
||||
if let Some(protocol) = objc::runtime::Protocol::get(name) {
|
||||
Ok(unsafe { msg_send![self, conformsToProtocol: protocol] })
|
||||
} else {
|
||||
Err(format!("Can not find the protocol for type: {}.", name))
|
||||
}
|
||||
} else {
|
||||
Err(format!("Unexpected type name: {}.", name))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// See <https://developer.apple.com/documentation/quartzcore/cametallayer>
|
||||
pub enum CAMetalLayer {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = CAMetalLayer;
|
||||
pub struct MetalLayer;
|
||||
}
|
||||
|
||||
impl MetalLayer {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(CAMetalLayer);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MetalLayerRef {
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
|
||||
pub fn set_device(&self, device: &DeviceRef) {
|
||||
unsafe { msg_send![self, setDevice: device] }
|
||||
}
|
||||
|
||||
pub fn pixel_format(&self) -> MTLPixelFormat {
|
||||
unsafe { msg_send![self, pixelFormat] }
|
||||
}
|
||||
|
||||
pub fn set_pixel_format(&self, pixel_format: MTLPixelFormat) {
|
||||
unsafe { msg_send![self, setPixelFormat: pixel_format] }
|
||||
}
|
||||
|
||||
pub fn drawable_size(&self) -> CGSize {
|
||||
unsafe { msg_send![self, drawableSize] }
|
||||
}
|
||||
|
||||
pub fn set_drawable_size(&self, size: CGSize) {
|
||||
unsafe { msg_send![self, setDrawableSize: size] }
|
||||
}
|
||||
|
||||
pub fn presents_with_transaction(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, presentsWithTransaction] }
|
||||
}
|
||||
|
||||
pub fn set_presents_with_transaction(&self, transaction: bool) {
|
||||
unsafe { msg_send![self, setPresentsWithTransaction: transaction] }
|
||||
}
|
||||
|
||||
pub fn display_sync_enabled(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, displaySyncEnabled] }
|
||||
}
|
||||
|
||||
pub fn set_display_sync_enabled(&self, enabled: bool) {
|
||||
unsafe { msg_send![self, setDisplaySyncEnabled: enabled] }
|
||||
}
|
||||
|
||||
pub fn maximum_drawable_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, maximumDrawableCount] }
|
||||
}
|
||||
|
||||
pub fn set_maximum_drawable_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setMaximumDrawableCount: count] }
|
||||
}
|
||||
|
||||
pub fn set_edge_antialiasing_mask(&self, mask: u64) {
|
||||
unsafe { msg_send![self, setEdgeAntialiasingMask: mask] }
|
||||
}
|
||||
|
||||
pub fn set_masks_to_bounds(&self, masks: bool) {
|
||||
unsafe { msg_send![self, setMasksToBounds: masks] }
|
||||
}
|
||||
|
||||
pub fn remove_all_animations(&self) {
|
||||
unsafe { msg_send![self, removeAllAnimations] }
|
||||
}
|
||||
|
||||
pub fn next_drawable(&self) -> Option<&MetalDrawableRef> {
|
||||
unsafe { msg_send![self, nextDrawable] }
|
||||
}
|
||||
|
||||
pub fn contents_scale(&self) -> CGFloat {
|
||||
unsafe { msg_send![self, contentsScale] }
|
||||
}
|
||||
|
||||
pub fn set_contents_scale(&self, scale: CGFloat) {
|
||||
unsafe { msg_send![self, setContentsScale: scale] }
|
||||
}
|
||||
|
||||
/// [framebufferOnly Apple Docs](https://developer.apple.com/documentation/metal/mtltexture/1515749-framebufferonly?language=objc)
|
||||
pub fn framebuffer_only(&self) -> bool {
|
||||
unsafe { msg_send_bool!(self, framebufferOnly) }
|
||||
}
|
||||
|
||||
pub fn set_framebuffer_only(&self, framebuffer_only: bool) {
|
||||
unsafe { msg_send![self, setFramebufferOnly: framebuffer_only] }
|
||||
}
|
||||
|
||||
pub fn is_opaque(&self) -> bool {
|
||||
unsafe { msg_send_bool!(self, isOpaque) }
|
||||
}
|
||||
|
||||
pub fn set_opaque(&self, opaque: bool) {
|
||||
unsafe { msg_send![self, setOpaque: opaque] }
|
||||
}
|
||||
|
||||
pub fn wants_extended_dynamic_range_content(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, wantsExtendedDynamicRangeContent] }
|
||||
}
|
||||
|
||||
pub fn set_wants_extended_dynamic_range_content(
|
||||
&self,
|
||||
wants_extended_dynamic_range_content: bool,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
setWantsExtendedDynamicRangeContent: wants_extended_dynamic_range_content
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod accelerator_structure;
|
||||
mod argument;
|
||||
mod buffer;
|
||||
mod capturedescriptor;
|
||||
mod capturemanager;
|
||||
mod commandbuffer;
|
||||
mod commandqueue;
|
||||
mod computepass;
|
||||
mod constants;
|
||||
mod counters;
|
||||
mod depthstencil;
|
||||
mod device;
|
||||
mod drawable;
|
||||
mod encoder;
|
||||
mod heap;
|
||||
mod indirect_encoder;
|
||||
mod library;
|
||||
#[cfg(feature = "mps")]
|
||||
pub mod mps;
|
||||
mod pipeline;
|
||||
mod renderpass;
|
||||
mod resource;
|
||||
mod sampler;
|
||||
mod sync;
|
||||
mod texture;
|
||||
mod types;
|
||||
mod vertexdescriptor;
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub use {
|
||||
accelerator_structure::*,
|
||||
argument::*,
|
||||
buffer::*,
|
||||
counters::*,
|
||||
computepass::*,
|
||||
capturedescriptor::*,
|
||||
capturemanager::*,
|
||||
commandbuffer::*,
|
||||
commandqueue::*,
|
||||
constants::*,
|
||||
depthstencil::*,
|
||||
device::*,
|
||||
drawable::*,
|
||||
encoder::*,
|
||||
heap::*,
|
||||
indirect_encoder::*,
|
||||
library::*,
|
||||
pipeline::*,
|
||||
renderpass::*,
|
||||
resource::*,
|
||||
sampler::*,
|
||||
texture::*,
|
||||
types::*,
|
||||
vertexdescriptor::*,
|
||||
sync::*,
|
||||
};
|
||||
|
||||
#[inline]
|
||||
unsafe fn obj_drop<T>(p: *mut T) {
|
||||
msg_send![(p as *mut Object), release]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn obj_clone<T: 'static>(p: *mut T) -> *mut T {
|
||||
msg_send![(p as *mut Object), retain]
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
type c_size_t = usize;
|
||||
|
||||
// TODO: expand supported interface
|
||||
/// See <https://developer.apple.com/documentation/foundation/nsurl>
|
||||
pub enum NSURL {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = NSURL;
|
||||
pub struct URL;
|
||||
}
|
||||
|
||||
impl URL {
|
||||
pub fn new_with_string(string: &str) -> Self {
|
||||
unsafe {
|
||||
let ns_str = crate::nsstring_from_str(string);
|
||||
let class = class!(NSURL);
|
||||
msg_send![class, URLWithString: ns_str]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl URLRef {
|
||||
pub fn absolute_string(&self) -> &str {
|
||||
unsafe {
|
||||
let absolute_string = msg_send![self, absoluteString];
|
||||
crate::nsstring_as_str(absolute_string)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn path(&self) -> &str {
|
||||
unsafe {
|
||||
let path = msg_send![self, path];
|
||||
crate::nsstring_as_str(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
901
third-party/vendor/metal/src/library.rs
vendored
Normal file
901
third-party/vendor/metal/src/library.rs
vendored
Normal file
|
|
@ -0,0 +1,901 @@
|
|||
// Copyright 2017 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
|
||||
use foreign_types::ForeignType;
|
||||
use objc::runtime::{Object, BOOL, NO, YES};
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::os::raw::{c_char, c_void};
|
||||
use std::ptr;
|
||||
|
||||
/// Only available on (macos(10.12), ios(10.0)
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlpatchtype/>
|
||||
#[repr(u64)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum MTLPatchType {
|
||||
None = 0,
|
||||
Triangle = 1,
|
||||
Quad = 2,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlvertexattribute/>
|
||||
pub enum MTLVertexAttribute {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLVertexAttribute;
|
||||
pub struct VertexAttribute;
|
||||
}
|
||||
|
||||
impl VertexAttributeRef {
|
||||
pub fn name(&self) -> &str {
|
||||
unsafe {
|
||||
let name = msg_send![self, name];
|
||||
crate::nsstring_as_str(name)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn attribute_index(&self) -> u64 {
|
||||
unsafe { msg_send![self, attributeIndex] }
|
||||
}
|
||||
|
||||
pub fn attribute_type(&self) -> MTLDataType {
|
||||
unsafe { msg_send![self, attributeType] }
|
||||
}
|
||||
|
||||
pub fn is_active(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isActive] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.12), ios(10.0)
|
||||
pub fn is_patch_data(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isPatchData] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.12), ios(10.0)
|
||||
pub fn is_patch_control_point_data(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isPatchControlPointData] }
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.12), ios(10.0))
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlattribute/>
|
||||
pub enum MTLAttribute {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLAttribute;
|
||||
pub struct Attribute;
|
||||
}
|
||||
|
||||
impl AttributeRef {
|
||||
pub fn name(&self) -> &str {
|
||||
unsafe {
|
||||
let name = msg_send![self, name];
|
||||
crate::nsstring_as_str(name)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn attribute_index(&self) -> u64 {
|
||||
unsafe { msg_send![self, attributeIndex] }
|
||||
}
|
||||
|
||||
pub fn attribute_type(&self) -> MTLDataType {
|
||||
unsafe { msg_send![self, attributeType] }
|
||||
}
|
||||
|
||||
pub fn is_active(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isActive] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.12), ios(10.0))
|
||||
pub fn is_patch_data(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isPatchData] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.12), ios(10.0))
|
||||
pub fn is_patch_control_point_data(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isPatchControlPointData] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlfunctiontype/>
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLFunctionType {
|
||||
Vertex = 1,
|
||||
Fragment = 2,
|
||||
Kernel = 3,
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
Visible = 5,
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
Intersection = 6,
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.12), ios(10.0))
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlfunctionconstant/>
|
||||
pub enum MTLFunctionConstant {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLFunctionConstant;
|
||||
pub struct FunctionConstant;
|
||||
}
|
||||
|
||||
impl FunctionConstantRef {
|
||||
pub fn name(&self) -> &str {
|
||||
unsafe {
|
||||
let name = msg_send![self, name];
|
||||
crate::nsstring_as_str(name)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn data_type(&self) -> MTLDataType {
|
||||
unsafe { msg_send![self, type] }
|
||||
}
|
||||
|
||||
pub fn index(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, index] }
|
||||
}
|
||||
|
||||
pub fn required(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, required] }
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlfunctionoptions/>
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct MTLFunctionOptions: NSUInteger {
|
||||
const None = 0;
|
||||
const CompileToBinary = 1 << 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlfunctiondescriptor/>
|
||||
pub enum MTLFunctionDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLFunctionDescriptor;
|
||||
pub struct FunctionDescriptor;
|
||||
}
|
||||
|
||||
impl FunctionDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLFunctionDescriptor);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FunctionDescriptorRef {
|
||||
pub fn name(&self) -> &str {
|
||||
unsafe {
|
||||
let name = msg_send![self, name];
|
||||
crate::nsstring_as_str(name)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_name(&self, name: &str) {
|
||||
unsafe {
|
||||
let ns_name = crate::nsstring_from_str(name);
|
||||
let () = msg_send![self, setName: ns_name];
|
||||
}
|
||||
}
|
||||
|
||||
pub fn specialized_name(&self) -> &str {
|
||||
unsafe {
|
||||
let name = msg_send![self, specializedName];
|
||||
crate::nsstring_as_str(name)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_specialized_name(&self, name: &str) {
|
||||
unsafe {
|
||||
let ns_name = crate::nsstring_from_str(name);
|
||||
let () = msg_send![self, setSpecializedName: ns_name];
|
||||
}
|
||||
}
|
||||
|
||||
pub fn constant_values(&self) -> &FunctionConstantValuesRef {
|
||||
unsafe { msg_send![self, constantValues] }
|
||||
}
|
||||
|
||||
pub fn set_constant_values(&self, values: &FunctionConstantValuesRef) {
|
||||
unsafe { msg_send![self, setConstantValues: values] }
|
||||
}
|
||||
|
||||
pub fn options(&self) -> MTLFunctionOptions {
|
||||
unsafe { msg_send![self, options] }
|
||||
}
|
||||
|
||||
pub fn set_options(&self, options: MTLFunctionOptions) {
|
||||
unsafe { msg_send![self, setOptions: options] }
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlintersectionfunctiondescriptor/>
|
||||
pub enum MTLIntersectionFunctionDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLIntersectionFunctionDescriptor;
|
||||
pub struct IntersectionFunctionDescriptor;
|
||||
type ParentType = FunctionDescriptor;
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlfunctionhandle/>
|
||||
pub enum MTLFunctionHandle {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLFunctionHandle;
|
||||
pub struct FunctionHandle;
|
||||
}
|
||||
|
||||
impl FunctionHandleRef {
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
unsafe {
|
||||
let ns_name = msg_send![self, name];
|
||||
crate::nsstring_as_str(ns_name)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn function_type(&self) -> MTLFunctionType {
|
||||
unsafe { msg_send![self, functionType] }
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// MTLVisibleFunctionTableDescriptor
|
||||
// MTLVisibleFunctionTable
|
||||
// MTLIntersectionFunctionSignature
|
||||
// MTLIntersectionFunctionTableDescriptor
|
||||
// MTLIntersectionFunctionTable
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlfunction/>
|
||||
pub enum MTLFunction {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLFunction;
|
||||
pub struct Function;
|
||||
}
|
||||
|
||||
impl FunctionRef {
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.12), ios(10.0))
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let ns_label = msg_send![self, label];
|
||||
crate::nsstring_as_str(ns_label)
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.12), ios(10.0))
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let ns_label = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: ns_label];
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
unsafe {
|
||||
let name = msg_send![self, name];
|
||||
crate::nsstring_as_str(name)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn function_type(&self) -> MTLFunctionType {
|
||||
unsafe { msg_send![self, functionType] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.12), ios(10.0))
|
||||
pub fn patch_type(&self) -> MTLPatchType {
|
||||
unsafe { msg_send![self, patchType] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.12), ios(10.0))
|
||||
pub fn patch_control_point_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, patchControlPointCount] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.12), ios(10.0))
|
||||
pub fn vertex_attributes(&self) -> &Array<VertexAttribute> {
|
||||
unsafe { msg_send![self, vertexAttributes] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.12), ios(10.0))
|
||||
pub fn stage_input_attributes(&self) -> &Array<Attribute> {
|
||||
unsafe { msg_send![self, stageInputAttributes] }
|
||||
}
|
||||
|
||||
pub fn new_argument_encoder(&self, buffer_index: NSUInteger) -> ArgumentEncoder {
|
||||
unsafe {
|
||||
let ptr = msg_send![self, newArgumentEncoderWithBufferIndex: buffer_index];
|
||||
ArgumentEncoder::from_ptr(ptr)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn function_constants_dictionary(&self) -> *mut Object {
|
||||
unsafe { msg_send![self, functionConstantsDictionary] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
pub fn options(&self) -> MTLFunctionOptions {
|
||||
unsafe { msg_send![self, options] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtllanguageversion/>
|
||||
#[repr(u64)]
|
||||
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub enum MTLLanguageVersion {
|
||||
V1_0 = 0x10000,
|
||||
V1_1 = 0x10001,
|
||||
V1_2 = 0x10002,
|
||||
V2_0 = 0x20000,
|
||||
V2_1 = 0x20001,
|
||||
V2_2 = 0x20002,
|
||||
/// available on macOS 11.0+, iOS 14.0+
|
||||
V2_3 = 0x20003,
|
||||
/// available on macOS 12.0+, iOS 15.0+
|
||||
V2_4 = 0x20004,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlfunctionconstantvalues/>
|
||||
pub enum MTLFunctionConstantValues {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLFunctionConstantValues;
|
||||
pub struct FunctionConstantValues;
|
||||
}
|
||||
|
||||
impl FunctionConstantValues {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLFunctionConstantValues);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FunctionConstantValuesRef {
|
||||
pub fn set_constant_value_at_index(
|
||||
&self,
|
||||
value: *const c_void,
|
||||
ty: MTLDataType,
|
||||
index: NSUInteger,
|
||||
) {
|
||||
unsafe { msg_send![self, setConstantValue:value type:ty atIndex:index] }
|
||||
}
|
||||
|
||||
pub fn set_constant_values_with_range(
|
||||
&self,
|
||||
values: *const c_void,
|
||||
ty: MTLDataType,
|
||||
range: NSRange,
|
||||
) {
|
||||
unsafe { msg_send![self, setConstantValues:values type:ty withRange:range] }
|
||||
}
|
||||
|
||||
pub fn set_constant_value_with_name(&self, value: *const c_void, ty: MTLDataType, name: &str) {
|
||||
unsafe {
|
||||
let ns_name = crate::nsstring_from_str(name);
|
||||
msg_send![self, setConstantValue:value type:ty withName:ns_name]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtllibrarytype/>
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLLibraryType {
|
||||
Executable = 0,
|
||||
Dynamic = 1,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcompileoptions/>
|
||||
pub enum MTLCompileOptions {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLCompileOptions;
|
||||
pub struct CompileOptions;
|
||||
}
|
||||
|
||||
impl CompileOptions {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLCompileOptions);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CompileOptionsRef {
|
||||
pub unsafe fn preprocessor_macros(&self) -> *mut Object {
|
||||
msg_send![self, preprocessorMacros]
|
||||
}
|
||||
|
||||
pub unsafe fn set_preprocessor_macros(&self, defines: *mut Object) {
|
||||
msg_send![self, setPreprocessorMacros: defines]
|
||||
}
|
||||
|
||||
pub fn is_fast_math_enabled(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, fastMathEnabled] }
|
||||
}
|
||||
|
||||
pub fn set_fast_math_enabled(&self, enabled: bool) {
|
||||
unsafe { msg_send![self, setFastMathEnabled: enabled] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.11), ios(9.0))
|
||||
pub fn language_version(&self) -> MTLLanguageVersion {
|
||||
unsafe { msg_send![self, languageVersion] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(10.11), ios(9.0))
|
||||
pub fn set_language_version(&self, version: MTLLanguageVersion) {
|
||||
unsafe { msg_send![self, setLanguageVersion: version] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
pub fn library_type(&self) -> MTLLibraryType {
|
||||
unsafe { msg_send![self, libraryType] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
pub fn set_library_type(&self, lib_type: MTLLibraryType) {
|
||||
unsafe { msg_send![self, setLibraryType: lib_type] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
pub fn install_name(&self) -> &str {
|
||||
unsafe {
|
||||
let name = msg_send![self, installName];
|
||||
crate::nsstring_as_str(name)
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
pub fn set_install_name(&self, name: &str) {
|
||||
unsafe {
|
||||
let install_name = crate::nsstring_from_str(name);
|
||||
let () = msg_send![self, setInstallName: install_name];
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
///
|
||||
/// Marshal to Rust Vec
|
||||
pub fn libraries(&self) -> Vec<DynamicLibrary> {
|
||||
unsafe {
|
||||
let libraries: *mut Object = msg_send![self, libraries];
|
||||
let count: NSUInteger = msg_send![libraries, count];
|
||||
let ret = (0..count)
|
||||
.map(|i| {
|
||||
let lib = msg_send![libraries, objectAtIndex: i];
|
||||
DynamicLibrary::from_ptr(lib)
|
||||
})
|
||||
.collect();
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
///
|
||||
/// As raw NSArray
|
||||
pub fn libraries_as_nsarray(&self) -> &ArrayRef<DynamicLibrary> {
|
||||
unsafe { msg_send![self, libraries] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
///
|
||||
/// Marshal from Rust slice
|
||||
pub fn set_libraries(&self, libraries: &[&DynamicLibraryRef]) {
|
||||
let ns_array = Array::<DynamicLibrary>::from_slice(libraries);
|
||||
unsafe { msg_send![self, setLibraries: ns_array] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
///
|
||||
/// From raw NSArray
|
||||
pub fn set_libraries_nsarray(&self, libraries: &ArrayRef<DynamicLibrary>) {
|
||||
unsafe { msg_send![self, setLibraries: libraries] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), macCatalyst(14.0), ios(13.0))
|
||||
pub fn preserve_invariance(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, preserveInvariance] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), macCatalyst(14.0), ios(13.0))
|
||||
pub fn set_preserve_invariance(&self, preserve: bool) {
|
||||
unsafe { msg_send![self, setPreserveInvariance: preserve] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtllibraryerror/>
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLLibraryError {
|
||||
Unsupported = 1,
|
||||
Internal = 2,
|
||||
CompileFailure = 3,
|
||||
CompileWarning = 4,
|
||||
/// Only available on (macos(10.12), ios(10.0))
|
||||
FunctionNotFound = 5,
|
||||
/// Only available on (macos(10.12), ios(10.0))
|
||||
FileNotFound = 6,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtllibrary/>
|
||||
pub enum MTLLibrary {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLLibrary;
|
||||
pub struct Library;
|
||||
}
|
||||
|
||||
impl LibraryRef {
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: nslabel];
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: should rename to new_function
|
||||
pub fn get_function(
|
||||
&self,
|
||||
name: &str,
|
||||
constants: Option<FunctionConstantValues>,
|
||||
) -> Result<Function, String> {
|
||||
unsafe {
|
||||
let nsname = crate::nsstring_from_str(name);
|
||||
|
||||
let function: *mut MTLFunction = match constants {
|
||||
Some(c) => try_objc! { err => msg_send![self,
|
||||
newFunctionWithName: nsname.as_ref()
|
||||
constantValues: c.as_ref()
|
||||
error: &mut err
|
||||
]},
|
||||
None => msg_send![self, newFunctionWithName: nsname.as_ref()],
|
||||
};
|
||||
|
||||
if !function.is_null() {
|
||||
Ok(Function::from_ptr(function))
|
||||
} else {
|
||||
Err(format!("Function '{}' does not exist", name))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: get_function_async with completion handler
|
||||
|
||||
pub fn function_names(&self) -> Vec<String> {
|
||||
unsafe {
|
||||
let names: *mut Object = msg_send![self, functionNames];
|
||||
let count: NSUInteger = msg_send![names, count];
|
||||
let ret = (0..count)
|
||||
.map(|i| {
|
||||
let name = msg_send![names, objectAtIndex: i];
|
||||
nsstring_as_str(name).to_string()
|
||||
})
|
||||
.collect();
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
pub fn library_type(&self) -> MTLLibraryType {
|
||||
unsafe { msg_send![self, type] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
pub fn install_name(&self) -> Option<&str> {
|
||||
unsafe {
|
||||
let maybe_name: *mut Object = msg_send![self, installName];
|
||||
maybe_name.as_ref().map(crate::nsstring_as_str)
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
pub fn new_function_with_descriptor(
|
||||
&self,
|
||||
descriptor: &FunctionDescriptorRef,
|
||||
) -> Result<Function, String> {
|
||||
unsafe {
|
||||
let function: *mut MTLFunction = try_objc! {
|
||||
err => msg_send![self,
|
||||
newFunctionWithDescriptor: descriptor
|
||||
error: &mut err
|
||||
]
|
||||
};
|
||||
|
||||
if !function.is_null() {
|
||||
Ok(Function::from_ptr(function))
|
||||
} else {
|
||||
Err(String::from("new_function_with_descriptor() failed"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
pub fn new_intersection_function_with_descriptor(
|
||||
&self,
|
||||
descriptor: &IntersectionFunctionDescriptorRef,
|
||||
) -> Result<Function, String> {
|
||||
unsafe {
|
||||
let function: *mut MTLFunction = try_objc! {
|
||||
err => msg_send![self,
|
||||
newIntersectionFunctionWithDescriptor: descriptor
|
||||
error: &mut err
|
||||
]
|
||||
};
|
||||
|
||||
if !function.is_null() {
|
||||
Ok(Function::from_ptr(function))
|
||||
} else {
|
||||
Err(String::from(
|
||||
"new_intersection_function_with_descriptor() failed",
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtldynamiclibraryerror/>
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLDynamicLibraryError {
|
||||
None = 0,
|
||||
InvalidFile = 1,
|
||||
CompilationFailure = 2,
|
||||
UnresolvedInstallName = 3,
|
||||
DependencyLoadFailure = 4,
|
||||
Unsupported = 5,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtldynamiclibrary/>
|
||||
pub enum MTLDynamicLibrary {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLDynamicLibrary;
|
||||
pub struct DynamicLibrary;
|
||||
}
|
||||
|
||||
impl DynamicLibraryRef {
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: nslabel];
|
||||
}
|
||||
}
|
||||
|
||||
pub fn install_name(&self) -> &str {
|
||||
unsafe {
|
||||
let name = msg_send![self, installName];
|
||||
crate::nsstring_as_str(name)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn serialize_to_url(&self, url: &URLRef) -> Result<bool, String> {
|
||||
unsafe { msg_send_bool_error_check![self, serializeToURL: url] }
|
||||
}
|
||||
}
|
||||
|
||||
/// macOS 11.0+ iOS 14.0+
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlbinaryarchivedescriptor/>
|
||||
pub enum MTLBinaryArchiveDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLBinaryArchiveDescriptor;
|
||||
pub struct BinaryArchiveDescriptor;
|
||||
}
|
||||
|
||||
impl BinaryArchiveDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLBinaryArchiveDescriptor);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BinaryArchiveDescriptorRef {
|
||||
pub fn url(&self) -> &URLRef {
|
||||
unsafe { msg_send![self, url] }
|
||||
}
|
||||
pub fn set_url(&self, url: &URLRef) {
|
||||
unsafe { msg_send![self, setUrl: url] }
|
||||
}
|
||||
}
|
||||
|
||||
/// macOS 11.0+ iOS 14.0+
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlbinaryarchive/>
|
||||
pub enum MTLBinaryArchive {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLBinaryArchive;
|
||||
pub struct BinaryArchive;
|
||||
}
|
||||
|
||||
impl BinaryArchiveRef {
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: nslabel];
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_compute_pipeline_functions_with_descriptor(
|
||||
&self,
|
||||
descriptor: &ComputePipelineDescriptorRef,
|
||||
) -> Result<bool, String> {
|
||||
unsafe {
|
||||
msg_send_bool_error_check![self, addComputePipelineFunctionsWithDescriptor: descriptor]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_render_pipeline_functions_with_descriptor(
|
||||
&self,
|
||||
descriptor: &RenderPipelineDescriptorRef,
|
||||
) -> Result<bool, String> {
|
||||
unsafe {
|
||||
msg_send_bool_error_check![self, addRenderPipelineFunctionsWithDescriptor: descriptor]
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: addTileRenderPipelineFunctionsWithDescriptor
|
||||
// - (BOOL)addTileRenderPipelineFunctionsWithDescriptor:(MTLTileRenderPipelineDescriptor *)descriptor
|
||||
// error:(NSError * _Nullable *)error;
|
||||
|
||||
pub fn serialize_to_url(&self, url: &URLRef) -> Result<bool, String> {
|
||||
unsafe {
|
||||
let mut err: *mut Object = ptr::null_mut();
|
||||
let result: BOOL = msg_send![self, serializeToURL:url
|
||||
error:&mut err];
|
||||
if !err.is_null() {
|
||||
// FIXME: copy pasta
|
||||
let desc: *mut Object = msg_send![err, localizedDescription];
|
||||
let c_msg: *const c_char = msg_send![desc, UTF8String];
|
||||
let message = CStr::from_ptr(c_msg).to_string_lossy().into_owned();
|
||||
Err(message)
|
||||
} else {
|
||||
match result {
|
||||
YES => Ok(true),
|
||||
NO => Ok(false),
|
||||
#[cfg(not(target_arch = "aarch64"))]
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// macOS 11.0+ iOS 14.0+
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtllinkedfunctions/>
|
||||
pub enum MTLLinkedFunctions {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLLinkedFunctions;
|
||||
pub struct LinkedFunctions;
|
||||
}
|
||||
|
||||
impl LinkedFunctions {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLLinkedFunctions);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LinkedFunctionsRef {
|
||||
/// Marshal to Rust Vec
|
||||
pub fn functions(&self) -> Vec<Function> {
|
||||
unsafe {
|
||||
let functions: *mut Object = msg_send![self, functions];
|
||||
let count: NSUInteger = msg_send![functions, count];
|
||||
let ret = (0..count)
|
||||
.map(|i| {
|
||||
let f = msg_send![functions, objectAtIndex: i];
|
||||
Function::from_ptr(f)
|
||||
})
|
||||
.collect();
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
/// Marshal from Rust slice
|
||||
pub fn set_functions(&self, functions: &[&FunctionRef]) {
|
||||
let ns_array = Array::<Function>::from_slice(functions);
|
||||
unsafe { msg_send![self, setFunctions: ns_array] }
|
||||
}
|
||||
|
||||
/// Marshal to Rust Vec
|
||||
pub fn binary_functions(&self) -> Vec<Function> {
|
||||
unsafe {
|
||||
let functions: *mut Object = msg_send![self, binaryFunctions];
|
||||
let count: NSUInteger = msg_send![functions, count];
|
||||
let ret = (0..count)
|
||||
.map(|i| {
|
||||
let f = msg_send![functions, objectAtIndex: i];
|
||||
Function::from_ptr(f)
|
||||
})
|
||||
.collect();
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
/// Marshal from Rust slice
|
||||
pub fn set_binary_functions(&self, functions: &[&FunctionRef]) {
|
||||
let ns_array = Array::<Function>::from_slice(functions);
|
||||
unsafe { msg_send![self, setBinaryFunctions: ns_array] }
|
||||
}
|
||||
|
||||
// TODO: figure out NSDictionary wrapper
|
||||
// TODO: groups
|
||||
// @property (readwrite, nonatomic, copy, nullable) NSDictionary<NSString*, NSArray<id<MTLFunction>>*> *groups;
|
||||
}
|
||||
572
third-party/vendor/metal/src/mps.rs
vendored
Normal file
572
third-party/vendor/metal/src/mps.rs
vendored
Normal file
|
|
@ -0,0 +1,572 @@
|
|||
// Copyright 2020 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
|
||||
use objc::runtime::{BOOL, YES};
|
||||
|
||||
#[cfg_attr(feature = "link", link(name = "MetalPerformanceShaders", kind = "framework"))]
|
||||
extern "C" {
|
||||
fn MPSSupportsMTLDevice(device: *const std::ffi::c_void) -> BOOL;
|
||||
}
|
||||
|
||||
pub fn mps_supports_device(device: &DeviceRef) -> bool {
|
||||
let b: BOOL = unsafe {
|
||||
let ptr: *const DeviceRef = device;
|
||||
MPSSupportsMTLDevice(ptr as _)
|
||||
};
|
||||
b == YES
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpskernel>
|
||||
pub enum MPSKernel {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MPSKernel;
|
||||
pub struct Kernel;
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpsraydatatype>
|
||||
pub enum MPSRayDataType {
|
||||
OriginDirection = 0,
|
||||
OriginMinDistanceDirectionMaxDistance = 1,
|
||||
OriginMaskDirectionMaxDistance = 2,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpsraymaskoptions>
|
||||
#[allow(non_upper_case_globals)]
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct MPSRayMaskOptions: NSUInteger {
|
||||
/// Enable primitive masks
|
||||
const Primitive = 1;
|
||||
/// Enable instance masks
|
||||
const Instance = 2;
|
||||
}
|
||||
}
|
||||
|
||||
/// Options that determine the data contained in an intersection result.
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpsintersectiondatatype>
|
||||
pub enum MPSIntersectionDataType {
|
||||
Distance = 0,
|
||||
DistancePrimitiveIndex = 1,
|
||||
DistancePrimitiveIndexCoordinates = 2,
|
||||
DistancePrimitiveIndexInstanceIndex = 3,
|
||||
DistancePrimitiveIndexInstanceIndexCoordinates = 4,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpsintersectiontype>
|
||||
pub enum MPSIntersectionType {
|
||||
/// Find the closest intersection to the ray's origin along the ray direction.
|
||||
/// This is potentially slower than `Any` but is well suited to primary visibility rays.
|
||||
Nearest = 0,
|
||||
/// Find any intersection along the ray direction. This is potentially faster than `Nearest` and
|
||||
/// is well suited to shadow and occlusion rays.
|
||||
Any = 1,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpsraymaskoperator>
|
||||
pub enum MPSRayMaskOperator {
|
||||
/// Accept the intersection if `(primitive mask & ray mask) != 0`.
|
||||
And = 0,
|
||||
/// Accept the intersection if `~(primitive mask & ray mask) != 0`.
|
||||
NotAnd = 1,
|
||||
/// Accept the intersection if `(primitive mask | ray mask) != 0`.
|
||||
Or = 2,
|
||||
/// Accept the intersection if `~(primitive mask | ray mask) != 0`.
|
||||
NotOr = 3,
|
||||
/// Accept the intersection if `(primitive mask ^ ray mask) != 0`.
|
||||
/// Note that this is equivalent to the "!=" operator.
|
||||
Xor = 4,
|
||||
/// Accept the intersection if `~(primitive mask ^ ray mask) != 0`.
|
||||
/// Note that this is equivalent to the "==" operator.
|
||||
NotXor = 5,
|
||||
/// Accept the intersection if `(primitive mask < ray mask) != 0`.
|
||||
LessThan = 6,
|
||||
/// Accept the intersection if `(primitive mask <= ray mask) != 0`.
|
||||
LessThanOrEqualTo = 7,
|
||||
/// Accept the intersection if `(primitive mask > ray mask) != 0`.
|
||||
GreaterThan = 8,
|
||||
/// Accept the intersection if `(primitive mask >= ray mask) != 0`.
|
||||
GreaterThanOrEqualTo = 9,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpstriangleintersectiontesttype>
|
||||
pub enum MPSTriangleIntersectionTestType {
|
||||
/// Use the default ray/triangle intersection test
|
||||
Default = 0,
|
||||
/// Use a watertight ray/triangle intersection test which avoids gaps along shared triangle edges.
|
||||
/// Shared vertices may still have gaps.
|
||||
/// This intersection test may be slower than `Default`.
|
||||
Watertight = 1,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpsaccelerationstructurestatus>
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MPSAccelerationStructureStatus {
|
||||
Unbuilt = 0,
|
||||
Built = 1,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpsaccelerationstructureusage>
|
||||
#[allow(non_upper_case_globals)]
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct MPSAccelerationStructureUsage: NSUInteger {
|
||||
/// No usage options specified
|
||||
const None = 0;
|
||||
/// Option that enables support for refitting the acceleration structure after it has been built.
|
||||
const Refit = 1;
|
||||
/// Option indicating that the acceleration structure will be rebuilt frequently.
|
||||
const FrequentRebuild = 2;
|
||||
const PreferGPUBuild = 4;
|
||||
const PreferCPUBuild = 8;
|
||||
}
|
||||
}
|
||||
|
||||
/// A common bit for all floating point data types.
|
||||
const MPSDataTypeFloatBit: isize = 0x10000000;
|
||||
const MPSDataTypeSignedBit: isize = 0x20000000;
|
||||
const MPSDataTypeNormalizedBit: isize = 0x40000000;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpsdatatype>
|
||||
pub enum MPSDataType {
|
||||
Invalid = 0,
|
||||
|
||||
Float32 = MPSDataTypeFloatBit | 32,
|
||||
Float16 = MPSDataTypeFloatBit | 16,
|
||||
|
||||
// Signed integers.
|
||||
Int8 = MPSDataTypeSignedBit | 8,
|
||||
Int16 = MPSDataTypeSignedBit | 16,
|
||||
Int32 = MPSDataTypeSignedBit | 32,
|
||||
|
||||
// Unsigned integers. Range: [0, UTYPE_MAX]
|
||||
UInt8 = 8,
|
||||
UInt16 = 16,
|
||||
UInt32 = 32,
|
||||
|
||||
// Unsigned normalized. Range: [0, 1.0]
|
||||
Unorm1 = MPSDataTypeNormalizedBit | 1,
|
||||
Unorm8 = MPSDataTypeNormalizedBit | 8,
|
||||
}
|
||||
|
||||
/// A kernel that performs intersection tests between rays and geometry.
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpsrayintersector>
|
||||
pub enum MPSRayIntersector {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MPSRayIntersector;
|
||||
pub struct RayIntersector;
|
||||
type ParentType = Kernel;
|
||||
}
|
||||
|
||||
impl RayIntersector {
|
||||
pub fn from_device(device: &DeviceRef) -> Option<Self> {
|
||||
unsafe {
|
||||
let intersector: RayIntersector = msg_send![class!(MPSRayIntersector), alloc];
|
||||
let ptr: *mut Object = msg_send![intersector.as_ref(), initWithDevice: device];
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(intersector)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RayIntersectorRef {
|
||||
pub fn set_cull_mode(&self, mode: MTLCullMode) {
|
||||
unsafe { msg_send![self, setCullMode: mode] }
|
||||
}
|
||||
|
||||
pub fn set_front_facing_winding(&self, winding: MTLWinding) {
|
||||
unsafe { msg_send![self, setFrontFacingWinding: winding] }
|
||||
}
|
||||
|
||||
pub fn set_intersection_data_type(&self, options: MPSIntersectionDataType) {
|
||||
unsafe { msg_send![self, setIntersectionDataType: options] }
|
||||
}
|
||||
|
||||
pub fn set_intersection_stride(&self, stride: NSUInteger) {
|
||||
unsafe { msg_send![self, setIntersectionStride: stride] }
|
||||
}
|
||||
|
||||
pub fn set_ray_data_type(&self, ty: MPSRayDataType) {
|
||||
unsafe { msg_send![self, setRayDataType: ty] }
|
||||
}
|
||||
|
||||
pub fn set_ray_index_data_type(&self, ty: MPSDataType) {
|
||||
unsafe { msg_send![self, setRayIndexDataType: ty] }
|
||||
}
|
||||
|
||||
pub fn set_ray_mask(&self, ray_mask: u32) {
|
||||
unsafe { msg_send![self, setRayMask: ray_mask] }
|
||||
}
|
||||
|
||||
pub fn set_ray_mask_operator(&self, operator: MPSRayMaskOperator) {
|
||||
unsafe { msg_send![self, setRayMaskOperator: operator] }
|
||||
}
|
||||
|
||||
pub fn set_ray_mask_options(&self, options: MPSRayMaskOptions) {
|
||||
unsafe { msg_send![self, setRayMaskOptions: options] }
|
||||
}
|
||||
|
||||
pub fn set_ray_stride(&self, stride: NSUInteger) {
|
||||
unsafe { msg_send![self, setRayStride: stride] }
|
||||
}
|
||||
|
||||
pub fn set_triangle_intersection_test_type(&self, test_type: MPSTriangleIntersectionTestType) {
|
||||
unsafe { msg_send![self, setTriangleIntersectionTestType: test_type] }
|
||||
}
|
||||
|
||||
pub fn encode_intersection_to_command_buffer(
|
||||
&self,
|
||||
command_buffer: &CommandBufferRef,
|
||||
intersection_type: MPSIntersectionType,
|
||||
ray_buffer: &BufferRef,
|
||||
ray_buffer_offset: NSUInteger,
|
||||
intersection_buffer: &BufferRef,
|
||||
intersection_buffer_offset: NSUInteger,
|
||||
ray_count: NSUInteger,
|
||||
acceleration_structure: &AccelerationStructureRef,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
encodeIntersectionToCommandBuffer: command_buffer
|
||||
intersectionType: intersection_type
|
||||
rayBuffer: ray_buffer
|
||||
rayBufferOffset: ray_buffer_offset
|
||||
intersectionBuffer: intersection_buffer
|
||||
intersectionBufferOffset: intersection_buffer_offset
|
||||
rayCount: ray_count
|
||||
accelerationStructure: acceleration_structure
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn recommended_minimum_ray_batch_size_for_ray_count(
|
||||
&self,
|
||||
ray_count: NSUInteger,
|
||||
) -> NSUInteger {
|
||||
unsafe { msg_send![self, recommendedMinimumRayBatchSizeForRayCount: ray_count] }
|
||||
}
|
||||
}
|
||||
|
||||
/// A group of acceleration structures which may be used together in an instance acceleration structure.
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpsaccelerationstructuregroup>
|
||||
pub enum MPSAccelerationStructureGroup {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MPSAccelerationStructureGroup;
|
||||
pub struct AccelerationStructureGroup;
|
||||
}
|
||||
|
||||
impl AccelerationStructureGroup {
|
||||
pub fn new_with_device(device: &DeviceRef) -> Option<Self> {
|
||||
unsafe {
|
||||
let group: AccelerationStructureGroup =
|
||||
msg_send![class!(MPSAccelerationStructureGroup), alloc];
|
||||
let ptr: *mut Object = msg_send![group.as_ref(), initWithDevice: device];
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(group)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AccelerationStructureGroupRef {
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
}
|
||||
|
||||
/// The base class for data structures that are built over geometry and used to accelerate ray tracing.
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpsaccelerationstructure>
|
||||
pub enum MPSAccelerationStructure {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MPSAccelerationStructure;
|
||||
pub struct AccelerationStructure;
|
||||
}
|
||||
|
||||
impl AccelerationStructureRef {
|
||||
pub fn status(&self) -> MPSAccelerationStructureStatus {
|
||||
unsafe { msg_send![self, status] }
|
||||
}
|
||||
|
||||
pub fn usage(&self) -> MPSAccelerationStructureUsage {
|
||||
unsafe { msg_send![self, usage] }
|
||||
}
|
||||
|
||||
pub fn set_usage(&self, usage: MPSAccelerationStructureUsage) {
|
||||
unsafe { msg_send![self, setUsage: usage] }
|
||||
}
|
||||
|
||||
pub fn group(&self) -> &AccelerationStructureGroupRef {
|
||||
unsafe { msg_send![self, group] }
|
||||
}
|
||||
|
||||
pub fn encode_refit_to_command_buffer(&self, buffer: &CommandBufferRef) {
|
||||
unsafe { msg_send![self, encodeRefitToCommandBuffer: buffer] }
|
||||
}
|
||||
|
||||
pub fn rebuild(&self) {
|
||||
unsafe { msg_send![self, rebuild] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpspolygonaccelerationstructure>
|
||||
pub enum MPSPolygonAccelerationStructure {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MPSPolygonAccelerationStructure;
|
||||
pub struct PolygonAccelerationStructure;
|
||||
type ParentType = AccelerationStructure;
|
||||
}
|
||||
|
||||
impl PolygonAccelerationStructureRef {
|
||||
pub fn set_index_buffer(&self, buffer: Option<&BufferRef>) {
|
||||
unsafe { msg_send![self, setIndexBuffer: buffer] }
|
||||
}
|
||||
|
||||
pub fn set_index_buffer_offset(&self, offset: NSUInteger) {
|
||||
unsafe { msg_send![self, setIndexBufferOffset: offset] }
|
||||
}
|
||||
|
||||
pub fn set_index_type(&self, data_type: MPSDataType) {
|
||||
unsafe { msg_send![self, setIndexType: data_type] }
|
||||
}
|
||||
|
||||
pub fn set_mask_buffer(&self, buffer: Option<&BufferRef>) {
|
||||
unsafe { msg_send![self, setMaskBuffer: buffer] }
|
||||
}
|
||||
|
||||
pub fn set_mask_buffer_offset(&self, offset: NSUInteger) {
|
||||
unsafe { msg_send![self, setMaskBufferOffset: offset] }
|
||||
}
|
||||
|
||||
pub fn set_vertex_buffer(&self, buffer: Option<&BufferRef>) {
|
||||
unsafe { msg_send![self, setVertexBuffer: buffer] }
|
||||
}
|
||||
|
||||
pub fn set_vertex_buffer_offset(&self, offset: NSUInteger) {
|
||||
unsafe { msg_send![self, setVertexBufferOffset: offset] }
|
||||
}
|
||||
|
||||
pub fn set_vertex_stride(&self, stride: NSUInteger) {
|
||||
unsafe { msg_send![self, setVertexStride: stride] }
|
||||
}
|
||||
}
|
||||
|
||||
/// An acceleration structure built over triangles.
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpstriangleaccelerationstructure>
|
||||
pub enum MPSTriangleAccelerationStructure {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MPSTriangleAccelerationStructure;
|
||||
pub struct TriangleAccelerationStructure;
|
||||
type ParentType = PolygonAccelerationStructure;
|
||||
}
|
||||
|
||||
impl TriangleAccelerationStructure {
|
||||
pub fn from_device(device: &DeviceRef) -> Option<Self> {
|
||||
unsafe {
|
||||
let structure: TriangleAccelerationStructure =
|
||||
msg_send![class!(MPSTriangleAccelerationStructure), alloc];
|
||||
let ptr: *mut Object = msg_send![structure.as_ref(), initWithDevice: device];
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(structure)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TriangleAccelerationStructureRef {
|
||||
pub fn triangle_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, triangleCount] }
|
||||
}
|
||||
|
||||
pub fn set_triangle_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setTriangleCount: count] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpstransformtype>
|
||||
#[repr(u64)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum MPSTransformType {
|
||||
Float4x4 = 0,
|
||||
Identity = 1,
|
||||
}
|
||||
|
||||
/// An acceleration structure built over instances of other acceleration structures
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpsinstanceaccelerationstructure>
|
||||
pub enum MPSInstanceAccelerationStructure {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MPSInstanceAccelerationStructure;
|
||||
pub struct InstanceAccelerationStructure;
|
||||
type ParentType = AccelerationStructure;
|
||||
}
|
||||
|
||||
impl InstanceAccelerationStructure {
|
||||
pub fn init_with_group(group: &AccelerationStructureGroupRef) -> Option<Self> {
|
||||
unsafe {
|
||||
let structure: InstanceAccelerationStructure =
|
||||
msg_send![class!(MPSInstanceAccelerationStructure), alloc];
|
||||
let ptr: *mut Object = msg_send![structure.as_ref(), initWithGroup: group];
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(structure)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl InstanceAccelerationStructureRef {
|
||||
/// Marshal to Rust Vec
|
||||
pub fn acceleration_structures(&self) -> Vec<PolygonAccelerationStructure> {
|
||||
unsafe {
|
||||
let acs: *mut Object = msg_send![self, accelerationStructures];
|
||||
let count: NSUInteger = msg_send![acs, count];
|
||||
let ret = (0..count)
|
||||
.map(|i| {
|
||||
let ac = msg_send![acs, objectAtIndex: i];
|
||||
PolygonAccelerationStructure::from_ptr(ac)
|
||||
})
|
||||
.collect();
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
/// Marshal from Rust slice
|
||||
pub fn set_acceleration_structures(&self, acs: &[&PolygonAccelerationStructureRef]) {
|
||||
let ns_array = Array::<PolygonAccelerationStructure>::from_slice(acs);
|
||||
unsafe { msg_send![self, setAccelerationStructures: ns_array] }
|
||||
}
|
||||
|
||||
pub fn instance_buffer(&self) -> &BufferRef {
|
||||
unsafe { msg_send![self, instanceBuffer] }
|
||||
}
|
||||
|
||||
pub fn set_instance_buffer(&self, buffer: &BufferRef) {
|
||||
unsafe { msg_send![self, setInstanceBuffer: buffer] }
|
||||
}
|
||||
|
||||
pub fn instance_buffer_offset(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, instanceBufferOffset] }
|
||||
}
|
||||
|
||||
pub fn set_instance_buffer_offset(&self, offset: NSUInteger) {
|
||||
unsafe { msg_send![self, setInstanceBufferOffset: offset] }
|
||||
}
|
||||
|
||||
pub fn transform_buffer(&self) -> &BufferRef {
|
||||
unsafe { msg_send![self, transformBuffer] }
|
||||
}
|
||||
|
||||
pub fn set_transform_buffer(&self, buffer: &BufferRef) {
|
||||
unsafe { msg_send![self, setTransformBuffer: buffer] }
|
||||
}
|
||||
|
||||
pub fn transform_buffer_offset(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, transformBufferOffset] }
|
||||
}
|
||||
|
||||
pub fn set_transform_buffer_offset(&self, offset: NSUInteger) {
|
||||
unsafe { msg_send![self, setTransformBufferOffset: offset] }
|
||||
}
|
||||
|
||||
pub fn transform_type(&self) -> MPSTransformType {
|
||||
unsafe { msg_send![self, transformType] }
|
||||
}
|
||||
|
||||
pub fn set_transform_type(&self, transform_type: MPSTransformType) {
|
||||
unsafe { msg_send![self, setTransformType: transform_type] }
|
||||
}
|
||||
|
||||
pub fn mask_buffer(&self) -> &BufferRef {
|
||||
unsafe { msg_send![self, maskBuffer] }
|
||||
}
|
||||
|
||||
pub fn set_mask_buffer(&self, buffer: &BufferRef) {
|
||||
unsafe { msg_send![self, setMaskBuffer: buffer] }
|
||||
}
|
||||
|
||||
pub fn mask_buffer_offset(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, maskBufferOffset] }
|
||||
}
|
||||
|
||||
pub fn set_mask_buffer_offset(&self, offset: NSUInteger) {
|
||||
unsafe { msg_send![self, setMaskBufferOffset: offset] }
|
||||
}
|
||||
|
||||
pub fn instance_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, instanceCount] }
|
||||
}
|
||||
|
||||
pub fn set_instance_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setInstanceCount: count] }
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct MPSPackedFloat3 {
|
||||
pub elements: [f32; 3],
|
||||
}
|
||||
|
||||
/// Represents a 3D ray with an origin, a direction, and an intersection distance range from the origin.
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpsrayoriginmindistancedirectionmaxdistance>
|
||||
#[repr(C)]
|
||||
pub struct MPSRayOriginMinDistanceDirectionMaxDistance {
|
||||
/// Ray origin. The intersection test will be skipped if the origin contains NaNs or infinities.
|
||||
pub origin: MPSPackedFloat3,
|
||||
/// Minimum intersection distance from the origin along the ray direction.
|
||||
/// The intersection test will be skipped if the minimum distance is equal to positive infinity or NaN.
|
||||
pub min_distance: f32,
|
||||
/// Ray direction. Does not need to be normalized. The intersection test will be skipped if
|
||||
/// the direction has length zero or contains NaNs or infinities.
|
||||
pub direction: MPSPackedFloat3,
|
||||
/// Maximum intersection distance from the origin along the ray direction. May be infinite.
|
||||
/// The intersection test will be skipped if the maximum distance is less than zero, NaN, or
|
||||
/// less than the minimum intersection distance.
|
||||
pub max_distance: f32,
|
||||
}
|
||||
|
||||
/// Intersection result which contains the distance from the ray origin to the intersection point,
|
||||
/// the index of the intersected primitive, and the first two barycentric coordinates of the intersection point.
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metalperformanceshaders/mpsintersectiondistanceprimitiveindexcoordinates>
|
||||
#[repr(C)]
|
||||
pub struct MPSIntersectionDistancePrimitiveIndexCoordinates {
|
||||
/// Distance from the ray origin to the intersection point along the ray direction vector such
|
||||
/// that `intersection = ray.origin + ray.direction * distance`.
|
||||
/// Is negative if there is no intersection. If the intersection type is `MPSIntersectionTypeAny`,
|
||||
/// is a positive value for a hit or a negative value for a miss.
|
||||
pub distance: f32,
|
||||
/// Index of the intersected primitive. Undefined if the ray does not intersect a primitive or
|
||||
/// if the intersection type is `MPSIntersectionTypeAny`.
|
||||
pub primitive_index: u32,
|
||||
/// The first two barycentric coordinates `U` and `V` of the intersection point.
|
||||
/// The third coordinate `W = 1 - U - V`. Undefined if the ray does not intersect a primitive or
|
||||
/// if the intersection type is `MPSIntersectionTypeAny`.
|
||||
pub coordinates: [f32; 2],
|
||||
}
|
||||
471
third-party/vendor/metal/src/pipeline/compute.rs
vendored
Normal file
471
third-party/vendor/metal/src/pipeline/compute.rs
vendored
Normal file
|
|
@ -0,0 +1,471 @@
|
|||
// Copyright 2017 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
|
||||
use objc::runtime::{NO, YES};
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlattributeformat>
|
||||
#[repr(u64)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum MTLAttributeFormat {
|
||||
Invalid = 0,
|
||||
UChar2 = 1,
|
||||
UChar3 = 2,
|
||||
UChar4 = 3,
|
||||
Char2 = 4,
|
||||
Char3 = 5,
|
||||
Char4 = 6,
|
||||
UChar2Normalized = 7,
|
||||
UChar3Normalized = 8,
|
||||
UChar4Normalized = 9,
|
||||
Char2Normalized = 10,
|
||||
Char3Normalized = 11,
|
||||
Char4Normalized = 12,
|
||||
UShort2 = 13,
|
||||
UShort3 = 14,
|
||||
UShort4 = 15,
|
||||
Short2 = 16,
|
||||
Short3 = 17,
|
||||
Short4 = 18,
|
||||
UShort2Normalized = 19,
|
||||
UShort3Normalized = 20,
|
||||
UShort4Normalized = 21,
|
||||
Short2Normalized = 22,
|
||||
Short3Normalized = 23,
|
||||
Short4Normalized = 24,
|
||||
Half2 = 25,
|
||||
Half3 = 26,
|
||||
Half4 = 27,
|
||||
Float = 28,
|
||||
Float2 = 29,
|
||||
Float3 = 30,
|
||||
Float4 = 31,
|
||||
Int = 32,
|
||||
Int2 = 33,
|
||||
Int3 = 34,
|
||||
Int4 = 35,
|
||||
UInt = 36,
|
||||
UInt2 = 37,
|
||||
UInt3 = 38,
|
||||
UInt4 = 39,
|
||||
Int1010102Normalized = 40,
|
||||
UInt1010102Normalized = 41,
|
||||
UChar4Normalized_BGRA = 42,
|
||||
UChar = 45,
|
||||
Char = 46,
|
||||
UCharNormalized = 47,
|
||||
CharNormalized = 48,
|
||||
UShort = 49,
|
||||
Short = 50,
|
||||
UShortNormalized = 51,
|
||||
ShortNormalized = 52,
|
||||
Half = 53,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlstepfunction>
|
||||
#[repr(u64)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum MTLStepFunction {
|
||||
Constant = 0,
|
||||
PerInstance = 1,
|
||||
PerPatch = 2,
|
||||
PerPatchControlPoint = 3,
|
||||
PerVertex = 4,
|
||||
ThreadPositionInGridX = 5,
|
||||
ThreadPositionInGridXIndexed = 6,
|
||||
ThreadPositionInGridY = 7,
|
||||
ThreadPositionInGridYIndexed = 8,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcomputepipelinedescriptor>
|
||||
pub enum MTLComputePipelineDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLComputePipelineDescriptor;
|
||||
pub struct ComputePipelineDescriptor;
|
||||
}
|
||||
|
||||
impl ComputePipelineDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLComputePipelineDescriptor);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputePipelineDescriptorRef {
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: nslabel];
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compute_function(&self) -> Option<&FunctionRef> {
|
||||
unsafe { msg_send![self, computeFunction] }
|
||||
}
|
||||
|
||||
pub fn set_compute_function(&self, function: Option<&FunctionRef>) {
|
||||
unsafe { msg_send![self, setComputeFunction: function] }
|
||||
}
|
||||
|
||||
pub fn thread_group_size_is_multiple_of_thread_execution_width(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, threadGroupSizeIsMultipleOfThreadExecutionWidth] }
|
||||
}
|
||||
|
||||
pub fn set_thread_group_size_is_multiple_of_thread_execution_width(
|
||||
&self,
|
||||
size_is_multiple_of_width: bool,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
setThreadGroupSizeIsMultipleOfThreadExecutionWidth: size_is_multiple_of_width
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
/// API_AVAILABLE(macos(10.14), ios(12.0));
|
||||
pub fn max_total_threads_per_threadgroup(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, maxTotalThreadsPerThreadgroup] }
|
||||
}
|
||||
|
||||
/// API_AVAILABLE(macos(10.14), ios(12.0));
|
||||
pub fn set_max_total_threads_per_threadgroup(&self, max_total_threads: NSUInteger) {
|
||||
unsafe { msg_send![self, setMaxTotalThreadsPerThreadgroup: max_total_threads] }
|
||||
}
|
||||
|
||||
/// API_AVAILABLE(ios(13.0),macos(11.0));
|
||||
pub fn support_indirect_command_buffers(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, supportIndirectCommandBuffers] }
|
||||
}
|
||||
|
||||
/// API_AVAILABLE(ios(13.0),macos(11.0));
|
||||
pub fn set_support_indirect_command_buffers(&self, support: bool) {
|
||||
unsafe { msg_send![self, setSupportIndirectCommandBuffers: support] }
|
||||
}
|
||||
|
||||
/// API_AVAILABLE(macos(11.0), ios(14.0));
|
||||
pub fn support_adding_binary_functions(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, supportAddingBinaryFunctions] }
|
||||
}
|
||||
|
||||
/// API_AVAILABLE(macos(11.0), ios(14.0));
|
||||
pub fn set_support_adding_binary_functions(&self, support: bool) {
|
||||
unsafe { msg_send![self, setSupportAddingBinaryFunctions: support] }
|
||||
}
|
||||
|
||||
/// API_AVAILABLE(macos(11.0), ios(14.0));
|
||||
pub fn max_call_stack_depth(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, maxCallStackDepth] }
|
||||
}
|
||||
|
||||
/// API_AVAILABLE(macos(11.0), ios(14.0));
|
||||
pub fn set_max_call_stack_depth(&self, depth: NSUInteger) {
|
||||
unsafe { msg_send![self, setMaxCallStackDepth: depth] }
|
||||
}
|
||||
|
||||
/// API_AVAILABLE(macos(11.0), ios(14.0));
|
||||
/// Marshal to Rust Vec
|
||||
pub fn insert_libraries(&self) -> Vec<DynamicLibrary> {
|
||||
unsafe {
|
||||
let libraries: *mut Object = msg_send![self, insertLibraries];
|
||||
let count: NSUInteger = msg_send![libraries, count];
|
||||
let ret = (0..count)
|
||||
.map(|i| {
|
||||
let lib = msg_send![libraries, objectAtIndex: i];
|
||||
DynamicLibrary::from_ptr(lib)
|
||||
})
|
||||
.collect();
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
/// Marshal from Rust slice
|
||||
pub fn set_insert_libraries(&self, libraries: &[&DynamicLibraryRef]) {
|
||||
let ns_array = Array::<DynamicLibrary>::from_slice(libraries);
|
||||
unsafe { msg_send![self, setInsertLibraries: ns_array] }
|
||||
}
|
||||
|
||||
/// API_AVAILABLE(macos(11.0), ios(14.0));
|
||||
/// Marshal to Rust Vec
|
||||
pub fn binary_archives(&self) -> Vec<BinaryArchive> {
|
||||
unsafe {
|
||||
let archives: *mut Object = msg_send![self, binaryArchives];
|
||||
let count: NSUInteger = msg_send![archives, count];
|
||||
let ret = (0..count)
|
||||
.map(|i| {
|
||||
let a = msg_send![archives, objectAtIndex: i];
|
||||
BinaryArchive::from_ptr(a)
|
||||
})
|
||||
.collect();
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
/// API_AVAILABLE(macos(11.0), ios(14.0));
|
||||
/// Marshal from Rust slice
|
||||
pub fn set_binary_archives(&self, archives: &[&BinaryArchiveRef]) {
|
||||
let ns_array = Array::<BinaryArchive>::from_slice(archives);
|
||||
unsafe { msg_send![self, setBinaryArchives: ns_array] }
|
||||
}
|
||||
|
||||
/// API_AVAILABLE(macos(11.0), ios(14.0));
|
||||
pub fn linked_functions(&self) -> &LinkedFunctionsRef {
|
||||
unsafe { msg_send![self, linkedFunctions] }
|
||||
}
|
||||
|
||||
/// API_AVAILABLE(macos(11.0), ios(14.0));
|
||||
pub fn set_linked_functions(&self, functions: &LinkedFunctionsRef) {
|
||||
unsafe { msg_send![self, setLinkedFunctions: functions] }
|
||||
}
|
||||
|
||||
pub fn stage_input_descriptor(&self) -> Option<&StageInputOutputDescriptorRef> {
|
||||
unsafe { msg_send![self, stageInputDescriptor] }
|
||||
}
|
||||
|
||||
pub fn set_stage_input_descriptor(&self, descriptor: Option<&StageInputOutputDescriptorRef>) {
|
||||
unsafe { msg_send![self, setStageInputDescriptor: descriptor] }
|
||||
}
|
||||
|
||||
pub fn buffers(&self) -> Option<&PipelineBufferDescriptorArrayRef> {
|
||||
unsafe { msg_send![self, buffers] }
|
||||
}
|
||||
|
||||
pub fn reset(&self) {
|
||||
unsafe { msg_send![self, reset] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcomputepipelinestate>
|
||||
pub enum MTLComputePipelineState {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLComputePipelineState;
|
||||
pub struct ComputePipelineState;
|
||||
}
|
||||
|
||||
impl ComputePipelineStateRef {
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max_total_threads_per_threadgroup(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, maxTotalThreadsPerThreadgroup] }
|
||||
}
|
||||
|
||||
pub fn thread_execution_width(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, threadExecutionWidth] }
|
||||
}
|
||||
|
||||
pub fn static_threadgroup_memory_length(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, staticThreadgroupMemoryLength] }
|
||||
}
|
||||
|
||||
/// Only available on (ios(11.0), macos(11.0), macCatalyst(14.0)) NOT available on (tvos)
|
||||
pub fn imageblock_memory_length_for_dimensions(&self, dimensions: MTLSize) -> NSUInteger {
|
||||
unsafe { msg_send![self, imageblockMemoryLengthForDimensions: dimensions] }
|
||||
}
|
||||
|
||||
/// Only available on (ios(13.0), macos(11.0))
|
||||
pub fn support_indirect_command_buffers(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, supportIndirectCommandBuffers] }
|
||||
}
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
pub fn function_handle_with_function(
|
||||
&self,
|
||||
function: &FunctionRef,
|
||||
) -> Option<&FunctionHandleRef> {
|
||||
unsafe { msg_send![self, functionHandleWithFunction: function] }
|
||||
}
|
||||
|
||||
// API_AVAILABLE(macos(11.0), ios(14.0));
|
||||
// TODO: newComputePipelineStateWithAdditionalBinaryFunctions
|
||||
// - (nullable id <MTLComputePipelineState>)newComputePipelineStateWithAdditionalBinaryFunctions:(nonnull NSArray<id<MTLFunction>> *)functions error:(__autoreleasing NSError **)error
|
||||
|
||||
// API_AVAILABLE(macos(11.0), ios(14.0));
|
||||
// TODO: newVisibleFunctionTableWithDescriptor
|
||||
// - (nullable id<MTLVisibleFunctionTable>)newVisibleFunctionTableWithDescriptor:(MTLVisibleFunctionTableDescriptor * __nonnull)descriptor
|
||||
|
||||
/// Only available on (macos(11.0), ios(14.0))
|
||||
pub fn new_intersection_function_table_with_descriptor(
|
||||
&self,
|
||||
descriptor: &IntersectionFunctionTableDescriptorRef,
|
||||
) -> IntersectionFunctionTable {
|
||||
unsafe { msg_send![self, newIntersectionFunctionTableWithDescriptor: descriptor] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlstageinputoutputdescriptor>
|
||||
pub enum MTLStageInputOutputDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLStageInputOutputDescriptor;
|
||||
pub struct StageInputOutputDescriptor;
|
||||
}
|
||||
|
||||
impl StageInputOutputDescriptor {
|
||||
pub fn new<'a>() -> &'a StageInputOutputDescriptorRef {
|
||||
unsafe {
|
||||
let class = class!(MTLStageInputOutputDescriptor);
|
||||
msg_send![class, stageInputOutputDescriptor]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StageInputOutputDescriptorRef {
|
||||
pub fn attributes(&self) -> Option<&AttributeDescriptorArrayRef> {
|
||||
unsafe { msg_send![self, attributes] }
|
||||
}
|
||||
|
||||
pub fn index_buffer_index(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, indexBufferIndex] }
|
||||
}
|
||||
|
||||
pub fn set_index_buffer_index(&self, idx_buffer_idx: NSUInteger) {
|
||||
unsafe { msg_send![self, setIndexBufferIndex: idx_buffer_idx] }
|
||||
}
|
||||
|
||||
pub fn index_type(&self) -> MTLIndexType {
|
||||
unsafe { msg_send![self, indexType] }
|
||||
}
|
||||
|
||||
pub fn set_index_type(&self, index_ty: MTLIndexType) {
|
||||
unsafe { msg_send![self, setIndexType: index_ty] }
|
||||
}
|
||||
|
||||
pub fn layouts(&self) -> Option<&BufferLayoutDescriptorArrayRef> {
|
||||
unsafe { msg_send![self, layouts] }
|
||||
}
|
||||
|
||||
pub fn reset(&self) {
|
||||
unsafe { msg_send![self, reset] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlattributedescriptorarray>
|
||||
pub enum MTLAttributeDescriptorArray {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLAttributeDescriptorArray;
|
||||
pub struct AttributeDescriptorArray;
|
||||
}
|
||||
|
||||
impl AttributeDescriptorArrayRef {
|
||||
pub fn object_at(&self, index: NSUInteger) -> Option<&AttributeDescriptorRef> {
|
||||
unsafe { msg_send![self, objectAtIndexedSubscript: index] }
|
||||
}
|
||||
|
||||
pub fn set_object_at(&self, index: NSUInteger, buffer_desc: Option<&AttributeDescriptorRef>) {
|
||||
unsafe { msg_send![self, setObject:buffer_desc atIndexedSubscript:index] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlattributedescriptor>
|
||||
pub enum MTLAttributeDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLAttributeDescriptor;
|
||||
pub struct AttributeDescriptor;
|
||||
}
|
||||
|
||||
impl AttributeDescriptorRef {
|
||||
pub fn buffer_index(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, bufferIndex] }
|
||||
}
|
||||
|
||||
pub fn set_buffer_index(&self, buffer_index: NSUInteger) {
|
||||
unsafe { msg_send![self, setBufferIndex: buffer_index] }
|
||||
}
|
||||
|
||||
pub fn format(&self) -> MTLAttributeFormat {
|
||||
unsafe { msg_send![self, format] }
|
||||
}
|
||||
|
||||
pub fn set_format(&self, format: MTLAttributeFormat) {
|
||||
unsafe { msg_send![self, setFormat: format] }
|
||||
}
|
||||
|
||||
pub fn offset(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, offset] }
|
||||
}
|
||||
|
||||
pub fn set_offset(&self, offset: NSUInteger) {
|
||||
unsafe { msg_send![self, setOffset: offset] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlbufferlayoutdescriptorarray>
|
||||
pub enum MTLBufferLayoutDescriptorArray {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLBufferLayoutDescriptorArray;
|
||||
pub struct BufferLayoutDescriptorArray;
|
||||
}
|
||||
|
||||
impl BufferLayoutDescriptorArrayRef {
|
||||
pub fn object_at(&self, index: NSUInteger) -> Option<&BufferLayoutDescriptorRef> {
|
||||
unsafe { msg_send![self, objectAtIndexedSubscript: index] }
|
||||
}
|
||||
|
||||
pub fn set_object_at(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
buffer_desc: Option<&BufferLayoutDescriptorRef>,
|
||||
) {
|
||||
unsafe { msg_send![self, setObject:buffer_desc atIndexedSubscript:index] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlbufferlayoutdescriptor>
|
||||
pub enum MTLBufferLayoutDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLBufferLayoutDescriptor;
|
||||
pub struct BufferLayoutDescriptor;
|
||||
}
|
||||
|
||||
impl BufferLayoutDescriptorRef {
|
||||
pub fn step_function(&self) -> MTLStepFunction {
|
||||
unsafe { msg_send![self, stepFunction] }
|
||||
}
|
||||
|
||||
pub fn set_step_function(&self, step_function: MTLStepFunction) {
|
||||
unsafe { msg_send![self, setStepFunction: step_function] }
|
||||
}
|
||||
|
||||
pub fn step_rate(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, stepRate] }
|
||||
}
|
||||
|
||||
pub fn set_step_rate(&self, step_rate: NSUInteger) {
|
||||
unsafe { msg_send![self, setStepRate: step_rate] }
|
||||
}
|
||||
|
||||
pub fn stride(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, stride] }
|
||||
}
|
||||
|
||||
pub fn set_stride(&self, stride: NSUInteger) {
|
||||
unsafe { msg_send![self, setStride: stride] }
|
||||
}
|
||||
}
|
||||
71
third-party/vendor/metal/src/pipeline/mod.rs
vendored
Normal file
71
third-party/vendor/metal/src/pipeline/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
// Copyright 2017 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
|
||||
mod compute;
|
||||
mod render;
|
||||
|
||||
pub use self::compute::*;
|
||||
pub use self::render::*;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlmutability>
|
||||
#[repr(u64)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum MTLMutability {
|
||||
Default = 0,
|
||||
Mutable = 1,
|
||||
Immutable = 2,
|
||||
}
|
||||
|
||||
impl Default for MTLMutability {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
MTLMutability::Default
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlpipelinebufferdescriptorarray>
|
||||
pub enum MTLPipelineBufferDescriptorArray {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLPipelineBufferDescriptorArray;
|
||||
pub struct PipelineBufferDescriptorArray;
|
||||
}
|
||||
|
||||
impl PipelineBufferDescriptorArrayRef {
|
||||
pub fn object_at(&self, index: NSUInteger) -> Option<&PipelineBufferDescriptorRef> {
|
||||
unsafe { msg_send![self, objectAtIndexedSubscript: index] }
|
||||
}
|
||||
|
||||
pub fn set_object_at(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
buffer_desc: Option<&PipelineBufferDescriptorRef>,
|
||||
) {
|
||||
unsafe { msg_send![self, setObject:buffer_desc atIndexedSubscript:index] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlpipelinebufferdescriptor>
|
||||
pub enum MTLPipelineBufferDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLPipelineBufferDescriptor;
|
||||
pub struct PipelineBufferDescriptor;
|
||||
}
|
||||
|
||||
impl PipelineBufferDescriptorRef {
|
||||
pub fn mutability(&self) -> MTLMutability {
|
||||
unsafe { msg_send![self, mutability] }
|
||||
}
|
||||
|
||||
pub fn set_mutability(&self, new_mutability: MTLMutability) {
|
||||
unsafe { msg_send![self, setMutability: new_mutability] }
|
||||
}
|
||||
}
|
||||
719
third-party/vendor/metal/src/pipeline/render.rs
vendored
Normal file
719
third-party/vendor/metal/src/pipeline/render.rs
vendored
Normal file
|
|
@ -0,0 +1,719 @@
|
|||
// Copyright 2017 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
|
||||
use objc::runtime::{NO, YES};
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlblendfactor>
|
||||
#[repr(u64)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum MTLBlendFactor {
|
||||
Zero = 0,
|
||||
One = 1,
|
||||
SourceColor = 2,
|
||||
OneMinusSourceColor = 3,
|
||||
SourceAlpha = 4,
|
||||
OneMinusSourceAlpha = 5,
|
||||
DestinationColor = 6,
|
||||
OneMinusDestinationColor = 7,
|
||||
DestinationAlpha = 8,
|
||||
OneMinusDestinationAlpha = 9,
|
||||
SourceAlphaSaturated = 10,
|
||||
BlendColor = 11,
|
||||
OneMinusBlendColor = 12,
|
||||
BlendAlpha = 13,
|
||||
OneMinusBlendAlpha = 14,
|
||||
Source1Color = 15,
|
||||
OneMinusSource1Color = 16,
|
||||
Source1Alpha = 17,
|
||||
OneMinusSource1Alpha = 18,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlblendoperation>
|
||||
#[repr(u64)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum MTLBlendOperation {
|
||||
Add = 0,
|
||||
Subtract = 1,
|
||||
ReverseSubtract = 2,
|
||||
Min = 3,
|
||||
Max = 4,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcolorwritemask>
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct MTLColorWriteMask: NSUInteger {
|
||||
const None = 0;
|
||||
const Red = 0x1 << 3;
|
||||
const Green = 0x1 << 2;
|
||||
const Blue = 0x1 << 1;
|
||||
const Alpha = 0x1 << 0;
|
||||
const All = 0xf;
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlprimitivetopologyclass>
|
||||
#[repr(u64)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum MTLPrimitiveTopologyClass {
|
||||
Unspecified = 0,
|
||||
Point = 1,
|
||||
Line = 2,
|
||||
Triangle = 3,
|
||||
}
|
||||
|
||||
// TODO: MTLTessellationPartitionMode
|
||||
// TODO: MTLTessellationFactorStepFunction
|
||||
// TODO: MTLTessellationFactorFormat
|
||||
// TODO: MTLTessellationControlPointIndexType
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlrenderpipelinecolorattachmentdescriptor>
|
||||
pub enum MTLRenderPipelineColorAttachmentDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLRenderPipelineColorAttachmentDescriptor;
|
||||
pub struct RenderPipelineColorAttachmentDescriptor;
|
||||
}
|
||||
|
||||
impl RenderPipelineColorAttachmentDescriptorRef {
|
||||
pub fn pixel_format(&self) -> MTLPixelFormat {
|
||||
unsafe { msg_send![self, pixelFormat] }
|
||||
}
|
||||
|
||||
pub fn set_pixel_format(&self, pixel_format: MTLPixelFormat) {
|
||||
unsafe { msg_send![self, setPixelFormat: pixel_format] }
|
||||
}
|
||||
|
||||
pub fn is_blending_enabled(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isBlendingEnabled] }
|
||||
}
|
||||
|
||||
pub fn set_blending_enabled(&self, enabled: bool) {
|
||||
unsafe { msg_send![self, setBlendingEnabled: enabled] }
|
||||
}
|
||||
|
||||
pub fn source_rgb_blend_factor(&self) -> MTLBlendFactor {
|
||||
unsafe { msg_send![self, sourceRGBBlendFactor] }
|
||||
}
|
||||
|
||||
pub fn set_source_rgb_blend_factor(&self, blend_factor: MTLBlendFactor) {
|
||||
unsafe { msg_send![self, setSourceRGBBlendFactor: blend_factor] }
|
||||
}
|
||||
|
||||
pub fn destination_rgb_blend_factor(&self) -> MTLBlendFactor {
|
||||
unsafe { msg_send![self, destinationRGBBlendFactor] }
|
||||
}
|
||||
|
||||
pub fn set_destination_rgb_blend_factor(&self, blend_factor: MTLBlendFactor) {
|
||||
unsafe { msg_send![self, setDestinationRGBBlendFactor: blend_factor] }
|
||||
}
|
||||
|
||||
pub fn rgb_blend_operation(&self) -> MTLBlendOperation {
|
||||
unsafe { msg_send![self, rgbBlendOperation] }
|
||||
}
|
||||
|
||||
pub fn set_rgb_blend_operation(&self, blend_operation: MTLBlendOperation) {
|
||||
unsafe { msg_send![self, setRgbBlendOperation: blend_operation] }
|
||||
}
|
||||
|
||||
pub fn source_alpha_blend_factor(&self) -> MTLBlendFactor {
|
||||
unsafe { msg_send![self, sourceAlphaBlendFactor] }
|
||||
}
|
||||
|
||||
pub fn set_source_alpha_blend_factor(&self, blend_factor: MTLBlendFactor) {
|
||||
unsafe { msg_send![self, setSourceAlphaBlendFactor: blend_factor] }
|
||||
}
|
||||
|
||||
pub fn destination_alpha_blend_factor(&self) -> MTLBlendFactor {
|
||||
unsafe { msg_send![self, destinationAlphaBlendFactor] }
|
||||
}
|
||||
|
||||
pub fn set_destination_alpha_blend_factor(&self, blend_factor: MTLBlendFactor) {
|
||||
unsafe { msg_send![self, setDestinationAlphaBlendFactor: blend_factor] }
|
||||
}
|
||||
|
||||
pub fn alpha_blend_operation(&self) -> MTLBlendOperation {
|
||||
unsafe { msg_send![self, alphaBlendOperation] }
|
||||
}
|
||||
|
||||
pub fn set_alpha_blend_operation(&self, blend_operation: MTLBlendOperation) {
|
||||
unsafe { msg_send![self, setAlphaBlendOperation: blend_operation] }
|
||||
}
|
||||
|
||||
pub fn write_mask(&self) -> MTLColorWriteMask {
|
||||
unsafe { msg_send![self, writeMask] }
|
||||
}
|
||||
|
||||
pub fn set_write_mask(&self, mask: MTLColorWriteMask) {
|
||||
unsafe { msg_send![self, setWriteMask: mask] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlrenderpipelinereflection>
|
||||
pub enum MTLRenderPipelineReflection {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLRenderPipelineReflection;
|
||||
pub struct RenderPipelineReflection;
|
||||
}
|
||||
|
||||
impl RenderPipelineReflection {
|
||||
#[cfg(feature = "private")]
|
||||
pub unsafe fn new(
|
||||
vertex_data: *mut std::ffi::c_void,
|
||||
fragment_data: *mut std::ffi::c_void,
|
||||
vertex_desc: *mut std::ffi::c_void,
|
||||
device: &DeviceRef,
|
||||
options: u64,
|
||||
flags: u64,
|
||||
) -> Self {
|
||||
let class = class!(MTLRenderPipelineReflection);
|
||||
let this: RenderPipelineReflection = msg_send![class, alloc];
|
||||
let this_alias: *mut Object = msg_send![this.as_ref(), initWithVertexData:vertex_data
|
||||
fragmentData:fragment_data
|
||||
serializedVertexDescriptor:vertex_desc
|
||||
device:device
|
||||
options:options
|
||||
flags:flags];
|
||||
if this_alias.is_null() {
|
||||
panic!("[MTLRenderPipelineReflection init] failed");
|
||||
}
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderPipelineReflectionRef {
|
||||
/// An array of objects that describe the arguments of a fragment function.
|
||||
pub fn fragment_arguments(&self) -> &ArgumentArrayRef {
|
||||
unsafe { msg_send![self, fragmentArguments] }
|
||||
}
|
||||
|
||||
/// An array of objects that describe the arguments of a vertex function.
|
||||
pub fn vertex_arguments(&self) -> &ArgumentArrayRef {
|
||||
unsafe { msg_send![self, vertexArguments] }
|
||||
}
|
||||
|
||||
/// An array of objects that describe the arguments of a tile shading function.
|
||||
pub fn tile_arguments(&self) -> &ArgumentArrayRef {
|
||||
unsafe { msg_send![self, tileArguments] }
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO: Find documentation link.
|
||||
pub enum MTLArgumentArray {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLArgumentArray;
|
||||
pub struct ArgumentArray;
|
||||
}
|
||||
|
||||
impl ArgumentArrayRef {
|
||||
pub fn object_at(&self, index: NSUInteger) -> Option<&ArgumentRef> {
|
||||
unsafe { msg_send![self, objectAtIndexedSubscript: index] }
|
||||
}
|
||||
|
||||
pub fn count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, count] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcomputepipelinereflection>
|
||||
pub enum MTLComputePipelineReflection {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLComputePipelineReflection;
|
||||
pub struct ComputePipelineReflection;
|
||||
}
|
||||
|
||||
impl ComputePipelineReflectionRef {
|
||||
/// An array of objects that describe the arguments of a compute function.
|
||||
pub fn arguments(&self) -> &ArgumentArrayRef {
|
||||
unsafe { msg_send![self, arguments] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlmeshrenderpipelinedescriptor>
|
||||
/// Only available in (macos(13.0), ios(16.0))
|
||||
pub enum MTLMeshRenderPipelineDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLMeshRenderPipelineDescriptor;
|
||||
pub struct MeshRenderPipelineDescriptor;
|
||||
}
|
||||
|
||||
impl MeshRenderPipelineDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLMeshRenderPipelineDescriptor);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MeshRenderPipelineDescriptorRef {
|
||||
pub fn color_attachments(&self) -> &RenderPipelineColorAttachmentDescriptorArrayRef {
|
||||
unsafe { msg_send![self, colorAttachments] }
|
||||
}
|
||||
|
||||
pub fn depth_attachment_pixel_format(&self) -> MTLPixelFormat {
|
||||
unsafe { msg_send![self, depthAttachmentPixelFormat] }
|
||||
}
|
||||
|
||||
pub fn set_depth_attachment_pixel_format(&self, pixel_format: MTLPixelFormat) {
|
||||
unsafe { msg_send![self, setDepthAttachmentPixelFormat: pixel_format] }
|
||||
}
|
||||
|
||||
pub fn fragment_buffers(&self) -> Option<&PipelineBufferDescriptorArrayRef> {
|
||||
unsafe { msg_send![self, fragmentBuffers] }
|
||||
}
|
||||
|
||||
pub fn fragment_function(&self) -> Option<&FunctionRef> {
|
||||
unsafe { msg_send![self, fragmentFunction] }
|
||||
}
|
||||
|
||||
pub fn set_fragment_function(&self, function: Option<&FunctionRef>) {
|
||||
unsafe { msg_send![self, setFragmentFunction: function] }
|
||||
}
|
||||
|
||||
pub fn is_alpha_to_coverage_enabled(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isAlphaToCoverageEnabled] }
|
||||
}
|
||||
|
||||
pub fn set_alpha_to_coverage_enabled(&self, enabled: bool) {
|
||||
unsafe { msg_send![self, setAlphaToCoverageEnabled: enabled] }
|
||||
}
|
||||
|
||||
pub fn is_alpha_to_one_enabled(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isAlphaToOneEnabled] }
|
||||
}
|
||||
|
||||
pub fn set_alpha_to_one_enabled(&self, enabled: bool) {
|
||||
unsafe { msg_send![self, setAlphaToOneEnabled: enabled] }
|
||||
}
|
||||
|
||||
pub fn is_rasterization_enabled(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isRasterizationEnabled] }
|
||||
}
|
||||
|
||||
pub fn set_rasterization_enabled(&self, enabled: bool) {
|
||||
unsafe { msg_send![self, setRasterizationEnabled: enabled] }
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: nslabel];
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max_total_threadgroups_per_mesh_grid(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, maxTotalThreadgroupsPerMeshGrid] }
|
||||
}
|
||||
|
||||
pub fn set_max_total_threadgroups_per_mesh_grid(
|
||||
&self,
|
||||
max_total_threadgroups_per_mesh_grid: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
setMaxTotalThreadgroupsPerMeshGrid: max_total_threadgroups_per_mesh_grid
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max_total_threads_per_mesh_threadgroup(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, maxTotalThreadsPerMeshThreadgroup] }
|
||||
}
|
||||
|
||||
pub fn set_max_total_threads_per_mesh_threadgroup(
|
||||
&self,
|
||||
max_total_threads_per_mesh_threadgroup: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
setMaxTotalThreadsPerMeshThreadgroup: max_total_threads_per_mesh_threadgroup
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max_total_threads_per_object_threadgroup(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, maxTotalThreadsPerObjectThreadgroup] }
|
||||
}
|
||||
|
||||
pub fn set_max_total_threads_per_object_threadgroup(
|
||||
&self,
|
||||
max_total_threads_per_object_threadgroup: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
setMaxTotalThreadsPerObjectThreadgroup: max_total_threads_per_object_threadgroup
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max_vertex_amplification_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, maxVertexAmplificationCount] }
|
||||
}
|
||||
|
||||
pub fn set_max_vertex_amplification_count(&self, max_vertex_amplification_count: NSUInteger) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
setMaxVertexAmplificationCount: max_vertex_amplification_count
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mesh_buffers(&self) -> Option<&PipelineBufferDescriptorArrayRef> {
|
||||
unsafe { msg_send![self, meshBuffers] }
|
||||
}
|
||||
|
||||
pub fn mesh_function(&self) -> Option<&FunctionRef> {
|
||||
unsafe { msg_send![self, meshFunction] }
|
||||
}
|
||||
|
||||
pub fn set_mesh_function(&self, function: Option<&FunctionRef>) {
|
||||
unsafe { msg_send![self, setMeshFunction: function] }
|
||||
}
|
||||
|
||||
pub fn mesh_threadgroup_size_is_multiple_of_thread_execution_width(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isMeshThreadgroupSizeIsMultipleOfThreadExecutionWidth] }
|
||||
}
|
||||
|
||||
pub fn set_mesh_threadgroup_size_is_multiple_of_thread_execution_width(
|
||||
&self,
|
||||
mesh_threadgroup_size_is_multiple_of_thread_execution_width: bool,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
setMeshThreadgroupSizeIsMultipleOfThreadExecutionWidth:
|
||||
mesh_threadgroup_size_is_multiple_of_thread_execution_width
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn object_buffers(&self) -> Option<&PipelineBufferDescriptorArrayRef> {
|
||||
unsafe { msg_send![self, objectBuffers] }
|
||||
}
|
||||
|
||||
pub fn object_function(&self) -> Option<&FunctionRef> {
|
||||
unsafe { msg_send![self, objectFunction] }
|
||||
}
|
||||
|
||||
pub fn set_object_function(&self, function: Option<&FunctionRef>) {
|
||||
unsafe { msg_send![self, setObjectFunction: function] }
|
||||
}
|
||||
|
||||
pub fn object_threadgroup_size_is_multiple_of_thread_execution_width(&self) -> bool {
|
||||
unsafe {
|
||||
msg_send_bool![
|
||||
self,
|
||||
isObjectThreadgroupSizeIsMultipleOfThreadExecutionWidth
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_object_threadgroup_size_is_multiple_of_thread_execution_width(
|
||||
&self,
|
||||
object_threadgroup_size_is_multiple_of_thread_execution_width: bool,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
setObjectThreadgroupSizeIsMultipleOfThreadExecutionWidth:
|
||||
object_threadgroup_size_is_multiple_of_thread_execution_width
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn payload_memory_length(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, payloadMemoryLength] }
|
||||
}
|
||||
|
||||
pub fn set_payload_memory_length(&self, payload_memory_length: NSUInteger) {
|
||||
unsafe { msg_send![self, setPayloadMemoryLength: payload_memory_length] }
|
||||
}
|
||||
|
||||
pub fn raster_sample_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, rasterSampleCount] }
|
||||
}
|
||||
|
||||
pub fn set_raster_sample_count(&self, raster_sample_count: NSUInteger) {
|
||||
unsafe { msg_send![self, setRasterSampleCount: raster_sample_count] }
|
||||
}
|
||||
|
||||
pub fn stencil_attachment_pixel_format(&self) -> MTLPixelFormat {
|
||||
unsafe { msg_send![self, stencilAttachmentPixelFormat] }
|
||||
}
|
||||
|
||||
pub fn set_stencil_attachment_pixel_format(&self, pixel_format: MTLPixelFormat) {
|
||||
unsafe { msg_send![self, setStencilAttachmentPixelFormat: pixel_format] }
|
||||
}
|
||||
|
||||
pub fn reset(&self) {
|
||||
unsafe { msg_send![self, reset] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlrenderpipelinedescriptor>
|
||||
pub enum MTLRenderPipelineDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLRenderPipelineDescriptor;
|
||||
pub struct RenderPipelineDescriptor;
|
||||
}
|
||||
|
||||
impl RenderPipelineDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLRenderPipelineDescriptor);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderPipelineDescriptorRef {
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: nslabel];
|
||||
}
|
||||
}
|
||||
|
||||
pub fn vertex_function(&self) -> Option<&FunctionRef> {
|
||||
unsafe { msg_send![self, vertexFunction] }
|
||||
}
|
||||
|
||||
pub fn set_vertex_function(&self, function: Option<&FunctionRef>) {
|
||||
unsafe { msg_send![self, setVertexFunction: function] }
|
||||
}
|
||||
|
||||
pub fn fragment_function(&self) -> Option<&FunctionRef> {
|
||||
unsafe { msg_send![self, fragmentFunction] }
|
||||
}
|
||||
|
||||
pub fn set_fragment_function(&self, function: Option<&FunctionRef>) {
|
||||
unsafe { msg_send![self, setFragmentFunction: function] }
|
||||
}
|
||||
|
||||
pub fn vertex_descriptor(&self) -> Option<&VertexDescriptorRef> {
|
||||
unsafe { msg_send![self, vertexDescriptor] }
|
||||
}
|
||||
|
||||
pub fn set_vertex_descriptor(&self, descriptor: Option<&VertexDescriptorRef>) {
|
||||
unsafe { msg_send![self, setVertexDescriptor: descriptor] }
|
||||
}
|
||||
|
||||
/// DEPRECATED - aliases rasterSampleCount property
|
||||
pub fn sample_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, sampleCount] }
|
||||
}
|
||||
|
||||
/// DEPRECATED - aliases rasterSampleCount property
|
||||
pub fn set_sample_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setSampleCount: count] }
|
||||
}
|
||||
|
||||
pub fn raster_sample_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, rasterSampleCount] }
|
||||
}
|
||||
|
||||
pub fn set_raster_sample_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setRasterSampleCount: count] }
|
||||
}
|
||||
|
||||
pub fn max_vertex_amplification_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, maxVertexAmplificationCount] }
|
||||
}
|
||||
|
||||
pub fn set_max_vertex_amplification_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setMaxVertexAmplificationCount: count] }
|
||||
}
|
||||
|
||||
pub fn is_alpha_to_coverage_enabled(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isAlphaToCoverageEnabled] }
|
||||
}
|
||||
|
||||
pub fn set_alpha_to_coverage_enabled(&self, enabled: bool) {
|
||||
unsafe { msg_send![self, setAlphaToCoverageEnabled: enabled] }
|
||||
}
|
||||
|
||||
pub fn is_alpha_to_one_enabled(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isAlphaToOneEnabled] }
|
||||
}
|
||||
|
||||
pub fn set_alpha_to_one_enabled(&self, enabled: bool) {
|
||||
unsafe { msg_send![self, setAlphaToOneEnabled: enabled] }
|
||||
}
|
||||
|
||||
pub fn is_rasterization_enabled(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isRasterizationEnabled] }
|
||||
}
|
||||
|
||||
pub fn set_rasterization_enabled(&self, enabled: bool) {
|
||||
unsafe { msg_send![self, setRasterizationEnabled: enabled] }
|
||||
}
|
||||
|
||||
pub fn color_attachments(&self) -> &RenderPipelineColorAttachmentDescriptorArrayRef {
|
||||
unsafe { msg_send![self, colorAttachments] }
|
||||
}
|
||||
|
||||
pub fn depth_attachment_pixel_format(&self) -> MTLPixelFormat {
|
||||
unsafe { msg_send![self, depthAttachmentPixelFormat] }
|
||||
}
|
||||
|
||||
pub fn set_depth_attachment_pixel_format(&self, pixel_format: MTLPixelFormat) {
|
||||
unsafe { msg_send![self, setDepthAttachmentPixelFormat: pixel_format] }
|
||||
}
|
||||
|
||||
pub fn stencil_attachment_pixel_format(&self) -> MTLPixelFormat {
|
||||
unsafe { msg_send![self, stencilAttachmentPixelFormat] }
|
||||
}
|
||||
|
||||
pub fn set_stencil_attachment_pixel_format(&self, pixel_format: MTLPixelFormat) {
|
||||
unsafe { msg_send![self, setStencilAttachmentPixelFormat: pixel_format] }
|
||||
}
|
||||
|
||||
pub fn input_primitive_topology(&self) -> MTLPrimitiveTopologyClass {
|
||||
unsafe { msg_send![self, inputPrimitiveTopology] }
|
||||
}
|
||||
|
||||
pub fn set_input_primitive_topology(&self, topology: MTLPrimitiveTopologyClass) {
|
||||
unsafe { msg_send![self, setInputPrimitiveTopology: topology] }
|
||||
}
|
||||
|
||||
#[cfg(feature = "private")]
|
||||
pub unsafe fn serialize_vertex_data(&self) -> *mut std::ffi::c_void {
|
||||
use std::ptr;
|
||||
let flags = 0;
|
||||
let err: *mut Object = ptr::null_mut();
|
||||
msg_send![self, newSerializedVertexDataWithFlags:flags
|
||||
error:err]
|
||||
}
|
||||
|
||||
#[cfg(feature = "private")]
|
||||
pub unsafe fn serialize_fragment_data(&self) -> *mut std::ffi::c_void {
|
||||
msg_send![self, serializeFragmentData]
|
||||
}
|
||||
|
||||
pub fn support_indirect_command_buffers(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, supportIndirectCommandBuffers] }
|
||||
}
|
||||
|
||||
pub fn set_support_indirect_command_buffers(&self, support: bool) {
|
||||
unsafe { msg_send![self, setSupportIndirectCommandBuffers: support] }
|
||||
}
|
||||
|
||||
pub fn vertex_buffers(&self) -> Option<&PipelineBufferDescriptorArrayRef> {
|
||||
unsafe { msg_send![self, vertexBuffers] }
|
||||
}
|
||||
|
||||
pub fn fragment_buffers(&self) -> Option<&PipelineBufferDescriptorArrayRef> {
|
||||
unsafe { msg_send![self, fragmentBuffers] }
|
||||
}
|
||||
|
||||
// TODO: tesselation stuff
|
||||
|
||||
/// API_AVAILABLE(macos(11.0), ios(14.0));
|
||||
/// Marshal to Rust Vec
|
||||
pub fn binary_archives(&self) -> Vec<BinaryArchive> {
|
||||
unsafe {
|
||||
let archives: *mut Object = msg_send![self, binaryArchives];
|
||||
let count: NSUInteger = msg_send![archives, count];
|
||||
let ret = (0..count)
|
||||
.map(|i| {
|
||||
let a = msg_send![archives, objectAtIndex: i];
|
||||
BinaryArchive::from_ptr(a)
|
||||
})
|
||||
.collect();
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
/// API_AVAILABLE(macos(11.0), ios(14.0));
|
||||
/// Marshal from Rust slice
|
||||
pub fn set_binary_archives(&self, archives: &[&BinaryArchiveRef]) {
|
||||
let ns_array = Array::<BinaryArchive>::from_slice(archives);
|
||||
unsafe { msg_send![self, setBinaryArchives: ns_array] }
|
||||
}
|
||||
|
||||
pub fn reset(&self) {
|
||||
unsafe { msg_send![self, reset] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlrenderpipelinestate>
|
||||
pub enum MTLRenderPipelineState {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLRenderPipelineState;
|
||||
pub struct RenderPipelineState;
|
||||
}
|
||||
|
||||
impl RenderPipelineStateRef {
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlrenderpipelinecolorattachmentdescriptorarray>
|
||||
pub enum MTLRenderPipelineColorAttachmentDescriptorArray {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLRenderPipelineColorAttachmentDescriptorArray;
|
||||
pub struct RenderPipelineColorAttachmentDescriptorArray;
|
||||
}
|
||||
|
||||
impl RenderPipelineColorAttachmentDescriptorArrayRef {
|
||||
pub fn object_at(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
) -> Option<&RenderPipelineColorAttachmentDescriptorRef> {
|
||||
unsafe { msg_send![self, objectAtIndexedSubscript: index] }
|
||||
}
|
||||
|
||||
pub fn set_object_at(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
attachment: Option<&RenderPipelineColorAttachmentDescriptorRef>,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self, setObject:attachment
|
||||
atIndexedSubscript:index]
|
||||
}
|
||||
}
|
||||
}
|
||||
443
third-party/vendor/metal/src/renderpass.rs
vendored
Normal file
443
third-party/vendor/metal/src/renderpass.rs
vendored
Normal file
|
|
@ -0,0 +1,443 @@
|
|||
// Copyright 2016 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlloadaction>
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum MTLLoadAction {
|
||||
DontCare = 0,
|
||||
Load = 1,
|
||||
Clear = 2,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlstoreaction>
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum MTLStoreAction {
|
||||
DontCare = 0,
|
||||
Store = 1,
|
||||
MultisampleResolve = 2,
|
||||
StoreAndMultisampleResolve = 3,
|
||||
Unknown = 4,
|
||||
CustomSampleDepthStore = 5,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlclearcolor>
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct MTLClearColor {
|
||||
pub red: f64,
|
||||
pub green: f64,
|
||||
pub blue: f64,
|
||||
pub alpha: f64,
|
||||
}
|
||||
|
||||
impl MTLClearColor {
|
||||
#[inline]
|
||||
pub fn new(red: f64, green: f64, blue: f64, alpha: f64) -> Self {
|
||||
Self {
|
||||
red,
|
||||
green,
|
||||
blue,
|
||||
alpha,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlmultisamplestencilresolvefilter>
|
||||
#[repr(u32)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum MTLMultisampleStencilResolveFilter {
|
||||
Sample0 = 0,
|
||||
DepthResolvedSample = 1,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlrenderpassattachmentdescriptor>
|
||||
pub enum MTLRenderPassAttachmentDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLRenderPassAttachmentDescriptor;
|
||||
pub struct RenderPassAttachmentDescriptor;
|
||||
}
|
||||
|
||||
impl RenderPassAttachmentDescriptorRef {
|
||||
pub fn texture(&self) -> Option<&TextureRef> {
|
||||
unsafe { msg_send![self, texture] }
|
||||
}
|
||||
|
||||
pub fn set_texture(&self, texture: Option<&TextureRef>) {
|
||||
unsafe { msg_send![self, setTexture: texture] }
|
||||
}
|
||||
|
||||
pub fn level(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, level] }
|
||||
}
|
||||
|
||||
pub fn set_level(&self, level: NSUInteger) {
|
||||
unsafe { msg_send![self, setLevel: level] }
|
||||
}
|
||||
|
||||
pub fn slice(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, slice] }
|
||||
}
|
||||
|
||||
pub fn set_slice(&self, slice: NSUInteger) {
|
||||
unsafe { msg_send![self, setSlice: slice] }
|
||||
}
|
||||
|
||||
pub fn depth_plane(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, depthPlane] }
|
||||
}
|
||||
|
||||
pub fn set_depth_plane(&self, depth_plane: NSUInteger) {
|
||||
unsafe { msg_send![self, setDepthPlane: depth_plane] }
|
||||
}
|
||||
|
||||
pub fn resolve_texture(&self) -> Option<&TextureRef> {
|
||||
unsafe { msg_send![self, resolveTexture] }
|
||||
}
|
||||
|
||||
pub fn set_resolve_texture(&self, resolve_texture: Option<&TextureRef>) {
|
||||
unsafe { msg_send![self, setResolveTexture: resolve_texture] }
|
||||
}
|
||||
|
||||
pub fn resolve_level(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, resolveLevel] }
|
||||
}
|
||||
|
||||
pub fn set_resolve_level(&self, resolve_level: NSUInteger) {
|
||||
unsafe { msg_send![self, setResolveLevel: resolve_level] }
|
||||
}
|
||||
|
||||
pub fn resolve_slice(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, resolveSlice] }
|
||||
}
|
||||
|
||||
pub fn set_resolve_slice(&self, resolve_slice: NSUInteger) {
|
||||
unsafe { msg_send![self, setResolveSlice: resolve_slice] }
|
||||
}
|
||||
|
||||
pub fn resolve_depth_plane(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, resolveDepthPlane] }
|
||||
}
|
||||
|
||||
pub fn set_resolve_depth_plane(&self, resolve_depth_plane: NSUInteger) {
|
||||
unsafe { msg_send![self, setResolveDepthPlane: resolve_depth_plane] }
|
||||
}
|
||||
|
||||
pub fn load_action(&self) -> MTLLoadAction {
|
||||
unsafe { msg_send![self, loadAction] }
|
||||
}
|
||||
|
||||
pub fn set_load_action(&self, load_action: MTLLoadAction) {
|
||||
unsafe { msg_send![self, setLoadAction: load_action] }
|
||||
}
|
||||
|
||||
pub fn store_action(&self) -> MTLStoreAction {
|
||||
unsafe { msg_send![self, storeAction] }
|
||||
}
|
||||
|
||||
pub fn set_store_action(&self, store_action: MTLStoreAction) {
|
||||
unsafe { msg_send![self, setStoreAction: store_action] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlrenderpasscolorattachmentdescriptor>
|
||||
pub enum MTLRenderPassColorAttachmentDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLRenderPassColorAttachmentDescriptor;
|
||||
pub struct RenderPassColorAttachmentDescriptor;
|
||||
type ParentType = RenderPassAttachmentDescriptor;
|
||||
}
|
||||
|
||||
impl RenderPassColorAttachmentDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLRenderPassColorAttachmentDescriptor);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderPassColorAttachmentDescriptorRef {
|
||||
pub fn clear_color(&self) -> MTLClearColor {
|
||||
unsafe { msg_send![self, clearColor] }
|
||||
}
|
||||
|
||||
pub fn set_clear_color(&self, clear_color: MTLClearColor) {
|
||||
unsafe { msg_send![self, setClearColor: clear_color] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlrenderpassdepthattachmentdescriptor>
|
||||
pub enum MTLRenderPassDepthAttachmentDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLRenderPassDepthAttachmentDescriptor;
|
||||
pub struct RenderPassDepthAttachmentDescriptor;
|
||||
type ParentType = RenderPassAttachmentDescriptor;
|
||||
}
|
||||
|
||||
impl RenderPassDepthAttachmentDescriptorRef {
|
||||
pub fn clear_depth(&self) -> f64 {
|
||||
unsafe { msg_send![self, clearDepth] }
|
||||
}
|
||||
|
||||
pub fn set_clear_depth(&self, clear_depth: f64) {
|
||||
unsafe { msg_send![self, setClearDepth: clear_depth] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlrenderpassstencilattachmentdescriptor>
|
||||
pub enum MTLRenderPassStencilAttachmentDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLRenderPassStencilAttachmentDescriptor;
|
||||
pub struct RenderPassStencilAttachmentDescriptor;
|
||||
type ParentType = RenderPassAttachmentDescriptor;
|
||||
}
|
||||
|
||||
impl RenderPassStencilAttachmentDescriptorRef {
|
||||
pub fn clear_stencil(&self) -> u32 {
|
||||
unsafe { msg_send![self, clearStencil] }
|
||||
}
|
||||
|
||||
pub fn set_clear_stencil(&self, clear_stencil: u32) {
|
||||
unsafe { msg_send![self, setClearStencil: clear_stencil] }
|
||||
}
|
||||
|
||||
pub fn stencil_resolve_filter(&self) -> MTLMultisampleStencilResolveFilter {
|
||||
unsafe { msg_send![self, stencilResolveFilter] }
|
||||
}
|
||||
|
||||
pub fn set_stencil_resolve_filter(
|
||||
&self,
|
||||
stencil_resolve_filter: MTLMultisampleStencilResolveFilter,
|
||||
) {
|
||||
unsafe { msg_send![self, setStencilResolveFilter: stencil_resolve_filter] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlrenderpasscolorattachmentdescriptorarray>
|
||||
pub enum MTLRenderPassColorAttachmentDescriptorArray {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLRenderPassColorAttachmentDescriptorArray;
|
||||
pub struct RenderPassColorAttachmentDescriptorArray;
|
||||
}
|
||||
|
||||
impl RenderPassColorAttachmentDescriptorArrayRef {
|
||||
pub fn object_at(&self, index: NSUInteger) -> Option<&RenderPassColorAttachmentDescriptorRef> {
|
||||
unsafe { msg_send![self, objectAtIndexedSubscript: index] }
|
||||
}
|
||||
|
||||
pub fn set_object_at(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
attachment: Option<&RenderPassColorAttachmentDescriptorRef>,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self, setObject:attachment
|
||||
atIndexedSubscript:index]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlrenderpasssamplebufferattachmentdescriptor>
|
||||
pub enum MTLRenderPassSampleBufferAttachmentDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLRenderPassSampleBufferAttachmentDescriptor;
|
||||
pub struct RenderPassSampleBufferAttachmentDescriptor;
|
||||
}
|
||||
|
||||
impl RenderPassSampleBufferAttachmentDescriptor {
|
||||
pub fn new() -> Self {
|
||||
let class = class!(MTLRenderPassSampleBufferAttachmentDescriptor);
|
||||
unsafe { msg_send![class, new] }
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderPassSampleBufferAttachmentDescriptorRef {
|
||||
pub fn sample_buffer(&self) -> &CounterSampleBufferRef {
|
||||
unsafe { msg_send![self, sampleBuffer] }
|
||||
}
|
||||
|
||||
pub fn set_sample_buffer(&self, sample_buffer: &CounterSampleBufferRef) {
|
||||
unsafe { msg_send![self, setSampleBuffer: sample_buffer] }
|
||||
}
|
||||
|
||||
pub fn start_of_vertex_sample_index(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, startOfVertexSampleIndex] }
|
||||
}
|
||||
|
||||
pub fn set_start_of_vertex_sample_index(&self, start_of_vertex_sample_index: NSUInteger) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
setStartOfVertexSampleIndex: start_of_vertex_sample_index
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn end_of_vertex_sample_index(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, endOfVertexSampleIndex] }
|
||||
}
|
||||
|
||||
pub fn set_end_of_vertex_sample_index(&self, end_of_vertex_sample_index: NSUInteger) {
|
||||
unsafe { msg_send![self, setEndOfVertexSampleIndex: end_of_vertex_sample_index] }
|
||||
}
|
||||
|
||||
pub fn start_of_fragment_sample_index(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, startOfFragmentSampleIndex] }
|
||||
}
|
||||
|
||||
pub fn set_start_of_fragment_sample_index(&self, start_of_fragment_sample_index: NSUInteger) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
setStartOfFragmentSampleIndex: start_of_fragment_sample_index
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn end_of_fragment_sample_index(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, endOfFragmentSampleIndex] }
|
||||
}
|
||||
|
||||
pub fn set_end_of_fragment_sample_index(&self, end_of_fragment_sample_index: NSUInteger) {
|
||||
unsafe {
|
||||
msg_send![
|
||||
self,
|
||||
setEndOfFragmentSampleIndex: end_of_fragment_sample_index
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlrenderpasssamplebufferattachmentdescriptorarray>
|
||||
pub enum MTLRenderPassSampleBufferAttachmentDescriptorArray {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLRenderPassSampleBufferAttachmentDescriptorArray;
|
||||
pub struct RenderPassSampleBufferAttachmentDescriptorArray;
|
||||
}
|
||||
|
||||
impl RenderPassSampleBufferAttachmentDescriptorArrayRef {
|
||||
pub fn object_at(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
) -> Option<&RenderPassSampleBufferAttachmentDescriptorRef> {
|
||||
unsafe { msg_send![self, objectAtIndexedSubscript: index] }
|
||||
}
|
||||
|
||||
pub fn set_object_at(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
attachment: Option<&RenderPassSampleBufferAttachmentDescriptorRef>,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self, setObject:attachment
|
||||
atIndexedSubscript:index]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// ## Important!
|
||||
/// When configuring a [`MTLTextureDescriptor`] object for use with an attachment, set its usage
|
||||
/// value to renderTarget if you already know that you intend to use the resulting MTLTexture object in
|
||||
/// an attachment. This may significantly improve your app’s performance with certain hardware.
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlrenderpassdescriptor>
|
||||
pub enum MTLRenderPassDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLRenderPassDescriptor;
|
||||
pub struct RenderPassDescriptor;
|
||||
}
|
||||
|
||||
impl RenderPassDescriptor {
|
||||
/// Creates a default render pass descriptor with no attachments.
|
||||
pub fn new<'a>() -> &'a RenderPassDescriptorRef {
|
||||
unsafe { msg_send![class!(MTLRenderPassDescriptor), renderPassDescriptor] }
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderPassDescriptorRef {
|
||||
pub fn color_attachments(&self) -> &RenderPassColorAttachmentDescriptorArrayRef {
|
||||
unsafe { msg_send![self, colorAttachments] }
|
||||
}
|
||||
|
||||
pub fn depth_attachment(&self) -> Option<&RenderPassDepthAttachmentDescriptorRef> {
|
||||
unsafe { msg_send![self, depthAttachment] }
|
||||
}
|
||||
|
||||
pub fn set_depth_attachment(
|
||||
&self,
|
||||
depth_attachment: Option<&RenderPassDepthAttachmentDescriptorRef>,
|
||||
) {
|
||||
unsafe { msg_send![self, setDepthAttachment: depth_attachment] }
|
||||
}
|
||||
|
||||
pub fn stencil_attachment(&self) -> Option<&RenderPassStencilAttachmentDescriptorRef> {
|
||||
unsafe { msg_send![self, stencilAttachment] }
|
||||
}
|
||||
|
||||
pub fn set_stencil_attachment(
|
||||
&self,
|
||||
stencil_attachment: Option<&RenderPassStencilAttachmentDescriptorRef>,
|
||||
) {
|
||||
unsafe { msg_send![self, setStencilAttachment: stencil_attachment] }
|
||||
}
|
||||
|
||||
pub fn visibility_result_buffer(&self) -> Option<&BufferRef> {
|
||||
unsafe { msg_send![self, visibilityResultBuffer] }
|
||||
}
|
||||
|
||||
pub fn set_visibility_result_buffer(&self, buffer: Option<&BufferRef>) {
|
||||
unsafe { msg_send![self, setVisibilityResultBuffer: buffer] }
|
||||
}
|
||||
|
||||
pub fn render_target_array_length(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, renderTargetArrayLength] }
|
||||
}
|
||||
|
||||
pub fn set_render_target_array_length(&self, length: NSUInteger) {
|
||||
unsafe { msg_send![self, setRenderTargetArrayLength: length] }
|
||||
}
|
||||
|
||||
pub fn render_target_width(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, renderTargetWidth] }
|
||||
}
|
||||
|
||||
pub fn set_render_target_width(&self, size: NSUInteger) {
|
||||
unsafe { msg_send![self, setRenderTargetWidth: size] }
|
||||
}
|
||||
|
||||
pub fn render_target_height(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, renderTargetHeight] }
|
||||
}
|
||||
|
||||
pub fn set_render_target_height(&self, size: NSUInteger) {
|
||||
unsafe { msg_send![self, setRenderTargetHeight: size] }
|
||||
}
|
||||
|
||||
pub fn default_raster_sample_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, defaultRasterSampleCount] }
|
||||
}
|
||||
|
||||
pub fn set_default_raster_sample_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setDefaultRasterSampleCount: count] }
|
||||
}
|
||||
|
||||
pub fn sample_buffer_attachments(&self) -> &RenderPassSampleBufferAttachmentDescriptorArrayRef {
|
||||
unsafe { msg_send![self, sampleBufferAttachments] }
|
||||
}
|
||||
}
|
||||
182
third-party/vendor/metal/src/resource.rs
vendored
Normal file
182
third-party/vendor/metal/src/resource.rs
vendored
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
// Copyright 2016 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
use objc::runtime::{NO, YES};
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlpurgeablestate>
|
||||
#[repr(u64)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum MTLPurgeableState {
|
||||
KeepCurrent = 1,
|
||||
NonVolatile = 2,
|
||||
Volatile = 3,
|
||||
Empty = 4,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlcpucachemode>
|
||||
#[repr(u64)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum MTLCPUCacheMode {
|
||||
DefaultCache = 0,
|
||||
WriteCombined = 1,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlstoragemode>
|
||||
#[repr(u64)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum MTLStorageMode {
|
||||
Shared = 0,
|
||||
Managed = 1,
|
||||
Private = 2,
|
||||
/// Only available on macos(11.0), macCatalyst(14.0), ios(10.0)
|
||||
Memoryless = 3,
|
||||
}
|
||||
|
||||
/// Only available on macos(10.15), ios(13.0)
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlhazardtrackingmode>
|
||||
#[repr(u64)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum MTLHazardTrackingMode {
|
||||
Default = 0,
|
||||
Untracked = 1,
|
||||
Tracked = 2,
|
||||
}
|
||||
|
||||
pub const MTLResourceCPUCacheModeShift: NSUInteger = 0;
|
||||
pub const MTLResourceCPUCacheModeMask: NSUInteger = 0xf << MTLResourceCPUCacheModeShift;
|
||||
pub const MTLResourceStorageModeShift: NSUInteger = 4;
|
||||
pub const MTLResourceStorageModeMask: NSUInteger = 0xf << MTLResourceStorageModeShift;
|
||||
pub const MTLResourceHazardTrackingModeShift: NSUInteger = 8;
|
||||
pub const MTLResourceHazardTrackingModeMask: NSUInteger = 0x3 << MTLResourceHazardTrackingModeShift;
|
||||
|
||||
bitflags! {
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlresourceoptions>
|
||||
#[allow(non_upper_case_globals)]
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct MTLResourceOptions: NSUInteger {
|
||||
const CPUCacheModeDefaultCache = (MTLCPUCacheMode::DefaultCache as NSUInteger) << MTLResourceCPUCacheModeShift;
|
||||
const CPUCacheModeWriteCombined = (MTLCPUCacheMode::WriteCombined as NSUInteger) << MTLResourceCPUCacheModeShift;
|
||||
|
||||
const StorageModeShared = (MTLStorageMode::Shared as NSUInteger) << MTLResourceStorageModeShift;
|
||||
const StorageModeManaged = (MTLStorageMode::Managed as NSUInteger) << MTLResourceStorageModeShift;
|
||||
const StorageModePrivate = (MTLStorageMode::Private as NSUInteger) << MTLResourceStorageModeShift;
|
||||
const StorageModeMemoryless = (MTLStorageMode::Memoryless as NSUInteger) << MTLResourceStorageModeShift;
|
||||
|
||||
/// Only available on macos(10.13), ios(10.0)
|
||||
const HazardTrackingModeDefault = (MTLHazardTrackingMode::Default as NSUInteger) << MTLResourceHazardTrackingModeShift;
|
||||
/// Only available on macos(10.13), ios(10.0)
|
||||
const HazardTrackingModeUntracked = (MTLHazardTrackingMode::Untracked as NSUInteger) << MTLResourceHazardTrackingModeShift;
|
||||
/// Only available on macos(10.15), ios(13.0)
|
||||
const HazardTrackingModeTracked = (MTLHazardTrackingMode::Tracked as NSUInteger) << MTLResourceHazardTrackingModeShift;
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
/// Options that describe how a graphics or compute function uses an argument buffer’s resource.
|
||||
///
|
||||
/// Enabling certain options for certain resources determines whether the Metal driver should
|
||||
/// convert the resource to another format (for example, whether to decompress a color render target).
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlresourceusage>
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct MTLResourceUsage: NSUInteger {
|
||||
/// An option that enables reading from the resource.
|
||||
const Read = 1 << 0;
|
||||
/// An option that enables writing to the resource.
|
||||
const Write = 1 << 1;
|
||||
/// An option that enables sampling from the resource.
|
||||
///
|
||||
/// Specify this option only if the resource is a texture.
|
||||
const Sample = 1 << 2;
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlsizeandalign>
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
#[repr(C)]
|
||||
pub struct MTLSizeAndAlign {
|
||||
pub size: NSUInteger,
|
||||
pub align: NSUInteger,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlresource>
|
||||
pub enum MTLResource {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLResource;
|
||||
pub struct Resource;
|
||||
type ParentType = NsObject;
|
||||
}
|
||||
|
||||
impl ResourceRef {
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: nslabel];
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cpu_cache_mode(&self) -> MTLCPUCacheMode {
|
||||
unsafe { msg_send![self, cpuCacheMode] }
|
||||
}
|
||||
|
||||
pub fn storage_mode(&self) -> MTLStorageMode {
|
||||
unsafe { msg_send![self, storageMode] }
|
||||
}
|
||||
|
||||
pub fn set_purgeable_state(&self, state: MTLPurgeableState) -> MTLPurgeableState {
|
||||
unsafe { msg_send![self, setPurgeableState: state] }
|
||||
}
|
||||
|
||||
/// Only available on macOS 10.13+ & iOS 10.11+
|
||||
pub fn allocated_size(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, allocatedSize] }
|
||||
}
|
||||
|
||||
/// Only available on macos(10.15), ios(13.0)
|
||||
pub fn hazard_tracking_mode(&self) -> MTLHazardTrackingMode {
|
||||
unsafe { msg_send![self, hazardTrackingMode] }
|
||||
}
|
||||
|
||||
/// Only available on macos(10.15), ios(13.0)
|
||||
pub fn resource_options(&self) -> MTLResourceOptions {
|
||||
unsafe { msg_send![self, resourceOptions] }
|
||||
}
|
||||
|
||||
/// Only available on macos(10.13), ios(10.0)
|
||||
pub fn heap(&self) -> &HeapRef {
|
||||
unsafe { msg_send![self, heap] }
|
||||
}
|
||||
|
||||
/// Only available on macos(10.15), ios(13.0)
|
||||
pub fn heap_offset(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, heapOffset] }
|
||||
}
|
||||
|
||||
/// Only available on macos(10.13), ios(10.0)
|
||||
pub fn make_aliasable(&self) {
|
||||
unsafe { msg_send![self, makeAliasable] }
|
||||
}
|
||||
|
||||
/// Only available on macos(10.13), ios(10.0)
|
||||
pub fn is_aliasable(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isAliasable] }
|
||||
}
|
||||
}
|
||||
161
third-party/vendor/metal/src/sampler.rs
vendored
Normal file
161
third-party/vendor/metal/src/sampler.rs
vendored
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
// Copyright 2016 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::{depthstencil::MTLCompareFunction, DeviceRef, NSUInteger};
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlsamplerminmagfilter>
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLSamplerMinMagFilter {
|
||||
Nearest = 0,
|
||||
Linear = 1,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlsamplermipfilter>
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLSamplerMipFilter {
|
||||
NotMipmapped = 0,
|
||||
Nearest = 1,
|
||||
Linear = 2,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlsampleraddressmode>
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLSamplerAddressMode {
|
||||
ClampToEdge = 0,
|
||||
MirrorClampToEdge = 1,
|
||||
Repeat = 2,
|
||||
MirrorRepeat = 3,
|
||||
ClampToZero = 4,
|
||||
ClampToBorderColor = 5,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlsamplerbordercolor>
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLSamplerBorderColor {
|
||||
TransparentBlack = 0,
|
||||
OpaqueBlack = 1,
|
||||
OpaqueWhite = 2,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlsamplerdescriptor>
|
||||
pub enum MTLSamplerDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLSamplerDescriptor;
|
||||
pub struct SamplerDescriptor;
|
||||
}
|
||||
|
||||
impl SamplerDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLSamplerDescriptor);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SamplerDescriptorRef {
|
||||
pub fn set_min_filter(&self, filter: MTLSamplerMinMagFilter) {
|
||||
unsafe { msg_send![self, setMinFilter: filter] }
|
||||
}
|
||||
|
||||
pub fn set_mag_filter(&self, filter: MTLSamplerMinMagFilter) {
|
||||
unsafe { msg_send![self, setMagFilter: filter] }
|
||||
}
|
||||
|
||||
pub fn set_mip_filter(&self, filter: MTLSamplerMipFilter) {
|
||||
unsafe { msg_send![self, setMipFilter: filter] }
|
||||
}
|
||||
|
||||
pub fn set_address_mode_s(&self, mode: MTLSamplerAddressMode) {
|
||||
unsafe { msg_send![self, setSAddressMode: mode] }
|
||||
}
|
||||
|
||||
pub fn set_address_mode_t(&self, mode: MTLSamplerAddressMode) {
|
||||
unsafe { msg_send![self, setTAddressMode: mode] }
|
||||
}
|
||||
|
||||
pub fn set_address_mode_r(&self, mode: MTLSamplerAddressMode) {
|
||||
unsafe { msg_send![self, setRAddressMode: mode] }
|
||||
}
|
||||
|
||||
pub fn set_max_anisotropy(&self, anisotropy: NSUInteger) {
|
||||
unsafe { msg_send![self, setMaxAnisotropy: anisotropy] }
|
||||
}
|
||||
|
||||
pub fn set_compare_function(&self, func: MTLCompareFunction) {
|
||||
unsafe { msg_send![self, setCompareFunction: func] }
|
||||
}
|
||||
|
||||
#[cfg(feature = "private")]
|
||||
pub unsafe fn set_lod_bias(&self, bias: f32) {
|
||||
msg_send![self, setLodBias: bias]
|
||||
}
|
||||
|
||||
pub fn set_lod_min_clamp(&self, clamp: f32) {
|
||||
unsafe { msg_send![self, setLodMinClamp: clamp] }
|
||||
}
|
||||
|
||||
pub fn set_lod_max_clamp(&self, clamp: f32) {
|
||||
unsafe { msg_send![self, setLodMaxClamp: clamp] }
|
||||
}
|
||||
|
||||
pub fn set_lod_average(&self, enable: bool) {
|
||||
unsafe { msg_send![self, setLodAverage: enable] }
|
||||
}
|
||||
|
||||
pub fn set_normalized_coordinates(&self, enable: bool) {
|
||||
unsafe { msg_send![self, setNormalizedCoordinates: enable] }
|
||||
}
|
||||
|
||||
pub fn set_support_argument_buffers(&self, enable: bool) {
|
||||
unsafe { msg_send![self, setSupportArgumentBuffers: enable] }
|
||||
}
|
||||
|
||||
pub fn set_border_color(&self, color: MTLSamplerBorderColor) {
|
||||
unsafe { msg_send![self, setBorderColor: color] }
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: nslabel];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlsamplerstate>
|
||||
pub enum MTLSamplerState {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLSamplerState;
|
||||
pub struct SamplerState;
|
||||
}
|
||||
|
||||
impl SamplerStateRef {
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
}
|
||||
178
third-party/vendor/metal/src/sync.rs
vendored
Normal file
178
third-party/vendor/metal/src/sync.rs
vendored
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
// Copyright 2016 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
use block::{Block, RcBlock};
|
||||
use std::mem;
|
||||
|
||||
#[cfg(feature = "dispatch_queue")]
|
||||
use dispatch;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlsharedeventnotificationblock>
|
||||
type MTLSharedEventNotificationBlock<'a> = RcBlock<(&'a SharedEventRef, u64), ()>;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlevent>
|
||||
pub enum MTLEvent {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLEvent;
|
||||
pub struct Event;
|
||||
}
|
||||
|
||||
impl EventRef {
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlsharedevent>
|
||||
pub enum MTLSharedEvent {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLSharedEvent;
|
||||
pub struct SharedEvent;
|
||||
type ParentType = Event;
|
||||
}
|
||||
|
||||
impl SharedEventRef {
|
||||
pub fn signaled_value(&self) -> u64 {
|
||||
unsafe { msg_send![self, signaledValue] }
|
||||
}
|
||||
|
||||
pub fn set_signaled_value(&self, new_value: u64) {
|
||||
unsafe { msg_send![self, setSignaledValue: new_value] }
|
||||
}
|
||||
|
||||
/// Schedules a notification handler to be called after the shareable event’s signal value
|
||||
/// equals or exceeds a given value.
|
||||
pub fn notify(
|
||||
&self,
|
||||
listener: &SharedEventListenerRef,
|
||||
value: u64,
|
||||
block: MTLSharedEventNotificationBlock,
|
||||
) {
|
||||
unsafe {
|
||||
// If the block doesn't have a signature, this segfaults.
|
||||
// Taken from https://github.com/servo/pathfinder/blob/e858c8dc1d8ff02a5b603e21e09a64d6b3e11327/metal/src/lib.rs#L2327
|
||||
let block = mem::transmute::<
|
||||
MTLSharedEventNotificationBlock,
|
||||
*mut BlockBase<(&SharedEventRef, u64), ()>,
|
||||
>(block);
|
||||
(*block).flags |= BLOCK_HAS_SIGNATURE | BLOCK_HAS_COPY_DISPOSE;
|
||||
(*block).extra = &BLOCK_EXTRA;
|
||||
let () = msg_send![self, notifyListener:listener atValue:value block:block];
|
||||
}
|
||||
|
||||
extern "C" fn dtor(_: *mut BlockBase<(&SharedEventRef, u64), ()>) {}
|
||||
|
||||
const SIGNATURE: &[u8] = b"v16@?0Q8\0";
|
||||
const SIGNATURE_PTR: *const i8 = &SIGNATURE[0] as *const u8 as *const i8;
|
||||
static mut BLOCK_EXTRA: BlockExtra<(&SharedEventRef, u64), ()> = BlockExtra {
|
||||
unknown0: 0 as *mut i32,
|
||||
unknown1: 0 as *mut i32,
|
||||
unknown2: 0 as *mut i32,
|
||||
dtor,
|
||||
signature: &SIGNATURE_PTR,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlsharedeventlistener>
|
||||
pub enum MTLSharedEventListener {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLSharedEventListener;
|
||||
pub struct SharedEventListener;
|
||||
}
|
||||
|
||||
impl SharedEventListener {
|
||||
pub unsafe fn from_queue_handle(queue: dispatch_queue_t) -> Self {
|
||||
let listener: SharedEventListener = msg_send![class!(MTLSharedEventListener), alloc];
|
||||
let ptr: *mut Object = msg_send![listener.as_ref(), initWithDispatchQueue: queue];
|
||||
if ptr.is_null() {
|
||||
panic!("[MTLSharedEventListener alloc] initWithDispatchQueue failed");
|
||||
}
|
||||
listener
|
||||
}
|
||||
|
||||
#[cfg(feature = "dispatch")]
|
||||
pub fn from_queue(queue: &dispatch::Queue) -> Self {
|
||||
unsafe {
|
||||
let raw_queue = std::mem::transmute::<&dispatch::Queue, *const dispatch_queue_t>(queue);
|
||||
Self::from_queue_handle(*raw_queue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlfence>
|
||||
pub enum MTLFence {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLFence;
|
||||
pub struct Fence;
|
||||
}
|
||||
|
||||
impl FenceRef {
|
||||
pub fn device(&self) -> &DeviceRef {
|
||||
unsafe { msg_send![self, device] }
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &str {
|
||||
unsafe {
|
||||
let label = msg_send![self, label];
|
||||
crate::nsstring_as_str(label)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_label(&self, label: &str) {
|
||||
unsafe {
|
||||
let nslabel = crate::nsstring_from_str(label);
|
||||
let () = msg_send![self, setLabel: nslabel];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
/// The render stages at which a synchronization command is triggered.
|
||||
///
|
||||
/// Render stages provide finer control for specifying when synchronization must occur,
|
||||
/// allowing for vertex and fragment processing to overlap in execution.
|
||||
///
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlrenderstages>
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct MTLRenderStages: NSUInteger {
|
||||
/// The vertex rendering stage.
|
||||
const Vertex = 1 << 0;
|
||||
/// The fragment rendering stage.
|
||||
const Fragment = 1 << 1;
|
||||
/// The tile rendering stage.
|
||||
const Tile = 1 << 2;
|
||||
}
|
||||
}
|
||||
|
||||
const BLOCK_HAS_COPY_DISPOSE: i32 = 0x02000000;
|
||||
const BLOCK_HAS_SIGNATURE: i32 = 0x40000000;
|
||||
|
||||
#[repr(C)]
|
||||
struct BlockBase<A, R> {
|
||||
isa: *const std::ffi::c_void, // 0x00
|
||||
flags: i32, // 0x08
|
||||
_reserved: i32, // 0x0c
|
||||
invoke: unsafe extern "C" fn(*mut Block<A, R>, ...) -> R, // 0x10
|
||||
extra: *const BlockExtra<A, R>, // 0x18
|
||||
}
|
||||
|
||||
type BlockExtraDtor<A, R> = extern "C" fn(*mut BlockBase<A, R>);
|
||||
|
||||
#[repr(C)]
|
||||
struct BlockExtra<A, R> {
|
||||
unknown0: *mut i32, // 0x00
|
||||
unknown1: *mut i32, // 0x08
|
||||
unknown2: *mut i32, // 0x10
|
||||
dtor: BlockExtraDtor<A, R>, // 0x18
|
||||
signature: *const *const i8, // 0x20
|
||||
}
|
||||
351
third-party/vendor/metal/src/texture.rs
vendored
Normal file
351
third-party/vendor/metal/src/texture.rs
vendored
Normal file
|
|
@ -0,0 +1,351 @@
|
|||
// Copyright 2016 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::*;
|
||||
|
||||
use objc::runtime::{NO, YES};
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtltexturetype>
|
||||
#[repr(u64)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
||||
pub enum MTLTextureType {
|
||||
D1 = 0,
|
||||
D1Array = 1,
|
||||
D2 = 2,
|
||||
D2Array = 3,
|
||||
D2Multisample = 4,
|
||||
Cube = 5,
|
||||
CubeArray = 6,
|
||||
D3 = 7,
|
||||
D2MultisampleArray = 8,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtltexturecompressiontype>
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
||||
pub enum MTLTextureCompressionType {
|
||||
Lossless = 0,
|
||||
Lossy = 1,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
/// See <https://developer.apple.com/documentation/metal/mtltextureusage>
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct MTLTextureUsage: NSUInteger {
|
||||
const Unknown = 0x0000;
|
||||
const ShaderRead = 0x0001;
|
||||
const ShaderWrite = 0x0002;
|
||||
const RenderTarget = 0x0004;
|
||||
const PixelFormatView = 0x0010;
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtltexturedescriptor>
|
||||
pub enum MTLTextureDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLTextureDescriptor;
|
||||
pub struct TextureDescriptor;
|
||||
}
|
||||
|
||||
impl TextureDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLTextureDescriptor);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TextureDescriptorRef {
|
||||
pub fn texture_type(&self) -> MTLTextureType {
|
||||
unsafe { msg_send![self, textureType] }
|
||||
}
|
||||
|
||||
pub fn set_texture_type(&self, texture_type: MTLTextureType) {
|
||||
unsafe { msg_send![self, setTextureType: texture_type] }
|
||||
}
|
||||
|
||||
pub fn pixel_format(&self) -> MTLPixelFormat {
|
||||
unsafe { msg_send![self, pixelFormat] }
|
||||
}
|
||||
|
||||
pub fn set_pixel_format(&self, pixel_format: MTLPixelFormat) {
|
||||
unsafe { msg_send![self, setPixelFormat: pixel_format] }
|
||||
}
|
||||
|
||||
pub fn width(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, width] }
|
||||
}
|
||||
|
||||
pub fn set_width(&self, width: NSUInteger) {
|
||||
unsafe { msg_send![self, setWidth: width] }
|
||||
}
|
||||
|
||||
pub fn height(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, height] }
|
||||
}
|
||||
|
||||
pub fn set_height(&self, height: NSUInteger) {
|
||||
unsafe { msg_send![self, setHeight: height] }
|
||||
}
|
||||
|
||||
pub fn depth(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, depth] }
|
||||
}
|
||||
|
||||
pub fn set_depth(&self, depth: NSUInteger) {
|
||||
unsafe { msg_send![self, setDepth: depth] }
|
||||
}
|
||||
|
||||
pub fn mipmap_level_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, mipmapLevelCount] }
|
||||
}
|
||||
|
||||
pub fn set_mipmap_level_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setMipmapLevelCount: count] }
|
||||
}
|
||||
|
||||
pub fn set_mipmap_level_count_for_size(&self, size: MTLSize) {
|
||||
let MTLSize {
|
||||
width,
|
||||
height,
|
||||
depth,
|
||||
} = size;
|
||||
let count = (width.max(height).max(depth) as f64).log2().ceil() as u64;
|
||||
self.set_mipmap_level_count(count);
|
||||
}
|
||||
|
||||
pub fn sample_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, sampleCount] }
|
||||
}
|
||||
|
||||
pub fn set_sample_count(&self, count: NSUInteger) {
|
||||
unsafe { msg_send![self, setSampleCount: count] }
|
||||
}
|
||||
|
||||
pub fn array_length(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, arrayLength] }
|
||||
}
|
||||
|
||||
pub fn set_array_length(&self, length: NSUInteger) {
|
||||
unsafe { msg_send![self, setArrayLength: length] }
|
||||
}
|
||||
|
||||
pub fn resource_options(&self) -> MTLResourceOptions {
|
||||
unsafe { msg_send![self, resourceOptions] }
|
||||
}
|
||||
|
||||
pub fn set_resource_options(&self, options: MTLResourceOptions) {
|
||||
unsafe { msg_send![self, setResourceOptions: options] }
|
||||
}
|
||||
|
||||
pub fn cpu_cache_mode(&self) -> MTLCPUCacheMode {
|
||||
unsafe { msg_send![self, cpuCacheMode] }
|
||||
}
|
||||
|
||||
pub fn set_cpu_cache_mode(&self, mode: MTLCPUCacheMode) {
|
||||
unsafe { msg_send![self, setCpuCacheMode: mode] }
|
||||
}
|
||||
|
||||
pub fn storage_mode(&self) -> MTLStorageMode {
|
||||
unsafe { msg_send![self, storageMode] }
|
||||
}
|
||||
|
||||
pub fn set_storage_mode(&self, mode: MTLStorageMode) {
|
||||
unsafe { msg_send![self, setStorageMode: mode] }
|
||||
}
|
||||
|
||||
pub fn usage(&self) -> MTLTextureUsage {
|
||||
unsafe { msg_send![self, usage] }
|
||||
}
|
||||
|
||||
pub fn set_usage(&self, usage: MTLTextureUsage) {
|
||||
unsafe { msg_send![self, setUsage: usage] }
|
||||
}
|
||||
|
||||
pub fn compression_type(&self) -> MTLTextureCompressionType {
|
||||
unsafe { msg_send![self, compressionType] }
|
||||
}
|
||||
|
||||
pub fn set_compression_type(&self, compression_type: MTLTextureCompressionType) {
|
||||
unsafe { msg_send![self, setCompressionType: compression_type] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtltexture>
|
||||
pub enum MTLTexture {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLTexture;
|
||||
pub struct Texture;
|
||||
type ParentType = Resource;
|
||||
}
|
||||
|
||||
impl TextureRef {
|
||||
#[deprecated(since = "0.13.0")]
|
||||
pub fn root_resource(&self) -> Option<&ResourceRef> {
|
||||
unsafe { msg_send![self, rootResource] }
|
||||
}
|
||||
|
||||
pub fn parent_texture(&self) -> Option<&TextureRef> {
|
||||
unsafe { msg_send![self, parentTexture] }
|
||||
}
|
||||
|
||||
pub fn parent_relative_level(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, parentRelativeLevel] }
|
||||
}
|
||||
|
||||
pub fn parent_relative_slice(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, parentRelativeSlice] }
|
||||
}
|
||||
|
||||
pub fn buffer(&self) -> Option<&BufferRef> {
|
||||
unsafe { msg_send![self, buffer] }
|
||||
}
|
||||
|
||||
pub fn buffer_offset(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, bufferOffset] }
|
||||
}
|
||||
|
||||
pub fn buffer_stride(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, bufferBytesPerRow] }
|
||||
}
|
||||
|
||||
pub fn texture_type(&self) -> MTLTextureType {
|
||||
unsafe { msg_send![self, textureType] }
|
||||
}
|
||||
|
||||
pub fn pixel_format(&self) -> MTLPixelFormat {
|
||||
unsafe { msg_send![self, pixelFormat] }
|
||||
}
|
||||
|
||||
pub fn width(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, width] }
|
||||
}
|
||||
|
||||
pub fn height(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, height] }
|
||||
}
|
||||
|
||||
pub fn depth(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, depth] }
|
||||
}
|
||||
|
||||
pub fn mipmap_level_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, mipmapLevelCount] }
|
||||
}
|
||||
|
||||
pub fn sample_count(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, sampleCount] }
|
||||
}
|
||||
|
||||
pub fn array_length(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, arrayLength] }
|
||||
}
|
||||
|
||||
pub fn usage(&self) -> MTLTextureUsage {
|
||||
unsafe { msg_send![self, usage] }
|
||||
}
|
||||
|
||||
/// [framebufferOnly Apple Docs](https://developer.apple.com/documentation/metal/mtltexture/1515749-framebufferonly?language=objc)
|
||||
pub fn framebuffer_only(&self) -> bool {
|
||||
unsafe { msg_send_bool![self, isFramebufferOnly] }
|
||||
}
|
||||
|
||||
pub fn get_bytes(
|
||||
&self,
|
||||
bytes: *mut std::ffi::c_void,
|
||||
stride: NSUInteger,
|
||||
region: MTLRegion,
|
||||
mipmap_level: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self, getBytes:bytes
|
||||
bytesPerRow:stride
|
||||
fromRegion:region
|
||||
mipmapLevel:mipmap_level]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_bytes_in_slice(
|
||||
&self,
|
||||
bytes: *mut std::ffi::c_void,
|
||||
stride: NSUInteger,
|
||||
image_stride: NSUInteger,
|
||||
region: MTLRegion,
|
||||
mipmap_level: NSUInteger,
|
||||
slice: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self, getBytes:bytes
|
||||
bytesPerRow:stride
|
||||
bytesPerImage:image_stride
|
||||
fromRegion:region
|
||||
mipmapLevel:mipmap_level
|
||||
slice:slice]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn replace_region(
|
||||
&self,
|
||||
region: MTLRegion,
|
||||
mipmap_level: NSUInteger,
|
||||
bytes: *const std::ffi::c_void,
|
||||
stride: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self, replaceRegion:region
|
||||
mipmapLevel:mipmap_level
|
||||
withBytes:bytes
|
||||
bytesPerRow:stride]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn replace_region_in_slice(
|
||||
&self,
|
||||
region: MTLRegion,
|
||||
mipmap_level: NSUInteger,
|
||||
slice: NSUInteger,
|
||||
bytes: *const std::ffi::c_void,
|
||||
stride: NSUInteger,
|
||||
image_stride: NSUInteger,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self, replaceRegion:region
|
||||
mipmapLevel:mipmap_level
|
||||
slice:slice
|
||||
withBytes:bytes
|
||||
bytesPerRow:stride
|
||||
bytesPerImage:image_stride]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_texture_view(&self, pixel_format: MTLPixelFormat) -> Texture {
|
||||
unsafe { msg_send![self, newTextureViewWithPixelFormat: pixel_format] }
|
||||
}
|
||||
|
||||
pub fn new_texture_view_from_slice(
|
||||
&self,
|
||||
pixel_format: MTLPixelFormat,
|
||||
texture_type: MTLTextureType,
|
||||
mipmap_levels: crate::NSRange,
|
||||
slices: crate::NSRange,
|
||||
) -> Texture {
|
||||
unsafe {
|
||||
msg_send![self, newTextureViewWithPixelFormat:pixel_format
|
||||
textureType:texture_type
|
||||
levels:mipmap_levels
|
||||
slices:slices]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn gpu_resource_id(&self) -> MTLResourceID {
|
||||
unsafe { msg_send![self, gpuResourceID] }
|
||||
}
|
||||
}
|
||||
90
third-party/vendor/metal/src/types.rs
vendored
Normal file
90
third-party/vendor/metal/src/types.rs
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
// Copyright 2016 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::NSUInteger;
|
||||
use std::default::Default;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlorigin>
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Default)]
|
||||
pub struct MTLOrigin {
|
||||
pub x: NSUInteger,
|
||||
pub y: NSUInteger,
|
||||
pub z: NSUInteger,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlsize>
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Default)]
|
||||
pub struct MTLSize {
|
||||
pub width: NSUInteger,
|
||||
pub height: NSUInteger,
|
||||
pub depth: NSUInteger,
|
||||
}
|
||||
|
||||
impl MTLSize {
|
||||
pub fn new(width: NSUInteger, height: NSUInteger, depth: NSUInteger) -> Self {
|
||||
Self {
|
||||
width,
|
||||
height,
|
||||
depth,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlregion>
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Default)]
|
||||
pub struct MTLRegion {
|
||||
pub origin: MTLOrigin,
|
||||
pub size: MTLSize,
|
||||
}
|
||||
|
||||
impl MTLRegion {
|
||||
#[inline]
|
||||
pub fn new_1d(x: NSUInteger, width: NSUInteger) -> Self {
|
||||
Self::new_2d(x, 0, width, 1)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new_2d(x: NSUInteger, y: NSUInteger, width: NSUInteger, height: NSUInteger) -> Self {
|
||||
Self::new_3d(x, y, 0, width, height, 1)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new_3d(
|
||||
x: NSUInteger,
|
||||
y: NSUInteger,
|
||||
z: NSUInteger,
|
||||
width: NSUInteger,
|
||||
height: NSUInteger,
|
||||
depth: NSUInteger,
|
||||
) -> Self {
|
||||
Self {
|
||||
origin: MTLOrigin { x, y, z },
|
||||
size: MTLSize {
|
||||
width,
|
||||
height,
|
||||
depth,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlsampleposition>
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Default)]
|
||||
pub struct MTLSamplePosition {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Default)]
|
||||
pub struct MTLResourceID {
|
||||
pub _impl: u64,
|
||||
}
|
||||
250
third-party/vendor/metal/src/vertexdescriptor.rs
vendored
Normal file
250
third-party/vendor/metal/src/vertexdescriptor.rs
vendored
Normal file
|
|
@ -0,0 +1,250 @@
|
|||
// Copyright 2016 GFX developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use super::NSUInteger;
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlvertexformat>
|
||||
#[repr(u64)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLVertexFormat {
|
||||
Invalid = 0,
|
||||
UChar2 = 1,
|
||||
UChar3 = 2,
|
||||
UChar4 = 3,
|
||||
Char2 = 4,
|
||||
Char3 = 5,
|
||||
Char4 = 6,
|
||||
UChar2Normalized = 7,
|
||||
UChar3Normalized = 8,
|
||||
UChar4Normalized = 9,
|
||||
Char2Normalized = 10,
|
||||
Char3Normalized = 11,
|
||||
Char4Normalized = 12,
|
||||
UShort2 = 13,
|
||||
UShort3 = 14,
|
||||
UShort4 = 15,
|
||||
Short2 = 16,
|
||||
Short3 = 17,
|
||||
Short4 = 18,
|
||||
UShort2Normalized = 19,
|
||||
UShort3Normalized = 20,
|
||||
UShort4Normalized = 21,
|
||||
Short2Normalized = 22,
|
||||
Short3Normalized = 23,
|
||||
Short4Normalized = 24,
|
||||
Half2 = 25,
|
||||
Half3 = 26,
|
||||
Half4 = 27,
|
||||
Float = 28,
|
||||
Float2 = 29,
|
||||
Float3 = 30,
|
||||
Float4 = 31,
|
||||
Int = 32,
|
||||
Int2 = 33,
|
||||
Int3 = 34,
|
||||
Int4 = 35,
|
||||
UInt = 36,
|
||||
UInt2 = 37,
|
||||
UInt3 = 38,
|
||||
UInt4 = 39,
|
||||
Int1010102Normalized = 40,
|
||||
UInt1010102Normalized = 41,
|
||||
UChar4Normalized_BGRA = 42,
|
||||
UChar = 45,
|
||||
Char = 46,
|
||||
UCharNormalized = 47,
|
||||
CharNormalized = 48,
|
||||
UShort = 49,
|
||||
Short = 50,
|
||||
UShortNormalized = 51,
|
||||
ShortNormalized = 52,
|
||||
Half = 53,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlvertexstepfunction>
|
||||
#[repr(u64)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum MTLVertexStepFunction {
|
||||
Constant = 0,
|
||||
PerVertex = 1,
|
||||
PerInstance = 2,
|
||||
PerPatch = 3,
|
||||
PerPatchControlPoint = 4,
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlvertexbufferlayoutdescriptor>
|
||||
pub enum MTLVertexBufferLayoutDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLVertexBufferLayoutDescriptor;
|
||||
pub struct VertexBufferLayoutDescriptor;
|
||||
}
|
||||
|
||||
impl VertexBufferLayoutDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLVertexBufferLayoutDescriptor);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VertexBufferLayoutDescriptorRef {
|
||||
pub fn stride(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, stride] }
|
||||
}
|
||||
|
||||
pub fn set_stride(&self, stride: NSUInteger) {
|
||||
unsafe { msg_send![self, setStride: stride] }
|
||||
}
|
||||
|
||||
pub fn step_function(&self) -> MTLVertexStepFunction {
|
||||
unsafe { msg_send![self, stepFunction] }
|
||||
}
|
||||
|
||||
pub fn set_step_function(&self, func: MTLVertexStepFunction) {
|
||||
unsafe { msg_send![self, setStepFunction: func] }
|
||||
}
|
||||
|
||||
pub fn step_rate(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, stepRate] }
|
||||
}
|
||||
|
||||
pub fn set_step_rate(&self, step_rate: NSUInteger) {
|
||||
unsafe { msg_send![self, setStepRate: step_rate] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlvertexbufferlayoutdescriptorarray>
|
||||
pub enum MTLVertexBufferLayoutDescriptorArray {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLVertexBufferLayoutDescriptorArray;
|
||||
pub struct VertexBufferLayoutDescriptorArray;
|
||||
}
|
||||
|
||||
impl VertexBufferLayoutDescriptorArrayRef {
|
||||
pub fn object_at(&self, index: NSUInteger) -> Option<&VertexBufferLayoutDescriptorRef> {
|
||||
unsafe { msg_send![self, objectAtIndexedSubscript: index] }
|
||||
}
|
||||
|
||||
pub fn set_object_at(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
layout: Option<&VertexBufferLayoutDescriptorRef>,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self, setObject:layout
|
||||
atIndexedSubscript:index]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlvertexattributedescriptor>
|
||||
pub enum MTLVertexAttributeDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLVertexAttributeDescriptor;
|
||||
pub struct VertexAttributeDescriptor;
|
||||
}
|
||||
|
||||
impl VertexAttributeDescriptor {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
let class = class!(MTLVertexAttributeDescriptor);
|
||||
msg_send![class, new]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VertexAttributeDescriptorRef {
|
||||
pub fn format(&self) -> MTLVertexFormat {
|
||||
unsafe { msg_send![self, format] }
|
||||
}
|
||||
|
||||
pub fn set_format(&self, format: MTLVertexFormat) {
|
||||
unsafe { msg_send![self, setFormat: format] }
|
||||
}
|
||||
|
||||
pub fn offset(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, offset] }
|
||||
}
|
||||
|
||||
pub fn set_offset(&self, offset: NSUInteger) {
|
||||
unsafe { msg_send![self, setOffset: offset] }
|
||||
}
|
||||
|
||||
pub fn buffer_index(&self) -> NSUInteger {
|
||||
unsafe { msg_send![self, bufferIndex] }
|
||||
}
|
||||
|
||||
pub fn set_buffer_index(&self, index: NSUInteger) {
|
||||
unsafe { msg_send![self, setBufferIndex: index] }
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlvertexattributedescriptorarray>
|
||||
pub enum MTLVertexAttributeDescriptorArray {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLVertexAttributeDescriptorArray;
|
||||
pub struct VertexAttributeDescriptorArray;
|
||||
}
|
||||
|
||||
impl VertexAttributeDescriptorArrayRef {
|
||||
pub fn object_at(&self, index: NSUInteger) -> Option<&VertexAttributeDescriptorRef> {
|
||||
unsafe { msg_send![self, objectAtIndexedSubscript: index] }
|
||||
}
|
||||
|
||||
pub fn set_object_at(
|
||||
&self,
|
||||
index: NSUInteger,
|
||||
attribute: Option<&VertexAttributeDescriptorRef>,
|
||||
) {
|
||||
unsafe {
|
||||
msg_send![self, setObject:attribute
|
||||
atIndexedSubscript:index]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://developer.apple.com/documentation/metal/mtlvertexdescriptor>
|
||||
pub enum MTLVertexDescriptor {}
|
||||
|
||||
foreign_obj_type! {
|
||||
type CType = MTLVertexDescriptor;
|
||||
pub struct VertexDescriptor;
|
||||
}
|
||||
|
||||
impl VertexDescriptor {
|
||||
pub fn new<'a>() -> &'a VertexDescriptorRef {
|
||||
unsafe {
|
||||
let class = class!(MTLVertexDescriptor);
|
||||
msg_send![class, vertexDescriptor]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VertexDescriptorRef {
|
||||
pub fn layouts(&self) -> &VertexBufferLayoutDescriptorArrayRef {
|
||||
unsafe { msg_send![self, layouts] }
|
||||
}
|
||||
|
||||
pub fn attributes(&self) -> &VertexAttributeDescriptorArrayRef {
|
||||
unsafe { msg_send![self, attributes] }
|
||||
}
|
||||
|
||||
#[cfg(feature = "private")]
|
||||
pub unsafe fn serialize_descriptor(&self) -> *mut std::ffi::c_void {
|
||||
msg_send![self, newSerializedDescriptor]
|
||||
}
|
||||
|
||||
pub fn reset(&self) {
|
||||
unsafe { msg_send![self, reset] }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue