@@ -14,13 +14,11 @@ use hal::{
14
14
use std:: {
15
15
borrow:: Cow ,
16
16
ffi:: { CStr , CString } ,
17
- os:: raw:: c_int,
17
+ os:: raw:: { c_int, c_void } ,
18
18
mem, ptr, str,
19
19
} ;
20
20
#[ cfg( feature = "gfx-backend-metal" ) ]
21
21
use std:: env;
22
- #[ cfg( feature = "renderdoc" ) ]
23
- use std:: os:: raw:: c_void;
24
22
25
23
use super :: * ;
26
24
@@ -64,6 +62,16 @@ pub extern "C" fn gfxCreateInstance(
64
62
#[ cfg( feature = "env_logger" ) ]
65
63
{
66
64
let _ = env_logger:: try_init ( ) ;
65
+ let backend = if cfg ! ( feature = "gfx-backend-vulkan" ) {
66
+ "Vulkan"
67
+ } else if cfg ! ( feature = "gfx-backend-dx12" ) {
68
+ "DX12"
69
+ } else if cfg ! ( feature = "gfx-backend-metal" ) {
70
+ "Metal"
71
+ } else {
72
+ "Other"
73
+ } ;
74
+ println ! ( "gfx-portability backend: {}" , backend) ;
67
75
}
68
76
69
77
#[ allow( unused_mut) ]
@@ -275,7 +283,7 @@ pub extern "C" fn gfxGetPhysicalDeviceFeatures2KHR(
275
283
other => {
276
284
warn ! ( "Unrecognized {:?}, skipping" , other) ;
277
285
unsafe {
278
- ( ptr as * const VkPhysicalDeviceFeatures2KHR )
286
+ ( ptr as * const VkBaseStruct )
279
287
. as_ref ( )
280
288
. unwrap ( )
281
289
}
@@ -385,7 +393,7 @@ pub extern "C" fn gfxGetPhysicalDeviceImageFormatProperties2KHR(
385
393
other => {
386
394
warn ! ( "Unrecognized {:?}, skipping" , other) ;
387
395
unsafe {
388
- ( ptr as * const VkPhysicalDeviceImageFormatInfo2KHR )
396
+ ( ptr as * const VkBaseStruct )
389
397
. as_ref ( )
390
398
. unwrap ( )
391
399
}
@@ -470,7 +478,7 @@ pub extern "C" fn gfxGetPhysicalDeviceProperties2KHR(
470
478
other => {
471
479
warn ! ( "Unrecognized {:?}, skipping" , other) ;
472
480
unsafe {
473
- ( ptr as * const VkPhysicalDeviceProperties2KHR ) . as_ref ( ) . unwrap ( )
481
+ ( ptr as * const VkBaseStruct ) . as_ref ( ) . unwrap ( )
474
482
} . pNext
475
483
}
476
484
} as * const VkStructureType ;
@@ -544,7 +552,9 @@ pub extern "C" fn gfxGetInstanceProcAddr(
544
552
545
553
vkGetPhysicalDeviceSurfaceSupportKHR, PFN_vkGetPhysicalDeviceSurfaceSupportKHR => gfxGetPhysicalDeviceSurfaceSupportKHR,
546
554
vkGetPhysicalDeviceSurfaceCapabilitiesKHR, PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR => gfxGetPhysicalDeviceSurfaceCapabilitiesKHR,
555
+ vkGetPhysicalDeviceSurfaceCapabilities2KHR, PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR => gfxGetPhysicalDeviceSurfaceCapabilities2KHR,
547
556
vkGetPhysicalDeviceSurfaceFormatsKHR, PFN_vkGetPhysicalDeviceSurfaceFormatsKHR => gfxGetPhysicalDeviceSurfaceFormatsKHR,
557
+ vkGetPhysicalDeviceSurfaceFormats2KHR, PFN_vkGetPhysicalDeviceSurfaceFormats2KHR => gfxGetPhysicalDeviceSurfaceFormats2KHR,
548
558
vkGetPhysicalDeviceSurfacePresentModesKHR, PFN_vkGetPhysicalDeviceSurfacePresentModesKHR => gfxGetPhysicalDeviceSurfacePresentModesKHR,
549
559
vkGetPhysicalDeviceWin32PresentationSupportKHR, PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR => gfxGetPhysicalDeviceWin32PresentationSupportKHR,
550
560
@@ -961,6 +971,7 @@ lazy_static! {
961
971
#[ cfg( target_os="macos" ) ]
962
972
VK_MVK_MACOS_SURFACE_EXTENSION_NAME ,
963
973
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME ,
974
+ VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME ,
964
975
]
965
976
} ;
966
977
@@ -1272,7 +1283,7 @@ pub extern "C" fn gfxMapMemory(
1272
1283
offset : VkDeviceSize ,
1273
1284
size : VkDeviceSize ,
1274
1285
_flags : VkMemoryMapFlags ,
1275
- ppData : * mut * mut :: std :: os :: raw :: c_void ,
1286
+ ppData : * mut * mut c_void ,
1276
1287
) -> VkResult {
1277
1288
let range = hal:: memory:: Segment {
1278
1289
offset,
@@ -1422,7 +1433,7 @@ pub extern "C" fn gfxGetImageMemoryRequirements2KHR(
1422
1433
other => {
1423
1434
warn!("Unrecognized {:?}, skipping", other);
1424
1435
unsafe {
1425
- (ptr as *const VkMemoryRequirements2KHR ).as_ref().unwrap()
1436
+ (ptr as *const VkBaseStruct ).as_ref().unwrap()
1426
1437
}.pNext
1427
1438
}
1428
1439
} as *const VkStructureType;
@@ -1691,7 +1702,7 @@ pub extern "C" fn gfxGetQueryPoolResults(
1691
1702
firstQuery : u32 ,
1692
1703
queryCount : u32 ,
1693
1704
dataSize : usize ,
1694
- pData : * mut :: std :: os :: raw :: c_void ,
1705
+ pData : * mut c_void ,
1695
1706
stride : VkDeviceSize ,
1696
1707
flags : VkQueryResultFlags ,
1697
1708
) -> VkResult {
@@ -1988,7 +1999,7 @@ pub extern "C" fn gfxGetPipelineCacheData(
1988
1999
_gpu : VkDevice ,
1989
2000
_pipelineCache : VkPipelineCache ,
1990
2001
pDataSize : * mut usize ,
1991
- _pData : * mut :: std :: os :: raw :: c_void ,
2002
+ _pData : * mut c_void ,
1992
2003
) -> VkResult {
1993
2004
//TODO: save
1994
2005
unsafe {
@@ -2982,11 +2993,22 @@ impl<'a> Iterator for DescriptorIter<'a> {
2982
2993
pso:: DescriptorType :: Image {
2983
2994
ty : pso:: ImageDescriptorType :: Sampled { with_sampler : true } ,
2984
2995
} => self . image_infos . next ( ) . map ( |image| {
2985
- pso:: Descriptor :: CombinedImageSampler (
2986
- image. imageView . to_native ( ) . unwrap ( ) ,
2987
- conv:: map_image_layout ( image. imageLayout ) ,
2988
- & * image. sampler ,
2989
- )
2996
+ // It is valid for the sampler to be NULL in case the descriptor is
2997
+ // actually associated with an immutable sampler.
2998
+ // It's still bad to try to derefence it, even theough the implementation
2999
+ // will not try to use the value. (TODO: make this nicer)
3000
+ if image. sampler != Handle :: null ( ) {
3001
+ pso:: Descriptor :: CombinedImageSampler (
3002
+ image. imageView . to_native ( ) . unwrap ( ) ,
3003
+ conv:: map_image_layout ( image. imageLayout ) ,
3004
+ & * image. sampler ,
3005
+ )
3006
+ } else {
3007
+ pso:: Descriptor :: Image (
3008
+ image. imageView . to_native ( ) . unwrap ( ) ,
3009
+ conv:: map_image_layout ( image. imageLayout ) ,
3010
+ )
3011
+ }
2990
3012
} ) ,
2991
3013
2992
3014
pso:: DescriptorType :: InputAttachment | pso:: DescriptorType :: Image { .. } => {
@@ -3805,8 +3827,20 @@ pub extern "C" fn gfxCmdBlitImage(
3805
3827
pRegions : * const VkImageBlit ,
3806
3828
filter : VkFilter ,
3807
3829
) {
3808
- let src = srcImage. to_native ( ) . unwrap ( ) ;
3809
- let dst = dstImage. to_native ( ) . unwrap ( ) ;
3830
+ let src = match srcImage. to_native ( ) {
3831
+ Ok ( img) => img,
3832
+ Err ( _) => {
3833
+ warn ! ( "Unable to copy from a swapchain image!" ) ;
3834
+ return ;
3835
+ }
3836
+ } ;
3837
+ let dst = match dstImage. to_native ( ) {
3838
+ Ok ( img) => img,
3839
+ Err ( _) => {
3840
+ warn ! ( "Unable to copy into a swapchain image!" ) ;
3841
+ return ;
3842
+ }
3843
+ } ;
3810
3844
3811
3845
let regions = unsafe { slice:: from_raw_parts ( pRegions, regionCount as _ ) }
3812
3846
. iter ( )
@@ -3896,7 +3930,7 @@ pub extern "C" fn gfxCmdUpdateBuffer(
3896
3930
dstBuffer : VkBuffer ,
3897
3931
dstOffset : VkDeviceSize ,
3898
3932
dataSize : VkDeviceSize ,
3899
- pData : * const :: std :: os :: raw :: c_void ,
3933
+ pData : * const c_void ,
3900
3934
) {
3901
3935
unsafe {
3902
3936
commandBuffer. update_buffer (
@@ -4277,7 +4311,7 @@ pub extern "C" fn gfxCmdPushConstants(
4277
4311
stageFlags : VkShaderStageFlags ,
4278
4312
offset : u32 ,
4279
4313
size : u32 ,
4280
- pValues : * const :: std :: os :: raw :: c_void ,
4314
+ pValues : * const c_void ,
4281
4315
) {
4282
4316
assert_eq ! ( size % 4 , 0 ) ;
4283
4317
unsafe {
@@ -4415,6 +4449,35 @@ pub extern "C" fn gfxGetPhysicalDeviceSurfaceCapabilitiesKHR(
4415
4449
VkResult :: VK_SUCCESS
4416
4450
}
4417
4451
4452
+ #[ inline]
4453
+ pub extern "C" fn gfxGetPhysicalDeviceSurfaceCapabilities2KHR (
4454
+ adapter : VkPhysicalDevice ,
4455
+ pSurfaceInfo : * const VkPhysicalDeviceSurfaceInfo2KHR ,
4456
+ pSurfaceCapabilities : * mut VkSurfaceCapabilities2KHR ,
4457
+ ) -> VkResult {
4458
+ let surface = unsafe { ( * pSurfaceInfo) . surface } ;
4459
+ let mut ptr = pSurfaceCapabilities as * const VkStructureType ;
4460
+ while !ptr. is_null ( ) {
4461
+ ptr = match unsafe { * ptr } {
4462
+ VkStructureType :: VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR => {
4463
+ let data = unsafe { ( ptr as * mut VkSurfaceCapabilities2KHR ) . as_mut ( ) . unwrap ( ) } ;
4464
+ gfxGetPhysicalDeviceSurfaceCapabilitiesKHR ( adapter, surface, & mut data. surfaceCapabilities ) ;
4465
+ data. pNext
4466
+ }
4467
+ other => {
4468
+ warn ! ( "Unrecognized {:?}, skipping" , other) ;
4469
+ unsafe {
4470
+ ( ptr as * const VkBaseStruct )
4471
+ . as_ref ( )
4472
+ . unwrap ( )
4473
+ }
4474
+ . pNext
4475
+ }
4476
+ } as * const VkStructureType ;
4477
+ }
4478
+ VkResult :: VK_SUCCESS
4479
+ }
4480
+
4418
4481
#[ inline]
4419
4482
pub extern "C" fn gfxGetPhysicalDeviceSurfaceFormatsKHR (
4420
4483
adapter : VkPhysicalDevice ,
@@ -4447,6 +4510,38 @@ pub extern "C" fn gfxGetPhysicalDeviceSurfaceFormatsKHR(
4447
4510
VkResult :: VK_SUCCESS
4448
4511
}
4449
4512
4513
+ #[ inline]
4514
+ pub extern "C" fn gfxGetPhysicalDeviceSurfaceFormats2KHR (
4515
+ adapter : VkPhysicalDevice ,
4516
+ pSurfaceInfo : * const VkPhysicalDeviceSurfaceInfo2KHR ,
4517
+ pSurfaceFormatCount : * mut u32 ,
4518
+ pSurfaceFormats : * mut VkSurfaceFormat2KHR ,
4519
+ ) -> VkResult {
4520
+ let formats = unsafe { ( * pSurfaceInfo) . surface }
4521
+ . supported_formats ( & adapter. physical_device )
4522
+ . map ( |formats| formats. into_iter ( ) . map ( conv:: format_from_hal) . collect ( ) )
4523
+ . unwrap_or ( vec ! [ VkFormat :: VK_FORMAT_UNDEFINED ] ) ;
4524
+
4525
+ if pSurfaceFormats. is_null ( ) {
4526
+ // Return only the number of formats
4527
+ unsafe { * pSurfaceFormatCount = formats. len ( ) as u32 } ;
4528
+ } else {
4529
+ let output =
4530
+ unsafe { slice:: from_raw_parts_mut ( pSurfaceFormats, * pSurfaceFormatCount as usize ) } ;
4531
+ if output. len ( ) > formats. len ( ) {
4532
+ unsafe { * pSurfaceFormatCount = formats. len ( ) as u32 } ;
4533
+ }
4534
+ for ( out, format) in output. iter_mut ( ) . zip ( formats) {
4535
+ out. surfaceFormat = VkSurfaceFormatKHR {
4536
+ format,
4537
+ colorSpace : VkColorSpaceKHR :: VK_COLOR_SPACE_SRGB_NONLINEAR_KHR , //TODO
4538
+ } ;
4539
+ }
4540
+ }
4541
+
4542
+ VkResult :: VK_SUCCESS
4543
+ }
4544
+
4450
4545
#[ inline]
4451
4546
pub extern "C" fn gfxGetPhysicalDeviceSurfacePresentModesKHR (
4452
4547
adapter : VkPhysicalDevice ,
0 commit comments