aux/vk: Report appropriate errors on unsupported image usage flags

This commit is contained in:
Christoph Haag 2020-08-21 17:46:22 +02:00
parent 092dddc2da
commit 6dc4a1f237
3 changed files with 118 additions and 12 deletions

View file

@ -83,6 +83,36 @@ vk_color_format_string(VkFormat code)
}
}
const char *
vk_format_feature_string(VkFormatFeatureFlagBits code)
{
switch (code) {
ENUM_TO_STR(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
ENUM_TO_STR(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
ENUM_TO_STR(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
ENUM_TO_STR(VK_FORMAT_FEATURE_TRANSFER_SRC_BIT);
ENUM_TO_STR(VK_FORMAT_FEATURE_TRANSFER_DST_BIT);
ENUM_TO_STR(VK_FORMAT_R5G6B5_UNORM_PACK16);
default: return "UNKNOWN FORMAT FEATURE";
}
}
const char *
xrt_swapchain_usage_string(enum xrt_swapchain_usage_bits code)
{
switch (code) {
ENUM_TO_STR(XRT_SWAPCHAIN_USAGE_COLOR);
ENUM_TO_STR(XRT_SWAPCHAIN_USAGE_DEPTH_STENCIL);
ENUM_TO_STR(XRT_SWAPCHAIN_USAGE_UNORDERED_ACCESS);
ENUM_TO_STR(XRT_SWAPCHAIN_USAGE_TRANSFER_SRC);
ENUM_TO_STR(XRT_SWAPCHAIN_USAGE_TRANSFER_DST);
ENUM_TO_STR(XRT_SWAPCHAIN_USAGE_SAMPLED);
ENUM_TO_STR(XRT_SWAPCHAIN_USAGE_MUTABLE_FORMAT);
ENUM_TO_STR(XRT_SWAPCHAIN_USAGE_INPUT_ATTACHMENT);
default: return "UNKNOWN SWAPCHAIN USAGE";
}
}
const char *
vk_present_mode_string(VkPresentModeKHR code)
{
@ -274,7 +304,15 @@ vk_create_image_from_native(struct vk_bundle *vk,
VkImage *out_image,
VkDeviceMemory *out_mem)
{
VkImageUsageFlags image_usage = vk_swapchain_usage_flags(info->bits);
VkImageUsageFlags image_usage =
vk_swapchain_usage_flags(vk, (VkFormat)info->format, info->bits);
if (image_usage == 0) {
U_LOG_E(
"vk_create_image_from_native: Unsupported swapchain usage "
"flags");
return VK_ERROR_FEATURE_NOT_PRESENT;
}
VkImage image = VK_NULL_HANDLE;
VkResult ret = VK_SUCCESS;
@ -658,6 +696,7 @@ vk_get_instance_functions(struct vk_bundle *vk)
vk->vkGetPhysicalDeviceSurfaceFormatsKHR = GET_INS_PROC(vk, vkGetPhysicalDeviceSurfaceFormatsKHR);
vk->vkGetPhysicalDeviceSurfacePresentModesKHR = GET_INS_PROC(vk, vkGetPhysicalDeviceSurfacePresentModesKHR);
vk->vkGetPhysicalDeviceSurfaceSupportKHR = GET_INS_PROC(vk, vkGetPhysicalDeviceSurfaceSupportKHR);
vk->vkGetPhysicalDeviceFormatProperties = GET_INS_PROC(vk, vkGetPhysicalDeviceFormatProperties);
#ifdef VK_USE_PLATFORM_XCB_KHR
vk->vkCreateXcbSurfaceKHR = GET_INS_PROC(vk, vkCreateXcbSurfaceKHR);
@ -1092,25 +1131,82 @@ vk_swapchain_access_flags(enum xrt_swapchain_usage_bits bits)
return result;
}
VkImageUsageFlags
vk_swapchain_usage_flags(enum xrt_swapchain_usage_bits bits)
static bool
check_feature(VkFormat format,
enum xrt_swapchain_usage_bits usage,
VkFormatFeatureFlags format_features,
VkFormatFeatureFlags flag)
{
VkImageUsageFlags image_usage =
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
if ((format_features & flag) == 0) {
U_LOG_E(
"vk_swapchain_usage_flags: %s requested but %s not "
"supported for format %s",
xrt_swapchain_usage_string(usage),
vk_format_feature_string(flag),
vk_color_format_string(format));
return false;
}
return true;
}
VkImageUsageFlags
vk_swapchain_usage_flags(struct vk_bundle *vk,
VkFormat format,
enum xrt_swapchain_usage_bits bits)
{
VkFormatProperties prop;
vk->vkGetPhysicalDeviceFormatProperties(vk->physical_device, format,
&prop);
VkImageUsageFlags image_usage = 0;
if ((bits & XRT_SWAPCHAIN_USAGE_DEPTH_STENCIL) != 0) {
if (!check_feature(
format, XRT_SWAPCHAIN_USAGE_DEPTH_STENCIL,
prop.optimalTilingFeatures,
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
return 0;
}
image_usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
}
if ((prop.optimalTilingFeatures &
VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) != 0) {
image_usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
VK_IMAGE_USAGE_SAMPLED_BIT;
}
if ((bits & XRT_SWAPCHAIN_USAGE_COLOR) != 0) {
if (!check_feature(format, XRT_SWAPCHAIN_USAGE_COLOR,
prop.optimalTilingFeatures,
VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) {
return 0;
}
image_usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
}
if ((bits & XRT_SWAPCHAIN_USAGE_DEPTH_STENCIL) != 0) {
image_usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
}
if ((bits & XRT_SWAPCHAIN_USAGE_TRANSFER_SRC) != 0) {
if (!check_feature(format, XRT_SWAPCHAIN_USAGE_TRANSFER_SRC,
prop.optimalTilingFeatures,
VK_FORMAT_FEATURE_TRANSFER_SRC_BIT)) {
return 0;
}
image_usage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
}
if ((bits & XRT_SWAPCHAIN_USAGE_TRANSFER_DST) != 0) {
if (!check_feature(format, XRT_SWAPCHAIN_USAGE_TRANSFER_DST,
prop.optimalTilingFeatures,
VK_FORMAT_FEATURE_TRANSFER_DST_BIT)) {
return 0;
}
image_usage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
}
if ((bits & XRT_SWAPCHAIN_USAGE_SAMPLED) != 0) {
if (!check_feature(format, XRT_SWAPCHAIN_USAGE_SAMPLED,
prop.optimalTilingFeatures,
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
return 0;
}
image_usage |= VK_IMAGE_USAGE_SAMPLED_BIT;
}
if ((bits & XRT_SWAPCHAIN_USAGE_INPUT_ATTACHMENT) != 0) {

View file

@ -97,6 +97,8 @@ struct vk_bundle
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR vkGetPhysicalDeviceSurfacePresentModesKHR;
PFN_vkGetPhysicalDeviceSurfaceSupportKHR vkGetPhysicalDeviceSurfaceSupportKHR;
PFN_vkGetPhysicalDeviceFormatProperties vkGetPhysicalDeviceFormatProperties;
// Device functions.
PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
@ -431,11 +433,13 @@ vk_swapchain_access_flags(enum xrt_swapchain_usage_bits bits);
/*!
* Always adds `VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT` and
* `VK_IMAGE_USAGE_SAMPLED_BIT` so they can be used by the compositor and
* client.
* `VK_IMAGE_USAGE_SAMPLED_BIT` to color formats so they can be used by the
* compositor and client.
*/
VkImageUsageFlags
vk_swapchain_usage_flags(enum xrt_swapchain_usage_bits bits);
vk_swapchain_usage_flags(struct vk_bundle *vk,
VkFormat format,
enum xrt_swapchain_usage_bits bits);
bool
vk_init_descriptor_pool(struct vk_bundle *vk,

View file

@ -87,7 +87,13 @@ create_image(struct vk_bundle *vk,
const struct xrt_swapchain_create_info *info,
struct vk_image *out_image)
{
VkImageUsageFlags image_usage = vk_swapchain_usage_flags(info->bits);
VkImageUsageFlags image_usage =
vk_swapchain_usage_flags(vk, (VkFormat)info->format, info->bits);
if (image_usage == 0) {
U_LOG_E("create_image: Unsupported swapchain usage flags");
return VK_ERROR_FEATURE_NOT_PRESENT;
}
VkDeviceMemory device_memory = VK_NULL_HANDLE;
VkImage image = VK_NULL_HANDLE;
VkResult ret = VK_SUCCESS;