2010-06-23 11:37:12 -07: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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
2010-11-10 16:33:10 -08:00
|
|
|
#include "main/compiler.h"
|
2010-06-23 11:37:12 -07:00
|
|
|
#include "ir.h"
|
|
|
|
|
#include "glsl_types.h"
|
2010-07-29 12:40:49 +03:00
|
|
|
#include "program/hash_table.h"
|
2010-06-23 11:37:12 -07:00
|
|
|
|
2011-09-22 15:04:56 -07:00
|
|
|
ir_rvalue *
|
|
|
|
|
ir_rvalue::clone(void *mem_ctx, struct hash_table *ht) const
|
|
|
|
|
{
|
|
|
|
|
/* The only possible instantiation is the generic error value. */
|
|
|
|
|
return error_value(mem_ctx);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-23 11:37:12 -07:00
|
|
|
/**
|
|
|
|
|
* Duplicate an IR variable
|
|
|
|
|
*/
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_variable *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_variable::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_variable *var = new(mem_ctx) ir_variable(this->type, this->name,
|
|
|
|
|
(ir_variable_mode) this->mode);
|
2010-06-23 11:37:12 -07:00
|
|
|
|
|
|
|
|
var->max_array_access = this->max_array_access;
|
2013-09-18 14:15:36 -07:00
|
|
|
if (this->is_interface_instance()) {
|
|
|
|
|
var->max_ifc_array_access =
|
|
|
|
|
rzalloc_array(var, unsigned, this->interface_type->length);
|
|
|
|
|
memcpy(var->max_ifc_array_access, this->max_ifc_array_access,
|
|
|
|
|
this->interface_type->length * sizeof(unsigned));
|
|
|
|
|
}
|
2010-06-23 11:37:12 -07:00
|
|
|
var->read_only = this->read_only;
|
|
|
|
|
var->centroid = this->centroid;
|
|
|
|
|
var->invariant = this->invariant;
|
|
|
|
|
var->interpolation = this->interpolation;
|
2010-07-07 16:11:10 -07:00
|
|
|
var->location = this->location;
|
2012-04-25 14:59:25 -07:00
|
|
|
var->index = this->index;
|
2013-07-18 15:10:49 -07:00
|
|
|
var->binding = this->binding;
|
2013-10-20 12:35:47 -07:00
|
|
|
var->atomic.buffer_index = this->atomic.buffer_index;
|
|
|
|
|
var->atomic.offset = this->atomic.offset;
|
2010-07-07 16:11:10 -07:00
|
|
|
var->warn_extension = this->warn_extension;
|
2010-07-28 14:41:51 -07:00
|
|
|
var->origin_upper_left = this->origin_upper_left;
|
|
|
|
|
var->pixel_center_integer = this->pixel_center_integer;
|
2010-10-07 15:13:38 -07:00
|
|
|
var->explicit_location = this->explicit_location;
|
glsl: add support for ARB_blend_func_extended (v3)
This adds index support to the GLSL compiler.
I'm not 100% sure of my approach here, esp without how output ordering
happens wrt location, index pairs, in the "mark" function.
Since current hw doesn't ever have a location > 0 with an index > 0,
we don't have to work out if the output ordering the hw requires is
location, index, location, index or location, location, index, index.
But we have no hw to know, so punt on it for now.
v2: index requires layout - catch and error
setup explicit index properly.
v3: drop idx_offset stuff, assume index follow location
Signed-off-by: Dave Airlie <airlied@redhat.com>
2012-03-24 13:33:41 +00:00
|
|
|
var->explicit_index = this->explicit_index;
|
2013-07-18 15:10:49 -07:00
|
|
|
var->explicit_binding = this->explicit_binding;
|
2011-10-31 14:31:07 -07:00
|
|
|
var->has_initializer = this->has_initializer;
|
2011-11-19 14:30:13 +01:00
|
|
|
var->depth_layout = this->depth_layout;
|
2013-08-30 15:27:49 -07:00
|
|
|
var->assigned = this->assigned;
|
2013-11-13 16:53:18 -08:00
|
|
|
var->how_declared = this->how_declared;
|
2013-08-30 15:27:49 -07:00
|
|
|
var->used = this->used;
|
2011-01-25 10:41:20 -08:00
|
|
|
|
|
|
|
|
var->num_state_slots = this->num_state_slots;
|
|
|
|
|
if (this->state_slots) {
|
|
|
|
|
/* FINISHME: This really wants to use something like talloc_reference, but
|
|
|
|
|
* FINISHME: ralloc doesn't have any similar function.
|
|
|
|
|
*/
|
|
|
|
|
var->state_slots = ralloc_array(var, ir_state_slot,
|
|
|
|
|
this->num_state_slots);
|
|
|
|
|
memcpy(var->state_slots, this->state_slots,
|
|
|
|
|
sizeof(this->state_slots[0]) * var->num_state_slots);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-07 16:11:10 -07:00
|
|
|
if (this->constant_value)
|
2010-08-04 12:34:56 -07:00
|
|
|
var->constant_value = this->constant_value->clone(mem_ctx, ht);
|
2010-06-23 11:37:12 -07:00
|
|
|
|
2011-10-31 14:31:07 -07:00
|
|
|
if (this->constant_initializer)
|
|
|
|
|
var->constant_initializer =
|
|
|
|
|
this->constant_initializer->clone(mem_ctx, ht);
|
|
|
|
|
|
2013-01-21 21:51:15 -05:00
|
|
|
var->interface_type = this->interface_type;
|
|
|
|
|
|
2010-06-23 11:37:12 -07:00
|
|
|
if (ht) {
|
2010-06-24 13:31:34 -07:00
|
|
|
hash_table_insert(ht, var, (void *)const_cast<ir_variable *>(this));
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return var;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_swizzle *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_swizzle::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
2010-08-04 12:34:56 -07:00
|
|
|
return new(mem_ctx) ir_swizzle(this->val->clone(mem_ctx, ht), this->mask);
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_return *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_return::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
|
|
|
|
ir_rvalue *new_value = NULL;
|
|
|
|
|
|
|
|
|
|
if (this->value)
|
2010-08-04 12:34:56 -07:00
|
|
|
new_value = this->value->clone(mem_ctx, ht);
|
2010-06-23 11:37:12 -07:00
|
|
|
|
2010-08-04 12:34:56 -07:00
|
|
|
return new(mem_ctx) ir_return(new_value);
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_discard *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_discard::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-30 10:47:34 -07:00
|
|
|
{
|
|
|
|
|
ir_rvalue *new_condition = NULL;
|
|
|
|
|
|
|
|
|
|
if (this->condition != NULL)
|
2010-08-04 12:34:56 -07:00
|
|
|
new_condition = this->condition->clone(mem_ctx, ht);
|
2010-06-30 10:47:34 -07:00
|
|
|
|
2010-08-04 12:34:56 -07:00
|
|
|
return new(mem_ctx) ir_discard(new_condition);
|
2010-06-30 10:47:34 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_loop_jump *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_loop_jump::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
|
|
|
|
(void)ht;
|
|
|
|
|
|
2010-08-04 12:34:56 -07:00
|
|
|
return new(mem_ctx) ir_loop_jump(this->mode);
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_if *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_if::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_if *new_if = new(mem_ctx) ir_if(this->condition->clone(mem_ctx, ht));
|
2010-06-23 11:37:12 -07:00
|
|
|
|
|
|
|
|
foreach_iter(exec_list_iterator, iter, this->then_instructions) {
|
|
|
|
|
ir_instruction *ir = (ir_instruction *)iter.get();
|
2010-08-04 12:34:56 -07:00
|
|
|
new_if->then_instructions.push_tail(ir->clone(mem_ctx, ht));
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach_iter(exec_list_iterator, iter, this->else_instructions) {
|
|
|
|
|
ir_instruction *ir = (ir_instruction *)iter.get();
|
2010-08-04 12:34:56 -07:00
|
|
|
new_if->else_instructions.push_tail(ir->clone(mem_ctx, ht));
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new_if;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_loop *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_loop::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_loop *new_loop = new(mem_ctx) ir_loop();
|
2010-06-23 11:37:12 -07:00
|
|
|
|
|
|
|
|
if (this->from)
|
2010-08-04 12:34:56 -07:00
|
|
|
new_loop->from = this->from->clone(mem_ctx, ht);
|
2010-06-23 11:37:12 -07:00
|
|
|
if (this->to)
|
2010-08-04 12:34:56 -07:00
|
|
|
new_loop->to = this->to->clone(mem_ctx, ht);
|
2010-06-23 11:37:12 -07:00
|
|
|
if (this->increment)
|
2010-08-04 12:34:56 -07:00
|
|
|
new_loop->increment = this->increment->clone(mem_ctx, ht);
|
glsl: Fix inconsistent assumptions about ir_loop::counter.
The compiler back-ends (i965's fs_visitor and brw_visitor,
ir_to_mesa_visitor, and glsl_to_tgsi_visitor) assume that when
ir_loop::counter is non-null, it points to a fresh ir_variable that
should be used as the loop counter (as opposed to an ir_variable that
exists elsewhere in the instruction stream).
However, previous to this patch:
(1) loop_control_visitor did not create a new variable for
ir_loop::counter; instead it re-used the existing ir_variable.
This caused the loop counter to be double-incremented (once
explicitly by the body of the loop, and once implicitly by
ir_loop::increment).
(2) ir_clone did not clone ir_loop::counter properly, resulting in the
cloned ir_loop pointing to the source ir_loop's counter.
(3) ir_hierarchical_visitor did not visit ir_loop::counter, resulting
in the ir_variable being missed by reparenting.
Additionally, most optimization passes (e.g. loop unrolling) assume
that the variable mentioned by ir_loop::counter is not accessed in the
body of the loop (an assumption which (1) violates).
The combination of these factors caused a perfect storm in which the
code worked properly nearly all of the time: for loops that got
unrolled, (1) would introduce a double-increment, but loop unrolling
would fail to notice it (since it assumes that ir_loop::counter is not
accessed in the body of the loop), so it would unroll the loop the
correct number of times. For loops that didn't get unrolled, (1)
would introduce a double-increment, but then later when the IR was
cloned for linking, (2) would prevent the loop counter from being
cloned properly, so it would look to further analysis stages like an
independent variable (and hence the double-increment would stop
occurring). At the end of linking, (3) would prevent the loop counter
from being reparented, so it would still belong to the shader object
rather than the linked program object. Provided that the client
program didn't delete the shader object, the memory would never get
reclaimed, and so the shader would function properly.
However, for loops that didn't get unrolled, if the client program did
delete the shader object, and the memory belonging to the loop counter
got re-used, this could cause a use-after-free bug, leading to a
crash.
This patch fixes loop_control_visitor, ir_clone, and
ir_hierarchical_visitor to treat ir_loop::counter the same way the
back-ends treat it: as a freshly allocated ir_variable that needs to
be visited and cloned independently of other ir_variables.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=72026
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-11-26 14:19:49 -08:00
|
|
|
if (this->counter)
|
|
|
|
|
new_loop->counter = this->counter->clone(mem_ctx, ht);
|
2010-06-23 11:37:12 -07:00
|
|
|
|
|
|
|
|
foreach_iter(exec_list_iterator, iter, this->body_instructions) {
|
|
|
|
|
ir_instruction *ir = (ir_instruction *)iter.get();
|
2010-08-04 12:34:56 -07:00
|
|
|
new_loop->body_instructions.push_tail(ir->clone(mem_ctx, ht));
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
2010-08-26 15:11:26 -07:00
|
|
|
new_loop->cmp = this->cmp;
|
2010-06-23 11:37:12 -07:00
|
|
|
return new_loop;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_call *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_call::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
glsl: Convert ir_call to be a statement rather than a value.
Aside from ir_call, our IR is cleanly split into two classes:
- Statements (typeless; used for side effects, control flow)
- Values (deeply nestable, pure, typed expression trees)
Unfortunately, ir_call confused all this:
- For void functions, we placed ir_call directly in the instruction
stream, treating it as an untyped statement. Yet, it was a subclass
of ir_rvalue, and no other ir_rvalue could be used in this way.
- For functions with a return value, ir_call could be placed in
arbitrary expression trees. While this fit naturally with the source
language, it meant that expressions might not be pure, making it
difficult to transform and optimize them. To combat this, we always
emitted ir_call directly in the RHS of an ir_assignment, only using
a temporary variable in expression trees. Many passes relied on this
assumption; the acos and atan built-ins violated it.
This patch makes ir_call a statement (ir_instruction) rather than a
value (ir_rvalue). Non-void calls now take a ir_dereference of a
variable, and store the return value there---effectively a call and
assignment rolled into one. They cannot be embedded in expressions.
All expression trees are now pure, without exception.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-03-20 15:56:37 -07:00
|
|
|
ir_dereference_variable *new_return_ref = NULL;
|
|
|
|
|
if (this->return_deref != NULL)
|
|
|
|
|
new_return_ref = this->return_deref->clone(mem_ctx, ht);
|
|
|
|
|
|
2010-06-23 11:37:12 -07:00
|
|
|
exec_list new_parameters;
|
|
|
|
|
|
|
|
|
|
foreach_iter(exec_list_iterator, iter, this->actual_parameters) {
|
|
|
|
|
ir_instruction *ir = (ir_instruction *)iter.get();
|
2010-08-04 12:34:56 -07:00
|
|
|
new_parameters.push_tail(ir->clone(mem_ctx, ht));
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
glsl: Convert ir_call to be a statement rather than a value.
Aside from ir_call, our IR is cleanly split into two classes:
- Statements (typeless; used for side effects, control flow)
- Values (deeply nestable, pure, typed expression trees)
Unfortunately, ir_call confused all this:
- For void functions, we placed ir_call directly in the instruction
stream, treating it as an untyped statement. Yet, it was a subclass
of ir_rvalue, and no other ir_rvalue could be used in this way.
- For functions with a return value, ir_call could be placed in
arbitrary expression trees. While this fit naturally with the source
language, it meant that expressions might not be pure, making it
difficult to transform and optimize them. To combat this, we always
emitted ir_call directly in the RHS of an ir_assignment, only using
a temporary variable in expression trees. Many passes relied on this
assumption; the acos and atan built-ins violated it.
This patch makes ir_call a statement (ir_instruction) rather than a
value (ir_rvalue). Non-void calls now take a ir_dereference of a
variable, and store the return value there---effectively a call and
assignment rolled into one. They cannot be embedded in expressions.
All expression trees are now pure, without exception.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-03-20 15:56:37 -07:00
|
|
|
return new(mem_ctx) ir_call(this->callee, new_return_ref, &new_parameters);
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_expression *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_expression::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
2010-11-10 16:33:10 -08:00
|
|
|
ir_rvalue *op[Elements(this->operands)] = { NULL, };
|
2010-06-23 11:37:12 -07:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < get_num_operands(); i++) {
|
2010-08-04 12:34:56 -07:00
|
|
|
op[i] = this->operands[i]->clone(mem_ctx, ht);
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
2010-11-16 12:01:42 -08:00
|
|
|
return new(mem_ctx) ir_expression(this->operation, this->type,
|
|
|
|
|
op[0], op[1], op[2], op[3]);
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_dereference_variable *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_dereference_variable::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
|
|
|
|
ir_variable *new_var;
|
|
|
|
|
|
|
|
|
|
if (ht) {
|
|
|
|
|
new_var = (ir_variable *)hash_table_find(ht, this->var);
|
|
|
|
|
if (!new_var)
|
|
|
|
|
new_var = this->var;
|
|
|
|
|
} else {
|
|
|
|
|
new_var = this->var;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-04 12:34:56 -07:00
|
|
|
return new(mem_ctx) ir_dereference_variable(new_var);
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_dereference_array *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_dereference_array::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
2010-08-04 12:34:56 -07:00
|
|
|
return new(mem_ctx) ir_dereference_array(this->array->clone(mem_ctx, ht),
|
|
|
|
|
this->array_index->clone(mem_ctx,
|
|
|
|
|
ht));
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_dereference_record *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_dereference_record::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
2010-08-04 12:34:56 -07:00
|
|
|
return new(mem_ctx) ir_dereference_record(this->record->clone(mem_ctx, ht),
|
|
|
|
|
this->field);
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_texture *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_texture::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_texture *new_tex = new(mem_ctx) ir_texture(this->op);
|
2010-07-22 15:34:01 -07:00
|
|
|
new_tex->type = this->type;
|
2010-06-23 11:37:12 -07:00
|
|
|
|
2010-08-04 12:34:56 -07:00
|
|
|
new_tex->sampler = this->sampler->clone(mem_ctx, ht);
|
2011-02-25 14:45:33 -08:00
|
|
|
if (this->coordinate)
|
|
|
|
|
new_tex->coordinate = this->coordinate->clone(mem_ctx, ht);
|
2010-06-23 11:37:12 -07:00
|
|
|
if (this->projector)
|
2010-08-04 12:34:56 -07:00
|
|
|
new_tex->projector = this->projector->clone(mem_ctx, ht);
|
2010-06-23 11:37:12 -07:00
|
|
|
if (this->shadow_comparitor) {
|
2010-08-04 12:34:56 -07:00
|
|
|
new_tex->shadow_comparitor = this->shadow_comparitor->clone(mem_ctx, ht);
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
2011-01-08 23:49:23 -08:00
|
|
|
if (this->offset != NULL)
|
|
|
|
|
new_tex->offset = this->offset->clone(mem_ctx, ht);
|
2010-06-23 11:37:12 -07:00
|
|
|
|
|
|
|
|
switch (this->op) {
|
|
|
|
|
case ir_tex:
|
2012-09-23 19:50:41 +10:00
|
|
|
case ir_lod:
|
2013-09-26 19:37:30 +12:00
|
|
|
case ir_query_levels:
|
2010-06-23 11:37:12 -07:00
|
|
|
break;
|
|
|
|
|
case ir_txb:
|
2010-08-04 12:34:56 -07:00
|
|
|
new_tex->lod_info.bias = this->lod_info.bias->clone(mem_ctx, ht);
|
2010-06-23 11:37:12 -07:00
|
|
|
break;
|
|
|
|
|
case ir_txl:
|
|
|
|
|
case ir_txf:
|
2011-02-25 14:45:33 -08:00
|
|
|
case ir_txs:
|
2010-08-04 12:34:56 -07:00
|
|
|
new_tex->lod_info.lod = this->lod_info.lod->clone(mem_ctx, ht);
|
2012-12-21 21:33:37 +13:00
|
|
|
break;
|
|
|
|
|
case ir_txf_ms:
|
|
|
|
|
new_tex->lod_info.sample_index = this->lod_info.sample_index->clone(mem_ctx, ht);
|
2010-06-23 11:37:12 -07:00
|
|
|
break;
|
|
|
|
|
case ir_txd:
|
2010-08-04 12:34:56 -07:00
|
|
|
new_tex->lod_info.grad.dPdx = this->lod_info.grad.dPdx->clone(mem_ctx, ht);
|
|
|
|
|
new_tex->lod_info.grad.dPdy = this->lod_info.grad.dPdy->clone(mem_ctx, ht);
|
2010-06-23 11:37:12 -07:00
|
|
|
break;
|
2013-10-05 18:26:56 +13:00
|
|
|
case ir_tg4:
|
|
|
|
|
new_tex->lod_info.component = this->lod_info.component->clone(mem_ctx, ht);
|
|
|
|
|
break;
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new_tex;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_assignment *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_assignment::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
|
|
|
|
ir_rvalue *new_condition = NULL;
|
|
|
|
|
|
|
|
|
|
if (this->condition)
|
2010-08-04 12:34:56 -07:00
|
|
|
new_condition = this->condition->clone(mem_ctx, ht);
|
2010-06-23 11:37:12 -07:00
|
|
|
|
2010-08-04 12:34:56 -07:00
|
|
|
return new(mem_ctx) ir_assignment(this->lhs->clone(mem_ctx, ht),
|
|
|
|
|
this->rhs->clone(mem_ctx, ht),
|
2010-08-02 18:48:25 -07:00
|
|
|
new_condition,
|
|
|
|
|
this->write_mask);
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_function *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_function::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
2010-07-07 11:02:19 -07:00
|
|
|
ir_function *copy = new(mem_ctx) ir_function(this->name);
|
|
|
|
|
|
|
|
|
|
foreach_list_const(node, &this->signatures) {
|
|
|
|
|
const ir_function_signature *const sig =
|
|
|
|
|
(const ir_function_signature *const) node;
|
|
|
|
|
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_function_signature *sig_copy = sig->clone(mem_ctx, ht);
|
2010-07-07 11:02:19 -07:00
|
|
|
copy->add_signature(sig_copy);
|
|
|
|
|
|
|
|
|
|
if (ht != NULL)
|
|
|
|
|
hash_table_insert(ht, sig_copy,
|
|
|
|
|
(void *)const_cast<ir_function_signature *>(sig));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return copy;
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_function_signature *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_function_signature::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-11-11 12:21:27 -08:00
|
|
|
{
|
|
|
|
|
ir_function_signature *copy = this->clone_prototype(mem_ctx, ht);
|
|
|
|
|
|
|
|
|
|
copy->is_defined = this->is_defined;
|
|
|
|
|
|
|
|
|
|
/* Clone the instruction list.
|
|
|
|
|
*/
|
|
|
|
|
foreach_list_const(node, &this->body) {
|
|
|
|
|
const ir_instruction *const inst = (const ir_instruction *) node;
|
|
|
|
|
|
|
|
|
|
ir_instruction *const inst_copy = inst->clone(mem_ctx, ht);
|
|
|
|
|
copy->body.push_tail(inst_copy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_function_signature *
|
|
|
|
|
ir_function_signature::clone_prototype(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 11:37:12 -07:00
|
|
|
{
|
2010-07-07 11:02:19 -07:00
|
|
|
ir_function_signature *copy =
|
|
|
|
|
new(mem_ctx) ir_function_signature(this->return_type);
|
|
|
|
|
|
2010-11-11 12:21:27 -08:00
|
|
|
copy->is_defined = false;
|
2013-09-09 14:53:22 -07:00
|
|
|
copy->builtin_avail = this->builtin_avail;
|
2012-05-02 23:11:41 +02:00
|
|
|
copy->origin = this;
|
2010-07-07 11:02:19 -07:00
|
|
|
|
2010-11-11 12:21:27 -08:00
|
|
|
/* Clone the parameter list, but NOT the body.
|
2010-07-07 11:02:19 -07:00
|
|
|
*/
|
|
|
|
|
foreach_list_const(node, &this->parameters) {
|
|
|
|
|
const ir_variable *const param = (const ir_variable *) node;
|
|
|
|
|
|
|
|
|
|
assert(const_cast<ir_variable *>(param)->as_variable() != NULL);
|
|
|
|
|
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_variable *const param_copy = param->clone(mem_ctx, ht);
|
2010-07-07 11:02:19 -07:00
|
|
|
copy->parameters.push_tail(param_copy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return copy;
|
2010-06-23 11:37:12 -07:00
|
|
|
}
|
2010-06-23 16:42:37 -07:00
|
|
|
|
2010-07-06 17:41:02 -07:00
|
|
|
ir_constant *
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_constant::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 16:42:37 -07:00
|
|
|
{
|
2010-06-23 16:43:08 -07:00
|
|
|
(void)ht;
|
|
|
|
|
|
2010-06-23 16:42:37 -07:00
|
|
|
switch (this->type->base_type) {
|
|
|
|
|
case GLSL_TYPE_UINT:
|
|
|
|
|
case GLSL_TYPE_INT:
|
|
|
|
|
case GLSL_TYPE_FLOAT:
|
|
|
|
|
case GLSL_TYPE_BOOL:
|
2010-08-04 12:34:56 -07:00
|
|
|
return new(mem_ctx) ir_constant(this->type, &this->value);
|
2010-06-23 16:42:37 -07:00
|
|
|
|
|
|
|
|
case GLSL_TYPE_STRUCT: {
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_constant *c = new(mem_ctx) ir_constant;
|
2010-06-23 16:42:37 -07:00
|
|
|
|
|
|
|
|
c->type = this->type;
|
|
|
|
|
for (exec_node *node = this->components.head
|
2010-07-29 13:52:25 -07:00
|
|
|
; !node->is_tail_sentinel()
|
2010-06-23 16:42:37 -07:00
|
|
|
; node = node->next) {
|
|
|
|
|
ir_constant *const orig = (ir_constant *) node;
|
|
|
|
|
|
2010-08-04 12:34:56 -07:00
|
|
|
c->components.push_tail(orig->clone(mem_ctx, NULL));
|
2010-06-23 16:42:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-20 01:06:33 -07:00
|
|
|
case GLSL_TYPE_ARRAY: {
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_constant *c = new(mem_ctx) ir_constant;
|
2010-07-20 01:06:33 -07:00
|
|
|
|
|
|
|
|
c->type = this->type;
|
2011-01-21 14:32:31 -08:00
|
|
|
c->array_elements = ralloc_array(c, ir_constant *, this->type->length);
|
2010-07-20 01:06:33 -07:00
|
|
|
for (unsigned i = 0; i < this->type->length; i++) {
|
2010-08-04 12:34:56 -07:00
|
|
|
c->array_elements[i] = this->array_elements[i]->clone(mem_ctx, NULL);
|
2010-07-20 01:06:33 -07:00
|
|
|
}
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-11 12:56:03 -08:00
|
|
|
case GLSL_TYPE_SAMPLER:
|
2013-10-20 12:35:47 -07:00
|
|
|
case GLSL_TYPE_ATOMIC_UINT:
|
2012-12-11 12:56:03 -08:00
|
|
|
case GLSL_TYPE_VOID:
|
|
|
|
|
case GLSL_TYPE_ERROR:
|
2012-12-11 12:11:16 -08:00
|
|
|
case GLSL_TYPE_INTERFACE:
|
2010-08-14 14:40:39 +01:00
|
|
|
assert(!"Should not get here.");
|
2012-12-11 12:56:03 -08:00
|
|
|
break;
|
2010-06-23 16:42:37 -07:00
|
|
|
}
|
2012-12-11 12:56:03 -08:00
|
|
|
|
|
|
|
|
return NULL;
|
2010-06-23 16:42:37 -07:00
|
|
|
}
|
2010-07-06 16:01:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class fixup_ir_call_visitor : public ir_hierarchical_visitor {
|
|
|
|
|
public:
|
|
|
|
|
fixup_ir_call_visitor(struct hash_table *ht)
|
|
|
|
|
{
|
|
|
|
|
this->ht = ht;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual ir_visitor_status visit_enter(ir_call *ir)
|
|
|
|
|
{
|
|
|
|
|
/* Try to find the function signature referenced by the ir_call in the
|
|
|
|
|
* table. If it is found, replace it with the value from the table.
|
|
|
|
|
*/
|
2010-07-18 17:45:16 -07:00
|
|
|
ir_function_signature *sig =
|
2011-09-20 18:08:11 -07:00
|
|
|
(ir_function_signature *) hash_table_find(this->ht, ir->callee);
|
2010-07-06 16:01:06 -07:00
|
|
|
if (sig != NULL)
|
2011-09-20 18:08:11 -07:00
|
|
|
ir->callee = sig;
|
2010-07-06 16:01:06 -07:00
|
|
|
|
|
|
|
|
/* Since this may be used before function call parameters are flattened,
|
|
|
|
|
* the children also need to be processed.
|
|
|
|
|
*/
|
|
|
|
|
return visit_continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct hash_table *ht;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
fixup_function_calls(struct hash_table *ht, exec_list *instructions)
|
|
|
|
|
{
|
|
|
|
|
fixup_ir_call_visitor v(ht);
|
|
|
|
|
v.run(instructions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-08-04 12:34:56 -07:00
|
|
|
clone_ir_list(void *mem_ctx, exec_list *out, const exec_list *in)
|
2010-07-06 16:01:06 -07:00
|
|
|
{
|
|
|
|
|
struct hash_table *ht =
|
|
|
|
|
hash_table_ctor(0, hash_table_pointer_hash, hash_table_pointer_compare);
|
|
|
|
|
|
|
|
|
|
foreach_list_const(node, in) {
|
|
|
|
|
const ir_instruction *const original = (ir_instruction *) node;
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_instruction *copy = original->clone(mem_ctx, ht);
|
2010-07-06 16:01:06 -07:00
|
|
|
|
|
|
|
|
out->push_tail(copy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Make a pass over the cloned tree to fix up ir_call nodes to point to the
|
|
|
|
|
* cloned ir_function_signature nodes. This cannot be done automatically
|
|
|
|
|
* during cloning because the ir_call might be a forward reference (i.e.,
|
|
|
|
|
* the function signature that it references may not have been cloned yet).
|
|
|
|
|
*/
|
|
|
|
|
fixup_function_calls(ht, out);
|
|
|
|
|
|
|
|
|
|
hash_table_dtor(ht);
|
|
|
|
|
}
|