From 2fcc5636bf5cca4005d3d2fefd11c0a5b16e2d1b Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Wed, 28 Oct 2020 23:12:28 -0400 Subject: [PATCH] Update gfx with swapchain readback support --- Cargo.lock | 148 +++++++++++++++++--------------- Makefile | 12 +-- libportability-gfx/Cargo.toml | 1 - libportability-gfx/src/conv.rs | 12 ++- libportability-gfx/src/impls.rs | 38 ++++---- libportability-gfx/src/lib.rs | 18 ++-- libportability-icd/src/lib.rs | 5 +- native/test.cpp | 4 +- 8 files changed, 125 insertions(+), 113 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 81ef15f..0a2ed4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,9 +2,9 @@ # It is not intended for manual editing. [[package]] name = "aho-corasick" -version = "0.7.13" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" +checksum = "b476ce7103678b0c6d3d395dbbae31d48ff910bd28be979ba5d48c6351131d0d" dependencies = [ "memchr", ] @@ -17,9 +17,9 @@ checksum = "000444226fcff248f2bc4c7625be32c63caccfecc2723a2b9f78a7487a49c407" [[package]] name = "arrayvec" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "ash" @@ -41,6 +41,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "bit-set" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3" + [[package]] name = "bitflags" version = "1.2.1" @@ -67,9 +82,9 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" [[package]] name = "cc" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef611cc68ff783f18535d77ddd080185275713d852c4f5cbb6122c462a7a825c" +checksum = "ed67cbde08356238e75fc4656be4749481eeffb09e19f320a25237d5221c985d" dependencies = [ "jobserver", ] @@ -80,6 +95,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "cgl" version = "0.2.3" @@ -149,7 +170,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" dependencies = [ - "core-foundation-sys 0.8.1", + "core-foundation-sys 0.8.2", "libc", ] @@ -164,9 +185,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0af3b5e4601de3837c9332e29e0aae47a0d46ebfa246d12b82f564bac233393" +checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" [[package]] name = "core-graphics" @@ -255,7 +276,7 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "wasi", ] @@ -263,7 +284,7 @@ dependencies = [ [[package]] name = "gfx-auxil" version = "0.5.0" -source = "git+https://github.com/gfx-rs/gfx#c3df31f6f4ee089d576b52550dfbba11a70c1a68" +source = "git+https://github.com/gfx-rs/gfx#17249afe4c3b219200abb3a5c979984bdcb4a640" dependencies = [ "fxhash", "gfx-hal", @@ -273,8 +294,9 @@ dependencies = [ [[package]] name = "gfx-backend-dx11" version = "0.6.0" -source = "git+https://github.com/gfx-rs/gfx#c3df31f6f4ee089d576b52550dfbba11a70c1a68" +source = "git+https://github.com/gfx-rs/gfx#17249afe4c3b219200abb3a5c979984bdcb4a640" dependencies = [ + "arrayvec", "bitflags", "gfx-auxil", "gfx-hal", @@ -285,6 +307,7 @@ dependencies = [ "raw-window-handle", "smallvec", "spirv_cross", + "thunderdome", "winapi", "wio", ] @@ -292,13 +315,16 @@ dependencies = [ [[package]] name = "gfx-backend-dx12" version = "0.6.2" -source = "git+https://github.com/gfx-rs/gfx#c3df31f6f4ee089d576b52550dfbba11a70c1a68" +source = "git+https://github.com/gfx-rs/gfx#17249afe4c3b219200abb3a5c979984bdcb4a640" dependencies = [ + "arrayvec", + "bit-set", "bitflags", "d3d12", "gfx-auxil", "gfx-hal", "log", + "parking_lot", "range-alloc", "raw-window-handle", "smallvec", @@ -309,7 +335,7 @@ dependencies = [ [[package]] name = "gfx-backend-empty" version = "0.6.0" -source = "git+https://github.com/gfx-rs/gfx#c3df31f6f4ee089d576b52550dfbba11a70c1a68" +source = "git+https://github.com/gfx-rs/gfx#17249afe4c3b219200abb3a5c979984bdcb4a640" dependencies = [ "gfx-hal", "log", @@ -319,7 +345,7 @@ dependencies = [ [[package]] name = "gfx-backend-metal" version = "0.6.0" -source = "git+https://github.com/gfx-rs/gfx#c3df31f6f4ee089d576b52550dfbba11a70c1a68" +source = "git+https://github.com/gfx-rs/gfx#17249afe4c3b219200abb3a5c979984bdcb4a640" dependencies = [ "arrayvec", "bitflags", @@ -342,8 +368,8 @@ dependencies = [ [[package]] name = "gfx-backend-vulkan" -version = "0.6.1" -source = "git+https://github.com/gfx-rs/gfx#c3df31f6f4ee089d576b52550dfbba11a70c1a68" +version = "0.6.5" +source = "git+https://github.com/gfx-rs/gfx#17249afe4c3b219200abb3a5c979984bdcb4a640" dependencies = [ "arrayvec", "ash", @@ -357,14 +383,12 @@ dependencies = [ "raw-window-handle", "smallvec", "winapi", - "x11", - "xcb", ] [[package]] name = "gfx-hal" version = "0.6.0" -source = "git+https://github.com/gfx-rs/gfx#c3df31f6f4ee089d576b52550dfbba11a70c1a68" +source = "git+https://github.com/gfx-rs/gfx#17249afe4c3b219200abb3a5c979984bdcb4a640" dependencies = [ "bitflags", "raw-window-handle", @@ -426,9 +450,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c30f6d0bc6b00693347368a67d41b58f2fb851215ff1da49e90fe2c5c667151" +checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" dependencies = [ "libc", ] @@ -450,11 +474,11 @@ checksum = "dd01a2a73f2f399df96b22dc88ea687ef4d76226284e7531ae3c7ee1dc5cb534" [[package]] name = "instant" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63312a18f7ea8760cdd0a7c5aac1a619752a246b833545e3e36d1f81f7cd9e66" +checksum = "cb1fc4429a33e1f80d41dc9fea4d108a88bec1de8053878898ae448a0b52f613" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -501,17 +525,17 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.77" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235" +checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" [[package]] name = "libloading" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2443d8f0478b16759158b2f66d525991a05491138bc05814ef52a250148ef4f9" +checksum = "1090080fe06ec2648d0da3881d9453d97e71a45f00eb179af7fdd7e3f686fdb0" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "winapi", ] @@ -530,7 +554,7 @@ version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", ] [[package]] @@ -550,9 +574,9 @@ checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" [[package]] name = "memchr" -version = "2.3.3" +version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] name = "memmap" @@ -623,7 +647,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "cloudabi", "instant", "libc", @@ -640,9 +664,9 @@ checksum = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" [[package]] name = "pkg-config" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "portability" @@ -687,9 +711,9 @@ checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" [[package]] name = "proc-macro2" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51ef7cd2518ead700af67bf9d1a658d90b6037d77110fd9c0445429d0ba1c6c9" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" dependencies = [ "unicode-xid", ] @@ -753,7 +777,7 @@ dependencies = [ [[package]] name = "range-alloc" version = "0.1.1" -source = "git+https://github.com/gfx-rs/gfx#c3df31f6f4ee089d576b52550dfbba11a70c1a68" +source = "git+https://github.com/gfx-rs/gfx#17249afe4c3b219200abb3a5c979984bdcb4a640" [[package]] name = "raw-window-handle" @@ -772,9 +796,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "regex" -version = "1.3.9" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" +checksum = "8963b85b8ce3074fecffde43b4b0dded83ce2f367dc8d363afc56679f3ee820b" dependencies = [ "aho-corasick", "memchr", @@ -784,9 +808,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" +checksum = "8cab7a364d15cde1e505267766a2d3c4e22a843e1a601f0fa7564c0f82ced11c" [[package]] name = "remove_dir_all" @@ -835,9 +859,9 @@ checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" [[package]] name = "spirv_cross" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b631bd956108f3e34a4fb7e39621711ac15ce022bc567da2d953c6df13f00e00" +checksum = "d8221f4aebf53a4447aebd4fe29ebff2c66dd2c2821e63675e09e85bd21c8633" dependencies = [ "cc", "js-sys", @@ -855,9 +879,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.42" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c51d92969d209b54a98397e1b91c8ae82d8c87a7bb87df0b29aa2ad81454228" +checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac" dependencies = [ "proc-macro2", "quote", @@ -870,7 +894,7 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "rand", "redox_syscall", @@ -896,6 +920,12 @@ dependencies = [ "lazy_static 1.4.0", ] +[[package]] +name = "thunderdome" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7572415bd688d401c52f6e36f4c8e805b9ae1622619303b9fa835d531db0acae" + [[package]] name = "token_store" version = "0.1.2" @@ -926,7 +956,7 @@ version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "wasm-bindgen-macro", ] @@ -1105,16 +1135,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "x11" -version = "2.18.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ecd092546cb16f25783a5451538e73afc8d32e242648d54f4ae5459ba1e773" -dependencies = [ - "libc", - "pkg-config", -] - [[package]] name = "x11-dl" version = "2.18.5" @@ -1127,16 +1147,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "xcb" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62056f63138b39116f82a540c983cc11f1c90cd70b3d492a70c25eaa50bd22a6" -dependencies = [ - "libc", - "log", -] - [[package]] name = "xml-rs" version = "0.7.0" diff --git a/Makefile b/Makefile index 0f8066a..c5598c0 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ CTS_DIR=../VK-GL-CTS CHERRY_DIR=../cherry BINDING=target/vulkan.rs +LIB_FILE_NAME= +LIB_VULKAN_NAME= NATIVE_DIR=target/native NATIVE_TARGET=$(NATIVE_DIR)/test NATIVE_OBJECTS=$(NATIVE_DIR)/test.o $(NATIVE_DIR)/window.o -LIB_FILE_NAME= -LIB_VULKAN_NAME= TEST_LIST=$(CURDIR)/conformance/deqp.txt TEST_LIST_SOURCE=$(CTS_DIR)/external/vulkancts/mustpass/1.0.2/vk-default.txt DEQP_DIR=$(CTS_DIR)/build/external/vulkancts/modules/vulkan/ @@ -18,7 +18,7 @@ ZIP_COMMAND= DOTA_DIR=../dota2/bin/osx64 DOTA_EXE=$(DOTA_DIR)/dota2.app/Contents/MacOS/dota2 #possible command lines are : -vulkan_disable_occlusion_queries -vulkan_scene_system_job_cost 2 +vulkan_batch_submits 1 +vulkan_batch_size 500 -DOTA_PARAMS:=-vulkan_disable_occlusion_queries +DOTA_PARAMS:=-vulkan -vulkan_disable_occlusion_queries -vulkan_descriptor_sets_per_pool 256 DOTA_DEMO_PHORONIX= "$(CURDIR)/../dota2/demos/dota2-pts-1971360796.dem" DOTA_BENCHMARK=+timedemoquit +timedemo $(DOTA_DEMO_PHORONIX) +timedemo_start 40000 +timedemo_end 50000 +fps_max 0 -novconsole -high -autoconfig_level 3 DOTA_BENCH_RESULTS=../dota2/dota/Source2Bench.csv @@ -135,15 +135,15 @@ $(BINDING): headers/vulkan/*.h bindgen --no-layout-tests --rustfmt-bindings headers/vulkan/vulkan.h -o $(BINDING) $(LIBRARY): dummy - cargo build --manifest-path libportability/Cargo.toml --features $(BACKEND) - cargo build --manifest-path libportability-icd/Cargo.toml --features $(BACKEND),portability-gfx/env_logger - mkdir -p target/native + cargo build --manifest-path libportability/Cargo.toml --features $(BACKEND),debug + cargo build --manifest-path libportability-icd/Cargo.toml --features $(BACKEND),debug $(LIBRARY_FAST): dummy cargo build --release --manifest-path libportability/Cargo.toml --features $(BACKEND) cargo build --release --manifest-path libportability-icd/Cargo.toml --features $(BACKEND) $(NATIVE_DIR)/%.o: native/%.cpp $(DEPS) Makefile + -mkdir $(NATIVE_DIR) $(CC) -c -o $@ $< $(CFLAGS) $(NATIVE_TARGET): $(LIBRARY) $(NATIVE_OBJECTS) Makefile diff --git a/libportability-gfx/Cargo.toml b/libportability-gfx/Cargo.toml index 7a7e836..fbfd232 100644 --- a/libportability-gfx/Cargo.toml +++ b/libportability-gfx/Cargo.toml @@ -38,7 +38,6 @@ git = "https://github.com/gfx-rs/gfx" #path = "../../gfx/src/backend/empty" [target.'cfg(not(any(target_os = "macos", target_os = "ios")))'.dependencies.gfx-backend-vulkan] -features = ["x11", "xcb"] git = "https://github.com/gfx-rs/gfx" #path = "../../gfx/src/backend/vulkan" optional = true diff --git a/libportability-gfx/src/conv.rs b/libportability-gfx/src/conv.rs index 3d74201..a94d658 100644 --- a/libportability-gfx/src/conv.rs +++ b/libportability-gfx/src/conv.rs @@ -422,7 +422,7 @@ pub fn map_image_usage(usage: VkImageUsageFlags) -> image::Usage { image::Usage::from_bits_truncate(usage) } -pub fn _map_image_usage_from_hal(usage: image::Usage) -> VkImageUsageFlags { +pub fn map_image_usage_from_hal(usage: image::Usage) -> VkImageUsageFlags { usage.bits() } @@ -568,6 +568,16 @@ pub fn memory_properties_from_hal(properties: memory::Properties) -> VkMemoryPro flags } +pub fn memory_heap_flags_from_hal(hal_flags: memory::HeapFlags) -> VkMemoryHeapFlags { + let mut flags = 0; + + if hal_flags.contains(memory::HeapFlags::DEVICE_LOCAL) { + flags |= VkMemoryHeapFlagBits::VK_MEMORY_HEAP_DEVICE_LOCAL_BIT as u32; + } + + flags +} + pub fn map_descriptor_type(ty: VkDescriptorType) -> pso::DescriptorType { use super::VkDescriptorType::*; diff --git a/libportability-gfx/src/impls.rs b/libportability-gfx/src/impls.rs index dd4e3db..1a845db 100644 --- a/libportability-gfx/src/impls.rs +++ b/libportability-gfx/src/impls.rs @@ -498,19 +498,20 @@ pub unsafe extern "C" fn gfxGetPhysicalDeviceMemoryProperties( let num_types = properties.memory_types.len(); memory_properties.memoryTypeCount = num_types as _; for i in 0..num_types { - let flags = conv::memory_properties_from_hal(properties.memory_types[i].properties); + let ty = &properties.memory_types[i]; memory_properties.memoryTypes[i] = VkMemoryType { - propertyFlags: flags, // propertyFlags - heapIndex: properties.memory_types[i].heap_index as _, + propertyFlags: conv::memory_properties_from_hal(ty.properties), + heapIndex: ty.heap_index as _, }; } let num_heaps = properties.memory_heaps.len(); memory_properties.memoryHeapCount = num_heaps as _; for i in 0..num_heaps { + let heap = &properties.memory_heaps[i]; memory_properties.memoryHeaps[i] = VkMemoryHeap { - size: properties.memory_heaps[i], - flags: 0, // TODO + size: heap.size, + flags: conv::memory_heap_flags_from_hal(heap.flags), }; } } @@ -1826,7 +1827,7 @@ pub unsafe extern "C" fn gfxCreateImage( kind, info.mipLevels as _, conv::map_format(info.format) - .expect(&format!("Unsupported image format: {:?}", info.format)), + .unwrap_or_else(|| panic!("Unsupported image format: {:?}", info.format)), conv::map_tiling(info.tiling), conv::map_image_usage(info.usage), conv::map_image_create_flags(info.flags), @@ -4274,8 +4275,7 @@ pub unsafe extern "C" fn gfxGetPhysicalDeviceSurfaceCapabilitiesKHR( as _, currentTransform: VkSurfaceTransformFlagBitsKHR::VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR, supportedCompositeAlpha: caps.composite_alpha_modes.bits(), - // Ignoring `caps.usage` since we only work with the new swapchain model here. - supportedUsageFlags: VkImageUsageFlagBits::VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT as _, + supportedUsageFlags: conv::map_image_usage_from_hal(caps.usage), }; *pSurfaceCapabilities = output; @@ -4428,16 +4428,14 @@ pub unsafe extern "C" fn gfxCreateSwapchainKHR( ) -> VkResult { let info = &*pCreateInfo; // TODO: more checks - assert_eq!(info.clipped, VK_TRUE); // TODO + if info.clipped == 0 { + warn!("Non-clipped swapchain requested"); + } assert_eq!( info.imageSharingMode, VkSharingMode::VK_SHARING_MODE_EXCLUSIVE ); // TODO - if info.imageUsage != VkImageUsageFlagBits::VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT as _ { - warn!("Unsupported swapchain usage: {:?}", info.imageUsage); - } - let config = hal::window::SwapchainConfig { present_mode: conv::map_present_mode(info.presentMode), composite_alpha_mode: conv::map_composite_alpha(info.compositeAlpha), @@ -4455,12 +4453,13 @@ pub unsafe extern "C" fn gfxCreateSwapchainKHR( .configure_swapchain(&gpu.device, config) { Ok(()) => { + let count = info.minImageCount; let swapchain = Swapchain { gpu, surface: info.surface, - count: info.minImageCount, + count, current_index: 0, - active: Vec::new(), + active: (0 .. count).map(|_| None).collect(), lazy_framebuffers: Mutex::new(Vec::with_capacity(1)), }; *pSwapchain = Handle::new(swapchain); @@ -4746,7 +4745,7 @@ pub unsafe extern "C" fn gfxAcquireNextImageKHR( match swapchain.surface.acquire_image(timeout) { Ok((frame, suboptimal)) => { let index = (swapchain.current_index + 1) % swapchain.count; - swapchain.active.push((index, frame)); + swapchain.active[index as usize] = Some(frame); *pImageIndex = index; swapchain.current_index = index; match suboptimal { @@ -4781,12 +4780,9 @@ pub unsafe extern "C" fn gfxQueuePresentKHR( for (swapchain, &index) in swapchain_slice.iter().zip(index_slice) { let sc = swapchain.as_mut().unwrap(); - let active_pos = sc - .active - .iter() - .position(|&(frame, _)| frame == index) + let frame = sc.active[index as usize] + .take() .expect("Frame was not acquired properly!"); - let (_, frame) = sc.active.swap_remove(active_pos); let sem = wait_semaphores.first().map(|s| &s.raw); if let Err(_) = queue.present(&mut *sc.surface, frame, sem) { return VkResult::VK_ERROR_SURFACE_LOST_KHR; diff --git a/libportability-gfx/src/lib.rs b/libportability-gfx/src/lib.rs index a8a7365..120f242 100644 --- a/libportability-gfx/src/lib.rs +++ b/libportability-gfx/src/lib.rs @@ -124,11 +124,14 @@ pub enum Image { #[derive(Debug)] struct UnexpectedSwapchainImage; -impl Image { - fn as_native(&self) -> Result<&B::Image, UnexpectedSwapchainImage> { +impl Image { + fn as_native(&self) -> Result<&::Image, UnexpectedSwapchainImage> { + //use std::borrow::Borrow; match *self { Image::Native { ref raw } => Ok(raw), Image::SwapchainFrame { .. } => Err(UnexpectedSwapchainImage), + //Image::SwapchainFrame { ref swapchain, frame } => + // Ok(swapchain.active[frame as usize].as_ref().unwrap().borrow()), } } } @@ -195,11 +198,9 @@ impl Framebuffer { } => { use std::borrow::Borrow; swapchain - .active - .iter() - .find(|&&(index, _)| index == frame) + .active[frame as usize] + .as_ref() .expect("Swapchain frame isn't acquired") - .1 .borrow() } }); @@ -249,10 +250,7 @@ pub struct Swapchain { surface: VkSurfaceKHR, count: hal::window::SwapImageIndex, current_index: hal::window::SwapImageIndex, - active: Vec<( - hal::window::SwapImageIndex, - >::SwapchainImage, - )>, + active: Vec>::SwapchainImage>>, lazy_framebuffers: parking_lot::Mutex::Framebuffer>>, } diff --git a/libportability-icd/src/lib.rs b/libportability-icd/src/lib.rs index e675a1a..0061fde 100644 --- a/libportability-icd/src/lib.rs +++ b/libportability-icd/src/lib.rs @@ -19,9 +19,8 @@ pub unsafe extern "C" fn vk_icdGetInstanceProcAddr( pub unsafe extern "C" fn vk_icdNegotiateLoaderICDInterfaceVersion( pSupportedVersion: *mut ::std::os::raw::c_uint, ) -> VkResult { - let supported_version = &mut *pSupportedVersion; - if *supported_version > ICD_VERSION { - *supported_version = ICD_VERSION; + if *pSupportedVersion > ICD_VERSION { + *pSupportedVersion = ICD_VERSION; } VkResult::VK_SUCCESS diff --git a/native/test.cpp b/native/test.cpp index 47ff0bc..e9effb2 100644 --- a/native/test.cpp +++ b/native/test.cpp @@ -381,8 +381,8 @@ int main() { vkGetImageMemoryRequirements(device, depth_image, &mem_reqs); printf("\tvkGetImageMemoryRequirements\n"); printf( - "\t\tsize: %llx\n" - "\t\talignment: %llx\n" + "\t\tsize: %zx\n" + "\t\talignment: %zx\n" "\t\tmemoryTypeBits: %x\n", mem_reqs.size, mem_reqs.alignment,