diff --git a/Cargo.toml b/Cargo.toml index 22609b2..bb27cab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,22 +1,6 @@ -[package] -name = "portability" -version = "0.1.0" -authors = ["Dzmitry Malyshau "] - -[lib] -name = "portability" -crate-type = ["staticlib"] - -[dependencies] -winit = "0.7" - -[dependencies.gfx-hal] -#path = "../gfx/src/hal" -git = "https://github.com/kvark/gfx-rs" -branch = "portable" - -[dependencies.gfx-backend-vulkan] -#path = "../gfx/src/backend/vulkan" -git = "https://github.com/kvark/gfx-rs" -branch = "portable" -features = ["portable"] +[workspace] +members = [ + "libportability", + "libportability-gfx", + "libportability-icd", +] diff --git a/libportability-gfx/Cargo.toml b/libportability-gfx/Cargo.toml new file mode 100644 index 0000000..b34486e --- /dev/null +++ b/libportability-gfx/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "portability-gfx" +version = "0.1.0" +authors = ["Dzmitry Malyshau "] + +[lib] +name = "portability_gfx" + +[dependencies.gfx-hal] +#path = "../gfx/src/hal" +git = "https://github.com/kvark/gfx-rs" +branch = "portable" + +[dependencies.gfx-backend-vulkan] +#path = "../gfx/src/backend/vulkan" +git = "https://github.com/kvark/gfx-rs" +branch = "portable" +features = ["portable"] diff --git a/src/conv.rs b/libportability-gfx/src/conv.rs similarity index 100% rename from src/conv.rs rename to libportability-gfx/src/conv.rs diff --git a/src/handle.rs b/libportability-gfx/src/handle.rs similarity index 100% rename from src/handle.rs rename to libportability-gfx/src/handle.rs diff --git a/libportability-gfx/src/impls.rs b/libportability-gfx/src/impls.rs new file mode 100644 index 0000000..8a3ed03 --- /dev/null +++ b/libportability-gfx/src/impls.rs @@ -0,0 +1,1132 @@ + +use super::*; + +pub fn gfxCreateInstance( + _pCreateInfo: *const VkInstanceCreateInfo, + _pAllocator: *const VkAllocationCallbacks, + pInstance: *mut VkInstance, +) -> VkResult { + let instance = back::Instance::create("portability", 1); + unsafe { *pInstance = Handle::new(instance) }; + VkResult::VK_SUCCESS +} + +pub fn gfxDestroyInstance( + instance: VkInstance, + _pAllocator: *const VkAllocationCallbacks, +) { + instance.unwrap(); + //let it drop +} + +pub fn gfxEnumeratePhysicalDevices( + instance: VkInstance, + pPhysicalDeviceCount: *mut u32, + pPhysicalDevices: *mut VkPhysicalDevice, +) -> VkResult { + let adapters = instance.enumerate_adapters(); + let output = unsafe { slice::from_raw_parts_mut(pPhysicalDevices, *pPhysicalDeviceCount as _) }; + let count = cmp::min(adapters.len(), output.len()); + + for (out, adapter) in output.iter_mut().zip(adapters.into_iter()) { + *out = Handle::new(adapter); + } + + unsafe { *pPhysicalDeviceCount = count as _ }; + VkResult::VK_SUCCESS +} + +pub fn gfxGetPhysicalDeviceQueueFamilyProperties( + adapter: VkPhysicalDevice, + pQueueFamilyPropertyCount: *mut u32, + pQueueFamilyProperties: *mut VkQueueFamilyProperties, +) { + let output = unsafe { + slice::from_raw_parts_mut(pQueueFamilyProperties, *pQueueFamilyPropertyCount as _) + }; + let families = &adapter.queue_families; + if output.len() > families.len() { + unsafe { *pQueueFamilyPropertyCount = families.len() as _ }; + } + for (ref mut out, ref family) in output.iter_mut().zip(families.iter()) { + **out = VkQueueFamilyProperties { + queueFlags: match family.queue_type() { + hal::QueueType::General => VkQueueFlagBits::VK_QUEUE_GRAPHICS_BIT as u32 | VkQueueFlagBits::VK_QUEUE_COMPUTE_BIT as u32, + hal::QueueType::Graphics => VkQueueFlagBits::VK_QUEUE_GRAPHICS_BIT as u32, + hal::QueueType::Compute => VkQueueFlagBits::VK_QUEUE_COMPUTE_BIT as u32, + hal::QueueType::Transfer => VkQueueFlagBits::VK_QUEUE_TRANSFER_BIT as u32, + }, + queueCount: family.max_queues() as _, + timestampValidBits: 0, //TODO + minImageTransferGranularity: VkExtent3D { width: 0, height: 0, depth: 0 }, //TODO + } + } +} + +extern "C" { + pub fn vkGetPhysicalDeviceFeatures(physicalDevice: VkPhysicalDevice, + pFeatures: + *mut VkPhysicalDeviceFeatures); +} +extern "C" { + pub fn vkGetPhysicalDeviceFormatProperties(physicalDevice: + VkPhysicalDevice, + format: VkFormat, + pFormatProperties: + *mut VkFormatProperties); +} +extern "C" { + pub fn vkGetPhysicalDeviceImageFormatProperties(physicalDevice: + VkPhysicalDevice, + format: VkFormat, + type_: VkImageType, + tiling: VkImageTiling, + usage: VkImageUsageFlags, + flags: VkImageCreateFlags, + pImageFormatProperties: + *mut VkImageFormatProperties) + -> VkResult; +} +extern "C" { + pub fn vkGetPhysicalDeviceProperties(physicalDevice: VkPhysicalDevice, + pProperties: + *mut VkPhysicalDeviceProperties); +} + +extern "C" { + pub fn vkGetPhysicalDeviceMemoryProperties(physicalDevice: + VkPhysicalDevice, + pMemoryProperties: + *mut VkPhysicalDeviceMemoryProperties); +} +extern "C" { + pub fn vkGetInstanceProcAddr(instance: VkInstance, + pName: *const ::std::os::raw::c_char) + -> PFN_vkVoidFunction; +} +extern "C" { + pub fn vkGetDeviceProcAddr(device: VkDevice, + pName: *const ::std::os::raw::c_char) + -> PFN_vkVoidFunction; +} + +pub fn gfxCreateDevice( + adapter: VkPhysicalDevice, + pCreateInfo: *const VkDeviceCreateInfo, + _pAllocator: *const VkAllocationCallbacks, + pDevice: *mut VkDevice, +) -> VkResult { + let dev_info = unsafe { &*pCreateInfo }; + let queue_infos = unsafe { + slice::from_raw_parts(dev_info.pQueueCreateInfos, dev_info.queueCreateInfoCount as _) + }; + let request_infos = queue_infos.iter().map(|info| { + let family = adapter + .queue_families[info.queueFamilyIndex as usize] + .clone(); + (family, vec![1.0; info.queueCount as usize]) + }).collect::>(); + + let gpu = adapter.physical_device.clone().open(request_infos); + unsafe { *pDevice = Handle::new(gpu) }; + + VkResult::VK_SUCCESS +} + +pub fn gfxDestroyDevice( + device: VkDevice, + _pAllocator: *const VkAllocationCallbacks, +) { + let _ = device.unwrap(); //TODO? +} + +extern "C" { + pub fn vkEnumerateInstanceExtensionProperties(pLayerName: + *const ::std::os::raw::c_char, + pPropertyCount: *mut u32, + pProperties: + *mut VkExtensionProperties) + -> VkResult; +} +extern "C" { + pub fn vkEnumerateDeviceExtensionProperties(physicalDevice: + VkPhysicalDevice, + pLayerName: + *const ::std::os::raw::c_char, + pPropertyCount: *mut u32, + pProperties: + *mut VkExtensionProperties) + -> VkResult; +} +extern "C" { + pub fn vkEnumerateInstanceLayerProperties(pPropertyCount: *mut u32, + pProperties: + *mut VkLayerProperties) + -> VkResult; +} +extern "C" { + pub fn vkEnumerateDeviceLayerProperties(physicalDevice: VkPhysicalDevice, + pPropertyCount: *mut u32, + pProperties: + *mut VkLayerProperties) + -> VkResult; +} +extern "C" { + pub fn vkGetDeviceQueue(device: VkDevice, queueFamilyIndex: u32, + queueIndex: u32, pQueue: *mut VkQueue); +} +extern "C" { + pub fn vkQueueSubmit(queue: VkQueue, submitCount: u32, + pSubmits: *const VkSubmitInfo, fence: VkFence) + -> VkResult; +} +extern "C" { + pub fn vkQueueWaitIdle(queue: VkQueue) -> VkResult; +} +extern "C" { + pub fn vkDeviceWaitIdle(device: VkDevice) -> VkResult; +} +extern "C" { + pub fn vkAllocateMemory(device: VkDevice, + pAllocateInfo: *const VkMemoryAllocateInfo, + pAllocator: *const VkAllocationCallbacks, + pMemory: *mut VkDeviceMemory) -> VkResult; +} +extern "C" { + pub fn vkFreeMemory(device: VkDevice, memory: VkDeviceMemory, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkMapMemory(device: VkDevice, memory: VkDeviceMemory, + offset: VkDeviceSize, size: VkDeviceSize, + flags: VkMemoryMapFlags, + ppData: *mut *mut ::std::os::raw::c_void) -> VkResult; +} +extern "C" { + pub fn vkUnmapMemory(device: VkDevice, memory: VkDeviceMemory); +} +extern "C" { + pub fn vkFlushMappedMemoryRanges(device: VkDevice, memoryRangeCount: u32, + pMemoryRanges: + *const VkMappedMemoryRange) + -> VkResult; +} +extern "C" { + pub fn vkInvalidateMappedMemoryRanges(device: VkDevice, + memoryRangeCount: u32, + pMemoryRanges: + *const VkMappedMemoryRange) + -> VkResult; +} +extern "C" { + pub fn vkGetDeviceMemoryCommitment(device: VkDevice, + memory: VkDeviceMemory, + pCommittedMemoryInBytes: + *mut VkDeviceSize); +} +extern "C" { + pub fn vkBindBufferMemory(device: VkDevice, buffer: VkBuffer, + memory: VkDeviceMemory, + memoryOffset: VkDeviceSize) -> VkResult; +} +extern "C" { + pub fn vkBindImageMemory(device: VkDevice, image: VkImage, + memory: VkDeviceMemory, + memoryOffset: VkDeviceSize) -> VkResult; +} +extern "C" { + pub fn vkGetBufferMemoryRequirements(device: VkDevice, buffer: VkBuffer, + pMemoryRequirements: + *mut VkMemoryRequirements); +} +extern "C" { + pub fn vkGetImageMemoryRequirements(device: VkDevice, image: VkImage, + pMemoryRequirements: + *mut VkMemoryRequirements); +} +extern "C" { + pub fn vkGetImageSparseMemoryRequirements(device: VkDevice, + image: VkImage, + pSparseMemoryRequirementCount: + *mut u32, + pSparseMemoryRequirements: + *mut VkSparseImageMemoryRequirements); +} +extern "C" { + pub fn vkGetPhysicalDeviceSparseImageFormatProperties(physicalDevice: + VkPhysicalDevice, + format: VkFormat, + type_: VkImageType, + samples: + VkSampleCountFlagBits, + usage: + VkImageUsageFlags, + tiling: + VkImageTiling, + pPropertyCount: + *mut u32, + pProperties: + *mut VkSparseImageFormatProperties); +} +extern "C" { + pub fn vkQueueBindSparse(queue: VkQueue, bindInfoCount: u32, + pBindInfo: *const VkBindSparseInfo, + fence: VkFence) -> VkResult; +} +extern "C" { + pub fn vkCreateFence(device: VkDevice, + pCreateInfo: *const VkFenceCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pFence: *mut VkFence) -> VkResult; +} +extern "C" { + pub fn vkDestroyFence(device: VkDevice, fence: VkFence, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkResetFences(device: VkDevice, fenceCount: u32, + pFences: *const VkFence) -> VkResult; +} +extern "C" { + pub fn vkGetFenceStatus(device: VkDevice, fence: VkFence) -> VkResult; +} +extern "C" { + pub fn vkWaitForFences(device: VkDevice, fenceCount: u32, + pFences: *const VkFence, waitAll: VkBool32, + timeout: u64) -> VkResult; +} +extern "C" { + pub fn vkCreateSemaphore(device: VkDevice, + pCreateInfo: *const VkSemaphoreCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pSemaphore: *mut VkSemaphore) -> VkResult; +} +extern "C" { + pub fn vkDestroySemaphore(device: VkDevice, semaphore: VkSemaphore, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkCreateEvent(device: VkDevice, + pCreateInfo: *const VkEventCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pEvent: *mut VkEvent) -> VkResult; +} +extern "C" { + pub fn vkDestroyEvent(device: VkDevice, event: VkEvent, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkGetEventStatus(device: VkDevice, event: VkEvent) -> VkResult; +} +extern "C" { + pub fn vkSetEvent(device: VkDevice, event: VkEvent) -> VkResult; +} +extern "C" { + pub fn vkResetEvent(device: VkDevice, event: VkEvent) -> VkResult; +} +extern "C" { + pub fn vkCreateQueryPool(device: VkDevice, + pCreateInfo: *const VkQueryPoolCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pQueryPool: *mut VkQueryPool) -> VkResult; +} +extern "C" { + pub fn vkDestroyQueryPool(device: VkDevice, queryPool: VkQueryPool, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkGetQueryPoolResults(device: VkDevice, queryPool: VkQueryPool, + firstQuery: u32, queryCount: u32, + dataSize: usize, + pData: *mut ::std::os::raw::c_void, + stride: VkDeviceSize, + flags: VkQueryResultFlags) -> VkResult; +} +extern "C" { + pub fn vkCreateBuffer(device: VkDevice, + pCreateInfo: *const VkBufferCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pBuffer: *mut VkBuffer) -> VkResult; +} +extern "C" { + pub fn vkDestroyBuffer(device: VkDevice, buffer: VkBuffer, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkCreateBufferView(device: VkDevice, + pCreateInfo: *const VkBufferViewCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pView: *mut VkBufferView) -> VkResult; +} +extern "C" { + pub fn vkDestroyBufferView(device: VkDevice, bufferView: VkBufferView, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkCreateImage(device: VkDevice, + pCreateInfo: *const VkImageCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pImage: *mut VkImage) -> VkResult; +} +extern "C" { + pub fn vkDestroyImage(device: VkDevice, image: VkImage, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkGetImageSubresourceLayout(device: VkDevice, image: VkImage, + pSubresource: + *const VkImageSubresource, + pLayout: *mut VkSubresourceLayout); +} +pub fn gfxCreateImageView( + gpu: VkDevice, + pCreateInfo: *const VkImageViewCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pView: *mut VkImageView, +) -> VkResult { + let info = unsafe { &*pCreateInfo }; + assert!(info.subresourceRange.levelCount != VK_REMAINING_MIP_LEVELS as _); // TODO + assert!(info.subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS as _); // TODO + + let view = gpu + .device + .create_image_view( + &info.image, + conv::hal_from_format(info.format), + conv::map_swizzle(info.components), + conv::map_subresource_range(info.subresourceRange), + ); + + match view { + Ok(view) => { + unsafe { *pView = Handle::new(view) }; + VkResult::VK_SUCCESS + }, + Err(err) => { + panic!("Unexpected image view creation error: {:?}", err) + }, + } +} +pub fn gfxDestroyImageView( + gpu: VkDevice, + imageView: VkImageView, + pAllocator: *const VkAllocationCallbacks, +) { + gpu.device.destroy_image_view(*imageView.unwrap()) +} +extern "C" { + pub fn vkCreateShaderModule(device: VkDevice, + pCreateInfo: *const VkShaderModuleCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pShaderModule: *mut VkShaderModule) + -> VkResult; +} +extern "C" { + pub fn vkDestroyShaderModule(device: VkDevice, + shaderModule: VkShaderModule, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkCreatePipelineCache(device: VkDevice, + pCreateInfo: + *const VkPipelineCacheCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pPipelineCache: *mut VkPipelineCache) + -> VkResult; +} +extern "C" { + pub fn vkDestroyPipelineCache(device: VkDevice, + pipelineCache: VkPipelineCache, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkGetPipelineCacheData(device: VkDevice, + pipelineCache: VkPipelineCache, + pDataSize: *mut usize, + pData: *mut ::std::os::raw::c_void) + -> VkResult; +} +extern "C" { + pub fn vkMergePipelineCaches(device: VkDevice, dstCache: VkPipelineCache, + srcCacheCount: u32, + pSrcCaches: *const VkPipelineCache) + -> VkResult; +} +extern "C" { + pub fn vkCreateGraphicsPipelines(device: VkDevice, + pipelineCache: VkPipelineCache, + createInfoCount: u32, + pCreateInfos: + *const VkGraphicsPipelineCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pPipelines: *mut VkPipeline) -> VkResult; +} +extern "C" { + pub fn vkCreateComputePipelines(device: VkDevice, + pipelineCache: VkPipelineCache, + createInfoCount: u32, + pCreateInfos: + *const VkComputePipelineCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pPipelines: *mut VkPipeline) -> VkResult; +} +extern "C" { + pub fn vkDestroyPipeline(device: VkDevice, pipeline: VkPipeline, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkCreatePipelineLayout(device: VkDevice, + pCreateInfo: + *const VkPipelineLayoutCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pPipelineLayout: *mut VkPipelineLayout) + -> VkResult; +} +extern "C" { + pub fn vkDestroyPipelineLayout(device: VkDevice, + pipelineLayout: VkPipelineLayout, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkCreateSampler(device: VkDevice, + pCreateInfo: *const VkSamplerCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pSampler: *mut VkSampler) -> VkResult; +} +extern "C" { + pub fn vkDestroySampler(device: VkDevice, sampler: VkSampler, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkCreateDescriptorSetLayout(device: VkDevice, + pCreateInfo: + *const VkDescriptorSetLayoutCreateInfo, + pAllocator: + *const VkAllocationCallbacks, + pSetLayout: *mut VkDescriptorSetLayout) + -> VkResult; +} +extern "C" { + pub fn vkDestroyDescriptorSetLayout(device: VkDevice, + descriptorSetLayout: + VkDescriptorSetLayout, + pAllocator: + *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkCreateDescriptorPool(device: VkDevice, + pCreateInfo: + *const VkDescriptorPoolCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pDescriptorPool: *mut VkDescriptorPool) + -> VkResult; +} +extern "C" { + pub fn vkDestroyDescriptorPool(device: VkDevice, + descriptorPool: VkDescriptorPool, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkResetDescriptorPool(device: VkDevice, + descriptorPool: VkDescriptorPool, + flags: VkDescriptorPoolResetFlags) + -> VkResult; +} +extern "C" { + pub fn vkAllocateDescriptorSets(device: VkDevice, + pAllocateInfo: + *const VkDescriptorSetAllocateInfo, + pDescriptorSets: *mut VkDescriptorSet) + -> VkResult; +} +extern "C" { + pub fn vkFreeDescriptorSets(device: VkDevice, + descriptorPool: VkDescriptorPool, + descriptorSetCount: u32, + pDescriptorSets: *const VkDescriptorSet) + -> VkResult; +} +extern "C" { + pub fn vkUpdateDescriptorSets(device: VkDevice, descriptorWriteCount: u32, + pDescriptorWrites: + *const VkWriteDescriptorSet, + descriptorCopyCount: u32, + pDescriptorCopies: + *const VkCopyDescriptorSet); +} +extern "C" { + pub fn vkCreateFramebuffer(device: VkDevice, + pCreateInfo: *const VkFramebufferCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pFramebuffer: *mut VkFramebuffer) -> VkResult; +} +extern "C" { + pub fn vkDestroyFramebuffer(device: VkDevice, framebuffer: VkFramebuffer, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkCreateRenderPass(device: VkDevice, + pCreateInfo: *const VkRenderPassCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pRenderPass: *mut VkRenderPass) -> VkResult; +} +extern "C" { + pub fn vkDestroyRenderPass(device: VkDevice, renderPass: VkRenderPass, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkGetRenderAreaGranularity(device: VkDevice, + renderPass: VkRenderPass, + pGranularity: *mut VkExtent2D); +} + +pub fn gfxCreateCommandPool( + gpu: VkDevice, + pCreateInfo: *const VkCommandPoolCreateInfo, + _pAllocator: *const VkAllocationCallbacks, + pCommandPool: *mut VkCommandPool, +) -> VkResult { + use hal::pool::CommandPoolCreateFlags; + + let info = unsafe { &*pCreateInfo }; + assert_eq!(info.queueFamilyIndex, 0); //TODO + let family = gpu.queue_groups[0].family(); + + let mut flags = CommandPoolCreateFlags::empty(); + if info.flags & VkCommandPoolCreateFlagBits::VK_COMMAND_POOL_CREATE_TRANSIENT_BIT as u32 != 0 { + flags |= CommandPoolCreateFlags::TRANSIENT; + } + if info.flags & VkCommandPoolCreateFlagBits::VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT as u32 != 0 { + flags |= CommandPoolCreateFlags::RESET_INDIVIDUAL; + } + + let pool = gpu.device.create_command_pool(family, flags); + unsafe { *pCommandPool = Handle::new(pool) }; + VkResult::VK_SUCCESS +} + +pub fn gfxDestroyCommandPool( + gpu: VkDevice, + commandPool: VkCommandPool, + _pAllocator: *const VkAllocationCallbacks, +) { + gpu.device.destroy_command_pool(*commandPool.unwrap()); +} + +pub fn gfxResetCommandPool( + _gpu: VkDevice, + mut commandPool: VkCommandPool, + _flags: VkCommandPoolResetFlags, +) -> VkResult { + commandPool.reset(); + VkResult::VK_SUCCESS +} + +pub fn gfxAllocateCommandBuffers( + _gpu: VkDevice, + pAllocateInfo: *const VkCommandBufferAllocateInfo, + pCommandBuffers: *mut VkCommandBuffer, +) -> VkResult { + let info = unsafe { &mut *(pAllocateInfo as *mut VkCommandBufferAllocateInfo) }; + assert_eq!(info.level, VkCommandBufferLevel::VK_COMMAND_BUFFER_LEVEL_PRIMARY); //TODO + let count = info.commandBufferCount as usize; + + let cmd_bufs = info.commandPool.allocate(count); + + let output = unsafe { + slice::from_raw_parts_mut(pCommandBuffers, count) + }; + for (out, cmd_buf) in output.iter_mut().zip(cmd_bufs) { + *out = Handle::new(cmd_buf); + } + + VkResult::VK_SUCCESS +} + +pub fn gfxFreeCommandBuffers( + _gpu: VkDevice, + mut commandPool: VkCommandPool, + commandBufferCount: u32, + pCommandBuffers: *const VkCommandBuffer, +) { + let buffer_slice = unsafe { + slice::from_raw_parts(pCommandBuffers, commandBufferCount as _) + }; + let buffers = buffer_slice + .iter() + .map(|buffer| *buffer.unwrap()) + .collect(); + + unsafe { commandPool.free(buffers) }; +} + +extern "C" { + pub fn vkBeginCommandBuffer(commandBuffer: VkCommandBuffer, + pBeginInfo: *const VkCommandBufferBeginInfo) + -> VkResult; +} +extern "C" { + pub fn vkEndCommandBuffer(commandBuffer: VkCommandBuffer) -> VkResult; +} +extern "C" { + pub fn vkResetCommandBuffer(commandBuffer: VkCommandBuffer, + flags: VkCommandBufferResetFlags) -> VkResult; +} +extern "C" { + pub fn vkCmdBindPipeline(commandBuffer: VkCommandBuffer, + pipelineBindPoint: VkPipelineBindPoint, + pipeline: VkPipeline); +} +extern "C" { + pub fn vkCmdSetViewport(commandBuffer: VkCommandBuffer, + firstViewport: u32, viewportCount: u32, + pViewports: *const VkViewport); +} +extern "C" { + pub fn vkCmdSetScissor(commandBuffer: VkCommandBuffer, firstScissor: u32, + scissorCount: u32, pScissors: *const VkRect2D); +} +extern "C" { + pub fn vkCmdSetLineWidth(commandBuffer: VkCommandBuffer, lineWidth: f32); +} +extern "C" { + pub fn vkCmdSetDepthBias(commandBuffer: VkCommandBuffer, + depthBiasConstantFactor: f32, + depthBiasClamp: f32, depthBiasSlopeFactor: f32); +} +extern "C" { + pub fn vkCmdSetBlendConstants(commandBuffer: VkCommandBuffer, + blendConstants: *const f32); +} +extern "C" { + pub fn vkCmdSetDepthBounds(commandBuffer: VkCommandBuffer, + minDepthBounds: f32, maxDepthBounds: f32); +} +extern "C" { + pub fn vkCmdSetStencilCompareMask(commandBuffer: VkCommandBuffer, + faceMask: VkStencilFaceFlags, + compareMask: u32); +} +extern "C" { + pub fn vkCmdSetStencilWriteMask(commandBuffer: VkCommandBuffer, + faceMask: VkStencilFaceFlags, + writeMask: u32); +} +extern "C" { + pub fn vkCmdSetStencilReference(commandBuffer: VkCommandBuffer, + faceMask: VkStencilFaceFlags, + reference: u32); +} +extern "C" { + pub fn vkCmdBindDescriptorSets(commandBuffer: VkCommandBuffer, + pipelineBindPoint: VkPipelineBindPoint, + layout: VkPipelineLayout, firstSet: u32, + descriptorSetCount: u32, + pDescriptorSets: *const VkDescriptorSet, + dynamicOffsetCount: u32, + pDynamicOffsets: *const u32); +} +extern "C" { + pub fn vkCmdBindIndexBuffer(commandBuffer: VkCommandBuffer, + buffer: VkBuffer, offset: VkDeviceSize, + indexType: VkIndexType); +} +extern "C" { + pub fn vkCmdBindVertexBuffers(commandBuffer: VkCommandBuffer, + firstBinding: u32, bindingCount: u32, + pBuffers: *const VkBuffer, + pOffsets: *const VkDeviceSize); +} +extern "C" { + pub fn vkCmdDraw(commandBuffer: VkCommandBuffer, vertexCount: u32, + instanceCount: u32, firstVertex: u32, + firstInstance: u32); +} +extern "C" { + pub fn vkCmdDrawIndexed(commandBuffer: VkCommandBuffer, indexCount: u32, + instanceCount: u32, firstIndex: u32, + vertexOffset: i32, firstInstance: u32); +} +extern "C" { + pub fn vkCmdDrawIndirect(commandBuffer: VkCommandBuffer, buffer: VkBuffer, + offset: VkDeviceSize, drawCount: u32, + stride: u32); +} +extern "C" { + pub fn vkCmdDrawIndexedIndirect(commandBuffer: VkCommandBuffer, + buffer: VkBuffer, offset: VkDeviceSize, + drawCount: u32, stride: u32); +} +extern "C" { + pub fn vkCmdDispatch(commandBuffer: VkCommandBuffer, groupCountX: u32, + groupCountY: u32, groupCountZ: u32); +} +extern "C" { + pub fn vkCmdDispatchIndirect(commandBuffer: VkCommandBuffer, + buffer: VkBuffer, offset: VkDeviceSize); +} +extern "C" { + pub fn vkCmdCopyBuffer(commandBuffer: VkCommandBuffer, + srcBuffer: VkBuffer, dstBuffer: VkBuffer, + regionCount: u32, pRegions: *const VkBufferCopy); +} +extern "C" { + pub fn vkCmdCopyImage(commandBuffer: VkCommandBuffer, srcImage: VkImage, + srcImageLayout: VkImageLayout, dstImage: VkImage, + dstImageLayout: VkImageLayout, regionCount: u32, + pRegions: *const VkImageCopy); +} +extern "C" { + pub fn vkCmdBlitImage(commandBuffer: VkCommandBuffer, srcImage: VkImage, + srcImageLayout: VkImageLayout, dstImage: VkImage, + dstImageLayout: VkImageLayout, regionCount: u32, + pRegions: *const VkImageBlit, filter: VkFilter); +} +extern "C" { + pub fn vkCmdCopyBufferToImage(commandBuffer: VkCommandBuffer, + srcBuffer: VkBuffer, dstImage: VkImage, + dstImageLayout: VkImageLayout, + regionCount: u32, + pRegions: *const VkBufferImageCopy); +} +extern "C" { + pub fn vkCmdCopyImageToBuffer(commandBuffer: VkCommandBuffer, + srcImage: VkImage, + srcImageLayout: VkImageLayout, + dstBuffer: VkBuffer, regionCount: u32, + pRegions: *const VkBufferImageCopy); +} +extern "C" { + pub fn vkCmdUpdateBuffer(commandBuffer: VkCommandBuffer, + dstBuffer: VkBuffer, dstOffset: VkDeviceSize, + dataSize: VkDeviceSize, + pData: *const ::std::os::raw::c_void); +} +extern "C" { + pub fn vkCmdFillBuffer(commandBuffer: VkCommandBuffer, + dstBuffer: VkBuffer, dstOffset: VkDeviceSize, + size: VkDeviceSize, data: u32); +} +extern "C" { + pub fn vkCmdClearColorImage(commandBuffer: VkCommandBuffer, + image: VkImage, imageLayout: VkImageLayout, + pColor: *const VkClearColorValue, + rangeCount: u32, + pRanges: *const VkImageSubresourceRange); +} +extern "C" { + pub fn vkCmdClearDepthStencilImage(commandBuffer: VkCommandBuffer, + image: VkImage, + imageLayout: VkImageLayout, + pDepthStencil: + *const VkClearDepthStencilValue, + rangeCount: u32, + pRanges: + *const VkImageSubresourceRange); +} +extern "C" { + pub fn vkCmdClearAttachments(commandBuffer: VkCommandBuffer, + attachmentCount: u32, + pAttachments: *const VkClearAttachment, + rectCount: u32, pRects: *const VkClearRect); +} +extern "C" { + pub fn vkCmdResolveImage(commandBuffer: VkCommandBuffer, + srcImage: VkImage, srcImageLayout: VkImageLayout, + dstImage: VkImage, dstImageLayout: VkImageLayout, + regionCount: u32, + pRegions: *const VkImageResolve); +} +extern "C" { + pub fn vkCmdSetEvent(commandBuffer: VkCommandBuffer, event: VkEvent, + stageMask: VkPipelineStageFlags); +} +extern "C" { + pub fn vkCmdResetEvent(commandBuffer: VkCommandBuffer, event: VkEvent, + stageMask: VkPipelineStageFlags); +} +extern "C" { + pub fn vkCmdWaitEvents(commandBuffer: VkCommandBuffer, eventCount: u32, + pEvents: *const VkEvent, + srcStageMask: VkPipelineStageFlags, + dstStageMask: VkPipelineStageFlags, + memoryBarrierCount: u32, + pMemoryBarriers: *const VkMemoryBarrier, + bufferMemoryBarrierCount: u32, + pBufferMemoryBarriers: + *const VkBufferMemoryBarrier, + imageMemoryBarrierCount: u32, + pImageMemoryBarriers: *const VkImageMemoryBarrier); +} +extern "C" { + pub fn vkCmdPipelineBarrier(commandBuffer: VkCommandBuffer, + srcStageMask: VkPipelineStageFlags, + dstStageMask: VkPipelineStageFlags, + dependencyFlags: VkDependencyFlags, + memoryBarrierCount: u32, + pMemoryBarriers: *const VkMemoryBarrier, + bufferMemoryBarrierCount: u32, + pBufferMemoryBarriers: + *const VkBufferMemoryBarrier, + imageMemoryBarrierCount: u32, + pImageMemoryBarriers: + *const VkImageMemoryBarrier); +} +extern "C" { + pub fn vkCmdBeginQuery(commandBuffer: VkCommandBuffer, + queryPool: VkQueryPool, query: u32, + flags: VkQueryControlFlags); +} +extern "C" { + pub fn vkCmdEndQuery(commandBuffer: VkCommandBuffer, + queryPool: VkQueryPool, query: u32); +} +extern "C" { + pub fn vkCmdResetQueryPool(commandBuffer: VkCommandBuffer, + queryPool: VkQueryPool, firstQuery: u32, + queryCount: u32); +} +extern "C" { + pub fn vkCmdWriteTimestamp(commandBuffer: VkCommandBuffer, + pipelineStage: VkPipelineStageFlagBits, + queryPool: VkQueryPool, query: u32); +} +extern "C" { + pub fn vkCmdCopyQueryPoolResults(commandBuffer: VkCommandBuffer, + queryPool: VkQueryPool, firstQuery: u32, + queryCount: u32, dstBuffer: VkBuffer, + dstOffset: VkDeviceSize, + stride: VkDeviceSize, + flags: VkQueryResultFlags); +} +extern "C" { + pub fn vkCmdPushConstants(commandBuffer: VkCommandBuffer, + layout: VkPipelineLayout, + stageFlags: VkShaderStageFlags, offset: u32, + size: u32, + pValues: *const ::std::os::raw::c_void); +} +extern "C" { + pub fn vkCmdBeginRenderPass(commandBuffer: VkCommandBuffer, + pRenderPassBegin: + *const VkRenderPassBeginInfo, + contents: VkSubpassContents); +} +extern "C" { + pub fn vkCmdNextSubpass(commandBuffer: VkCommandBuffer, + contents: VkSubpassContents); +} +extern "C" { + pub fn vkCmdEndRenderPass(commandBuffer: VkCommandBuffer); +} +extern "C" { + pub fn vkCmdExecuteCommands(commandBuffer: VkCommandBuffer, + commandBufferCount: u32, + pCommandBuffers: *const VkCommandBuffer); +} + +pub fn gfxDestroySurfaceKHR( + _instance: VkInstance, + surface: VkSurfaceKHR, + _: *const VkAllocationCallbacks, +) { + let _ = surface.unwrap(); //TODO +} + +pub fn gfxGetPhysicalDeviceSurfaceSupportKHR( + adapter: VkPhysicalDevice, + queueFamilyIndex: u32, + surface: VkSurfaceKHR, + pSupported: *mut VkBool32, +) -> VkResult { + let family = &adapter.queue_families[queueFamilyIndex as usize]; + let supports = surface.supports_queue_family(family); + unsafe { *pSupported = supports as _ }; + VkResult::VK_SUCCESS +} + +pub fn gfxGetPhysicalDeviceSurfaceCapabilitiesKHR( + adapter: VkPhysicalDevice, + surface: VkSurfaceKHR, + pSurfaceCapabilities: *mut VkSurfaceCapabilitiesKHR, +) -> VkResult { + let (caps, _) = surface.capabilities_and_formats(&adapter.physical_device); + + let output = VkSurfaceCapabilitiesKHR { + minImageCount: caps.image_count.start, + maxImageCount: caps.image_count.end, + currentExtent: match caps.current_extent { + Some(extent) => conv::extent2d_from_hal(extent), + None => VkExtent2D { + width: !0, + height: !0, + }, + }, + minImageExtent: conv::extent2d_from_hal(caps.extents.start), + maxImageExtent: conv::extent2d_from_hal(caps.extents.end), + maxImageArrayLayers: caps.max_image_layers, + supportedTransforms: VkSurfaceTransformFlagBitsKHR::VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR as _, + currentTransform: VkSurfaceTransformFlagBitsKHR::VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR, + supportedCompositeAlpha: VkCompositeAlphaFlagBitsKHR::VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR as _, + supportedUsageFlags: 0, + }; + + unsafe { *pSurfaceCapabilities = output }; + VkResult::VK_SUCCESS +} + +pub fn gfxGetPhysicalDeviceSurfaceFormatsKHR( + adapter: VkPhysicalDevice, + surface: VkSurfaceKHR, + pSurfaceFormatCount: *mut u32, + pSurfaceFormats: *mut VkSurfaceFormatKHR, +) -> VkResult { + let (_, formats) = surface.capabilities_and_formats(&adapter.physical_device); + let output = unsafe { slice::from_raw_parts_mut(pSurfaceFormats, *pSurfaceFormatCount as usize) }; + + if output.len() > formats.len() { + unsafe { *pSurfaceFormatCount = formats.len() as u32 }; + } + for (out, format) in output.iter_mut().zip(formats) { + *out = VkSurfaceFormatKHR { + format: conv::format_from_hal(format), + colorSpace: VkColorSpaceKHR::VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, //TODO + }; + } + + VkResult::VK_SUCCESS +} + +pub fn gfxGetPhysicalDeviceSurfacePresentModesKHR( + _adapter: VkPhysicalDevice, + _surface: VkSurfaceKHR, + pPresentModeCount: *mut u32, + pPresentModes: *mut VkPresentModeKHR, +) -> VkResult { + let modes = vec![VkPresentModeKHR::VK_PRESENT_MODE_FIFO_KHR]; //TODO + let output = unsafe { slice::from_raw_parts_mut(pPresentModes, *pPresentModeCount as usize) }; + + if output.len() > modes.len() { + unsafe { *pPresentModeCount = modes.len() as u32 }; + } + for (out, mode) in output.iter_mut().zip(modes) { + *out = mode; + } + + VkResult::VK_SUCCESS +} + +extern "C" { + pub fn vkCmdProcessCommandsNVX(commandBuffer: VkCommandBuffer, + pProcessCommandsInfo: + *const VkCmdProcessCommandsInfoNVX); +} +extern "C" { + pub fn vkCmdReserveSpaceForCommandsNVX(commandBuffer: VkCommandBuffer, + pReserveSpaceInfo: + *const VkCmdReserveSpaceForCommandsInfoNVX); +} +extern "C" { + pub fn vkCreateIndirectCommandsLayoutNVX(device: VkDevice, + pCreateInfo: + *const VkIndirectCommandsLayoutCreateInfoNVX, + pAllocator: + *const VkAllocationCallbacks, + pIndirectCommandsLayout: + *mut VkIndirectCommandsLayoutNVX) + -> VkResult; +} +extern "C" { + pub fn vkDestroyIndirectCommandsLayoutNVX(device: VkDevice, + indirectCommandsLayout: + VkIndirectCommandsLayoutNVX, + pAllocator: + *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkCreateObjectTableNVX(device: VkDevice, + pCreateInfo: + *const VkObjectTableCreateInfoNVX, + pAllocator: *const VkAllocationCallbacks, + pObjectTable: *mut VkObjectTableNVX) + -> VkResult; +} +extern "C" { + pub fn vkDestroyObjectTableNVX(device: VkDevice, + objectTable: VkObjectTableNVX, + pAllocator: *const VkAllocationCallbacks); +} +extern "C" { + pub fn vkRegisterObjectsNVX(device: VkDevice, + objectTable: VkObjectTableNVX, + objectCount: u32, + ppObjectTableEntries: + *const *const VkObjectTableEntryNVX, + pObjectIndices: *const u32) -> VkResult; +} +extern "C" { + pub fn vkUnregisterObjectsNVX(device: VkDevice, + objectTable: VkObjectTableNVX, + objectCount: u32, + pObjectEntryTypes: + *const VkObjectEntryTypeNVX, + pObjectIndices: *const u32) -> VkResult; +} +extern "C" { + pub fn vkGetPhysicalDeviceGeneratedCommandsPropertiesNVX(physicalDevice: + VkPhysicalDevice, + pFeatures: + *mut VkDeviceGeneratedCommandsFeaturesNVX, + pLimits: + *mut VkDeviceGeneratedCommandsLimitsNVX); +} +extern "C" { + pub fn vkCmdSetViewportWScalingNV(commandBuffer: VkCommandBuffer, + firstViewport: u32, viewportCount: u32, + pViewportWScalings: + *const VkViewportWScalingNV); +} +extern "C" { + pub fn vkReleaseDisplayEXT(physicalDevice: VkPhysicalDevice, + display: VkDisplayKHR) -> VkResult; +} +extern "C" { + pub fn vkGetPhysicalDeviceSurfaceCapabilities2EXT(physicalDevice: + VkPhysicalDevice, + surface: VkSurfaceKHR, + pSurfaceCapabilities: + *mut VkSurfaceCapabilities2EXT) + -> VkResult; +} +extern "C" { + pub fn vkDisplayPowerControlEXT(device: VkDevice, display: VkDisplayKHR, + pDisplayPowerInfo: + *const VkDisplayPowerInfoEXT) + -> VkResult; +} +extern "C" { + pub fn vkRegisterDeviceEventEXT(device: VkDevice, + pDeviceEventInfo: + *const VkDeviceEventInfoEXT, + pAllocator: *const VkAllocationCallbacks, + pFence: *mut VkFence) -> VkResult; +} +extern "C" { + pub fn vkRegisterDisplayEventEXT(device: VkDevice, display: VkDisplayKHR, + pDisplayEventInfo: + *const VkDisplayEventInfoEXT, + pAllocator: *const VkAllocationCallbacks, + pFence: *mut VkFence) -> VkResult; +} +extern "C" { + pub fn vkGetSwapchainCounterEXT(device: VkDevice, + swapchain: VkSwapchainKHR, + counter: VkSurfaceCounterFlagBitsEXT, + pCounterValue: *mut u64) -> VkResult; +} +extern "C" { + pub fn vkCmdSetDiscardRectangleEXT(commandBuffer: VkCommandBuffer, + firstDiscardRectangle: u32, + discardRectangleCount: u32, + pDiscardRectangles: *const VkRect2D); +} diff --git a/src/lib.rs b/libportability-gfx/src/lib.rs similarity index 85% rename from src/lib.rs rename to libportability-gfx/src/lib.rs index 310fae6..0d9698a 100644 --- a/src/lib.rs +++ b/libportability-gfx/src/lib.rs @@ -5,10 +5,10 @@ extern crate gfx_hal as hal; extern crate gfx_backend_vulkan as back; -extern crate winit; mod conv; mod handle; +mod impls; use std::{cmp, slice}; use hal::{Device, Instance, PhysicalDevice, QueueFamily, Surface}; // traits only @@ -16,6 +16,29 @@ use hal::pool::RawCommandPool; use back::Backend as B; use handle::Handle; +pub use impls::*; + +// Vulkan objects +pub type VkInstance = Handle; +pub type VkPhysicalDevice = Handle>; +pub type VkDevice = Handle>; +pub type VkCommandPool = Handle<::CommandPool>; +pub type VkCommandBuffer = Handle<::CommandBuffer>; + +pub type VkImage = Handle<::Image>; +pub type VkImageView = Handle<::ImageView>; + +//NOTE: all *KHR types have to be pure `Handle` things for compatibility with +//`VK_DEFINE_NON_DISPATCHABLE_HANDLE` used in `vulkan.h` +pub type VkSurfaceKHR = Handle<::Surface>; + +pub struct Swapchain { + raw: ::Swapchain, + images: Vec, +} +pub type VkSwapchainKHR = Handle; + + /* automatically generated by rust-bindgen */ pub const VULKAN_H_: ::std::os::raw::c_uint = 1; @@ -462,12 +485,6 @@ pub type VkBool32 = u32; pub type VkDeviceSize = u64; pub type VkSampleMask = u32; -pub type VkInstance = Handle; -pub type VkPhysicalDevice = Handle>; -pub type VkDevice = Handle>; -pub type VkCommandPool = Handle<::CommandPool>; -pub type VkCommandBuffer = Handle<::CommandBuffer>; - #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct VkQueue_T { @@ -499,8 +516,6 @@ pub struct VkBuffer_T { } pub type VkBuffer = *mut VkBuffer_T; -pub type VkImage = Handle<::Image>; - #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct VkEvent_T { @@ -520,8 +535,6 @@ pub struct VkBufferView_T { } pub type VkBufferView = *mut VkBufferView_T; -pub type VkImageView = Handle<::ImageView>; - #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct VkShaderModule_T { @@ -3436,7 +3449,6 @@ pub struct VkDrawIndirectCommand { impl Clone for VkDrawIndirectCommand { fn clone(&self) -> Self { *self } } - pub type PFN_vkGetPhysicalDeviceFeatures = ::std::option::Option; - - -#[no_mangle] -pub extern fn vkCreateInstance( - _pCreateInfo: *const VkInstanceCreateInfo, - _pAllocator: *const VkAllocationCallbacks, - pInstance: *mut VkInstance, -) -> VkResult { - let instance = back::Instance::create("portability", 1); - unsafe { *pInstance = Handle::new(instance) }; - VkResult::VK_SUCCESS -} - -#[no_mangle] -pub extern fn vkDestroyInstance( - instance: VkInstance, - _pAllocator: *const VkAllocationCallbacks, -) { - instance.unwrap(); - //let it drop -} - -#[no_mangle] -pub extern fn vkEnumeratePhysicalDevices( - instance: VkInstance, - pPhysicalDeviceCount: *mut u32, - pPhysicalDevices: *mut VkPhysicalDevice, -) -> VkResult { - let adapters = instance.enumerate_adapters(); - let output = unsafe { slice::from_raw_parts_mut(pPhysicalDevices, *pPhysicalDeviceCount as _) }; - let count = cmp::min(adapters.len(), output.len()); - - for (out, adapter) in output.iter_mut().zip(adapters.into_iter()) { - *out = Handle::new(adapter); - } - - unsafe { *pPhysicalDeviceCount = count as _ }; - VkResult::VK_SUCCESS -} - -extern "C" { - pub fn vkGetPhysicalDeviceFeatures(physicalDevice: VkPhysicalDevice, - pFeatures: - *mut VkPhysicalDeviceFeatures); -} -extern "C" { - pub fn vkGetPhysicalDeviceFormatProperties(physicalDevice: - VkPhysicalDevice, - format: VkFormat, - pFormatProperties: - *mut VkFormatProperties); -} -extern "C" { - pub fn vkGetPhysicalDeviceImageFormatProperties(physicalDevice: - VkPhysicalDevice, - format: VkFormat, - type_: VkImageType, - tiling: VkImageTiling, - usage: VkImageUsageFlags, - flags: VkImageCreateFlags, - pImageFormatProperties: - *mut VkImageFormatProperties) - -> VkResult; -} -extern "C" { - pub fn vkGetPhysicalDeviceProperties(physicalDevice: VkPhysicalDevice, - pProperties: - *mut VkPhysicalDeviceProperties); -} - -#[no_mangle] -pub extern fn vkGetPhysicalDeviceQueueFamilyProperties( - adapter: VkPhysicalDevice, - pQueueFamilyPropertyCount: *mut u32, - pQueueFamilyProperties: *mut VkQueueFamilyProperties, -) { - let output = unsafe { - slice::from_raw_parts_mut(pQueueFamilyProperties, *pQueueFamilyPropertyCount as _) - }; - let families = &adapter.queue_families; - if output.len() > families.len() { - unsafe { *pQueueFamilyPropertyCount = families.len() as _ }; - } - for (ref mut out, ref family) in output.iter_mut().zip(families.iter()) { - **out = VkQueueFamilyProperties { - queueFlags: match family.queue_type() { - hal::QueueType::General => VkQueueFlagBits::VK_QUEUE_GRAPHICS_BIT as u32 | VkQueueFlagBits::VK_QUEUE_COMPUTE_BIT as u32, - hal::QueueType::Graphics => VkQueueFlagBits::VK_QUEUE_GRAPHICS_BIT as u32, - hal::QueueType::Compute => VkQueueFlagBits::VK_QUEUE_COMPUTE_BIT as u32, - hal::QueueType::Transfer => VkQueueFlagBits::VK_QUEUE_TRANSFER_BIT as u32, - }, - queueCount: family.max_queues() as _, - timestampValidBits: 0, //TODO - minImageTransferGranularity: VkExtent3D { width: 0, height: 0, depth: 0 }, //TODO - } - } -} - -extern "C" { - pub fn vkGetPhysicalDeviceMemoryProperties(physicalDevice: - VkPhysicalDevice, - pMemoryProperties: - *mut VkPhysicalDeviceMemoryProperties); -} -extern "C" { - pub fn vkGetInstanceProcAddr(instance: VkInstance, - pName: *const ::std::os::raw::c_char) - -> PFN_vkVoidFunction; -} -extern "C" { - pub fn vkGetDeviceProcAddr(device: VkDevice, - pName: *const ::std::os::raw::c_char) - -> PFN_vkVoidFunction; -} - -#[no_mangle] -pub extern fn vkCreateDevice( - adapter: VkPhysicalDevice, - pCreateInfo: *const VkDeviceCreateInfo, - _pAllocator: *const VkAllocationCallbacks, - pDevice: *mut VkDevice, -) -> VkResult { - let dev_info = unsafe { &*pCreateInfo }; - let queue_infos = unsafe { - slice::from_raw_parts(dev_info.pQueueCreateInfos, dev_info.queueCreateInfoCount as _) - }; - let request_infos = queue_infos.iter().map(|info| { - let family = adapter - .queue_families[info.queueFamilyIndex as usize] - .clone(); - (family, vec![1.0; info.queueCount as usize]) - }).collect::>(); - - let gpu = adapter.physical_device.clone().open(request_infos); - unsafe { *pDevice = Handle::new(gpu) }; - - VkResult::VK_SUCCESS -} - -#[no_mangle] -pub extern fn vkDestroyDevice( - device: VkDevice, - _pAllocator: *const VkAllocationCallbacks, -) { - let _ = device.unwrap(); //TODO? -} - -extern "C" { - pub fn vkEnumerateInstanceExtensionProperties(pLayerName: - *const ::std::os::raw::c_char, - pPropertyCount: *mut u32, - pProperties: - *mut VkExtensionProperties) - -> VkResult; -} -extern "C" { - pub fn vkEnumerateDeviceExtensionProperties(physicalDevice: - VkPhysicalDevice, - pLayerName: - *const ::std::os::raw::c_char, - pPropertyCount: *mut u32, - pProperties: - *mut VkExtensionProperties) - -> VkResult; -} -extern "C" { - pub fn vkEnumerateInstanceLayerProperties(pPropertyCount: *mut u32, - pProperties: - *mut VkLayerProperties) - -> VkResult; -} -extern "C" { - pub fn vkEnumerateDeviceLayerProperties(physicalDevice: VkPhysicalDevice, - pPropertyCount: *mut u32, - pProperties: - *mut VkLayerProperties) - -> VkResult; -} -extern "C" { - pub fn vkGetDeviceQueue(device: VkDevice, queueFamilyIndex: u32, - queueIndex: u32, pQueue: *mut VkQueue); -} -extern "C" { - pub fn vkQueueSubmit(queue: VkQueue, submitCount: u32, - pSubmits: *const VkSubmitInfo, fence: VkFence) - -> VkResult; -} -extern "C" { - pub fn vkQueueWaitIdle(queue: VkQueue) -> VkResult; -} -extern "C" { - pub fn vkDeviceWaitIdle(device: VkDevice) -> VkResult; -} -extern "C" { - pub fn vkAllocateMemory(device: VkDevice, - pAllocateInfo: *const VkMemoryAllocateInfo, - pAllocator: *const VkAllocationCallbacks, - pMemory: *mut VkDeviceMemory) -> VkResult; -} -extern "C" { - pub fn vkFreeMemory(device: VkDevice, memory: VkDeviceMemory, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkMapMemory(device: VkDevice, memory: VkDeviceMemory, - offset: VkDeviceSize, size: VkDeviceSize, - flags: VkMemoryMapFlags, - ppData: *mut *mut ::std::os::raw::c_void) -> VkResult; -} -extern "C" { - pub fn vkUnmapMemory(device: VkDevice, memory: VkDeviceMemory); -} -extern "C" { - pub fn vkFlushMappedMemoryRanges(device: VkDevice, memoryRangeCount: u32, - pMemoryRanges: - *const VkMappedMemoryRange) - -> VkResult; -} -extern "C" { - pub fn vkInvalidateMappedMemoryRanges(device: VkDevice, - memoryRangeCount: u32, - pMemoryRanges: - *const VkMappedMemoryRange) - -> VkResult; -} -extern "C" { - pub fn vkGetDeviceMemoryCommitment(device: VkDevice, - memory: VkDeviceMemory, - pCommittedMemoryInBytes: - *mut VkDeviceSize); -} -extern "C" { - pub fn vkBindBufferMemory(device: VkDevice, buffer: VkBuffer, - memory: VkDeviceMemory, - memoryOffset: VkDeviceSize) -> VkResult; -} -extern "C" { - pub fn vkBindImageMemory(device: VkDevice, image: VkImage, - memory: VkDeviceMemory, - memoryOffset: VkDeviceSize) -> VkResult; -} -extern "C" { - pub fn vkGetBufferMemoryRequirements(device: VkDevice, buffer: VkBuffer, - pMemoryRequirements: - *mut VkMemoryRequirements); -} -extern "C" { - pub fn vkGetImageMemoryRequirements(device: VkDevice, image: VkImage, - pMemoryRequirements: - *mut VkMemoryRequirements); -} -extern "C" { - pub fn vkGetImageSparseMemoryRequirements(device: VkDevice, - image: VkImage, - pSparseMemoryRequirementCount: - *mut u32, - pSparseMemoryRequirements: - *mut VkSparseImageMemoryRequirements); -} -extern "C" { - pub fn vkGetPhysicalDeviceSparseImageFormatProperties(physicalDevice: - VkPhysicalDevice, - format: VkFormat, - type_: VkImageType, - samples: - VkSampleCountFlagBits, - usage: - VkImageUsageFlags, - tiling: - VkImageTiling, - pPropertyCount: - *mut u32, - pProperties: - *mut VkSparseImageFormatProperties); -} -extern "C" { - pub fn vkQueueBindSparse(queue: VkQueue, bindInfoCount: u32, - pBindInfo: *const VkBindSparseInfo, - fence: VkFence) -> VkResult; -} -extern "C" { - pub fn vkCreateFence(device: VkDevice, - pCreateInfo: *const VkFenceCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pFence: *mut VkFence) -> VkResult; -} -extern "C" { - pub fn vkDestroyFence(device: VkDevice, fence: VkFence, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkResetFences(device: VkDevice, fenceCount: u32, - pFences: *const VkFence) -> VkResult; -} -extern "C" { - pub fn vkGetFenceStatus(device: VkDevice, fence: VkFence) -> VkResult; -} -extern "C" { - pub fn vkWaitForFences(device: VkDevice, fenceCount: u32, - pFences: *const VkFence, waitAll: VkBool32, - timeout: u64) -> VkResult; -} -extern "C" { - pub fn vkCreateSemaphore(device: VkDevice, - pCreateInfo: *const VkSemaphoreCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pSemaphore: *mut VkSemaphore) -> VkResult; -} -extern "C" { - pub fn vkDestroySemaphore(device: VkDevice, semaphore: VkSemaphore, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkCreateEvent(device: VkDevice, - pCreateInfo: *const VkEventCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pEvent: *mut VkEvent) -> VkResult; -} -extern "C" { - pub fn vkDestroyEvent(device: VkDevice, event: VkEvent, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkGetEventStatus(device: VkDevice, event: VkEvent) -> VkResult; -} -extern "C" { - pub fn vkSetEvent(device: VkDevice, event: VkEvent) -> VkResult; -} -extern "C" { - pub fn vkResetEvent(device: VkDevice, event: VkEvent) -> VkResult; -} -extern "C" { - pub fn vkCreateQueryPool(device: VkDevice, - pCreateInfo: *const VkQueryPoolCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pQueryPool: *mut VkQueryPool) -> VkResult; -} -extern "C" { - pub fn vkDestroyQueryPool(device: VkDevice, queryPool: VkQueryPool, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkGetQueryPoolResults(device: VkDevice, queryPool: VkQueryPool, - firstQuery: u32, queryCount: u32, - dataSize: usize, - pData: *mut ::std::os::raw::c_void, - stride: VkDeviceSize, - flags: VkQueryResultFlags) -> VkResult; -} -extern "C" { - pub fn vkCreateBuffer(device: VkDevice, - pCreateInfo: *const VkBufferCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pBuffer: *mut VkBuffer) -> VkResult; -} -extern "C" { - pub fn vkDestroyBuffer(device: VkDevice, buffer: VkBuffer, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkCreateBufferView(device: VkDevice, - pCreateInfo: *const VkBufferViewCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pView: *mut VkBufferView) -> VkResult; -} -extern "C" { - pub fn vkDestroyBufferView(device: VkDevice, bufferView: VkBufferView, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkCreateImage(device: VkDevice, - pCreateInfo: *const VkImageCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pImage: *mut VkImage) -> VkResult; -} -extern "C" { - pub fn vkDestroyImage(device: VkDevice, image: VkImage, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkGetImageSubresourceLayout(device: VkDevice, image: VkImage, - pSubresource: - *const VkImageSubresource, - pLayout: *mut VkSubresourceLayout); -} -#[no_mangle] -pub extern fn vkCreateImageView( - gpu: VkDevice, - pCreateInfo: *const VkImageViewCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pView: *mut VkImageView, -) -> VkResult { - let info = unsafe { &*pCreateInfo }; - assert!(info.subresourceRange.levelCount != VK_REMAINING_MIP_LEVELS as _); // TODO - assert!(info.subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS as _); // TODO - - let view = gpu - .device - .create_image_view( - &info.image, - conv::hal_from_format(info.format), - conv::map_swizzle(info.components), - conv::map_subresource_range(info.subresourceRange), - ); - - match view { - Ok(view) => { - unsafe { *pView = Handle::new(view) }; - VkResult::VK_SUCCESS - }, - Err(err) => { - panic!("Unexpected image view creation error: {:?}", err) - }, - } -} -#[no_mangle] -pub extern fn vkDestroyImageView( - gpu: VkDevice, - imageView: VkImageView, - pAllocator: *const VkAllocationCallbacks, -) { - gpu.device.destroy_image_view(*imageView.unwrap()) -} -extern "C" { - pub fn vkCreateShaderModule(device: VkDevice, - pCreateInfo: *const VkShaderModuleCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pShaderModule: *mut VkShaderModule) - -> VkResult; -} -extern "C" { - pub fn vkDestroyShaderModule(device: VkDevice, - shaderModule: VkShaderModule, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkCreatePipelineCache(device: VkDevice, - pCreateInfo: - *const VkPipelineCacheCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pPipelineCache: *mut VkPipelineCache) - -> VkResult; -} -extern "C" { - pub fn vkDestroyPipelineCache(device: VkDevice, - pipelineCache: VkPipelineCache, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkGetPipelineCacheData(device: VkDevice, - pipelineCache: VkPipelineCache, - pDataSize: *mut usize, - pData: *mut ::std::os::raw::c_void) - -> VkResult; -} -extern "C" { - pub fn vkMergePipelineCaches(device: VkDevice, dstCache: VkPipelineCache, - srcCacheCount: u32, - pSrcCaches: *const VkPipelineCache) - -> VkResult; -} -extern "C" { - pub fn vkCreateGraphicsPipelines(device: VkDevice, - pipelineCache: VkPipelineCache, - createInfoCount: u32, - pCreateInfos: - *const VkGraphicsPipelineCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pPipelines: *mut VkPipeline) -> VkResult; -} -extern "C" { - pub fn vkCreateComputePipelines(device: VkDevice, - pipelineCache: VkPipelineCache, - createInfoCount: u32, - pCreateInfos: - *const VkComputePipelineCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pPipelines: *mut VkPipeline) -> VkResult; -} -extern "C" { - pub fn vkDestroyPipeline(device: VkDevice, pipeline: VkPipeline, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkCreatePipelineLayout(device: VkDevice, - pCreateInfo: - *const VkPipelineLayoutCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pPipelineLayout: *mut VkPipelineLayout) - -> VkResult; -} -extern "C" { - pub fn vkDestroyPipelineLayout(device: VkDevice, - pipelineLayout: VkPipelineLayout, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkCreateSampler(device: VkDevice, - pCreateInfo: *const VkSamplerCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pSampler: *mut VkSampler) -> VkResult; -} -extern "C" { - pub fn vkDestroySampler(device: VkDevice, sampler: VkSampler, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkCreateDescriptorSetLayout(device: VkDevice, - pCreateInfo: - *const VkDescriptorSetLayoutCreateInfo, - pAllocator: - *const VkAllocationCallbacks, - pSetLayout: *mut VkDescriptorSetLayout) - -> VkResult; -} -extern "C" { - pub fn vkDestroyDescriptorSetLayout(device: VkDevice, - descriptorSetLayout: - VkDescriptorSetLayout, - pAllocator: - *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkCreateDescriptorPool(device: VkDevice, - pCreateInfo: - *const VkDescriptorPoolCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pDescriptorPool: *mut VkDescriptorPool) - -> VkResult; -} -extern "C" { - pub fn vkDestroyDescriptorPool(device: VkDevice, - descriptorPool: VkDescriptorPool, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkResetDescriptorPool(device: VkDevice, - descriptorPool: VkDescriptorPool, - flags: VkDescriptorPoolResetFlags) - -> VkResult; -} -extern "C" { - pub fn vkAllocateDescriptorSets(device: VkDevice, - pAllocateInfo: - *const VkDescriptorSetAllocateInfo, - pDescriptorSets: *mut VkDescriptorSet) - -> VkResult; -} -extern "C" { - pub fn vkFreeDescriptorSets(device: VkDevice, - descriptorPool: VkDescriptorPool, - descriptorSetCount: u32, - pDescriptorSets: *const VkDescriptorSet) - -> VkResult; -} -extern "C" { - pub fn vkUpdateDescriptorSets(device: VkDevice, descriptorWriteCount: u32, - pDescriptorWrites: - *const VkWriteDescriptorSet, - descriptorCopyCount: u32, - pDescriptorCopies: - *const VkCopyDescriptorSet); -} -extern "C" { - pub fn vkCreateFramebuffer(device: VkDevice, - pCreateInfo: *const VkFramebufferCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pFramebuffer: *mut VkFramebuffer) -> VkResult; -} -extern "C" { - pub fn vkDestroyFramebuffer(device: VkDevice, framebuffer: VkFramebuffer, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkCreateRenderPass(device: VkDevice, - pCreateInfo: *const VkRenderPassCreateInfo, - pAllocator: *const VkAllocationCallbacks, - pRenderPass: *mut VkRenderPass) -> VkResult; -} -extern "C" { - pub fn vkDestroyRenderPass(device: VkDevice, renderPass: VkRenderPass, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkGetRenderAreaGranularity(device: VkDevice, - renderPass: VkRenderPass, - pGranularity: *mut VkExtent2D); -} - -#[no_mangle] -pub extern fn vkCreateCommandPool( - gpu: VkDevice, - pCreateInfo: *const VkCommandPoolCreateInfo, - _pAllocator: *const VkAllocationCallbacks, - pCommandPool: *mut VkCommandPool, -) -> VkResult { - use hal::pool::CommandPoolCreateFlags; - - let info = unsafe { &*pCreateInfo }; - assert_eq!(info.queueFamilyIndex, 0); //TODO - let family = gpu.queue_groups[0].family(); - - let mut flags = CommandPoolCreateFlags::empty(); - if info.flags & VkCommandPoolCreateFlagBits::VK_COMMAND_POOL_CREATE_TRANSIENT_BIT as u32 != 0 { - flags |= CommandPoolCreateFlags::TRANSIENT; - } - if info.flags & VkCommandPoolCreateFlagBits::VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT as u32 != 0 { - flags |= CommandPoolCreateFlags::RESET_INDIVIDUAL; - } - - let pool = gpu.device.create_command_pool(family, flags); - unsafe { *pCommandPool = Handle::new(pool) }; - VkResult::VK_SUCCESS -} - -#[no_mangle] -pub extern fn vkDestroyCommandPool( - gpu: VkDevice, - commandPool: VkCommandPool, - _pAllocator: *const VkAllocationCallbacks, -) { - gpu.device.destroy_command_pool(*commandPool.unwrap()); -} - -#[no_mangle] -pub extern fn vkResetCommandPool( - _gpu: VkDevice, - mut commandPool: VkCommandPool, - _flags: VkCommandPoolResetFlags, -) -> VkResult { - commandPool.reset(); - VkResult::VK_SUCCESS -} - -#[no_mangle] -pub extern fn vkAllocateCommandBuffers( - _gpu: VkDevice, - pAllocateInfo: *const VkCommandBufferAllocateInfo, - pCommandBuffers: *mut VkCommandBuffer, -) -> VkResult { - let info = unsafe { &mut *(pAllocateInfo as *mut VkCommandBufferAllocateInfo) }; - assert_eq!(info.level, VkCommandBufferLevel::VK_COMMAND_BUFFER_LEVEL_PRIMARY); //TODO - let count = info.commandBufferCount as usize; - - let cmd_bufs = info.commandPool.allocate(count); - - let output = unsafe { - slice::from_raw_parts_mut(pCommandBuffers, count) - }; - for (out, cmd_buf) in output.iter_mut().zip(cmd_bufs) { - *out = Handle::new(cmd_buf); - } - - VkResult::VK_SUCCESS -} - -#[no_mangle] -pub extern fn vkFreeCommandBuffers( - _gpu: VkDevice, - mut commandPool: VkCommandPool, - commandBufferCount: u32, - pCommandBuffers: *const VkCommandBuffer, -) { - let buffer_slice = unsafe { - slice::from_raw_parts(pCommandBuffers, commandBufferCount as _) - }; - let buffers = buffer_slice - .iter() - .map(|buffer| *buffer.unwrap()) - .collect(); - - unsafe { commandPool.free(buffers) }; -} - -extern "C" { - pub fn vkBeginCommandBuffer(commandBuffer: VkCommandBuffer, - pBeginInfo: *const VkCommandBufferBeginInfo) - -> VkResult; -} -extern "C" { - pub fn vkEndCommandBuffer(commandBuffer: VkCommandBuffer) -> VkResult; -} -extern "C" { - pub fn vkResetCommandBuffer(commandBuffer: VkCommandBuffer, - flags: VkCommandBufferResetFlags) -> VkResult; -} -extern "C" { - pub fn vkCmdBindPipeline(commandBuffer: VkCommandBuffer, - pipelineBindPoint: VkPipelineBindPoint, - pipeline: VkPipeline); -} -extern "C" { - pub fn vkCmdSetViewport(commandBuffer: VkCommandBuffer, - firstViewport: u32, viewportCount: u32, - pViewports: *const VkViewport); -} -extern "C" { - pub fn vkCmdSetScissor(commandBuffer: VkCommandBuffer, firstScissor: u32, - scissorCount: u32, pScissors: *const VkRect2D); -} -extern "C" { - pub fn vkCmdSetLineWidth(commandBuffer: VkCommandBuffer, lineWidth: f32); -} -extern "C" { - pub fn vkCmdSetDepthBias(commandBuffer: VkCommandBuffer, - depthBiasConstantFactor: f32, - depthBiasClamp: f32, depthBiasSlopeFactor: f32); -} -extern "C" { - pub fn vkCmdSetBlendConstants(commandBuffer: VkCommandBuffer, - blendConstants: *const f32); -} -extern "C" { - pub fn vkCmdSetDepthBounds(commandBuffer: VkCommandBuffer, - minDepthBounds: f32, maxDepthBounds: f32); -} -extern "C" { - pub fn vkCmdSetStencilCompareMask(commandBuffer: VkCommandBuffer, - faceMask: VkStencilFaceFlags, - compareMask: u32); -} -extern "C" { - pub fn vkCmdSetStencilWriteMask(commandBuffer: VkCommandBuffer, - faceMask: VkStencilFaceFlags, - writeMask: u32); -} -extern "C" { - pub fn vkCmdSetStencilReference(commandBuffer: VkCommandBuffer, - faceMask: VkStencilFaceFlags, - reference: u32); -} -extern "C" { - pub fn vkCmdBindDescriptorSets(commandBuffer: VkCommandBuffer, - pipelineBindPoint: VkPipelineBindPoint, - layout: VkPipelineLayout, firstSet: u32, - descriptorSetCount: u32, - pDescriptorSets: *const VkDescriptorSet, - dynamicOffsetCount: u32, - pDynamicOffsets: *const u32); -} -extern "C" { - pub fn vkCmdBindIndexBuffer(commandBuffer: VkCommandBuffer, - buffer: VkBuffer, offset: VkDeviceSize, - indexType: VkIndexType); -} -extern "C" { - pub fn vkCmdBindVertexBuffers(commandBuffer: VkCommandBuffer, - firstBinding: u32, bindingCount: u32, - pBuffers: *const VkBuffer, - pOffsets: *const VkDeviceSize); -} -extern "C" { - pub fn vkCmdDraw(commandBuffer: VkCommandBuffer, vertexCount: u32, - instanceCount: u32, firstVertex: u32, - firstInstance: u32); -} -extern "C" { - pub fn vkCmdDrawIndexed(commandBuffer: VkCommandBuffer, indexCount: u32, - instanceCount: u32, firstIndex: u32, - vertexOffset: i32, firstInstance: u32); -} -extern "C" { - pub fn vkCmdDrawIndirect(commandBuffer: VkCommandBuffer, buffer: VkBuffer, - offset: VkDeviceSize, drawCount: u32, - stride: u32); -} -extern "C" { - pub fn vkCmdDrawIndexedIndirect(commandBuffer: VkCommandBuffer, - buffer: VkBuffer, offset: VkDeviceSize, - drawCount: u32, stride: u32); -} -extern "C" { - pub fn vkCmdDispatch(commandBuffer: VkCommandBuffer, groupCountX: u32, - groupCountY: u32, groupCountZ: u32); -} -extern "C" { - pub fn vkCmdDispatchIndirect(commandBuffer: VkCommandBuffer, - buffer: VkBuffer, offset: VkDeviceSize); -} -extern "C" { - pub fn vkCmdCopyBuffer(commandBuffer: VkCommandBuffer, - srcBuffer: VkBuffer, dstBuffer: VkBuffer, - regionCount: u32, pRegions: *const VkBufferCopy); -} -extern "C" { - pub fn vkCmdCopyImage(commandBuffer: VkCommandBuffer, srcImage: VkImage, - srcImageLayout: VkImageLayout, dstImage: VkImage, - dstImageLayout: VkImageLayout, regionCount: u32, - pRegions: *const VkImageCopy); -} -extern "C" { - pub fn vkCmdBlitImage(commandBuffer: VkCommandBuffer, srcImage: VkImage, - srcImageLayout: VkImageLayout, dstImage: VkImage, - dstImageLayout: VkImageLayout, regionCount: u32, - pRegions: *const VkImageBlit, filter: VkFilter); -} -extern "C" { - pub fn vkCmdCopyBufferToImage(commandBuffer: VkCommandBuffer, - srcBuffer: VkBuffer, dstImage: VkImage, - dstImageLayout: VkImageLayout, - regionCount: u32, - pRegions: *const VkBufferImageCopy); -} -extern "C" { - pub fn vkCmdCopyImageToBuffer(commandBuffer: VkCommandBuffer, - srcImage: VkImage, - srcImageLayout: VkImageLayout, - dstBuffer: VkBuffer, regionCount: u32, - pRegions: *const VkBufferImageCopy); -} -extern "C" { - pub fn vkCmdUpdateBuffer(commandBuffer: VkCommandBuffer, - dstBuffer: VkBuffer, dstOffset: VkDeviceSize, - dataSize: VkDeviceSize, - pData: *const ::std::os::raw::c_void); -} -extern "C" { - pub fn vkCmdFillBuffer(commandBuffer: VkCommandBuffer, - dstBuffer: VkBuffer, dstOffset: VkDeviceSize, - size: VkDeviceSize, data: u32); -} -extern "C" { - pub fn vkCmdClearColorImage(commandBuffer: VkCommandBuffer, - image: VkImage, imageLayout: VkImageLayout, - pColor: *const VkClearColorValue, - rangeCount: u32, - pRanges: *const VkImageSubresourceRange); -} -extern "C" { - pub fn vkCmdClearDepthStencilImage(commandBuffer: VkCommandBuffer, - image: VkImage, - imageLayout: VkImageLayout, - pDepthStencil: - *const VkClearDepthStencilValue, - rangeCount: u32, - pRanges: - *const VkImageSubresourceRange); -} -extern "C" { - pub fn vkCmdClearAttachments(commandBuffer: VkCommandBuffer, - attachmentCount: u32, - pAttachments: *const VkClearAttachment, - rectCount: u32, pRects: *const VkClearRect); -} -extern "C" { - pub fn vkCmdResolveImage(commandBuffer: VkCommandBuffer, - srcImage: VkImage, srcImageLayout: VkImageLayout, - dstImage: VkImage, dstImageLayout: VkImageLayout, - regionCount: u32, - pRegions: *const VkImageResolve); -} -extern "C" { - pub fn vkCmdSetEvent(commandBuffer: VkCommandBuffer, event: VkEvent, - stageMask: VkPipelineStageFlags); -} -extern "C" { - pub fn vkCmdResetEvent(commandBuffer: VkCommandBuffer, event: VkEvent, - stageMask: VkPipelineStageFlags); -} -extern "C" { - pub fn vkCmdWaitEvents(commandBuffer: VkCommandBuffer, eventCount: u32, - pEvents: *const VkEvent, - srcStageMask: VkPipelineStageFlags, - dstStageMask: VkPipelineStageFlags, - memoryBarrierCount: u32, - pMemoryBarriers: *const VkMemoryBarrier, - bufferMemoryBarrierCount: u32, - pBufferMemoryBarriers: - *const VkBufferMemoryBarrier, - imageMemoryBarrierCount: u32, - pImageMemoryBarriers: *const VkImageMemoryBarrier); -} -extern "C" { - pub fn vkCmdPipelineBarrier(commandBuffer: VkCommandBuffer, - srcStageMask: VkPipelineStageFlags, - dstStageMask: VkPipelineStageFlags, - dependencyFlags: VkDependencyFlags, - memoryBarrierCount: u32, - pMemoryBarriers: *const VkMemoryBarrier, - bufferMemoryBarrierCount: u32, - pBufferMemoryBarriers: - *const VkBufferMemoryBarrier, - imageMemoryBarrierCount: u32, - pImageMemoryBarriers: - *const VkImageMemoryBarrier); -} -extern "C" { - pub fn vkCmdBeginQuery(commandBuffer: VkCommandBuffer, - queryPool: VkQueryPool, query: u32, - flags: VkQueryControlFlags); -} -extern "C" { - pub fn vkCmdEndQuery(commandBuffer: VkCommandBuffer, - queryPool: VkQueryPool, query: u32); -} -extern "C" { - pub fn vkCmdResetQueryPool(commandBuffer: VkCommandBuffer, - queryPool: VkQueryPool, firstQuery: u32, - queryCount: u32); -} -extern "C" { - pub fn vkCmdWriteTimestamp(commandBuffer: VkCommandBuffer, - pipelineStage: VkPipelineStageFlagBits, - queryPool: VkQueryPool, query: u32); -} -extern "C" { - pub fn vkCmdCopyQueryPoolResults(commandBuffer: VkCommandBuffer, - queryPool: VkQueryPool, firstQuery: u32, - queryCount: u32, dstBuffer: VkBuffer, - dstOffset: VkDeviceSize, - stride: VkDeviceSize, - flags: VkQueryResultFlags); -} -extern "C" { - pub fn vkCmdPushConstants(commandBuffer: VkCommandBuffer, - layout: VkPipelineLayout, - stageFlags: VkShaderStageFlags, offset: u32, - size: u32, - pValues: *const ::std::os::raw::c_void); -} -extern "C" { - pub fn vkCmdBeginRenderPass(commandBuffer: VkCommandBuffer, - pRenderPassBegin: - *const VkRenderPassBeginInfo, - contents: VkSubpassContents); -} -extern "C" { - pub fn vkCmdNextSubpass(commandBuffer: VkCommandBuffer, - contents: VkSubpassContents); -} -extern "C" { - pub fn vkCmdEndRenderPass(commandBuffer: VkCommandBuffer); -} -extern "C" { - pub fn vkCmdExecuteCommands(commandBuffer: VkCommandBuffer, - commandBufferCount: u32, - pCommandBuffers: *const VkCommandBuffer); -} - -//NOTE: all *KHR types have to be pure `Handle` things for compatibility with -//`VK_DEFINE_NON_DISPATCHABLE_HANDLE` used in `vulkan.h` -pub type VkSurfaceKHR = Handle<::Surface>; - pub const VkColorSpaceKHR_VK_COLOR_SPACE_BEGIN_RANGE_KHR: VkColorSpaceKHR = VkColorSpaceKHR::VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; pub const VkColorSpaceKHR_VK_COLOR_SPACE_END_RANGE_KHR: VkColorSpaceKHR = @@ -5307,142 +4376,77 @@ impl Clone for VkSurfaceFormatKHR { fn clone(&self) -> Self { *self } } pub type PFN_vkDestroySurfaceKHR = - ::std::option::Option; + ::std::option::Option; pub type PFN_vkGetPhysicalDeviceSurfaceSupportKHR = - ::std::option::Option VkResult>; + ::std::option::Option VkResult>; pub type PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR = - ::std::option::Option VkResult>; + ::std::option::Option VkResult>; pub type PFN_vkGetPhysicalDeviceSurfaceFormatsKHR = - ::std::option::Option VkResult>; + ::std::option::Option VkResult>; pub type PFN_vkGetPhysicalDeviceSurfacePresentModesKHR = + ::std::option::Option VkResult>; +pub type PFN_vkGetPhysicalDeviceSurfaceCapabilities2EXT = ::std::option::Option VkResult>; +pub type PFN_vkDisplayPowerControlEXT = + ::std::option::Option VkResult>; +pub type PFN_vkRegisterDeviceEventEXT = + ::std::option::Option VkResult>; +pub type PFN_vkRegisterDisplayEventEXT = + ::std::option::Option VkResult>; +pub type PFN_vkGetSwapchainCounterEXT = + ::std::option::Option VkResult>; - -#[no_mangle] -pub extern fn vkDestroySurfaceKHR( - _instance: VkInstance, - surface: VkSurfaceKHR, - _: *const VkAllocationCallbacks, -) { - let _ = surface.unwrap(); //TODO -} - -#[no_mangle] -pub extern fn vkGetPhysicalDeviceSurfaceSupportKHR( - adapter: VkPhysicalDevice, - queueFamilyIndex: u32, - surface: VkSurfaceKHR, - pSupported: *mut VkBool32, -) -> VkResult { - let family = &adapter.queue_families[queueFamilyIndex as usize]; - let supports = surface.supports_queue_family(family); - unsafe { *pSupported = supports as _ }; - VkResult::VK_SUCCESS -} - -#[no_mangle] -pub extern fn vkGetPhysicalDeviceSurfaceCapabilitiesKHR( - adapter: VkPhysicalDevice, - surface: VkSurfaceKHR, - pSurfaceCapabilities: *mut VkSurfaceCapabilitiesKHR, -) -> VkResult { - let (caps, _) = surface.capabilities_and_formats(&adapter.physical_device); - - let output = VkSurfaceCapabilitiesKHR { - minImageCount: caps.image_count.start, - maxImageCount: caps.image_count.end, - currentExtent: match caps.current_extent { - Some(extent) => conv::extent2d_from_hal(extent), - None => VkExtent2D { - width: !0, - height: !0, - }, - }, - minImageExtent: conv::extent2d_from_hal(caps.extents.start), - maxImageExtent: conv::extent2d_from_hal(caps.extents.end), - maxImageArrayLayers: caps.max_image_layers, - supportedTransforms: VkSurfaceTransformFlagBitsKHR::VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR as _, - currentTransform: VkSurfaceTransformFlagBitsKHR::VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR, - supportedCompositeAlpha: VkCompositeAlphaFlagBitsKHR::VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR as _, - supportedUsageFlags: 0, - }; - - unsafe { *pSurfaceCapabilities = output }; - VkResult::VK_SUCCESS -} - -#[no_mangle] -pub extern fn vkGetPhysicalDeviceSurfaceFormatsKHR( - adapter: VkPhysicalDevice, - surface: VkSurfaceKHR, - pSurfaceFormatCount: *mut u32, - pSurfaceFormats: *mut VkSurfaceFormatKHR, -) -> VkResult { - let (_, formats) = surface.capabilities_and_formats(&adapter.physical_device); - let output = unsafe { slice::from_raw_parts_mut(pSurfaceFormats, *pSurfaceFormatCount as usize) }; - - if output.len() > formats.len() { - unsafe { *pSurfaceFormatCount = formats.len() as u32 }; - } - for (out, format) in output.iter_mut().zip(formats) { - *out = VkSurfaceFormatKHR { - format: conv::format_from_hal(format), - colorSpace: VkColorSpaceKHR::VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, //TODO - }; - } - - VkResult::VK_SUCCESS -} - -#[no_mangle] -pub extern fn vkGetPhysicalDeviceSurfacePresentModesKHR( - _adapter: VkPhysicalDevice, - _surface: VkSurfaceKHR, - pPresentModeCount: *mut u32, - pPresentModes: *mut VkPresentModeKHR, -) -> VkResult { - let modes = vec![VkPresentModeKHR::VK_PRESENT_MODE_FIFO_KHR]; //TODO - let output = unsafe { slice::from_raw_parts_mut(pPresentModes, *pPresentModeCount as usize) }; - - if output.len() > modes.len() { - unsafe { *pPresentModeCount = modes.len() as u32 }; - } - for (out, mode) in output.iter_mut().zip(modes) { - *out = mode; - } - - VkResult::VK_SUCCESS -} - -pub struct Swapchain { - raw: ::Swapchain, - images: Vec, -} -pub type VkSwapchainKHR = Handle; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum VkSwapchainCreateFlagBitsKHR { @@ -5523,8 +4527,7 @@ pub type PFN_vkQueuePresentKHR = pPresentInfo: *const VkPresentInfoKHR) -> VkResult>; -#[no_mangle] -pub extern fn vkCreateSwapchainKHR( +pub fn gfxCreateSwapchainKHR( gpu: VkDevice, pCreateInfo: *const VkSwapchainCreateInfoKHR, _pAllocator: *const VkAllocationCallbacks, @@ -5559,8 +4562,7 @@ pub extern fn vkCreateSwapchainKHR( unsafe { *pSwapchain = Handle::new(swapchain) }; VkResult::VK_SUCCESS } -#[no_mangle] -pub extern fn vkDestroySwapchainKHR( +pub fn gfxDestroySwapchainKHR( device: VkDevice, mut swapchain: VkSwapchainKHR, pAllocator: *const VkAllocationCallbacks, @@ -5570,8 +4572,7 @@ pub extern fn vkDestroySwapchainKHR( } let _ = swapchain.unwrap(); } -#[no_mangle] -pub extern fn vkGetSwapchainImagesKHR( +pub fn gfxGetSwapchainImagesKHR( device: VkDevice, swapchain: VkSwapchainKHR, pSwapchainImageCount: *mut u32, @@ -5882,8 +4883,7 @@ pub struct VkWin32SurfaceCreateInfoKHR { impl Clone for VkWin32SurfaceCreateInfoKHR { fn clone(&self) -> Self { *self } } -#[no_mangle] -pub extern fn vkCreateWin32SurfaceKHR( +pub fn gfxCreateWin32SurfaceKHR( instance: VkInstance, pCreateInfos: *const VkWin32SurfaceCreateInfoKHR, pAllocator: *const VkAllocationCallbacks, @@ -7696,70 +6696,6 @@ pub type PFN_vkGetPhysicalDeviceGeneratedCommandsPropertiesNVX = *mut VkDeviceGeneratedCommandsFeaturesNVX, pLimits: *mut VkDeviceGeneratedCommandsLimitsNVX)>; -extern "C" { - pub fn vkCmdProcessCommandsNVX(commandBuffer: VkCommandBuffer, - pProcessCommandsInfo: - *const VkCmdProcessCommandsInfoNVX); -} -extern "C" { - pub fn vkCmdReserveSpaceForCommandsNVX(commandBuffer: VkCommandBuffer, - pReserveSpaceInfo: - *const VkCmdReserveSpaceForCommandsInfoNVX); -} -extern "C" { - pub fn vkCreateIndirectCommandsLayoutNVX(device: VkDevice, - pCreateInfo: - *const VkIndirectCommandsLayoutCreateInfoNVX, - pAllocator: - *const VkAllocationCallbacks, - pIndirectCommandsLayout: - *mut VkIndirectCommandsLayoutNVX) - -> VkResult; -} -extern "C" { - pub fn vkDestroyIndirectCommandsLayoutNVX(device: VkDevice, - indirectCommandsLayout: - VkIndirectCommandsLayoutNVX, - pAllocator: - *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkCreateObjectTableNVX(device: VkDevice, - pCreateInfo: - *const VkObjectTableCreateInfoNVX, - pAllocator: *const VkAllocationCallbacks, - pObjectTable: *mut VkObjectTableNVX) - -> VkResult; -} -extern "C" { - pub fn vkDestroyObjectTableNVX(device: VkDevice, - objectTable: VkObjectTableNVX, - pAllocator: *const VkAllocationCallbacks); -} -extern "C" { - pub fn vkRegisterObjectsNVX(device: VkDevice, - objectTable: VkObjectTableNVX, - objectCount: u32, - ppObjectTableEntries: - *const *const VkObjectTableEntryNVX, - pObjectIndices: *const u32) -> VkResult; -} -extern "C" { - pub fn vkUnregisterObjectsNVX(device: VkDevice, - objectTable: VkObjectTableNVX, - objectCount: u32, - pObjectEntryTypes: - *const VkObjectEntryTypeNVX, - pObjectIndices: *const u32) -> VkResult; -} -extern "C" { - pub fn vkGetPhysicalDeviceGeneratedCommandsPropertiesNVX(physicalDevice: - VkPhysicalDevice, - pFeatures: - *mut VkDeviceGeneratedCommandsFeaturesNVX, - pLimits: - *mut VkDeviceGeneratedCommandsLimitsNVX); -} #[repr(C)] #[derive(Debug, Copy)] pub struct VkViewportWScalingNV { @@ -7787,21 +6723,12 @@ pub type PFN_vkCmdSetViewportWScalingNV = viewportCount: u32, pViewportWScalings: *const VkViewportWScalingNV)>; -extern "C" { - pub fn vkCmdSetViewportWScalingNV(commandBuffer: VkCommandBuffer, - firstViewport: u32, viewportCount: u32, - pViewportWScalings: - *const VkViewportWScalingNV); -} + pub type PFN_vkReleaseDisplayEXT = ::std::option::Option VkResult>; -extern "C" { - pub fn vkReleaseDisplayEXT(physicalDevice: VkPhysicalDevice, - display: VkDisplayKHR) -> VkResult; -} #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum VkSurfaceCounterFlagBitsEXT { @@ -7829,21 +6756,6 @@ pub struct VkSurfaceCapabilities2EXT { impl Clone for VkSurfaceCapabilities2EXT { fn clone(&self) -> Self { *self } } -pub type PFN_vkGetPhysicalDeviceSurfaceCapabilities2EXT = - ::std::option::Option VkResult>; -extern "C" { - pub fn vkGetPhysicalDeviceSurfaceCapabilities2EXT(physicalDevice: - VkPhysicalDevice, - surface: VkSurfaceKHR, - pSurfaceCapabilities: - *mut VkSurfaceCapabilities2EXT) - -> VkResult; -} pub const VkDisplayPowerStateEXT_VK_DISPLAY_POWER_STATE_BEGIN_RANGE_EXT: VkDisplayPowerStateEXT = VkDisplayPowerStateEXT::VK_DISPLAY_POWER_STATE_OFF_EXT; @@ -7925,62 +6837,7 @@ pub struct VkSwapchainCounterCreateInfoEXT { impl Clone for VkSwapchainCounterCreateInfoEXT { fn clone(&self) -> Self { *self } } -pub type PFN_vkDisplayPowerControlEXT = - ::std::option::Option VkResult>; -pub type PFN_vkRegisterDeviceEventEXT = - ::std::option::Option VkResult>; -pub type PFN_vkRegisterDisplayEventEXT = - ::std::option::Option VkResult>; -pub type PFN_vkGetSwapchainCounterEXT = - ::std::option::Option VkResult>; -extern "C" { - pub fn vkDisplayPowerControlEXT(device: VkDevice, display: VkDisplayKHR, - pDisplayPowerInfo: - *const VkDisplayPowerInfoEXT) - -> VkResult; -} -extern "C" { - pub fn vkRegisterDeviceEventEXT(device: VkDevice, - pDeviceEventInfo: - *const VkDeviceEventInfoEXT, - pAllocator: *const VkAllocationCallbacks, - pFence: *mut VkFence) -> VkResult; -} -extern "C" { - pub fn vkRegisterDisplayEventEXT(device: VkDevice, display: VkDisplayKHR, - pDisplayEventInfo: - *const VkDisplayEventInfoEXT, - pAllocator: *const VkAllocationCallbacks, - pFence: *mut VkFence) -> VkResult; -} -extern "C" { - pub fn vkGetSwapchainCounterEXT(device: VkDevice, - swapchain: VkSwapchainKHR, - counter: VkSurfaceCounterFlagBitsEXT, - pCounterValue: *mut u64) -> VkResult; -} + #[repr(C)] #[derive(Debug, Copy)] pub struct VkPhysicalDeviceMultiviewPerViewAttributesPropertiesNVX { @@ -8079,9 +6936,3 @@ pub type PFN_vkCmdSetDiscardRectangleEXT = discardRectangleCount: u32, pDiscardRectangles: *const VkRect2D)>; -extern "C" { - pub fn vkCmdSetDiscardRectangleEXT(commandBuffer: VkCommandBuffer, - firstDiscardRectangle: u32, - discardRectangleCount: u32, - pDiscardRectangles: *const VkRect2D); -} diff --git a/libportability-icd/Cargo.toml b/libportability-icd/Cargo.toml new file mode 100644 index 0000000..019d2ed --- /dev/null +++ b/libportability-icd/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "portability-icd" +version = "0.1.0" +authors = ["Dzmitry Malyshau "] + +[lib] +name = "portability_icd" +crate-type = ["dylib"] + +[dependencies] +portability-gfx = { path = "../libportability-gfx" } diff --git a/libportability-icd/src/lib.rs b/libportability-icd/src/lib.rs new file mode 100644 index 0000000..6b0881d --- /dev/null +++ b/libportability-icd/src/lib.rs @@ -0,0 +1,3 @@ +extern crate portability_gfx; + +use portability_gfx::*; diff --git a/libportability/Cargo.toml b/libportability/Cargo.toml new file mode 100644 index 0000000..622ae02 --- /dev/null +++ b/libportability/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "portability" +version = "0.1.0" +authors = ["Dzmitry Malyshau "] + +[lib] +name = "portability" +crate-type = ["staticlib"] + +[dependencies] +portability-gfx = { path = "../libportability-gfx" } diff --git a/libportability/src/lib.rs b/libportability/src/lib.rs new file mode 100644 index 0000000..f36b232 --- /dev/null +++ b/libportability/src/lib.rs @@ -0,0 +1,208 @@ +#![allow(non_snake_case)] + +extern crate portability_gfx; + +use portability_gfx::*; + +#[no_mangle] +pub extern fn vkCreateInstance( + pCreateInfo: *const VkInstanceCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pInstance: *mut VkInstance, +) -> VkResult { + gfxCreateInstance(pCreateInfo, pAllocator, pInstance) +} + +#[no_mangle] +pub extern fn vkDestroyInstance( + instance: VkInstance, + pAllocator: *const VkAllocationCallbacks, +) { + gfxDestroyInstance(instance, pAllocator) +} + +#[no_mangle] +pub extern fn vkEnumeratePhysicalDevices( + instance: VkInstance, + pPhysicalDeviceCount: *mut u32, + pPhysicalDevices: *mut VkPhysicalDevice, +) -> VkResult { + gfxEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices) +} + +#[no_mangle] +pub extern fn vkGetPhysicalDeviceQueueFamilyProperties( + adapter: VkPhysicalDevice, + pQueueFamilyPropertyCount: *mut u32, + pQueueFamilyProperties: *mut VkQueueFamilyProperties, +) { + gfxGetPhysicalDeviceQueueFamilyProperties(adapter, pQueueFamilyPropertyCount, pQueueFamilyProperties) +} + +#[no_mangle] +pub extern fn vkCreateDevice( + adapter: VkPhysicalDevice, + pCreateInfo: *const VkDeviceCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pDevice: *mut VkDevice, +) -> VkResult { + gfxCreateDevice(adapter, pCreateInfo, pAllocator, pDevice) +} + +#[no_mangle] +pub extern fn vkDestroyDevice( + device: VkDevice, + pAllocator: *const VkAllocationCallbacks, +) { + gfxDestroyDevice(device, pAllocator) +} + +#[no_mangle] +pub extern fn vkCreateImageView( + device: VkDevice, + pCreateInfo: *const VkImageViewCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pView: *mut VkImageView, +) -> VkResult { + gfxCreateImageView(device, pCreateInfo, pAllocator, pView) +} +#[no_mangle] +pub extern fn vkDestroyImageView( + device: VkDevice, + imageView: VkImageView, + pAllocator: *const VkAllocationCallbacks, +) { + gfxDestroyImageView(device, imageView, pAllocator) +} + +#[no_mangle] +pub extern fn vkCreateCommandPool( + device: VkDevice, + pCreateInfo: *const VkCommandPoolCreateInfo, + pAllocator: *const VkAllocationCallbacks, + pCommandPool: *mut VkCommandPool, +) -> VkResult { + gfxCreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool) +} + +#[no_mangle] +pub extern fn vkDestroyCommandPool( + device: VkDevice, + commandPool: VkCommandPool, + pAllocator: *const VkAllocationCallbacks, +) { + gfxDestroyCommandPool(device, commandPool, pAllocator) +} + +#[no_mangle] +pub extern fn vkResetCommandPool( + device: VkDevice, + commandPool: VkCommandPool, + flags: VkCommandPoolResetFlags, +) -> VkResult { + gfxResetCommandPool(device, commandPool, flags) +} + +#[no_mangle] +pub extern fn vkAllocateCommandBuffers( + device: VkDevice, + pAllocateInfo: *const VkCommandBufferAllocateInfo, + pCommandBuffers: *mut VkCommandBuffer, +) -> VkResult { + gfxAllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers) +} + +#[no_mangle] +pub extern fn vkFreeCommandBuffers( + device: VkDevice, + commandPool: VkCommandPool, + commandBufferCount: u32, + pCommandBuffers: *const VkCommandBuffer, +) { + gfxFreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers) +} + +#[no_mangle] +pub extern fn vkDestroySurfaceKHR( + instance: VkInstance, + surface: VkSurfaceKHR, + pAllocator: *const VkAllocationCallbacks, +) { + gfxDestroySurfaceKHR(instance, surface, pAllocator) +} + +#[no_mangle] +pub extern fn vkGetPhysicalDeviceSurfaceSupportKHR( + adapter: VkPhysicalDevice, + queueFamilyIndex: u32, + surface: VkSurfaceKHR, + pSupported: *mut VkBool32, +) -> VkResult { + gfxGetPhysicalDeviceSurfaceSupportKHR(adapter, queueFamilyIndex, surface, pSupported) +} + +#[no_mangle] +pub extern fn vkGetPhysicalDeviceSurfaceCapabilitiesKHR( + adapter: VkPhysicalDevice, + surface: VkSurfaceKHR, + pSurfaceCapabilities: *mut VkSurfaceCapabilitiesKHR, +) -> VkResult { + gfxGetPhysicalDeviceSurfaceCapabilitiesKHR(adapter, surface, pSurfaceCapabilities) +} + +#[no_mangle] +pub extern fn vkGetPhysicalDeviceSurfaceFormatsKHR( + adapter: VkPhysicalDevice, + surface: VkSurfaceKHR, + pSurfaceFormatCount: *mut u32, + pSurfaceFormats: *mut VkSurfaceFormatKHR, +) -> VkResult { + gfxGetPhysicalDeviceSurfaceFormatsKHR(adapter, surface, pSurfaceFormatCount, pSurfaceFormats) +} + +#[no_mangle] +pub extern fn vkGetPhysicalDeviceSurfacePresentModesKHR( + adapter: VkPhysicalDevice, + surface: VkSurfaceKHR, + pPresentModeCount: *mut u32, + pPresentModes: *mut VkPresentModeKHR, +) -> VkResult { + gfxGetPhysicalDeviceSurfacePresentModesKHR(adapter, surface, pPresentModeCount, pPresentModes) +} + +#[no_mangle] +pub extern fn vkCreateSwapchainKHR( + device: VkDevice, + pCreateInfo: *const VkSwapchainCreateInfoKHR, + pAllocator: *const VkAllocationCallbacks, + pSwapchain: *mut VkSwapchainKHR, +) -> VkResult { + gfxCreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain) +} +#[no_mangle] +pub extern fn vkDestroySwapchainKHR( + device: VkDevice, + swapchain: VkSwapchainKHR, + pAllocator: *const VkAllocationCallbacks, +) { + gfxDestroySwapchainKHR(device, swapchain, pAllocator) +} +#[no_mangle] +pub extern fn vkGetSwapchainImagesKHR( + device: VkDevice, + swapchain: VkSwapchainKHR, + pSwapchainImageCount: *mut u32, + pSwapchainImages: *mut VkImage, +) -> VkResult { + gfxGetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages) +} + +#[no_mangle] +pub extern fn vkCreateWin32SurfaceKHR( + instance: VkInstance, + pCreateInfos: *const VkWin32SurfaceCreateInfoKHR, + pAllocator: *const VkAllocationCallbacks, + pSurface: *mut VkSurfaceKHR, +) -> VkResult { + gfxCreateWin32SurfaceKHR(instance, pCreateInfos, pAllocator, pSurface) +}