summaryrefslogtreecommitdiffstats
path: root/third_party/rust/metal/src/buffer.rs
blob: e334c54e501ff5e54783a283106e085d0c049e00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// 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::*;

pub enum MTLBuffer {}

foreign_obj_type! {
    type CType = MTLBuffer;
    pub struct Buffer;
    pub struct BufferRef;
    type ParentType = ResourceRef;
}

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] }
    }
}