v2: - Fix a missing check in has_layout() v3: - Mention shader storage block in error message for layout qualifiers (Kristian). Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>tags/11.1-branchpoint
@@ -491,6 +491,7 @@ struct ast_type_qualifier { | |||
/** \name Layout qualifiers for GL_ARB_uniform_buffer_object */ | |||
/** \{ */ | |||
unsigned std140:1; | |||
unsigned std430:1; | |||
unsigned shared:1; | |||
unsigned packed:1; | |||
unsigned column_major:1; |
@@ -2920,11 +2920,13 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual, | |||
var->data.depth_layout = ir_depth_layout_none; | |||
if (qual->flags.q.std140 || | |||
qual->flags.q.std430 || | |||
qual->flags.q.packed || | |||
qual->flags.q.shared) { | |||
_mesa_glsl_error(loc, state, | |||
"uniform block layout qualifiers std140, packed, and " | |||
"shared can only be applied to uniform blocks, not " | |||
"uniform and shader storage block layout qualifiers " | |||
"std140, std430, packed, and shared can only be " | |||
"applied to uniform or shader storage blocks, not " | |||
"members"); | |||
} | |||
@@ -5691,12 +5693,14 @@ ast_process_structure_or_interface_block(exec_list *instructions, | |||
const struct ast_type_qualifier *const qual = | |||
& decl_list->type->qualifier; | |||
if (qual->flags.q.std140 || | |||
qual->flags.q.std430 || | |||
qual->flags.q.packed || | |||
qual->flags.q.shared) { | |||
_mesa_glsl_error(&loc, state, | |||
"uniform/shader storage block layout qualifiers " | |||
"std140, packed, and shared can only be applied " | |||
"to uniform/shader storage blocks, not members"); | |||
"std140, std430, packed, and shared can only be " | |||
"applied to uniform/shader storage blocks, not " | |||
"members"); | |||
} | |||
if (qual->flags.q.constant) { | |||
@@ -5908,6 +5912,13 @@ ast_interface_block::hir(exec_list *instructions, | |||
this->block_name); | |||
} | |||
if (!this->layout.flags.q.buffer && | |||
this->layout.flags.q.std430) { | |||
_mesa_glsl_error(&loc, state, | |||
"std430 storage block layout qualifier is supported " | |||
"only for shader storage blocks"); | |||
} | |||
/* The ast_interface_block has a list of ast_declarator_lists. We | |||
* need to turn those into ir_variables with an association | |||
* with this uniform block. | |||
@@ -5917,6 +5928,8 @@ ast_interface_block::hir(exec_list *instructions, | |||
packing = GLSL_INTERFACE_PACKING_SHARED; | |||
} else if (this->layout.flags.q.packed) { | |||
packing = GLSL_INTERFACE_PACKING_PACKED; | |||
} else if (this->layout.flags.q.std430) { | |||
packing = GLSL_INTERFACE_PACKING_STD430; | |||
} else { | |||
/* The default layout is std140. | |||
*/ |
@@ -65,6 +65,7 @@ ast_type_qualifier::has_layout() const | |||
|| this->flags.q.depth_less | |||
|| this->flags.q.depth_unchanged | |||
|| this->flags.q.std140 | |||
|| this->flags.q.std430 | |||
|| this->flags.q.shared | |||
|| this->flags.q.column_major | |||
|| this->flags.q.row_major | |||
@@ -123,6 +124,7 @@ ast_type_qualifier::merge_qualifier(YYLTYPE *loc, | |||
ubo_layout_mask.flags.q.std140 = 1; | |||
ubo_layout_mask.flags.q.packed = 1; | |||
ubo_layout_mask.flags.q.shared = 1; | |||
ubo_layout_mask.flags.q.std430 = 1; | |||
ast_type_qualifier ubo_binding_mask; | |||
ubo_binding_mask.flags.i = 0; |
@@ -1199,6 +1199,8 @@ layout_qualifier_id: | |||
$$.flags.q.std140 = 1; | |||
} else if (match_layout_qualifier($1, "shared", state) == 0) { | |||
$$.flags.q.shared = 1; | |||
} else if (match_layout_qualifier($1, "std430", state) == 0) { | |||
$$.flags.q.std430 = 1; | |||
} else if (match_layout_qualifier($1, "column_major", state) == 0) { | |||
$$.flags.q.column_major = 1; | |||
/* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed |
@@ -77,7 +77,8 @@ enum glsl_sampler_dim { | |||
enum glsl_interface_packing { | |||
GLSL_INTERFACE_PACKING_STD140, | |||
GLSL_INTERFACE_PACKING_SHARED, | |||
GLSL_INTERFACE_PACKING_PACKED | |||
GLSL_INTERFACE_PACKING_PACKED, | |||
GLSL_INTERFACE_PACKING_STD430 | |||
}; | |||
enum glsl_matrix_layout { |
@@ -119,8 +119,16 @@ private: | |||
v->IndexName = v->Name; | |||
} | |||
const unsigned alignment = type->std140_base_alignment(v->RowMajor); | |||
unsigned size = type->std140_size(v->RowMajor); | |||
unsigned alignment = 0; | |||
unsigned size = 0; | |||
if (v->Type->interface_packing == GLSL_INTERFACE_PACKING_STD430) { | |||
alignment = type->std430_base_alignment(v->RowMajor); | |||
size = type->std430_size(v->RowMajor); | |||
} else { | |||
alignment = type->std140_base_alignment(v->RowMajor); | |||
size = type->std140_size(v->RowMajor); | |||
} | |||
this->offset = glsl_align(this->offset, alignment); | |||
v->Offset = this->offset; | |||
@@ -255,7 +263,8 @@ link_uniform_blocks(void *mem_ctx, | |||
== unsigned(ubo_packing_shared)); | |||
STATIC_ASSERT(unsigned(GLSL_INTERFACE_PACKING_PACKED) | |||
== unsigned(ubo_packing_packed)); | |||
STATIC_ASSERT(unsigned(GLSL_INTERFACE_PACKING_STD430) | |||
== unsigned(ubo_packing_std430)); | |||
hash_table_foreach (block_hash, entry) { | |||
const struct link_uniform_block_active *const b = |
@@ -2454,7 +2454,8 @@ enum gl_uniform_block_packing | |||
{ | |||
ubo_packing_std140, | |||
ubo_packing_shared, | |||
ubo_packing_packed | |||
ubo_packing_packed, | |||
ubo_packing_std430 | |||
}; | |||