c/render: Rename defines to proper prefix [NFC]

This commit is contained in:
Jakob Bornecrantz 2023-09-14 20:19:16 +01:00
parent 7441a9bda6
commit 7996013e4d
6 changed files with 77 additions and 66 deletions

View file

@ -1085,8 +1085,8 @@ do_layers(struct comp_renderer *r,
// Tightly pack color and optional depth images.
uint32_t cur_image = 0;
VkSampler src_samplers[COMP_MAX_IMAGES];
VkImageView src_image_views[COMP_MAX_IMAGES];
VkSampler src_samplers[RENDER_MAX_IMAGES];
VkImageView src_image_views[RENDER_MAX_IMAGES];
for (uint32_t layer_i = 0; layer_i < layer_count; layer_i++) {
const struct xrt_layer_data *data = &layers[layer_i].data;
@ -1303,7 +1303,7 @@ do_layers(struct comp_renderer *r,
}
}
for (uint32_t i = layer_count; i < COMP_MAX_LAYERS; i++) {
for (uint32_t i = layer_count; i < RENDER_MAX_LAYERS; i++) {
ubo_data->layer_type[i].val = UINT32_MAX;
}

View file

@ -88,8 +88,8 @@ calc_dispatch_dims(const struct render_viewport_data views[2], uint32_t *out_w,
XRT_MAYBE_UNUSED static void
update_compute_layer_descriptor_set(struct vk_bundle *vk,
uint32_t src_binding,
VkSampler src_samplers[COMP_MAX_IMAGES],
VkImageView src_image_views[COMP_MAX_IMAGES],
VkSampler src_samplers[RENDER_MAX_IMAGES],
VkImageView src_image_views[RENDER_MAX_IMAGES],
uint32_t image_count,
uint32_t target_binding,
VkImageView target_image_view,
@ -98,9 +98,9 @@ update_compute_layer_descriptor_set(struct vk_bundle *vk,
VkDeviceSize ubo_size,
VkDescriptorSet descriptor_set)
{
assert(image_count <= COMP_MAX_IMAGES);
assert(image_count <= RENDER_MAX_IMAGES);
VkDescriptorImageInfo src_image_info[COMP_MAX_IMAGES];
VkDescriptorImageInfo src_image_info[RENDER_MAX_IMAGES];
for (uint32_t i = 0; i < image_count; i++) {
src_image_info[i].sampler = src_samplers[i];
src_image_info[i].imageView = src_image_views[i];
@ -410,8 +410,8 @@ render_compute_close(struct render_compute *crc)
void
render_compute_layers(struct render_compute *crc,
VkSampler src_samplers[COMP_MAX_IMAGES],
VkImageView src_image_views[COMP_MAX_IMAGES],
VkSampler src_samplers[RENDER_MAX_IMAGES],
VkImageView src_image_views[RENDER_MAX_IMAGES],
uint32_t image_count,
VkImage target_image,
VkImageView target_image_view,

View file

@ -184,7 +184,7 @@ create_and_queue_upload_locked(struct vk_bundle *vk,
VkImage *out_image,
VkImageView *out_image_view)
{
VkExtent2D extent = {COMP_DISTORTION_IMAGE_DIMENSIONS, COMP_DISTORTION_IMAGE_DIMENSIONS};
VkExtent2D extent = {RENDER_DISTORTION_IMAGE_DIMENSIONS, RENDER_DISTORTION_IMAGE_DIMENSIONS};
VkDeviceMemory device_memory = VK_NULL_HANDLE;
VkImage image = VK_NULL_HANDLE;
VkImageView image_view = VK_NULL_HANDLE;
@ -219,7 +219,7 @@ create_and_queue_upload_locked(struct vk_bundle *vk,
*/
struct texture
{
struct xrt_vec2 pixels[COMP_DISTORTION_IMAGE_DIMENSIONS][COMP_DISTORTION_IMAGE_DIMENSIONS];
struct xrt_vec2 pixels[RENDER_DISTORTION_IMAGE_DIMENSIONS][RENDER_DISTORTION_IMAGE_DIMENSIONS];
};
struct tan_angles_transforms
@ -310,13 +310,13 @@ create_and_fill_in_distortion_buffer_for_view(struct vk_bundle *vk,
struct texture *g = g_buffer->mapped;
struct texture *b = b_buffer->mapped;
const double dim_minus_one_f64 = COMP_DISTORTION_IMAGE_DIMENSIONS - 1;
const double dim_minus_one_f64 = RENDER_DISTORTION_IMAGE_DIMENSIONS - 1;
for (int row = 0; row < COMP_DISTORTION_IMAGE_DIMENSIONS; row++) {
for (int row = 0; row < RENDER_DISTORTION_IMAGE_DIMENSIONS; row++) {
// This goes from 0 to 1.0 inclusive.
float v = (float)(row / dim_minus_one_f64);
for (int col = 0; col < COMP_DISTORTION_IMAGE_DIMENSIONS; col++) {
for (int col = 0; col < RENDER_DISTORTION_IMAGE_DIMENSIONS; col++) {
// This goes from 0 to 1.0 inclusive.
float u = (float)(col / dim_minus_one_f64);
@ -355,10 +355,10 @@ render_distortion_buffer_init(struct render_resources *r,
struct xrt_device *xdev,
bool pre_rotate)
{
struct render_buffer bufs[COMP_DISTORTION_NUM_IMAGES];
VkDeviceMemory device_memories[COMP_DISTORTION_NUM_IMAGES];
VkImage images[COMP_DISTORTION_NUM_IMAGES];
VkImageView image_views[COMP_DISTORTION_NUM_IMAGES];
struct render_buffer bufs[RENDER_DISTORTION_NUM_IMAGES];
VkDeviceMemory device_memories[RENDER_DISTORTION_NUM_IMAGES];
VkImage images[RENDER_DISTORTION_NUM_IMAGES];
VkImageView image_views[RENDER_DISTORTION_NUM_IMAGES];
VkCommandBuffer upload_buffer = VK_NULL_HANDLE;
VkResult ret;
@ -367,7 +367,7 @@ render_distortion_buffer_init(struct render_resources *r,
* Basics
*/
static_assert(COMP_DISTORTION_NUM_IMAGES == 6, "Wrong number of distortion images!");
static_assert(RENDER_DISTORTION_NUM_IMAGES == 6, "Wrong number of distortion images!");
calc_uv_to_tanangle(xdev, 0, &r->distortion.uv_to_tanangle[0]);
calc_uv_to_tanangle(xdev, 1, &r->distortion.uv_to_tanangle[1]);
@ -395,7 +395,7 @@ render_distortion_buffer_init(struct render_resources *r,
ret = vk_cmd_pool_create_and_begin_cmd_buffer_locked(vk, pool, 0, &upload_buffer);
CG(vk, ret, "vk_cmd_pool_create_and_begin_cmd_buffer_locked", err_unlock);
for (uint32_t i = 0; i < COMP_DISTORTION_NUM_IMAGES; i++) {
for (uint32_t i = 0; i < RENDER_DISTORTION_NUM_IMAGES; i++) {
ret = create_and_queue_upload_locked( //
vk, // vk_bundle
pool, // pool
@ -418,7 +418,7 @@ render_distortion_buffer_init(struct render_resources *r,
r->distortion.pre_rotated = pre_rotate;
for (uint32_t i = 0; i < COMP_DISTORTION_NUM_IMAGES; i++) {
for (uint32_t i = 0; i < RENDER_DISTORTION_NUM_IMAGES; i++) {
r->distortion.device_memories[i] = device_memories[i];
r->distortion.images[i] = images[i];
r->distortion.image_views[i] = image_views[i];
@ -429,7 +429,7 @@ render_distortion_buffer_init(struct render_resources *r,
* Tidy
*/
for (uint32_t i = 0; i < COMP_DISTORTION_NUM_IMAGES; i++) {
for (uint32_t i = 0; i < RENDER_DISTORTION_NUM_IMAGES; i++) {
render_buffer_close(vk, &bufs[i]);
}
@ -443,7 +443,7 @@ err_unlock:
vk_cmd_pool_unlock(pool);
err_resources:
for (uint32_t i = 0; i < COMP_DISTORTION_NUM_IMAGES; i++) {
for (uint32_t i = 0; i < RENDER_DISTORTION_NUM_IMAGES; i++) {
D(ImageView, image_views[i]);
D(Image, images[i]);
DF(Memory, device_memories[i]);
@ -465,11 +465,12 @@ render_distortion_images_close(struct render_resources *r)
{
struct vk_bundle *vk = r->vk;
static_assert(COMP_DISTORTION_NUM_IMAGES == ARRAY_SIZE(r->distortion.image_views), "Array size is wrong!");
static_assert(COMP_DISTORTION_NUM_IMAGES == ARRAY_SIZE(r->distortion.images), "Array size is wrong!");
static_assert(COMP_DISTORTION_NUM_IMAGES == ARRAY_SIZE(r->distortion.device_memories), "Array size is wrong!");
static_assert(RENDER_DISTORTION_NUM_IMAGES == ARRAY_SIZE(r->distortion.image_views), "Array size is wrong!");
static_assert(RENDER_DISTORTION_NUM_IMAGES == ARRAY_SIZE(r->distortion.images), "Array size is wrong!");
static_assert(RENDER_DISTORTION_NUM_IMAGES == ARRAY_SIZE(r->distortion.device_memories),
"Array size is wrong!");
for (uint32_t i = 0; i < COMP_DISTORTION_NUM_IMAGES; i++) {
for (uint32_t i = 0; i < RENDER_DISTORTION_NUM_IMAGES; i++) {
D(ImageView, r->distortion.image_views[i]);
D(Image, r->distortion.images[i]);
DF(Memory, r->distortion.device_memories[i]);

View file

@ -10,9 +10,7 @@
#pragma once
#define COMP_MAX_LAYERS 16
#define COMP_VIEWS_PER_LAYER 2
#define COMP_MAX_IMAGES 32
#include "xrt/xrt_compiler.h"
#include "xrt/xrt_defines.h"
@ -44,11 +42,23 @@ extern "C" {
*
*/
/*!
* Max number of layers for layer squasher, can be different from
* @ref COMP_MAX_LAYERS as the render module is separate from the compositor.
*/
#define RENDER_MAX_LAYERS (16)
/*!
* Max number of images that can be given at a single time to the layer
* squasher in a single dispatch.
*/
#define RENDER_MAX_IMAGES (RENDER_MAX_LAYERS * 2)
//! How large in pixels the distortion image is.
#define COMP_DISTORTION_IMAGE_DIMENSIONS (128)
#define RENDER_DISTORTION_IMAGE_DIMENSIONS (128)
//! How many distortion images we have, one for each channel (3 rgb) and per view, total 6.
#define COMP_DISTORTION_NUM_IMAGES (6)
#define RENDER_DISTORTION_NUM_IMAGES (6)
/*
@ -386,13 +396,13 @@ struct render_resources
struct xrt_normalized_rect uv_to_tanangle[2];
//! Backing memory to distortion images.
VkDeviceMemory device_memories[COMP_DISTORTION_NUM_IMAGES];
VkDeviceMemory device_memories[RENDER_DISTORTION_NUM_IMAGES];
//! Distortion images.
VkImage images[COMP_DISTORTION_NUM_IMAGES];
VkImage images[RENDER_DISTORTION_NUM_IMAGES];
//! The views into the distortion images.
VkImageView image_views[COMP_DISTORTION_NUM_IMAGES];
VkImageView image_views[RENDER_DISTORTION_NUM_IMAGES];
//! Whether distortion images have been pre-rotated 90 degrees.
bool pre_rotated;
@ -764,7 +774,7 @@ struct render_compute_layer_ubo_data
{
struct render_viewport_data views[2];
struct xrt_normalized_rect pre_transforms[2];
struct xrt_normalized_rect post_transforms[COMP_MAX_LAYERS * COMP_VIEWS_PER_LAYER];
struct xrt_normalized_rect post_transforms[RENDER_MAX_LAYERS * COMP_VIEWS_PER_LAYER];
//! std140 uvec2, corresponds to enum xrt_layer_type and unpremultiplied alpha.
struct
@ -772,7 +782,7 @@ struct render_compute_layer_ubo_data
uint32_t val;
uint32_t unpremultiplied;
uint32_t padding[2];
} layer_type[COMP_MAX_LAYERS];
} layer_type[RENDER_MAX_LAYERS];
//! Which image/sampler(s) correspond to each layer.
struct
@ -780,7 +790,7 @@ struct render_compute_layer_ubo_data
uint32_t images[2];
//! @todo Implement separated samplers and images (and change to samplers[2])
uint32_t padding[2];
} images_samplers[COMP_MAX_LAYERS * 2];
} images_samplers[RENDER_MAX_LAYERS * 2];
/*!
@ -788,7 +798,7 @@ struct render_compute_layer_ubo_data
*/
//! Timewarp matrices
struct xrt_matrix_4x4 transforms[COMP_MAX_LAYERS * COMP_VIEWS_PER_LAYER];
struct xrt_matrix_4x4 transforms[RENDER_MAX_LAYERS * COMP_VIEWS_PER_LAYER];
/*!
@ -800,20 +810,20 @@ struct render_compute_layer_ubo_data
{
struct xrt_vec3 val;
float padding;
} quad_position[COMP_MAX_LAYERS * 2];
} quad_position[RENDER_MAX_LAYERS * 2];
struct
{
struct xrt_vec3 val;
float padding;
} quad_normal[COMP_MAX_LAYERS * 2];
struct xrt_matrix_4x4 inverse_quad_transform[COMP_MAX_LAYERS * 2];
} quad_normal[RENDER_MAX_LAYERS * 2];
struct xrt_matrix_4x4 inverse_quad_transform[RENDER_MAX_LAYERS * 2];
//! Quad extent in world scale
struct
{
struct xrt_vec2 val;
float padding[2];
} quad_extent[COMP_MAX_LAYERS];
} quad_extent[RENDER_MAX_LAYERS];
};
/*!
@ -867,14 +877,14 @@ render_compute_end(struct render_compute *crc);
* @public @memberof render_compute
*/
void
render_compute_layers(struct render_compute *crc, //
VkSampler src_samplers[COMP_MAX_IMAGES], //
VkImageView src_image_views[COMP_MAX_IMAGES], //
uint32_t image_count, //
VkImage target_image, //
VkImageView target_image_view, //
VkImageLayout transition_to, //
bool timewarp); //
render_compute_layers(struct render_compute *crc, //
VkSampler src_samplers[RENDER_MAX_IMAGES], //
VkImageView src_image_views[RENDER_MAX_IMAGES], //
uint32_t image_count, //
VkImage target_image, //
VkImageView target_image_view, //
VkImageLayout transition_to, //
bool timewarp); //
/*!
* @public @memberof render_compute

View file

@ -570,8 +570,8 @@ render_resources_init(struct render_resources *r,
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 > COMP_MAX_IMAGES) {
r->compute.layer.image_array_size = COMP_MAX_IMAGES;
if (r->compute.layer.image_array_size > RENDER_MAX_IMAGES) {
r->compute.layer.image_array_size = RENDER_MAX_IMAGES;
}
@ -773,7 +773,7 @@ render_resources_init(struct render_resources *r,
struct compute_layer_params layer_params = {
.do_timewarp = false,
.do_color_correction = true,
.max_layers = COMP_MAX_LAYERS,
.max_layers = RENDER_MAX_LAYERS,
.views_per_layer = COMP_VIEWS_PER_LAYER,
.image_array_size = r->compute.layer.image_array_size,
};
@ -789,7 +789,7 @@ render_resources_init(struct render_resources *r,
struct compute_layer_params layer_timewarp_params = {
.do_timewarp = true,
.do_color_correction = true,
.max_layers = COMP_MAX_LAYERS,
.max_layers = RENDER_MAX_LAYERS,
.views_per_layer = COMP_VIEWS_PER_LAYER,
.image_array_size = r->compute.layer.image_array_size,
};
@ -833,7 +833,7 @@ render_resources_init(struct render_resources *r,
&r->compute.distortion.pipeline_layout)); // out_pipeline_layout
struct compute_distortion_params distortion_params = {
.distortion_texel_count = COMP_DISTORTION_IMAGE_DIMENSIONS,
.distortion_texel_count = RENDER_DISTORTION_IMAGE_DIMENSIONS,
.do_timewarp = false,
};
@ -846,7 +846,7 @@ render_resources_init(struct render_resources *r,
&r->compute.distortion.pipeline)); // out_compute_pipeline
struct compute_distortion_params distortion_timewarp_params = {
.distortion_texel_count = COMP_DISTORTION_IMAGE_DIMENSIONS,
.distortion_texel_count = RENDER_DISTORTION_IMAGE_DIMENSIONS,
.do_timewarp = true,
};

View file

@ -20,7 +20,7 @@
// Should we do timewarp.
layout(constant_id = 1) const bool do_timewarp = false;
layout(constant_id = 2) const bool do_color_correction = true;
layout(constant_id = 3) const int COMP_MAX_LAYERS = 16;
layout(constant_id = 3) const int RENDER_MAX_LAYERS = 16;
layout(constant_id = 4) const int COMP_VIEWS_PER_LAYER = 2;
layout(constant_id = 5) const int SAMPLER_ARRAY_SIZE = 16;
@ -33,29 +33,29 @@ layout(set = 0, binding = 3, std140) uniform restrict Config
{
ivec4 views[2];
vec4 pre_transform[2];
vec4 post_transform[COMP_MAX_LAYERS][2];
vec4 post_transform[RENDER_MAX_LAYERS][2];
// corresponds to enum xrt_layer_type
uvec2 layer_type_and_unpremultiplied[COMP_MAX_LAYERS];
uvec2 layer_type_and_unpremultiplied[RENDER_MAX_LAYERS];
// which image/sampler(s) correspond to each layer
ivec2 images_samplers[COMP_MAX_LAYERS][2];
ivec2 images_samplers[RENDER_MAX_LAYERS][2];
// for projection layers
// timewarp matrices
mat4 transform[COMP_MAX_LAYERS][2];
mat4 transform[RENDER_MAX_LAYERS][2];
// for quad layers
// all quad transforms and coordinates are in view space
vec4 quad_position[COMP_MAX_LAYERS][2];
vec4 quad_normal[COMP_MAX_LAYERS][2];
mat4 inverse_quad_transform[COMP_MAX_LAYERS][2];
vec4 quad_position[RENDER_MAX_LAYERS][2];
vec4 quad_normal[RENDER_MAX_LAYERS][2];
mat4 inverse_quad_transform[RENDER_MAX_LAYERS][2];
// quad extent in world scale
vec2 quad_extent[COMP_MAX_LAYERS];
vec2 quad_extent[RENDER_MAX_LAYERS];
} ubo;
@ -227,7 +227,7 @@ vec4 do_quad(uint view_index, vec2 view_uv, uint layer)
vec4 do_layers(vec2 view_uv, uint view_index)
{
vec4 accum = vec4(0, 0, 0, 0);
for (uint layer = 0; layer < COMP_MAX_LAYERS; layer++) {
for (uint layer = 0; layer < RENDER_MAX_LAYERS; layer++) {
bool use_layer = false;
vec4 rgba = vec4(0, 0, 0, 0);