feat(vk): Create image views for texture2d resources
This commit is contained in:
		
							parent
							
								
									033eac90bb
								
							
						
					
					
						commit
						823b9ef9af
					
				@ -272,16 +272,44 @@ rt_result rtVkPhysicalResourceManagerCreateTexture2D(void *o, rt_render_resource
 | 
				
			|||||||
        rtLog("VK", "Failed to create image.");
 | 
					        rtLog("VK", "Failed to create image.");
 | 
				
			||||||
        return RT_UNKNOWN_ERROR;
 | 
					        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 */
 | 
					    /* Store */
 | 
				
			||||||
    rt_result res = RT_SUCCESS;
 | 
					    rt_result res = RT_SUCCESS;
 | 
				
			||||||
    rtLockWrite(&phys_res_mgr->lock);
 | 
					    rtLockWrite(&phys_res_mgr->lock);
 | 
				
			||||||
    uint32_t slot = AllocStorageSlot(phys_res_mgr, h);
 | 
					    uint32_t slot = AllocStorageSlot(phys_res_mgr, h);
 | 
				
			||||||
    if (slot != UINT32_MAX) {
 | 
					    if (slot != UINT32_MAX) {
 | 
				
			||||||
        phys_res_mgr->resources[slot].type = RT_RENDER_RESOURCE_TYPE_BUFFER;
 | 
					        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;
 | 
					        phys_res_mgr->resources[slot].allocation = allocation;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        res = RT_OUT_OF_MEMORY;
 | 
					        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);
 | 
					        vmaDestroyImage(phys_res_mgr->allocator, image, allocation);
 | 
				
			||||||
        rtLog("VK","Could not create image because no storage space is available.");
 | 
					        rtLog("VK","Could not create image because no storage space is available.");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -21,7 +21,10 @@ typedef struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    union {
 | 
					    union {
 | 
				
			||||||
        VkBuffer buffer;
 | 
					        VkBuffer buffer;
 | 
				
			||||||
 | 
					        struct {
 | 
				
			||||||
            VkImage image;
 | 
					            VkImage image;
 | 
				
			||||||
 | 
					            VkImageView view;
 | 
				
			||||||
 | 
					        } texture2d;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
} rt_vk_physical_resource;
 | 
					} rt_vk_physical_resource;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user