WIP: Vulkan: Workbench #107886
|
@ -243,6 +243,7 @@ static ConversionType type_of_conversion_uint(eGPUTextureFormat device_format)
|
|||
case GPU_RG32UI:
|
||||
case GPU_R32UI:
|
||||
case GPU_DEPTH_COMPONENT24:
|
||||
case GPU_DEPTH24_STENCIL8:
|
||||
return ConversionType::PASS_THROUGH;
|
||||
|
||||
case GPU_RGBA16UI:
|
||||
|
@ -284,7 +285,6 @@ static ConversionType type_of_conversion_uint(eGPUTextureFormat device_format)
|
|||
case GPU_RGB10_A2:
|
||||
case GPU_RGB10_A2UI:
|
||||
case GPU_R11F_G11F_B10F:
|
||||
case GPU_DEPTH24_STENCIL8:
|
||||
case GPU_SRGB8_A8:
|
||||
case GPU_RGBA8_SNORM:
|
||||
case GPU_RGBA16_SNORM:
|
||||
|
|
|
@ -403,6 +403,7 @@ void VKFrameBuffer::render_pass_create()
|
|||
VKTexture &texture = *static_cast<VKTexture *>(unwrap(attachment.tex));
|
||||
texture.ensure_allocated();
|
||||
/* TODO: use image_view for attachment.mip */
|
||||
// texture.mip_range_set(attachment.mip, attachment.mip);
|
||||
image_views[attachment_location] = texture.vk_image_view_handle();
|
||||
|
||||
VkAttachmentDescription &attachment_description =
|
||||
|
@ -412,8 +413,8 @@ void VKFrameBuffer::render_pass_create()
|
|||
attachment_description.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
attachment_description.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
attachment_description.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
attachment_description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
attachment_description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
attachment_description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
attachment_description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
attachment_description.initialLayout = texture.current_layout_get();
|
||||
attachment_description.finalLayout = texture.current_layout_get();
|
||||
|
||||
|
@ -468,8 +469,11 @@ void VKFrameBuffer::render_pass_create()
|
|||
render_pass_info.pSubpasses = &subpass;
|
||||
|
||||
const VKDevice &device = VKBackend::get().device_get();
|
||||
vkCreateRenderPass(
|
||||
VkResult result = vkCreateRenderPass(
|
||||
device.device_get(), &render_pass_info, vk_allocation_callbacks, &vk_render_pass_);
|
||||
if (result != VK_SUCCESS) {
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
/* We might want to split frame-buffer and render pass. */
|
||||
VkFramebufferCreateInfo framebuffer_create_info = {};
|
||||
|
@ -481,8 +485,11 @@ void VKFrameBuffer::render_pass_create()
|
|||
framebuffer_create_info.height = height_;
|
||||
framebuffer_create_info.layers = 1;
|
||||
|
||||
vkCreateFramebuffer(
|
||||
result = vkCreateFramebuffer(
|
||||
device.device_get(), &framebuffer_create_info, vk_allocation_callbacks, &vk_framebuffer_);
|
||||
if (result != VK_SUCCESS) {
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
void VKFrameBuffer::render_pass_free()
|
||||
|
|
|
@ -83,6 +83,9 @@ void VKTexture::generate_mipmap()
|
|||
*this,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
Span<VkImageBlit>(&image_blit, 1));
|
||||
/* TODO: Until we do actual command encoding we need to submit each transfer operation
|
||||
* individually. */
|
||||
command_buffer.submit();
|
||||
}
|
||||
/* Ensure that all mipmap levels are in `VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL`. All miplevels are
|
||||
* except the last one. */
|
||||
|
@ -148,9 +151,12 @@ void VKTexture::swizzle_set(const char /*swizzle_mask*/[4])
|
|||
NOT_YET_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void VKTexture::mip_range_set(int /*min*/, int /*max*/)
|
||||
void VKTexture::mip_range_set(int min, int max)
|
||||
{
|
||||
NOT_YET_IMPLEMENTED;
|
||||
mip_min_ = min;
|
||||
mip_max_ = max;
|
||||
|
||||
flags_ |= IMAGE_VIEW_DIRTY;
|
||||
}
|
||||
|
||||
void VKTexture::read_sub(int mip, eGPUDataFormat format, const int area[4], void *r_data)
|
||||
|
@ -430,20 +436,6 @@ bool VKTexture::allocate()
|
|||
/* Promote image to the correct layout. */
|
||||
layout_ensure(context, VK_IMAGE_LAYOUT_GENERAL);
|
||||
|
||||
VK_ALLOCATION_CALLBACKS
|
||||
VkImageViewCreateInfo image_view_info = {};
|
||||
image_view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
image_view_info.image = vk_image_;
|
||||
image_view_info.viewType = to_vk_image_view_type(type_);
|
||||
image_view_info.format = to_vk_format(format_);
|
||||
image_view_info.components = to_vk_component_mapping(format_);
|
||||
image_view_info.subresourceRange.aspectMask = to_vk_image_aspect_flag_bits(format_);
|
||||
image_view_info.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
|
||||
image_view_info.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
||||
|
||||
result = vkCreateImageView(
|
||||
device.device_get(), &image_view_info, vk_allocation_callbacks, &vk_image_view_);
|
||||
debug::object_label(vk_image_view_, name_);
|
||||
return result == VK_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -527,4 +519,57 @@ void VKTexture::layout_ensure(VKContext &context,
|
|||
}
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Mipmapping
|
||||
* \{ */
|
||||
|
||||
void VKTexture::vk_image_view_ensure()
|
||||
{
|
||||
if (flags_ & IMAGE_VIEW_DIRTY) {
|
||||
vk_image_view_free();
|
||||
vk_image_view_create();
|
||||
flags_ &= ~IMAGE_VIEW_DIRTY;
|
||||
}
|
||||
BLI_assert(vk_image_view_ != VK_NULL_HANDLE);
|
||||
}
|
||||
|
||||
void VKTexture::vk_image_view_free()
|
||||
{
|
||||
if (vk_image_view_ != VK_NULL_HANDLE) {
|
||||
VK_ALLOCATION_CALLBACKS
|
||||
const VKDevice &device = VKBackend::get().device_get();
|
||||
vkDestroyImageView(device.device_get(), vk_image_view_, vk_allocation_callbacks);
|
||||
vk_image_view_ = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
void VKTexture::vk_image_view_create()
|
||||
{
|
||||
BLI_assert(vk_image_view_ == VK_NULL_HANDLE);
|
||||
VK_ALLOCATION_CALLBACKS
|
||||
VkImageViewCreateInfo image_view_info = {};
|
||||
image_view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
image_view_info.image = vk_image_;
|
||||
image_view_info.viewType = to_vk_image_view_type(type_);
|
||||
image_view_info.format = to_vk_format(format_);
|
||||
image_view_info.components = to_vk_component_mapping(format_);
|
||||
image_view_info.subresourceRange.aspectMask = to_vk_image_aspect_flag_bits(format_);
|
||||
IndexRange mip_range = mip_map_range();
|
||||
image_view_info.subresourceRange.baseMipLevel = mip_range.first();
|
||||
image_view_info.subresourceRange.levelCount = mip_range.size();
|
||||
image_view_info.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
||||
|
||||
const VKDevice &device = VKBackend::get().device_get();
|
||||
vkCreateImageView(
|
||||
device.device_get(), &image_view_info, vk_allocation_callbacks, &vk_image_view_);
|
||||
debug::object_label(vk_image_view_, name_);
|
||||
}
|
||||
|
||||
IndexRange VKTexture::mip_map_range() const
|
||||
{
|
||||
return IndexRange(mip_min_, mip_max_ - mip_min_ + 1);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
} // namespace blender::gpu
|
||||
|
|
|
@ -26,6 +26,10 @@ class VKTexture : public Texture {
|
|||
* can be done. */
|
||||
VkImageLayout current_layout_ = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
|
||||
const int IMAGE_VIEW_DIRTY = (1 << 0);
|
||||
|
||||
int flags_ = IMAGE_VIEW_DIRTY;
|
||||
|
||||
public:
|
||||
VKTexture(const char *name) : Texture(name) {}
|
||||
|
||||
|
@ -58,11 +62,6 @@ class VKTexture : public Texture {
|
|||
BLI_assert(vk_image_ != VK_NULL_HANDLE);
|
||||
return vk_image_;
|
||||
}
|
||||
VkImageView vk_image_view_handle() const
|
||||
{
|
||||
BLI_assert(is_allocated());
|
||||
return vk_image_view_;
|
||||
}
|
||||
|
||||
void ensure_allocated();
|
||||
|
||||
|
@ -123,6 +122,24 @@ class VKTexture : public Texture {
|
|||
VkImageLayout requested_layout);
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Mipmapping
|
||||
* \{ */
|
||||
public:
|
||||
VkImageView vk_image_view_handle()
|
||||
{
|
||||
vk_image_view_ensure();
|
||||
return vk_image_view_;
|
||||
}
|
||||
|
||||
private:
|
||||
IndexRange mip_map_range() const;
|
||||
void vk_image_view_ensure();
|
||||
void vk_image_view_free();
|
||||
void vk_image_view_create();
|
||||
|
||||
/** \} */
|
||||
};
|
||||
|
||||
static inline VKTexture *unwrap(Texture *tex)
|
||||
|
|
Loading…
Reference in New Issue