mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 23:50:11 +01:00
glsl: allow nonconst indexing of arrays where we can work out an implicit size
Signed-off-by: Chris Forbes <chrisf@ijw.co.nz> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
parent
64a0ae88b9
commit
b7f98f9f09
1 changed files with 36 additions and 1 deletions
|
|
@ -107,6 +107,33 @@ update_max_array_access(ir_rvalue *ir, int idx, YYLTYPE *loc,
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
get_implicit_array_size(struct _mesa_glsl_parse_state *state,
|
||||
ir_rvalue *array)
|
||||
{
|
||||
ir_variable *var = array->variable_referenced();
|
||||
|
||||
/* Inputs in control shader are implicitly sized
|
||||
* to the maximum patch size.
|
||||
*/
|
||||
if (state->stage == MESA_SHADER_TESS_CTRL &&
|
||||
var->data.mode == ir_var_shader_in) {
|
||||
return state->Const.MaxPatchVertices;
|
||||
}
|
||||
|
||||
/* Non-patch inputs in evaluation shader are implicitly sized
|
||||
* to the maximum patch size.
|
||||
*/
|
||||
if (state->stage == MESA_SHADER_TESS_EVAL &&
|
||||
var->data.mode == ir_var_shader_in &&
|
||||
!var->data.patch) {
|
||||
return state->Const.MaxPatchVertices;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ir_rvalue *
|
||||
_mesa_ast_array_index_to_hir(void *mem_ctx,
|
||||
struct _mesa_glsl_parse_state *state,
|
||||
|
|
@ -183,7 +210,15 @@ _mesa_ast_array_index_to_hir(void *mem_ctx,
|
|||
update_max_array_access(array, idx, &loc, state);
|
||||
} else if (const_index == NULL && array->type->is_array()) {
|
||||
if (array->type->is_unsized_array()) {
|
||||
_mesa_glsl_error(&loc, state, "unsized array index must be constant");
|
||||
int implicit_size = get_implicit_array_size(state, array);
|
||||
if (implicit_size) {
|
||||
ir_variable *v = array->whole_variable_referenced();
|
||||
if (v != NULL)
|
||||
v->data.max_array_access = implicit_size - 1;
|
||||
}
|
||||
else {
|
||||
_mesa_glsl_error(&loc, state, "unsized array index must be constant");
|
||||
}
|
||||
} else if (array->type->fields.array->is_interface()
|
||||
&& array->variable_referenced()->data.mode == ir_var_uniform
|
||||
&& !state->is_version(400, 0) && !state->ARB_gpu_shader5_enable) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue