mirror of
https://github.com/italicsjenga/portability.git
synced 2024-11-22 15:01:31 +11:00
Update to latest gfx master
This commit is contained in:
parent
d93282925c
commit
d270a36ba3
|
@ -4,11 +4,21 @@ project (portability)
|
||||||
include_directories("modules/vulkan-docs/src")
|
include_directories("modules/vulkan-docs/src")
|
||||||
add_executable(native_test native/test.cpp native/window.cpp)
|
add_executable(native_test native/test.cpp native/window.cpp)
|
||||||
|
|
||||||
find_library(PORTABILITY_LIB portability "target/debug")
|
# That's quite a mess, cleanup if possible..
|
||||||
target_link_libraries(native_test ${PORTABILITY_LIB})
|
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
# TODO: can we use `find_library`? It seemed to search for `portability.lib` always..
|
||||||
|
target_link_libraries(native_test "../target/debug/portability.dll")
|
||||||
target_link_libraries(native_test Dwmapi Userenv ws2_32)
|
target_link_libraries(native_test Dwmapi Userenv ws2_32)
|
||||||
|
|
||||||
|
# Copy dll over to build directory
|
||||||
|
add_custom_command(TARGET native_test POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"${PROJECT_SOURCE_DIR}/target/debug/portability.dll"
|
||||||
|
$<TARGET_FILE_DIR:native_test>)
|
||||||
|
|
||||||
else (WIN32)
|
else (WIN32)
|
||||||
|
find_library(PORTABILITY_LIB portability "target/debug")
|
||||||
|
target_link_libraries(native_test ${PORTABILITY_LIB})
|
||||||
target_link_libraries(native_test pthread dl m X11 xcb)
|
target_link_libraries(native_test pthread dl m X11 xcb)
|
||||||
|
|
||||||
endif (WIN32)
|
endif (WIN32)
|
||||||
|
|
|
@ -1,42 +1,13 @@
|
||||||
|
|
||||||
|
use hal::{adapter, format, image, memory, window};
|
||||||
|
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use hal::{self, format, image, memory, window};
|
|
||||||
|
|
||||||
pub fn format_from_hal(format: format::Format) -> VkFormat {
|
pub fn format_from_hal(format: format::Format) -> VkFormat {
|
||||||
use VkFormat::*;
|
// HAL formats have the same numeric representation as Vulkan formats
|
||||||
use hal::format::ChannelType::*;
|
unsafe { mem::transmute(format) }
|
||||||
use hal::format::SurfaceType::*;
|
|
||||||
|
|
||||||
match format.0 {
|
|
||||||
R5_G6_B5 => match format.1 {
|
|
||||||
Unorm => VK_FORMAT_R5G6B5_UNORM_PACK16,
|
|
||||||
_ => unreachable!(),
|
|
||||||
},
|
|
||||||
R4_G4_B4_A4 => match format.1 {
|
|
||||||
Unorm => VK_FORMAT_R4G4B4A4_UNORM_PACK16,
|
|
||||||
_ => unreachable!(),
|
|
||||||
},
|
|
||||||
R8_G8_B8_A8 => match format.1 {
|
|
||||||
Unorm => VK_FORMAT_R8G8B8A8_UNORM,
|
|
||||||
Inorm => VK_FORMAT_R8G8B8A8_SNORM,
|
|
||||||
Srgb => VK_FORMAT_R8G8B8A8_SRGB,
|
|
||||||
_ => panic!("format {:?}", format),
|
|
||||||
},
|
|
||||||
B8_G8_R8_A8 => match format.1 {
|
|
||||||
Unorm => VK_FORMAT_B8G8R8A8_UNORM,
|
|
||||||
Inorm => VK_FORMAT_B8G8R8A8_SNORM,
|
|
||||||
Srgb => VK_FORMAT_B8G8R8A8_SRGB,
|
|
||||||
_ => panic!("format {:?}", format),
|
|
||||||
},
|
|
||||||
R16_G16_B16_A16 => match format.1 {
|
|
||||||
Unorm => VK_FORMAT_R16G16B16A16_UNORM,
|
|
||||||
Inorm => VK_FORMAT_R16G16B16A16_SNORM,
|
|
||||||
Float => VK_FORMAT_R16G16B16A16_SFLOAT,
|
|
||||||
_ => panic!("format {:?}", format),
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
panic!("format {:?}", format);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_properties_from_hal(properties: format::Properties) -> VkFormatProperties {
|
pub fn format_properties_from_hal(properties: format::Properties) -> VkFormatProperties {
|
||||||
|
@ -101,19 +72,12 @@ fn buffer_features_from_hal(features: format::BufferFeature) -> VkFormatFeatureF
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_format(format: VkFormat) -> format::Format {
|
pub fn map_format(format: VkFormat) -> format::Format {
|
||||||
use VkFormat::*;
|
if (format as usize) < format::NUM_FORMATS {
|
||||||
use hal::format::ChannelType::*;
|
// HAL formats have the same numeric representation as Vulkan formats
|
||||||
use hal::format::SurfaceType::*;
|
unsafe { mem::transmute(format) }
|
||||||
|
} else {
|
||||||
let (sf, cf) = match format {
|
unimplemented!("Unknown format {:?}", format);
|
||||||
VK_FORMAT_B8G8R8A8_UNORM => (B8_G8_R8_A8, Unorm),
|
}
|
||||||
VK_FORMAT_D16_UNORM => (D16, Unorm),
|
|
||||||
_ => {
|
|
||||||
panic!("format {:?}", format);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
format::Format(sf, cf)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extent2d_from_hal(extent: window::Extent2d) -> VkExtent2D {
|
pub fn extent2d_from_hal(extent: window::Extent2d) -> VkExtent2D {
|
||||||
|
@ -158,16 +122,16 @@ pub fn map_subresource_range(subresource: VkImageSubresourceRange) -> image::Sub
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_aspect(aspects: VkImageAspectFlags) -> image::AspectFlags {
|
fn map_aspect(aspects: VkImageAspectFlags) -> format::AspectFlags {
|
||||||
let mut flags = image::AspectFlags::empty();
|
let mut flags = format::AspectFlags::empty();
|
||||||
if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_COLOR_BIT as u32 != 0 {
|
if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_COLOR_BIT as u32 != 0 {
|
||||||
flags |= image::AspectFlags::COLOR;
|
flags |= format::AspectFlags::COLOR;
|
||||||
}
|
}
|
||||||
if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_DEPTH_BIT as u32 != 0 {
|
if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_DEPTH_BIT as u32 != 0 {
|
||||||
flags |= image::AspectFlags::DEPTH;
|
flags |= format::AspectFlags::DEPTH;
|
||||||
}
|
}
|
||||||
if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_STENCIL_BIT as u32 != 0 {
|
if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_STENCIL_BIT as u32 != 0 {
|
||||||
flags |= image::AspectFlags::DEPTH;
|
flags |= format::AspectFlags::DEPTH;
|
||||||
}
|
}
|
||||||
if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_METADATA_BIT as u32 != 0 {
|
if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_METADATA_BIT as u32 != 0 {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
|
@ -278,3 +242,17 @@ pub fn memory_properties_from_hal(properties: memory::Properties) -> VkMemoryPro
|
||||||
|
|
||||||
flags
|
flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn map_err_device_creation(err: adapter::DeviceCreationError) -> VkResult {
|
||||||
|
use hal::adapter::DeviceCreationError::*;
|
||||||
|
|
||||||
|
match err {
|
||||||
|
OutOfHostMemory => VkResult::VK_ERROR_OUT_OF_HOST_MEMORY,
|
||||||
|
OutOfDeviceMemory => VkResult::VK_ERROR_OUT_OF_DEVICE_MEMORY,
|
||||||
|
InitializationFailed => VkResult::VK_ERROR_INITIALIZATION_FAILED,
|
||||||
|
MissingExtension => VkResult::VK_ERROR_EXTENSION_NOT_PRESENT,
|
||||||
|
MissingFeature => VkResult::VK_ERROR_FEATURE_NOT_PRESENT,
|
||||||
|
TooManyObjects => VkResult::VK_ERROR_TOO_MANY_OBJECTS,
|
||||||
|
DeviceLost => VkResult::VK_ERROR_DEVICE_LOST,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
|
|
||||||
use super::*;
|
use hal::{Device, Instance, PhysicalDevice, QueueFamily, Surface};
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern fn gfxCreateInstance(
|
pub extern fn gfxCreateInstance(
|
||||||
_pCreateInfo: *const VkInstanceCreateInfo,
|
_pCreateInfo: *const VkInstanceCreateInfo,
|
||||||
|
@ -80,7 +83,12 @@ pub extern fn gfxGetPhysicalDeviceFormatProperties(
|
||||||
format: VkFormat,
|
format: VkFormat,
|
||||||
pFormatProperties: *mut VkFormatProperties,
|
pFormatProperties: *mut VkFormatProperties,
|
||||||
) {
|
) {
|
||||||
let properties = adapter.physical_device.format_properties(conv::map_format(format));
|
let format = match format {
|
||||||
|
VkFormat::VK_FORMAT_UNDEFINED => None,
|
||||||
|
format => Some(conv::map_format(format)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let properties = adapter.physical_device.format_properties(format);
|
||||||
unsafe { *pFormatProperties = conv::format_properties_from_hal(properties); }
|
unsafe { *pFormatProperties = conv::format_properties_from_hal(properties); }
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -157,9 +165,14 @@ pub extern fn gfxCreateDevice(
|
||||||
}).collect::<Vec<_>>();
|
}).collect::<Vec<_>>();
|
||||||
|
|
||||||
let gpu = adapter.physical_device.open(request_infos);
|
let gpu = adapter.physical_device.open(request_infos);
|
||||||
unsafe { *pDevice = Handle::new(gpu) };
|
|
||||||
|
|
||||||
VkResult::VK_SUCCESS
|
match gpu {
|
||||||
|
Ok(device) => {
|
||||||
|
unsafe { *pDevice = Handle::new(device); }
|
||||||
|
VkResult::VK_SUCCESS
|
||||||
|
}
|
||||||
|
Err(err) => conv::map_err_device_creation(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1132,17 +1145,31 @@ pub extern fn gfxGetPhysicalDeviceSurfaceFormatsKHR(
|
||||||
pSurfaceFormatCount: *mut u32,
|
pSurfaceFormatCount: *mut u32,
|
||||||
pSurfaceFormats: *mut VkSurfaceFormatKHR,
|
pSurfaceFormats: *mut VkSurfaceFormatKHR,
|
||||||
) -> VkResult {
|
) -> VkResult {
|
||||||
let (_, formats) = surface.capabilities_and_formats(&adapter.physical_device);
|
let formats = surface
|
||||||
let output = unsafe { slice::from_raw_parts_mut(pSurfaceFormats, *pSurfaceFormatCount as usize) };
|
.capabilities_and_formats(&adapter.physical_device)
|
||||||
|
.1
|
||||||
|
.map(|formats|
|
||||||
|
formats
|
||||||
|
.into_iter()
|
||||||
|
.map(conv::format_from_hal)
|
||||||
|
.collect()
|
||||||
|
)
|
||||||
|
.unwrap_or(vec![VkFormat::VK_FORMAT_UNDEFINED]);
|
||||||
|
|
||||||
if output.len() > formats.len() {
|
if pSurfaceFormats.is_null() {
|
||||||
|
// Return only the number of formats
|
||||||
unsafe { *pSurfaceFormatCount = formats.len() as u32 };
|
unsafe { *pSurfaceFormatCount = formats.len() as u32 };
|
||||||
}
|
} else {
|
||||||
for (out, format) in output.iter_mut().zip(formats) {
|
let output = unsafe { slice::from_raw_parts_mut(pSurfaceFormats, *pSurfaceFormatCount as usize) };
|
||||||
*out = VkSurfaceFormatKHR {
|
if output.len() > formats.len() {
|
||||||
format: conv::format_from_hal(format),
|
unsafe { *pSurfaceFormatCount = formats.len() as u32 };
|
||||||
colorSpace: VkColorSpaceKHR::VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, //TODO
|
}
|
||||||
};
|
for (out, format) in output.iter_mut().zip(formats) {
|
||||||
|
*out = VkSurfaceFormatKHR {
|
||||||
|
format,
|
||||||
|
colorSpace: VkColorSpaceKHR::VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, //TODO
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VkResult::VK_SUCCESS
|
VkResult::VK_SUCCESS
|
||||||
|
|
|
@ -17,7 +17,6 @@ mod handle;
|
||||||
mod impls;
|
mod impls;
|
||||||
|
|
||||||
use std::{cmp, slice};
|
use std::{cmp, slice};
|
||||||
use hal::{Device, Instance, PhysicalDevice, QueueFamily, Surface}; // traits only
|
|
||||||
use hal::pool::RawCommandPool;
|
use hal::pool::RawCommandPool;
|
||||||
use back::Backend as B;
|
use back::Backend as B;
|
||||||
use handle::Handle;
|
use handle::Handle;
|
||||||
|
|
|
@ -193,12 +193,12 @@ int main() {
|
||||||
|
|
||||||
uint32_t image_count = 0;
|
uint32_t image_count = 0;
|
||||||
res = vkGetSwapchainImagesKHR(device, swapchain, &image_count, NULL);
|
res = vkGetSwapchainImagesKHR(device, swapchain, &image_count, NULL);
|
||||||
printf("\tvkCreateSwapchainKHR (query): res=%d image_count=%d\n", res, image_count);
|
printf("\tvkGetSwapchainImagesKHR (query): res=%d image_count=%d\n", res, image_count);
|
||||||
assert(!res);
|
assert(!res);
|
||||||
|
|
||||||
std::vector<VkImage> swapchain_images(image_count);
|
std::vector<VkImage> swapchain_images(image_count);
|
||||||
res = vkGetSwapchainImagesKHR(device, swapchain, &image_count, &swapchain_images[0]);
|
res = vkGetSwapchainImagesKHR(device, swapchain, &image_count, &swapchain_images[0]);
|
||||||
printf("\tvkCreateSwapchainKHR: res=%d\n", res);
|
printf("\tvkGetSwapchainImagesKHR: res=%d\n", res);
|
||||||
assert(!res);
|
assert(!res);
|
||||||
|
|
||||||
std::vector<VkImageView> swapchain_views(image_count);
|
std::vector<VkImageView> swapchain_views(image_count);
|
||||||
|
|
Loading…
Reference in a new issue