X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fcompiler%2Fglsl_types.cpp;h=73e3abd329d74b528860ff57ebad4896d5193f8b;hb=f546b41f6ac9b4394b931d9e0ac4e30fc3f2c40f;hp=2421bd6195446411ddd1d1462a5a90b419c05372;hpb=7f6a0cb29c89a03441be744680a2145445be3a3c;p=mesa.git diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp index 2421bd61954..73e3abd329d 100644 --- a/src/compiler/glsl_types.cpp +++ b/src/compiler/glsl_types.cpp @@ -55,6 +55,13 @@ glsl_type::glsl_type(GLenum gl_type, vector_elements(vector_elements), matrix_columns(matrix_columns), length(0) { + /* Values of these types must fit in the two bits of + * glsl_type::sampled_type. + */ + STATIC_ASSERT((unsigned(GLSL_TYPE_UINT) & 3) == unsigned(GLSL_TYPE_UINT)); + STATIC_ASSERT((unsigned(GLSL_TYPE_INT) & 3) == unsigned(GLSL_TYPE_INT)); + STATIC_ASSERT((unsigned(GLSL_TYPE_FLOAT) & 3) == unsigned(GLSL_TYPE_FLOAT)); + mtx_lock(&glsl_type::mutex); init_ralloc_type_ctx(); @@ -132,6 +139,10 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, this->fields.structure[i].image_volatile = fields[i].image_volatile; this->fields.structure[i].image_restrict = fields[i].image_restrict; this->fields.structure[i].precision = fields[i].precision; + this->fields.structure[i].explicit_xfb_buffer = + fields[i].explicit_xfb_buffer; + this->fields.structure[i].xfb_buffer = fields[i].xfb_buffer; + this->fields.structure[i].xfb_stride = fields[i].xfb_stride; } mtx_unlock(&glsl_type::mutex); @@ -172,6 +183,10 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, this->fields.structure[i].image_volatile = fields[i].image_volatile; this->fields.structure[i].image_restrict = fields[i].image_restrict; this->fields.structure[i].precision = fields[i].precision; + this->fields.structure[i].explicit_xfb_buffer = + fields[i].explicit_xfb_buffer; + this->fields.structure[i].xfb_buffer = fields[i].xfb_buffer; + this->fields.structure[i].xfb_stride = fields[i].xfb_stride; } mtx_unlock(&glsl_type::mutex); @@ -659,6 +674,8 @@ glsl_type::get_sampler_instance(enum glsl_sampler_dim dim, return error_type; else return samplerExternalOES_type; + case GLSL_SAMPLER_DIM_SUBPASS: + return error_type; } case GLSL_TYPE_INT: if (shadow) @@ -686,6 +703,8 @@ glsl_type::get_sampler_instance(enum glsl_sampler_dim dim, return (array ? isampler2DMSArray_type : isampler2DMS_type); case GLSL_SAMPLER_DIM_EXTERNAL: return error_type; + case GLSL_SAMPLER_DIM_SUBPASS: + return error_type; } case GLSL_TYPE_UINT: if (shadow) @@ -713,6 +732,8 @@ glsl_type::get_sampler_instance(enum glsl_sampler_dim dim, return (array ? usampler2DMSArray_type : usampler2DMS_type); case GLSL_SAMPLER_DIM_EXTERNAL: return error_type; + case GLSL_SAMPLER_DIM_SUBPASS: + return error_type; } default: return error_type; @@ -725,6 +746,8 @@ const glsl_type * glsl_type::get_image_instance(enum glsl_sampler_dim dim, bool array, glsl_base_type type) { + if (dim == GLSL_SAMPLER_DIM_SUBPASS) + return subpassInput_type; switch (type) { case GLSL_TYPE_FLOAT: switch (dim) { @@ -749,6 +772,7 @@ glsl_type::get_image_instance(enum glsl_sampler_dim dim, case GLSL_SAMPLER_DIM_MS: return (array ? image2DMSArray_type : image2DMS_type); case GLSL_SAMPLER_DIM_EXTERNAL: + case GLSL_SAMPLER_DIM_SUBPASS: return error_type; } case GLSL_TYPE_INT: @@ -774,6 +798,7 @@ glsl_type::get_image_instance(enum glsl_sampler_dim dim, case GLSL_SAMPLER_DIM_MS: return (array ? iimage2DMSArray_type : iimage2DMS_type); case GLSL_SAMPLER_DIM_EXTERNAL: + case GLSL_SAMPLER_DIM_SUBPASS: return error_type; } case GLSL_TYPE_UINT: @@ -799,6 +824,7 @@ glsl_type::get_image_instance(enum glsl_sampler_dim dim, case GLSL_SAMPLER_DIM_MS: return (array ? uimage2DMSArray_type : uimage2DMS_type); case GLSL_SAMPLER_DIM_EXTERNAL: + case GLSL_SAMPLER_DIM_SUBPASS: return error_type; } default: @@ -848,7 +874,7 @@ glsl_type::get_array_instance(const glsl_type *base, unsigned array_size) bool -glsl_type::record_compare(const glsl_type *b) const +glsl_type::record_compare(const glsl_type *b, bool match_locations) const { if (this->length != b->length) return false; @@ -879,7 +905,7 @@ glsl_type::record_compare(const glsl_type *b) const if (this->fields.structure[i].matrix_layout != b->fields.structure[i].matrix_layout) return false; - if (this->fields.structure[i].location + if (match_locations && this->fields.structure[i].location != b->fields.structure[i].location) return false; if (this->fields.structure[i].offset @@ -915,6 +941,15 @@ glsl_type::record_compare(const glsl_type *b) const if (this->fields.structure[i].precision != b->fields.structure[i].precision) return false; + if (this->fields.structure[i].explicit_xfb_buffer + != b->fields.structure[i].explicit_xfb_buffer) + return false; + if (this->fields.structure[i].xfb_buffer + != b->fields.structure[i].xfb_buffer) + return false; + if (this->fields.structure[i].xfb_stride + != b->fields.structure[i].xfb_stride) + return false; } return true; @@ -1062,7 +1097,7 @@ function_key_compare(const void *a, const void *b) const glsl_type *const key2 = (glsl_type *) b; if (key1->length != key2->length) - return 1; + return false; return memcmp(key1->fields.parameters, key2->fields.parameters, (key1->length + 1) * sizeof(*key1->fields.parameters)) == 0; @@ -1073,20 +1108,8 @@ static uint32_t function_key_hash(const void *a) { const glsl_type *const key = (glsl_type *) a; - char hash_key[128]; - unsigned size = 0; - - size = snprintf(hash_key, sizeof(hash_key), "%08x", key->length); - - for (unsigned i = 0; i < key->length; i++) { - if (size >= sizeof(hash_key)) - break; - - size += snprintf(& hash_key[size], sizeof(hash_key) - size, - "%p", (void *) key->fields.structure[i].type); - } - - return _mesa_hash_string(hash_key); + return _mesa_hash_data(key->fields.parameters, + (key->length + 1) * sizeof(*key->fields.parameters)); } const glsl_type * @@ -1333,6 +1356,38 @@ glsl_type::uniform_locations() const } } +unsigned +glsl_type::varying_count() const +{ + unsigned size = 0; + + switch (this->base_type) { + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: + case GLSL_TYPE_FLOAT: + case GLSL_TYPE_DOUBLE: + case GLSL_TYPE_BOOL: + return 1; + + case GLSL_TYPE_STRUCT: + case GLSL_TYPE_INTERFACE: + for (unsigned i = 0; i < this->length; i++) + size += this->fields.structure[i].type->varying_count(); + return size; + case GLSL_TYPE_ARRAY: + /* Don't count innermost array elements */ + if (this->without_array()->is_record() || + this->without_array()->is_interface() || + this->fields.array->is_array()) + return this->length * this->fields.array->varying_count(); + else + return this->fields.array->varying_count(); + default: + assert(!"unsupported varying type"); + return 0; + } +} + bool glsl_type::can_implicitly_convert_to(const glsl_type *desired, _mesa_glsl_parse_state *state) const @@ -1340,11 +1395,11 @@ glsl_type::can_implicitly_convert_to(const glsl_type *desired, if (this == desired) return true; - /* ESSL does not allow implicit conversions. If there is no state, we're - * doing intra-stage function linking where these checks have already been - * done. + /* GLSL 1.10 and ESSL do not allow implicit conversions. If there is no + * state, we're doing intra-stage function linking where these checks have + * already been done. */ - if (state && state->es_shader) + if (state && (state->es_shader || !state->is_version(120, 0))) return false; /* There is no conversion among matrix types. */ @@ -1359,11 +1414,14 @@ glsl_type::can_implicitly_convert_to(const glsl_type *desired, if (desired->is_float() && this->is_integer()) return true; - /* With GLSL 4.0 / ARB_gpu_shader5, int can be converted to uint. - * Note that state may be NULL here, when resolving function calls in the - * linker. By this time, all the state-dependent checks have already - * happened though, so allow anything that's allowed in any shader version. */ - if ((!state || state->is_version(400, 0) || state->ARB_gpu_shader5_enable) && + /* With GLSL 4.0, ARB_gpu_shader5, or MESA_shader_integer_functions, int + * can be converted to uint. Note that state may be NULL here, when + * resolving function calls in the linker. By this time, all the + * state-dependent checks have already happened though, so allow anything + * that's allowed in any shader version. + */ + if ((!state || state->is_version(400, 0) || state->ARB_gpu_shader5_enable || + state->MESA_shader_integer_functions_enable) && desired->base_type == GLSL_TYPE_UINT && this->base_type == GLSL_TYPE_INT) return true; @@ -1385,7 +1443,7 @@ glsl_type::can_implicitly_convert_to(const glsl_type *desired, unsigned glsl_type::std140_base_alignment(bool row_major) const { - unsigned N = is_double() ? 8 : 4; + unsigned N = is_64bit() ? 8 : 4; /* (1) If the member is a scalar consuming basic machine units, the * base alignment is . @@ -1503,7 +1561,7 @@ glsl_type::std140_base_alignment(bool row_major) const unsigned glsl_type::std140_size(bool row_major) const { - unsigned N = is_double() ? 8 : 4; + unsigned N = is_64bit() ? 8 : 4; /* (1) If the member is a scalar consuming basic machine units, the * base alignment is . @@ -1640,7 +1698,7 @@ unsigned glsl_type::std430_base_alignment(bool row_major) const { - unsigned N = is_double() ? 8 : 4; + unsigned N = is_64bit() ? 8 : 4; /* (1) If the member is a scalar consuming basic machine units, the * base alignment is . @@ -1749,7 +1807,7 @@ glsl_type::std430_base_alignment(bool row_major) const unsigned glsl_type::std430_array_stride(bool row_major) const { - unsigned N = is_double() ? 8 : 4; + unsigned N = is_64bit() ? 8 : 4; /* Notice that the array stride of a vec3 is not 3 * N but 4 * N. * See OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout" @@ -1767,7 +1825,7 @@ glsl_type::std430_array_stride(bool row_major) const unsigned glsl_type::std430_size(bool row_major) const { - unsigned N = is_double() ? 8 : 4; + unsigned N = is_64bit() ? 8 : 4; /* OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout": * @@ -1848,7 +1906,7 @@ glsl_type::std430_size(bool row_major) const } unsigned -glsl_type::count_attribute_slots(bool vertex_input_slots) const +glsl_type::count_attribute_slots(bool is_vertex_input) const { /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec: * @@ -1882,7 +1940,7 @@ glsl_type::count_attribute_slots(bool vertex_input_slots) const case GLSL_TYPE_BOOL: return this->matrix_columns; case GLSL_TYPE_DOUBLE: - if (this->vector_elements > 2 && !vertex_input_slots) + if (this->vector_elements > 2 && !is_vertex_input) return this->matrix_columns * 2; else return this->matrix_columns; @@ -1891,13 +1949,13 @@ glsl_type::count_attribute_slots(bool vertex_input_slots) const unsigned size = 0; for (unsigned i = 0; i < this->length; i++) - size += this->fields.structure[i].type->count_attribute_slots(vertex_input_slots); + size += this->fields.structure[i].type->count_attribute_slots(is_vertex_input); return size; } case GLSL_TYPE_ARRAY: - return this->length * this->fields.array->count_attribute_slots(vertex_input_slots); + return this->length * this->fields.array->count_attribute_slots(is_vertex_input); case GLSL_TYPE_FUNCTION: case GLSL_TYPE_SAMPLER: @@ -1928,6 +1986,7 @@ glsl_type::coordinate_components() const case GLSL_SAMPLER_DIM_RECT: case GLSL_SAMPLER_DIM_MS: case GLSL_SAMPLER_DIM_EXTERNAL: + case GLSL_SAMPLER_DIM_SUBPASS: size = 2; break; case GLSL_SAMPLER_DIM_3D: