From c56c2613bee0c44ef22a2f435dc8fa6ee5f52f9a Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 17 Mar 2018 14:56:42 -0700 Subject: Added VulkanPhysiclDevice class --- Graphics/GraphicsEngineVulkan/CMakeLists.txt | 2 + .../include/VulkanUtilities/VulkanPhysicalDevice.h | 44 +++++++++++++++++ .../src/RenderDeviceFactoryVk.cpp | 8 ++-- .../src/VulkanUtilities/VulkanPhysicalDevice.cpp | 55 ++++++++++++++++++++++ 4 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanPhysicalDevice.h create mode 100644 Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanPhysicalDevice.cpp (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt index 91875ac1..2ae05941 100644 --- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt +++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt @@ -35,6 +35,7 @@ set(INCLUDE set(VULKAN_UTILS_INCLUDE include/VulkanUtilities/VulkanDebug.h include/VulkanUtilities/VulkanInstance.h + include/VulkanUtilities/VulkanPhysicalDevice.h ) @@ -86,6 +87,7 @@ set(SRC set(VULKAN_UTILS_SRC src/VulkanUtilities/VulkanDebug.cpp src/VulkanUtilities/VulkanInstance.cpp + src/VulkanUtilities/VulkanPhysicalDevice.cpp ) #set(SHADERS diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanPhysicalDevice.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanPhysicalDevice.h new file mode 100644 index 00000000..76cd8bc8 --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanPhysicalDevice.h @@ -0,0 +1,44 @@ +/* Copyright 2015-2018 Egor Yusov +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. +* +* In no event and under no legal theory, whether in tort (including negligence), +* contract, or otherwise, unless required by applicable law (such as deliberate +* and grossly negligent acts) or agreed to in writing, shall any Contributor be +* liable for any damages, including any direct, indirect, special, incidental, +* or consequential damages of any character arising as a result of this License or +* out of the use or inability to use the software (including but not limited to damages +* for loss of goodwill, work stoppage, computer failure or malfunction, or any and +* all other commercial damages or losses), even if such Contributor has been advised +* of the possibility of such damages. +*/ + +#pragma once + +#include +#include "vulkan.h" + +namespace VulkanUtilities +{ + class VulkanPhysicalDevice + { + public: + VulkanPhysicalDevice(VkPhysicalDevice vkDevice); + + private: + const VkPhysicalDevice m_VkDevice; + VkPhysicalDeviceProperties m_Properties; + VkPhysicalDeviceFeatures m_Features; + VkPhysicalDeviceMemoryProperties m_MemoryProperties; + std::vector m_QueueFamilyProperties; + std::vector m_SupportedExtensions; + }; +} diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp index 0f49494d..c3b4c5ea 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp @@ -25,8 +25,6 @@ /// Routines that initialize Vulkan-based engine implementation #include "pch.h" -#include - #include "RenderDeviceFactoryVk.h" #include "RenderDeviceVkImpl.h" #include "DeviceContextVkImpl.h" @@ -36,6 +34,7 @@ #include "EngineMemory.h" #include "CommandQueueVkImpl.h" #include "VulkanUtilities/VulkanInstance.h" +#include "VulkanUtilities/VulkanPhysicalDevice.h" namespace Diligent { @@ -138,7 +137,10 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk( const EngineVkAttribs& Crea return; } - Instance->SelectPhysicalDevice(); + auto vkDevice = Instance->SelectPhysicalDevice(); + std::unique_ptr PhysicalDevice(new VulkanUtilities::VulkanPhysicalDevice(vkDevice)); + + #if 0 for(Uint32 Type=Vk_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; Type < Vk_DESCRIPTOR_HEAP_TYPE_NUM_TYPES; ++Type) diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanPhysicalDevice.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanPhysicalDevice.cpp new file mode 100644 index 00000000..f75e24b5 --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanPhysicalDevice.cpp @@ -0,0 +1,55 @@ +/* Copyright 2015-2018 Egor Yusov +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. +* +* In no event and under no legal theory, whether in tort (including negligence), +* contract, or otherwise, unless required by applicable law (such as deliberate +* and grossly negligent acts) or agreed to in writing, shall any Contributor be +* liable for any damages, including any direct, indirect, special, incidental, +* or consequential damages of any character arising as a result of this License or +* out of the use or inability to use the software (including but not limited to damages +* for loss of goodwill, work stoppage, computer failure or malfunction, or any and +* all other commercial damages or losses), even if such Contributor has been advised +* of the possibility of such damages. +*/ + +#include "pch.h" +#include "VulkanUtilities/VulkanPhysicalDevice.h" + +namespace VulkanUtilities +{ + VulkanPhysicalDevice::VulkanPhysicalDevice(VkPhysicalDevice vkDevice) : + m_VkDevice(vkDevice) + { + VERIFY_EXPR(m_VkDevice != VK_NULL_HANDLE); + + vkGetPhysicalDeviceProperties(m_VkDevice, &m_Properties); + vkGetPhysicalDeviceFeatures(m_VkDevice, &m_Features); + vkGetPhysicalDeviceMemoryProperties(m_VkDevice, &m_MemoryProperties); + uint32_t QueueFamilyCount = 0; + vkGetPhysicalDeviceQueueFamilyProperties(m_VkDevice, &QueueFamilyCount, nullptr); + VERIFY_EXPR(QueueFamilyCount> 0); + m_QueueFamilyProperties.resize(QueueFamilyCount); + vkGetPhysicalDeviceQueueFamilyProperties(m_VkDevice, &QueueFamilyCount, m_QueueFamilyProperties.data()); + VERIFY_EXPR(QueueFamilyCount == m_QueueFamilyProperties.size()); + + // Get list of supported extensions + uint32_t ExtensionCount = 0; + vkEnumerateDeviceExtensionProperties(m_VkDevice, nullptr, &ExtensionCount, nullptr); + if (ExtensionCount > 0) + { + m_SupportedExtensions.resize(ExtensionCount); + auto res = vkEnumerateDeviceExtensionProperties(m_VkDevice, nullptr, &ExtensionCount, m_SupportedExtensions.data()); + VERIFY_EXPR(res == VK_SUCCESS); + VERIFY_EXPR(ExtensionCount == m_SupportedExtensions.size()); + } + } +} -- cgit v1.2.3