diff --git a/src/xrt/compositor/render/render_compute.c b/src/xrt/compositor/render/render_compute.c index 41b8e087d..27b1953cf 100644 --- a/src/xrt/compositor/render/render_compute.c +++ b/src/xrt/compositor/render/render_compute.c @@ -295,7 +295,7 @@ render_compute_init(struct render_compute *render, struct render_resources *r) struct vk_bundle *vk = r->vk; render->r = r; - for (uint32_t i = 0; i < RENDER_MAX_LAYER_RUNS_COUNT; i++) { + for (uint32_t i = 0; i < RENDER_MAX_LAYER_RUNS_COUNT(r); i++) { ret = vk_create_descriptor_set( // vk, // vk_bundle r->compute.descriptor_pool, // descriptor_pool diff --git a/src/xrt/compositor/render/render_distortion.c b/src/xrt/compositor/render/render_distortion.c index d695832d0..8ac24db8e 100644 --- a/src/xrt/compositor/render/render_distortion.c +++ b/src/xrt/compositor/render/render_distortion.c @@ -324,7 +324,7 @@ render_distortion_buffer_init(struct render_resources *r, VK_CHK_WITH_GOTO(ret, "vk_cmd_pool_create_and_begin_cmd_buffer_locked", err_unlock); VK_NAME_COMMAND_BUFFER(vk, upload_buffer, "render_resources distortion command buffer"); - for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT; i++) { + for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT(r); i++) { ret = create_and_queue_upload_locked( // vk, // vk_bundle pool, // pool @@ -347,7 +347,7 @@ render_distortion_buffer_init(struct render_resources *r, r->distortion.pre_rotated = pre_rotate; - for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT; i++) { + for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT(r); i++) { r->distortion.device_memories[i] = device_memories[i]; r->distortion.images[i] = images[i]; r->distortion.image_views[i] = image_views[i]; @@ -358,7 +358,7 @@ render_distortion_buffer_init(struct render_resources *r, * Tidy */ - for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT; i++) { + for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT(r); i++) { render_buffer_fini(vk, &bufs[i]); } @@ -372,7 +372,7 @@ err_unlock: vk_cmd_pool_unlock(pool); err_resources: - for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT; i++) { + for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT(r); i++) { D(ImageView, image_views[i]); D(Image, images[i]); DF(Memory, device_memories[i]); @@ -394,7 +394,7 @@ render_distortion_images_fini(struct render_resources *r) { struct vk_bundle *vk = r->vk; - for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT; i++) { + for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT(r); i++) { D(ImageView, r->distortion.image_views[i]); D(Image, r->distortion.images[i]); DF(Memory, r->distortion.device_memories[i]); diff --git a/src/xrt/compositor/render/render_interface.h b/src/xrt/compositor/render/render_interface.h index d37b37f18..4ade0ba61 100644 --- a/src/xrt/compositor/render/render_interface.h +++ b/src/xrt/compositor/render/render_interface.h @@ -62,7 +62,7 @@ extern "C" { * squasher in a single dispatch. */ #define RENDER_MAX_IMAGES_SIZE (RENDER_MAX_LAYERS * XRT_MAX_VIEWS) -#define RENDER_MAX_IMAGES_COUNT (RENDER_MAX_LAYERS * r->view_count) +#define RENDER_MAX_IMAGES_COUNT(RENDER_RESOURCES) (RENDER_MAX_LAYERS * RENDER_RESOURCES->view_count) /*! * Maximum number of times that the layer squasher shader can run per @@ -72,14 +72,14 @@ extern "C" { * composition (which is this number divided by number of composition). */ #define RENDER_MAX_LAYER_RUNS_SIZE (XRT_MAX_VIEWS) -#define RENDER_MAX_LAYER_RUNS_COUNT (r->view_count) +#define RENDER_MAX_LAYER_RUNS_COUNT(RENDER_RESOURCES) (RENDER_RESOURCES->view_count) //! Distortion image dimension in pixels #define RENDER_DISTORTION_IMAGE_DIMENSIONS (128) //! How many distortion images we have, one for each channel (3 rgb) and per view. #define RENDER_DISTORTION_IMAGES_SIZE (3 * XRT_MAX_VIEWS) -#define RENDER_DISTORTION_IMAGES_COUNT (3 * r->view_count) +#define RENDER_DISTORTION_IMAGES_COUNT(RENDER_RESOURCES) (3 * RENDER_RESOURCES->view_count) //! The binding that the layer projection and quad shader have their UBO on. #define RENDER_BINDING_LAYER_SHARED_UBO 0 diff --git a/src/xrt/compositor/render/render_resources.c b/src/xrt/compositor/render/render_resources.c index 4dc515738..ffd395880 100644 --- a/src/xrt/compositor/render/render_resources.c +++ b/src/xrt/compositor/render/render_resources.c @@ -542,10 +542,8 @@ render_resources_init(struct render_resources *r, r->compute.target_binding = 2; r->compute.ubo_binding = 3; - r->compute.layer.image_array_size = vk->features.max_per_stage_descriptor_sampled_images; - if (r->compute.layer.image_array_size > RENDER_MAX_IMAGES_COUNT) { - r->compute.layer.image_array_size = RENDER_MAX_IMAGES_COUNT; - } + r->compute.layer.image_array_size = + MAX(vk->features.max_per_stage_descriptor_sampled_images, RENDER_MAX_IMAGES_COUNT(r)); /* @@ -697,10 +695,10 @@ render_resources_init(struct render_resources *r, { // Number of layer shader runs (views) times number of layers. - const uint32_t layer_shader_count = RENDER_MAX_LAYER_RUNS_COUNT * RENDER_MAX_LAYERS; + const uint32_t layer_shader_count = RENDER_MAX_LAYER_RUNS_COUNT(r) * RENDER_MAX_LAYERS; // Two mesh distortion runs. - const uint32_t mesh_shader_count = RENDER_MAX_LAYER_RUNS_COUNT; + const uint32_t mesh_shader_count = RENDER_MAX_LAYER_RUNS_COUNT(r); struct vk_descriptor_pool_info mesh_pool_info = { .uniform_per_descriptor_count = 1, @@ -731,7 +729,7 @@ render_resources_init(struct render_resources *r, buffer_count += layer_shader_count; // One UBO per mesh shader. - buffer_count += RENDER_MAX_LAYER_RUNS_COUNT; + buffer_count += RENDER_MAX_LAYER_RUNS_COUNT(r); // We currently use the aligmnent as max UBO size. static_assert(sizeof(struct render_gfx_mesh_ubo_data) <= RENDER_ALWAYS_SAFE_UBO_ALIGNMENT, "MAX"); @@ -831,12 +829,12 @@ render_resources_init(struct render_resources *r, const uint32_t compute_descriptor_count = // 1 + // Shared/distortion run(s). - RENDER_MAX_LAYER_RUNS_COUNT; // Layer shader run(s). + RENDER_MAX_LAYER_RUNS_COUNT(r); // Layer shader run(s). struct vk_descriptor_pool_info compute_pool_info = { .uniform_per_descriptor_count = 1, // layer images - .sampler_per_descriptor_count = r->compute.layer.image_array_size + RENDER_DISTORTION_IMAGES_COUNT, + .sampler_per_descriptor_count = r->compute.layer.image_array_size + RENDER_DISTORTION_IMAGES_COUNT(r), .storage_image_per_descriptor_count = 1, .storage_buffer_per_descriptor_count = 0, .descriptor_count = compute_descriptor_count, @@ -1041,13 +1039,13 @@ render_resources_init(struct render_resources *r, * Compute distortion textures, not created until later. */ - for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT; i++) { + for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT(r); i++) { r->distortion.image_views[i] = VK_NULL_HANDLE; } - for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT; i++) { + for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT(r); i++) { r->distortion.images[i] = VK_NULL_HANDLE; } - for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT; i++) { + for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT(r); i++) { r->distortion.device_memories[i] = VK_NULL_HANDLE; }