Lines Matching refs:state

67 detect_conflicting_assignments(struct _mesa_glsl_parse_state *state,
70 verify_subroutine_associated_funcs(struct _mesa_glsl_parse_state *state);
74 _mesa_glsl_parse_state *state, ir_variable_mode mode);
129 _mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state)
131 _mesa_glsl_initialize_variables(instructions, state);
133 state->symbols->separate_function_namespace = state->language_version == 110;
135 state->current_function = NULL;
137 state->toplevel_ir = instructions;
139 state->gs_input_prim_type_specified = false;
140 state->tcs_output_vertices_specified = false;
141 state->cs_input_local_size_specified = false;
156 state->symbols->push_scope();
158 foreach_list_typed (ast_node, ast, link, & state->translation_unit)
159 ast->hir(instructions, state);
161 verify_subroutine_associated_funcs(state);
162 detect_recursion_unlinked(state, instructions);
163 detect_conflicting_assignments(state, instructions);
165 state->toplevel_ir = NULL;
186 ir_variable *const var = state->symbols->get_variable("gl_FragCoord");
188 state->fs_uses_gl_fragcoord = var->data.used;
221 remove_per_vertex_blocks(instructions, state, ir_var_shader_in);
222 remove_per_vertex_blocks(instructions, state, ir_var_shader_out);
234 _mesa_glsl_error(&loc, state, "Read from write-only variable `%s'",
242 struct _mesa_glsl_parse_state *state)
253 if (!state->has_implicit_int_to_uint_conversion())
261 if (!state->has_double())
273 if (!state->has_int64())
283 if (!state->has_int64())
302 * \param state GLSL compiler state
310 struct _mesa_glsl_parse_state *state)
312 void *ctx = state;
317 if (!state->has_implicit_conversions())
336 ir_expression_operation op = get_implicit_conversion_operation(to, from->type, state);
349 struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
361 _mesa_glsl_error(loc, state,
371 if (!apply_implicit_conversion(type_a, value_b, state)
372 && !apply_implicit_conversion(type_b, value_a, state)) {
373 _mesa_glsl_error(loc, state,
391 _mesa_glsl_error(loc, state,
434 _mesa_glsl_error(loc, state,
472 _mesa_glsl_error(loc, state,
482 _mesa_glsl_error(loc, state, "type mismatch");
489 struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
500 _mesa_glsl_error(loc, state,
520 struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
525 if (!state->check_bitwise_operations_allowed(loc)) {
536 _mesa_glsl_error(loc, state, "LHS of `%s' must be an integer",
541 _mesa_glsl_error(loc, state, "RHS of `%s' must be an integer",
558 if (!apply_implicit_conversion(type_a, value_b, state)
559 && !apply_implicit_conversion(type_b, value_a, state)) {
560 _mesa_glsl_error(loc, state,
566 _mesa_glsl_warning(loc, state,
580 _mesa_glsl_error(loc, state, "operands of `%s' must have the same "
589 _mesa_glsl_error(loc, state, "operands of `%s' cannot be vectors of "
607 struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
612 if (!state->EXT_gpu_shader4_enable &&
613 !state->check_version(130, 300, loc, "operator '%%' is reserved")) {
623 _mesa_glsl_error(loc, state, "LHS of operator %% must be an integer");
627 _mesa_glsl_error(loc, state, "RHS of operator %% must be an integer");
643 if (!apply_implicit_conversion(type_a, value_b, state) &&
644 !apply_implicit_conversion(type_b, value_a, state)) {
645 _mesa_glsl_error(loc, state,
668 _mesa_glsl_error(loc, state, "type mismatch");
675 struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
689 _mesa_glsl_error(loc, state,
699 if (!apply_implicit_conversion(type_a, value_b, state)
700 && !apply_implicit_conversion(type_b, value_a, state)) {
701 _mesa_glsl_error(loc, state,
710 _mesa_glsl_error(loc, state, "base type mismatch");
732 struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
734 if (!state->check_bitwise_operations_allowed(loc)) {
745 _mesa_glsl_error(loc, state, "LHS of operator %s must be an integer or "
751 _mesa_glsl_error(loc, state, "RHS of operator %s must be an integer or "
760 _mesa_glsl_error(loc, state, "if the first operand of %s is scalar, the "
772 _mesa_glsl_error(loc, state, "vector operands to operator %s must "
829 validate_assignment(struct _mesa_glsl_parse_state *state,
844 if (state->stage == MESA_SHADER_TESS_CTRL && !lhs->type->is_error()) {
850 _mesa_glsl_error(&loc, state,
898 _mesa_glsl_error(&loc, state,
905 if (apply_implicit_conversion(lhs->type, rhs, state)) {
910 _mesa_glsl_error(&loc, state,
930 do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
937 void *ctx = state;
947 _mesa_glsl_error(&lhs_loc, state,
962 if (state->ignore_write_to_readonly_var)
965 _mesa_glsl_error(&lhs_loc, state,
971 !state->check_version(state->allow_glsl_120_subset_in_110 ? 110 : 120,
983 } else if (!lhs->is_lvalue(state)) {
984 _mesa_glsl_error(& lhs_loc, state, "non-lvalue in assignment");
990 validate_assignment(state, lhs_loc, lhs, rhs, is_initializer);
1010 _mesa_glsl_error(& lhs_loc, state, "array size must be > %u due to "
1081 ast_node::hir(exec_list *instructions, struct _mesa_glsl_parse_state *state)
1084 (void) state;
1102 struct _mesa_glsl_parse_state *state)
1104 (void)hir(instructions, state);
1109 struct _mesa_glsl_parse_state *state)
1111 (void)hir(instructions, state);
1209 struct _mesa_glsl_parse_state *state,
1216 void *ctx = state;
1217 ir_rvalue *val = expr->hir(instructions, state);
1224 _mesa_glsl_error(&loc, state, "%s of `%s' must be scalar boolean",
1239 YYLTYPE loc, struct _mesa_glsl_parse_state *state)
1242 && (size > state->Const.MaxTextureCoords)) {
1248 _mesa_glsl_error(&loc, state, "`gl_TexCoord' array size cannot "
1250 state->Const.MaxTextureCoords);
1252 state->clip_dist_size = size;
1253 if (size + state->cull_dist_size > state->Const.MaxClipPlanes) {
1263 _mesa_glsl_error(&loc, state, "`gl_ClipDistance' array size cannot "
1265 state->Const.MaxClipPlanes);
1268 state->cull_dist_size = size;
1269 if (size + state->clip_dist_size > state->Const.MaxClipPlanes) {
1279 _mesa_glsl_error(&loc, state, "`gl_CullDistance' array size cannot "
1281 state->Const.MaxClipPlanes);
1314 struct _mesa_glsl_parse_state *state)
1316 return do_hir(instructions, state, true);
1321 struct _mesa_glsl_parse_state *state)
1323 do_hir(instructions, state, false);
1346 struct _mesa_glsl_parse_state *state,
1349 void *ctx = state;
1420 op[0] = this->subexpressions[0]->hir(instructions, state);
1421 op[1] = this->subexpressions[1]->hir(instructions, state);
1424 do_assignment(instructions, state,
1432 op[0] = this->subexpressions[0]->hir(instructions, state);
1434 type = unary_arithmetic_result_type(op[0]->type, state, & loc);
1442 op[0] = this->subexpressions[0]->hir(instructions, state);
1444 type = unary_arithmetic_result_type(op[0]->type, state, & loc);
1456 op[0] = this->subexpressions[0]->hir(instructions, state);
1457 op[1] = this->subexpressions[1]->hir(instructions, state);
1461 state, & loc);
1469 op[0] = this->subexpressions[0]->hir(instructions, state);
1470 op[1] = this->subexpressions[1]->hir(instructions, state);
1472 type = modulus_result_type(op[0], op[1], state, &loc);
1483 if (!state->check_bitwise_operations_allowed(&loc)) {
1487 op[0] = this->subexpressions[0]->hir(instructions, state);
1488 op[1] = this->subexpressions[1]->hir(instructions, state);
1489 type = shift_result_type(op[0]->type, op[1]->type, this->oper, state,
1500 op[0] = this->subexpressions[0]->hir(instructions, state);
1501 op[1] = this->subexpressions[1]->hir(instructions, state);
1503 type = relational_result_type(op[0], op[1], state, & loc);
1527 op[0] = this->subexpressions[0]->hir(instructions, state);
1528 op[1] = this->subexpressions[1]->hir(instructions, state);
1541 _mesa_glsl_error(& loc, state, "`%s': wrong operand types: "
1546 } else if ((!apply_implicit_conversion(op[0]->type, op[1], state)
1547 && !apply_implicit_conversion(op[1]->type, op[0], state))
1549 _mesa_glsl_error(& loc, state, "operands of `%s' must have the same "
1553 !state->check_version(120, 300, &loc,
1558 _mesa_glsl_error(&loc, state, "subroutine comparisons forbidden");
1562 _mesa_glsl_error(&loc, state, "opaque type comparisons forbidden");
1577 op[0] = this->subexpressions[0]->hir(instructions, state);
1578 op[1] = this->subexpressions[1]->hir(instructions, state);
1579 type = bit_logic_result_type(op[0], op[1], this->oper, state, &loc);
1586 op[0] = this->subexpressions[0]->hir(instructions, state);
1588 if (!state->check_bitwise_operations_allowed(&loc)) {
1593 _mesa_glsl_error(&loc, state, "operand of `~' must be an integer");
1603 op[0] = get_scalar_boolean_operand(instructions, state, this, 0,
1605 op[1] = get_scalar_boolean_operand(&rhs_instructions, state, this, 1,
1637 op[0] = get_scalar_boolean_operand(instructions, state, this, 0,
1639 op[1] = get_scalar_boolean_operand(&rhs_instructions, state, this, 1,
1676 op[0] = get_scalar_boolean_operand(instructions, state, this, 0, "LHS",
1678 op[1] = get_scalar_boolean_operand(instructions, state, this, 1, "RHS",
1686 op[0] = get_scalar_boolean_operand(instructions, state, this, 0,
1698 op[0] = this->subexpressions[0]->hir(instructions, state);
1699 op[1] = this->subexpressions[1]->hir(instructions, state);
1713 state, & loc);
1716 _mesa_glsl_error(& loc, state,
1726 do_assignment(instructions, state,
1742 op[0] = this->subexpressions[0]->hir(instructions, state);
1743 op[1] = this->subexpressions[1]->hir(instructions, state);
1754 type = modulus_result_type(op[0], op[1], state, &loc);
1757 _mesa_glsl_error(& loc, state,
1770 do_assignment(instructions, state,
1781 op[0] = this->subexpressions[0]->hir(instructions, state);
1782 op[1] = this->subexpressions[1]->hir(instructions, state);
1792 type = shift_result_type(op[0]->type, op[1]->type, this->oper, state,
1797 do_assignment(instructions, state,
1809 op[0] = this->subexpressions[0]->hir(instructions, state);
1810 op[1] = this->subexpressions[1]->hir(instructions, state);
1821 type = bit_logic_result_type(op[0], op[1], this->oper, state, &loc);
1824 _mesa_glsl_error(& loc, state,
1833 do_assignment(instructions, state,
1848 op[0] = get_scalar_boolean_operand(instructions, state, this, 0,
1859 op[1] = this->subexpressions[1]->hir(&then_instructions, state);
1860 op[2] = this->subexpressions[2]->hir(&else_instructions, state);
1871 if ((!apply_implicit_conversion(op[1]->type, op[2], state)
1872 && !apply_implicit_conversion(op[2]->type, op[1], state))
1876 _mesa_glsl_error(& loc, state, "second and third operands of ?: "
1890 !state->check_version(120, 300, &loc,
1903 if (!(state->has_bindless() && (type->is_image() || type->is_sampler()))) {
1904 _mesa_glsl_error(&loc, state, "variables of type %s cannot be "
1954 op[0] = this->subexpressions[0]->hir(instructions, state);
1957 type = arithmetic_result_type(op[0], op[1], false, state, & loc);
1964 do_assignment(instructions, state,
1976 op[0] = this->subexpressions[0]->hir(instructions, state);
1986 type = arithmetic_result_type(op[0], op[1], false, state, & loc);
1999 do_assignment(instructions, state,
2009 result = _mesa_ast_field_selection_to_hir(this, instructions, state);
2020 op[0] = subexpressions[0]->hir(instructions, state);
2021 op[1] = subexpressions[1]->hir(instructions, state);
2023 result = _mesa_ast_array_index_to_hir(ctx, state, op[0], op[1],
2047 state->symbols->get_variable(this->primary_expression.identifier);
2052 sub_name = ralloc_asprintf(ctx, "%s_%s", _mesa_shader_stage_to_subroutine_prefix(state->stage), this->primary_expression.identifier);
2053 var = state->symbols->get_variable(sub_name);
2065 _mesa_glsl_warning(&loc, state, "`%s' used uninitialized",
2076 if (var->data.memory_coherent && !state->EXT_shader_framebuffer_fetch_enable) {
2077 _mesa_glsl_error(&loc, state,
2088 if (state->fs_early_fragment_tests) {
2089 _mesa_glsl_error(&loc, state,
2096 _mesa_glsl_error(& loc, state, "`%s' undeclared",
2165 _mesa_glsl_warning(&previous_operand_loc, state,
2178 result = ast->hir(instructions, state);
2191 _mesa_glsl_error(& loc, state, "type mismatch");
2278 struct _mesa_glsl_parse_state *state)
2290 expression->hir_no_rvalue(instructions, state);
2300 struct _mesa_glsl_parse_state *state)
2303 state->symbols->push_scope();
2306 ast->hir(instructions, state);
2309 state->symbols->pop_scope();
2322 struct _mesa_glsl_parse_state *state)
2324 void *mem_ctx = state;
2337 ir_rvalue *const ir = array_size->hir(& dummy_instructions, state);
2341 _mesa_glsl_error(& loc, state,
2347 _mesa_glsl_error(& loc, state,
2353 _mesa_glsl_error(& loc, state,
2360 (state->is_version(120, 300) &&
2362 _mesa_glsl_error(& loc, state, "array size must be a "
2368 _mesa_glsl_error(& loc, state, "array size must be > 0");
2388 struct _mesa_glsl_parse_state *state)
2399 if (!state->check_arrays_of_arrays_allowed(loc)) {
2406 unsigned array_size = process_array_size(node, state);
2452 struct _mesa_glsl_parse_state *state) const
2461 type = state->symbols->get_type(this->type_name);
2465 type = process_array_type(&loc, type, this->array_specifier, state);
2698 struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
2706 assert(state->es_shader);
2717 state->symbols->get_default_precision_qualifier(type_name);
2719 _mesa_glsl_error(loc, state,
2733 _mesa_glsl_error(loc, state,
2742 struct _mesa_glsl_parse_state *state) const
2744 return this->specifier->glsl_type(name, state);
2772 is_allowed_invariant(ir_variable *var, struct _mesa_glsl_parse_state *state)
2774 if (is_varying_var(var, state->stage))
2781 if (!state->is_version(130, 100))
2788 if (state->stage == MESA_SHADER_FRAGMENT &&
2795 validate_component_layout_for_type(struct _mesa_glsl_parse_state *state,
2803 _mesa_glsl_error(loc, state, "component layout qualifier "
2807 _mesa_glsl_error(loc, state, "component layout qualifier "
2811 _mesa_glsl_error(loc, state, "component overflow (%u > 3)",
2817 _mesa_glsl_error(loc, state, "doubles cannot begin at component 1 or 3");
2825 validate_matrix_layout_for_type(struct _mesa_glsl_parse_state *state,
2834 _mesa_glsl_error(loc, state,
2845 _mesa_glsl_warning(loc, state,
2854 struct _mesa_glsl_parse_state *state,
2856 if (xfb_buffer >= state->Const.MaxTransformFeedbackBuffers) {
2857 _mesa_glsl_error(loc, state,
2861 state->Const.MaxTransformFeedbackBuffers - 1);
2880 struct _mesa_glsl_parse_state *state,
2886 _mesa_glsl_error(loc, state,
2905 validate_xfb_offset_qualifier(loc, state, xfb_offset, member_t,
2917 _mesa_glsl_error(loc, state,
2930 validate_stream_qualifier(YYLTYPE *loc, struct _mesa_glsl_parse_state *state,
2933 if (stream >= state->consts->MaxVertexStreams) {
2934 _mesa_glsl_error(loc, state,
2937 stream, state->consts->MaxVertexStreams - 1);
2945 apply_explicit_binding(struct _mesa_glsl_parse_state *state,
2952 _mesa_glsl_error(loc, state,
2959 if (!process_qualifier_constant(state, loc, "binding", qual->binding,
2964 const struct gl_constants *consts = state->consts;
2982 _mesa_glsl_error(loc, state, "layout(binding = %u) for %d UBOs exceeds "
3000 _mesa_glsl_error(loc, state, "layout(binding = %u) for %d SSBOs exceeds "
3017 _mesa_glsl_error(loc, state, "layout(binding = %d) for %d samplers "
3026 _mesa_glsl_error(loc, state, "layout(binding = %d) exceeds the "
3033 } else if ((state->is_version(420, 310) ||
3034 state->ARB_shading_language_420pack_enable) &&
3038 _mesa_glsl_error(loc, state, "Image binding %d exceeds the "
3045 _mesa_glsl_error(loc, state,
3059 validate_fragment_flat_interpolation_input(struct _mesa_glsl_parse_state *state,
3065 if (state->stage != MESA_SHADER_FRAGMENT ||
3099 if ((state->is_version(130, 300) || state->EXT_gpu_shader4_enable)
3101 _mesa_glsl_error(loc, state, "if a fragment input is (or contains) "
3122 if (state->has_double()
3124 _mesa_glsl_error(loc, state, "if a fragment input is (or contains) "
3141 if (state->has_bindless()
3143 _mesa_glsl_error(loc, state, "if a fragment input is (or contains) "
3150 validate_interpolation_qualifier(struct _mesa_glsl_parse_state *state,
3180 if ((state->is_version(130, 300) || state->EXT_gpu_shader4_enable)
3184 _mesa_glsl_error(loc, state,
3188 switch (state->stage) {
3191 _mesa_glsl_error(loc, state,
3198 _mesa_glsl_error(loc, state,
3220 if (state->is_version(130, 0) && !state->EXT_gpu_shader4_enable
3231 _mesa_glsl_error(loc, state,
3236 validate_fragment_flat_interpolation_input(state, loc, interpolation,
3244 struct _mesa_glsl_parse_state *state,
3257 validate_interpolation_qualifier(state, loc,
3268 struct _mesa_glsl_parse_state *state,
3274 if (!process_qualifier_constant(state, loc, "location", qual->location,
3281 if (!state->check_explicit_uniform_location_allowed(loc, var))
3284 const struct gl_constants *consts = state->consts;
3288 _mesa_glsl_error(loc, state, "location(s) consumed by uniform %s "
3312 switch (state->stage) {
3315 if (!state->check_explicit_attrib_location_allowed(loc, var))
3322 if (!state->check_separate_shader_objects_allowed(loc, var))
3335 if (!state->check_separate_shader_objects_allowed(loc, var))
3346 if (!state->check_separate_shader_objects_allowed(loc, var))
3353 if (!state->check_explicit_attrib_location_allowed(loc, var))
3363 _mesa_glsl_error(loc, state,
3373 _mesa_glsl_error(loc, state,
3376 _mesa_shader_stage_to_string(state->stage));
3380 switch (state->stage) {
3408 _mesa_glsl_error(loc, state, "an index qualifier can only be "
3415 process_qualifier_constant(state, loc, "index", qual->index,
3427 _mesa_glsl_error(loc, state,
3439 struct _mesa_glsl_parse_state *state,
3457 if (state->has_bindless()) {
3465 _mesa_glsl_error(loc, state, "bindless image/sampler variables may "
3474 _mesa_glsl_error(loc, state, "image/sampler variables may only be "
3484 validate_memory_qualifier_for_type(struct _mesa_glsl_parse_state *state,
3501 _mesa_glsl_error(loc, state, "memory qualifiers may only be applied "
3511 validate_image_format_qualifier_for_type(struct _mesa_glsl_parse_state *state,
3522 _mesa_glsl_error(loc, state, "format layout qualifiers may only be "
3532 struct _mesa_glsl_parse_state *state,
3537 if (!validate_image_format_qualifier_for_type(state, loc, qual, base_type) ||
3538 !validate_memory_qualifier_for_type(state, loc, qual, base_type))
3544 if (!validate_storage_for_sampler_image_types(var, state, loc))
3555 _mesa_glsl_error(loc, state, "format qualifiers cannot be used on "
3560 _mesa_glsl_error(loc, state, "format qualifier doesn't match the base "
3565 } else if (state->has_image_load_formatted()) {
3567 state->EXT_shader_image_load_formatted_warn) {
3568 _mesa_glsl_warning(loc, state, "GL_EXT_image_load_formatted used");
3572 if (state->es_shader ||
3573 !(state->is_version(420, 310) || state->ARB_shader_image_load_store_enable)) {
3574 _mesa_glsl_error(loc, state, "all image uniforms must have a "
3577 _mesa_glsl_error(loc, state, "image uniforms not qualified with "
3590 if (state->es_shader &&
3596 _mesa_glsl_error(loc, state, "image variables of format other than r32f, "
3616 is_conflicting_fragcoord_redeclaration(struct _mesa_glsl_parse_state *state,
3622 if (state->fs_redeclares_gl_fragcoord) {
3623 return (state->fs_pixel_center_integer != qual->flags.q.pixel_center_integer
3624 || state->fs_origin_upper_left != qual->flags.q.origin_upper_left);
3631 is_conflicting_layer_redeclaration(struct _mesa_glsl_parse_state *state,
3634 if (state->redeclares_gl_layer) {
3635 return state->layer_viewport_relative != qual->flags.q.viewport_relative;
3642 struct _mesa_glsl_parse_state *state,
3648 _mesa_glsl_error(loc, state,
3662 struct _mesa_glsl_parse_state *state,
3680 _mesa_glsl_error(loc, state, "ARB_bindless_texture layout qualifiers "
3686 /* The ARB_bindless_texture spec doesn't state anything in this situation,
3693 _mesa_glsl_error(loc, state, "bindless_sampler or bound_sampler can only "
3700 _mesa_glsl_error(loc, state, "bindless_image or bound_image can only be "
3712 state->bindless_sampler_specified ||
3713 state->bindless_image_specified;
3717 state->bound_sampler_specified ||
3718 state->bound_image_specified;
3725 struct _mesa_glsl_parse_state *state,
3738 ir_variable *earlier = state->symbols->get_variable("gl_FragCoord");
3741 !state->fs_redeclares_gl_fragcoord) {
3742 _mesa_glsl_error(loc, state,
3750 if (is_conflicting_fragcoord_redeclaration(state, qual)) {
3756 get_layout_qualifier_string(state->fs_origin_upper_left,
3757 state->fs_pixel_center_integer);
3759 _mesa_glsl_error(loc, state,
3765 state->fs_origin_upper_left = qual->flags.q.origin_upper_left;
3766 state->fs_pixel_center_integer = qual->flags.q.pixel_center_integer;
3767 state->fs_redeclares_gl_fragcoord_with_no_layout_qualifiers =
3769 state->fs_redeclares_gl_fragcoord =
3770 state->fs_origin_upper_left ||
3771 state->fs_pixel_center_integer ||
3772 state->fs_redeclares_gl_fragcoord_with_no_layout_qualifiers;
3780 _mesa_glsl_error(loc, state,
3787 apply_explicit_location(qual, var, state, loc);
3791 if (process_qualifier_constant(state, loc, "component",
3793 validate_component_layout_for_type(state, loc, var->type,
3801 _mesa_glsl_error(loc, state,
3804 _mesa_glsl_error(loc, state,
3809 apply_explicit_binding(state, loc, var, var->type, qual);
3812 if (state->stage == MESA_SHADER_GEOMETRY &&
3815 if (process_qualifier_constant(state, loc, "stream", qual->stream,
3817 validate_stream_qualifier(loc, state, qual_stream)) {
3824 if (process_qualifier_constant(state, loc, "xfb_buffer",
3826 validate_xfb_buffer_qualifier(loc, state, qual_xfb_buffer)) {
3837 if (process_qualifier_constant(state, loc, "xfb_offset",
3839 validate_xfb_offset_qualifier(loc, state, (int) qual_xfb_offset,
3848 if (process_qualifier_constant(state, loc, "xfb_stride",
3859 &state->atomic_counter_offsets[var->data.binding];
3862 _mesa_glsl_error(loc, state,
3869 _mesa_glsl_error(loc, state,
3873 _mesa_glsl_error(loc, state, "atomic counters may only be declared as "
3880 !validate_storage_for_sampler_image_types(var, state, loc))
3904 state->ARB_fragment_coord_conventions_enable;
3910 _mesa_glsl_warning(loc, state,
3914 _mesa_glsl_error(loc, state,
3924 && !state->is_version(420, 0)
3925 && !state->AMD_conservative_depth_enable
3926 && !state->ARB_conservative_depth_enable) {
3927 _mesa_glsl_error(loc, state,
3933 _mesa_glsl_error(loc, state,
3960 _mesa_glsl_error(loc, state,
3968 validate_matrix_layout_for_type(state, loc, var->type, var);
3981 _mesa_glsl_error(loc, state, "early_fragment_tests layout qualifier only "
3986 _mesa_glsl_error(loc, state, "inner_coverage layout qualifier only "
3991 _mesa_glsl_error(loc, state, "post_depth_coverage layout qualifier only "
3995 if (state->has_bindless())
3996 apply_bindless_qualifier_to_variable(qual, var, state, loc);
4002 _mesa_glsl_error(loc, state, "interlock layout qualifiers: "
4009 if (is_conflicting_layer_redeclaration(state, qual)) {
4010 _mesa_glsl_error(loc, state, "gl_Layer redeclaration with "
4013 state->redeclares_gl_layer = true;
4015 state->layer_viewport_relative = true;
4018 _mesa_glsl_error(loc, state,
4027 struct _mesa_glsl_parse_state *state,
4035 _mesa_glsl_error(loc, state,
4047 _mesa_glsl_error(loc, state,
4057 _mesa_glsl_error(loc, state,
4064 || (qual->flags.q.varying && (state->stage == MESA_SHADER_FRAGMENT)))
4074 if (state->es_shader) {
4076 select_gles_precision(qual->precision, var->type, state, loc);
4082 if (qual->flags.q.attribute && state->stage != MESA_SHADER_VERTEX) {
4084 _mesa_glsl_error(loc, state,
4087 _mesa_shader_stage_to_string(state->stage));
4092 _mesa_glsl_error(loc, state,
4107 _mesa_glsl_error(loc, state,
4121 || (qual->flags.q.varying && (state->stage == MESA_SHADER_FRAGMENT)))
4125 else if (qual->flags.q.varying && (state->stage == MESA_SHADER_VERTEX))
4134 if (!is_parameter && state->stage == MESA_SHADER_FRAGMENT) {
4135 if (state->has_framebuffer_fetch()) {
4136 if (state->is_version(130, 300))
4142 if (state->has_framebuffer_fetch_zs() &&
4162 !state->EXT_shader_framebuffer_fetch_enable)
4163 _mesa_glsl_error(loc, state,
4174 _mesa_glsl_error(loc, state,
4179 if (!is_parameter && is_varying_var(var, state->stage)) {
4181 if (state->stage == MESA_SHADER_COMPUTE) {
4182 _mesa_glsl_error(loc, state,
4231 if (state->is_version(130, 300) || state->EXT_gpu_shader4_enable)
4233 _mesa_glsl_error(loc, state,
4235 state->get_version_string());
4238 if (state->is_version(150, 300))
4240 _mesa_glsl_error(loc, state,
4250 if (state->has_bindless())
4254 _mesa_glsl_error(loc, state, "illegal type for a varying variable");
4259 if (state->all_invariant && var->data.mode == ir_var_shader_out) {
4267 state, loc);
4293 if (qual->flags.q.sample && (!is_varying_var(var, state->stage) || uses_deprecated_qualifier)) {
4294 _mesa_glsl_error(loc, state,
4298 if (qual->flags.q.centroid && !is_varying_var(var, state->stage)) {
4299 _mesa_glsl_error(loc, state,
4304 if (qual->flags.q.shared_storage && state->stage != MESA_SHADER_COMPUTE) {
4305 _mesa_glsl_error(loc, state,
4310 apply_image_qualifier_to_variable(qual, var, state, loc);
4329 struct _mesa_glsl_parse_state *state,
4341 ir_variable *earlier = state->symbols->get_variable(var->name);
4343 (state->current_function != NULL &&
4344 !state->symbols->name_declared_this_scope(var->name))) {
4368 _mesa_glsl_error(&loc, state,
4383 check_builtin_array_max_size(var->name, size, loc, state);
4385 _mesa_glsl_error(& loc, state, "array size must be > %u due to "
4395 _mesa_glsl_error(&loc, state,
4398 } else if ((state->ARB_fragment_coord_conventions_enable ||
4399 state->is_version(150, 0))
4420 } else if (state->is_version(130, 0)
4430 } else if ((state->is_version(420, 0) ||
4431 state->AMD_conservative_depth_enable ||
4432 state->ARB_conservative_depth_enable)
4440 _mesa_glsl_error(&loc, state,
4448 _mesa_glsl_error(&loc, state,
4458 } else if (state->has_framebuffer_fetch() &&
4473 } else if (state->NV_viewport_array2_enable &&
4476 /* No need to do anything, just allow it. Qualifier is stored in state */
4478 } else if (state->is_version(0, 300) &&
4479 state->has_separate_shader_objects() &&
4496 _mesa_glsl_error(&loc, state, "the first redeclaration of "
4500 state->allow_builtin_variable_redeclaration) ||
4506 _mesa_glsl_error(&loc, state, "`%s' redeclared", var->name);
4519 struct _mesa_glsl_parse_state *state)
4521 void *mem_ctx = state;
4533 state->check_version(120, 0, &initializer_loc,
4543 _mesa_glsl_error(&initializer_loc, state,
4565 (!state->has_bindless() && var->type->contains_opaque())) {
4566 _mesa_glsl_error(&initializer_loc, state,
4568 var->name, state->has_bindless() ? "atomic" : "opaque");
4571 if ((var->data.mode == ir_var_shader_in) && (state->current_function == NULL)) {
4572 _mesa_glsl_error(&initializer_loc, state,
4574 _mesa_shader_stage_to_string(state->stage),
4575 (state->stage == MESA_SHADER_VERTEX)
4580 if (var->data.mode == ir_var_shader_out && state->current_function == NULL) {
4581 _mesa_glsl_error(&initializer_loc, state,
4583 _mesa_shader_stage_to_string(state->stage),
4594 ir_dereference *const lhs = new(state) ir_dereference_variable(var);
4595 ir_rvalue *rhs = decl->initializer->hir(initializer_instructions, state);
4611 || (state->es_shader && state->current_function == NULL)) {
4612 ir_rvalue *new_rhs = validate_assignment(state, initializer_loc,
4660 (state->is_version(430, 300) &&
4672 if (!state->has_420pack()
4673 || state->current_function == NULL) {
4674 _mesa_glsl_error(& initializer_loc, state,
4682 ? ir_constant::zero(state, var->type) : NULL;
4694 ? ir_constant::zero(state, var->type) : NULL;
4710 do_assignment(initializer_instructions, state,
4753 validate_layout_qualifier_vertex_count(struct _mesa_glsl_parse_state *state,
4795 _mesa_glsl_error(&loc, state,
4800 _mesa_glsl_error(&loc, state,
4811 handle_tess_ctrl_shader_output_decl(struct _mesa_glsl_parse_state *state,
4816 if (state->tcs_output_vertices_specified) {
4817 if (!state->out_qualifier->vertices->
4818 process_qualifier_constant(state, "vertices",
4823 if (num_vertices > state->Const.MaxPatchVertices) {
4824 _mesa_glsl_error(&loc, state, "vertices (%d) exceeds "
4831 _mesa_glsl_error(&loc, state,
4841 validate_layout_qualifier_vertex_count(state, loc, var, num_vertices,
4842 &state->tcs_output_size,
4852 handle_tess_shader_input_decl(struct _mesa_glsl_parse_state *state,
4856 _mesa_glsl_error(&loc, state,
4876 state->Const.MaxPatchVertices);
4877 } else if (var->type->length != state->Const.MaxPatchVertices) {
4878 _mesa_glsl_error(&loc, state,
4881 state->Const.MaxPatchVertices);
4891 handle_geometry_shader_input_decl(struct _mesa_glsl_parse_state *state,
4896 if (state->gs_input_prim_type_specified) {
4897 num_vertices = vertices_per_prim(state->in_qualifier->prim_type);
4904 assert(state->error);
4910 validate_layout_qualifier_vertex_count(state, loc, var, num_vertices,
4911 &state->gs_input_size,
4917 struct _mesa_glsl_parse_state *state)
4926 _mesa_glsl_error(&loc, state,
4944 _mesa_glsl_warning(&loc, state,
4952 struct _mesa_glsl_parse_state *state)
4954 void *ctx = state;
4974 if (state->current_function != NULL) {
4975 _mesa_glsl_error(& loc, state,
4985 state->symbols->get_variable(decl->identifier);
4987 _mesa_glsl_error(& loc, state,
4990 } else if (!is_allowed_invariant(earlier, state)) {
4991 _mesa_glsl_error(&loc, state,
4995 _mesa_glsl_error(& loc, state,
5018 state->symbols->get_variable(decl->identifier);
5020 _mesa_glsl_error(& loc, state,
5023 } else if (state->current_function != NULL &&
5024 !state->symbols->name_declared_this_scope(decl->identifier)) {
5028 _mesa_glsl_error(& loc, state,
5033 _mesa_glsl_error(& loc, state,
5077 _mesa_glsl_error(& loc, state,
5128 (void) this->type->specifier->hir(instructions, state);
5130 decl_type = this->type->glsl_type(& type_name, state);
5139 _mesa_glsl_error(&loc, state,
5153 if (process_qualifier_constant(state, &loc, "binding",
5156 && process_qualifier_constant(state, &loc, "offset",
5159 if (qual_binding < ARRAY_SIZE(state->atomic_counter_offsets))
5160 state->atomic_counter_offsets[qual_binding] = qual_offset;
5170 type->qualifier.validate_flags(&loc, state, allowed_atomic_qual_mask,
5198 || state->error);
5201 _mesa_glsl_error(&loc, state,
5213 if (state->es_shader && decl_type->is_unsized_array()) {
5214 _mesa_glsl_error(&loc, state, "array size must be explicitly "
5224 validate_array_dimensions(decl_type, state, &loc);
5234 _mesa_glsl_error(&loc, state,
5245 _mesa_glsl_warning(&loc, state,
5254 _mesa_glsl_warning(&loc, state, "empty declaration");
5269 _mesa_glsl_error(& loc, state,
5273 _mesa_glsl_error(& loc, state,
5284 t = state->symbols->get_type(this->type->specifier->type_name);
5286 _mesa_glsl_error(& loc, state,
5289 name = ralloc_asprintf(ctx, "%s_%s", _mesa_shader_stage_to_subroutine_prefix(state->stage), decl->identifier);
5295 state);
5305 _mesa_glsl_error(& loc, state,
5311 _mesa_glsl_error(& loc, state,
5330 if (!state->is_version(130, 300)
5331 && !state->has_explicit_attrib_location()
5332 && !state->has_separate_shader_objects()
5333 && !state->ARB_fragment_coord_conventions_enable) {
5338 (!state->EXT_gpu_shader4_enable ||
5339 state->stage != MESA_SHADER_FRAGMENT)) {
5340 _mesa_glsl_error(& loc, state,
5343 decl->identifier, state->get_version_string());
5346 _mesa_glsl_error(& loc, state,
5349 decl->identifier, state->get_version_string());
5354 apply_type_qualifier_to_variable(& this->type->qualifier, var, state,
5356 apply_layout_qualifier_to_variable(&this->type->qualifier, var, state,
5359 if ((state->zero_init & (1u << var->data.mode)) &&
5368 if (!is_allowed_invariant(var, state)) {
5369 _mesa_glsl_error(&loc, state,
5375 if (state->current_function != NULL) {
5399 _mesa_glsl_error(& loc, state,
5407 if (state->stage == MESA_SHADER_VERTEX) {
5453 error = !state->is_version(120, 300) && !state->EXT_gpu_shader4_enable;
5456 error = !state->is_version(410, 0) && !state->ARB_vertex_attrib_64bit_enable;
5461 error = !state->has_bindless();
5468 _mesa_glsl_error(& loc, state,
5474 !state->check_version(150, 0, &loc,
5478 } else if (state->stage == MESA_SHADER_GEOMETRY) {
5488 _mesa_glsl_error(&loc, state,
5492 handle_geometry_shader_input_decl(state, loc, var);
5493 } else if (state->stage == MESA_SHADER_FRAGMENT) {
5506 if (state->es_shader) {
5510 _mesa_glsl_error(&loc, state,
5516 _mesa_glsl_error(&loc, state,
5519 _mesa_shader_stage_to_string(state->stage));
5523 _mesa_glsl_error(&loc, state,
5531 _mesa_glsl_error(&loc, state,
5538 } else if (state->stage == MESA_SHADER_TESS_CTRL ||
5539 state->stage == MESA_SHADER_TESS_EVAL) {
5540 handle_tess_shader_input_decl(state, loc, var);
5556 if (state->stage == MESA_SHADER_FRAGMENT) {
5558 _mesa_glsl_error(&loc, state,
5567 _mesa_glsl_error(&loc, state,
5612 if (state->es_shader) {
5615 _mesa_glsl_error(&loc, state,
5618 _mesa_shader_stage_to_string(state->stage));
5620 if (state->stage <= MESA_SHADER_GEOMETRY) {
5623 if (state->stage == MESA_SHADER_TESS_CTRL &&
5629 _mesa_glsl_error(&loc, state,
5632 _mesa_shader_stage_to_string(state->stage));
5638 _mesa_glsl_error(&loc, state,
5642 _mesa_shader_stage_to_string(state->stage));
5648 if (state->stage == MESA_SHADER_TESS_CTRL) {
5649 handle_tess_ctrl_shader_output_decl(state, loc, var);
5667 if (state->stage != MESA_SHADER_TESS_EVAL
5671 _mesa_glsl_error(&loc, state, "'patch in' can only be used in a "
5675 if (state->stage != MESA_SHADER_TESS_CTRL
5679 _mesa_glsl_error(&loc, state, "'patch out' can only be used in a "
5686 state->check_precision_qualifiers_allowed(&loc);
5691 _mesa_glsl_error(&loc, state,
5713 (!state->has_bindless() && var_type->contains_opaque()))) {
5714 _mesa_glsl_error(&loc, state,
5716 state->has_bindless() ? "atomic" : "opaque");
5731 var = get_variable_being_redeclared(&var, decl->get_location(), state,
5737 _mesa_glsl_error(&loc, state,
5747 &initializer_instructions, state);
5749 validate_array_dimensions(var_type, state, &loc);
5759 _mesa_glsl_error(& loc, state,
5764 if (state->es_shader) {
5788 state->stage >= MESA_SHADER_TESS_CTRL &&
5789 state->stage <= MESA_SHADER_GEOMETRY) ||
5791 state->stage == MESA_SHADER_TESS_CTRL);
5811 _mesa_glsl_error(& loc, state,
5823 _mesa_glsl_error(& loc, state,
5832 validate_identifier(decl->identifier, loc, state);
5846 if (!state->symbols->add_variable(var)) {
5848 _mesa_glsl_error(&loc, state, "name `%s' already taken in the "
5881 struct _mesa_glsl_parse_state *state)
5883 void *ctx = state;
5888 type = this->type->glsl_type(& name, state);
5892 _mesa_glsl_error(& loc, state,
5896 _mesa_glsl_error(& loc, state,
5918 _mesa_glsl_error(& loc, state,
5926 _mesa_glsl_error(& loc, state, "formal parameter lacks a name");
5933 type = process_array_type(&loc, type, this->array_specifier, state);
5936 _mesa_glsl_error(&loc, state, "arrays passed as parameters must have "
5948 apply_type_qualifier_to_variable(& this->type->qualifier, var, state, & loc,
5951 if (((1u << var->data.mode) & state->zero_init) &&
5977 (!state->has_bindless() && type->contains_opaque()))) {
5978 _mesa_glsl_error(&loc, state, "out and inout parameters cannot "
5980 state->has_bindless() ? "atomic" : "opaque");
6000 && !state->check_version(120, 100, &loc,
6017 _mesa_glsl_parse_state *state)
6024 param->hir(ir_parameters, state);
6035 _mesa_glsl_error(& loc, state,
6042 emit_function(_mesa_glsl_parse_state *state, ir_function *f)
6051 state->toplevel_ir->push_tail(f);
6057 struct _mesa_glsl_parse_state *state)
6059 void *ctx = state;
6085 if ((state->current_function != NULL) &&
6086 state->is_version(120, 100)) {
6088 _mesa_glsl_error(&loc, state,
6093 validate_identifier(name, this->get_location(), state);
6101 & hir_parameters, state);
6105 this->return_type->glsl_type(& return_type_name, state);
6109 _mesa_glsl_error(&loc, state,
6121 _mesa_glsl_error(&loc, state,
6129 if (this->return_type->has_qualifiers(state)) {
6131 _mesa_glsl_error(& loc, state,
6142 _mesa_glsl_error(& loc, state,
6153 if (state->language_version == 100 && return_type->contains_array()) {
6155 _mesa_glsl_error(& loc, state,
6164 * The ARB_bindless_texture spec doesn't clearly state this, but as it says
6169 (!state->has_bindless() && return_type->contains_opaque())) {
6171 _mesa_glsl_error(&loc, state,
6173 name, state->has_bindless() ? "atomic" : "opaque");
6179 _mesa_glsl_error(&loc, state,
6187 if (state->es_shader) {
6192 state,
6199 f = state->symbols->get_function(name);
6203 if (!state->symbols->add_function(f)) {
6206 _mesa_glsl_error(&loc, state, "function name `%s' conflicts with "
6211 emit_function(state, f);
6223 if (state->es_shader) {
6225 if (state->language_version >= 300 &&
6226 _mesa_glsl_has_builtin_function(state, name)) {
6228 _mesa_glsl_error(& loc, state,
6234 if (state->language_version == 100) {
6236 _mesa_glsl_find_builtin_function(state, name, &hir_parameters);
6238 _mesa_glsl_error(& loc, state,
6249 if (state->es_shader || f->has_user_signature()) {
6250 sig = f->exact_matching_signature(state, &hir_parameters);
6256 _mesa_glsl_error(&loc, state, "function `%s' parameter `%s' "
6263 _mesa_glsl_error(&loc, state, "function `%s' return type doesn't "
6270 _mesa_glsl_error(&loc, state, "function `%s' return type precision "
6277 _mesa_glsl_error(& loc, state, "function `%s' redefined", name);
6285 } else if (state->language_version == 100 && !is_definition) {
6294 _mesa_glsl_error(&loc, state, "function `%s' redeclared", name);
6304 _mesa_glsl_error(& loc, state, "main() must return void");
6310 _mesa_glsl_error(& loc, state, "main() must not take any parameters");
6330 if (process_qualifier_constant(state, &loc, "index",
6333 if (!state->has_explicit_uniform_location()) {
6334 _mesa_glsl_error(&loc, state, "subroutine index requires "
6338 _mesa_glsl_error(&loc, state,
6350 f->subroutine_types = ralloc_array(state, const struct glsl_type *,
6356 type = state->symbols->get_type(decl->identifier);
6358 _mesa_glsl_error(& loc, state, "unknown type '%s' in subroutine function definition", decl->identifier);
6361 for (int i = 0; i < state->num_subroutine_types; i++) {
6362 ir_function *fn = state->subroutine_types[i];
6368 tsig = fn->matching_signature(state, &sig->parameters,
6371 _mesa_glsl_error(& loc, state, "subroutine type mismatch '%s' - signatures do not match\n", decl->identifier);
6374 _mesa_glsl_error(& loc, state, "subroutine type mismatch '%s' - return types do not match\n", decl->identifier);
6380 state->subroutines = (ir_function **)reralloc(state, state->subroutines,
6382 state->num_subroutines + 1);
6383 state->subroutines[state->num_subroutines] = f;
6384 state->num_subroutines++;
6389 if (!state->symbols->add_type(this->identifier, glsl_type::get_subroutine_instance(this->identifier))) {
6390 _mesa_glsl_error(& loc, state, "type '%s' previously defined", this->identifier);
6393 state->subroutine_types = (ir_function **)reralloc(state, state->subroutine_types,
6395 state->num_subroutine_types + 1);
6396 state->subroutine_types[state->num_subroutine_types] = f;
6397 state->num_subroutine_types++;
6410 struct _mesa_glsl_parse_state *state)
6413 prototype->hir(instructions, state);
6419 assert(state->current_function == NULL);
6420 state->current_function = signature;
6421 state->found_return = false;
6422 state->found_begin_interlock = false;
6423 state->found_end_interlock = false;
6428 state->symbols->push_scope();
6435 if (state->symbols->name_declared_this_scope(var->name)) {
6438 _mesa_glsl_error(& loc, state, "parameter `%s' redeclared", var->name);
6440 state->symbols->add_variable(var);
6445 this->body->hir(&signature->body, state);
6448 state->symbols->pop_scope();
6450 assert(state->current_function == signature);
6451 state->current_function = NULL;
6453 if (!signature->return_type->is_void() && !state->found_return) {
6455 _mesa_glsl_error(& loc, state, "function `%s' has non-void return type "
6469 struct _mesa_glsl_parse_state *state)
6471 void *ctx = state;
6476 assert(state->current_function);
6479 ir_rvalue *ret = opt_return_value->hir(instructions, state);
6494 if (state->current_function->return_type != ret_type) {
6497 if (state->has_420pack()) {
6498 if (!apply_implicit_conversion(state->current_function->return_type,
6499 ret, state)
6500 || (ret->type != state->current_function->return_type)) {
6501 _mesa_glsl_error(& loc, state,
6504 state->current_function->return_type->name,
6505 state->current_function->function_name());
6508 _mesa_glsl_error(& loc, state,
6512 state->current_function->function_name(),
6513 state->current_function->return_type->name);
6515 } else if (state->current_function->return_type->base_type ==
6528 _mesa_glsl_error(& loc, state,
6535 if (state->current_function->return_type->base_type !=
6539 _mesa_glsl_error(& loc, state,
6542 state->current_function->function_name());
6547 state->found_return = true;
6553 if (state->stage != MESA_SHADER_FRAGMENT) {
6556 _mesa_glsl_error(& loc, state,
6565 state->loop_nesting_ast == NULL) {
6568 _mesa_glsl_error(& loc, state, "continue may only appear in a loop");
6570 state->loop_nesting_ast == NULL &&
6571 state->switch_state.switch_nesting_ast == NULL) {
6574 _mesa_glsl_error(& loc, state,
6582 if (state->loop_nesting_ast != NULL &&
6583 mode == ast_continue && !state->switch_state.is_switch_innermost) {
6584 if (state->loop_nesting_ast->rest_expression) {
6586 &state->loop_nesting_ast->rest_instructions);
6588 if (state->loop_nesting_ast->mode ==
6590 state->loop_nesting_ast->condition_to_hir(instructions, state);
6594 if (state->switch_state.is_switch_innermost &&
6599 new(ctx) ir_dereference_variable(state->switch_state.continue_inside);
6609 } else if (state->switch_state.is_switch_innermost &&
6635 struct _mesa_glsl_parse_state *state)
6637 void *ctx = state;
6639 if (state->stage != MESA_SHADER_FRAGMENT) {
6642 _mesa_glsl_error(& loc, state,
6654 struct _mesa_glsl_parse_state *state)
6656 void *ctx = state;
6658 ir_rvalue *const condition = this->condition->hir(instructions, state);
6672 _mesa_glsl_error(& loc, state, "if-statement condition must be scalar "
6679 state->symbols->push_scope();
6680 then_statement->hir(& stmt->then_instructions, state);
6681 state->symbols->pop_scope();
6685 state->symbols->push_scope();
6686 else_statement->hir(& stmt->else_instructions, state);
6687 state->symbols->pop_scope();
6734 struct _mesa_glsl_parse_state *state)
6737 test_val = this->test_expression->hir(instructions, state);
6742 struct _mesa_glsl_parse_state *state)
6744 void *ctx = state;
6746 this->eval_test_expression(instructions, state);
6758 state,
6766 struct glsl_switch_state saved = state->switch_state;
6768 state->switch_state.is_switch_innermost = true;
6769 state->switch_state.switch_nesting_ast = this;
6770 state->switch_state.labels_ht =
6773 state->switch_state.previous_default = NULL;
6775 /* Initalize is_fallthru state to false.
6778 state->switch_state.is_fallthru_var =
6782 instructions->push_tail(state->switch_state.is_fallthru_var);
6785 new(ctx) ir_dereference_variable(state->switch_state.is_fallthru_var);
6789 /* Initialize continue_inside state to false.
6791 state->switch_state.continue_inside =
6795 instructions->push_tail(state->switch_state.continue_inside);
6799 new(ctx) ir_dereference_variable(state->switch_state.continue_inside);
6803 state->switch_state.run_default =
6807 instructions->push_tail(state->switch_state.run_default);
6815 test_to_hir(&loop->body_instructions, state);
6819 body->hir(&loop->body_instructions, state);
6826 if (state->loop_nesting_ast != NULL) {
6828 new(ctx) ir_dereference_variable(state->switch_state.continue_inside);
6832 if (state->loop_nesting_ast != NULL) {
6833 if (state->loop_nesting_ast->rest_expression) {
6835 &state->loop_nesting_ast->rest_instructions);
6837 if (state->loop_nesting_ast->mode ==
6839 state->loop_nesting_ast->condition_to_hir(&irif->then_instructions, state);
6846 _mesa_hash_table_destroy(state->switch_state.labels_ht, NULL);
6848 state->switch_state = saved;
6857 struct _mesa_glsl_parse_state *state)
6859 void *ctx = state;
6867 this->eval_test_expression(instructions, state);
6869 state->switch_state.test_var = new(ctx) ir_variable(test_val->type,
6873 new(ctx) ir_dereference_variable(state->switch_state.test_var);
6875 instructions->push_tail(state->switch_state.test_var);
6882 struct _mesa_glsl_parse_state *state)
6885 state->symbols->push_scope();
6886 stmts->hir(instructions, state);
6887 state->symbols->pop_scope();
6896 struct _mesa_glsl_parse_state *state)
6901 case_stmt->hir(&tmp, state);
6904 if (state->switch_state.previous_default && default_case.is_empty()) {
6921 ir_factory body(instructions, state);
6925 hash_table_foreach(state->switch_state.labels_ht, entry) {
6934 state->switch_state.test_var->type->base_type == GLSL_TYPE_UINT
6939 ? equal(cnst, state->switch_state.test_var)
6940 : logic_or(cmp, equal(cnst, state->switch_state.test_var));
6945 body.emit(assign(state->switch_state.run_default, logic_not(cmp)));
6947 body.emit(assign(state->switch_state.run_default, body.constant(true)));
6960 struct _mesa_glsl_parse_state *state)
6962 labels->hir(instructions, state);
6964 /* Guard case statements depending on fallthru state. */
6966 new(state) ir_dereference_variable(state->switch_state.is_fallthru_var);
6967 ir_if *const test_fallthru = new(state) ir_if(deref_fallthru_guard);
6970 stmt->hir(& test_fallthru->then_instructions, state);
6981 struct _mesa_glsl_parse_state *state)
6984 label->hir(instructions, state);
6992 struct _mesa_glsl_parse_state *state)
6994 ir_factory body(instructions, state);
6996 ir_variable *const fallthru_var = state->switch_state.is_fallthru_var;
7000 /* Conditionally set fallthru state based on
7003 ir_rvalue *const label_rval = this->test_value->hir(instructions, state);
7010 _mesa_glsl_error(& loc, state,
7018 _mesa_hash_table_search(state->switch_state.labels_ht,
7027 _mesa_glsl_error(& loc, state, "duplicate case value");
7030 _mesa_glsl_error(& loc, state, "this is the previous case label");
7032 struct case_label *l = ralloc(state->switch_state.labels_ht,
7036 l->after_default = state->switch_state.previous_default != NULL;
7039 _mesa_hash_table_insert(state->switch_state.labels_ht,
7052 new(body.mem_ctx) ir_dereference_variable(state->switch_state.test_var);
7065 if (label->type != state->switch_state.test_var->type) {
7069 const glsl_type *type_b = state->switch_state.test_var->type;
7074 state);
7078 _mesa_glsl_error(&loc, state, "type mismatch with switch "
7085 label, state))
7086 _mesa_glsl_error(&loc, state, "implicit type conversion error");
7090 deref_test_var, state))
7091 _mesa_glsl_error(&loc, state, "implicit type conversion error");
7106 if (state->switch_state.previous_default) {
7108 _mesa_glsl_error(& loc, state,
7111 loc = state->switch_state.previous_default->get_location();
7112 _mesa_glsl_error(& loc, state, "this is the first default label");
7114 state->switch_state.previous_default = this;
7119 state->switch_state.run_default)));
7128 struct _mesa_glsl_parse_state *state)
7130 void *ctx = state;
7134 condition->hir(instructions, state);
7140 _mesa_glsl_error(& loc, state,
7163 struct _mesa_glsl_parse_state *state)
7165 void *ctx = state;
7170 state->symbols->push_scope();
7173 init_statement->hir(instructions, state);
7179 ast_iteration_statement *nesting_ast = state->loop_nesting_ast;
7181 state->loop_nesting_ast = this;
7186 bool saved_is_switch_innermost = state->switch_state.is_switch_innermost;
7187 state->switch_state.is_switch_innermost = false;
7190 condition_to_hir(&stmt->body_instructions, state);
7193 rest_expression->hir(&rest_instructions, state);
7197 state->symbols->push_scope();
7199 body->hir(& stmt->body_instructions, state);
7202 state->symbols->pop_scope();
7209 condition_to_hir(&stmt->body_instructions, state);
7212 state->symbols->pop_scope();
7215 state->loop_nesting_ast = nesting_ast;
7216 state->switch_state.is_switch_innermost = saved_is_switch_innermost;
7268 struct _mesa_glsl_parse_state *state)
7286 if (!state->check_precision_qualifiers_allowed(&loc))
7290 _mesa_glsl_error(&loc, state,
7296 _mesa_glsl_error(&loc, state,
7303 state->symbols->get_type(this->type_name);
7305 _mesa_glsl_error(&loc, state,
7311 if (state->es_shader) {
7327 * variables. So, we can track the state of the default precision
7332 state->symbols->add_default_precision_qualifier(this->type_name,
7353 return this->structure->hir(instructions, state);
7378 struct _mesa_glsl_parse_state *state,
7409 glsl_struct_field *const fields = rzalloc_array(state, glsl_struct_field,
7420 decl_list->type->specifier->hir(instructions, state);
7436 if (state->language_version != 110 &&
7438 _mesa_glsl_error(&loc, state,
7442 decl_list->type->glsl_type(& type_name, state);
7468 (!state->has_bindless() && decl_type->contains_opaque())) {
7469 _mesa_glsl_error(&loc, state, "uniform/buffer in non-default "
7471 state->has_bindless() ? "atomic" : "opaque");
7480 _mesa_glsl_error(&loc, state, "atomic counter in structure");
7483 if (!state->has_bindless() && decl_type->contains_image()) {
7488 _mesa_glsl_error(&loc, state, "image in structure");
7493 _mesa_glsl_error(&loc, state,
7505 _mesa_glsl_error(&loc, state,
7523 _mesa_glsl_error(&loc, state,
7531 _mesa_glsl_error(&loc, state,
7536 validate_memory_qualifier_for_type(state, &loc, qual, decl_type);
7537 validate_image_format_qualifier_for_type(state, &loc, qual, decl_type);
7547 if (process_qualifier_constant(state, &loc, "stream",
7550 _mesa_glsl_error(&loc, state, "stream layout qualifier on "
7561 if (process_qualifier_constant(state, &loc, "xfb_buffer",
7565 _mesa_glsl_error(&loc, state, "xfb_buffer layout qualifier on "
7580 if (process_qualifier_constant(state, &loc, "xfb_stride",
7587 _mesa_glsl_error(&loc, state,
7594 _mesa_glsl_error(&loc, state,
7601 _mesa_glsl_error(&loc, state,
7605 validate_matrix_layout_for_type(state, &loc, decl_type, NULL);
7613 validate_identifier(decl->identifier, loc, state);
7616 process_array_type(&loc, decl_type, decl->array_specifier, state);
7617 validate_array_dimensions(field_type, state, &loc);
7622 var_mode, state, &loc);
7633 if (process_qualifier_constant(state, &loc, "location",
7651 if (process_qualifier_constant(state, &loc, "component",
7653 validate_component_layout_for_type(state, &loc, fields[i].type,
7686 if (process_qualifier_constant(state, &loc, "offset",
7690 _mesa_glsl_error(&loc, state, "layout qualifier "
7694 _mesa_glsl_error(&loc, state, "layout qualifier offset "
7701 _mesa_glsl_error(&loc, state, "offset can only be used "
7711 _mesa_glsl_error(&loc, state, "align can only be used with "
7715 if (process_qualifier_constant(state, &loc, "align",
7719 _mesa_glsl_error(&loc, state, "align layout qualifier "
7746 if (process_qualifier_constant(state, &loc, "xfb_offset",
7818 _mesa_glsl_error(&loc, state, "format qualifier doesn't "
7825 _mesa_glsl_error(&loc, state, "image not qualified with "
7836 if (state->es_shader) {
7839 state,
7858 struct _mesa_glsl_parse_state *state)
7864 if (!process_qualifier_constant(state, &loc, "location",
7875 state,
7889 validate_identifier(this->name, loc, state);
7893 if (!type->is_anonymous() && !state->symbols->add_type(name, type)) {
7894 const glsl_type *match = state->symbols->get_type(name);
7896 if (match != NULL && state->is_version(130, 0) && match->record_compare(type, true, false))
7897 _mesa_glsl_warning(& loc, state, "struct `%s' previously defined", name);
7899 _mesa_glsl_error(& loc, state, "struct `%s' previously defined", name);
7901 const glsl_type **s = reralloc(state, state->user_structures,
7903 state->num_user_structures + 1);
7905 s[state->num_user_structures] = type;
7906 state->user_structures = s;
7907 state->num_user_structures++;
7974 struct _mesa_glsl_parse_state *state)
7979 if (state->current_function != NULL) {
7980 _mesa_glsl_error(&loc, state,
8032 if (state->stage == MESA_SHADER_GEOMETRY ||
8033 state->stage == MESA_SHADER_TESS_CTRL ||
8034 state->stage == MESA_SHADER_TESS_EVAL ||
8035 state->stage == MESA_SHADER_VERTEX ) {
8042 if (state->stage == MESA_SHADER_GEOMETRY) {
8046 if (state->stage == MESA_SHADER_TESS_CTRL) {
8051 if (state->stage == MESA_SHADER_TESS_EVAL) {
8057 this->layout.validate_flags(&loc, state, allowed_blk_qualifiers,
8108 _mesa_glsl_error(&loc, state,
8113 if (!process_qualifier_constant(state, &loc, "stream", this->layout.stream,
8115 !validate_stream_qualifier(&loc, state, qual_stream)) {
8125 if (!process_qualifier_constant(state, &loc, "xfb_buffer",
8127 !validate_xfb_buffer_qualifier(&loc, state, qual_xfb_buffer)) {
8134 if (!process_qualifier_constant(state, &loc, "xfb_offset",
8142 if (!process_qualifier_constant(state, &loc, "xfb_stride",
8150 if (!process_qualifier_constant(state, &loc, "location",
8161 if (!process_qualifier_constant(state, &loc, "align",
8166 _mesa_glsl_error(&loc, state, "align layout qualifier is not a "
8175 state,
8190 validate_identifier(this->block_name, loc, state);
8198 ir_variable *var = state->symbols->get_variable(this->block_name);
8200 _mesa_glsl_error(&loc, state, "Block name `%s' is "
8220 state->symbols->get_variable("gl_in")) {
8223 _mesa_glsl_error(&loc, state,
8226 _mesa_shader_stage_to_string(state->stage));
8231 _mesa_glsl_error(&loc, state,
8238 state->symbols->get_variable("gl_Position")) {
8241 state->symbols->get_variable("gl_out")) {
8244 _mesa_glsl_error(&loc, state,
8247 _mesa_shader_stage_to_string(state->stage));
8249 if (state->stage == MESA_SHADER_TESS_CTRL) {
8252 _mesa_glsl_error(&loc, state,
8258 _mesa_glsl_error(&loc, state,
8265 _mesa_glsl_error(&loc, state,
8282 _mesa_glsl_error(&loc, state,
8323 _mesa_glsl_error(&loc, state,
8341 validate_xfb_offset_qualifier(&loc, state, xfb_offset, block_type,
8344 if (!state->symbols->add_interface(block_type->name, block_type, var_mode)) {
8346 _mesa_glsl_error(&loc, state, "interface block `%s' with type `%s' "
8364 if (state->stage == MESA_SHADER_GEOMETRY && this->array_specifier == NULL &&
8366 _mesa_glsl_error(&loc, state, "geometry shader inputs must be arrays");
8367 } else if ((state->stage == MESA_SHADER_TESS_CTRL ||
8368 state->stage == MESA_SHADER_TESS_EVAL) &&
8372 _mesa_glsl_error(&loc, state, "per-vertex tessellation shader inputs must be arrays");
8373 } else if (state->stage == MESA_SHADER_TESS_CTRL &&
8377 _mesa_glsl_error(&loc, state, "tessellation control shader outputs must be arrays");
8401 check_builtin_array_max_size(fields[i].name, size, loc, state);
8405 validate_identifier(this->instance_name, loc, state);
8412 process_array_type(&loc, block_type, this->array_specifier, state);
8438 (state->has_enhanced_layouts() || state->has_shader_io_blocks())) {
8440 switch (state->stage)
8458 _mesa_glsl_error(&loc, state,
8461 _mesa_shader_stage_to_string(state->stage));
8491 bool allow_inputs = state->stage == MESA_SHADER_GEOMETRY ||
8492 state->stage == MESA_SHADER_TESS_CTRL ||
8493 state->stage == MESA_SHADER_TESS_EVAL;
8494 bool allow_outputs = state->stage == MESA_SHADER_TESS_CTRL;
8498 _mesa_glsl_error(&loc, state,
8501 _mesa_shader_stage_to_string(state->stage));
8504 _mesa_glsl_error(&loc, state,
8507 _mesa_shader_stage_to_string(state->stage));
8510 _mesa_glsl_error(&loc, state,
8513 _mesa_shader_stage_to_string(state->stage));
8521 if (state->es_shader && block_array_type->is_array() &&
8523 _mesa_glsl_error(&loc, state,
8528 var = new(state) ir_variable(block_array_type,
8532 var = new(state) ir_variable(block_type,
8545 if (state->stage == MESA_SHADER_GEOMETRY && var_mode == ir_var_shader_in)
8546 handle_geometry_shader_input_decl(state, loc, var);
8547 else if ((state->stage == MESA_SHADER_TESS_CTRL ||
8548 state->stage == MESA_SHADER_TESS_EVAL) && var_mode == ir_var_shader_in)
8549 handle_tess_shader_input_decl(state, loc, var);
8550 else if (state->stage == MESA_SHADER_TESS_CTRL && var_mode == ir_var_shader_out)
8551 handle_tess_ctrl_shader_output_decl(state, loc, var);
8559 state->symbols->get_variable(this->instance_name)) {
8561 _mesa_glsl_error(&loc, state, "`%s' redeclared",
8570 apply_explicit_binding(state, &loc, var, var->type,
8580 state->symbols->add_variable(var);
8591 new(state) ir_variable(fields[i].type,
8592 ralloc_strdup(state, fields[i].name),
8617 if (state->es_shader) {
8620 state, &loc);
8639 get_variable_being_redeclared(&var, loc, state,
8643 _mesa_glsl_error(&loc, state,
8647 _mesa_glsl_error(&loc, state,
8657 if (state->symbols->get_variable(var->name) != NULL)
8658 _mesa_glsl_error(&loc, state, "`%s' redeclared", var->name);
8665 apply_explicit_binding(state, &loc, var,
8685 if (state->es_shader) {
8686 _mesa_glsl_error(&loc, state, "unsized array `%s' "
8694 state->symbols->add_variable(var);
8726 _mesa_glsl_error(&loc, state,
8731 state->symbols->disable_variable(var->name);
8744 struct _mesa_glsl_parse_state *state)
8749 if (!state->out_qualifier->vertices->
8750 process_qualifier_constant(state, "vertices", &num_vertices,
8760 if (state->tcs_output_size != 0 && state->tcs_output_size != num_vertices) {
8761 _mesa_glsl_error(&loc, state,
8765 num_vertices, state->tcs_output_size);
8769 state->tcs_output_vertices_specified = true;
8784 _mesa_glsl_error(&loc, state,
8801 struct _mesa_glsl_parse_state *state)
8806 assert(!state->gs_input_prim_type_specified
8807 || state->in_qualifier->prim_type == this->prim_type);
8814 if (state->gs_input_size != 0 && state->gs_input_size != num_vertices) {
8815 _mesa_glsl_error(&loc, state,
8818 " with size %u", num_vertices, state->gs_input_size);
8822 state->gs_input_prim_type_specified = true;
8838 _mesa_glsl_error(&loc, state,
8856 struct _mesa_glsl_parse_state *state)
8881 process_qualifier_constant(state, local_size_str,
8888 if (qual_local_size[i] > state->consts->MaxComputeWorkGroupSize[i]) {
8889 _mesa_glsl_error(&loc, state,
8892 state->consts->MaxComputeWorkGroupSize[i]);
8897 state->consts->MaxComputeWorkGroupInvocations) {
8898 _mesa_glsl_error(&loc, state,
8901 state->consts->MaxComputeWorkGroupInvocations);
8909 if (state->cs_input_local_size_specified) {
8911 if (state->cs_input_local_size[i] != qual_local_size[i]) {
8912 _mesa_glsl_error(&loc, state,
8927 if (state->cs_input_local_size_variable_specified) {
8928 _mesa_glsl_error(&loc, state,
8934 state->cs_input_local_size_specified = true;
8936 state->cs_input_local_size[i] = qual_local_size[i];
8942 ir_variable *var = new(state->symbols)
8947 state->symbols->add_variable(var);
8963 detect_conflicting_assignments(struct _mesa_glsl_parse_state *state,
8985 if (!var->constant_initializer && state->zero_init) {
8999 if (state->stage == MESA_SHADER_FRAGMENT &&
9023 _mesa_glsl_error(&loc, state, "fragment shader writes to both "
9026 _mesa_glsl_error(&loc, state, "fragment shader writes to both "
9030 _mesa_glsl_error(&loc, state, "fragment shader writes to both "
9034 _mesa_glsl_error(&loc, state, "fragment shader writes to both "
9038 _mesa_glsl_error(&loc, state, "fragment shader writes to both "
9042 _mesa_glsl_error(&loc, state, "fragment shader writes to both "
9048 !state->EXT_blend_func_extended_enable) {
9049 _mesa_glsl_error(&loc, state,
9055 verify_subroutine_associated_funcs(struct _mesa_glsl_parse_state *state)
9067 for (int i = 0; i < state->num_subroutines; i++) {
9069 ir_function *fn = state->subroutines[i];
9074 _mesa_glsl_error(&loc, state,
9078 _mesa_shader_stage_to_string(state->stage),
9089 _mesa_glsl_parse_state *state, ir_variable_mode mode)
9097 if (ir_variable *gl_in = state->symbols->get_variable("gl_in"))
9102 state->symbols->get_variable("gl_Position")) {
9132 state->symbols->disable_variable(var->name);
9140 struct _mesa_glsl_parse_state *state)
9142 state->warnings_enabled = enable;