From 30f55be93644300143cad35bc5d0e0fce7ad0434 Mon Sep 17 00:00:00 2001 From: msiglreith Date: Thu, 23 Nov 2017 00:02:09 +0100 Subject: [PATCH 1/3] Change file-ending for MSVC compiler --- native/{test.c => test.cpp} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename native/{test.c => test.cpp} (98%) diff --git a/native/test.c b/native/test.cpp similarity index 98% rename from native/test.c rename to native/test.cpp index fc7cf93..65095f1 100644 --- a/native/test.c +++ b/native/test.cpp @@ -4,13 +4,13 @@ #include #include -VkSurfaceKHR vkCreateSurfaceGFX(VkInstance); +extern "C" VkSurfaceKHR vkCreateSurfaceGFX(VkInstance); int main() { printf("starting the portability test\n"); VkInstance instance; - VkResult res = 0; + VkResult res = (VkResult)0; unsigned int i; VkInstanceCreateInfo inst_info = {}; From 7d45552cbc3872e7e5be4e1b8ce54e071d706302 Mon Sep 17 00:00:00 2001 From: msiglreith Date: Thu, 23 Nov 2017 00:02:50 +0100 Subject: [PATCH 2/3] Add support for more formats --- src/conv.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/conv.rs b/src/conv.rs index ac589d8..be5d8fc 100644 --- a/src/conv.rs +++ b/src/conv.rs @@ -9,19 +9,34 @@ pub fn format_from_hal(format: format::Format) -> VkFormat { use hal::format::SurfaceType::*; match format.0 { + R5_G6_B5 => match format.1 { + Unorm => VK_FORMAT_R5G6B5_UNORM_PACK16, + _ => unreachable!(), + }, + R4_G4_B4_A4 => match format.1 { + Unorm => VK_FORMAT_R4G4B4A4_UNORM_PACK16, + _ => unreachable!(), + }, R8_G8_B8_A8 => match format.1 { Unorm => VK_FORMAT_R8G8B8A8_UNORM, + Inorm => VK_FORMAT_R8G8B8A8_SNORM, Srgb => VK_FORMAT_R8G8B8A8_SRGB, - _ => unimplemented!() + _ => panic!("format {:?}", format), }, B8_G8_R8_A8 => match format.1 { Unorm => VK_FORMAT_B8G8R8A8_UNORM, + Inorm => VK_FORMAT_B8G8R8A8_SNORM, Srgb => VK_FORMAT_B8G8R8A8_SRGB, - _ => unimplemented!() + _ => panic!("format {:?}", format), + }, + R16_G16_B16_A16 => match format.1 { + Unorm => VK_FORMAT_R16G16B16A16_UNORM, + Inorm => VK_FORMAT_R16G16B16A16_SNORM, + Float => VK_FORMAT_R16G16B16A16_SFLOAT, + _ => panic!("format {:?}", format), }, _ => { - println!("\tformat {:?}", format); - unimplemented!() + panic!("format {:?}", format); } } } From ca1ff277fa66a7559964614e66df4371904601c6 Mon Sep 17 00:00:00 2001 From: msiglreith Date: Thu, 23 Nov 2017 00:04:29 +0100 Subject: [PATCH 3/3] Fix stack corruption caused by command buffers Command buffer size needs to match between exposed type in Rust and vulkan declaration. Therefore, cmd buffers get wrapped in handles --- src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 819e531..ac54f51 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -466,7 +466,7 @@ pub type VkInstance = Handle; pub type VkPhysicalDevice = Handle>; pub type VkDevice = Handle>; pub type VkCommandPool = Handle<::CommandPool>; -pub type VkCommandBuffer = ::CommandBuffer; +pub type VkCommandBuffer = Handle<::CommandBuffer>; #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -4915,7 +4915,7 @@ pub extern fn vkAllocateCommandBuffers( slice::from_raw_parts_mut(pCommandBuffers, count) }; for (out, cmd_buf) in output.iter_mut().zip(cmd_bufs) { - *out = cmd_buf; + *out = Handle::new(cmd_buf); } VkResult::VK_SUCCESS @@ -4931,7 +4931,10 @@ pub extern fn vkFreeCommandBuffers( let buffer_slice = unsafe { slice::from_raw_parts(pCommandBuffers, commandBufferCount as _) }; - let buffers = buffer_slice.to_vec(); + let buffers = buffer_slice + .iter() + .map(|buffer| *buffer.unwrap()) + .collect(); unsafe { commandPool.free(buffers) }; }