From: Jean-Philippe Bruyère Date: Mon, 7 Jan 2019 14:29:00 +0000 (+0100) Subject: vkvg_surface_create_for_VkhImage X-Git-Tag: v0.1-alpha~107^2 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=refs%2Fpull%2F17%2Fhead;p=jp%2Fvkvg.git vkvg_surface_create_for_VkhImage --- diff --git a/include/vkvg.h b/include/vkvg.h index 7591769..550b90c 100644 --- a/include/vkvg.h +++ b/include/vkvg.h @@ -167,6 +167,7 @@ uint32_t vkvg_device_get_reference_count (VkvgDevice dev); VkvgSurface vkvg_surface_create (VkvgDevice dev, uint32_t width, uint32_t height); VkvgSurface vkvg_surface_create_from_image (VkvgDevice dev, const char* filePath); +VkvgSurface vkvg_surface_create_for_VkhImage (VkvgDevice dev, void* vkhImg); // VkvgSurface vkvg_surface_create_from_bitmap (VkvgDevice dev, unsigned char* img, uint32_t width, uint32_t height); VkvgSurface vkvg_surface_reference (VkvgSurface surf); uint32_t vkvg_surface_get_reference_count(VkvgSurface surf); diff --git a/src/vkvg_device_internal.c b/src/vkvg_device_internal.c index 1e56a88..5d30911 100644 --- a/src/vkvg_device_internal.c +++ b/src/vkvg_device_internal.c @@ -344,3 +344,32 @@ void _create_empty_texture (VkvgDevice dev) { vkh_cmd_end (dev->cmd); _submit_cmd (dev, &dev->cmd, dev->fence); } + +void _dump_image_format_properties (VkvgDevice dev) { + VkImageFormatProperties imgProps; + VK_CHECK_RESULT(vkGetPhysicalDeviceImageFormatProperties(dev->phy, + FB_COLOR_FORMAT, VK_IMAGE_TYPE_2D, VKVG_TILING, + VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT, + 0, &imgProps)); + printf ("tiling = %d\n", VKVG_TILING); + printf ("max extend = (%d, %d, %d)\n", imgProps.maxExtent.width, imgProps.maxExtent.height, imgProps.maxExtent.depth); + printf ("max mip levels = %d\n", imgProps.maxMipLevels); + printf ("max array layers = %d\n", imgProps.maxArrayLayers); + printf ("sample counts = "); + if (imgProps.sampleCounts & VK_SAMPLE_COUNT_1_BIT) + printf ("1,"); + if (imgProps.sampleCounts & VK_SAMPLE_COUNT_2_BIT) + printf ("2,"); + if (imgProps.sampleCounts & VK_SAMPLE_COUNT_4_BIT) + printf ("4,"); + if (imgProps.sampleCounts & VK_SAMPLE_COUNT_8_BIT) + printf ("8,"); + if (imgProps.sampleCounts & VK_SAMPLE_COUNT_16_BIT) + printf ("16,"); + if (imgProps.sampleCounts & VK_SAMPLE_COUNT_32_BIT) + printf ("32,"); + printf ("\n"); + printf ("max resource size= %lu\n", imgProps.maxResourceSize); + + +} diff --git a/src/vkvg_device_internal.h b/src/vkvg_device_internal.h index c5b3f37..ac47984 100644 --- a/src/vkvg_device_internal.h +++ b/src/vkvg_device_internal.h @@ -96,6 +96,7 @@ typedef struct _vkvg_device_t{ void _init_function_pointers (VkvgDevice dev); void _create_empty_texture (VkvgDevice dev); +void _check_image_format_properties (VkvgDevice dev); void _create_pipeline_cache (VkvgDevice dev); void _setupRenderPass (VkvgDevice dev); void _setupPipelines (VkvgDevice dev); diff --git a/src/vkvg_surface.c b/src/vkvg_surface.c index 707dd99..d904f36 100644 --- a/src/vkvg_surface.c +++ b/src/vkvg_surface.c @@ -73,19 +73,20 @@ void _clear_surface (VkvgSurface surf, VkImageAspectFlags aspect) _submit_cmd (dev, &cmd, dev->fence); } -void _init_surface (VkvgSurface surf) { - surf->format = FB_COLOR_FORMAT;//force bgra internally +void _create_surface_main_image (VkvgSurface surf){ surf->img = vkh_image_create((VkhDevice)surf->dev,surf->format,surf->width,surf->height,VKVG_TILING,VMA_MEMORY_USAGE_GPU_ONLY, VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT); + vkh_image_create_descriptor(surf->img, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT, VK_FILTER_NEAREST, VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_NEAREST,VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE); +} +void _create_surface_ms_images (VkvgSurface surf) { surf->imgMS = vkh_image_ms_create((VkhDevice)surf->dev,surf->format,surf->dev->samples,surf->width,surf->height,VMA_MEMORY_USAGE_GPU_ONLY, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT); surf->stencilMS = vkh_image_ms_create((VkhDevice)surf->dev,VK_FORMAT_S8_UINT,surf->dev->samples,surf->width,surf->height,VMA_MEMORY_USAGE_GPU_ONLY, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT); - - vkh_image_create_descriptor(surf->img, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT, VK_FILTER_NEAREST, VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_NEAREST,VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE); vkh_image_create_descriptor(surf->imgMS, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT, VK_FILTER_NEAREST, VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_NEAREST,VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE); vkh_image_create_descriptor(surf->stencilMS, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_STENCIL_BIT, VK_FILTER_NEAREST, VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_NEAREST,VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE); - +} +void _create_framebuffer (VkvgSurface surf) { VkImageView attachments[] = { vkh_image_get_view (surf->imgMS), vkh_image_get_view (surf->img), @@ -99,8 +100,15 @@ void _init_surface (VkvgSurface surf) { .height = surf->height, .layers = 1 }; VK_CHECK_RESULT(vkCreateFramebuffer(surf->dev->vkDev, &frameBufferCreateInfo, NULL, &surf->fb)); +} +void _init_surface (VkvgSurface surf) { + surf->format = FB_COLOR_FORMAT;//force bgra internally + + _create_surface_main_image (surf); + _create_surface_ms_images (surf); + _create_framebuffer (surf); - _clear_surface(surf, VK_IMAGE_ASPECT_STENCIL_BIT); + _clear_surface (surf, VK_IMAGE_ASPECT_STENCIL_BIT); } void vkvg_surface_clear (VkvgSurface surf) { _clear_surface(surf, VK_IMAGE_ASPECT_STENCIL_BIT|VK_IMAGE_ASPECT_COLOR_BIT); @@ -119,6 +127,29 @@ VkvgSurface vkvg_surface_create(VkvgDevice dev, uint32_t width, uint32_t height) return surf; } +VkvgSurface vkvg_surface_create_for_VkhImage (VkvgDevice dev, void* vkhImg) { + VkhImage img = (VkhImage)vkhImg; + VkvgSurface surf = (vkvg_surface*)calloc(1,sizeof(vkvg_surface)); + + surf->format = FB_COLOR_FORMAT;//force bgra internally + surf->dev = dev; + surf->width = img->infos.extent.width; + surf->height= img->infos.extent.height; + + surf->img = img; + + vkh_image_create_sampler(img, VK_FILTER_NEAREST, VK_FILTER_NEAREST, + VK_SAMPLER_MIPMAP_MODE_NEAREST,VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE); + + _create_surface_ms_images (surf); + _create_framebuffer (surf); + _clear_surface (surf, VK_IMAGE_ASPECT_STENCIL_BIT); + + surf->references = 1; + vkvg_device_reference (surf->dev); + + return surf; +} //TODO: it would be better to blit in original size and create ms final image with dest surf dims VkvgSurface vkvg_surface_create_from_bitmap (VkvgDevice dev, unsigned char* img, uint32_t width, uint32_t height) { VkvgSurface surf = (vkvg_surface*)calloc(1,sizeof(vkvg_surface)); @@ -242,7 +273,8 @@ void vkvg_surface_destroy(VkvgSurface surf) if (surf->references > 0) return; vkDestroyFramebuffer(surf->dev->vkDev, surf->fb, NULL); - vkh_image_destroy(surf->img); + if (!surf->img->imported) + vkh_image_destroy(surf->img); vkh_image_destroy(surf->imgMS); vkh_image_destroy(surf->stencilMS); diff --git a/tests/vkengine.c b/tests/vkengine.c index 1754ce5..148fc67 100644 --- a/tests/vkengine.c +++ b/tests/vkengine.c @@ -31,7 +31,12 @@ bool vkeCheckPhyPropBlitSource (VkEngine e) { VkFormatProperties formatProps; vkGetPhysicalDeviceFormatProperties(e->dev->phy, e->renderer->format, &formatProps); + +#if VKVG_TILING_OPTIMAL assert((formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT) && "Format cannot be used as transfer source"); +#else + assert((formatProps.linearTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT) && "Format cannot be used as transfer source"); +#endif } VkSampleCountFlagBits getMaxUsableSampleCount(VkSampleCountFlags counts) @@ -151,7 +156,7 @@ vk_engine_t* vkengine_create (VkPhysicalDeviceType preferedGPU, uint32_t width, static char const * dlay [] = {"VK_LAYER_LUNARG_standard_validation"}; #else uint32_t dlayCpt = 0; - static char const * dlay [] = {}; + static char const * dlay [] = {NULL}; #endif VkPhysicalDeviceFeatures enabledFeatures = { .fillModeNonSolid = true, @@ -175,9 +180,10 @@ vk_engine_t* vkengine_create (VkPhysicalDeviceType preferedGPU, uint32_t width, e->renderer = vkh_presenter_create (e->dev, pi->pQueue, surf, width, height, VK_FORMAT_B8G8R8A8_UNORM, VK_PRESENT_MODE_MAILBOX_KHR); - vkh_app_free_phyinfos (phyCount, phys); + vkeCheckPhyPropBlitSource (e); + return e; } diff --git a/vkh b/vkh index 311dac1..f2b18c9 160000 --- a/vkh +++ b/vkh @@ -1 +1 @@ -Subproject commit 311dac1b50ea5506a239f8b39450a2761d101fa2 +Subproject commit f2b18c96b0a919a35edaf13ee42593ee3ee55095