Switch to libc
This commit is contained in:
parent
b100cc55a7
commit
5875de85ce
7 changed files with 31 additions and 28 deletions
|
@ -12,6 +12,7 @@ documentation = "https://docs.rs/ash"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
shared_library = "0.1.5"
|
shared_library = "0.1.5"
|
||||||
lazy_static = "0.2.1"
|
lazy_static = "0.2.1"
|
||||||
|
libc = "0.2.26"
|
||||||
|
|
||||||
[package.metadata.release]
|
[package.metadata.release]
|
||||||
no-dev-version = true
|
no-dev-version = true
|
||||||
|
|
|
@ -753,9 +753,9 @@ pub trait DeviceV1_0 {
|
||||||
offset: vk::DeviceSize,
|
offset: vk::DeviceSize,
|
||||||
size: vk::DeviceSize,
|
size: vk::DeviceSize,
|
||||||
flags: vk::MemoryMapFlags,
|
flags: vk::MemoryMapFlags,
|
||||||
) -> VkResult<*mut ()> {
|
) -> VkResult<*mut vk::c_void> {
|
||||||
|
|
||||||
let mut data: *mut () = mem::uninitialized();
|
let mut data: *mut vk::c_void = mem::uninitialized();
|
||||||
let err_code = self.fp_v1_0().map_memory(
|
let err_code = self.fp_v1_0().map_memory(
|
||||||
self.handle(),
|
self.handle(),
|
||||||
memory,
|
memory,
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
extern crate libc;
|
||||||
extern crate shared_library;
|
extern crate shared_library;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
@ -10,7 +11,7 @@ mod device;
|
||||||
mod entry;
|
mod entry;
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
pub mod vk;
|
pub mod vk;
|
||||||
mod allocator;
|
//mod allocator;
|
||||||
pub mod extensions;
|
pub mod extensions;
|
||||||
pub mod version;
|
pub mod version;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
|
@ -52,7 +52,7 @@ impl AlignByteSlice {
|
||||||
/// that is allocated on 4 bytes boundries, and insert the correct amount of paddings.
|
/// that is allocated on 4 bytes boundries, and insert the correct amount of paddings.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Align<T> {
|
pub struct Align<T> {
|
||||||
ptr: *mut (),
|
ptr: *mut vk::c_void,
|
||||||
elem_size: vk::DeviceSize,
|
elem_size: vk::DeviceSize,
|
||||||
size: vk::DeviceSize,
|
size: vk::DeviceSize,
|
||||||
_m: PhantomData<T>,
|
_m: PhantomData<T>,
|
||||||
|
@ -85,7 +85,11 @@ fn calc_padding(adr: vk::DeviceSize, align: vk::DeviceSize) -> vk::DeviceSize {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Align<T> {
|
impl<T> Align<T> {
|
||||||
pub unsafe fn new(ptr: *mut (), alignment: vk::DeviceSize, size: vk::DeviceSize) -> Self {
|
pub unsafe fn new(
|
||||||
|
ptr: *mut vk::c_void,
|
||||||
|
alignment: vk::DeviceSize,
|
||||||
|
size: vk::DeviceSize,
|
||||||
|
) -> Self {
|
||||||
let padding = calc_padding(size_of::<T>() as vk::DeviceSize, alignment);
|
let padding = calc_padding(size_of::<T>() as vk::DeviceSize, alignment);
|
||||||
let elem_size = size_of::<T>() as vk::DeviceSize + padding;
|
let elem_size = size_of::<T>() as vk::DeviceSize + padding;
|
||||||
assert!(calc_padding(size, alignment) == 0, "size must be aligned");
|
assert!(calc_padding(size, alignment) == 0, "size must be aligned");
|
||||||
|
|
|
@ -199,23 +199,22 @@ macro_rules! vk_version_patch {
|
||||||
($minor: expr) => (($minor as uint32_t) & 0xfff)
|
($minor: expr) => (($minor as uint32_t) & 0xfff)
|
||||||
}
|
}
|
||||||
|
|
||||||
mod libc_reexports {}
|
|
||||||
pub mod types {
|
pub mod types {
|
||||||
#![allow(non_camel_case_types, dead_code)]
|
#![allow(non_camel_case_types, dead_code)]
|
||||||
use std::ops::*;
|
use std::ops::*;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use super::*;
|
use super::*;
|
||||||
#[allow(unused_imports)]
|
use libc;
|
||||||
use super::libc_reexports::*;
|
|
||||||
pub type c_void = ();
|
pub type c_void = libc::c_void;
|
||||||
pub type c_char = i8;
|
pub type c_char = libc::c_char;
|
||||||
pub type uint32_t = u32;
|
pub type uint32_t = libc::uint32_t;
|
||||||
pub type size_t = usize;
|
pub type size_t = libc::size_t;
|
||||||
pub type uint64_t = u64;
|
pub type uint64_t = libc::uint64_t;
|
||||||
pub type uint8_t = u8;
|
pub type uint8_t = libc::uint8_t;
|
||||||
pub type c_float = f32;
|
pub type c_float = libc::c_float;
|
||||||
pub type int32_t = i32;
|
pub type int32_t = libc::int32_t;
|
||||||
pub type Display = *const ();
|
pub type Display = *const ();
|
||||||
pub type Window = *const ();
|
pub type Window = *const ();
|
||||||
pub type VisualID = *const ();
|
pub type VisualID = *const ();
|
||||||
|
@ -3913,8 +3912,6 @@ macro_rules! vk_functions {
|
||||||
pub mod cmds {
|
pub mod cmds {
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
use super::*;
|
use super::*;
|
||||||
#[allow(unused_imports)]
|
|
||||||
use super::libc_reexports::*;
|
|
||||||
|
|
||||||
vk_functions!{
|
vk_functions!{
|
||||||
StaticFn,
|
StaticFn,
|
||||||
|
|
|
@ -147,7 +147,7 @@ fn main() {
|
||||||
let index_buffer_memory = base.device
|
let index_buffer_memory = base.device
|
||||||
.allocate_memory(&index_allocate_info, None)
|
.allocate_memory(&index_allocate_info, None)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let index_ptr = base.device
|
let index_ptr: *mut vk::c_void = base.device
|
||||||
.map_memory(
|
.map_memory(
|
||||||
index_buffer_memory,
|
index_buffer_memory,
|
||||||
0,
|
0,
|
||||||
|
@ -330,12 +330,12 @@ fn main() {
|
||||||
vk::MemoryMapFlags::empty(),
|
vk::MemoryMapFlags::empty(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut image_slice = AlignByteSlice::new(
|
let mut image_slice = Align::new(
|
||||||
image_ptr,
|
image_ptr,
|
||||||
image_buffer_memory_req.alignment,
|
std::mem::align_of::<u8>() as u64,
|
||||||
image_buffer_memory_req.size,
|
image_buffer_memory_req.size,
|
||||||
);
|
);
|
||||||
image_slice.copy_from_slices(&[&image_data]);
|
image_slice.copy_from_slice(&image_data);
|
||||||
base.device.unmap_memory(image_buffer_memory);
|
base.device.unmap_memory(image_buffer_memory);
|
||||||
base.device
|
base.device
|
||||||
.bind_buffer_memory(image_buffer, image_buffer_memory, 0)
|
.bind_buffer_memory(image_buffer, image_buffer_memory, 0)
|
||||||
|
|
|
@ -131,12 +131,12 @@ fn extension_names() -> Vec<*const i8> {
|
||||||
|
|
||||||
unsafe extern "system" fn vulkan_debug_callback(_: vk::DebugReportFlagsEXT,
|
unsafe extern "system" fn vulkan_debug_callback(_: vk::DebugReportFlagsEXT,
|
||||||
_: vk::DebugReportObjectTypeEXT,
|
_: vk::DebugReportObjectTypeEXT,
|
||||||
_: u64,
|
_: vk::uint64_t,
|
||||||
_: usize,
|
_: vk::size_t,
|
||||||
_: i32,
|
_: vk::int32_t,
|
||||||
_: *const i8,
|
_: *const vk::c_char,
|
||||||
p_message: *const i8,
|
p_message: *const vk::c_char,
|
||||||
_: *mut ())
|
_: *mut vk::c_void)
|
||||||
-> u32 {
|
-> u32 {
|
||||||
println!("{:?}", CStr::from_ptr(p_message));
|
println!("{:?}", CStr::from_ptr(p_message));
|
||||||
1
|
1
|
||||||
|
|
Loading…
Add table
Reference in a new issue