2010-02-22 13:19:34 -08:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2010-06-22 10:38:52 -07:00
|
|
|
|
|
|
|
#include "ir.h"
|
2010-02-22 13:19:34 -08:00
|
|
|
#include "glsl_parser_extras.h"
|
|
|
|
#include "ast.h"
|
2016-01-18 11:35:29 +02:00
|
|
|
#include "compiler/glsl_types.h"
|
2010-02-22 13:19:34 -08:00
|
|
|
|
2010-08-13 16:46:43 -07:00
|
|
|
ir_rvalue *
|
2010-02-22 13:19:34 -08:00
|
|
|
_mesa_ast_field_selection_to_hir(const ast_expression *expr,
|
2010-03-08 23:44:00 -08:00
|
|
|
exec_list *instructions,
|
2010-02-22 13:19:34 -08:00
|
|
|
struct _mesa_glsl_parse_state *state)
|
|
|
|
{
|
2010-06-25 13:14:37 -07:00
|
|
|
void *ctx = state;
|
2010-03-26 01:20:08 -07:00
|
|
|
ir_rvalue *result = NULL;
|
2010-03-26 00:25:36 -07:00
|
|
|
ir_rvalue *op;
|
2010-02-22 13:19:34 -08:00
|
|
|
|
2010-03-01 13:49:10 -08:00
|
|
|
op = expr->subexpressions[0]->hir(instructions, state);
|
2010-02-22 13:19:34 -08:00
|
|
|
|
|
|
|
/* There are two kinds of field selection. There is the selection of a
|
|
|
|
* specific field from a structure, and there is the selection of a
|
|
|
|
* swizzle / mask from a vector. Which is which is determined entirely
|
|
|
|
* by the base type of the thing to which the field selection operator is
|
|
|
|
* being applied.
|
|
|
|
*/
|
2010-03-26 01:20:08 -07:00
|
|
|
YYLTYPE loc = expr->get_location();
|
2010-03-26 14:27:23 -07:00
|
|
|
if (op->type->is_error()) {
|
2010-03-26 01:20:08 -07:00
|
|
|
/* silently propagate the error */
|
2017-04-21 10:32:39 +02:00
|
|
|
} else if (op->type->is_record() || op->type->is_interface()) {
|
2010-06-23 18:11:51 -07:00
|
|
|
result = new(ctx) ir_dereference_record(op,
|
|
|
|
expr->primary_expression.identifier);
|
2010-04-19 15:41:23 -07:00
|
|
|
|
|
|
|
if (result->type->is_error()) {
|
2013-07-25 19:56:43 -07:00
|
|
|
_mesa_glsl_error(& loc, state, "cannot access field `%s' of "
|
2010-04-19 15:41:23 -07:00
|
|
|
"structure",
|
|
|
|
expr->primary_expression.identifier);
|
|
|
|
}
|
2013-05-20 11:01:37 -07:00
|
|
|
} else if (op->type->is_vector() ||
|
2015-12-07 14:11:01 -08:00
|
|
|
(state->has_420pack() && op->type->is_scalar())) {
|
2013-05-20 09:18:01 -07:00
|
|
|
ir_swizzle *swiz = ir_swizzle::create(op,
|
|
|
|
expr->primary_expression.identifier,
|
|
|
|
op->type->vector_elements);
|
|
|
|
if (swiz != NULL) {
|
|
|
|
result = swiz;
|
|
|
|
} else {
|
|
|
|
/* FINISHME: Logging of error messages should be moved into
|
|
|
|
* FINISHME: ir_swizzle::create. This allows the generation of more
|
|
|
|
* FINISHME: specific error messages.
|
|
|
|
*/
|
2013-07-25 19:56:43 -07:00
|
|
|
_mesa_glsl_error(& loc, state, "invalid swizzle / mask `%s'",
|
2013-05-20 09:18:01 -07:00
|
|
|
expr->primary_expression.identifier);
|
|
|
|
}
|
2010-02-22 13:19:34 -08:00
|
|
|
} else {
|
2013-07-25 19:56:43 -07:00
|
|
|
_mesa_glsl_error(& loc, state, "cannot access field `%s' of "
|
|
|
|
"non-structure / non-vector",
|
2010-02-22 13:19:34 -08:00
|
|
|
expr->primary_expression.identifier);
|
|
|
|
}
|
|
|
|
|
2011-09-22 15:04:56 -07:00
|
|
|
return result ? result : ir_rvalue::error_value(ctx);
|
2010-02-22 13:19:34 -08:00
|
|
|
}
|