Format code using rustfmt

This commit is contained in:
Martin Krošlák 2020-01-19 22:40:21 +01:00
parent a9edbc0337
commit 9f5d97a43c
6 changed files with 3610 additions and 3088 deletions

View file

@ -1,11 +1,10 @@
use hal::{buffer, command, device, format, image, memory, pass, pso, query, window}; use hal::{buffer, command, device, format, image, memory, pass, pso, query, window};
use hal::{IndexType, Features, Limits, PatchSize, Primitive}; use hal::{Features, IndexType, Limits, PatchSize, Primitive};
use std::mem; use std::mem;
use super::*; use super::*;
pub fn limits_from_hal(limits: Limits) -> VkPhysicalDeviceLimits { pub fn limits_from_hal(limits: Limits) -> VkPhysicalDeviceLimits {
let viewport_size = limits.max_viewport_dimensions[0].max(limits.max_viewport_dimensions[1]); let viewport_size = limits.max_viewport_dimensions[0].max(limits.max_viewport_dimensions[1]);
VkPhysicalDeviceLimits { VkPhysicalDeviceLimits {
@ -86,16 +85,33 @@ pub fn features_from_hal(features: Features) -> VkPhysicalDeviceFeatures {
pipelineStatisticsQuery: features.contains(Features::PIPELINE_STATISTICS_QUERY) as _, pipelineStatisticsQuery: features.contains(Features::PIPELINE_STATISTICS_QUERY) as _,
vertexPipelineStoresAndAtomics: features.contains(Features::VERTEX_STORES_AND_ATOMICS) as _, vertexPipelineStoresAndAtomics: features.contains(Features::VERTEX_STORES_AND_ATOMICS) as _,
fragmentStoresAndAtomics: features.contains(Features::FRAGMENT_STORES_AND_ATOMICS) as _, fragmentStoresAndAtomics: features.contains(Features::FRAGMENT_STORES_AND_ATOMICS) as _,
shaderTessellationAndGeometryPointSize: features.contains(Features::SHADER_TESSELLATION_AND_GEOMETRY_POINT_SIZE) as _, shaderTessellationAndGeometryPointSize: features
.contains(Features::SHADER_TESSELLATION_AND_GEOMETRY_POINT_SIZE)
as _,
shaderImageGatherExtended: features.contains(Features::SHADER_IMAGE_GATHER_EXTENDED) as _, shaderImageGatherExtended: features.contains(Features::SHADER_IMAGE_GATHER_EXTENDED) as _,
shaderStorageImageExtendedFormats: features.contains(Features::SHADER_STORAGE_IMAGE_EXTENDED_FORMATS) as _, shaderStorageImageExtendedFormats: features
shaderStorageImageMultisample: features.contains(Features::SHADER_STORAGE_IMAGE_MULTISAMPLE) as _, .contains(Features::SHADER_STORAGE_IMAGE_EXTENDED_FORMATS)
shaderStorageImageReadWithoutFormat: features.contains(Features::SHADER_STORAGE_IMAGE_READ_WITHOUT_FORMAT) as _, as _,
shaderStorageImageWriteWithoutFormat: features.contains(Features::SHADER_STORAGE_IMAGE_WRITE_WITHOUT_FORMAT) as _, shaderStorageImageMultisample: features.contains(Features::SHADER_STORAGE_IMAGE_MULTISAMPLE)
shaderUniformBufferArrayDynamicIndexing: features.contains(Features::SHADER_UNIFORM_BUFFER_ARRAY_DYNAMIC_INDEXING) as _, as _,
shaderSampledImageArrayDynamicIndexing: features.contains(Features::SHADER_SAMPLED_IMAGE_ARRAY_DYNAMIC_INDEXING) as _, shaderStorageImageReadWithoutFormat: features
shaderStorageBufferArrayDynamicIndexing: features.contains(Features::SHADER_STORAGE_BUFFER_ARRAY_DYNAMIC_INDEXING) as _, .contains(Features::SHADER_STORAGE_IMAGE_READ_WITHOUT_FORMAT)
shaderStorageImageArrayDynamicIndexing: features.contains(Features::SHADER_STORAGE_IMAGE_ARRAY_DYNAMIC_INDEXING) as _, as _,
shaderStorageImageWriteWithoutFormat: features
.contains(Features::SHADER_STORAGE_IMAGE_WRITE_WITHOUT_FORMAT)
as _,
shaderUniformBufferArrayDynamicIndexing: features
.contains(Features::SHADER_UNIFORM_BUFFER_ARRAY_DYNAMIC_INDEXING)
as _,
shaderSampledImageArrayDynamicIndexing: features
.contains(Features::SHADER_SAMPLED_IMAGE_ARRAY_DYNAMIC_INDEXING)
as _,
shaderStorageBufferArrayDynamicIndexing: features
.contains(Features::SHADER_STORAGE_BUFFER_ARRAY_DYNAMIC_INDEXING)
as _,
shaderStorageImageArrayDynamicIndexing: features
.contains(Features::SHADER_STORAGE_IMAGE_ARRAY_DYNAMIC_INDEXING)
as _,
shaderClipDistance: features.contains(Features::SHADER_CLIP_DISTANCE) as _, shaderClipDistance: features.contains(Features::SHADER_CLIP_DISTANCE) as _,
shaderCullDistance: features.contains(Features::SHADER_CULL_DISTANCE) as _, shaderCullDistance: features.contains(Features::SHADER_CULL_DISTANCE) as _,
shaderFloat64: features.contains(Features::SHADER_FLOAT64) as _, shaderFloat64: features.contains(Features::SHADER_FLOAT64) as _,
@ -131,7 +147,9 @@ pub fn format_properties_from_hal(properties: format::Properties) -> VkFormatPro
} }
} }
pub fn image_format_properties_from_hal(properties: image::FormatProperties) -> VkImageFormatProperties { pub fn image_format_properties_from_hal(
properties: image::FormatProperties,
) -> VkImageFormatProperties {
VkImageFormatProperties { VkImageFormatProperties {
maxExtent: extent3d_from_hal(properties.max_extent), maxExtent: extent3d_from_hal(properties.max_extent),
maxMipLevels: properties.max_levels as _, maxMipLevels: properties.max_levels as _,
@ -284,9 +302,16 @@ pub fn map_image_kind(
debug_assert_ne!(array_layers, 0); debug_assert_ne!(array_layers, 0);
match ty { match ty {
VkImageType::VK_IMAGE_TYPE_1D => image::Kind::D1(extent.width as _, array_layers), VkImageType::VK_IMAGE_TYPE_1D => image::Kind::D1(extent.width as _, array_layers),
VkImageType::VK_IMAGE_TYPE_2D => image::Kind::D2(extent.width as _, extent.height as _, array_layers, samples as _), VkImageType::VK_IMAGE_TYPE_2D => image::Kind::D2(
VkImageType::VK_IMAGE_TYPE_3D => image::Kind::D3(extent.width as _, extent.height as _, extent.depth as _), extent.width as _,
_ => unreachable!() extent.height as _,
array_layers,
samples as _,
),
VkImageType::VK_IMAGE_TYPE_3D => {
image::Kind::D3(extent.width as _, extent.height as _, extent.depth as _)
}
_ => unreachable!(),
} }
} }
@ -299,7 +324,7 @@ pub fn map_view_kind(ty: VkImageViewType) -> image::ViewKind {
VkImageViewType::VK_IMAGE_VIEW_TYPE_3D => image::ViewKind::D3, VkImageViewType::VK_IMAGE_VIEW_TYPE_3D => image::ViewKind::D3,
VkImageViewType::VK_IMAGE_VIEW_TYPE_CUBE => image::ViewKind::Cube, VkImageViewType::VK_IMAGE_VIEW_TYPE_CUBE => image::ViewKind::Cube,
VkImageViewType::VK_IMAGE_VIEW_TYPE_CUBE_ARRAY => image::ViewKind::CubeArray, VkImageViewType::VK_IMAGE_VIEW_TYPE_CUBE_ARRAY => image::ViewKind::CubeArray,
_ => unreachable!() _ => unreachable!(),
} }
} }
@ -309,8 +334,12 @@ pub fn map_image_layout(layout: VkImageLayout) -> image::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,
VkImageLayout::VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL => ColorAttachmentOptimal, VkImageLayout::VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL => ColorAttachmentOptimal,
VkImageLayout::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL => DepthStencilAttachmentOptimal, VkImageLayout::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL => {
VkImageLayout::VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL => DepthStencilReadOnlyOptimal, DepthStencilAttachmentOptimal
}
VkImageLayout::VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL => {
DepthStencilReadOnlyOptimal
}
VkImageLayout::VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL => ShaderReadOnlyOptimal, VkImageLayout::VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL => ShaderReadOnlyOptimal,
VkImageLayout::VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL => TransferSrcOptimal, VkImageLayout::VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL => TransferSrcOptimal,
VkImageLayout::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL => TransferDstOptimal, VkImageLayout::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL => TransferDstOptimal,
@ -560,8 +589,9 @@ pub fn map_attachment_store_op(op: VkAttachmentStoreOp) -> pass::AttachmentStore
pub fn map_subpass_contents(contents: VkSubpassContents) -> command::SubpassContents { pub fn map_subpass_contents(contents: VkSubpassContents) -> command::SubpassContents {
match contents { match contents {
VkSubpassContents::VK_SUBPASS_CONTENTS_INLINE => command::SubpassContents::Inline, VkSubpassContents::VK_SUBPASS_CONTENTS_INLINE => command::SubpassContents::Inline,
VkSubpassContents::VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS => VkSubpassContents::VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS => {
command::SubpassContents::SecondaryBuffers, command::SubpassContents::SecondaryBuffers
}
_ => panic!("Unexpected subpass contents: {:?}", contents), _ => panic!("Unexpected subpass contents: {:?}", contents),
} }
@ -594,7 +624,10 @@ pub fn map_front_face(face: VkFrontFace) -> pso::FrontFace {
} }
} }
pub fn map_primitive_topology(topology: VkPrimitiveTopology, patch_size: PatchSize) -> Option<Primitive> { pub fn map_primitive_topology(
topology: VkPrimitiveTopology,
patch_size: PatchSize,
) -> Option<Primitive> {
use super::VkPrimitiveTopology::*; use super::VkPrimitiveTopology::*;
Some(match topology { Some(match topology {
@ -622,14 +655,15 @@ pub fn map_present_mode(present_mode: VkPresentModeKHR) -> window::PresentMode {
pub fn map_composite_alpha(composite_alpha: VkCompositeAlphaFlagBitsKHR) -> window::CompositeAlpha { pub fn map_composite_alpha(composite_alpha: VkCompositeAlphaFlagBitsKHR) -> window::CompositeAlpha {
if composite_alpha == VkCompositeAlphaFlagBitsKHR::VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR { if composite_alpha == VkCompositeAlphaFlagBitsKHR::VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR {
window::CompositeAlpha::OPAQUE window::CompositeAlpha::OPAQUE
} else } else if composite_alpha
if composite_alpha == VkCompositeAlphaFlagBitsKHR::VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR { == VkCompositeAlphaFlagBitsKHR::VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR
{
window::CompositeAlpha::PREMULTIPLIED window::CompositeAlpha::PREMULTIPLIED
} else } else if composite_alpha
if composite_alpha == VkCompositeAlphaFlagBitsKHR::VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR { == VkCompositeAlphaFlagBitsKHR::VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR
{
window::CompositeAlpha::POSTMULTIPLIED window::CompositeAlpha::POSTMULTIPLIED
} else } else if composite_alpha == VkCompositeAlphaFlagBitsKHR::VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR {
if composite_alpha == VkCompositeAlphaFlagBitsKHR::VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR {
window::CompositeAlpha::INHERIT window::CompositeAlpha::INHERIT
} else { } else {
error!("Unrecognized composite alpha: {:?}", composite_alpha); error!("Unrecognized composite alpha: {:?}", composite_alpha);
@ -674,21 +708,23 @@ fn map_blend_factor(factor: VkBlendFactor) -> pso::Factor {
} }
pub fn map_blend_op( pub fn map_blend_op(
blend_op: VkBlendOp, src_factor: VkBlendFactor, dst_factor: VkBlendFactor, blend_op: VkBlendOp,
src_factor: VkBlendFactor,
dst_factor: VkBlendFactor,
) -> pso::BlendOp { ) -> pso::BlendOp {
use super::VkBlendOp::*; use super::VkBlendOp::*;
match blend_op { match blend_op {
VK_BLEND_OP_ADD => pso::BlendOp::Add { VK_BLEND_OP_ADD => pso::BlendOp::Add {
src: map_blend_factor(src_factor), src: map_blend_factor(src_factor),
dst: map_blend_factor(dst_factor) dst: map_blend_factor(dst_factor),
}, },
VK_BLEND_OP_SUBTRACT => pso::BlendOp::Sub { VK_BLEND_OP_SUBTRACT => pso::BlendOp::Sub {
src: map_blend_factor(src_factor), src: map_blend_factor(src_factor),
dst: map_blend_factor(dst_factor) dst: map_blend_factor(dst_factor),
}, },
VK_BLEND_OP_REVERSE_SUBTRACT => pso::BlendOp::RevSub { VK_BLEND_OP_REVERSE_SUBTRACT => pso::BlendOp::RevSub {
src: map_blend_factor(src_factor), src: map_blend_factor(src_factor),
dst: map_blend_factor(dst_factor) dst: map_blend_factor(dst_factor),
}, },
VK_BLEND_OP_MIN => pso::BlendOp::Min, VK_BLEND_OP_MIN => pso::BlendOp::Min,
VK_BLEND_OP_MAX => pso::BlendOp::Max, VK_BLEND_OP_MAX => pso::BlendOp::Max,
@ -706,7 +742,7 @@ pub fn map_filter(filter: VkFilter) -> image::Filter {
match filter { match filter {
VkFilter::VK_FILTER_NEAREST => image::Filter::Nearest, VkFilter::VK_FILTER_NEAREST => image::Filter::Nearest,
VkFilter::VK_FILTER_LINEAR => image::Filter::Linear, VkFilter::VK_FILTER_LINEAR => image::Filter::Linear,
_ => panic!("Unsupported filter {:?}", filter) _ => panic!("Unsupported filter {:?}", filter),
} }
} }
@ -714,7 +750,7 @@ pub fn map_mipmap_filter(mode: VkSamplerMipmapMode) -> image::Filter {
match mode { match mode {
VkSamplerMipmapMode::VK_SAMPLER_MIPMAP_MODE_NEAREST => image::Filter::Nearest, VkSamplerMipmapMode::VK_SAMPLER_MIPMAP_MODE_NEAREST => image::Filter::Nearest,
VkSamplerMipmapMode::VK_SAMPLER_MIPMAP_MODE_LINEAR => image::Filter::Linear, VkSamplerMipmapMode::VK_SAMPLER_MIPMAP_MODE_LINEAR => image::Filter::Linear,
_ => panic!("Unsupported mipmap mode {:?}", mode) _ => panic!("Unsupported mipmap mode {:?}", mode),
} }
} }
@ -797,9 +833,9 @@ pub fn map_index_type(ty: VkIndexType) -> IndexType {
pub fn map_query_type(ty: VkQueryType, statistic: VkQueryPipelineStatisticFlags) -> query::Type { pub fn map_query_type(ty: VkQueryType, statistic: VkQueryPipelineStatisticFlags) -> query::Type {
match ty { match ty {
VkQueryType::VK_QUERY_TYPE_OCCLUSION => query::Type::Occlusion, VkQueryType::VK_QUERY_TYPE_OCCLUSION => query::Type::Occlusion,
VkQueryType::VK_QUERY_TYPE_PIPELINE_STATISTICS => query::Type::PipelineStatistics( VkQueryType::VK_QUERY_TYPE_PIPELINE_STATISTICS => {
map_pipeline_statistics(statistic) query::Type::PipelineStatistics(map_pipeline_statistics(statistic))
), }
VkQueryType::VK_QUERY_TYPE_TIMESTAMP => query::Type::Timestamp, VkQueryType::VK_QUERY_TYPE_TIMESTAMP => query::Type::Timestamp,
_ => panic!("Unexpected query type: {:?}", ty), _ => panic!("Unexpected query type: {:?}", ty),
} }

View file

@ -1,17 +1,17 @@
use VK_NULL_HANDLE;
use std::{borrow, cmp, fmt, ops};
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::{borrow, cmp, fmt, ops};
use VK_NULL_HANDLE;
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
use hal::backend::FastHashMap; use hal::backend::FastHashMap;
use copyless::{BoxAllocation, BoxHelper}; use copyless::{BoxAllocation, BoxHelper};
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
lazy_static! { lazy_static! {
static ref REGISTRY: Arc<Mutex<FastHashMap<usize, &'static str>>> = Arc::new(Mutex::new(FastHashMap::default())); static ref REGISTRY: Arc<Mutex<FastHashMap<usize, &'static str>>> =
Arc::new(Mutex::new(FastHashMap::default()));
} }
#[repr(C)] #[repr(C)]
@ -141,9 +141,9 @@ pub type DispatchHandle<T> = Handle<T>;
#[cfg(feature = "dispatch")] #[cfg(feature = "dispatch")]
mod dispatch { mod dispatch {
use VK_NULL_HANDLE;
use copyless::{BoxAllocation, BoxHelper}; use copyless::{BoxAllocation, BoxHelper};
use std::{borrow, cmp, fmt, ops}; use std::{borrow, cmp, fmt, ops};
use VK_NULL_HANDLE;
const ICD_LOADER_MAGIC: u64 = 0x01CDC0DE; const ICD_LOADER_MAGIC: u64 = 0x01CDC0DE;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -7,7 +7,6 @@ use portability_gfx::*;
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
const ICD_VERSION: u32 = 5; const ICD_VERSION: u32 = 5;
#[no_mangle] #[no_mangle]

View file

@ -638,14 +638,7 @@ pub extern "C" fn vkGetQueryPoolResults(
flags: VkQueryResultFlags, flags: VkQueryResultFlags,
) -> VkResult { ) -> VkResult {
gfxGetQueryPoolResults( gfxGetQueryPoolResults(
device, device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags,
queryPool,
firstQuery,
queryCount,
dataSize,
pData,
stride,
flags,
) )
} }
#[no_mangle] #[no_mangle]
@ -1078,7 +1071,13 @@ pub extern "C" fn vkCmdDraw(
firstVertex: u32, firstVertex: u32,
firstInstance: u32, firstInstance: u32,
) { ) {
gfxCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance) gfxCmdDraw(
commandBuffer,
vertexCount,
instanceCount,
firstVertex,
firstInstance,
)
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn vkCmdDrawIndexed( pub extern "C" fn vkCmdDrawIndexed(
@ -1231,13 +1230,7 @@ pub extern "C" fn vkCmdUpdateBuffer(
dataSize: VkDeviceSize, dataSize: VkDeviceSize,
pData: *const ::std::os::raw::c_void, pData: *const ::std::os::raw::c_void,
) { ) {
gfxCmdUpdateBuffer( gfxCmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData)
commandBuffer,
dstBuffer,
dstOffset,
dataSize,
pData,
)
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn vkCmdFillBuffer( pub extern "C" fn vkCmdFillBuffer(
@ -1327,11 +1320,7 @@ pub extern "C" fn vkCmdSetEvent(
event: VkEvent, event: VkEvent,
stageMask: VkPipelineStageFlags, stageMask: VkPipelineStageFlags,
) { ) {
gfxCmdSetEvent( gfxCmdSetEvent(commandBuffer, event, stageMask)
commandBuffer,
event,
stageMask,
)
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn vkCmdResetEvent( pub extern "C" fn vkCmdResetEvent(
@ -1339,11 +1328,7 @@ pub extern "C" fn vkCmdResetEvent(
event: VkEvent, event: VkEvent,
stageMask: VkPipelineStageFlags, stageMask: VkPipelineStageFlags,
) { ) {
gfxCmdResetEvent( gfxCmdResetEvent(commandBuffer, event, stageMask)
commandBuffer,
event,
stageMask,
)
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn vkCmdWaitEvents( pub extern "C" fn vkCmdWaitEvents(
@ -1500,14 +1485,7 @@ pub extern "C" fn vkAcquireNextImageKHR(
fence: VkFence, fence: VkFence,
pImageIndex: *mut u32, pImageIndex: *mut u32,
) -> VkResult { ) -> VkResult {
gfxAcquireNextImageKHR( gfxAcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex)
device,
swapchain,
timeout,
semaphore,
fence,
pImageIndex,
)
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn vkQueuePresentKHR( pub extern "C" fn vkQueuePresentKHR(