Add allocation callbacks everywhere
This commit is contained in:
parent
85b7a7c136
commit
ce4945a61c
|
@ -249,7 +249,7 @@ impl ExampleBase {
|
||||||
pp_enabled_extension_names: extension_names_raw.as_ptr(),
|
pp_enabled_extension_names: extension_names_raw.as_ptr(),
|
||||||
enabled_extension_count: extension_names_raw.len() as u32,
|
enabled_extension_count: extension_names_raw.len() as u32,
|
||||||
};
|
};
|
||||||
let instance: Instance = entry.create_instance(&create_info)
|
let instance: Instance = entry.create_instance(&create_info, None)
|
||||||
.expect("Instance creation error");
|
.expect("Instance creation error");
|
||||||
let debug_info = vk::DebugReportCallbackCreateInfoEXT {
|
let debug_info = vk::DebugReportCallbackCreateInfoEXT {
|
||||||
s_type: vk::StructureType::DebugReportCallbackCreateInfoExt,
|
s_type: vk::StructureType::DebugReportCallbackCreateInfoExt,
|
||||||
|
|
|
@ -36,7 +36,37 @@ pub trait VkAllocation {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DefaultAllocatorCallback;
|
pub struct DefaultAllocatorCallback;
|
||||||
|
pub struct TestAlloc;
|
||||||
|
|
||||||
|
impl VkAllocation for TestAlloc {
|
||||||
|
unsafe extern "system" fn allocation(_: *mut (),
|
||||||
|
_: vk::size_t,
|
||||||
|
_: vk::size_t,
|
||||||
|
_: vk::SystemAllocationScope)
|
||||||
|
-> *mut () {
|
||||||
|
ptr::null_mut()
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe extern "system" fn reallocation(_: *mut vk::c_void,
|
||||||
|
_: *mut vk::c_void,
|
||||||
|
_: vk::size_t,
|
||||||
|
_: vk::size_t,
|
||||||
|
_: vk::SystemAllocationScope)
|
||||||
|
-> *mut vk::c_void {
|
||||||
|
ptr::null_mut()
|
||||||
|
}
|
||||||
|
unsafe extern "system" fn free(_: *mut vk::c_void, _: *mut vk::c_void) {}
|
||||||
|
unsafe extern "system" fn internal_allocation(_: *mut vk::c_void,
|
||||||
|
_: vk::size_t,
|
||||||
|
_: vk::InternalAllocationType,
|
||||||
|
_: vk::SystemAllocationScope) {
|
||||||
|
}
|
||||||
|
unsafe extern "system" fn internal_free(_: *mut vk::c_void,
|
||||||
|
_: vk::size_t,
|
||||||
|
_: vk::InternalAllocationType,
|
||||||
|
_: vk::SystemAllocationScope) {
|
||||||
|
}
|
||||||
|
}
|
||||||
impl VkAllocation for DefaultAllocatorCallback {
|
impl VkAllocation for DefaultAllocatorCallback {
|
||||||
unsafe extern "system" fn allocation(_: *mut (),
|
unsafe extern "system" fn allocation(_: *mut (),
|
||||||
_: vk::size_t,
|
_: vk::size_t,
|
||||||
|
|
223
src/device.rs
223
src/device.rs
|
@ -3,6 +3,7 @@ use prelude::*;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use vk;
|
use vk;
|
||||||
|
use ::RawPtr;
|
||||||
|
|
||||||
unsafe impl Sync for Device {}
|
unsafe impl Sync for Device {}
|
||||||
unsafe impl Send for Device {}
|
unsafe impl Send for Device {}
|
||||||
|
@ -24,69 +25,105 @@ impl Device {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy_device(&self) {
|
pub unsafe fn destroy_device(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
self.device_fn.destroy_device(self.handle, ptr::null());
|
self.device_fn.destroy_device(self.handle, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy_sampler(&self, sampler: vk::Sampler) {
|
pub unsafe fn destroy_sampler(&self,
|
||||||
self.device_fn.destroy_sampler(self.handle, sampler, ptr::null());
|
sampler: vk::Sampler,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
|
self.device_fn.destroy_sampler(self.handle, sampler, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn free_memory(&self, memory: vk::DeviceMemory) {
|
pub unsafe fn free_memory(&self,
|
||||||
self.device_fn.free_memory(self.handle, memory, ptr::null());
|
memory: vk::DeviceMemory,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
|
self.device_fn.free_memory(self.handle, memory, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy_fence(&self, fence: vk::Fence) {
|
pub unsafe fn destroy_fence(&self,
|
||||||
self.device_fn.destroy_fence(self.handle, fence, ptr::null());
|
fence: vk::Fence,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
|
self.device_fn.destroy_fence(self.handle, fence, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy_image(&self, image: vk::Image) {
|
pub unsafe fn destroy_image(&self,
|
||||||
self.device_fn.destroy_image(self.handle, image, ptr::null());
|
image: vk::Image,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
|
self.device_fn.destroy_image(self.handle, image, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy_command_pool(&self, pool: vk::CommandPool) {
|
pub unsafe fn destroy_command_pool(&self,
|
||||||
self.device_fn.destroy_command_pool(self.handle, pool, ptr::null());
|
pool: vk::CommandPool,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
|
self.device_fn.destroy_command_pool(self.handle, pool, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub unsafe fn destroy_image_view(&self, image_view: vk::ImageView) {
|
pub unsafe fn destroy_image_view(&self,
|
||||||
self.device_fn.destroy_image_view(self.handle, image_view, ptr::null());
|
image_view: vk::ImageView,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
|
self.device_fn
|
||||||
|
.destroy_image_view(self.handle, image_view, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy_render_pass(&self, renderpass: vk::RenderPass) {
|
pub unsafe fn destroy_render_pass(&self,
|
||||||
self.device_fn.destroy_render_pass(self.handle, renderpass, ptr::null());
|
renderpass: vk::RenderPass,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
|
self.device_fn
|
||||||
|
.destroy_render_pass(self.handle, renderpass, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy_framebuffer(&self, framebuffer: vk::Framebuffer) {
|
pub unsafe fn destroy_framebuffer(&self,
|
||||||
self.device_fn.destroy_framebuffer(self.handle, framebuffer, ptr::null());
|
framebuffer: vk::Framebuffer,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
|
self.device_fn
|
||||||
|
.destroy_framebuffer(self.handle, framebuffer, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy_pipeline_layout(&self, pipeline_layout: vk::PipelineLayout) {
|
pub unsafe fn destroy_pipeline_layout(&self,
|
||||||
self.device_fn.destroy_pipeline_layout(self.handle, pipeline_layout, ptr::null());
|
pipeline_layout: vk::PipelineLayout,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
|
self.device_fn.destroy_pipeline_layout(self.handle,
|
||||||
|
pipeline_layout,
|
||||||
|
allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy_buffer(&self, buffer: vk::Buffer) {
|
pub unsafe fn destroy_buffer(&self,
|
||||||
self.device_fn.destroy_buffer(self.handle, buffer, ptr::null());
|
buffer: vk::Buffer,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
|
self.device_fn.destroy_buffer(self.handle, buffer, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy_shader_module(&self, shader: vk::ShaderModule) {
|
pub unsafe fn destroy_shader_module(&self,
|
||||||
self.device_fn.destroy_shader_module(self.handle, shader, ptr::null());
|
shader: vk::ShaderModule,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
|
self.device_fn
|
||||||
|
.destroy_shader_module(self.handle, shader, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy_pipeline(&self, pipeline: vk::Pipeline) {
|
pub unsafe fn destroy_pipeline(&self,
|
||||||
self.device_fn.destroy_pipeline(self.handle, pipeline, ptr::null());
|
pipeline: vk::Pipeline,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
|
self.device_fn.destroy_pipeline(self.handle, pipeline, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy_semaphore(&self, semaphore: vk::Semaphore) {
|
pub unsafe fn destroy_semaphore(&self,
|
||||||
self.device_fn.destroy_semaphore(self.handle, semaphore, ptr::null());
|
semaphore: vk::Semaphore,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
|
self.device_fn.destroy_semaphore(self.handle, semaphore, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy_descriptor_pool(&self, pool: vk::DescriptorPool) {
|
pub unsafe fn destroy_descriptor_pool(&self,
|
||||||
self.device_fn.destroy_descriptor_pool(self.handle, pool, ptr::null());
|
pool: vk::DescriptorPool,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
|
self.device_fn
|
||||||
|
.destroy_descriptor_pool(self.handle, pool, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy_descriptor_set_layout(&self, layout: vk::DescriptorSetLayout) {
|
pub unsafe fn destroy_descriptor_set_layout(&self, layout: vk::DescriptorSetLayout, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||||
self.device_fn.destroy_descriptor_set_layout(self.handle, layout, ptr::null());
|
self.device_fn
|
||||||
|
.destroy_descriptor_set_layout(self.handle, layout, allocation_callbacks.as_raw_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn free_descriptor_sets(&self,
|
pub unsafe fn free_descriptor_sets(&self,
|
||||||
|
@ -108,11 +145,17 @@ impl Device {
|
||||||
descriptor_copies.as_ptr());
|
descriptor_copies.as_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_sampler(&self, create_info: &vk::SamplerCreateInfo) -> VkResult<vk::Sampler> {
|
pub fn create_sampler(&self,
|
||||||
|
create_info: &vk::SamplerCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
|
-> VkResult<vk::Sampler> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut sampler = mem::uninitialized();
|
let mut sampler = mem::uninitialized();
|
||||||
let err_code = self.device_fn
|
let err_code = self.device_fn
|
||||||
.create_sampler(self.handle, create_info, ptr::null(), &mut sampler);
|
.create_sampler(self.handle,
|
||||||
|
create_info,
|
||||||
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
&mut sampler);
|
||||||
match err_code {
|
match err_code {
|
||||||
vk::Result::Success => Ok(sampler),
|
vk::Result::Success => Ok(sampler),
|
||||||
_ => Err(err_code),
|
_ => Err(err_code),
|
||||||
|
@ -176,12 +219,16 @@ impl Device {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn create_descriptor_set_layout(&self,
|
pub fn create_descriptor_set_layout(&self,
|
||||||
create_info: &vk::DescriptorSetLayoutCreateInfo)
|
create_info: &vk::DescriptorSetLayoutCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
-> VkResult<vk::DescriptorSetLayout> {
|
-> VkResult<vk::DescriptorSetLayout> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut layout = mem::uninitialized();
|
let mut layout = mem::uninitialized();
|
||||||
let err_code = self.device_fn
|
let err_code = self.device_fn
|
||||||
.create_descriptor_set_layout(self.handle, create_info, ptr::null(), &mut layout);
|
.create_descriptor_set_layout(self.handle,
|
||||||
|
create_info,
|
||||||
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
&mut layout);
|
||||||
match err_code {
|
match err_code {
|
||||||
vk::Result::Success => Ok(layout),
|
vk::Result::Success => Ok(layout),
|
||||||
_ => Err(err_code),
|
_ => Err(err_code),
|
||||||
|
@ -199,12 +246,16 @@ impl Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_descriptor_pool(&self,
|
pub fn create_descriptor_pool(&self,
|
||||||
create_info: &vk::DescriptorPoolCreateInfo)
|
create_info: &vk::DescriptorPoolCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
-> VkResult<vk::DescriptorPool> {
|
-> VkResult<vk::DescriptorPool> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut pool = mem::uninitialized();
|
let mut pool = mem::uninitialized();
|
||||||
let err_code = self.device_fn
|
let err_code = self.device_fn
|
||||||
.create_descriptor_pool(self.handle, create_info, ptr::null(), &mut pool);
|
.create_descriptor_pool(self.handle,
|
||||||
|
create_info,
|
||||||
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
&mut pool);
|
||||||
match err_code {
|
match err_code {
|
||||||
vk::Result::Success => Ok(pool),
|
vk::Result::Success => Ok(pool),
|
||||||
_ => Err(err_code),
|
_ => Err(err_code),
|
||||||
|
@ -337,12 +388,16 @@ impl Device {
|
||||||
|
|
||||||
|
|
||||||
pub fn create_semaphore(&self,
|
pub fn create_semaphore(&self,
|
||||||
create_info: &vk::SemaphoreCreateInfo)
|
create_info: &vk::SemaphoreCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
-> VkResult<vk::Semaphore> {
|
-> VkResult<vk::Semaphore> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut semaphore = mem::uninitialized();
|
let mut semaphore = mem::uninitialized();
|
||||||
let err_code = self.device_fn
|
let err_code = self.device_fn
|
||||||
.create_semaphore(self.handle, create_info, ptr::null(), &mut semaphore);
|
.create_semaphore(self.handle,
|
||||||
|
create_info,
|
||||||
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
&mut semaphore);
|
||||||
match err_code {
|
match err_code {
|
||||||
vk::Result::Success => Ok(semaphore),
|
vk::Result::Success => Ok(semaphore),
|
||||||
_ => Err(err_code),
|
_ => Err(err_code),
|
||||||
|
@ -352,7 +407,8 @@ impl Device {
|
||||||
|
|
||||||
pub fn create_graphics_pipelines(&self,
|
pub fn create_graphics_pipelines(&self,
|
||||||
pipeline_cache: vk::PipelineCache,
|
pipeline_cache: vk::PipelineCache,
|
||||||
create_infos: &[vk::GraphicsPipelineCreateInfo])
|
create_infos: &[vk::GraphicsPipelineCreateInfo],
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
-> VkResult<Vec<vk::Pipeline>> {
|
-> VkResult<Vec<vk::Pipeline>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut pipelines = Vec::with_capacity(create_infos.len());
|
let mut pipelines = Vec::with_capacity(create_infos.len());
|
||||||
|
@ -361,7 +417,7 @@ impl Device {
|
||||||
pipeline_cache,
|
pipeline_cache,
|
||||||
create_infos.len() as vk::uint32_t,
|
create_infos.len() as vk::uint32_t,
|
||||||
create_infos.as_ptr(),
|
create_infos.as_ptr(),
|
||||||
ptr::null(),
|
allocation_callbacks.as_raw_ptr(),
|
||||||
pipelines.as_mut_ptr());
|
pipelines.as_mut_ptr());
|
||||||
pipelines.set_len(create_infos.len());
|
pipelines.set_len(create_infos.len());
|
||||||
match err_code {
|
match err_code {
|
||||||
|
@ -371,11 +427,17 @@ impl Device {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_buffer(&self, create_info: &vk::BufferCreateInfo) -> VkResult<vk::Buffer> {
|
pub fn create_buffer(&self,
|
||||||
|
create_info: &vk::BufferCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
|
-> VkResult<vk::Buffer> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut buffer = mem::uninitialized();
|
let mut buffer = mem::uninitialized();
|
||||||
let err_code = self.device_fn
|
let err_code = self.device_fn
|
||||||
.create_buffer(self.handle, create_info, ptr::null(), &mut buffer);
|
.create_buffer(self.handle,
|
||||||
|
create_info,
|
||||||
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
&mut buffer);
|
||||||
match err_code {
|
match err_code {
|
||||||
vk::Result::Success => Ok(buffer),
|
vk::Result::Success => Ok(buffer),
|
||||||
_ => Err(err_code),
|
_ => Err(err_code),
|
||||||
|
@ -384,14 +446,15 @@ impl Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_pipeline_layout(&self,
|
pub fn create_pipeline_layout(&self,
|
||||||
create_info: &vk::PipelineLayoutCreateInfo)
|
create_info: &vk::PipelineLayoutCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
-> VkResult<vk::PipelineLayout> {
|
-> VkResult<vk::PipelineLayout> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut pipeline_layout = mem::uninitialized();
|
let mut pipeline_layout = mem::uninitialized();
|
||||||
let err_code = self.device_fn
|
let err_code = self.device_fn
|
||||||
.create_pipeline_layout(self.handle,
|
.create_pipeline_layout(self.handle,
|
||||||
create_info,
|
create_info,
|
||||||
ptr::null(),
|
allocation_callbacks.as_raw_ptr(),
|
||||||
&mut pipeline_layout);
|
&mut pipeline_layout);
|
||||||
match err_code {
|
match err_code {
|
||||||
vk::Result::Success => Ok(pipeline_layout),
|
vk::Result::Success => Ok(pipeline_layout),
|
||||||
|
@ -423,12 +486,16 @@ impl Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_framebuffer(&self,
|
pub fn create_framebuffer(&self,
|
||||||
create_info: &vk::FramebufferCreateInfo)
|
create_info: &vk::FramebufferCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
-> VkResult<vk::Framebuffer> {
|
-> VkResult<vk::Framebuffer> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut framebuffer = mem::uninitialized();
|
let mut framebuffer = mem::uninitialized();
|
||||||
let err_code = self.device_fn
|
let err_code = self.device_fn
|
||||||
.create_framebuffer(self.handle, create_info, ptr::null(), &mut framebuffer);
|
.create_framebuffer(self.handle,
|
||||||
|
create_info,
|
||||||
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
&mut framebuffer);
|
||||||
match err_code {
|
match err_code {
|
||||||
vk::Result::Success => Ok(framebuffer),
|
vk::Result::Success => Ok(framebuffer),
|
||||||
_ => Err(err_code),
|
_ => Err(err_code),
|
||||||
|
@ -469,12 +536,16 @@ impl Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_render_pass(&self,
|
pub fn create_render_pass(&self,
|
||||||
create_info: &vk::RenderPassCreateInfo)
|
create_info: &vk::RenderPassCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
-> VkResult<vk::RenderPass> {
|
-> VkResult<vk::RenderPass> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut renderpass = mem::uninitialized();
|
let mut renderpass = mem::uninitialized();
|
||||||
let err_code = self.device_fn
|
let err_code = self.device_fn
|
||||||
.create_render_pass(self.handle, create_info, ptr::null(), &mut renderpass);
|
.create_render_pass(self.handle,
|
||||||
|
create_info,
|
||||||
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
&mut renderpass);
|
||||||
match err_code {
|
match err_code {
|
||||||
vk::Result::Success => Ok(renderpass),
|
vk::Result::Success => Ok(renderpass),
|
||||||
_ => Err(err_code),
|
_ => Err(err_code),
|
||||||
|
@ -561,12 +632,16 @@ impl Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_image_view(&self,
|
pub fn create_image_view(&self,
|
||||||
create_info: &vk::ImageViewCreateInfo)
|
create_info: &vk::ImageViewCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
-> VkResult<vk::ImageView> {
|
-> VkResult<vk::ImageView> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut image_view = mem::uninitialized();
|
let mut image_view = mem::uninitialized();
|
||||||
let err_code = self.device_fn
|
let err_code = self.device_fn
|
||||||
.create_image_view(self.handle, create_info, ptr::null(), &mut image_view);
|
.create_image_view(self.handle,
|
||||||
|
create_info,
|
||||||
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
&mut image_view);
|
||||||
match err_code {
|
match err_code {
|
||||||
vk::Result::Success => Ok(image_view),
|
vk::Result::Success => Ok(image_view),
|
||||||
_ => Err(err_code),
|
_ => Err(err_code),
|
||||||
|
@ -589,12 +664,16 @@ impl Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_command_pool(&self,
|
pub fn create_command_pool(&self,
|
||||||
create_info: &vk::CommandPoolCreateInfo)
|
create_info: &vk::CommandPoolCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
-> VkResult<vk::CommandPool> {
|
-> VkResult<vk::CommandPool> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut pool = mem::uninitialized();
|
let mut pool = mem::uninitialized();
|
||||||
let err_code = self.device_fn
|
let err_code = self.device_fn
|
||||||
.create_command_pool(self.handle, create_info, ptr::null(), &mut pool);
|
.create_command_pool(self.handle,
|
||||||
|
create_info,
|
||||||
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
&mut pool);
|
||||||
match err_code {
|
match err_code {
|
||||||
vk::Result::Success => Ok(pool),
|
vk::Result::Success => Ok(pool),
|
||||||
_ => Err(err_code),
|
_ => Err(err_code),
|
||||||
|
@ -603,11 +682,17 @@ impl Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn create_image(&self, create_info: &vk::ImageCreateInfo) -> VkResult<vk::Image> {
|
pub fn create_image(&self,
|
||||||
|
create_info: &vk::ImageCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
|
-> VkResult<vk::Image> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut image = mem::uninitialized();
|
let mut image = mem::uninitialized();
|
||||||
let err_code = self.device_fn
|
let err_code = self.device_fn
|
||||||
.create_image(self.handle, create_info, ptr::null(), &mut image);
|
.create_image(self.handle,
|
||||||
|
create_info,
|
||||||
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
&mut image);
|
||||||
match err_code {
|
match err_code {
|
||||||
vk::Result::Success => Ok(image),
|
vk::Result::Success => Ok(image),
|
||||||
_ => Err(err_code),
|
_ => Err(err_code),
|
||||||
|
@ -634,12 +719,16 @@ impl Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn allocate_memory(&self,
|
pub fn allocate_memory(&self,
|
||||||
create_info: &vk::MemoryAllocateInfo)
|
create_info: &vk::MemoryAllocateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
-> VkResult<vk::DeviceMemory> {
|
-> VkResult<vk::DeviceMemory> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut memory = mem::uninitialized();
|
let mut memory = mem::uninitialized();
|
||||||
let err_code = self.device_fn
|
let err_code = self.device_fn
|
||||||
.allocate_memory(self.handle, create_info, ptr::null(), &mut memory);
|
.allocate_memory(self.handle,
|
||||||
|
create_info,
|
||||||
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
&mut memory);
|
||||||
match err_code {
|
match err_code {
|
||||||
vk::Result::Success => Ok(memory),
|
vk::Result::Success => Ok(memory),
|
||||||
_ => Err(err_code),
|
_ => Err(err_code),
|
||||||
|
@ -648,12 +737,16 @@ impl Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_shader_module(&self,
|
pub fn create_shader_module(&self,
|
||||||
create_info: &vk::ShaderModuleCreateInfo)
|
create_info: &vk::ShaderModuleCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
-> VkResult<vk::ShaderModule> {
|
-> VkResult<vk::ShaderModule> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut shader = mem::uninitialized();
|
let mut shader = mem::uninitialized();
|
||||||
let err_code = self.device_fn
|
let err_code = self.device_fn
|
||||||
.create_shader_module(self.handle, create_info, ptr::null(), &mut shader);
|
.create_shader_module(self.handle,
|
||||||
|
create_info,
|
||||||
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
&mut shader);
|
||||||
match err_code {
|
match err_code {
|
||||||
vk::Result::Success => Ok(shader),
|
vk::Result::Success => Ok(shader),
|
||||||
_ => Err(err_code),
|
_ => Err(err_code),
|
||||||
|
@ -661,11 +754,17 @@ impl Device {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_fence(&self, create_info: &vk::FenceCreateInfo) -> VkResult<vk::Fence> {
|
pub fn create_fence(&self,
|
||||||
|
create_info: &vk::FenceCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
|
-> VkResult<vk::Fence> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut fence = mem::uninitialized();
|
let mut fence = mem::uninitialized();
|
||||||
let err_code = self.device_fn
|
let err_code = self.device_fn
|
||||||
.create_fence(self.handle, create_info, ptr::null(), &mut fence);
|
.create_fence(self.handle,
|
||||||
|
create_info,
|
||||||
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
&mut fence);
|
||||||
match err_code {
|
match err_code {
|
||||||
vk::Result::Success => Ok(fence),
|
vk::Result::Success => Ok(fence),
|
||||||
_ => Err(err_code),
|
_ => Err(err_code),
|
||||||
|
|
|
@ -69,11 +69,15 @@ impl Entry {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_instance(&self,
|
pub fn create_instance(&self,
|
||||||
create_info: &vk::InstanceCreateInfo)
|
create_info: &vk::InstanceCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
-> Result<Instance, InstanceError> {
|
-> Result<Instance, InstanceError> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
use ::RawPtr;
|
||||||
let mut instance: vk::Instance = mem::uninitialized();
|
let mut instance: vk::Instance = mem::uninitialized();
|
||||||
let err_code = self.entry_fn.create_instance(create_info, ptr::null(), &mut instance);
|
let err_code = self.entry_fn.create_instance(create_info,
|
||||||
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
&mut instance);
|
||||||
if err_code != vk::Result::Success {
|
if err_code != vk::Result::Success {
|
||||||
return Err(InstanceError::VkError(err_code));
|
return Err(InstanceError::VkError(err_code));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ use std::ptr;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use vk;
|
use vk;
|
||||||
use device::Device;
|
use device::Device;
|
||||||
|
use ::RawPtr;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum DeviceError {
|
pub enum DeviceError {
|
||||||
|
@ -31,12 +32,13 @@ impl Instance {
|
||||||
|
|
||||||
pub fn create_device(&self,
|
pub fn create_device(&self,
|
||||||
physical_device: vk::PhysicalDevice,
|
physical_device: vk::PhysicalDevice,
|
||||||
create_info: &vk::DeviceCreateInfo)
|
create_info: &vk::DeviceCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
-> Result<Device, DeviceError> {
|
-> Result<Device, DeviceError> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut device: vk::Device = mem::uninitialized();
|
let mut device: vk::Device = mem::uninitialized();
|
||||||
let err_code = self.instance_fn
|
let err_code = self.instance_fn
|
||||||
.create_device(physical_device, create_info, ptr::null(), &mut device);
|
.create_device(physical_device, create_info, allocation_callbacks.as_raw_ptr(), &mut device);
|
||||||
if err_code != vk::Result::Success {
|
if err_code != vk::Result::Success {
|
||||||
return Err(DeviceError::VkError(err_code));
|
return Err(DeviceError::VkError(err_code));
|
||||||
}
|
}
|
||||||
|
|
13
src/lib.rs
13
src/lib.rs
|
@ -8,3 +8,16 @@ pub mod prelude;
|
||||||
pub mod vk;
|
pub mod vk;
|
||||||
pub mod allocator;
|
pub mod allocator;
|
||||||
pub mod extensions;
|
pub mod extensions;
|
||||||
|
|
||||||
|
pub trait RawPtr<T>{
|
||||||
|
fn as_raw_ptr(&self) -> *const T;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'r, T> RawPtr<T> for Option<&'r T>{
|
||||||
|
fn as_raw_ptr(&self) -> *const T{
|
||||||
|
match self{
|
||||||
|
&Some(inner) => inner as *const T,
|
||||||
|
_ => ::std::ptr::null()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue