c/render: Do not use a local that isn't a macro parameter.

Makes logic hard to follow, and it can be fragile

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2380>
This commit is contained in:
Rylie Pavlik 2024-12-06 17:56:25 -06:00
parent 1c342e8146
commit a7846911a6
4 changed files with 19 additions and 21 deletions

View file

@ -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

View file

@ -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]);

View file

@ -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

View file

@ -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;
}