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
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Generated by `scripts/generate.js`

use utils::c_bindings::*;
use utils::vk_traits::*;
use utils::vk_ptr::*;
use utils::vk_convert::*;
use std::os::raw::c_char;
use std::ops::Drop;
use std::ptr;
use std::mem;
use std::cmp;
use std::slice;
use vulkan::*;
use vulkan::vk::*;

#[doc(hidden)]
pub type RawVkDeviceMemory = u64;

/// Wrapper for [VkDeviceMemory](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkDeviceMemory.html).
#[derive(Debug, Clone, Copy)]
pub struct VkDeviceMemory {
    _handle: RawVkDeviceMemory,
    _fn_table: *mut VkFunctionTable
}

impl VkRawType<VkDeviceMemory> for RawVkDeviceMemory {
    fn vk_to_wrapped(src: &RawVkDeviceMemory) -> VkDeviceMemory {
        VkDeviceMemory {
            _handle: *src,
            _fn_table: ptr::null_mut()
        }
    }
}

impl VkWrappedType<RawVkDeviceMemory> for VkDeviceMemory {
    fn vk_to_raw(src: &VkDeviceMemory, dst: &mut RawVkDeviceMemory) {
        *dst = src._handle
    }
}

impl Default for VkDeviceMemory {
    fn default() -> VkDeviceMemory {
        VkDeviceMemory {
            _handle: 0,
            _fn_table: ptr::null_mut()
        }
    }
}

impl PartialEq for VkDeviceMemory {
    fn eq(&self, other: &VkDeviceMemory) -> bool {
        self._handle == other._handle
    }
}

impl VkSetup for VkDeviceMemory {
    fn vk_setup(&mut self, fn_table: *mut VkFunctionTable) {
        self._fn_table = fn_table;
    }
}

impl VkDeviceMemory {
    
    /// Returns the internal Vulkan handle for the object.
    pub fn vk_handle(&self) -> u64 {
        self._handle
    }
    
    /// Indicates if the Vulkan internal handle for this object is 0.
    pub fn is_null(&self) -> bool {
        self._handle == 0
    }
    
    /// Creates an object with a null Vulkan internal handle.
    ///
    /// Calling a method with a null handle will most likely result in a crash.
    pub fn null() -> Self {
        Self {
            _handle: 0,
            _fn_table: ptr::null_mut()
        }
    }
    
    /// Wrapper for [vkFreeMemory](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkFreeMemory.html).
    pub fn free(&self) {
        unsafe {
            ((&*self._fn_table).vkFreeMemory)((*self._fn_table).device, self._handle, ptr::null());
        }
    }
    
    /// Wrapper for [vkMapMemory](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkMapMemory.html).
    pub fn map<'a>(&self, offset: usize, size: usize, flags: VkMemoryMapFlags) -> LavaResult<&'a mut [c_void]> {
        unsafe {
            let raw_offset = vk_to_raw_value(&offset);
            let raw_size = vk_to_raw_value(&size);
            let raw_flags = vk_to_raw_value(&flags);
            let mut vk_result = 0;
            let raw_data = &mut mem::zeroed() as *mut *mut c_void;
            
            vk_result = ((&*self._fn_table).vkMapMemory)((*self._fn_table).device, self._handle, raw_offset, raw_size, raw_flags, raw_data);
            
            let data = slice::from_raw_parts_mut(*raw_data, size);
            if vk_result == 0 { Ok(data) } else { Err((RawVkResult::vk_to_wrapped(&vk_result), data)) }
        }
    }
    
    /// Wrapper for [vkUnmapMemory](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkUnmapMemory.html).
    pub fn unmap(&self) {
        unsafe {
            ((&*self._fn_table).vkUnmapMemory)((*self._fn_table).device, self._handle);
        }
    }
    
    /// Wrapper for [vkGetDeviceMemoryCommitment](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDeviceMemoryCommitment.html).
    pub fn get_commitment(&self) -> usize {
        unsafe {
            let raw_committed_memory_in_bytes = &mut mem::zeroed() as *mut u64;
            
            ((&*self._fn_table).vkGetDeviceMemoryCommitment)((*self._fn_table).device, self._handle, raw_committed_memory_in_bytes);
            
            let committed_memory_in_bytes = new_vk_value(raw_committed_memory_in_bytes);
            committed_memory_in_bytes
        }
    }
}