deps from crates.io

This commit is contained in:
Alex Janka 2023-10-20 11:00:48 +11:00
parent 6d55421ea7
commit 5e15714976
7 changed files with 455 additions and 431 deletions

576
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,22 +1,6 @@
[workspace] [workspace]
members = [ members = ["libportability", "libportability-gfx", "libportability-icd"]
"libportability",
"libportability-gfx",
"libportability-icd",
]
[profile.release] [profile.release]
debug = true debug = true
panic = "abort" panic = "abort"
[patch."https://github.com/gfx-rs/gfx"]
#gfx-hal = { path = "../gfx/src/hal" }
#gfx-backend-empty = { path = "../gfx/src/backend/empty" }
#gfx-backend-vulkan = { path = "../gfx/src/backend/vulkan" }
#gfx-backend-gl = { path = "../gfx/src/backend/gl" }
#gfx-backend-dx12 = { path = "../gfx/src/backend/dx12" }
#gfx-backend-dx11 = { path = "../gfx/src/backend/dx11" }
#gfx-backend-metal = { path = "../gfx/src/backend/metal" }
[patch.crates-io]
#naga = { path = "../naga" }

View file

@ -25,37 +25,24 @@ lazy_static = { version = "1", optional = true }
log = { version = "0.4", features = ["release_max_level_error"] } log = { version = "0.4", features = ["release_max_level_error"] }
renderdoc = { version = "0.5", optional = true } renderdoc = { version = "0.5", optional = true }
raw-window-handle = "0.3" raw-window-handle = "0.3"
gfx-hal = "0.9"
gfx-backend-empty = "0.9.0"
[dependencies.profiling] [dependencies.profiling]
version = "1.0.1" version = "1.0.1"
default-features = false default-features = false
#features = ["profile-with-tracy"] #features = ["profile-with-tracy"]
[dependencies.hal]
package = "gfx-hal"
git = "https://github.com/gfx-rs/gfx"
[dependencies.gfx-backend-empty] [target.'cfg(not(any(target_os = "macos", target_os = "ios")))'.dependencies]
git = "https://github.com/gfx-rs/gfx" gfx-backend-vulkan = { version = "0.9", optional = true }
[target.'cfg(not(any(target_os = "macos", target_os = "ios")))'.dependencies.gfx-backend-vulkan] [target.'cfg(windows)'.dependencies]
git = "https://github.com/gfx-rs/gfx" gfx-backend-dx12 = { version = "0.9", optional = true }
optional = true gfx-backend-dx11 = { version = "0.9", optional = true }
[target.'cfg(windows)'.dependencies.gfx-backend-dx12] [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
git = "https://github.com/gfx-rs/gfx" gfx-backend-metal = { version = "0.9", optional = true }
optional = true
[target.'cfg(windows)'.dependencies.gfx-backend-dx11] [target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "ios")))'.dependencies]
git = "https://github.com/gfx-rs/gfx" gfx-backend-gl = { version = "0.9", optional = true }
optional = true
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.gfx-backend-metal]
git = "https://github.com/gfx-rs/gfx"
#features = ["cross"]
optional = true
[target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "ios")))'.dependencies.gfx-backend-gl]
git = "https://github.com/gfx-rs/gfx"
#features = ["cross"]
optional = true

View file

@ -1,4 +1,4 @@
use hal::{ use gfx_hal::{
buffer, command, device, format, image, memory, pass, pso, pso::PatchSize, pso::Primitive, buffer, command, device, format, image, memory, pass, pso, pso::PatchSize, pso::Primitive,
query, window, Features, IndexType, Limits, query, window, Features, IndexType, Limits,
}; };
@ -394,7 +394,7 @@ pub fn map_view_kind(ty: VkImageViewType) -> image::ViewKind {
} }
pub fn map_image_layout(layout: VkImageLayout) -> image::Layout { pub fn map_image_layout(layout: VkImageLayout) -> image::Layout {
use hal::image::Layout::*; use gfx_hal::image::Layout::*;
match layout { match layout {
VkImageLayout::VK_IMAGE_LAYOUT_UNDEFINED => Undefined, VkImageLayout::VK_IMAGE_LAYOUT_UNDEFINED => Undefined,
VkImageLayout::VK_IMAGE_LAYOUT_GENERAL => General, VkImageLayout::VK_IMAGE_LAYOUT_GENERAL => General,
@ -680,7 +680,7 @@ pub fn map_dependency_flags(dependencies: VkDependencyFlags) -> memory::Dependen
} }
pub fn map_err_device_creation(err: device::CreationError) -> VkResult { pub fn map_err_device_creation(err: device::CreationError) -> VkResult {
use hal::device::OutOfMemory::{Device, Host}; use gfx_hal::device::OutOfMemory::{Device, Host};
match err { match err {
device::CreationError::OutOfMemory(Host) => VkResult::VK_ERROR_OUT_OF_HOST_MEMORY, device::CreationError::OutOfMemory(Host) => VkResult::VK_ERROR_OUT_OF_HOST_MEMORY,
device::CreationError::OutOfMemory(Device) => VkResult::VK_ERROR_OUT_OF_DEVICE_MEMORY, device::CreationError::OutOfMemory(Device) => VkResult::VK_ERROR_OUT_OF_DEVICE_MEMORY,
@ -997,8 +997,8 @@ pub fn map_pipeline_statistics(flags: VkQueryPipelineStatisticFlags) -> query::P
} }
#[inline] #[inline]
pub fn map_subresource(subresource: VkImageSubresource) -> hal::image::Subresource { pub fn map_subresource(subresource: VkImageSubresource) -> gfx_hal::image::Subresource {
hal::image::Subresource { gfx_hal::image::Subresource {
aspects: map_aspect(subresource.aspectMask), aspects: map_aspect(subresource.aspectMask),
level: subresource.mipLevel as _, level: subresource.mipLevel as _,
layer: subresource.arrayLayer as _, layer: subresource.arrayLayer as _,
@ -1008,8 +1008,8 @@ pub fn map_subresource(subresource: VkImageSubresource) -> hal::image::Subresour
#[inline] #[inline]
pub fn map_subresource_layers( pub fn map_subresource_layers(
subresource: VkImageSubresourceLayers, subresource: VkImageSubresourceLayers,
) -> hal::image::SubresourceLayers { ) -> gfx_hal::image::SubresourceLayers {
hal::image::SubresourceLayers { gfx_hal::image::SubresourceLayers {
aspects: map_aspect(subresource.aspectMask), aspects: map_aspect(subresource.aspectMask),
level: subresource.mipLevel as _, level: subresource.mipLevel as _,
layers: subresource.baseArrayLayer as _ layers: subresource.baseArrayLayer as _
@ -1018,8 +1018,10 @@ pub fn map_subresource_layers(
} }
#[inline] #[inline]
pub fn map_subresource_range(subresource: VkImageSubresourceRange) -> hal::image::SubresourceRange { pub fn map_subresource_range(
hal::image::SubresourceRange { subresource: VkImageSubresourceRange,
) -> gfx_hal::image::SubresourceRange {
gfx_hal::image::SubresourceRange {
aspects: map_aspect(subresource.aspectMask), aspects: map_aspect(subresource.aspectMask),
level_start: subresource.baseMipLevel as _, level_start: subresource.baseMipLevel as _,
level_count: if subresource.levelCount == VK_REMAINING_MIP_LEVELS as _ { level_count: if subresource.levelCount == VK_REMAINING_MIP_LEVELS as _ {

View file

@ -1,7 +1,11 @@
use crate::VK_NULL_HANDLE; use crate::VK_NULL_HANDLE;
#[cfg(feature = "nightly")]
use std::{collections::HashMap, hash::BuildHasherDefault, sync::{Arc, Mutex}};
use std::{borrow, fmt, ops}; use std::{borrow, fmt, ops};
#[cfg(feature = "nightly")]
use std::{
collections::HashMap,
hash::BuildHasherDefault,
sync::{Arc, Mutex},
};
use copyless::{BoxAllocation, BoxHelper}; use copyless::{BoxAllocation, BoxHelper};
@ -94,7 +98,7 @@ impl<T> Handle<T> {
impl<T> Clone for Handle<T> { impl<T> Clone for Handle<T> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Handle(self.0) *self
} }
} }
@ -192,7 +196,7 @@ mod dispatch {
impl<T> Clone for DispatchHandle<T> { impl<T> Clone for DispatchHandle<T> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
DispatchHandle(self.0) *self
} }
} }

View file

@ -1,6 +1,6 @@
use super::*; use super::*;
use hal::{ use gfx_hal::{
adapter::PhysicalDevice, adapter::PhysicalDevice,
command::CommandBuffer, command::CommandBuffer,
device::{Device, WaitFor}, device::{Device, WaitFor},
@ -40,17 +40,17 @@ unsafe fn make_slice_mut<'a, T: 'a>(pointer: *mut T, count: usize) -> &'a mut [T
} }
} }
fn map_oom(oom: hal::device::OutOfMemory) -> VkResult { fn map_oom(oom: gfx_hal::device::OutOfMemory) -> VkResult {
match oom { match oom {
hal::device::OutOfMemory::Host => VkResult::VK_ERROR_OUT_OF_HOST_MEMORY, gfx_hal::device::OutOfMemory::Host => VkResult::VK_ERROR_OUT_OF_HOST_MEMORY,
hal::device::OutOfMemory::Device => VkResult::VK_ERROR_OUT_OF_DEVICE_MEMORY, gfx_hal::device::OutOfMemory::Device => VkResult::VK_ERROR_OUT_OF_DEVICE_MEMORY,
} }
} }
fn map_alloc_error(alloc_error: hal::device::AllocationError) -> VkResult { fn map_alloc_error(alloc_error: gfx_hal::device::AllocationError) -> VkResult {
match alloc_error { match alloc_error {
hal::device::AllocationError::OutOfMemory(oom) => map_oom(oom), gfx_hal::device::AllocationError::OutOfMemory(oom) => map_oom(oom),
hal::device::AllocationError::TooManyObjects => VkResult::VK_ERROR_TOO_MANY_OBJECTS, gfx_hal::device::AllocationError::TooManyObjects => VkResult::VK_ERROR_TOO_MANY_OBJECTS,
} }
} }
@ -219,20 +219,22 @@ pub unsafe extern "C" fn gfxGetPhysicalDeviceQueueFamilyProperties(
for (ref mut out, ref family) in output.iter_mut().zip(families.iter()) { for (ref mut out, ref family) in output.iter_mut().zip(families.iter()) {
**out = VkQueueFamilyProperties { **out = VkQueueFamilyProperties {
queueFlags: match family.queue_type() { queueFlags: match family.queue_type() {
hal::queue::QueueType::General => { gfx_hal::queue::QueueType::General => {
VkQueueFlagBits::VK_QUEUE_GRAPHICS_BIT as u32 VkQueueFlagBits::VK_QUEUE_GRAPHICS_BIT as u32
| VkQueueFlagBits::VK_QUEUE_COMPUTE_BIT as u32 | VkQueueFlagBits::VK_QUEUE_COMPUTE_BIT as u32
| VkQueueFlagBits::VK_QUEUE_TRANSFER_BIT as u32 | VkQueueFlagBits::VK_QUEUE_TRANSFER_BIT as u32
} }
hal::queue::QueueType::Graphics => { gfx_hal::queue::QueueType::Graphics => {
VkQueueFlagBits::VK_QUEUE_GRAPHICS_BIT as u32 VkQueueFlagBits::VK_QUEUE_GRAPHICS_BIT as u32
| VkQueueFlagBits::VK_QUEUE_TRANSFER_BIT as u32 | VkQueueFlagBits::VK_QUEUE_TRANSFER_BIT as u32
} }
hal::queue::QueueType::Compute => { gfx_hal::queue::QueueType::Compute => {
VkQueueFlagBits::VK_QUEUE_COMPUTE_BIT as u32 VkQueueFlagBits::VK_QUEUE_COMPUTE_BIT as u32
| VkQueueFlagBits::VK_QUEUE_TRANSFER_BIT as u32 | VkQueueFlagBits::VK_QUEUE_TRANSFER_BIT as u32
} }
hal::queue::QueueType::Transfer => VkQueueFlagBits::VK_QUEUE_TRANSFER_BIT as u32, gfx_hal::queue::QueueType::Transfer => {
VkQueueFlagBits::VK_QUEUE_TRANSFER_BIT as u32
}
}, },
queueCount: family.max_queues() as _, queueCount: family.max_queues() as _,
timestampValidBits: 0, //TODO timestampValidBits: 0, //TODO
@ -288,16 +290,16 @@ pub unsafe extern "C" fn gfxGetPhysicalDeviceFeatures2KHR(
.as_mut() .as_mut()
.unwrap(); .unwrap();
data.events = VK_TRUE; data.events = VK_TRUE;
if features.contains(hal::Features::TRIANGLE_FAN) { if features.contains(gfx_hal::Features::TRIANGLE_FAN) {
data.triangleFans = VK_TRUE; data.triangleFans = VK_TRUE;
} }
if features.contains(hal::Features::SEPARATE_STENCIL_REF_VALUES) { if features.contains(gfx_hal::Features::SEPARATE_STENCIL_REF_VALUES) {
data.separateStencilMaskRef = VK_TRUE; data.separateStencilMaskRef = VK_TRUE;
} }
if features.contains(hal::Features::SAMPLER_MIP_LOD_BIAS) { if features.contains(gfx_hal::Features::SAMPLER_MIP_LOD_BIAS) {
data.samplerMipLodBias = VK_TRUE; data.samplerMipLodBias = VK_TRUE;
} }
if features.contains(hal::Features::MUTABLE_COMPARISON_SAMPLER) { if features.contains(gfx_hal::Features::MUTABLE_COMPARISON_SAMPLER) {
data.mutableComparisonSamplers = VK_TRUE; data.mutableComparisonSamplers = VK_TRUE;
} }
//TODO: turn these into a feature flags //TODO: turn these into a feature flags
@ -446,7 +448,7 @@ pub unsafe extern "C" fn gfxGetPhysicalDeviceProperties(
mem::transmute(name) mem::transmute(name)
}; };
use hal::adapter::DeviceType; use gfx_hal::adapter::DeviceType;
let device_type = match adapter.info.device_type { let device_type = match adapter.info.device_type {
DeviceType::IntegratedGpu => VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU, DeviceType::IntegratedGpu => VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU,
DeviceType::DiscreteGpu => VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, DeviceType::DiscreteGpu => VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU,
@ -1254,7 +1256,7 @@ pub unsafe extern "C" fn gfxAllocateMemory(
let memory = gpu let memory = gpu
.device .device
.allocate_memory( .allocate_memory(
hal::MemoryTypeId(info.memoryTypeIndex as _), gfx_hal::MemoryTypeId(info.memoryTypeIndex as _),
info.allocationSize, info.allocationSize,
) )
.unwrap(); // TODO: .unwrap(); // TODO:
@ -1281,7 +1283,7 @@ pub unsafe extern "C" fn gfxMapMemory(
_flags: VkMemoryMapFlags, _flags: VkMemoryMapFlags,
ppData: *mut *mut c_void, ppData: *mut *mut c_void,
) -> VkResult { ) -> VkResult {
let range = hal::memory::Segment { let range = gfx_hal::memory::Segment {
offset, offset,
size: if size == VK_WHOLE_SIZE as VkDeviceSize { size: if size == VK_WHOLE_SIZE as VkDeviceSize {
None None
@ -1306,7 +1308,7 @@ pub unsafe extern "C" fn gfxFlushMappedMemoryRanges(
let ranges = slice::from_raw_parts(pMemoryRanges, memoryRangeCount as _) let ranges = slice::from_raw_parts(pMemoryRanges, memoryRangeCount as _)
.iter() .iter()
.map(|r| { .map(|r| {
let range = hal::memory::Segment { let range = gfx_hal::memory::Segment {
offset: r.offset, offset: r.offset,
size: if r.size == VK_WHOLE_SIZE as VkDeviceSize { size: if r.size == VK_WHOLE_SIZE as VkDeviceSize {
None None
@ -1331,7 +1333,7 @@ pub unsafe extern "C" fn gfxInvalidateMappedMemoryRanges(
let ranges = slice::from_raw_parts(pMemoryRanges, memoryRangeCount as _) let ranges = slice::from_raw_parts(pMemoryRanges, memoryRangeCount as _)
.iter() .iter()
.map(|r| { .map(|r| {
let range = hal::memory::Segment { let range = gfx_hal::memory::Segment {
offset: r.offset, offset: r.offset,
size: if r.size == VK_WHOLE_SIZE as VkDeviceSize { size: if r.size == VK_WHOLE_SIZE as VkDeviceSize {
None None
@ -1534,7 +1536,7 @@ pub unsafe extern "C" fn gfxGetFenceStatus(gpu: VkDevice, fence: VkFence) -> VkR
match gpu.device.get_fence_status(&fence.raw) { match gpu.device.get_fence_status(&fence.raw) {
Ok(true) => VkResult::VK_SUCCESS, Ok(true) => VkResult::VK_SUCCESS,
Ok(false) => VkResult::VK_NOT_READY, Ok(false) => VkResult::VK_NOT_READY,
Err(hal::device::DeviceLost) => VkResult::VK_ERROR_DEVICE_LOST, Err(gfx_hal::device::DeviceLost) => VkResult::VK_ERROR_DEVICE_LOST,
} }
} }
} }
@ -1569,8 +1571,8 @@ pub unsafe extern "C" fn gfxWaitForFences(
match result { match result {
Ok(true) => VkResult::VK_SUCCESS, Ok(true) => VkResult::VK_SUCCESS,
Ok(false) => VkResult::VK_TIMEOUT, Ok(false) => VkResult::VK_TIMEOUT,
Err(hal::device::WaitError::OutOfMemory(oom)) => map_oom(oom), Err(gfx_hal::device::WaitError::OutOfMemory(oom)) => map_oom(oom),
Err(hal::device::WaitError::DeviceLost(hal::device::DeviceLost)) => { Err(gfx_hal::device::WaitError::DeviceLost(gfx_hal::device::DeviceLost)) => {
VkResult::VK_ERROR_DEVICE_LOST VkResult::VK_ERROR_DEVICE_LOST
} }
} }
@ -1633,8 +1635,8 @@ pub unsafe extern "C" fn gfxGetEventStatus(gpu: VkDevice, event: VkEvent) -> VkR
match gpu.device.get_event_status(&event) { match gpu.device.get_event_status(&event) {
Ok(true) => VkResult::VK_EVENT_SET, Ok(true) => VkResult::VK_EVENT_SET,
Ok(false) => VkResult::VK_EVENT_RESET, Ok(false) => VkResult::VK_EVENT_RESET,
Err(hal::device::WaitError::OutOfMemory(oom)) => map_oom(oom), Err(gfx_hal::device::WaitError::OutOfMemory(oom)) => map_oom(oom),
Err(hal::device::WaitError::DeviceLost(hal::device::DeviceLost)) => { Err(gfx_hal::device::WaitError::DeviceLost(gfx_hal::device::DeviceLost)) => {
VkResult::VK_ERROR_DEVICE_LOST VkResult::VK_ERROR_DEVICE_LOST
} }
} }
@ -1721,7 +1723,7 @@ pub unsafe extern "C" fn gfxCreateBuffer(
let info = &*pCreateInfo; let info = &*pCreateInfo;
assert_eq!(info.sharingMode, VkSharingMode::VK_SHARING_MODE_EXCLUSIVE); // TODO assert_eq!(info.sharingMode, VkSharingMode::VK_SHARING_MODE_EXCLUSIVE); // TODO
let sparse_flags = hal::memory::SparseFlags::from_bits_truncate(info.flags); let sparse_flags = gfx_hal::memory::SparseFlags::from_bits_truncate(info.flags);
let buffer = gpu let buffer = gpu
.device .device
.create_buffer(info.size, conv::map_buffer_usage(info.usage), sparse_flags) .create_buffer(info.size, conv::map_buffer_usage(info.usage), sparse_flags)
@ -1750,7 +1752,7 @@ pub unsafe extern "C" fn gfxCreateBufferView(
let view_result = gpu.device.create_buffer_view( let view_result = gpu.device.create_buffer_view(
&info.buffer, &info.buffer,
conv::map_format(info.format), conv::map_format(info.format),
hal::buffer::SubRange { gfx_hal::buffer::SubRange {
offset: info.offset, offset: info.offset,
size: if info.range as i32 == VK_WHOLE_SIZE { size: if info.range as i32 == VK_WHOLE_SIZE {
None None
@ -1794,7 +1796,7 @@ pub unsafe extern "C" fn gfxCreateImage(
warn!("unexpected initial layout: {:?}", info.initialLayout); warn!("unexpected initial layout: {:?}", info.initialLayout);
} }
let sparse_flags = hal::memory::SparseFlags::from_bits_truncate(info.flags); let sparse_flags = gfx_hal::memory::SparseFlags::from_bits_truncate(info.flags);
let kind = conv::map_image_kind( let kind = conv::map_image_kind(
info.imageType, info.imageType,
info.extent, info.extent,
@ -1805,7 +1807,7 @@ pub unsafe extern "C" fn gfxCreateImage(
let view_caps = conv::map_image_create_flags(info.flags); let view_caps = conv::map_image_create_flags(info.flags);
let format = conv::map_format(info.format) let format = conv::map_format(info.format)
.unwrap_or_else(|| panic!("Unsupported image format: {:?}", info.format)); .unwrap_or_else(|| panic!("Unsupported image format: {:?}", info.format));
let fb_attachment = hal::image::FramebufferAttachment { let fb_attachment = gfx_hal::image::FramebufferAttachment {
usage, usage,
view_caps, view_caps,
format, format,
@ -1943,7 +1945,7 @@ pub unsafe extern "C" fn gfxCreateShaderModule(
let base = std::path::PathBuf::from(value.as_str()); let base = std::path::PathBuf::from(value.as_str());
if base.is_dir() { if base.is_dir() {
let code_u8 = slice::from_raw_parts(info.pCode as *const u8, info.codeSize); let code_u8 = slice::from_raw_parts(info.pCode as *const u8, info.codeSize);
for i in 1 .. { for i in 1.. {
let full = base.join(format!("{}.spv", i)); let full = base.join(format!("{}.spv", i));
if !full.exists() { if !full.exists() {
std::fs::write(full, code_u8).unwrap(); std::fs::write(full, code_u8).unwrap();
@ -2017,7 +2019,7 @@ pub unsafe extern "C" fn gfxGetPipelineCacheData(
) -> VkResult { ) -> VkResult {
let data = match gpu.device.get_pipeline_cache_data(&pipelineCache) { let data = match gpu.device.get_pipeline_cache_data(&pipelineCache) {
Ok(data) => data, Ok(data) => data,
Err(oom) => return map_oom(oom) Err(oom) => return map_oom(oom),
}; };
if pData.is_null() { if pData.is_null() {
@ -2207,7 +2209,7 @@ pub unsafe extern "C" fn gfxCreateGraphicsPipelines(
"Primitive topology {:?} is not supported", "Primitive topology {:?} is not supported",
input_state.topology input_state.topology
); );
(hal::pso::Primitive::PointList, false) (gfx_hal::pso::Primitive::PointList, false)
} }
}; };
@ -2711,18 +2713,18 @@ pub unsafe extern "C" fn gfxCreateSampler(
pSampler: *mut VkSampler, pSampler: *mut VkSampler,
) -> VkResult { ) -> VkResult {
let info = &*pCreateInfo; let info = &*pCreateInfo;
let gfx_info = hal::image::SamplerDesc { let gfx_info = gfx_hal::image::SamplerDesc {
min_filter: conv::map_filter(info.minFilter), min_filter: conv::map_filter(info.minFilter),
mag_filter: conv::map_filter(info.magFilter), mag_filter: conv::map_filter(info.magFilter),
mip_filter: conv::map_mipmap_filter(info.mipmapMode), mip_filter: conv::map_mipmap_filter(info.mipmapMode),
reduction_mode: hal::image::ReductionMode::WeightedAverage, reduction_mode: gfx_hal::image::ReductionMode::WeightedAverage,
wrap_mode: ( wrap_mode: (
conv::map_wrap_mode(info.addressModeU), conv::map_wrap_mode(info.addressModeU),
conv::map_wrap_mode(info.addressModeV), conv::map_wrap_mode(info.addressModeV),
conv::map_wrap_mode(info.addressModeW), conv::map_wrap_mode(info.addressModeW),
), ),
lod_bias: hal::image::Lod(info.mipLodBias), lod_bias: gfx_hal::image::Lod(info.mipLodBias),
lod_range: hal::image::Lod(info.minLod)..hal::image::Lod(info.maxLod), lod_range: gfx_hal::image::Lod(info.minLod)..gfx_hal::image::Lod(info.maxLod),
comparison: if info.compareEnable == VK_TRUE { comparison: if info.compareEnable == VK_TRUE {
Some(conv::map_compare_op(info.compareOp)) Some(conv::map_compare_op(info.compareOp))
} else { } else {
@ -2986,7 +2988,7 @@ impl<'a> Iterator for DescriptorIter<'a> {
.map(|view| pso::Descriptor::TexelBuffer(&**view)), .map(|view| pso::Descriptor::TexelBuffer(&**view)),
pso::BufferDescriptorFormat::Structured { .. } => { pso::BufferDescriptorFormat::Structured { .. } => {
self.buffer_infos.next().map(|buffer| { self.buffer_infos.next().map(|buffer| {
let range = hal::buffer::SubRange { let range = gfx_hal::buffer::SubRange {
offset: buffer.offset, offset: buffer.offset,
size: if buffer.range as i32 == VK_WHOLE_SIZE { size: if buffer.range as i32 == VK_WHOLE_SIZE {
None None
@ -3073,7 +3075,7 @@ pub unsafe extern "C" fn gfxCreateFramebuffer(
pFramebuffer: *mut VkFramebuffer, pFramebuffer: *mut VkFramebuffer,
) -> VkResult { ) -> VkResult {
let info = &*pCreateInfo; let info = &*pCreateInfo;
let extent = hal::image::Extent { let extent = gfx_hal::image::Extent {
width: info.width, width: info.width,
height: info.height, height: info.height,
depth: info.layers, depth: info.layers,
@ -3108,7 +3110,7 @@ pub unsafe extern "C" fn gfxCreateFramebuffer(
&*info.renderPass, &*info.renderPass,
raw_attachment_infos raw_attachment_infos
.iter() .iter()
.map(|ai| hal::image::FramebufferAttachment { .map(|ai| gfx_hal::image::FramebufferAttachment {
usage: conv::map_image_usage(ai.usage), usage: conv::map_image_usage(ai.usage),
view_caps: conv::map_image_create_flags(ai.flags), view_caps: conv::map_image_create_flags(ai.flags),
//TODO: properly support view format lists! //TODO: properly support view format lists!
@ -3336,7 +3338,7 @@ pub unsafe extern "C" fn gfxCreateCommandPool(
_pAllocator: *const VkAllocationCallbacks, _pAllocator: *const VkAllocationCallbacks,
pCommandPool: *mut VkCommandPool, pCommandPool: *mut VkCommandPool,
) -> VkResult { ) -> VkResult {
use hal::pool::CommandPoolCreateFlags; use gfx_hal::pool::CommandPoolCreateFlags;
let info = &*pCreateInfo; let info = &*pCreateInfo;
let family = queue::QueueFamilyId(info.queueFamilyIndex as _); let family = queue::QueueFamilyId(info.queueFamilyIndex as _);
@ -3600,7 +3602,7 @@ pub unsafe extern "C" fn gfxCmdBindIndexBuffer(
) { ) {
commandBuffer.bind_index_buffer( commandBuffer.bind_index_buffer(
&*buffer, &*buffer,
hal::buffer::SubRange { offset, size: None }, gfx_hal::buffer::SubRange { offset, size: None },
conv::map_index_type(indexType), conv::map_index_type(indexType),
); );
} }
@ -3619,7 +3621,7 @@ pub unsafe extern "C" fn gfxCmdBindVertexBuffers(
let views = buffers let views = buffers
.into_iter() .into_iter()
.zip(offsets) .zip(offsets)
.map(|(buffer, &offset)| (&**buffer, hal::buffer::SubRange { offset, size: None })); .map(|(buffer, &offset)| (&**buffer, gfx_hal::buffer::SubRange { offset, size: None }));
commandBuffer.bind_vertex_buffers(firstBinding, views); commandBuffer.bind_vertex_buffers(firstBinding, views);
} }
@ -3873,7 +3875,7 @@ pub unsafe extern "C" fn gfxCmdFillBuffer(
size: VkDeviceSize, size: VkDeviceSize,
data: u32, data: u32,
) { ) {
let range = hal::buffer::SubRange { let range = gfx_hal::buffer::SubRange {
offset: dstOffset, offset: dstOffset,
size: if size == VK_WHOLE_SIZE as VkDeviceSize { size: if size == VK_WHOLE_SIZE as VkDeviceSize {
None None
@ -4051,7 +4053,7 @@ fn make_barriers<'a>(
states: conv::map_buffer_access(b.srcAccessMask)..conv::map_buffer_access(b.dstAccessMask), states: conv::map_buffer_access(b.srcAccessMask)..conv::map_buffer_access(b.dstAccessMask),
target: &*b.buffer, target: &*b.buffer,
families: None, families: None,
range: hal::buffer::SubRange { range: gfx_hal::buffer::SubRange {
offset: b.offset, offset: b.offset,
size: if b.size as i32 == VK_WHOLE_SIZE { size: if b.size as i32 == VK_WHOLE_SIZE {
None None
@ -4141,7 +4143,7 @@ pub unsafe extern "C" fn gfxCmdBeginQuery(
query: u32, query: u32,
flags: VkQueryControlFlags, flags: VkQueryControlFlags,
) { ) {
let query = hal::query::Query { let query = gfx_hal::query::Query {
pool: &*queryPool, pool: &*queryPool,
id: query, id: query,
}; };
@ -4153,7 +4155,7 @@ pub unsafe extern "C" fn gfxCmdEndQuery(
queryPool: VkQueryPool, queryPool: VkQueryPool,
query: u32, query: u32,
) { ) {
let query = hal::query::Query { let query = gfx_hal::query::Query {
pool: &*queryPool, pool: &*queryPool,
id: query, id: query,
}; };
@ -4175,7 +4177,7 @@ pub unsafe extern "C" fn gfxCmdWriteTimestamp(
queryPool: VkQueryPool, queryPool: VkQueryPool,
query: u32, query: u32,
) { ) {
let query = hal::query::Query { let query = gfx_hal::query::Query {
pool: &*queryPool, pool: &*queryPool,
id: query, id: query,
}; };
@ -4270,11 +4272,12 @@ pub unsafe extern "C" fn gfxCmdBeginRenderPass(
.iter() .iter()
// HAL and Vulkan clear value union sharing same memory representation // HAL and Vulkan clear value union sharing same memory representation
.map(|cv| mem::transmute::<_, com::ClearValue>(*cv)) .map(|cv| mem::transmute::<_, com::ClearValue>(*cv))
.chain((info.clearValueCount..).map(|_| hal::command::ClearValue::default())); .chain((info.clearValueCount..).map(|_| gfx_hal::command::ClearValue::default()));
let attachments = image_views let attachments = image_views
.iter() .iter()
.zip(clear_values) .zip(clear_values)
.map(|(view, clear_value)| hal::command::RenderAttachmentInfo { .map(
|(view, clear_value)| gfx_hal::command::RenderAttachmentInfo {
image_view: match **view { image_view: match **view {
ImageView::Native { ref raw, .. } => raw, ImageView::Native { ref raw, .. } => raw,
ImageView::SwapchainFrame { ImageView::SwapchainFrame {
@ -4286,7 +4289,8 @@ pub unsafe extern "C" fn gfxCmdBeginRenderPass(
.borrow(), .borrow(),
}, },
clear_value, clear_value,
}); },
);
let contents = conv::map_subpass_contents(contents); let contents = conv::map_subpass_contents(contents);
commandBuffer.begin_render_pass( commandBuffer.begin_render_pass(
@ -4536,7 +4540,7 @@ pub unsafe extern "C" fn gfxCreateSwapchainKHR(
VkSharingMode::VK_SHARING_MODE_EXCLUSIVE VkSharingMode::VK_SHARING_MODE_EXCLUSIVE
); // TODO ); // TODO
let config = hal::window::SwapchainConfig { let config = gfx_hal::window::SwapchainConfig {
present_mode: conv::map_present_mode(info.presentMode), present_mode: conv::map_present_mode(info.presentMode),
composite_alpha_mode: conv::map_composite_alpha(info.compositeAlpha), composite_alpha_mode: conv::map_composite_alpha(info.compositeAlpha),
format: conv::map_format(info.imageFormat).unwrap(), format: conv::map_format(info.imageFormat).unwrap(),
@ -4570,13 +4574,16 @@ pub unsafe extern "C" fn gfxCreateSwapchainKHR(
VkResult::VK_SUCCESS VkResult::VK_SUCCESS
} }
Err(err) => { Err(err) => {
use hal::window::SwapchainError as Se; use gfx_hal::window::SwapchainError as Se;
match err { match err {
Se::OutOfMemory(oom) => map_oom(oom), Se::OutOfMemory(oom) => map_oom(oom),
Se::DeviceLost(hal::device::DeviceLost) => VkResult::VK_ERROR_DEVICE_LOST, Se::DeviceLost(gfx_hal::device::DeviceLost) => VkResult::VK_ERROR_DEVICE_LOST,
Se::SurfaceLost(hal::window::SurfaceLost) => VkResult::VK_ERROR_SURFACE_LOST_KHR, Se::SurfaceLost(gfx_hal::window::SurfaceLost) => {
VkResult::VK_ERROR_SURFACE_LOST_KHR
}
Se::WindowInUse => VkResult::VK_ERROR_NATIVE_WINDOW_IN_USE_KHR, Se::WindowInUse => VkResult::VK_ERROR_NATIVE_WINDOW_IN_USE_KHR,
Se::Unknown => VkResult::VK_ERROR_UNKNOWN, Se::Unknown => VkResult::VK_ERROR_UNKNOWN,
Se::WrongThread => VkResult::VK_ERROR_UNKNOWN,
} }
} }
} }
@ -4925,12 +4932,12 @@ pub unsafe extern "C" fn gfxAcquireNextImageKHR(
None => VkResult::VK_SUCCESS, None => VkResult::VK_SUCCESS,
} }
} }
Err(hal::window::AcquireError::NotReady { timeout: false }) => VkResult::VK_NOT_READY, Err(gfx_hal::window::AcquireError::NotReady { timeout: false }) => VkResult::VK_NOT_READY,
Err(hal::window::AcquireError::NotReady { timeout: true }) => VkResult::VK_TIMEOUT, Err(gfx_hal::window::AcquireError::NotReady { timeout: true }) => VkResult::VK_TIMEOUT,
Err(hal::window::AcquireError::OutOfDate(_)) => VkResult::VK_ERROR_OUT_OF_DATE_KHR, Err(gfx_hal::window::AcquireError::OutOfDate(_)) => VkResult::VK_ERROR_OUT_OF_DATE_KHR,
Err(hal::window::AcquireError::SurfaceLost(_)) => VkResult::VK_ERROR_SURFACE_LOST_KHR, Err(gfx_hal::window::AcquireError::SurfaceLost(_)) => VkResult::VK_ERROR_SURFACE_LOST_KHR,
Err(hal::window::AcquireError::DeviceLost(_)) => VkResult::VK_ERROR_DEVICE_LOST, Err(gfx_hal::window::AcquireError::DeviceLost(_)) => VkResult::VK_ERROR_DEVICE_LOST,
Err(hal::window::AcquireError::OutOfMemory(oom)) => map_oom(oom), Err(gfx_hal::window::AcquireError::OutOfMemory(oom)) => map_oom(oom),
} }
} }
#[inline] #[inline]

View file

@ -49,30 +49,30 @@ pub use crate::impls::*;
// Vulkan objects // Vulkan objects
pub type VkInstance = Handle<RawInstance>; pub type VkInstance = Handle<RawInstance>;
pub type VkPhysicalDevice = Handle<hal::adapter::Adapter<B>>; pub type VkPhysicalDevice = Handle<gfx_hal::adapter::Adapter<B>>;
pub type VkDevice = DispatchHandle<Gpu<B>>; pub type VkDevice = DispatchHandle<Gpu<B>>;
pub type VkQueue = DispatchHandle<Queue<B>>; pub type VkQueue = DispatchHandle<Queue<B>>;
pub type VkCommandPool = Handle<CommandPool<B>>; pub type VkCommandPool = Handle<CommandPool<B>>;
pub type VkCommandBuffer = DispatchHandle<<B as hal::Backend>::CommandBuffer>; pub type VkCommandBuffer = DispatchHandle<<B as gfx_hal::Backend>::CommandBuffer>;
pub type VkDeviceMemory = Handle<<B as hal::Backend>::Memory>; pub type VkDeviceMemory = Handle<<B as gfx_hal::Backend>::Memory>;
pub type VkDescriptorSetLayout = Handle<<B as hal::Backend>::DescriptorSetLayout>; pub type VkDescriptorSetLayout = Handle<<B as gfx_hal::Backend>::DescriptorSetLayout>;
pub type VkPipelineLayout = Handle<<B as hal::Backend>::PipelineLayout>; pub type VkPipelineLayout = Handle<<B as gfx_hal::Backend>::PipelineLayout>;
pub type VkDescriptorPool = Handle<DescriptorPool<B>>; pub type VkDescriptorPool = Handle<DescriptorPool<B>>;
pub type VkDescriptorSet = Handle<<B as hal::Backend>::DescriptorSet>; pub type VkDescriptorSet = Handle<<B as gfx_hal::Backend>::DescriptorSet>;
pub type VkSampler = Handle<<B as hal::Backend>::Sampler>; pub type VkSampler = Handle<<B as gfx_hal::Backend>::Sampler>;
pub type VkBufferView = Handle<<B as hal::Backend>::BufferView>; pub type VkBufferView = Handle<<B as gfx_hal::Backend>::BufferView>;
pub type VkShaderModule = Handle<<B as hal::Backend>::ShaderModule>; pub type VkShaderModule = Handle<<B as gfx_hal::Backend>::ShaderModule>;
pub type VkImage = Handle<Image<B>>; pub type VkImage = Handle<Image<B>>;
pub type VkImageView = Handle<ImageView>; pub type VkImageView = Handle<ImageView>;
pub type VkBuffer = Handle<<B as hal::Backend>::Buffer>; pub type VkBuffer = Handle<<B as gfx_hal::Backend>::Buffer>;
pub type VkSemaphore = Handle<Semaphore<B>>; pub type VkSemaphore = Handle<Semaphore<B>>;
pub type VkEvent = Handle<<B as hal::Backend>::Event>; pub type VkEvent = Handle<<B as gfx_hal::Backend>::Event>;
pub type VkFence = Handle<Fence<B>>; pub type VkFence = Handle<Fence<B>>;
pub type VkRenderPass = Handle<<B as hal::Backend>::RenderPass>; pub type VkRenderPass = Handle<<B as gfx_hal::Backend>::RenderPass>;
pub type VkFramebuffer = Handle<Framebuffer>; pub type VkFramebuffer = Handle<Framebuffer>;
pub type VkPipeline = Handle<Pipeline<B>>; pub type VkPipeline = Handle<Pipeline<B>>;
pub type VkPipelineCache = Handle<<B as hal::Backend>::PipelineCache>; pub type VkPipelineCache = Handle<<B as gfx_hal::Backend>::PipelineCache>;
pub type VkQueryPool = Handle<<B as hal::Backend>::QueryPool>; pub type VkQueryPool = Handle<<B as gfx_hal::Backend>::QueryPool>;
pub type QueueFamilyIndex = u32; pub type QueueFamilyIndex = u32;
@ -82,7 +82,7 @@ pub struct RawInstance {
pub enabled_extensions: Vec<String>, pub enabled_extensions: Vec<String>,
} }
pub struct Gpu<B: hal::Backend> { pub struct Gpu<B: gfx_hal::Backend> {
device: B::Device, device: B::Device,
queues: HashMap<QueueFamilyIndex, Vec<VkQueue>>, queues: HashMap<QueueFamilyIndex, Vec<VkQueue>>,
enabled_extensions: Vec<String>, enabled_extensions: Vec<String>,
@ -92,7 +92,7 @@ pub struct Gpu<B: hal::Backend> {
capturing: *mut (), capturing: *mut (),
} }
impl<B: hal::Backend> Gpu<B> { impl<B: gfx_hal::Backend> Gpu<B> {
fn has_extension(&self, extension: &[u8]) -> bool { fn has_extension(&self, extension: &[u8]) -> bool {
self.enabled_extensions self.enabled_extensions
.iter() .iter()
@ -100,33 +100,33 @@ impl<B: hal::Backend> Gpu<B> {
} }
} }
pub struct Queue<B: hal::Backend> { pub struct Queue<B: gfx_hal::Backend> {
raw: B::Queue, raw: B::Queue,
temp_semaphores: Vec<(VkPipelineStageFlags, VkSemaphore)>, temp_semaphores: Vec<(VkPipelineStageFlags, VkSemaphore)>,
} }
pub struct DescriptorPool<B: hal::Backend> { pub struct DescriptorPool<B: gfx_hal::Backend> {
raw: B::DescriptorPool, raw: B::DescriptorPool,
temp_sets: Vec<B::DescriptorSet>, temp_sets: Vec<B::DescriptorSet>,
set_handles: Option<Vec<VkDescriptorSet>>, set_handles: Option<Vec<VkDescriptorSet>>,
} }
pub enum Pipeline<B: hal::Backend> { pub enum Pipeline<B: gfx_hal::Backend> {
Graphics(B::GraphicsPipeline), Graphics(B::GraphicsPipeline),
Compute(B::ComputePipeline), Compute(B::ComputePipeline),
} }
pub enum Image<B: hal::Backend> { pub enum Image<B: gfx_hal::Backend> {
Native { Native {
raw: B::Image, raw: B::Image,
//mip_levels: u32, //mip_levels: u32,
//array_layers: u32, //array_layers: u32,
fb_attachment: hal::image::FramebufferAttachment, fb_attachment: gfx_hal::image::FramebufferAttachment,
usage: hal::image::Usage, usage: gfx_hal::image::Usage,
}, },
SwapchainFrame { SwapchainFrame {
swapchain: VkSwapchainKHR, swapchain: VkSwapchainKHR,
frame: hal::window::SwapImageIndex, frame: gfx_hal::window::SwapImageIndex,
}, },
} }
@ -134,7 +134,7 @@ pub enum Image<B: hal::Backend> {
struct UnexpectedSwapchainImage; struct UnexpectedSwapchainImage;
impl Image<B> { impl Image<B> {
fn as_native(&self) -> Result<&<B as hal::Backend>::Image, UnexpectedSwapchainImage> { fn as_native(&self) -> Result<&<B as gfx_hal::Backend>::Image, UnexpectedSwapchainImage> {
//use std::borrow::Borrow; //use std::borrow::Borrow;
match *self { match *self {
Image::Native { ref raw, .. } => Ok(raw), Image::Native { ref raw, .. } => Ok(raw),
@ -147,24 +147,24 @@ impl Image<B> {
pub enum ImageView { pub enum ImageView {
Native { Native {
raw: <B as hal::Backend>::ImageView, raw: <B as gfx_hal::Backend>::ImageView,
fb_attachment: hal::image::FramebufferAttachment, fb_attachment: gfx_hal::image::FramebufferAttachment,
}, },
SwapchainFrame { SwapchainFrame {
swapchain: VkSwapchainKHR, swapchain: VkSwapchainKHR,
frame: hal::window::SwapImageIndex, frame: gfx_hal::window::SwapImageIndex,
}, },
} }
impl ImageView { impl ImageView {
fn as_native(&self) -> Result<&<B as hal::Backend>::ImageView, UnexpectedSwapchainImage> { fn as_native(&self) -> Result<&<B as gfx_hal::Backend>::ImageView, UnexpectedSwapchainImage> {
match *self { match *self {
ImageView::Native { ref raw, .. } => Ok(raw), ImageView::Native { ref raw, .. } => Ok(raw),
ImageView::SwapchainFrame { .. } => Err(UnexpectedSwapchainImage), ImageView::SwapchainFrame { .. } => Err(UnexpectedSwapchainImage),
} }
} }
fn framebuffer_attachment(&self) -> hal::image::FramebufferAttachment { fn framebuffer_attachment(&self) -> gfx_hal::image::FramebufferAttachment {
match *self { match *self {
Self::Native { Self::Native {
raw: _, raw: _,
@ -179,22 +179,22 @@ impl ImageView {
} }
pub struct Framebuffer { pub struct Framebuffer {
raw: <B as hal::Backend>::Framebuffer, raw: <B as gfx_hal::Backend>::Framebuffer,
// If none, the VkFramebuffer is image-less // If none, the VkFramebuffer is image-less
image_views: Option<Box<[VkImageView]>>, image_views: Option<Box<[VkImageView]>>,
} }
pub struct Semaphore<B: hal::Backend> { pub struct Semaphore<B: gfx_hal::Backend> {
raw: B::Semaphore, raw: B::Semaphore,
is_fake: Cell<bool>, is_fake: Cell<bool>,
} }
pub struct Fence<B: hal::Backend> { pub struct Fence<B: gfx_hal::Backend> {
raw: B::Fence, raw: B::Fence,
is_fake: bool, is_fake: bool,
} }
pub struct CommandPool<B: hal::Backend> { pub struct CommandPool<B: gfx_hal::Backend> {
pool: B::CommandPool, pool: B::CommandPool,
buffers: Vec<VkCommandBuffer>, buffers: Vec<VkCommandBuffer>,
} }
@ -204,17 +204,17 @@ pub struct CommandPool<B: hal::Backend> {
pub type VkSurfaceKHR = Handle<Surface<B>>; pub type VkSurfaceKHR = Handle<Surface<B>>;
pub type VkSwapchainKHR = Handle<Swapchain<B>>; pub type VkSwapchainKHR = Handle<Swapchain<B>>;
pub struct Surface<B: hal::Backend> { pub struct Surface<B: gfx_hal::Backend> {
raw: B::Surface, raw: B::Surface,
swapchain_revision: u32, swapchain_revision: u32,
} }
pub struct Swapchain<B: hal::Backend> { pub struct Swapchain<B: gfx_hal::Backend> {
surface: VkSurfaceKHR, surface: VkSurfaceKHR,
framebuffer_attachment: hal::image::FramebufferAttachment, framebuffer_attachment: gfx_hal::image::FramebufferAttachment,
frame_count: hal::window::SwapImageIndex, frame_count: gfx_hal::window::SwapImageIndex,
current_index: hal::window::SwapImageIndex, current_index: gfx_hal::window::SwapImageIndex,
active: Vec<Option<<B::Surface as hal::window::PresentationSurface<B>>::SwapchainImage>>, active: Vec<Option<<B::Surface as gfx_hal::window::PresentationSurface<B>>::SwapchainImage>>,
revision: u32, revision: u32,
} }