comp: Respect swapchain array size

This commit is contained in:
Benjamin Saunders 2019-04-30 08:22:19 -07:00
parent c8cdf3ee38
commit f6b8cb25b8
6 changed files with 38 additions and 32 deletions

View file

@ -195,7 +195,8 @@ client_gl_swapchain_create(struct xrt_compositor *xc,
sc->base.base.num_images = num_images; sc->base.base.num_images = num_images;
sc->xscfd = xrt_swapchain_fd(xsc); 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]); glCreateMemoryObjectsEXT(num_images, &sc->base.memory[0]);
for (uint32_t i = 0; i < num_images; i++) { for (uint32_t i = 0; i < num_images; i++) {
GLint dedicated = GL_TRUE; GLint dedicated = GL_TRUE;
@ -205,9 +206,15 @@ client_gl_swapchain_create(struct xrt_compositor *xc,
glImportMemoryFdEXT( glImportMemoryFdEXT(
sc->base.memory[i], sc->xscfd->images[i].size, sc->base.memory[i], sc->xscfd->images[i].size,
GL_HANDLE_TYPE_OPAQUE_FD_EXT, sc->xscfd->images[i].fd); GL_HANDLE_TYPE_OPAQUE_FD_EXT, sc->xscfd->images[i].fd);
glTextureStorageMem2DEXT(sc->base.images[i], mip_count, if (array_size == 1) {
(GLuint)format, width, height, glTextureStorageMem2DEXT(sc->base.images[i], mip_count,
sc->base.memory[i], 0); (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; return &sc->base.base;

View file

@ -203,7 +203,7 @@ client_vk_swapchain_create(struct xrt_compositor *xc,
.baseMipLevel = 0, .baseMipLevel = 0,
.levelCount = 1, .levelCount = 1,
.baseArrayLayer = 0, .baseArrayLayer = 0,
.layerCount = 1, .layerCount = array_size,
}; };
struct client_vk_swapchain *sc = struct client_vk_swapchain *sc =
@ -217,10 +217,10 @@ client_vk_swapchain_create(struct xrt_compositor *xc,
sc->xscfd = xrt_swapchain_fd(xsc); sc->xscfd = xrt_swapchain_fd(xsc);
for (uint32_t i = 0; i < num_images; i++) { for (uint32_t i = 0; i < num_images; i++) {
ret = vk_create_image_from_fd(&c->vk, format, width, height, ret = vk_create_image_from_fd(
mip_count, &sc->xscfd->images[i], &c->vk, format, width, height, array_size, mip_count,
&sc->base.images[i], &sc->xscfd->images[i], &sc->base.images[i],
&sc->base.mems[i]); &sc->base.mems[i]);
if (ret != VK_SUCCESS) { if (ret != VK_SUCCESS) {
return NULL; return NULL;
} }

View file

@ -239,6 +239,7 @@ vk_create_image_from_fd(struct vk_bundle *vk,
int64_t format, int64_t format,
uint32_t width, uint32_t width,
uint32_t height, uint32_t height,
uint32_t array_size,
uint32_t mip_count, uint32_t mip_count,
struct xrt_image_fd *image_fd, struct xrt_image_fd *image_fd,
VkImage *out_image, VkImage *out_image,
@ -267,7 +268,7 @@ vk_create_image_from_fd(struct vk_bundle *vk,
.format = (VkFormat)format, .format = (VkFormat)format,
.extent = {.width = width, .height = height, .depth = 1}, .extent = {.width = width, .height = height, .depth = 1},
.mipLevels = mip_count, .mipLevels = mip_count,
.arrayLayers = 1, .arrayLayers = array_size,
.samples = VK_SAMPLE_COUNT_1_BIT, .samples = VK_SAMPLE_COUNT_1_BIT,
.tiling = VK_IMAGE_TILING_OPTIMAL, .tiling = VK_IMAGE_TILING_OPTIMAL,
.usage = image_usage, .usage = image_usage,
@ -389,6 +390,7 @@ VkResult
vk_create_view(struct vk_bundle *vk, vk_create_view(struct vk_bundle *vk,
VkImage image, VkImage image,
VkFormat format, VkFormat format,
VkImageSubresourceRange subresource_range,
VkImageView *out_view) VkImageView *out_view)
{ {
VkImageView view; VkImageView view;
@ -408,14 +410,7 @@ vk_create_view(struct vk_bundle *vk,
.b = VK_COMPONENT_SWIZZLE_B, .b = VK_COMPONENT_SWIZZLE_B,
.a = VK_COMPONENT_SWIZZLE_A, .a = VK_COMPONENT_SWIZZLE_A,
}, },
.subresourceRange = .subresourceRange = subresource_range,
{
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = 1,
},
}; };
ret = vk->vkCreateImageView(vk->device, &imageView, NULL, &view); ret = vk->vkCreateImageView(vk->device, &imageView, NULL, &view);

View file

@ -284,6 +284,7 @@ vk_create_image_from_fd(struct vk_bundle *vk,
int64_t format, int64_t format,
uint32_t width, uint32_t width,
uint32_t height, uint32_t height,
uint32_t array_size,
uint32_t mip_count, uint32_t mip_count,
struct xrt_image_fd *image_fd, struct xrt_image_fd *image_fd,
VkImage *out_image, VkImage *out_image,
@ -313,6 +314,7 @@ VkResult
vk_create_view(struct vk_bundle *vk, vk_create_view(struct vk_bundle *vk,
VkImage image, VkImage image,
VkFormat format, VkFormat format,
VkImageSubresourceRange subresource_range,
VkImageView *out_view); VkImageView *out_view);
/*! /*!

View file

@ -568,7 +568,7 @@ renderer_init_dummy_images(struct comp_renderer *r)
vk_create_sampler(vk, &r->dummy_images[i].sampler); vk_create_sampler(vk, &r->dummy_images[i].sampler);
vk_create_view(vk, r->dummy_images[i].image, vk_create_view(vk, r->dummy_images[i].image,
VK_FORMAT_B8G8R8A8_SRGB, VK_FORMAT_B8G8R8A8_SRGB, subresource_range,
&r->dummy_images[i].view); &r->dummy_images[i].view);
} }

View file

@ -65,6 +65,7 @@ create_image_fd(struct comp_compositor *c,
int64_t format, int64_t format,
uint32_t width, uint32_t width,
uint32_t height, uint32_t height,
uint32_t array_size,
uint32_t mip_count, uint32_t mip_count,
VkImage *out_image, VkImage *out_image,
VkDeviceMemory *out_mem, VkDeviceMemory *out_mem,
@ -102,7 +103,7 @@ create_image_fd(struct comp_compositor *c,
.format = (VkFormat)format, .format = (VkFormat)format,
.extent = {.width = width, .height = height, .depth = 1}, .extent = {.width = width, .height = height, .depth = 1},
.mipLevels = mip_count, .mipLevels = mip_count,
.arrayLayers = 1, .arrayLayers = array_size,
.samples = VK_SAMPLE_COUNT_1_BIT, .samples = VK_SAMPLE_COUNT_1_BIT,
.tiling = VK_IMAGE_TILING_OPTIMAL, .tiling = VK_IMAGE_TILING_OPTIMAL,
.usage = image_usage, .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); 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++) { for (uint32_t i = 0; i < num_images; i++) {
ret = create_image_fd( ret =
c, format, width, height, mip_count, &sc->images[i].image, create_image_fd(c, format, width, height, array_size,
&sc->images[i].memory, &sc->base.images[i]); mip_count, &sc->images[i].image,
&sc->images[i].memory, &sc->base.images[i]);
if (ret != VK_SUCCESS) { if (ret != VK_SUCCESS) {
return NULL; return NULL;
} }
vk_create_sampler(&c->vk, &sc->images[i].sampler); vk_create_sampler(&c->vk, &sc->images[i].sampler);
vk_create_view(&c->vk, sc->images[i].image, (VkFormat)format, 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); 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++) { for (uint32_t i = 0; i < num_images; i++) {
vk_set_image_layout(&c->vk, cmd_buffer, sc->images[i].image, 0, vk_set_image_layout(&c->vk, cmd_buffer, sc->images[i].image, 0,
VK_ACCESS_SHADER_READ_BIT, VK_ACCESS_SHADER_READ_BIT,