Switch to libc

This commit is contained in:
Maik Klein 2017-07-08 09:40:38 +02:00
parent b100cc55a7
commit 5875de85ce
7 changed files with 31 additions and 28 deletions

View file

@ -12,6 +12,7 @@ documentation = "https://docs.rs/ash"
[dependencies]
shared_library = "0.1.5"
lazy_static = "0.2.1"
libc = "0.2.26"
[package.metadata.release]
no-dev-version = true

View file

@ -753,9 +753,9 @@ pub trait DeviceV1_0 {
offset: vk::DeviceSize,
size: vk::DeviceSize,
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(
self.handle(),
memory,

View file

@ -1,3 +1,4 @@
extern crate libc;
extern crate shared_library;
#[macro_use]
extern crate lazy_static;
@ -10,7 +11,7 @@ mod device;
mod entry;
pub mod prelude;
pub mod vk;
mod allocator;
//mod allocator;
pub mod extensions;
pub mod version;
pub mod util;

View file

@ -52,7 +52,7 @@ impl AlignByteSlice {
/// that is allocated on 4 bytes boundries, and insert the correct amount of paddings.
#[derive(Debug, Clone)]
pub struct Align<T> {
ptr: *mut (),
ptr: *mut vk::c_void,
elem_size: vk::DeviceSize,
size: vk::DeviceSize,
_m: PhantomData<T>,
@ -85,7 +85,11 @@ fn calc_padding(adr: vk::DeviceSize, align: vk::DeviceSize) -> vk::DeviceSize {
}
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 elem_size = size_of::<T>() as vk::DeviceSize + padding;
assert!(calc_padding(size, alignment) == 0, "size must be aligned");

View file

@ -199,23 +199,22 @@ macro_rules! vk_version_patch {
($minor: expr) => (($minor as uint32_t) & 0xfff)
}
mod libc_reexports {}
pub mod types {
#![allow(non_camel_case_types, dead_code)]
use std::ops::*;
use std::fmt;
use std::ffi::CStr;
use super::*;
#[allow(unused_imports)]
use super::libc_reexports::*;
pub type c_void = ();
pub type c_char = i8;
pub type uint32_t = u32;
pub type size_t = usize;
pub type uint64_t = u64;
pub type uint8_t = u8;
pub type c_float = f32;
pub type int32_t = i32;
use libc;
pub type c_void = libc::c_void;
pub type c_char = libc::c_char;
pub type uint32_t = libc::uint32_t;
pub type size_t = libc::size_t;
pub type uint64_t = libc::uint64_t;
pub type uint8_t = libc::uint8_t;
pub type c_float = libc::c_float;
pub type int32_t = libc::int32_t;
pub type Display = *const ();
pub type Window = *const ();
pub type VisualID = *const ();
@ -3913,8 +3912,6 @@ macro_rules! vk_functions {
pub mod cmds {
#![allow(dead_code)]
use super::*;
#[allow(unused_imports)]
use super::libc_reexports::*;
vk_functions!{
StaticFn,

View file

@ -147,7 +147,7 @@ fn main() {
let index_buffer_memory = base.device
.allocate_memory(&index_allocate_info, None)
.unwrap();
let index_ptr = base.device
let index_ptr: *mut vk::c_void = base.device
.map_memory(
index_buffer_memory,
0,
@ -330,12 +330,12 @@ fn main() {
vk::MemoryMapFlags::empty(),
)
.unwrap();
let mut image_slice = AlignByteSlice::new(
let mut image_slice = Align::new(
image_ptr,
image_buffer_memory_req.alignment,
std::mem::align_of::<u8>() as u64,
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
.bind_buffer_memory(image_buffer, image_buffer_memory, 0)

View file

@ -131,12 +131,12 @@ fn extension_names() -> Vec<*const i8> {
unsafe extern "system" fn vulkan_debug_callback(_: vk::DebugReportFlagsEXT,
_: vk::DebugReportObjectTypeEXT,
_: u64,
_: usize,
_: i32,
_: *const i8,
p_message: *const i8,
_: *mut ())
_: vk::uint64_t,
_: vk::size_t,
_: vk::int32_t,
_: *const vk::c_char,
p_message: *const vk::c_char,
_: *mut vk::c_void)
-> u32 {
println!("{:?}", CStr::from_ptr(p_message));
1