Commit 13cef1b8 authored by Benjamin Saunders's avatar Benjamin Saunders

comp: Support rendering individual array layers

parent b6f2013b
Pipeline #34541 passed with stages
in 1 minute and 33 seconds
...@@ -128,6 +128,7 @@ client_gl_compositor_end_frame(struct xrt_compositor *xc, ...@@ -128,6 +128,7 @@ client_gl_compositor_end_frame(struct xrt_compositor *xc,
enum xrt_blend_mode blend_mode, enum xrt_blend_mode blend_mode,
struct xrt_swapchain **xscs, struct xrt_swapchain **xscs,
uint32_t *image_index, uint32_t *image_index,
uint32_t *layers,
uint32_t num_swapchains) uint32_t num_swapchains)
{ {
struct client_gl_compositor *c = client_gl_compositor(xc); struct client_gl_compositor *c = client_gl_compositor(xc);
...@@ -145,7 +146,7 @@ client_gl_compositor_end_frame(struct xrt_compositor *xc, ...@@ -145,7 +146,7 @@ client_gl_compositor_end_frame(struct xrt_compositor *xc,
// Pipe down call into fd compositor. // Pipe down call into fd compositor.
c->xcfd->base.end_frame(&c->xcfd->base, blend_mode, internal, c->xcfd->base.end_frame(&c->xcfd->base, blend_mode, internal,
image_index, num_swapchains); image_index, layers, num_swapchains);
} }
static int64_t static int64_t
......
...@@ -148,6 +148,7 @@ client_vk_compositor_end_frame(struct xrt_compositor *xc, ...@@ -148,6 +148,7 @@ client_vk_compositor_end_frame(struct xrt_compositor *xc,
enum xrt_blend_mode blend_mode, enum xrt_blend_mode blend_mode,
struct xrt_swapchain **xscs, struct xrt_swapchain **xscs,
uint32_t *image_index, uint32_t *image_index,
uint32_t *layers,
uint32_t num_swapchains) uint32_t num_swapchains)
{ {
struct client_vk_compositor *c = client_vk_compositor(xc); struct client_vk_compositor *c = client_vk_compositor(xc);
...@@ -165,7 +166,7 @@ client_vk_compositor_end_frame(struct xrt_compositor *xc, ...@@ -165,7 +166,7 @@ client_vk_compositor_end_frame(struct xrt_compositor *xc,
// Pipe down call into fd compositor. // Pipe down call into fd compositor.
c->xcfd->base.end_frame(&c->xcfd->base, blend_mode, internal, c->xcfd->base.end_frame(&c->xcfd->base, blend_mode, internal,
image_index, num_swapchains); image_index, layers, num_swapchains);
} }
static struct xrt_swapchain * static struct xrt_swapchain *
......
...@@ -110,6 +110,7 @@ compositor_end_frame(struct xrt_compositor *xc, ...@@ -110,6 +110,7 @@ compositor_end_frame(struct xrt_compositor *xc,
enum xrt_blend_mode blend_mode, enum xrt_blend_mode blend_mode,
struct xrt_swapchain **xscs, struct xrt_swapchain **xscs,
uint32_t *image_index, uint32_t *image_index,
uint32_t *layers,
uint32_t num_swapchains) uint32_t num_swapchains)
{ {
struct comp_compositor *c = comp_compositor(xc); struct comp_compositor *c = comp_compositor(xc);
...@@ -122,7 +123,7 @@ compositor_end_frame(struct xrt_compositor *xc, ...@@ -122,7 +123,7 @@ compositor_end_frame(struct xrt_compositor *xc,
if (num_swapchains == 2) { if (num_swapchains == 2) {
left = &comp_swapchain(xscs[0])->images[image_index[0]]; left = &comp_swapchain(xscs[0])->images[image_index[0]];
right = &comp_swapchain(xscs[1])->images[image_index[1]]; right = &comp_swapchain(xscs[1])->images[image_index[1]];
comp_renderer_frame(c->r, left, right); comp_renderer_frame(c->r, left, layers[0], right, layers[1]);
} else { } else {
COMP_ERROR(c, "non-stereo rendering not supported"); COMP_ERROR(c, "non-stereo rendering not supported");
} }
......
...@@ -40,8 +40,8 @@ struct comp_swapchain_image ...@@ -40,8 +40,8 @@ struct comp_swapchain_image
VkDeviceMemory memory; VkDeviceMemory memory;
//! Sampler used by the renderer and distortion code. //! Sampler used by the renderer and distortion code.
VkSampler sampler; VkSampler sampler;
//! View used by the renderer and distortion code. //! Views used by the renderer and distortion code, for each array layer.
VkImageView view; VkImageView *views;
}; };
/*! /*!
...@@ -159,6 +159,7 @@ comp_swapchain_create(struct xrt_compositor *xc, ...@@ -159,6 +159,7 @@ comp_swapchain_create(struct xrt_compositor *xc,
*/ */
void void
comp_swapchain_image_cleanup(struct vk_bundle *vk, comp_swapchain_image_cleanup(struct vk_bundle *vk,
uint32_t array_size,
struct comp_swapchain_image *image); struct comp_swapchain_image *image);
/*! /*!
......
...@@ -75,7 +75,8 @@ renderer_init(struct comp_renderer *r); ...@@ -75,7 +75,8 @@ renderer_init(struct comp_renderer *r);
static void static void
renderer_set_swapchain_image(struct comp_renderer *r, renderer_set_swapchain_image(struct comp_renderer *r,
uint32_t eye, uint32_t eye,
struct comp_swapchain_image *image); struct comp_swapchain_image *image,
uint32_t layer);
static void static void
renderer_render(struct comp_renderer *r); renderer_render(struct comp_renderer *r);
...@@ -157,10 +158,12 @@ comp_renderer_create(struct comp_compositor *c) ...@@ -157,10 +158,12 @@ comp_renderer_create(struct comp_compositor *c)
void void
comp_renderer_frame(struct comp_renderer *r, comp_renderer_frame(struct comp_renderer *r,
struct comp_swapchain_image *left, struct comp_swapchain_image *left,
struct comp_swapchain_image *right) uint32_t left_layer,
struct comp_swapchain_image *right,
uint32_t right_layer)
{ {
renderer_set_swapchain_image(r, 0, left); renderer_set_swapchain_image(r, 0, left, left_layer);
renderer_set_swapchain_image(r, 1, right); renderer_set_swapchain_image(r, 1, right, right_layer);
renderer_render(r); renderer_render(r);
r->c->vk.vkDeviceWaitIdle(r->c->vk.device); r->c->vk.vkDeviceWaitIdle(r->c->vk.device);
} }
...@@ -197,6 +200,8 @@ renderer_create(struct comp_renderer *r, struct comp_compositor *c) ...@@ -197,6 +200,8 @@ renderer_create(struct comp_renderer *r, struct comp_compositor *c)
memset(&r->dummy_images[0], 0, sizeof(struct comp_swapchain_image)); memset(&r->dummy_images[0], 0, sizeof(struct comp_swapchain_image));
memset(&r->dummy_images[1], 0, sizeof(struct comp_swapchain_image)); memset(&r->dummy_images[1], 0, sizeof(struct comp_swapchain_image));
r->dummy_images[0].views = U_TYPED_CALLOC(VkImageView);
r->dummy_images[1].views = U_TYPED_CALLOC(VkImageView);
r->distortion = NULL; r->distortion = NULL;
r->cmd_buffers = NULL; r->cmd_buffers = NULL;
...@@ -569,7 +574,7 @@ renderer_init_dummy_images(struct comp_renderer *r) ...@@ -569,7 +574,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, subresource_range, VK_FORMAT_B8G8R8A8_SRGB, subresource_range,
&r->dummy_images[i].view); &r->dummy_images[i].views[0]);
} }
_submit_cmd_buffer(r->c, vk->cmd_pool, cmd_buffer); _submit_cmd_buffer(r->c, vk->cmd_pool, cmd_buffer);
...@@ -605,7 +610,7 @@ renderer_init(struct comp_renderer *r) ...@@ -605,7 +610,7 @@ renderer_init(struct comp_renderer *r)
for (uint32_t i = 0; i < 2; i++) for (uint32_t i = 0; i < 2; i++)
comp_distortion_update_descriptor_set( comp_distortion_update_descriptor_set(
r->distortion, r->dummy_images[i].sampler, r->distortion, r->dummy_images[i].sampler,
r->dummy_images[i].view, i); r->dummy_images[i].views[0], i);
renderer_build_command_buffers(r); renderer_build_command_buffers(r);
} }
...@@ -613,7 +618,8 @@ renderer_init(struct comp_renderer *r) ...@@ -613,7 +618,8 @@ renderer_init(struct comp_renderer *r)
static void static void
renderer_set_swapchain_image(struct comp_renderer *r, renderer_set_swapchain_image(struct comp_renderer *r,
uint32_t eye, uint32_t eye,
struct comp_swapchain_image *image) struct comp_swapchain_image *image,
uint32_t layer)
{ {
if (eye > 1) { if (eye > 1) {
COMP_ERROR(r->c, "Swapchain image %p %u not found", COMP_ERROR(r->c, "Swapchain image %p %u not found",
...@@ -627,7 +633,8 @@ renderer_set_swapchain_image(struct comp_renderer *r, ...@@ -627,7 +633,8 @@ renderer_set_swapchain_image(struct comp_renderer *r,
" swapchain image %p and eye %u", " swapchain image %p and eye %u",
(void *)image, eye); (void *)image, eye);
comp_distortion_update_descriptor_set( comp_distortion_update_descriptor_set(
r->distortion, image->sampler, image->view, (uint32_t)eye); r->distortion, image->sampler, image->views[layer],
(uint32_t)eye);
renderer_rebuild_command_buffers(r); renderer_rebuild_command_buffers(r);
r->one_buffer_imported[eye] = true; r->one_buffer_imported[eye] = true;
} }
...@@ -944,7 +951,7 @@ renderer_destroy(struct comp_renderer *r) ...@@ -944,7 +951,7 @@ renderer_destroy(struct comp_renderer *r)
// Dummy images // Dummy images
for (uint32_t i = 0; i < 2; i++) { for (uint32_t i = 0; i < 2; i++) {
comp_swapchain_image_cleanup(vk, &r->dummy_images[i]); comp_swapchain_image_cleanup(vk, 1, &r->dummy_images[i]);
} }
// Discriptor pool // Discriptor pool
......
...@@ -37,7 +37,9 @@ comp_renderer_create(struct comp_compositor *c); ...@@ -37,7 +37,9 @@ comp_renderer_create(struct comp_compositor *c);
void void
comp_renderer_frame(struct comp_renderer *r, comp_renderer_frame(struct comp_renderer *r,
struct comp_swapchain_image *left, struct comp_swapchain_image *left,
struct comp_swapchain_image *right); uint32_t left_layer,
struct comp_swapchain_image *right,
uint32_t right_layer);
/*! /*!
* Clean up and free the renderer. * Clean up and free the renderer.
......
...@@ -24,7 +24,8 @@ swapchain_destroy(struct xrt_swapchain *xsc) ...@@ -24,7 +24,8 @@ swapchain_destroy(struct xrt_swapchain *xsc)
COMP_SPEW(sc->c, "DESTROY"); COMP_SPEW(sc->c, "DESTROY");
for (uint32_t i = 0; i < sc->base.base.num_images; i++) { for (uint32_t i = 0; i < sc->base.base.num_images; i++) {
comp_swapchain_image_cleanup(vk, &sc->images[i]); comp_swapchain_image_cleanup(vk, sc->base.base.array_size,
&sc->images[i]);
} }
free(sc); free(sc);
...@@ -236,14 +237,6 @@ comp_swapchain_create(struct xrt_compositor *xc, ...@@ -236,14 +237,6 @@ 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 = ret =
create_image_fd(c, format, width, height, array_size, create_image_fd(c, format, width, height, array_size,
...@@ -254,8 +247,25 @@ comp_swapchain_create(struct xrt_compositor *xc, ...@@ -254,8 +247,25 @@ comp_swapchain_create(struct xrt_compositor *xc,
} }
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, }
subresource_range, &sc->images[i].view);
for (uint32_t i = 0; i < num_images; i++) {
sc->images[i].views =
U_TYPED_ARRAY_CALLOC(VkImageView, array_size);
for (uint32_t layer = 0; layer < array_size; ++layer) {
VkImageSubresourceRange subresource_range = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = layer,
.layerCount = 1,
};
vk_create_view(&c->vk, sc->images[i].image,
(VkFormat)format, subresource_range,
&sc->images[i].views[layer]);
}
} }
...@@ -267,6 +277,14 @@ comp_swapchain_create(struct xrt_compositor *xc, ...@@ -267,6 +277,14 @@ 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 = array_size,
};
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,
...@@ -282,11 +300,18 @@ comp_swapchain_create(struct xrt_compositor *xc, ...@@ -282,11 +300,18 @@ comp_swapchain_create(struct xrt_compositor *xc,
void void
comp_swapchain_image_cleanup(struct vk_bundle *vk, comp_swapchain_image_cleanup(struct vk_bundle *vk,
uint32_t array_size,
struct comp_swapchain_image *image) struct comp_swapchain_image *image)
{ {
if (image->view != NULL) { if (image->views != NULL) {
vk->vkDestroyImageView(vk->device, image->view, NULL); for (uint32_t i = 0; i < array_size; ++i) {
image->view = NULL; if (image->views[i] != NULL) {
vk->vkDestroyImageView(vk->device,
image->views[i], NULL);
}
}
free(image->views);
image->views = NULL;
} }
if (image->sampler != NULL) { if (image->sampler != NULL) {
......
...@@ -73,6 +73,11 @@ struct xrt_swapchain ...@@ -73,6 +73,11 @@ struct xrt_swapchain
*/ */
uint32_t num_images; uint32_t num_images;
/*!
* Number of array layers per image.
*/
uint32_t array_size;
/*! /*!
* Must have called release_image before calling this function. * Must have called release_image before calling this function.
*/ */
...@@ -186,6 +191,7 @@ struct xrt_compositor ...@@ -186,6 +191,7 @@ struct xrt_compositor
enum xrt_blend_mode blend_mode, enum xrt_blend_mode blend_mode,
struct xrt_swapchain **xscs, struct xrt_swapchain **xscs,
uint32_t *image_index, uint32_t *image_index,
uint32_t *layers,
uint32_t num_swapchains); uint32_t num_swapchains);
/*! /*!
......
...@@ -464,6 +464,7 @@ oxr_session_frame_end(struct oxr_logger *log, ...@@ -464,6 +464,7 @@ oxr_session_frame_end(struct oxr_logger *log,
struct xrt_swapchain *chains[2]; struct xrt_swapchain *chains[2];
uint32_t image_index[2]; uint32_t image_index[2];
uint32_t layers[2];
uint32_t num_chains = ARRAY_SIZE(chains); uint32_t num_chains = ARRAY_SIZE(chains);
for (uint32_t i = 0; i < num_chains; i++) { for (uint32_t i = 0; i < num_chains; i++) {
...@@ -471,10 +472,11 @@ oxr_session_frame_end(struct oxr_logger *log, ...@@ -471,10 +472,11 @@ oxr_session_frame_end(struct oxr_logger *log,
struct oxr_swapchain *sc = struct oxr_swapchain *sc =
(struct oxr_swapchain *)proj->views[i].subImage.swapchain; (struct oxr_swapchain *)proj->views[i].subImage.swapchain;
chains[i] = sc->swapchain; chains[i] = sc->swapchain;
layers[i] = proj->views[i].subImage.imageArrayIndex;
image_index[i] = sc->released_index; image_index[i] = sc->released_index;
} }
xc->end_frame(xc, blend_mode, chains, image_index, num_chains); xc->end_frame(xc, blend_mode, chains, image_index, layers, num_chains);
sess->frame_started = false; sess->frame_started = false;
......
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