feat(vk): Create image views for texture2d resources
Some checks failed
Ubuntu Cross to Win64 / Cross Compile with ming64 (1.4.0, ubuntu-latest) (push) Failing after 1m46s
Ubuntu Cross to Win64 / Compile for linux (1.4.0, ubuntu-latest) (push) Successful in 1m24s

This commit is contained in:
Kevin Trogant 2024-08-03 14:43:11 +02:00
parent 033eac90bb
commit 823b9ef9af
2 changed files with 33 additions and 2 deletions

View File

@ -272,16 +272,44 @@ rt_result rtVkPhysicalResourceManagerCreateTexture2D(void *o, rt_render_resource
rtLog("VK", "Failed to create image.");
return RT_UNKNOWN_ERROR;
}
VkImageViewCreateInfo view_info ={
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
.format = format,
.viewType = VK_IMAGE_VIEW_TYPE_2D,
.subresourceRange = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.levelCount = 1,
.baseMipLevel = 0,
.layerCount = 1,
.baseArrayLayer = 0
},
.components = {
.r = VK_COMPONENT_SWIZZLE_IDENTITY,
.g = VK_COMPONENT_SWIZZLE_IDENTITY,
.b = VK_COMPONENT_SWIZZLE_IDENTITY,
.a = VK_COMPONENT_SWIZZLE_IDENTITY
},
};
VkImageView view;
if (vkCreateImageView(phys_res_mgr->dev->device, &view_info, phys_res_mgr->dev->alloc_cb, &view) != VK_SUCCESS) {
vmaDestroyImage(phys_res_mgr->allocator, image, allocation);
rtLog("VK","Failed to create image view.");
return RT_UNKNOWN_ERROR;
}
/* Store */
rt_result res = RT_SUCCESS;
rtLockWrite(&phys_res_mgr->lock);
uint32_t slot = AllocStorageSlot(phys_res_mgr, h);
if (slot != UINT32_MAX) {
phys_res_mgr->resources[slot].type = RT_RENDER_RESOURCE_TYPE_BUFFER;
phys_res_mgr->resources[slot].image = image;
phys_res_mgr->resources[slot].texture2d.image = image;
phys_res_mgr->resources[slot].texture2d.view = view;
phys_res_mgr->resources[slot].allocation = allocation;
} else {
res = RT_OUT_OF_MEMORY;
vkDestroyImageView(phys_res_mgr->dev->device, view, phys_res_mgr->dev->alloc_cb);
vmaDestroyImage(phys_res_mgr->allocator, image, allocation);
rtLog("VK","Could not create image because no storage space is available.");
}

View File

@ -21,7 +21,10 @@ typedef struct {
union {
VkBuffer buffer;
VkImage image;
struct {
VkImage image;
VkImageView view;
} texture2d;
};
} rt_vk_physical_resource;