From c8eaeb0dc7f046685c55e9dcbc8a228b261e0cac Mon Sep 17 00:00:00 2001 From: Dominik Witczak Date: Fri, 27 Apr 2018 14:17:53 +0200 Subject: [PATCH] Bug-fixes & improvements --- include/misc/extensions.h | 48 +++++++++++++------- include/misc/external_handle.h | 16 ++++++- include/misc/graphics_pipeline_create_info.h | 3 -- include/misc/types.h | 4 +- include/misc/types_enums.h | 16 +++++-- include/wrappers/fence.h | 3 -- include/wrappers/queue.h | 2 + src/wrappers/fence.cpp | 9 +--- src/wrappers/instance.cpp | 20 +++++--- src/wrappers/queue.cpp | 9 ++++ 10 files changed, 85 insertions(+), 45 deletions(-) diff --git a/include/misc/extensions.h b/include/misc/extensions.h index 8185a5ab..4ade1132 100644 --- a/include/misc/extensions.h +++ b/include/misc/extensions.h @@ -164,9 +164,13 @@ namespace Anvil ValueType khr_surface; #ifdef _WIN32 - ValueType khr_win32_surface; + #if defined(ANVIL_INCLUDE_WIN3264_WINDOW_SYSTEM_SUPPORT) + ValueType khr_win32_surface; + #endif #else - ValueType khr_xcb_surface; + #if defined(ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT) + ValueType khr_xcb_surface; + #endif #endif std::map values_by_extension_names; @@ -198,9 +202,13 @@ namespace Anvil {ExtensionData(VK_KHR_SURFACE_EXTENSION_NAME, &khr_surface)}, #ifdef _WIN32 - {ExtensionData(VK_KHR_WIN32_SURFACE_EXTENSION_NAME, &khr_win32_surface)}, + #if defined(ANVIL_INCLUDE_WIN3264_WINDOW_SYSTEM_SUPPORT) + {ExtensionData(VK_KHR_WIN32_SURFACE_EXTENSION_NAME, &khr_win32_surface)}, + #endif #else - {ExtensionData(VK_KHR_XCB_SURFACE_EXTENSION_NAME, &khr_xcb_surface)}, + #if defined(ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT) + {ExtensionData(VK_KHR_XCB_SURFACE_EXTENSION_NAME, &khr_xcb_surface)}, + #endif #endif }; @@ -291,9 +299,13 @@ namespace Anvil virtual bool khr_surface () const = 0; #ifdef _WIN32 - virtual bool khr_win32_surface() const = 0; + #if defined(ANVIL_INCLUDE_WIN3264_WINDOW_SYSTEM_SUPPORT) + virtual bool khr_win32_surface() const = 0; + #endif #else - virtual bool khr_xcb_surface() const = 0; + #if defined(ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT) + virtual bool khr_xcb_surface() const = 0; + #endif #endif virtual bool by_name(const std::string& in_name) const = 0; @@ -676,19 +688,23 @@ namespace Anvil #ifdef _WIN32 - ValueType khr_win32_surface() const final - { - anvil_assert(!m_expose_device_extensions); + #if defined(ANVIL_INCLUDE_WIN3264_WINDOW_SYSTEM_SUPPORT) + ValueType khr_win32_surface() const final + { + anvil_assert(!m_expose_device_extensions); - return m_instance_extensions_ptr->khr_win32_surface; - } + return m_instance_extensions_ptr->khr_win32_surface; + } + #endif #else - ValueType khr_xcb_surface() const final - { - anvil_assert(!m_expose_device_extensions); + #if defined(ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT) + ValueType khr_xcb_surface() const final + { + anvil_assert(!m_expose_device_extensions); - return m_instance_extensions_ptr->khr_xcb_surface; - } + return m_instance_extensions_ptr->khr_xcb_surface; + } + #endif #endif /* Private variables */ diff --git a/include/misc/external_handle.h b/include/misc/external_handle.h index 8b06d3d6..6c028023 100644 --- a/include/misc/external_handle.h +++ b/include/misc/external_handle.h @@ -40,11 +40,25 @@ namespace Anvil return m_handle; } + #if defined(_WIN32) + /* If a payload of an object exported to a NT handle is imported to ano ther object, the ownership is passed + * to the new object. + * + * For NT handles, it is assumed the handle should be destroyed when th e wrapper goes out of scope. If the above + * import is performed, you MUST tell ExternalHandleWrapper to release the ownership of the handle, or else anything + * can happen. + */ + void release_ownership() + { + m_close_at_destruction_time = false; + } + #endif + private: ExternalHandle(const ExternalHandleType& in_handle, const bool& in_close_at_destruction_time); - const bool m_close_at_destruction_time; + bool m_close_at_destruction_time; const ExternalHandleType m_handle; ANVIL_DISABLE_ASSIGNMENT_OPERATOR(ExternalHandle); diff --git a/include/misc/graphics_pipeline_create_info.h b/include/misc/graphics_pipeline_create_info.h index f6bc9196..0a9199a3 100644 --- a/include/misc/graphics_pipeline_create_info.h +++ b/include/misc/graphics_pipeline_create_info.h @@ -258,9 +258,6 @@ namespace Anvil uint32_t get_n_viewports() const; - bool get_pipeline_color_blend_attachment_state(uint32_t in_n_subpass_color_attachment, - VkPipelineColorBlendAttachmentState* out_result_ptr) const; - /** Tells what primitive topology has been specified for this instance. **/ VkPrimitiveTopology get_primitive_topology() const; diff --git a/include/misc/types.h b/include/misc/types.h index 1217e2dd..87069d3e 100644 --- a/include/misc/types.h +++ b/include/misc/types.h @@ -50,9 +50,7 @@ /* The following #define is required to include Vulkan entry-point prototype declarations. */ #ifdef _WIN32 - #if defined(ANVIL_INCLUDE_WIN3264_WINDOW_SYSTEM_SUPPORT) - #define VK_USE_PLATFORM_WIN32_KHR - #endif + #define VK_USE_PLATFORM_WIN32_KHR #else #if defined(ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT) #define VK_USE_PLATFORM_XCB_KHR diff --git a/include/misc/types_enums.h b/include/misc/types_enums.h index e89262fb..467b67c3 100644 --- a/include/misc/types_enums.h +++ b/include/misc/types_enums.h @@ -77,10 +77,12 @@ namespace Anvil EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT = 1 << 0, EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT = 1 << 1, #else - EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT = 1 << 2, - EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT = 1 << 2, + EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT = 1 << 0, + EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT = 1 << 1, #endif + /* Always last */ + EXTERNAL_FENCE_HANDLE_TYPE_COUNT } ExternalFenceHandleTypeBit; typedef uint32_t ExternalFenceHandleTypeBits; @@ -96,9 +98,11 @@ namespace Anvil EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT = 1 << 4, EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT = 1 << 5, #else - EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT = 1 << 6, + EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT = 1 << 0, #endif + /* Always last */ + EXTERNAL_MEMORY_HANDLE_TYPE_COUNT } ExternalMemoryHandleTypeBit; typedef uint32_t ExternalMemoryHandleTypeBits; @@ -111,10 +115,12 @@ namespace Anvil EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT = 1 << 1, EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT = 1 << 2, #else - EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT = 1 << 3, - EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT = 1 << 4, + EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT = 1 << 0, + EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT = 1 << 1, #endif + /* Always last */ + EXTERNAL_SEMAPHORE_HANDLE_TYPE_COUNT } ExternalSemaphoreHandleTypeBit; typedef uint32_t ExternalSemaphoreHandleTypeBits; diff --git a/include/wrappers/fence.h b/include/wrappers/fence.h index cb5845be..e8f2a45a 100644 --- a/include/wrappers/fence.h +++ b/include/wrappers/fence.h @@ -82,8 +82,6 @@ namespace Anvil /** Retrieves a pointer to the raw handle to the underlying Vulkan fence instance */ const VkFence* get_fence_ptr() const { - m_possibly_set = true; - return &m_fence; } @@ -158,7 +156,6 @@ namespace Anvil Anvil::FenceCreateInfoUniquePtr m_create_info_ptr; std::map m_external_fence_created_for_handle_type; VkFence m_fence; - mutable bool m_possibly_set; }; }; /* namespace Anvil */ diff --git a/include/wrappers/queue.h b/include/wrappers/queue.h index 99d9f036..51c408e7 100644 --- a/include/wrappers/queue.h +++ b/include/wrappers/queue.h @@ -140,6 +140,8 @@ namespace Anvil return m_supports_sparse_bindings; } + void wait_idle(); + private: /* Private functions */ void present_lock_unlock(uint32_t in_n_swapchains, diff --git a/src/wrappers/fence.cpp b/src/wrappers/fence.cpp index aea1a154..cd4ec807 100644 --- a/src/wrappers/fence.cpp +++ b/src/wrappers/fence.cpp @@ -36,8 +36,7 @@ Anvil::Fence::Fence(Anvil::FenceCreateInfoUniquePtr in_create_info_ptr) VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT), MTSafetySupportProvider (Anvil::Utils::convert_mt_safety_enum_to_boolean(in_create_info_ptr->get_mt_safety(), in_create_info_ptr->get_device () )), - m_fence (VK_NULL_HANDLE), - m_possibly_set (false) + m_fence (VK_NULL_HANDLE) { m_create_info_ptr = std::move(in_create_info_ptr); @@ -395,10 +394,6 @@ bool Anvil::Fence::reset() } unlock(); - anvil_assert_vk_call_succeeded(result); - - m_possibly_set = false; - return (result == VK_SUCCESS); } @@ -435,8 +430,6 @@ bool Anvil::Fence::reset_fences(const uint32_t in_n_fences, device_ptr = current_fence.m_device_ptr; fence_cache[n_fence] = current_fence.m_fence; - current_fence.m_possibly_set = false; - current_fence.lock(); } { diff --git a/src/wrappers/instance.cpp b/src/wrappers/instance.cpp index e9dc49db..37bb0602 100644 --- a/src/wrappers/instance.cpp +++ b/src/wrappers/instance.cpp @@ -405,15 +405,13 @@ void Anvil::Instance::init(const std::vector& in_disallowed_instanc n_instance_layer < n_instance_layers; ++n_instance_layer) { - const auto& layer_extensions = m_supported_layers[n_instance_layer].extensions; - const std::string& layer_name = m_supported_layers[n_instance_layer].name; + const std::string& layer_description = m_supported_layers[n_instance_layer].description; + const std::string& layer_name = m_supported_layers[n_instance_layer].name; /* If validation is enabled and this is a layer which issues debug call-backs, cache it, so that * we can request for it at vkCreateInstance() call time */ - if (m_validation_callback_function != nullptr && - std::find(layer_extensions.begin(), - layer_extensions.end(), - VK_EXT_DEBUG_REPORT_EXTENSION_NAME) != layer_extensions.end() ) + if (m_validation_callback_function != nullptr && + layer_description.find("Validation") != std::string::npos) { enabled_layers.push_back(layer_name.c_str() ); } @@ -451,11 +449,21 @@ void Anvil::Instance::init(const std::vector& in_disallowed_instanc extension_enabled_status[VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME] = true; } + if (is_instance_extension_supported(VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME) ) + { + extension_enabled_status[VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME] = true; + } + if (is_instance_extension_supported(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME) ) { extension_enabled_status[VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME] = true; } + if (is_instance_extension_supported(VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME) ) + { + extension_enabled_status[VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME] = true; + } + /* Filter out undesired extensions */ for (const auto& current_extension_name : in_disallowed_instance_level_extensions) { diff --git a/src/wrappers/queue.cpp b/src/wrappers/queue.cpp index b52c0f0d..732de37d 100644 --- a/src/wrappers/queue.cpp +++ b/src/wrappers/queue.cpp @@ -875,3 +875,12 @@ void Anvil::Queue::submit_command_buffers_lock_unlock(uint32_t } } } + +void Anvil::Queue::wait_idle() +{ + lock(); + { + vkQueueWaitIdle(m_queue); + } + unlock(); +}