[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.
This commit is contained in:
Bill Currie 2023-02-19 12:25:13 +09:00
parent ed74a6420b
commit fd36147749
6 changed files with 56 additions and 29 deletions

View file

@ -31,23 +31,30 @@ typedef struct qfv_resobj_s {
VkBufferView view; VkBufferView view;
} buffer_view; } buffer_view;
struct { struct {
int cubemap; VkImageCreateFlags flags;
VkImageType type; VkImageType type;
VkFormat format; VkFormat format;
VkExtent3D extent; VkExtent3D extent;
uint32_t num_mipmaps; uint32_t num_mipmaps;
uint32_t num_layers; uint32_t num_layers;
VkSampleCountFlags samples; VkSampleCountFlags samples;
VkImageTiling tiling;
VkImageUsageFlags usage; VkImageUsageFlags usage;
VkSharingMode sharing;
uint32_t num_queue_inds;
const uint32_t *queue_inds;
VkImageLayout initialLayout;
VkImage image; VkImage image;
VkDeviceSize offset; VkDeviceSize offset;
} image; } image;
struct { struct {
unsigned image; unsigned image;
VkImage external_image;
VkImageViewCreateFlags flags;
VkImageViewType type; VkImageViewType type;
VkFormat format; VkFormat format;
VkImageAspectFlags aspect;
VkComponentMapping components; VkComponentMapping components;
VkImageSubresourceRange subresourceRange;
VkImageView view; VkImageView view;
} image_view; } image_view;
}; };

View file

@ -439,7 +439,11 @@ Vulkan_Mod_IQMFinish (model_t *mod, vulkan_ctx_t *ctx)
.image = image_ind, .image = image_ind,
.type = VK_IMAGE_VIEW_TYPE_2D, .type = VK_IMAGE_VIEW_TYPE_2D,
.format = mesh->mesh->objects[image_ind].image.format, .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,
},
}, },
}; };
} }

View file

@ -42,17 +42,25 @@ create_image (qfv_device_t *device, qfv_resobj_t *image_obj)
{ {
qfv_devfuncs_t *dfunc = device->funcs; qfv_devfuncs_t *dfunc = device->funcs;
__auto_type image = &image_obj->image; __auto_type image = &image_obj->image;
if (image->image) {
// the image was created externally and is being
return;
}
VkImageCreateInfo createInfo = { VkImageCreateInfo createInfo = {
VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, 0, VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, 0,
image->cubemap ? VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0, .flags = image->flags,
image->type, image->format, image->extent, image->num_mipmaps, .imageType = image->type,
image->num_layers, .format = image->format,
image->samples, .extent = image->extent,
VK_IMAGE_TILING_OPTIMAL, .mipLevels = image->num_mipmaps,
image->usage, .arrayLayers = image->num_layers,
VK_SHARING_MODE_EXCLUSIVE, .samples = image->samples,
0, 0, .tiling = image->tiling,
VK_IMAGE_LAYOUT_UNDEFINED, .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); 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; qfv_devfuncs_t *dfunc = device->funcs;
__auto_type view = &imgview_obj->image_view; __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 = { VkImageViewCreateInfo createInfo = {
VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, 0, VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, 0,
//FIXME flags should be input for both image and image view .flags = view->flags,
.flags = image->cubemap ? VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0, .image = image,
.image = image->image,
.viewType = view->type, .viewType = view->type,
.format = view->format, .format = view->format,
.components = view->components, .components = view->components,
.subresourceRange = { .subresourceRange = view->subresourceRange,
.aspectMask = view->aspect,
.baseMipLevel = 0,
.levelCount = VK_REMAINING_MIP_LEVELS,
.baseArrayLayer = 0,
.layerCount = VK_REMAINING_ARRAY_LAYERS,
},
}; };
dfunc->vkCreateImageView (device->dev, &createInfo, 0, &view->view); 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 imgview = &obj->image_view;
__auto_type imgobj = &resource->objects[imgview->image]; __auto_type imgobj = &resource->objects[imgview->image];
if (imgview->image >= resource->num_objects if (!imgview->external_image
|| imgobj->type != qfv_res_image) { && (imgview->image >= resource->num_objects
|| imgobj->type != qfv_res_image)) {
Sys_Error ("%s:%s invalid image for view", Sys_Error ("%s:%s invalid image for view",
resource->name, obj->name); resource->name, obj->name);
} }

View file

@ -691,7 +691,11 @@ load_lmp (const char *path, vulkan_ctx_t *ctx)
.image = 0, .image = 0,
.type = VK_IMAGE_VIEW_TYPE_2D, .type = VK_IMAGE_VIEW_TYPE_2D,
.format = font->resource->glyph_image.image.format, .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 = { .components = {
.r = VK_COMPONENT_SWIZZLE_IDENTITY, .r = VK_COMPONENT_SWIZZLE_IDENTITY,
.g = 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, .image = 2,
.type = VK_IMAGE_VIEW_TYPE_2D, .type = VK_IMAGE_VIEW_TYPE_2D,
.format = font->resource->glyph_image.image.format, .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 = { .components = {
.r = VK_COMPONENT_SWIZZLE_R, .r = VK_COMPONENT_SWIZZLE_R,
.g = VK_COMPONENT_SWIZZLE_R, .g = VK_COMPONENT_SWIZZLE_R,

View file

@ -790,11 +790,12 @@ build_shadow_maps (lightingctx_t *lctx, vulkan_ctx_t *ctx)
.objects = (qfv_resobj_t *) &shad[1], .objects = (qfv_resobj_t *) &shad[1],
}; };
for (int i = 0; i < numMaps; i++) { for (int i = 0; i < numMaps; i++) {
int cube = maps[i].layers < 6 ? 0 : maps[i].cube;
shad->objects[i] = (qfv_resobj_t) { shad->objects[i] = (qfv_resobj_t) {
.name = "map", .name = "map",
.type = qfv_res_image, .type = qfv_res_image,
.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, .type = VK_IMAGE_TYPE_2D,
.format = VK_FORMAT_X8_D24_UNORM_PACK32, .format = VK_FORMAT_X8_D24_UNORM_PACK32,
.extent = { maps[i].size, maps[i].size, 1 }, .extent = { maps[i].size, maps[i].size, 1 },

View file

@ -194,7 +194,11 @@ Vulkan_Translucent_CreateBuffers (vulkan_ctx_t *ctx, VkExtent2D extent)
.image = i, .image = i,
.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY, .type = VK_IMAGE_VIEW_TYPE_2D_ARRAY,
.format = VK_FORMAT_R32_SINT, .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) { buffer_objs[i] = (qfv_resobj_t) {