VulkanInfo: Implement gathering of VkSurfaceKHR related info
This commit is contained in:
parent
7648217f15
commit
04d8567d31
|
@ -262,6 +262,18 @@ namespace backend { namespace vulkan {
|
|||
return mDeviceInfo;
|
||||
}
|
||||
|
||||
VkInstance Device::GetInstance() const {
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
VkPhysicalDevice Device::GetPhysicalDevice() const {
|
||||
return mPhysicalDevice;
|
||||
}
|
||||
|
||||
VkDevice Device::GetVkDevice() const {
|
||||
return mVkDevice;
|
||||
}
|
||||
|
||||
MapReadRequestTracker* Device::GetMapReadRequestTracker() const {
|
||||
return mMapReadRequestTracker;
|
||||
}
|
||||
|
@ -331,14 +343,6 @@ namespace backend { namespace vulkan {
|
|||
mNextSerial++;
|
||||
}
|
||||
|
||||
VkInstance Device::GetInstance() const {
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
VkDevice Device::GetVkDevice() const {
|
||||
return mVkDevice;
|
||||
}
|
||||
|
||||
bool Device::CreateInstance(VulkanGlobalKnobs* usedKnobs) {
|
||||
std::vector<const char*> layersToRequest;
|
||||
std::vector<const char*> extensionsToRequest;
|
||||
|
|
|
@ -100,6 +100,7 @@ namespace backend { namespace vulkan {
|
|||
|
||||
const VulkanDeviceInfo& GetDeviceInfo() const;
|
||||
VkInstance GetInstance() const;
|
||||
VkPhysicalDevice GetPhysicalDevice() const;
|
||||
VkDevice GetVkDevice() const;
|
||||
|
||||
BufferUploader* GetBufferUploader() const;
|
||||
|
|
|
@ -183,4 +183,71 @@ namespace backend { namespace vulkan {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GatherSurfaceInfo(const Device& device, VkSurfaceKHR surface, VulkanSurfaceInfo* info) {
|
||||
VkPhysicalDevice physicalDevice = device.GetPhysicalDevice();
|
||||
|
||||
// Get the surface capabilities
|
||||
{
|
||||
VkResult result = device.fn.GetPhysicalDeviceSurfaceCapabilitiesKHR(
|
||||
physicalDevice, surface, &info->capabilities);
|
||||
if (result != VK_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Query which queue families support presenting this surface
|
||||
{
|
||||
size_t nQueueFamilies = device.GetDeviceInfo().queueFamilies.size();
|
||||
info->supportedQueueFamilies.resize(nQueueFamilies, false);
|
||||
|
||||
for (uint32_t i = 0; i < nQueueFamilies; ++i) {
|
||||
VkBool32 supported = VK_FALSE;
|
||||
VkResult result = device.fn.GetPhysicalDeviceSurfaceSupportKHR(physicalDevice, i,
|
||||
surface, &supported);
|
||||
|
||||
if (result != VK_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
info->supportedQueueFamilies[i] = (supported == VK_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
// Gather supported formats
|
||||
{
|
||||
uint32_t count = 0;
|
||||
VkResult result = device.fn.GetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface,
|
||||
&count, nullptr);
|
||||
if (result != VK_SUCCESS && result != VK_INCOMPLETE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
info->formats.resize(count);
|
||||
result = device.fn.GetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, &count,
|
||||
info->formats.data());
|
||||
if (result != VK_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Gather supported presents modes
|
||||
{
|
||||
uint32_t count = 0;
|
||||
VkResult result = device.fn.GetPhysicalDeviceSurfacePresentModesKHR(
|
||||
physicalDevice, surface, &count, nullptr);
|
||||
if (result != VK_SUCCESS && result != VK_INCOMPLETE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
info->presentModes.resize(count);
|
||||
result = device.fn.GetPhysicalDeviceSurfacePresentModesKHR(
|
||||
physicalDevice, surface, &count, info->presentModes.data());
|
||||
if (result != VK_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}} // namespace backend::vulkan
|
||||
|
|
|
@ -65,11 +65,20 @@ namespace backend { namespace vulkan {
|
|||
// TODO(cwallez@chromium.org): layer instance extensions
|
||||
};
|
||||
|
||||
struct VulkanSurfaceInfo {
|
||||
VkSurfaceCapabilitiesKHR capabilities;
|
||||
std::vector<VkSurfaceFormatKHR> formats;
|
||||
std::vector<VkPresentModeKHR> presentModes;
|
||||
std::vector<bool> supportedQueueFamilies;
|
||||
};
|
||||
|
||||
bool GatherGlobalInfo(const Device& device, VulkanGlobalInfo* info);
|
||||
bool GetPhysicalDevices(const Device& device, std::vector<VkPhysicalDevice>* physicalDevices);
|
||||
bool GatherDeviceInfo(const Device& device,
|
||||
VkPhysicalDevice physicalDevice,
|
||||
VulkanDeviceInfo* info);
|
||||
bool GatherSurfaceInfo(const Device& device, VkSurfaceKHR surface, VulkanSurfaceInfo* info);
|
||||
|
||||
}} // namespace backend::vulkan
|
||||
|
||||
#endif // BACKEND_VULKAN_VULKANINFO_H_
|
||||
|
|
Loading…
Reference in New Issue