From fd36147749a248bc5696c3d41402a386cca0415e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 19 Feb 2023 12:25:13 +0900 Subject: [PATCH] [vulkan] Complete resource image and image view I don't remember why I kept the abbreviated configs for images and image views, but it because such that I need to be able to specify them completely. In addition, image views support external images. The rest was just cleaning up after the changes to qfv_resobj_t. --- include/QF/Vulkan/resource.h | 11 ++++- libs/models/iqm/vulkan_model_iqm.c | 6 ++- libs/video/renderer/vulkan/resource.c | 47 ++++++++++--------- libs/video/renderer/vulkan/vulkan_draw.c | 12 ++++- libs/video/renderer/vulkan/vulkan_lighting.c | 3 +- .../renderer/vulkan/vulkan_translucent.c | 6 ++- 6 files changed, 56 insertions(+), 29 deletions(-) diff --git a/include/QF/Vulkan/resource.h b/include/QF/Vulkan/resource.h index ac47d0609..74a5deb2e 100644 --- a/include/QF/Vulkan/resource.h +++ b/include/QF/Vulkan/resource.h @@ -31,23 +31,30 @@ typedef struct qfv_resobj_s { VkBufferView view; } buffer_view; struct { - int cubemap; + VkImageCreateFlags flags; VkImageType type; VkFormat format; VkExtent3D extent; uint32_t num_mipmaps; uint32_t num_layers; VkSampleCountFlags samples; + VkImageTiling tiling; VkImageUsageFlags usage; + VkSharingMode sharing; + uint32_t num_queue_inds; + const uint32_t *queue_inds; + VkImageLayout initialLayout; VkImage image; VkDeviceSize offset; } image; struct { unsigned image; + VkImage external_image; + VkImageViewCreateFlags flags; VkImageViewType type; VkFormat format; - VkImageAspectFlags aspect; VkComponentMapping components; + VkImageSubresourceRange subresourceRange; VkImageView view; } image_view; }; diff --git a/libs/models/iqm/vulkan_model_iqm.c b/libs/models/iqm/vulkan_model_iqm.c index 42f8f867b..b86e4108d 100644 --- a/libs/models/iqm/vulkan_model_iqm.c +++ b/libs/models/iqm/vulkan_model_iqm.c @@ -439,7 +439,11 @@ Vulkan_Mod_IQMFinish (model_t *mod, vulkan_ctx_t *ctx) .image = image_ind, .type = VK_IMAGE_VIEW_TYPE_2D, .format = mesh->mesh->objects[image_ind].image.format, - .aspect = VK_IMAGE_ASPECT_COLOR_BIT, + .subresourceRange = { + .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, + .levelCount = VK_REMAINING_MIP_LEVELS, + .layerCount = VK_REMAINING_ARRAY_LAYERS, + }, }, }; } diff --git a/libs/video/renderer/vulkan/resource.c b/libs/video/renderer/vulkan/resource.c index 029081f71..b2b56deae 100644 --- a/libs/video/renderer/vulkan/resource.c +++ b/libs/video/renderer/vulkan/resource.c @@ -42,17 +42,25 @@ create_image (qfv_device_t *device, qfv_resobj_t *image_obj) { qfv_devfuncs_t *dfunc = device->funcs; __auto_type image = &image_obj->image; + if (image->image) { + // the image was created externally and is being + return; + } VkImageCreateInfo createInfo = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, 0, - image->cubemap ? VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0, - image->type, image->format, image->extent, image->num_mipmaps, - image->num_layers, - image->samples, - VK_IMAGE_TILING_OPTIMAL, - image->usage, - VK_SHARING_MODE_EXCLUSIVE, - 0, 0, - VK_IMAGE_LAYOUT_UNDEFINED, + .flags = image->flags, + .imageType = image->type, + .format = image->format, + .extent = image->extent, + .mipLevels = image->num_mipmaps, + .arrayLayers = image->num_layers, + .samples = image->samples, + .tiling = image->tiling, + .usage = image->usage, + .sharingMode = image->sharing, + .queueFamilyIndexCount = image->num_queue_inds, + .pQueueFamilyIndices = image->queue_inds, + .initialLayout = image->initialLayout, }; dfunc->vkCreateImage (device->dev, &createInfo, 0, &image->image); } @@ -63,23 +71,17 @@ create_image_view (qfv_device_t *device, qfv_resobj_t *imgview_obj, { qfv_devfuncs_t *dfunc = device->funcs; __auto_type view = &imgview_obj->image_view; - __auto_type image = &imgobj->image; + VkImage image = view->external_image ? view->external_image + : imgobj->image.image; VkImageViewCreateInfo createInfo = { VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, 0, - //FIXME flags should be input for both image and image view - .flags = image->cubemap ? VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0, - .image = image->image, + .flags = view->flags, + .image = image, .viewType = view->type, .format = view->format, .components = view->components, - .subresourceRange = { - .aspectMask = view->aspect, - .baseMipLevel = 0, - .levelCount = VK_REMAINING_MIP_LEVELS, - .baseArrayLayer = 0, - .layerCount = VK_REMAINING_ARRAY_LAYERS, - }, + .subresourceRange = view->subresourceRange, }; dfunc->vkCreateImageView (device->dev, &createInfo, 0, &view->view); } @@ -137,8 +139,9 @@ QFV_CreateResource (qfv_device_t *device, qfv_resource_t *resource) { __auto_type imgview = &obj->image_view; __auto_type imgobj = &resource->objects[imgview->image]; - if (imgview->image >= resource->num_objects - || imgobj->type != qfv_res_image) { + if (!imgview->external_image + && (imgview->image >= resource->num_objects + || imgobj->type != qfv_res_image)) { Sys_Error ("%s:%s invalid image for view", resource->name, obj->name); } diff --git a/libs/video/renderer/vulkan/vulkan_draw.c b/libs/video/renderer/vulkan/vulkan_draw.c index ea0a10e3f..deaafb716 100644 --- a/libs/video/renderer/vulkan/vulkan_draw.c +++ b/libs/video/renderer/vulkan/vulkan_draw.c @@ -691,7 +691,11 @@ load_lmp (const char *path, vulkan_ctx_t *ctx) .image = 0, .type = VK_IMAGE_VIEW_TYPE_2D, .format = font->resource->glyph_image.image.format, - .aspect = VK_IMAGE_ASPECT_COLOR_BIT, + .subresourceRange = { + .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, + .levelCount = VK_REMAINING_MIP_LEVELS, + .layerCount = VK_REMAINING_ARRAY_LAYERS, + }, .components = { .r = VK_COMPONENT_SWIZZLE_IDENTITY, .g = VK_COMPONENT_SWIZZLE_IDENTITY, @@ -1649,7 +1653,11 @@ Vulkan_Draw_AddFont (font_t *rfont, vulkan_ctx_t *ctx) .image = 2, .type = VK_IMAGE_VIEW_TYPE_2D, .format = font->resource->glyph_image.image.format, - .aspect = VK_IMAGE_ASPECT_COLOR_BIT, + .subresourceRange = { + .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, + .levelCount = VK_REMAINING_MIP_LEVELS, + .layerCount = VK_REMAINING_ARRAY_LAYERS, + }, .components = { .r = VK_COMPONENT_SWIZZLE_R, .g = VK_COMPONENT_SWIZZLE_R, diff --git a/libs/video/renderer/vulkan/vulkan_lighting.c b/libs/video/renderer/vulkan/vulkan_lighting.c index 4439d1d32..33c8fc52b 100644 --- a/libs/video/renderer/vulkan/vulkan_lighting.c +++ b/libs/video/renderer/vulkan/vulkan_lighting.c @@ -790,11 +790,12 @@ build_shadow_maps (lightingctx_t *lctx, vulkan_ctx_t *ctx) .objects = (qfv_resobj_t *) &shad[1], }; for (int i = 0; i < numMaps; i++) { + int cube = maps[i].layers < 6 ? 0 : maps[i].cube; shad->objects[i] = (qfv_resobj_t) { .name = "map", .type = qfv_res_image, .image = { - .cubemap = maps[i].layers < 6 ? 0 : maps[i].cube, + .flags = cube ? VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0, .type = VK_IMAGE_TYPE_2D, .format = VK_FORMAT_X8_D24_UNORM_PACK32, .extent = { maps[i].size, maps[i].size, 1 }, diff --git a/libs/video/renderer/vulkan/vulkan_translucent.c b/libs/video/renderer/vulkan/vulkan_translucent.c index e99fba25f..541485ea1 100644 --- a/libs/video/renderer/vulkan/vulkan_translucent.c +++ b/libs/video/renderer/vulkan/vulkan_translucent.c @@ -194,7 +194,11 @@ Vulkan_Translucent_CreateBuffers (vulkan_ctx_t *ctx, VkExtent2D extent) .image = i, .type = VK_IMAGE_VIEW_TYPE_2D_ARRAY, .format = VK_FORMAT_R32_SINT, - .aspect = VK_IMAGE_ASPECT_COLOR_BIT, + .subresourceRange = { + .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, + .levelCount = VK_REMAINING_MIP_LEVELS, + .layerCount = VK_REMAINING_ARRAY_LAYERS, + }, }, }; buffer_objs[i] = (qfv_resobj_t) {