From f6b8cb25b86aa70dac92e3cda22c3e60d77adf8a Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Tue, 30 Apr 2019 08:22:19 -0700 Subject: [PATCH] comp: Respect swapchain array size --- src/xrt/compositor/client/comp_gl_client.c | 15 ++++++++---- src/xrt/compositor/client/comp_vk_client.c | 10 ++++---- src/xrt/compositor/common/comp_vk.c | 13 ++++------ src/xrt/compositor/common/comp_vk.h | 2 ++ src/xrt/compositor/main/comp_renderer.c | 2 +- src/xrt/compositor/main/comp_swapchain.c | 28 ++++++++++++---------- 6 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/xrt/compositor/client/comp_gl_client.c b/src/xrt/compositor/client/comp_gl_client.c index 59d1cab28..edaac04f7 100644 --- a/src/xrt/compositor/client/comp_gl_client.c +++ b/src/xrt/compositor/client/comp_gl_client.c @@ -195,7 +195,8 @@ client_gl_swapchain_create(struct xrt_compositor *xc, sc->base.base.num_images = num_images; sc->xscfd = xrt_swapchain_fd(xsc); - glCreateTextures(GL_TEXTURE_2D, num_images, &sc->base.images[0]); + glCreateTextures(array_size == 1 ? GL_TEXTURE_2D : GL_TEXTURE_2D_ARRAY, + num_images, &sc->base.images[0]); glCreateMemoryObjectsEXT(num_images, &sc->base.memory[0]); for (uint32_t i = 0; i < num_images; i++) { GLint dedicated = GL_TRUE; @@ -205,9 +206,15 @@ client_gl_swapchain_create(struct xrt_compositor *xc, glImportMemoryFdEXT( sc->base.memory[i], sc->xscfd->images[i].size, GL_HANDLE_TYPE_OPAQUE_FD_EXT, sc->xscfd->images[i].fd); - glTextureStorageMem2DEXT(sc->base.images[i], mip_count, - (GLuint)format, width, height, - sc->base.memory[i], 0); + if (array_size == 1) { + glTextureStorageMem2DEXT(sc->base.images[i], mip_count, + (GLuint)format, width, height, + sc->base.memory[i], 0); + } else { + glTextureStorageMem3DEXT( + sc->base.images[i], mip_count, (GLuint)format, + width, height, array_size, sc->base.memory[i], 0); + } } return &sc->base.base; diff --git a/src/xrt/compositor/client/comp_vk_client.c b/src/xrt/compositor/client/comp_vk_client.c index d86dcf2bc..ad6a583ab 100644 --- a/src/xrt/compositor/client/comp_vk_client.c +++ b/src/xrt/compositor/client/comp_vk_client.c @@ -203,7 +203,7 @@ client_vk_swapchain_create(struct xrt_compositor *xc, .baseMipLevel = 0, .levelCount = 1, .baseArrayLayer = 0, - .layerCount = 1, + .layerCount = array_size, }; struct client_vk_swapchain *sc = @@ -217,10 +217,10 @@ client_vk_swapchain_create(struct xrt_compositor *xc, sc->xscfd = xrt_swapchain_fd(xsc); for (uint32_t i = 0; i < num_images; i++) { - ret = vk_create_image_from_fd(&c->vk, format, width, height, - mip_count, &sc->xscfd->images[i], - &sc->base.images[i], - &sc->base.mems[i]); + ret = vk_create_image_from_fd( + &c->vk, format, width, height, array_size, mip_count, + &sc->xscfd->images[i], &sc->base.images[i], + &sc->base.mems[i]); if (ret != VK_SUCCESS) { return NULL; } diff --git a/src/xrt/compositor/common/comp_vk.c b/src/xrt/compositor/common/comp_vk.c index 269d6b5c2..2244328ca 100644 --- a/src/xrt/compositor/common/comp_vk.c +++ b/src/xrt/compositor/common/comp_vk.c @@ -239,6 +239,7 @@ vk_create_image_from_fd(struct vk_bundle *vk, int64_t format, uint32_t width, uint32_t height, + uint32_t array_size, uint32_t mip_count, struct xrt_image_fd *image_fd, VkImage *out_image, @@ -267,7 +268,7 @@ vk_create_image_from_fd(struct vk_bundle *vk, .format = (VkFormat)format, .extent = {.width = width, .height = height, .depth = 1}, .mipLevels = mip_count, - .arrayLayers = 1, + .arrayLayers = array_size, .samples = VK_SAMPLE_COUNT_1_BIT, .tiling = VK_IMAGE_TILING_OPTIMAL, .usage = image_usage, @@ -389,6 +390,7 @@ VkResult vk_create_view(struct vk_bundle *vk, VkImage image, VkFormat format, + VkImageSubresourceRange subresource_range, VkImageView *out_view) { VkImageView view; @@ -408,14 +410,7 @@ vk_create_view(struct vk_bundle *vk, .b = VK_COMPONENT_SWIZZLE_B, .a = VK_COMPONENT_SWIZZLE_A, }, - .subresourceRange = - { - .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, - .baseMipLevel = 0, - .levelCount = 1, - .baseArrayLayer = 0, - .layerCount = 1, - }, + .subresourceRange = subresource_range, }; ret = vk->vkCreateImageView(vk->device, &imageView, NULL, &view); diff --git a/src/xrt/compositor/common/comp_vk.h b/src/xrt/compositor/common/comp_vk.h index e6486fd30..99f2e2f9e 100644 --- a/src/xrt/compositor/common/comp_vk.h +++ b/src/xrt/compositor/common/comp_vk.h @@ -284,6 +284,7 @@ vk_create_image_from_fd(struct vk_bundle *vk, int64_t format, uint32_t width, uint32_t height, + uint32_t array_size, uint32_t mip_count, struct xrt_image_fd *image_fd, VkImage *out_image, @@ -313,6 +314,7 @@ VkResult vk_create_view(struct vk_bundle *vk, VkImage image, VkFormat format, + VkImageSubresourceRange subresource_range, VkImageView *out_view); /*! diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c index 6a312ad17..2a0c64980 100644 --- a/src/xrt/compositor/main/comp_renderer.c +++ b/src/xrt/compositor/main/comp_renderer.c @@ -568,7 +568,7 @@ renderer_init_dummy_images(struct comp_renderer *r) vk_create_sampler(vk, &r->dummy_images[i].sampler); vk_create_view(vk, r->dummy_images[i].image, - VK_FORMAT_B8G8R8A8_SRGB, + VK_FORMAT_B8G8R8A8_SRGB, subresource_range, &r->dummy_images[i].view); } diff --git a/src/xrt/compositor/main/comp_swapchain.c b/src/xrt/compositor/main/comp_swapchain.c index f0fb04417..a2b6c361a 100644 --- a/src/xrt/compositor/main/comp_swapchain.c +++ b/src/xrt/compositor/main/comp_swapchain.c @@ -65,6 +65,7 @@ create_image_fd(struct comp_compositor *c, int64_t format, uint32_t width, uint32_t height, + uint32_t array_size, uint32_t mip_count, VkImage *out_image, VkDeviceMemory *out_mem, @@ -102,7 +103,7 @@ create_image_fd(struct comp_compositor *c, .format = (VkFormat)format, .extent = {.width = width, .height = height, .depth = 1}, .mipLevels = mip_count, - .arrayLayers = 1, + .arrayLayers = array_size, .samples = VK_SAMPLE_COUNT_1_BIT, .tiling = VK_IMAGE_TILING_OPTIMAL, .usage = image_usage, @@ -235,17 +236,26 @@ comp_swapchain_create(struct xrt_compositor *xc, COMP_DEBUG(c, "CREATE %p %dx%d", (void *)sc, width, height); + VkImageSubresourceRange subresource_range = { + .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, + .baseMipLevel = 0, + .levelCount = 1, + .baseArrayLayer = 0, + .layerCount = array_size, + }; + for (uint32_t i = 0; i < num_images; i++) { - ret = create_image_fd( - c, format, width, height, mip_count, &sc->images[i].image, - &sc->images[i].memory, &sc->base.images[i]); + ret = + create_image_fd(c, format, width, height, array_size, + mip_count, &sc->images[i].image, + &sc->images[i].memory, &sc->base.images[i]); if (ret != VK_SUCCESS) { return NULL; } vk_create_sampler(&c->vk, &sc->images[i].sampler); vk_create_view(&c->vk, sc->images[i].image, (VkFormat)format, - &sc->images[i].view); + subresource_range, &sc->images[i].view); } @@ -257,14 +267,6 @@ comp_swapchain_create(struct xrt_compositor *xc, vk_init_cmd_buffer(&c->vk, &cmd_buffer); - VkImageSubresourceRange subresource_range = { - .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, - .baseMipLevel = 0, - .levelCount = 1, - .baseArrayLayer = 0, - .layerCount = 1, - }; - for (uint32_t i = 0; i < num_images; i++) { vk_set_image_layout(&c->vk, cmd_buffer, sc->images[i].image, 0, VK_ACCESS_SHADER_READ_BIT,