Optimizations for Vulkan device
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
#if GRAPHICS_API_VULKAN
|
||||
|
||||
#include "GPUAdapterVulkan.h"
|
||||
#include "GPUDeviceVulkan.h"
|
||||
|
||||
GPUAdapterVulkan::GPUAdapterVulkan(VkPhysicalDevice gpu)
|
||||
: Gpu(gpu)
|
||||
{
|
||||
vkGetPhysicalDeviceProperties(gpu, &GpuProps);
|
||||
Description = GpuProps.deviceName;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -37,12 +37,6 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GPUAdapterVulkan"/> class.
|
||||
/// </summary>
|
||||
/// <param name="gpu">The GPU device handle.</param>
|
||||
GPUAdapterVulkan(VkPhysicalDevice gpu);
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
@@ -67,12 +61,10 @@ public:
|
||||
{
|
||||
return Gpu != VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
uint32 GetVendorId() const override
|
||||
{
|
||||
return GpuProps.vendorID;
|
||||
}
|
||||
|
||||
String GetDescription() const override
|
||||
{
|
||||
return Description;
|
||||
|
||||
@@ -179,6 +179,16 @@ static bool FindLayerExtension(const Array<LayerExtension>& list, const char* ex
|
||||
return FindLayerExtension(list, extensionName, dummy);
|
||||
}
|
||||
|
||||
static bool ListContains(const Array<const char*>& list, const char* name)
|
||||
{
|
||||
for (const char* element : list)
|
||||
{
|
||||
if (!StringUtils::Compare(element, name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GPUDeviceVulkan::GetInstanceLayersAndExtensions(Array<const char*>& outInstanceExtensions, Array<const char*>& outInstanceLayers, bool& outDebugUtils)
|
||||
{
|
||||
VkResult result;
|
||||
@@ -486,6 +496,7 @@ void GPUDeviceVulkan::GetDeviceExtensionsAndLayers(VkPhysicalDevice gpu, Array<c
|
||||
}
|
||||
#endif
|
||||
|
||||
// Find all extensions
|
||||
Array<const char*> availableExtensions;
|
||||
{
|
||||
for (int32 i = 0; i < deviceLayerExtensions[0].Extensions.Count(); i++)
|
||||
@@ -512,19 +523,7 @@ void GPUDeviceVulkan::GetDeviceExtensionsAndLayers(VkPhysicalDevice gpu, Array<c
|
||||
}
|
||||
TrimDuplicates(availableExtensions);
|
||||
|
||||
const auto ListContains = [](const Array<const char*>& list, const char* name)
|
||||
{
|
||||
for (const char* element : list)
|
||||
{
|
||||
if (!StringUtils::Compare(element, name))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// Pick extensions to use
|
||||
Array<const char*> platformExtensions;
|
||||
VulkanPlatform::GetDeviceExtensions(platformExtensions, outDeviceLayers);
|
||||
for (const char* extension : platformExtensions)
|
||||
@@ -535,7 +534,6 @@ void GPUDeviceVulkan::GetDeviceExtensionsAndLayers(VkPhysicalDevice gpu, Array<c
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32 i = 0; i < ARRAY_COUNT(GDeviceExtensions) && GDeviceExtensions[i] != nullptr; i++)
|
||||
{
|
||||
if (ListContains(availableExtensions, GDeviceExtensions[i]))
|
||||
|
||||
@@ -1137,15 +1137,17 @@ GPUDevice* GPUDeviceVulkan::Create()
|
||||
uint32 gpuCount = 0;
|
||||
VALIDATE_VULKAN_RESULT(vkEnumeratePhysicalDevices(Instance, &gpuCount, nullptr));
|
||||
ASSERT(gpuCount >= 1);
|
||||
Array<VkPhysicalDevice> gpus;
|
||||
gpus.AddZeroed(gpuCount);
|
||||
Array<VkPhysicalDevice, InlinedAllocation<4>> gpus;
|
||||
gpus.Resize(gpuCount);
|
||||
VALIDATE_VULKAN_RESULT(vkEnumeratePhysicalDevices(Instance, &gpuCount, gpus.Get()));
|
||||
Array<GPUAdapterVulkan> adapters;
|
||||
adapters.EnsureCapacity(gpuCount);
|
||||
Array<GPUAdapterVulkan, InlinedAllocation<4>> adapters;
|
||||
adapters.Resize(gpuCount);
|
||||
for (uint32 gpuIndex = 0; gpuIndex < gpuCount; gpuIndex++)
|
||||
{
|
||||
GPUAdapterVulkan adapter(gpus[gpuIndex]);
|
||||
adapters.Add(adapter);
|
||||
GPUAdapterVulkan& adapter = adapters[gpuIndex];
|
||||
adapter.Gpu = gpus[gpuIndex];
|
||||
vkGetPhysicalDeviceProperties(adapter.Gpu, &adapter.GpuProps);
|
||||
adapter.Description = adapter.GpuProps.deviceName;
|
||||
|
||||
const Char* type;
|
||||
switch (adapter.GpuProps.deviceType)
|
||||
@@ -1490,7 +1492,7 @@ bool GPUDeviceVulkan::Init()
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queueCount, QueueFamilyProps.Get());
|
||||
|
||||
// Query device features
|
||||
vkGetPhysicalDeviceFeatures(Adapter->Gpu, &PhysicalDeviceFeatures);
|
||||
vkGetPhysicalDeviceFeatures(gpu, &PhysicalDeviceFeatures);
|
||||
|
||||
// Get extensions and layers
|
||||
Array<const char*> deviceExtensions;
|
||||
|
||||
@@ -312,7 +312,7 @@ bool GPUSwapChainVulkan::CreateSwapChain(int32 width, int32 height)
|
||||
VALIDATE_VULKAN_RESULT(vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, _surface, &presentModesCount, nullptr));
|
||||
ASSERT(presentModesCount > 0);
|
||||
|
||||
Array<VkPresentModeKHR> presentModes;
|
||||
Array<VkPresentModeKHR, InlinedAllocation<4>> presentModes;
|
||||
presentModes.Resize(presentModesCount);
|
||||
VALIDATE_VULKAN_RESULT(vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, _surface, &presentModesCount, presentModes.Get()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user