diff --git a/src/xrt/compositor/client/comp_gl_client.c b/src/xrt/compositor/client/comp_gl_client.c index 91adfe51b..fae2c4760 100644 --- a/src/xrt/compositor/client/comp_gl_client.c +++ b/src/xrt/compositor/client/comp_gl_client.c @@ -260,6 +260,10 @@ gl_format_to_vk(int64_t format) case GL_SRGB8_ALPHA8: return 43 /*VK_FORMAT_R8G8B8A8_SRGB*/; case GL_RGB10_A2: return 64 /*VK_FORMAT_A2B10G10R10_UNORM_PACK32*/; case GL_RGBA16F: return 97 /*VK_FORMAT_R16G16B16A16_SFLOAT*/; + case GL_DEPTH_COMPONENT16: return 124 /*VK_FORMAT_D16_UNORM*/; + case GL_DEPTH_COMPONENT32F: return 126 /*VK_FORMAT_D32_SFLOAT*/; + case GL_DEPTH24_STENCIL8: return 129 /*VK_FORMAT_D24_UNORM_S8_UINT*/; + case GL_DEPTH32F_STENCIL8: return 130 /*VK_FORMAT_D32_SFLOAT_S8_UINT*/; default: return 0; } } @@ -274,6 +278,10 @@ vk_format_to_gl(int64_t format) case 50 /*VK_FORMAT_B8G8R8A8_SRGB*/: return 0; case 64 /*VK_FORMAT_A2B10G10R10_UNORM_PACK32*/: return GL_RGB10_A2; case 97 /*VK_FORMAT_R16G16B16A16_SFLOAT*/: return GL_RGBA16F; + case 124 /*VK_FORMAT_D16_UNORM*/: return GL_DEPTH_COMPONENT16; + case 126 /*VK_FORMAT_D32_SFLOAT*/: return GL_DEPTH_COMPONENT32F; + case 129 /*VK_FORMAT_D24_UNORM_S8_UINT*/: return GL_DEPTH24_STENCIL8; + case 130 /*VK_FORMAT_D32_SFLOAT_S8_UINT*/: return GL_DEPTH32F_STENCIL8; default: printf("Cannot convert VK format 0x%016" PRIx64 " to GL format!\n", diff --git a/src/xrt/compositor/main/comp_compositor.c b/src/xrt/compositor/main/comp_compositor.c index 304b3f542..cb4b9caa6 100644 --- a/src/xrt/compositor/main/comp_compositor.c +++ b/src/xrt/compositor/main/comp_compositor.c @@ -1150,13 +1150,26 @@ xrt_gfx_provider_create_native(struct xrt_device *xdev) * two formats should not be used as they are linear but doesn't have * enough bits to express it without resulting in banding. */ - info->formats[0] = VK_FORMAT_R8G8B8A8_SRGB; // OGL VK - info->formats[1] = VK_FORMAT_A2B10G10R10_UNORM_PACK32; // OGL VK - info->formats[2] = VK_FORMAT_R16G16B16A16_SFLOAT; // OGL VK - info->formats[3] = VK_FORMAT_B8G8R8A8_SRGB; // VK - info->formats[4] = VK_FORMAT_R8G8B8A8_UNORM; // OGL VK - info->formats[5] = VK_FORMAT_B8G8R8A8_UNORM; // VK - info->num_formats = 6; + uint32_t formats = 0; + + // color formats + info->formats[formats++] = VK_FORMAT_R8G8B8A8_SRGB; // OGL VK + info->formats[formats++] = VK_FORMAT_A2B10G10R10_UNORM_PACK32; // OGL VK + info->formats[formats++] = VK_FORMAT_R16G16B16A16_SFLOAT; // OGL VK + info->formats[formats++] = VK_FORMAT_B8G8R8A8_SRGB; // VK + info->formats[formats++] = VK_FORMAT_R8G8B8A8_UNORM; // OGL VK + info->formats[formats++] = VK_FORMAT_B8G8R8A8_UNORM; // VK + + // depth formats + info->formats[formats++] = VK_FORMAT_D16_UNORM; // OGL VK + info->formats[formats++] = VK_FORMAT_D32_SFLOAT; // OGL VK + + // depth stencil formats + info->formats[formats++] = VK_FORMAT_D24_UNORM_S8_UINT; // OGL VK + info->formats[formats++] = VK_FORMAT_D32_SFLOAT_S8_UINT; // OGL VK + + assert(formats <= XRT_MAX_SWAPCHAIN_FORMATS); + info->num_formats = formats; float scale = c->settings.viewport_scale; diff --git a/src/xrt/compositor/main/comp_swapchain.c b/src/xrt/compositor/main/comp_swapchain.c index 863e64f3a..51f068647 100644 --- a/src/xrt/compositor/main/comp_swapchain.c +++ b/src/xrt/compositor/main/comp_swapchain.c @@ -105,9 +105,9 @@ alloc_and_set_funcs(struct comp_compositor *c, uint32_t num_images) static void do_post_create_vulkan_setup(struct comp_compositor *c, + const struct xrt_swapchain_create_info *info, struct comp_swapchain *sc) { - struct xrt_swapchain_create_info *info = &sc->vkic.info; uint32_t num_images = sc->vkic.num_images; VkCommandBuffer cmd_buffer; @@ -118,6 +118,10 @@ do_post_create_vulkan_setup(struct comp_compositor *c, .a = VK_COMPONENT_SWIZZLE_ONE, }; + bool depth = (info->bits & XRT_SWAPCHAIN_USAGE_DEPTH_STENCIL) != 0; + VkImageAspectFlagBits aspect = + depth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; + for (uint32_t i = 0; i < num_images; i++) { sc->images[i].views.alpha = U_TYPED_ARRAY_CALLOC(VkImageView, info->array_size); @@ -128,9 +132,10 @@ do_post_create_vulkan_setup(struct comp_compositor *c, vk_create_sampler(&c->vk, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, &sc->images[i].sampler); + for (uint32_t layer = 0; layer < info->array_size; ++layer) { VkImageSubresourceRange subresource_range = { - .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, + .aspectMask = aspect, .baseMipLevel = 0, .levelCount = 1, .baseArrayLayer = layer, @@ -163,7 +168,7 @@ do_post_create_vulkan_setup(struct comp_compositor *c, vk_init_cmd_buffer(&c->vk, &cmd_buffer); VkImageSubresourceRange subresource_range = { - .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, + .aspectMask = aspect, .baseMipLevel = 0, .levelCount = 1, .baseArrayLayer = 0, @@ -274,7 +279,7 @@ comp_swapchain_create(struct xrt_compositor *xc, sc->base.images[i].size = sc->vkic.images[i].size; } - do_post_create_vulkan_setup(c, sc); + do_post_create_vulkan_setup(c, info, sc); *out_xsc = &sc->base.base; @@ -303,7 +308,7 @@ comp_swapchain_import(struct xrt_compositor *xc, return XRT_ERROR_VULKAN; } - do_post_create_vulkan_setup(c, sc); + do_post_create_vulkan_setup(c, info, sc); *out_xsc = &sc->base.base; diff --git a/src/xrt/include/xrt/xrt_compositor.h b/src/xrt/include/xrt/xrt_compositor.h index 9aa6885fc..cc6fbdb1d 100644 --- a/src/xrt/include/xrt/xrt_compositor.h +++ b/src/xrt/include/xrt/xrt_compositor.h @@ -49,7 +49,7 @@ typedef uint64_t VkDeviceMemory; /*! * Max formats supported by a compositor, artificial limit. */ -#define XRT_MAX_SWAPCHAIN_FORMATS 8 +#define XRT_MAX_SWAPCHAIN_FORMATS 16 /*! * Special flags for creating swapchain images.