mirror of
https://gitlab.freedesktop.org/mesa/vulkan-wsi-layer.git
synced 2025-12-20 04:30:11 +01:00
Create common functions in surface_capabilities class
Signed-off-by: Lior Dekel <lior.dekel@arm.com> Change-Id: Ia5053b202f4e64fd7a255ede513653a951ab3d41
This commit is contained in:
parent
711836af6c
commit
91583f1af2
4 changed files with 87 additions and 93 deletions
|
|
@ -57,34 +57,7 @@ surface_properties& surface_properties::get_instance()
|
|||
VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_device,
|
||||
VkSurfaceCapabilitiesKHR *surface_capabilities)
|
||||
{
|
||||
/* Image count limits */
|
||||
surface_capabilities->minImageCount = 1;
|
||||
surface_capabilities->maxImageCount = MAX_SWAPCHAIN_IMAGE_COUNT;
|
||||
|
||||
/* Surface extents */
|
||||
surface_capabilities->currentExtent = { 0xffffffff, 0xffffffff };
|
||||
surface_capabilities->minImageExtent = { 1, 1 };
|
||||
/* Ask the device for max */
|
||||
VkPhysicalDeviceProperties dev_props;
|
||||
layer::instance_private_data::get(physical_device).disp.GetPhysicalDeviceProperties(physical_device, &dev_props);
|
||||
|
||||
surface_capabilities->maxImageExtent = { dev_props.limits.maxImageDimension2D,
|
||||
dev_props.limits.maxImageDimension2D };
|
||||
surface_capabilities->maxImageArrayLayers = 1;
|
||||
|
||||
/* Surface transforms */
|
||||
surface_capabilities->supportedTransforms = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||
surface_capabilities->currentTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||
|
||||
/* Composite alpha */
|
||||
surface_capabilities->supportedCompositeAlpha = static_cast<VkCompositeAlphaFlagBitsKHR>(
|
||||
VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR | VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR |
|
||||
VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR | VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR);
|
||||
|
||||
/* Image usage flags */
|
||||
surface_capabilities->supportedUsageFlags =
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT |
|
||||
VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
|
||||
get_surface_capabilities_common(physical_device, surface_capabilities);
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
|
@ -140,29 +113,9 @@ VkResult surface_properties::get_surface_present_modes(VkPhysicalDevice physical
|
|||
UNUSED(physical_device);
|
||||
UNUSED(surface);
|
||||
|
||||
VkResult res = VK_SUCCESS;
|
||||
static const std::array<VkPresentModeKHR, 2> modes = { VK_PRESENT_MODE_FIFO_KHR, VK_PRESENT_MODE_FIFO_RELAXED_KHR };
|
||||
|
||||
assert(present_mode_count != nullptr);
|
||||
|
||||
if (nullptr == present_modes)
|
||||
{
|
||||
*present_mode_count = modes.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (modes.size() > *present_mode_count)
|
||||
{
|
||||
res = VK_INCOMPLETE;
|
||||
}
|
||||
*present_mode_count = std::min(*present_mode_count, static_cast<uint32_t>(modes.size()));
|
||||
for (uint32_t i = 0; i < *present_mode_count; ++i)
|
||||
{
|
||||
present_modes[i] = modes[i];
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
return get_surface_present_modes_common(present_mode_count, present_modes, modes);
|
||||
}
|
||||
|
||||
VWL_VKAPI_CALL(VkResult)
|
||||
|
|
|
|||
|
|
@ -96,4 +96,36 @@ void surface_format_properties::fill_format_properties(VkSurfaceFormat2KHR &surf
|
|||
#endif
|
||||
}
|
||||
|
||||
void get_surface_capabilities_common(VkPhysicalDevice physical_device, VkSurfaceCapabilitiesKHR *surface_capabilities)
|
||||
{
|
||||
/* Image count limits */
|
||||
surface_capabilities->minImageCount = 1;
|
||||
surface_capabilities->maxImageCount = surface_properties::MAX_SWAPCHAIN_IMAGE_COUNT;
|
||||
|
||||
/* Surface extents */
|
||||
surface_capabilities->currentExtent = { 0xffffffff, 0xffffffff };
|
||||
surface_capabilities->minImageExtent = { 1, 1 };
|
||||
/* Ask the device for max */
|
||||
VkPhysicalDeviceProperties dev_props;
|
||||
layer::instance_private_data::get(physical_device).disp.GetPhysicalDeviceProperties(physical_device, &dev_props);
|
||||
|
||||
surface_capabilities->maxImageExtent = { dev_props.limits.maxImageDimension2D,
|
||||
dev_props.limits.maxImageDimension2D };
|
||||
surface_capabilities->maxImageArrayLayers = 1;
|
||||
|
||||
/* Surface transforms */
|
||||
surface_capabilities->supportedTransforms = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||
surface_capabilities->currentTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||
|
||||
/* Composite alpha */
|
||||
surface_capabilities->supportedCompositeAlpha = static_cast<VkCompositeAlphaFlagBitsKHR>(
|
||||
VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR | VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR |
|
||||
VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR | VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR);
|
||||
|
||||
/* Image usage flags */
|
||||
surface_capabilities->supportedUsageFlags =
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT |
|
||||
VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
|
||||
}
|
||||
|
||||
} /* namespace wsi */
|
||||
|
|
@ -200,5 +200,55 @@ VkResult surface_properties_formats_helper(It begin, It end, uint32_t *surface_f
|
|||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Common function for the get_surface_capabilities.
|
||||
*
|
||||
* Initiates the different fields in surface_capabilities struct, also
|
||||
* according to the physical_device.
|
||||
*
|
||||
* @param physical_device Vulkan physical_device.
|
||||
* @param surface_capabilities address of Vulkan surface capabilities struct.
|
||||
*
|
||||
*/
|
||||
void get_surface_capabilities_common(VkPhysicalDevice physical_device, VkSurfaceCapabilitiesKHR *surface_capabilities);
|
||||
|
||||
/**
|
||||
* @brief Common function for the get_surface_present_modes.
|
||||
*
|
||||
* Preparing the present_modes array for get_surface_present_modes.
|
||||
*
|
||||
* @param present_mode_count address of counter for the present modes.
|
||||
* @param present_modes array of present modes.
|
||||
* @param modes array of modes
|
||||
*
|
||||
* @return VK_SUCCESS on success, VK_INCOMPLETE otherwise.
|
||||
*
|
||||
*/
|
||||
template <std::size_t SIZE>
|
||||
VkResult get_surface_present_modes_common(uint32_t *present_mode_count, VkPresentModeKHR *present_modes,
|
||||
const std::array<VkPresentModeKHR, SIZE> &modes)
|
||||
{
|
||||
VkResult res = VK_SUCCESS;
|
||||
|
||||
assert(present_mode_count != nullptr);
|
||||
|
||||
if (nullptr == present_modes)
|
||||
{
|
||||
*present_mode_count = modes.size();
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
if (modes.size() > *present_mode_count)
|
||||
{
|
||||
res = VK_INCOMPLETE;
|
||||
}
|
||||
*present_mode_count = std::min(*present_mode_count, static_cast<uint32_t>(modes.size()));
|
||||
for (uint32_t i = 0; i < *present_mode_count; ++i)
|
||||
{
|
||||
present_modes[i] = modes[i];
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
} /* namespace wsi */
|
||||
|
|
|
|||
|
|
@ -71,33 +71,13 @@ VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_
|
|||
VkSurfaceCapabilitiesKHR *pSurfaceCapabilities)
|
||||
{
|
||||
/* Image count limits */
|
||||
get_surface_capabilities_common(physical_device, pSurfaceCapabilities);
|
||||
pSurfaceCapabilities->minImageCount = 2;
|
||||
pSurfaceCapabilities->maxImageCount = MAX_SWAPCHAIN_IMAGE_COUNT;
|
||||
|
||||
/* Surface extents */
|
||||
pSurfaceCapabilities->currentExtent = { 0xffffffff, 0xffffffff };
|
||||
pSurfaceCapabilities->minImageExtent = { 1, 1 };
|
||||
|
||||
VkPhysicalDeviceProperties dev_props;
|
||||
layer::instance_private_data::get(physical_device).disp.GetPhysicalDeviceProperties(physical_device, &dev_props);
|
||||
|
||||
pSurfaceCapabilities->maxImageExtent = { dev_props.limits.maxImageDimension2D,
|
||||
dev_props.limits.maxImageDimension2D };
|
||||
pSurfaceCapabilities->maxImageArrayLayers = 1;
|
||||
|
||||
/* Surface transforms */
|
||||
pSurfaceCapabilities->supportedTransforms = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||
pSurfaceCapabilities->currentTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||
|
||||
/* Composite alpha */
|
||||
pSurfaceCapabilities->supportedCompositeAlpha = static_cast<VkCompositeAlphaFlagBitsKHR>(
|
||||
VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR | VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR);
|
||||
|
||||
/* Image usage flags */
|
||||
pSurfaceCapabilities->supportedUsageFlags =
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT |
|
||||
VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -235,33 +215,12 @@ VkResult surface_properties::get_surface_present_modes(VkPhysicalDevice physical
|
|||
uint32_t *pPresentModeCount, VkPresentModeKHR *pPresentModes)
|
||||
{
|
||||
|
||||
VkResult res = VK_SUCCESS;
|
||||
|
||||
static std::array<const VkPresentModeKHR, 2> modes = {
|
||||
static const std::array<VkPresentModeKHR, 2> modes = {
|
||||
VK_PRESENT_MODE_FIFO_KHR,
|
||||
VK_PRESENT_MODE_MAILBOX_KHR,
|
||||
};
|
||||
|
||||
assert(pPresentModeCount != nullptr);
|
||||
|
||||
if (nullptr == pPresentModes)
|
||||
{
|
||||
*pPresentModeCount = modes.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (modes.size() > *pPresentModeCount)
|
||||
{
|
||||
res = VK_INCOMPLETE;
|
||||
}
|
||||
*pPresentModeCount = std::min(*pPresentModeCount, static_cast<uint32_t>(modes.size()));
|
||||
for (uint32_t i = 0; i < *pPresentModeCount; ++i)
|
||||
{
|
||||
pPresentModes[i] = modes[i];
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
return get_surface_present_modes_common(pPresentModeCount, pPresentModes, modes);
|
||||
}
|
||||
|
||||
static const char *required_device_extensions[] = {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue