Commit f6b8cb25 authored by Benjamin Saunders's avatar Benjamin Saunders

comp: Respect swapchain array size

parent c8cdf3ee
......@@ -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;
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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);
/*!
......
......@@ -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);
}
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment