kiba-engine
depth.c
1 #include <kiba/renderer/vulkan/depth.h>
2 
3 #include <kiba/renderer/vulkan/image.h>
4 
5 VkFormat vulkan_depth_fitting_format(vulkan_context *context) {
6  VkFormat candidates[] = {
7  VK_FORMAT_D32_SFLOAT,
8  VK_FORMAT_D32_SFLOAT_S8_UINT,
9  VK_FORMAT_D24_UNORM_S8_UINT,
10  };
11  return vulkan_image_fitting_format(context,
12  candidates,
13  sizeof(candidates) / sizeof(candidates[0]),
14  VK_IMAGE_TILING_OPTIMAL,
15  VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
16 }
17 
18 /*static b8 vulkan_depth_format_has_stencil_component(VkFormat format) {
19  return format == VK_FORMAT_D32_SFLOAT_S8_UINT || format == VK_FORMAT_D24_UNORM_S8_UINT;
20 }*/
21 
22 b8 vulkan_depth_create(vulkan_context *context) {
23  const VkFormat format = vulkan_depth_fitting_format(context);
24  if (!vulkan_image_create(context,
25  context->swap_chain.extent.width,
26  context->swap_chain.extent.height,
27  format,
28  VK_IMAGE_TILING_OPTIMAL,
29  VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
30  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
31  &context->depth.image)) {
32  KB_ERROR("cannot create image for depth attachment");
33  return false;
34  }
35  if (!vulkan_image_view_create(context,
36  context->depth.image.image,
37  format,
38  VK_IMAGE_ASPECT_DEPTH_BIT,
39  &context->depth.view)) {
40  KB_ERROR("cannot create image view for depth attachment");
41  }
42  return true;
43 }
44 
45 void vulkan_depth_destroy(vulkan_context *context) {
46  vulkan_image_view_destroy(context, &context->depth.view);
47  vulkan_image_destroy(context, &context->depth.image);
48 }
#define KB_ERROR(...)
Log entry with error log level.
Definition: log.h:142