mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 02:10:11 +01:00
compiler: use align instead glsl_align and remove glsl_align
#include "util/u_math.h" when necessary to call align function Reviewed-by: Rohan Garg <rohan.garg@intel.com> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23421>
This commit is contained in:
parent
4134f9ac09
commit
1eda220f18
7 changed files with 31 additions and 33 deletions
|
|
@ -7758,17 +7758,17 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
|
|||
_mesa_glsl_error(&loc, state, "align layout qualifier "
|
||||
"is not a power of 2");
|
||||
} else {
|
||||
fields[i].offset = glsl_align(offset, member_align);
|
||||
fields[i].offset = align(offset, member_align);
|
||||
next_offset = fields[i].offset + size;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fields[i].offset = glsl_align(offset, expl_align);
|
||||
fields[i].offset = align(offset, expl_align);
|
||||
next_offset = fields[i].offset + size;
|
||||
}
|
||||
} else if (!qual->flags.q.explicit_offset) {
|
||||
if (base_alignment != 0 && size != 0)
|
||||
next_offset = glsl_align(next_offset, base_alignment) + size;
|
||||
next_offset = align(next_offset, base_alignment) + size;
|
||||
}
|
||||
|
||||
/* From the ARB_enhanced_layouts spec:
|
||||
|
|
@ -7791,7 +7791,7 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
|
|||
} else {
|
||||
if (layout && layout->flags.q.explicit_xfb_offset) {
|
||||
unsigned base_alignment = field_type->is_64bit() ? 8 : 4;
|
||||
fields[i].offset = glsl_align(block_xfb_offset, base_alignment);
|
||||
fields[i].offset = align(block_xfb_offset, base_alignment);
|
||||
block_xfb_offset += 4 * field_type->component_slots();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include "ir_uniform.h" /* for gl_uniform_storage */
|
||||
#include "linker_util.h"
|
||||
#include "main/shader_types.h"
|
||||
#include "util/u_math.h"
|
||||
|
||||
/**
|
||||
* This file contains code to do a nir-based linking for uniform blocks. This
|
||||
|
|
@ -530,7 +531,7 @@ fill_block(struct gl_uniform_block *block,
|
|||
* or end-of-structure padding), adding one, and rounding up to the next
|
||||
* multiple of the base alignment required for a vec4."
|
||||
*/
|
||||
block->UniformBufferSize = glsl_align(block->UniformBufferSize, 16);
|
||||
block->UniformBufferSize = align(block->UniformBufferSize, 16);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include "compiler/glsl/ir_uniform.h" /* for gl_uniform_storage */
|
||||
#include "linker_util.h"
|
||||
#include "util/u_dynarray.h"
|
||||
#include "util/u_math.h"
|
||||
#include "main/consts_exts.h"
|
||||
#include "main/shader_types.h"
|
||||
|
||||
|
|
@ -1138,10 +1139,10 @@ enter_record(struct nir_link_uniforms_state *state,
|
|||
use_std430);
|
||||
|
||||
if (packing == GLSL_INTERFACE_PACKING_STD430)
|
||||
state->offset = glsl_align(
|
||||
state->offset = align(
|
||||
state->offset, glsl_get_std430_base_alignment(type, row_major));
|
||||
else
|
||||
state->offset = glsl_align(
|
||||
state->offset = align(
|
||||
state->offset, glsl_get_std140_base_alignment(type, row_major));
|
||||
}
|
||||
|
||||
|
|
@ -1161,10 +1162,10 @@ leave_record(struct nir_link_uniforms_state *state,
|
|||
use_std430);
|
||||
|
||||
if (packing == GLSL_INTERFACE_PACKING_STD430)
|
||||
state->offset = glsl_align(
|
||||
state->offset = align(
|
||||
state->offset, glsl_get_std430_base_alignment(type, row_major));
|
||||
else
|
||||
state->offset = glsl_align(
|
||||
state->offset = align(
|
||||
state->offset, glsl_get_std140_base_alignment(type, row_major));
|
||||
}
|
||||
|
||||
|
|
@ -1407,7 +1408,7 @@ nir_link_uniform(const struct gl_constants *consts,
|
|||
alignment =
|
||||
glsl_get_std430_base_alignment(type, uniform->row_major);
|
||||
}
|
||||
state->offset = glsl_align(state->offset, alignment);
|
||||
state->offset = align(state->offset, alignment);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include "ir_uniform.h"
|
||||
#include "link_uniform_block_active_visitor.h"
|
||||
#include "util/hash_table.h"
|
||||
#include "util/u_math.h"
|
||||
#include "program.h"
|
||||
#include "main/errors.h"
|
||||
#include "main/shader_types.h"
|
||||
|
|
@ -71,10 +72,10 @@ private:
|
|||
{
|
||||
assert(type->is_struct());
|
||||
if (packing == GLSL_INTERFACE_PACKING_STD430)
|
||||
this->offset = glsl_align(
|
||||
this->offset = align(
|
||||
this->offset, type->std430_base_alignment(row_major));
|
||||
else
|
||||
this->offset = glsl_align(
|
||||
this->offset = align(
|
||||
this->offset, type->std140_base_alignment(row_major));
|
||||
}
|
||||
|
||||
|
|
@ -92,10 +93,10 @@ private:
|
|||
* multiple of the base alignment of the structure.
|
||||
*/
|
||||
if (packing == GLSL_INTERFACE_PACKING_STD430)
|
||||
this->offset = glsl_align(
|
||||
this->offset = align(
|
||||
this->offset, type->std430_base_alignment(row_major));
|
||||
else
|
||||
this->offset = glsl_align(
|
||||
this->offset = align(
|
||||
this->offset, type->std140_base_alignment(row_major));
|
||||
}
|
||||
|
||||
|
|
@ -169,7 +170,7 @@ private:
|
|||
size = type_for_size->std140_size(v->RowMajor);
|
||||
}
|
||||
|
||||
this->offset = glsl_align(this->offset, alignment);
|
||||
this->offset = align(this->offset, alignment);
|
||||
v->Offset = this->offset;
|
||||
|
||||
this->offset += size;
|
||||
|
|
@ -184,7 +185,7 @@ private:
|
|||
* rounding up to the next multiple of the base alignment required
|
||||
* for a vec4.
|
||||
*/
|
||||
this->buffer_size = glsl_align(this->offset, 16);
|
||||
this->buffer_size = align(this->offset, 16);
|
||||
}
|
||||
|
||||
bool use_std430_as_default;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
#include "main/shader_types.h"
|
||||
#include "main/consts_exts.h"
|
||||
#include "util/strndup.h"
|
||||
#include "util/u_math.h"
|
||||
|
||||
/**
|
||||
* \file link_uniforms.cpp
|
||||
|
|
@ -278,6 +279,6 @@ link_calculate_matrix_stride(const glsl_type *matrix, bool row_major,
|
|||
* vec4.
|
||||
*/
|
||||
return packing == GLSL_INTERFACE_PACKING_STD430
|
||||
? (items < 3 ? items * N : glsl_align(items * N, 16))
|
||||
: glsl_align(items * N, 16);
|
||||
? (items < 3 ? items * N : align(items * N, 16))
|
||||
: align(items * N, 16);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2186,15 +2186,15 @@ glsl_type::std140_size(bool row_major) const
|
|||
if (field_type->is_unsized_array())
|
||||
continue;
|
||||
|
||||
size = glsl_align(size, base_alignment);
|
||||
size = align(size, base_alignment);
|
||||
size += field_type->std140_size(field_row_major);
|
||||
|
||||
max_align = MAX2(base_alignment, max_align);
|
||||
|
||||
if (field_type->is_struct() && (i + 1 < this->length))
|
||||
size = glsl_align(size, 16);
|
||||
size = align(size, 16);
|
||||
}
|
||||
size = glsl_align(size, MAX2(max_align, 16));
|
||||
size = align(size, MAX2(max_align, 16));
|
||||
return size;
|
||||
}
|
||||
|
||||
|
|
@ -2214,14 +2214,14 @@ glsl_type::get_explicit_std140_type(bool row_major) const
|
|||
else
|
||||
vec_type = get_instance(this->base_type, this->vector_elements, 1);
|
||||
unsigned elem_size = vec_type->std140_size(false);
|
||||
unsigned stride = glsl_align(elem_size, 16);
|
||||
unsigned stride = align(elem_size, 16);
|
||||
return get_instance(this->base_type, this->vector_elements,
|
||||
this->matrix_columns, stride, row_major);
|
||||
} else if (this->is_array()) {
|
||||
unsigned elem_size = this->fields.array->std140_size(row_major);
|
||||
const glsl_type *elem_type =
|
||||
this->fields.array->get_explicit_std140_type(row_major);
|
||||
unsigned stride = glsl_align(elem_size, 16);
|
||||
unsigned stride = align(elem_size, 16);
|
||||
return get_array_instance(elem_type, this->length, stride);
|
||||
} else if (this->is_struct() || this->is_interface()) {
|
||||
glsl_struct_field *fields = new glsl_struct_field[this->length];
|
||||
|
|
@ -2254,7 +2254,7 @@ glsl_type::get_explicit_std140_type(bool row_major) const
|
|||
assert((unsigned)fields[i].offset >= offset);
|
||||
offset = fields[i].offset;
|
||||
}
|
||||
offset = glsl_align(offset, falign);
|
||||
offset = align(offset, falign);
|
||||
fields[i].offset = offset;
|
||||
offset += fsize;
|
||||
}
|
||||
|
|
@ -2549,12 +2549,12 @@ glsl_type::std430_size(bool row_major) const
|
|||
|
||||
const struct glsl_type *field_type = this->fields.structure[i].type;
|
||||
unsigned base_alignment = field_type->std430_base_alignment(field_row_major);
|
||||
size = glsl_align(size, base_alignment);
|
||||
size = align(size, base_alignment);
|
||||
size += field_type->std430_size(field_row_major);
|
||||
|
||||
max_align = MAX2(base_alignment, max_align);
|
||||
}
|
||||
size = glsl_align(size, max_align);
|
||||
size = align(size, max_align);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
|
@ -2612,7 +2612,7 @@ glsl_type::get_explicit_std430_type(bool row_major) const
|
|||
assert((unsigned)fields[i].offset >= offset);
|
||||
offset = fields[i].offset;
|
||||
}
|
||||
offset = glsl_align(offset, falign);
|
||||
offset = align(offset, falign);
|
||||
fields[i].offset = offset;
|
||||
offset += fsize;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1483,10 +1483,4 @@ struct glsl_function_param {
|
|||
bool out;
|
||||
};
|
||||
|
||||
static inline unsigned int
|
||||
glsl_align(unsigned int a, unsigned int align)
|
||||
{
|
||||
return (a + align - 1) / align * align;
|
||||
}
|
||||
|
||||
#endif /* GLSL_TYPES_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue