Path: blob/21.2-virgl/src/compiler/glsl/hir_field_selection.cpp
4545 views
/*1* Copyright © 2010 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20* DEALINGS IN THE SOFTWARE.21*/2223#include "ir.h"24#include "glsl_parser_extras.h"25#include "ast.h"26#include "compiler/glsl_types.h"2728ir_rvalue *29_mesa_ast_field_selection_to_hir(const ast_expression *expr,30exec_list *instructions,31struct _mesa_glsl_parse_state *state)32{33void *ctx = state;34ir_rvalue *result = NULL;35ir_rvalue *op;3637op = expr->subexpressions[0]->hir(instructions, state);3839/* There are two kinds of field selection. There is the selection of a40* specific field from a structure, and there is the selection of a41* swizzle / mask from a vector. Which is which is determined entirely42* by the base type of the thing to which the field selection operator is43* being applied.44*/45YYLTYPE loc = expr->get_location();46if (op->type->is_error()) {47/* silently propagate the error */48} else if (op->type->is_struct() || op->type->is_interface()) {49result = new(ctx) ir_dereference_record(op,50expr->primary_expression.identifier);5152if (result->type->is_error()) {53_mesa_glsl_error(& loc, state, "cannot access field `%s' of "54"structure",55expr->primary_expression.identifier);56}57} else if (op->type->is_vector() ||58(state->has_420pack() && op->type->is_scalar())) {59ir_swizzle *swiz = ir_swizzle::create(op,60expr->primary_expression.identifier,61op->type->vector_elements);62if (swiz != NULL) {63result = swiz;64} else {65/* FINISHME: Logging of error messages should be moved into66* FINISHME: ir_swizzle::create. This allows the generation of more67* FINISHME: specific error messages.68*/69_mesa_glsl_error(& loc, state, "invalid swizzle / mask `%s'",70expr->primary_expression.identifier);71}72} else {73_mesa_glsl_error(& loc, state, "cannot access field `%s' of "74"non-structure / non-vector",75expr->primary_expression.identifier);76}7778return result ? result : ir_rvalue::error_value(ctx);79}808182