mirror of
https://github.com/italicsjenga/portability.git
synced 2024-11-22 15:01:31 +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;
|
use std::mem;
|
||||||
|
|
||||||
|
@ -221,6 +221,40 @@ pub fn map_image_usage(usage: VkImageUsageFlags) -> image::Usage {
|
||||||
flags
|
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 {
|
pub fn memory_properties_from_hal(properties: memory::Properties) -> VkMemoryPropertyFlags {
|
||||||
let mut flags = 0;
|
let mut flags = 0;
|
||||||
|
|
||||||
|
|
|
@ -347,6 +347,7 @@ pub extern fn gfxBindBufferMemory(
|
||||||
memory: VkDeviceMemory,
|
memory: VkDeviceMemory,
|
||||||
memoryOffset: VkDeviceSize,
|
memoryOffset: VkDeviceSize,
|
||||||
) -> VkResult {
|
) -> VkResult {
|
||||||
|
let mut buffer_copy = buffer;
|
||||||
let new_buffer = match *buffer.unwrap() {
|
let new_buffer = match *buffer.unwrap() {
|
||||||
Buffer::Buffer(_) => panic!("An Buffer can only be bound once!"),
|
Buffer::Buffer(_) => panic!("An Buffer can only be bound once!"),
|
||||||
Buffer::Unbound(unbound) => {
|
Buffer::Unbound(unbound) => {
|
||||||
|
@ -359,7 +360,7 @@ pub extern fn gfxBindBufferMemory(
|
||||||
};
|
};
|
||||||
|
|
||||||
// Replace the unbound buffer with an actual buffer under the hood.
|
// 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
|
VkResult::VK_SUCCESS
|
||||||
}
|
}
|
||||||
|
@ -370,6 +371,7 @@ pub extern fn gfxBindImageMemory(
|
||||||
memory: VkDeviceMemory,
|
memory: VkDeviceMemory,
|
||||||
memoryOffset: VkDeviceSize,
|
memoryOffset: VkDeviceSize,
|
||||||
) -> VkResult {
|
) -> VkResult {
|
||||||
|
let mut image_copy = image;
|
||||||
let new_img = match *image.unwrap() {
|
let new_img = match *image.unwrap() {
|
||||||
Image::Image(_) => panic!("An Image can only be bound once!"),
|
Image::Image(_) => panic!("An Image can only be bound once!"),
|
||||||
Image::Unbound(unbound) => {
|
Image::Unbound(unbound) => {
|
||||||
|
@ -382,7 +384,7 @@ pub extern fn gfxBindImageMemory(
|
||||||
};
|
};
|
||||||
|
|
||||||
// Replace the unbound image with an actual image under the hood.
|
// 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
|
VkResult::VK_SUCCESS
|
||||||
}
|
}
|
||||||
|
@ -521,11 +523,24 @@ extern "C" {
|
||||||
stride: VkDeviceSize,
|
stride: VkDeviceSize,
|
||||||
flags: VkQueryResultFlags) -> VkResult;
|
flags: VkQueryResultFlags) -> VkResult;
|
||||||
}
|
}
|
||||||
extern "C" {
|
#[inline]
|
||||||
pub fn vkCreateBuffer(device: VkDevice,
|
pub extern fn gfxCreateBuffer(
|
||||||
pCreateInfo: *const VkBufferCreateInfo,
|
gpu: VkDevice,
|
||||||
pAllocator: *const VkAllocationCallbacks,
|
pCreateInfo: *const VkBufferCreateInfo,
|
||||||
pBuffer: *mut VkBuffer) -> VkResult;
|
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]
|
#[inline]
|
||||||
pub extern fn gfxDestroyBuffer(
|
pub extern fn gfxDestroyBuffer(
|
||||||
|
|
|
@ -304,6 +304,16 @@ pub extern fn vkDestroyImage(
|
||||||
gfxDestroyImage(device, image, pAllocator)
|
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]
|
#[no_mangle]
|
||||||
pub extern fn vkDestroyBuffer(
|
pub extern fn vkDestroyBuffer(
|
||||||
device: VkDevice,
|
device: VkDevice,
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "math.hpp"
|
#include "math.hpp"
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
|
|
Loading…
Reference in a new issue