From: Jean-Philippe Bruyère Date: Sun, 23 Jan 2022 16:49:58 +0000 (+0100) Subject: add test for png blit img format support, debug surface img format feature test X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=4915cbe0ada941b77a64fcc9a9fed16b51b7922e;p=jp%2Fvkvg.git add test for png blit img format support, debug surface img format feature test --- diff --git a/src/vkvg_device_internal.c b/src/vkvg_device_internal.c index 90556a2..1e73616 100644 --- a/src/vkvg_device_internal.c +++ b/src/vkvg_device_internal.c @@ -481,12 +481,27 @@ void _check_best_image_tiling (VkvgDevice dev, VkFormat format) { VkFlags stencilFormats[] = { VK_FORMAT_S8_UINT, VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT }; VkFormatProperties phyStencilProps = { 0 }, phyImgProps = { 0 }; + //check png blit format + VkFlags pngBlitFormats[] = { VK_FORMAT_R8G8B8A8_SRGB, VK_FORMAT_R8G8B8A8_UNORM}; + dev->pngStagFormat = VK_FORMAT_UNDEFINED; + for (int i = 0; i < 2; i++) + { + vkGetPhysicalDeviceFormatProperties(dev->phy, pngBlitFormats[i], &phyImgProps); + if ((phyImgProps.linearTilingFeatures & VKVG_PNG_WRITE_IMG_REQUIREMENTS) == VKVG_PNG_WRITE_IMG_REQUIREMENTS) { + dev->pngStagFormat = pngBlitFormats[i]; + break; + } + } + + if (dev->pngStagFormat == VK_FORMAT_UNDEFINED) + LOG(VKVG_LOG_DEBUG, "vkvg create device failed: no suitable image format for png write\n"); + dev->stencilFormat = VK_FORMAT_UNDEFINED; dev->supportedTiling = 0xff; vkGetPhysicalDeviceFormatProperties(dev->phy, format, &phyImgProps); - if (phyImgProps.optimalTilingFeatures & (VKVG_SURFACE_IMGS_REQUIREMENTS)) { + if ((phyImgProps.optimalTilingFeatures & VKVG_SURFACE_IMGS_REQUIREMENTS) == VKVG_SURFACE_IMGS_REQUIREMENTS) { for (int i = 0; i < 4; i++) { vkGetPhysicalDeviceFormatProperties(dev->phy, stencilFormats[i], &phyStencilProps); @@ -497,7 +512,7 @@ void _check_best_image_tiling (VkvgDevice dev, VkFormat format) { } } } - if (phyImgProps.linearTilingFeatures & (VKVG_SURFACE_IMGS_REQUIREMENTS)) { + if ((phyImgProps.linearTilingFeatures & VKVG_SURFACE_IMGS_REQUIREMENTS) == VKVG_SURFACE_IMGS_REQUIREMENTS) { for (int i = 0; i < 4; i++) { vkGetPhysicalDeviceFormatProperties(dev->phy, stencilFormats[i], &phyStencilProps); diff --git a/src/vkvg_device_internal.h b/src/vkvg_device_internal.h index d706416..14b807a 100644 --- a/src/vkvg_device_internal.h +++ b/src/vkvg_device_internal.h @@ -60,6 +60,7 @@ typedef struct _vkvg_device_t{ VkImageTiling supportedTiling; /**< Supported image tiling for surface, 0xFF=no support */ VkFormat stencilFormat; /**< Supported vulkan image format for stencil */ + VkFormat pngStagFormat; /**< Supported vulkan image format png write staging img */ VkhQueue gQueue; /**< Vulkan Queue with Graphic flag */ MUTEX gQMutex; /**< queue submission has to be externally syncronized */ diff --git a/src/vkvg_internal.h b/src/vkvg_internal.h index 7af8fa4..08655a7 100644 --- a/src/vkvg_internal.h +++ b/src/vkvg_internal.h @@ -75,8 +75,9 @@ //the two first bits of the stencil are the FILL and the CLIP bits, all other bits are //used to store clipping bit on context saving. 8 bit stencil will allow 6 save/restore layer #define FB_COLOR_FORMAT VK_FORMAT_B8G8R8A8_UNORM -#define VKVG_SURFACE_IMGS_REQUIREMENTS VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|\ - VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_FORMAT_FEATURE_BLIT_SRC_BIT +#define VKVG_SURFACE_IMGS_REQUIREMENTS (VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT|VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT|\ + VK_FORMAT_FEATURE_TRANSFER_DST_BIT|VK_FORMAT_FEATURE_TRANSFER_SRC_BIT|VK_FORMAT_FEATURE_BLIT_SRC_BIT) +#define VKVG_PNG_WRITE_IMG_REQUIREMENTS (VK_FORMAT_FEATURE_TRANSFER_SRC_BIT|VK_FORMAT_FEATURE_TRANSFER_DST_BIT|VK_FORMAT_FEATURE_BLIT_DST_BIT) //30 seconds fence timeout #define VKVG_FENCE_TIMEOUT 30000000000 //#define VKVG_FENCE_TIMEOUT 10000 diff --git a/src/vkvg_surface.c b/src/vkvg_surface.c index ed9a19c..e2394e7 100644 --- a/src/vkvg_surface.c +++ b/src/vkvg_surface.c @@ -237,12 +237,17 @@ uint32_t vkvg_surface_get_height (VkvgSurface surf) { return surf->height; } -void vkvg_surface_write_to_png (VkvgSurface surf, const char* path){ +void vkvg_surface_write_to_png (VkvgSurface surf, const char* path){ + if (surf->dev->pngStagFormat == VK_FORMAT_UNDEFINED) { + LOG(VKVG_LOG_ERR, "no suitable image format for png write\n"); + return; + } + VkImageSubresourceLayers imgSubResLayers = {VK_IMAGE_ASPECT_COLOR_BIT,0,0,1}; VkvgDevice dev = surf->dev; //RGBA to blit to, surf img is bgra - VkhImage stagImg= vkh_image_create ((VkhDevice)surf->dev,VK_FORMAT_R8G8B8A8_SRGB,surf->width,surf->height,VK_IMAGE_TILING_LINEAR, + VkhImage stagImg= vkh_image_create ((VkhDevice)surf->dev, dev->pngStagFormat, surf->width,surf->height,VK_IMAGE_TILING_LINEAR, VMA_MEMORY_USAGE_GPU_TO_CPU, VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT);