1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright © 2009 Intel Corporation 3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a 5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the "Software"), 6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to deal in the Software without restriction, including without limitation 7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and/or sell copies of the Software, and to permit persons to whom the 9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software is furnished to do so, subject to the following conditions: 10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the next 12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * paragraph) shall be included in all copies or substantial portions of the 13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software. 14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * DEALINGS IN THE SOFTWARE. 22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <stdio.h> 25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <stdlib.h> 26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "main/core.h" /* for Elements */ 27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "glsl_symbol_table.h" 28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "glsl_parser_extras.h" 29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "glsl_types.h" 30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "builtin_types.h" 31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgextern "C" { 32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "program/hash_table.h" 33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orghash_table *glsl_type::array_types = NULL; 36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orghash_table *glsl_type::record_types = NULL; 37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid *glsl_type::mem_ctx = NULL; 38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::init_ralloc_type_ctx(void) 41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (glsl_type::mem_ctx == NULL) { 43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type::mem_ctx = ralloc_autofree_context(); 44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(glsl_type::mem_ctx != NULL); 45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::glsl_type(GLenum gl_type, 49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_base_type base_type, unsigned vector_elements, 50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned matrix_columns, const char *name) : 51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org gl_type(gl_type), 52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org base_type(base_type), 53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), 54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org sampler_type(0), 55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org vector_elements(vector_elements), matrix_columns(matrix_columns), 56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org length(0) 57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org init_ralloc_type_ctx(); 59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->name = ralloc_strdup(this->mem_ctx, name); 60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Neither dimension is zero or both dimensions are zero. 61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert((vector_elements == 0) == (matrix_columns == 0)); 63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org memset(& fields, 0, sizeof(fields)); 64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::glsl_type(GLenum gl_type, 67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org enum glsl_sampler_dim dim, bool shadow, bool array, 68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned type, const char *name) : 69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org gl_type(gl_type), 70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org base_type(GLSL_TYPE_SAMPLER), 71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org sampler_dimensionality(dim), sampler_shadow(shadow), 72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org sampler_array(array), sampler_type(type), 73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org vector_elements(0), matrix_columns(0), 74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org length(0) 75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org init_ralloc_type_ctx(); 77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->name = ralloc_strdup(this->mem_ctx, name); 78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org memset(& fields, 0, sizeof(fields)); 79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, 82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const char *name) : 83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org base_type(GLSL_TYPE_STRUCT), 84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), 85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org sampler_type(0), 86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org vector_elements(0), matrix_columns(0), 87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org length(num_fields) 88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned int i; 90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org init_ralloc_type_ctx(); 92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->name = ralloc_strdup(this->mem_ctx, name); 93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->fields.structure = ralloc_array(this->mem_ctx, 94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_struct_field, length); 95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (i = 0; i < length; i++) { 96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->fields.structure[i].type = fields[i].type; 97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->fields.structure[i].name = ralloc_strdup(this->fields.structure, 98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org fields[i].name); 99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void 103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgadd_types_to_symbol_table(glsl_symbol_table *symtab, 104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct glsl_type *types, 105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned num_types, bool warn) 106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (void) warn; 108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (unsigned i = 0; i < num_types; i++) { 110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org symtab->add_type(types[i].name, & types[i]); 111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgbool 115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::contains_sampler() const 116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->is_array()) { 118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return this->fields.array->contains_sampler(); 119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } else if (this->is_record()) { 120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (unsigned int i = 0; i < this->length; i++) { 121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->fields.structure[i].type->contains_sampler()) 122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return true; 123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return false; 125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } else { 126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return this->is_sampler(); 127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orggl_texture_index 131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::sampler_index() const 132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type *const t = (this->is_array()) ? this->fields.array : this; 134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(t->is_sampler()); 136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org switch (t->sampler_dimensionality) { 138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_SAMPLER_DIM_1D: 139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return (t->sampler_array) ? TEXTURE_1D_ARRAY_INDEX : TEXTURE_1D_INDEX; 140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_SAMPLER_DIM_2D: 141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return (t->sampler_array) ? TEXTURE_2D_ARRAY_INDEX : TEXTURE_2D_INDEX; 142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_SAMPLER_DIM_3D: 143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return TEXTURE_3D_INDEX; 144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_SAMPLER_DIM_CUBE: 145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return TEXTURE_CUBE_INDEX; 146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_SAMPLER_DIM_RECT: 147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return TEXTURE_RECT_INDEX; 148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_SAMPLER_DIM_BUF: 149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return TEXTURE_BUFFER_INDEX; 150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_SAMPLER_DIM_EXTERNAL: 151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return TEXTURE_EXTERNAL_INDEX; 152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org default: 153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(!"Should not get here."); 154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return TEXTURE_BUFFER_INDEX; 155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::generate_100ES_types(glsl_symbol_table *symtab) 160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org add_types_to_symbol_table(symtab, builtin_core_types, 162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Elements(builtin_core_types), 163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org false); 164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org add_types_to_symbol_table(symtab, builtin_structure_types, 165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Elements(builtin_structure_types), 166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org false); 167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org add_types_to_symbol_table(symtab, void_type, 1, false); 168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::generate_110_types(glsl_symbol_table *symtab, bool add_deprecated) 172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org generate_100ES_types(symtab); 174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org add_types_to_symbol_table(symtab, builtin_110_types, 176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Elements(builtin_110_types), 177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org false); 178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org add_types_to_symbol_table(symtab, &_sampler3D_type, 1, false); 179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (add_deprecated) { 180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org add_types_to_symbol_table(symtab, builtin_110_deprecated_structure_types, 181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Elements(builtin_110_deprecated_structure_types), 182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org false); 183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::generate_120_types(glsl_symbol_table *symtab, bool add_deprecated) 189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org generate_110_types(symtab, add_deprecated); 191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org add_types_to_symbol_table(symtab, builtin_120_types, 193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Elements(builtin_120_types), false); 194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::generate_130_types(glsl_symbol_table *symtab, bool add_deprecated) 199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org generate_120_types(symtab, add_deprecated); 201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org add_types_to_symbol_table(symtab, builtin_130_types, 203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Elements(builtin_130_types), false); 204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org generate_EXT_texture_array_types(symtab, false); 205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::generate_140_types(glsl_symbol_table *symtab) 210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org generate_130_types(symtab, false); 212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org add_types_to_symbol_table(symtab, builtin_140_types, 214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Elements(builtin_140_types), false); 215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org add_types_to_symbol_table(symtab, builtin_EXT_texture_buffer_object_types, 217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Elements(builtin_EXT_texture_buffer_object_types), 218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org false); 219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::generate_ARB_texture_rectangle_types(glsl_symbol_table *symtab, 224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool warn) 225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org add_types_to_symbol_table(symtab, builtin_ARB_texture_rectangle_types, 227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Elements(builtin_ARB_texture_rectangle_types), 228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org warn); 229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::generate_EXT_texture_array_types(glsl_symbol_table *symtab, 234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool warn) 235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org add_types_to_symbol_table(symtab, builtin_EXT_texture_array_types, 237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Elements(builtin_EXT_texture_array_types), 238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org warn); 239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::generate_OES_texture_3D_types(glsl_symbol_table *symtab, bool warn) 244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org add_types_to_symbol_table(symtab, &_sampler3D_type, 1, warn); 246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::generate_OES_EGL_image_external_types(glsl_symbol_table *symtab, 251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool warn) 252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org add_types_to_symbol_table(symtab, builtin_OES_EGL_image_external_types, 254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Elements(builtin_OES_EGL_image_external_types), 255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org warn); 256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state) 260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org switch (state->language_version) { 262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case 100: 263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(state->es_shader); 264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type::generate_100ES_types(state->symbols); 265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org break; 266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case 110: 267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type::generate_110_types(state->symbols, true); 268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org break; 269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case 120: 270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type::generate_120_types(state->symbols, true); 271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org break; 272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case 130: 273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type::generate_130_types(state->symbols, true); 274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org break; 275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case 140: 276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type::generate_140_types(state->symbols); 277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org break; 278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org default: 279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* error */ 280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org break; 281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (state->ARB_texture_rectangle_enable || 284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->language_version >= 140) { 285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type::generate_ARB_texture_rectangle_types(state->symbols, 286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->ARB_texture_rectangle_warn); 287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 288f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (state->OES_texture_3D_enable && state->language_version == 100) { 289f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type::generate_OES_texture_3D_types(state->symbols, 290f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->OES_texture_3D_warn); 291f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 292f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 293f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (state->EXT_texture_array_enable && state->language_version < 130) { 294f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org // These are already included in 130; don't create twice. 295f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type::generate_EXT_texture_array_types(state->symbols, 296f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->EXT_texture_array_warn); 297f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 298f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 299f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* We cannot check for language_version == 100 here because we need the 300f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * types to support fixed-function program generation. But this is fine 301f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * since the extension is never enabled for OpenGL contexts. 302f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 303f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (state->OES_EGL_image_external_enable) { 304f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type::generate_OES_EGL_image_external_types(state->symbols, 305f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->OES_EGL_image_external_warn); 306f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 307f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 308f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 309f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 310f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgconst glsl_type *glsl_type::get_base_type() const 311f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 312f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org switch (base_type) { 313f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_UINT: 314f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return uint_type; 315f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_INT: 316f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return int_type; 317f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_FLOAT: 318f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return float_type; 319f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_BOOL: 320f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return bool_type; 321f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org default: 322f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return error_type; 323f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 324f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 325f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 326f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 327f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgconst glsl_type *glsl_type::get_scalar_type() const 328f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 329f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type *type = this; 330f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 331f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Handle arrays */ 332f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org while (type->base_type == GLSL_TYPE_ARRAY) 333f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org type = type->fields.array; 334f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 335f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Handle vectors and matrices */ 336f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org switch (type->base_type) { 337f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_UINT: 338f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return uint_type; 339f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_INT: 340f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return int_type; 341f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_FLOAT: 342f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return float_type; 343f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org default: 344f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Handle everything else */ 345f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return type; 346f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 347f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 348f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 349f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 350f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 351f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_glsl_release_types(void) 352f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 353f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (glsl_type::array_types != NULL) { 354f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org hash_table_dtor(glsl_type::array_types); 355f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type::array_types = NULL; 356f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 357f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 358f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (glsl_type::record_types != NULL) { 359f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org hash_table_dtor(glsl_type::record_types); 360f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type::record_types = NULL; 361f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 362f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 363f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 364f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 365f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::glsl_type(const glsl_type *array, unsigned length) : 366f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org base_type(GLSL_TYPE_ARRAY), 367f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), 368f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org sampler_type(0), 369f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org vector_elements(0), matrix_columns(0), 370f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org name(NULL), length(length) 371f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 372f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->fields.array = array; 373f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Inherit the gl type of the base. The GL type is used for 374f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * uniform/statevar handling in Mesa and the arrayness of the type 375f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * is represented by the size rather than the type. 376f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 377f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->gl_type = array->gl_type; 378f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 379f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Allow a maximum of 10 characters for the array size. This is enough 380f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * for 32-bits of ~0. The extra 3 are for the '[', ']', and terminating 381f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * NUL. 382f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 383f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const unsigned name_length = strlen(array->name) + 10 + 3; 384f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org char *const n = (char *) ralloc_size(this->mem_ctx, name_length); 385f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 386f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (length == 0) 387f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org snprintf(n, name_length, "%s[]", array->name); 388f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org else 389f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org snprintf(n, name_length, "%s[%u]", array->name, length); 390f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 391f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->name = n; 392f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 393f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 394f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 395f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgconst glsl_type * 396f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns) 397f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 398f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (base_type == GLSL_TYPE_VOID) 399f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return void_type; 400f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 401f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if ((rows < 1) || (rows > 4) || (columns < 1) || (columns > 4)) 402f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return error_type; 403f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 404f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Treat GLSL vectors as Nx1 matrices. 405f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 406f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (columns == 1) { 407f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org switch (base_type) { 408f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_UINT: 409f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return uint_type + (rows - 1); 410f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_INT: 411f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return int_type + (rows - 1); 412f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_FLOAT: 413f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return float_type + (rows - 1); 414f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_BOOL: 415f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return bool_type + (rows - 1); 416f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org default: 417f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return error_type; 418f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 419f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } else { 420f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if ((base_type != GLSL_TYPE_FLOAT) || (rows == 1)) 421f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return error_type; 422f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 423f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following 424f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * combinations are valid: 425f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 426f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 1 2 3 4 427f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 1 428f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 2 x x x 429f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 3 x x x 430f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 4 x x x 431f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 432f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define IDX(c,r) (((c-1)*3) + (r-1)) 433f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 434f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org switch (IDX(columns, rows)) { 435f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case IDX(2,2): return mat2_type; 436f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case IDX(2,3): return mat2x3_type; 437f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case IDX(2,4): return mat2x4_type; 438f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case IDX(3,2): return mat3x2_type; 439f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case IDX(3,3): return mat3_type; 440f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case IDX(3,4): return mat3x4_type; 441f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case IDX(4,2): return mat4x2_type; 442f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case IDX(4,3): return mat4x3_type; 443f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case IDX(4,4): return mat4_type; 444f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org default: return error_type; 445f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 446f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 447f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 448f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(!"Should not get here."); 449f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return error_type; 450f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 451f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 452f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 453f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgconst glsl_type * 454f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::get_array_instance(const glsl_type *base, unsigned array_size) 455f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 456f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 457f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (array_types == NULL) { 458f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org array_types = hash_table_ctor(64, hash_table_string_hash, 459f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org hash_table_string_compare); 460f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 461f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 462f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Generate a name using the base type pointer in the key. This is 463f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * done because the name of the base type may not be unique across 464f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * shaders. For example, two shaders may have different record types 465f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * named 'foo'. 466f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 467f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org char key[128]; 468f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org snprintf(key, sizeof(key), "%p[%u]", (void *) base, array_size); 469f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 470f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type *t = (glsl_type *) hash_table_find(array_types, key); 471f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (t == NULL) { 472f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org t = new glsl_type(base, array_size); 473f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 474f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org hash_table_insert(array_types, (void *) t, ralloc_strdup(mem_ctx, key)); 475f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 476f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 477f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(t->base_type == GLSL_TYPE_ARRAY); 478f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(t->length == array_size); 479f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(t->fields.array == base); 480f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 481f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return t; 482f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 483f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 484f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 485f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgint 486f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::record_key_compare(const void *a, const void *b) 487f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 488f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type *const key1 = (glsl_type *) a; 489f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type *const key2 = (glsl_type *) b; 490f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 491f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Return zero is the types match (there is zero difference) or non-zero 492f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * otherwise. 493f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 494f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (strcmp(key1->name, key2->name) != 0) 495f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 1; 496f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 497f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (key1->length != key2->length) 498f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 1; 499f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 500f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (unsigned i = 0; i < key1->length; i++) { 501f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (key1->fields.structure[i].type != key2->fields.structure[i].type) 502f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 1; 503f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (strcmp(key1->fields.structure[i].name, 504f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org key2->fields.structure[i].name) != 0) 505f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 1; 506f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 507f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 508f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 0; 509f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 510f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 511f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 512f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgunsigned 513f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::record_key_hash(const void *a) 514f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 515f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type *const key = (glsl_type *) a; 516f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org char hash_key[128]; 517f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned size = 0; 518f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 519f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org size = snprintf(hash_key, sizeof(hash_key), "%08x", key->length); 520f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 521f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (unsigned i = 0; i < key->length; i++) { 522f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (size >= sizeof(hash_key)) 523f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org break; 524f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 525f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org size += snprintf(& hash_key[size], sizeof(hash_key) - size, 526f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org "%p", (void *) key->fields.structure[i].type); 527f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 528f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 529f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return hash_table_string_hash(& hash_key); 530f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 531f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 532f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 533f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgconst glsl_type * 534f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::get_record_instance(const glsl_struct_field *fields, 535f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned num_fields, 536f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const char *name) 537f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 538f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type key(fields, num_fields, name); 539f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 540f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (record_types == NULL) { 541f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org record_types = hash_table_ctor(64, record_key_hash, record_key_compare); 542f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 543f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 544f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type *t = (glsl_type *) hash_table_find(record_types, & key); 545f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (t == NULL) { 546f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org t = new glsl_type(fields, num_fields, name); 547f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 548f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org hash_table_insert(record_types, (void *) t, t); 549f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 550f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 551f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(t->base_type == GLSL_TYPE_STRUCT); 552f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(t->length == num_fields); 553f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(strcmp(t->name, name) == 0); 554f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 555f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return t; 556f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 557f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 558f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 559f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgconst glsl_type * 560f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::field_type(const char *name) const 561f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 562f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->base_type != GLSL_TYPE_STRUCT) 563f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return error_type; 564f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 565f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (unsigned i = 0; i < this->length; i++) { 566f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (strcmp(name, this->fields.structure[i].name) == 0) 567f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return this->fields.structure[i].type; 568f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 569f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 570f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return error_type; 571f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 572f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 573f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 574f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgint 575f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::field_index(const char *name) const 576f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 577f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->base_type != GLSL_TYPE_STRUCT) 578f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return -1; 579f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 580f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (unsigned i = 0; i < this->length; i++) { 581f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (strcmp(name, this->fields.structure[i].name) == 0) 582f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return i; 583f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 584f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 585f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return -1; 586f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 587f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 588f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 589f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgunsigned 590f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::component_slots() const 591f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 592f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org switch (this->base_type) { 593f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_UINT: 594f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_INT: 595f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_FLOAT: 596f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_BOOL: 597f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return this->components(); 598f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 599f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_STRUCT: { 600f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned size = 0; 601f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 602f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (unsigned i = 0; i < this->length; i++) 603f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org size += this->fields.structure[i].type->component_slots(); 604f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 605f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return size; 606f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 607f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 608f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GLSL_TYPE_ARRAY: 609f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return this->length * this->fields.array->component_slots(); 610f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 611f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org default: 612f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 0; 613f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 614f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 615f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 616f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgbool 617f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::can_implicitly_convert_to(const glsl_type *desired) const 618f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 619f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this == desired) 620f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return true; 621f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 622f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* There is no conversion among matrix types. */ 623f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->matrix_columns > 1 || desired->matrix_columns > 1) 624f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return false; 625f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 626f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* int and uint can be converted to float. */ 627f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return desired->is_float() 628f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org && this->is_integer() 629f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org && this->vector_elements == desired->vector_elements; 630f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 631f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 632f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgunsigned 633f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::std140_base_alignment(bool row_major) const 634f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 635f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* (1) If the member is a scalar consuming <N> basic machine units, the 636f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * base alignment is <N>. 637f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 638f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (2) If the member is a two- or four-component vector with components 639f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * consuming <N> basic machine units, the base alignment is 2<N> or 640f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 4<N>, respectively. 641f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 642f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (3) If the member is a three-component vector with components consuming 643f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * <N> basic machine units, the base alignment is 4<N>. 644f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 645f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->is_scalar() || this->is_vector()) { 646f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org switch (this->vector_elements) { 647f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case 1: 648f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 4; 649f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case 2: 650f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 8; 651f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case 3: 652f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case 4: 653f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 16; 654f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 655f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 656f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 657f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* (4) If the member is an array of scalars or vectors, the base alignment 658f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and array stride are set to match the base alignment of a single 659f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * array element, according to rules (1), (2), and (3), and rounded up 660f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to the base alignment of a vec4. The array may have padding at the 661f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * end; the base offset of the member following the array is rounded up 662f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to the next multiple of the base alignment. 663f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 664f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (6) If the member is an array of <S> column-major matrices with <C> 665f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * columns and <R> rows, the matrix is stored identically to a row of 666f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * <S>*<C> column vectors with <R> components each, according to rule 667f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (4). 668f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 669f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (8) If the member is an array of <S> row-major matrices with <C> columns 670f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and <R> rows, the matrix is stored identically to a row of <S>*<R> 671f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * row vectors with <C> components each, according to rule (4). 672f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 673f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (10) If the member is an array of <S> structures, the <S> elements of 674f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the array are laid out in order, according to rule (9). 675f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 676f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->is_array()) { 677f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->fields.array->is_scalar() || 678f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->fields.array->is_vector() || 679f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->fields.array->is_matrix()) { 680f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return MAX2(this->fields.array->std140_base_alignment(row_major), 16); 681f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } else { 682f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(this->fields.array->is_record()); 683f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return this->fields.array->std140_base_alignment(row_major); 684f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 685f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 686f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 687f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* (5) If the member is a column-major matrix with <C> columns and 688f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * <R> rows, the matrix is stored identically to an array of 689f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * <C> column vectors with <R> components each, according to 690f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * rule (4). 691f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 692f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (7) If the member is a row-major matrix with <C> columns and <R> 693f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * rows, the matrix is stored identically to an array of <R> 694f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * row vectors with <C> components each, according to rule (4). 695f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 696f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->is_matrix()) { 697f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct glsl_type *vec_type, *array_type; 698f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org int c = this->matrix_columns; 699f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org int r = this->vector_elements; 700f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 701f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (row_major) { 702f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org vec_type = get_instance(GLSL_TYPE_FLOAT, c, 1); 703f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org array_type = glsl_type::get_array_instance(vec_type, r); 704f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } else { 705f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org vec_type = get_instance(GLSL_TYPE_FLOAT, r, 1); 706f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org array_type = glsl_type::get_array_instance(vec_type, c); 707f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 708f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 709f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return array_type->std140_base_alignment(false); 710f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 711f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 712f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* (9) If the member is a structure, the base alignment of the 713f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * structure is <N>, where <N> is the largest base alignment 714f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * value of any of its members, and rounded up to the base 715f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * alignment of a vec4. The individual members of this 716f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * sub-structure are then assigned offsets by applying this set 717f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of rules recursively, where the base offset of the first 718f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * member of the sub-structure is equal to the aligned offset 719f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of the structure. The structure may have padding at the end; 720f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the base offset of the member following the sub-structure is 721f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * rounded up to the next multiple of the base alignment of the 722f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * structure. 723f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 724f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->is_record()) { 725f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned base_alignment = 16; 726f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (unsigned i = 0; i < this->length; i++) { 727f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct glsl_type *field_type = this->fields.structure[i].type; 728f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org base_alignment = MAX2(base_alignment, 729f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org field_type->std140_base_alignment(row_major)); 730f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 731f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return base_alignment; 732f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 733f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 734f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(!"not reached"); 735f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return -1; 736f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 737f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 738f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic unsigned 739f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgalign(unsigned val, unsigned align) 740f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 741f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return (val + align - 1) / align * align; 742f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 743f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 744f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgunsigned 745f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgglsl_type::std140_size(bool row_major) const 746f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 747f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* (1) If the member is a scalar consuming <N> basic machine units, the 748f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * base alignment is <N>. 749f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 750f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (2) If the member is a two- or four-component vector with components 751f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * consuming <N> basic machine units, the base alignment is 2<N> or 752f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 4<N>, respectively. 753f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 754f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (3) If the member is a three-component vector with components consuming 755f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * <N> basic machine units, the base alignment is 4<N>. 756f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 757f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->is_scalar() || this->is_vector()) { 758f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return this->vector_elements * 4; 759f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 760f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 761f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* (5) If the member is a column-major matrix with <C> columns and 762f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * <R> rows, the matrix is stored identically to an array of 763f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * <C> column vectors with <R> components each, according to 764f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * rule (4). 765f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 766f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (6) If the member is an array of <S> column-major matrices with <C> 767f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * columns and <R> rows, the matrix is stored identically to a row of 768f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * <S>*<C> column vectors with <R> components each, according to rule 769f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (4). 770f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 771f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (7) If the member is a row-major matrix with <C> columns and <R> 772f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * rows, the matrix is stored identically to an array of <R> 773f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * row vectors with <C> components each, according to rule (4). 774f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 775f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (8) If the member is an array of <S> row-major matrices with <C> columns 776f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and <R> rows, the matrix is stored identically to a row of <S>*<R> 777f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * row vectors with <C> components each, according to rule (4). 778f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 779f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->is_matrix() || (this->is_array() && 780f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->fields.array->is_matrix())) { 781f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct glsl_type *element_type; 782f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct glsl_type *vec_type; 783f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned int array_len; 784f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 785f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->is_array()) { 786f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org element_type = this->fields.array; 787f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org array_len = this->length; 788f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } else { 789f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org element_type = this; 790f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org array_len = 1; 791f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 792f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 793f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (row_major) { 794f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org vec_type = get_instance(GLSL_TYPE_FLOAT, 795f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org element_type->matrix_columns, 1); 796f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org array_len *= element_type->vector_elements; 797f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } else { 798f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org vec_type = get_instance(GLSL_TYPE_FLOAT, 799f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org element_type->vector_elements, 1); 800f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org array_len *= element_type->matrix_columns; 801f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 802f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type *array_type = glsl_type::get_array_instance(vec_type, 803f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org array_len); 804f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 805f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return array_type->std140_size(false); 806f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 807f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 808f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* (4) If the member is an array of scalars or vectors, the base alignment 809f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and array stride are set to match the base alignment of a single 810f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * array element, according to rules (1), (2), and (3), and rounded up 811f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to the base alignment of a vec4. The array may have padding at the 812f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * end; the base offset of the member following the array is rounded up 813f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to the next multiple of the base alignment. 814f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 815f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (10) If the member is an array of <S> structures, the <S> elements of 816f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the array are laid out in order, according to rule (9). 817f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 818f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->is_array()) { 819f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->fields.array->is_record()) { 820f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return this->length * this->fields.array->std140_size(row_major); 821f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } else { 822f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned element_base_align = 823f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->fields.array->std140_base_alignment(row_major); 824f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return this->length * MAX2(element_base_align, 16); 825f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 826f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 827f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 828f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* (9) If the member is a structure, the base alignment of the 829f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * structure is <N>, where <N> is the largest base alignment 830f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * value of any of its members, and rounded up to the base 831f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * alignment of a vec4. The individual members of this 832f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * sub-structure are then assigned offsets by applying this set 833f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of rules recursively, where the base offset of the first 834f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * member of the sub-structure is equal to the aligned offset 835f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of the structure. The structure may have padding at the end; 836f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the base offset of the member following the sub-structure is 837f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * rounded up to the next multiple of the base alignment of the 838f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * structure. 839f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 840f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (this->is_record()) { 841f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned size = 0; 842f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (unsigned i = 0; i < this->length; i++) { 843f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct glsl_type *field_type = this->fields.structure[i].type; 844f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned align = field_type->std140_base_alignment(row_major); 845f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org size = (size + align - 1) / align * align; 846f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org size += field_type->std140_size(row_major); 847f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 848f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org size = align(size, 849f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->fields.structure[0].type->std140_base_alignment(row_major)); 850f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return size; 851f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 852f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 853f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(!"not reached"); 854f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return -1; 855f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 856