mirror of
https://github.com/italicsjenga/portability.git
synced 2024-11-22 07:01:29 +11:00
Implement vkCreateBuffer and fix memory binding
This commit is contained in:
parent
728e338ffa
commit
7c19ad77ae
|
@ -1,5 +1,5 @@
|
|||
|
||||
use hal::{adapter, format, image, memory, window};
|
||||
use hal::{adapter, buffer, format, image, memory, window};
|
||||
|
||||
use std::mem;
|
||||
|
||||
|
@ -221,6 +221,40 @@ pub fn map_image_usage(usage: VkImageUsageFlags) -> image::Usage {
|
|||
flags
|
||||
}
|
||||
|
||||
pub fn map_buffer_usage(usage: VkBufferUsageFlags) -> buffer::Usage {
|
||||
let mut flags = buffer::Usage::empty();
|
||||
|
||||
if usage & VkBufferUsageFlagBits::VK_BUFFER_USAGE_TRANSFER_SRC_BIT as u32 != 0 {
|
||||
flags |= buffer::Usage::TRANSFER_SRC;
|
||||
}
|
||||
if usage & VkBufferUsageFlagBits::VK_BUFFER_USAGE_TRANSFER_DST_BIT as u32 != 0 {
|
||||
flags |= buffer::Usage::TRANSFER_DST;
|
||||
}
|
||||
if usage & VkBufferUsageFlagBits::VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT as u32 != 0 {
|
||||
flags |= buffer::Usage::UNIFORM_TEXEL;
|
||||
}
|
||||
if usage & VkBufferUsageFlagBits::VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT as u32 != 0 {
|
||||
flags |= buffer::Usage::STORAGE_TEXEL;
|
||||
}
|
||||
if usage & VkBufferUsageFlagBits::VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT as u32 != 0 {
|
||||
flags |= buffer::Usage::UNIFORM;
|
||||
}
|
||||
if usage & VkBufferUsageFlagBits::VK_BUFFER_USAGE_STORAGE_BUFFER_BIT as u32 != 0 {
|
||||
flags |= buffer::Usage::STORAGE;
|
||||
}
|
||||
if usage & VkBufferUsageFlagBits::VK_BUFFER_USAGE_INDEX_BUFFER_BIT as u32 != 0 {
|
||||
flags |= buffer::Usage::INDEX;
|
||||
}
|
||||
if usage & VkBufferUsageFlagBits::VK_BUFFER_USAGE_VERTEX_BUFFER_BIT as u32 != 0 {
|
||||
flags |= buffer::Usage::VERTEX;
|
||||
}
|
||||
if usage & VkBufferUsageFlagBits::VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT as u32 != 0 {
|
||||
flags |= buffer::Usage::INDIRECT;
|
||||
}
|
||||
|
||||
flags
|
||||
}
|
||||
|
||||
pub fn memory_properties_from_hal(properties: memory::Properties) -> VkMemoryPropertyFlags {
|
||||
let mut flags = 0;
|
||||
|
||||
|
|
|
@ -347,6 +347,7 @@ pub extern fn gfxBindBufferMemory(
|
|||
memory: VkDeviceMemory,
|
||||
memoryOffset: VkDeviceSize,
|
||||
) -> VkResult {
|
||||
let mut buffer_copy = buffer;
|
||||
let new_buffer = match *buffer.unwrap() {
|
||||
Buffer::Buffer(_) => panic!("An Buffer can only be bound once!"),
|
||||
Buffer::Unbound(unbound) => {
|
||||
|
@ -359,7 +360,7 @@ pub extern fn gfxBindBufferMemory(
|
|||
};
|
||||
|
||||
// Replace the unbound buffer with an actual buffer under the hood.
|
||||
*buffer = Buffer::Buffer(new_buffer);
|
||||
*buffer_copy = Buffer::Buffer(new_buffer);
|
||||
|
||||
VkResult::VK_SUCCESS
|
||||
}
|
||||
|
@ -370,6 +371,7 @@ pub extern fn gfxBindImageMemory(
|
|||
memory: VkDeviceMemory,
|
||||
memoryOffset: VkDeviceSize,
|
||||
) -> VkResult {
|
||||
let mut image_copy = image;
|
||||
let new_img = match *image.unwrap() {
|
||||
Image::Image(_) => panic!("An Image can only be bound once!"),
|
||||
Image::Unbound(unbound) => {
|
||||
|
@ -382,7 +384,7 @@ pub extern fn gfxBindImageMemory(
|
|||
};
|
||||
|
||||
// Replace the unbound image with an actual image under the hood.
|
||||
*image = Image::Image(new_img);
|
||||
*image_copy = Image::Image(new_img);
|
||||
|
||||
VkResult::VK_SUCCESS
|
||||
}
|
||||
|
@ -521,11 +523,24 @@ extern "C" {
|
|||
stride: VkDeviceSize,
|
||||
flags: VkQueryResultFlags) -> VkResult;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn vkCreateBuffer(device: VkDevice,
|
||||
pCreateInfo: *const VkBufferCreateInfo,
|
||||
pAllocator: *const VkAllocationCallbacks,
|
||||
pBuffer: *mut VkBuffer) -> VkResult;
|
||||
#[inline]
|
||||
pub extern fn gfxCreateBuffer(
|
||||
gpu: VkDevice,
|
||||
pCreateInfo: *const VkBufferCreateInfo,
|
||||
pAllocator: *const VkAllocationCallbacks,
|
||||
pBuffer: *mut VkBuffer,
|
||||
) -> VkResult {
|
||||
let info = unsafe { &*pCreateInfo };
|
||||
assert_eq!(info.sharingMode, VkSharingMode::VK_SHARING_MODE_EXCLUSIVE); // TODO
|
||||
assert_eq!(info.flags, 0); // TODO
|
||||
|
||||
let buffer = gpu.device.create_buffer(
|
||||
info.size,
|
||||
conv::map_buffer_usage(info.usage),
|
||||
).expect("Error on creating buffer");
|
||||
|
||||
unsafe { *pBuffer = Handle::new(Buffer::Unbound(buffer)); }
|
||||
VkResult::VK_SUCCESS
|
||||
}
|
||||
#[inline]
|
||||
pub extern fn gfxDestroyBuffer(
|
||||
|
|
|
@ -304,6 +304,16 @@ pub extern fn vkDestroyImage(
|
|||
gfxDestroyImage(device, image, pAllocator)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn vkCreateBuffer(
|
||||
device: VkDevice,
|
||||
pCreateInfo: *const VkBufferCreateInfo,
|
||||
pAllocator: *const VkAllocationCallbacks,
|
||||
pBuffer: *mut VkBuffer,
|
||||
) -> VkResult {
|
||||
gfxCreateBuffer(device, pCreateInfo, pAllocator, pBuffer)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn vkDestroyBuffer(
|
||||
device: VkDevice,
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
|
||||
#include "math.hpp"
|
||||
#include "window.hpp"
|
||||
|
|
Loading…
Reference in a new issue