本文整理汇总了C++中ralloc_parent函数的典型用法代码示例。如果您正苦于以下问题:C++ ralloc_parent函数的具体用法?C++ ralloc_parent怎么用?C++ ralloc_parent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ralloc_parent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: new
/**
* If the given ir satisfies is_clip_distance_vec8(), return new ir
* representing its lowered equivalent. That is, map:
*
* - gl_ClipDistance => gl_ClipDistanceMESA (if gl_ClipDistance is 1D)
* - gl_ClipDistance[i] => gl_ClipDistanceMESA[i] (if gl_ClipDistance is 2D)
*
* Otherwise return NULL.
*/
ir_rvalue *
lower_clip_distance_visitor::lower_clip_distance_vec8(ir_rvalue *ir)
{
if (!ir->type->is_array())
return NULL;
if (ir->type->fields.array != glsl_type::float_type)
return NULL;
ir_variable **new_var = NULL;
if (this->old_clip_distance_out_var) {
if (ir->variable_referenced() == this->old_clip_distance_out_var)
new_var = &this->new_clip_distance_out_var;
}
if (this->old_clip_distance_in_var) {
if (ir->variable_referenced() == this->old_clip_distance_in_var)
new_var = &this->new_clip_distance_in_var;
}
if (new_var == NULL)
return NULL;
if (ir->as_dereference_variable()) {
return new(ralloc_parent(ir)) ir_dereference_variable(*new_var);
} else {
ir_dereference_array *array_ref = ir->as_dereference_array();
assert(array_ref);
assert(array_ref->array->as_dereference_variable());
return new(ralloc_parent(ir))
ir_dereference_array(*new_var, array_ref->array_index);
}
}
示例2: new
/**
* If the given ir satisfies is_clip_distance_vec8(), return new ir
* representing its lowered equivalent. That is, map:
*
* - gl_ClipDistance => gl_ClipDistanceMESA (if gl_ClipDistance is 1D)
* - gl_ClipDistance[i] => gl_ClipDistanceMESA[i] (if gl_ClipDistance is 2D)
*
* Otherwise return NULL.
*/
ir_rvalue *
lower_clip_distance_visitor::lower_clip_distance_vec8(ir_rvalue *ir)
{
if (this->old_clip_distance_1d_var) {
ir_dereference_variable *var_ref = ir->as_dereference_variable();
if (var_ref && var_ref->var == this->old_clip_distance_1d_var) {
return new(ralloc_parent(ir))
ir_dereference_variable(this->new_clip_distance_1d_var);
}
}
if (this->old_clip_distance_2d_var) {
/* 2D clip distance is only possible as a geometry input */
assert(this->shader_stage == MESA_SHADER_GEOMETRY);
ir_dereference_array *array_ref = ir->as_dereference_array();
if (array_ref) {
ir_dereference_variable *var_ref =
array_ref->array->as_dereference_variable();
if (var_ref && var_ref->var == this->old_clip_distance_2d_var) {
return new(ralloc_parent(ir))
ir_dereference_array(this->new_clip_distance_2d_var,
array_ref->array_index);
}
}
}
return NULL;
}
示例3:
void
ir_coalesce_floats_replacing_visitor::handle_rvalue(ir_rvalue **rvalue)
{
ir_rvalue *ir = *rvalue;
if(!ir) return;
ir_dereference *dv;
ir_swizzle *swiz;
ir_swizzle *outerswiz = ir->as_swizzle();
if( outerswiz ) {
dv = outerswiz->val->as_dereference();
if(dv) {
//fprintf(stderr, "var1: %s\n", dv->variable_referenced()->name);
swiz = (ir_swizzle*)hash_table_find(promotions, dv->variable_referenced());
if(swiz) {
//fprintf(stderr, "// replacing[1] %p %p\n", ir, swiz);
*rvalue = swiz->clone(ralloc_parent(swiz), NULL);
return;
}
}
}
dv = ir->as_dereference();
if(!dv) return;
swiz = (ir_swizzle*)hash_table_find(promotions, dv->variable_referenced());
//fprintf(stderr, "var2: %s %p\n", dv->variable_referenced()->name, dv->variable_referenced());
if (!swiz) return;
//fprintf(stderr, "// replacing[2] %p %p\n", ir, swiz);
*rvalue = swiz->clone(ralloc_parent(swiz), NULL);
}
示例4: assert
/**
* Replace any declaration of gl_TessLevel* as an array of floats with a
* declaration of gl_TessLevel*MESA as a vec4.
*/
ir_visitor_status
lower_tess_level_visitor::visit(ir_variable *ir)
{
if ((!ir->name) ||
((strcmp(ir->name, "gl_TessLevelInner") != 0) &&
(strcmp(ir->name, "gl_TessLevelOuter") != 0)))
return visit_continue;
assert (ir->type->is_array());
if (strcmp(ir->name, "gl_TessLevelOuter") == 0) {
if (this->old_tess_level_outer_var)
return visit_continue;
old_tess_level_outer_var = ir;
assert(ir->type->fields.array == glsl_type::float_type);
/* Clone the old var so that we inherit all of its properties */
new_tess_level_outer_var = ir->clone(ralloc_parent(ir), NULL);
/* And change the properties that we need to change */
new_tess_level_outer_var->name = ralloc_strdup(new_tess_level_outer_var,
"gl_TessLevelOuterMESA");
new_tess_level_outer_var->type = glsl_type::vec4_type;
new_tess_level_outer_var->data.max_array_access = 0;
ir->replace_with(new_tess_level_outer_var);
} else if (strcmp(ir->name, "gl_TessLevelInner") == 0) {
if (this->old_tess_level_inner_var)
return visit_continue;
old_tess_level_inner_var = ir;
assert(ir->type->fields.array == glsl_type::float_type);
/* Clone the old var so that we inherit all of its properties */
new_tess_level_inner_var = ir->clone(ralloc_parent(ir), NULL);
/* And change the properties that we need to change */
new_tess_level_inner_var->name = ralloc_strdup(new_tess_level_inner_var,
"gl_TessLevelInnerMESA");
new_tess_level_inner_var->type = glsl_type::vec2_type;
new_tess_level_inner_var->data.max_array_access = 0;
ir->replace_with(new_tess_level_inner_var);
} else {
assert(0);
}
this->progress = true;
return visit_continue;
}
示例5: assert
/**
* Replace any declaration of gl_ClipDistance as an array of floats with a
* declaration of gl_ClipDistanceMESA as an array of vec4's.
*/
ir_visitor_status
lower_clip_distance_visitor::visit(ir_variable *ir)
{
/* No point in looking for the declaration of gl_ClipDistance if
* we've already found it.
*/
if (this->old_clip_distance_var)
return visit_continue;
if (ir->name && strcmp(ir->name, "gl_ClipDistance") == 0) {
this->progress = true;
this->old_clip_distance_var = ir;
assert (ir->type->is_array());
assert (ir->type->element_type() == glsl_type::float_type);
unsigned new_size = (ir->type->array_size() + 3) / 4;
/* Clone the old var so that we inherit all of its properties */
this->new_clip_distance_var = ir->clone(ralloc_parent(ir), NULL);
/* And change the properties that we need to change */
this->new_clip_distance_var->name
= ralloc_strdup(this->new_clip_distance_var, "gl_ClipDistanceMESA");
this->new_clip_distance_var->type
= glsl_type::get_array_instance(glsl_type::vec4_type, new_size);
this->new_clip_distance_var->max_array_access = ir->max_array_access / 4;
ir->replace_with(this->new_clip_distance_var);
}
return visit_continue;
}
示例6: _mesa_hash_table_search
ir_visitor_status
output_read_remover::visit(ir_dereference_variable *ir)
{
if (ir->var->data.mode != ir_var_shader_out)
return visit_continue;
if (stage == MESA_SHADER_TESS_CTRL)
return visit_continue;
hash_entry *entry = _mesa_hash_table_search(replacements, ir->var);
ir_variable *temp = entry ? (ir_variable *) entry->data : NULL;
/* If we don't have an existing temporary, create one. */
if (temp == NULL) {
void *var_ctx = ralloc_parent(ir->var);
temp = new(var_ctx) ir_variable(ir->var->type, ir->var->name,
ir_var_temporary);
_mesa_hash_table_insert(replacements, ir->var, temp);
ir->var->insert_after(temp);
}
/* Update the dereference to use the temporary */
ir->var = temp;
return visit_continue;
}
示例7: opt_undef_alu
static bool
opt_undef_alu(nir_alu_instr *instr)
{
if (instr->op != nir_op_bcsel && instr->op != nir_op_fcsel)
return false;
assert(instr->dest.dest.is_ssa);
for (int i = 1; i <= 2; i++) {
if (!instr->src[i].src.is_ssa)
continue;
nir_instr *parent = instr->src[i].src.ssa->parent_instr;
if (parent->type != nir_instr_type_ssa_undef)
continue;
/* We can't just use nir_alu_src_copy, because we need the def/use
* updated.
*/
nir_instr_rewrite_src(&instr->instr, &instr->src[0].src,
instr->src[i == 1 ? 2 : 1].src);
nir_alu_src_copy(&instr->src[0], &instr->src[i == 1 ? 2 : 1],
ralloc_parent(instr));
nir_src empty_src;
memset(&empty_src, 0, sizeof(empty_src));
nir_instr_rewrite_src(&instr->instr, &instr->src[1].src, empty_src);
nir_instr_rewrite_src(&instr->instr, &instr->src[2].src, empty_src);
instr->op = nir_op_imov;
return true;
}
return false;
}
示例8: ralloc_parent
ir_rvalue *
ir_vec_index_to_swizzle_visitor::convert_vector_extract_to_swizzle(ir_rvalue *ir)
{
ir_expression *const expr = ir->as_expression();
if (expr == NULL || expr->operation != ir_binop_vector_extract)
return ir;
ir_constant *const idx = expr->operands[1]->constant_expression_value();
if (idx == NULL)
return ir;
void *ctx = ralloc_parent(ir);
this->progress = true;
/* Page 40 of the GLSL 1.20 spec says:
*
* "When indexing with non-constant expressions, behavior is undefined
* if the index is negative, or greater than or equal to the size of
* the vector."
*
* The quoted spec text mentions non-constant expressions, but this code
* operates on constants. These constants are the result of non-constant
* expressions that have been optimized to constants. The common case here
* is a loop counter from an unrolled loop that is used to index a vector.
*
* The ir_swizzle constructor gets angry if the index is negative or too
* large. For simplicity sake, just clamp the index to [0, size-1].
*/
const int i = CLAMP(idx->value.i[0], 0,
(int) expr->operands[0]->type->vector_elements - 1);
return new(ctx) ir_swizzle(expr->operands[0], i, 0, 0, 0, 1);
}
示例9: generate
void generate(unsigned i, ir_rvalue* condition, exec_list *list) const
{
/* Just clone the rest of the deref chain when trying to get at the
* underlying variable.
*/
void *mem_ctx = ralloc_parent(base_ir);
/* Clone the old r-value in its entirety. Then replace any occurances of
* the old variable index with the new constant index.
*/
ir_dereference *element = this->rvalue->clone(mem_ctx, NULL);
ir_constant *const index = new(mem_ctx)ir_constant(i);
deref_replacer r(this->old_index, index);
element->accept(&r);
check(r.progress);
/* Generate a conditional assignment to (or from) the constant indexed
* array dereference.
*/
ir_rvalue *variable = new(mem_ctx)ir_dereference_variable(this->var);
ir_assignment *const assignment = (is_write)
? new(mem_ctx)ir_assignment(element, variable, condition, write_mask)
: new(mem_ctx)ir_assignment(variable, element, condition);
list->push_tail(assignment);
}
示例10: ralloc_parent
/**
* If a 1D gl_ClipDistance variable appears as an argument in an ir_call
* expression, replace it with a temporary variable, and make sure the ir_call
* is preceded and/or followed by assignments that copy the contents of the
* temporary variable to and/or from gl_ClipDistance. Each of these
* assignments is then lowered to refer to gl_ClipDistanceMESA.
*
* We need to do a similar replacement for 2D gl_ClipDistance, however since
* it's an input, the only case we need to address is where a 1D slice of it
* is passed as an "in" parameter to an ir_call, e.g.:
*
* foo(gl_in[i].gl_ClipDistance)
*/
ir_visitor_status
lower_clip_distance_visitor::visit_leave(ir_call *ir)
{
void *ctx = ralloc_parent(ir);
const exec_node *formal_param_node = ir->callee->parameters.head;
const exec_node *actual_param_node = ir->actual_parameters.head;
while (!actual_param_node->is_tail_sentinel()) {
ir_variable *formal_param = (ir_variable *) formal_param_node;
ir_rvalue *actual_param = (ir_rvalue *) actual_param_node;
/* Advance formal_param_node and actual_param_node now so that we can
* safely replace actual_param with another node, if necessary, below.
*/
formal_param_node = formal_param_node->next;
actual_param_node = actual_param_node->next;
if (this->is_clip_distance_vec8(actual_param)) {
/* User is trying to pass the whole 1D gl_ClipDistance array (or a 1D
* slice of a 2D gl_ClipDistance array) to a function call. Since we
* are reshaping gl_ClipDistance from an array of floats to an array
* of vec4's, this isn't going to work anymore, so use a temporary
* array instead.
*/
ir_variable *temp_clip_distance = new(ctx) ir_variable(
actual_param->type, "temp_clip_distance", ir_var_temporary, actual_param->get_precision());
this->base_ir->insert_before(temp_clip_distance);
actual_param->replace_with(
new(ctx) ir_dereference_variable(temp_clip_distance));
if (formal_param->data.mode == ir_var_function_in
|| formal_param->data.mode == ir_var_function_inout) {
/* Copy from gl_ClipDistance to the temporary before the call.
* Since we are going to insert this copy before the current
* instruction, we need to visit it afterwards to make sure it
* gets lowered.
*/
ir_assignment *new_assignment = new(ctx) ir_assignment(
new(ctx) ir_dereference_variable(temp_clip_distance),
actual_param->clone(ctx, NULL));
this->base_ir->insert_before(new_assignment);
this->visit_new_assignment(new_assignment);
}
if (formal_param->data.mode == ir_var_function_out
|| formal_param->data.mode == ir_var_function_inout) {
/* Copy from the temporary to gl_ClipDistance after the call.
* Since visit_list_elements() has already decided which
* instruction it's going to visit next, we need to visit
* afterwards to make sure it gets lowered.
*/
ir_assignment *new_assignment = new(ctx) ir_assignment(
actual_param->clone(ctx, NULL),
new(ctx) ir_dereference_variable(temp_clip_distance));
this->base_ir->insert_after(new_assignment);
this->visit_new_assignment(new_assignment);
}
}
}
return rvalue_visit(ir);
}
示例11: ralloc_parent
void
lower_tess_level_visitor::handle_rvalue(ir_rvalue **rv)
{
if (*rv == NULL)
return;
ir_dereference_array *const array_deref = (*rv)->as_dereference_array();
if (array_deref == NULL)
return;
/* Replace any expression that indexes one of the floats in gl_TessLevel*
* with an expression that indexes into one of the vec4's
* gl_TessLevel*MESA and accesses the appropriate component.
*/
ir_rvalue *lowered_vec4 =
this->lower_tess_level_array(array_deref->array);
if (lowered_vec4 != NULL) {
this->progress = true;
void *mem_ctx = ralloc_parent(array_deref);
ir_expression *const expr =
new(mem_ctx) ir_expression(ir_binop_vector_extract,
lowered_vec4,
array_deref->array_index);
*rv = expr;
}
}
示例12: expr
ir_expression *
expr(ir_expression_operation op, operand a, operand b)
{
void *mem_ctx = ralloc_parent(a.val);
return new(mem_ctx) ir_expression(op, a.val, b.val);
}
示例13: validate_deref_chain
static void
validate_deref_chain(nir_deref *deref, validate_state *state)
{
assert(deref->child == NULL || ralloc_parent(deref->child) == deref);
nir_deref *parent = NULL;
while (deref != NULL) {
switch (deref->deref_type) {
case nir_deref_type_array:
assert(deref->type == glsl_get_array_element(parent->type));
if (nir_deref_as_array(deref)->deref_array_type ==
nir_deref_array_type_indirect)
validate_src(&nir_deref_as_array(deref)->indirect, state);
break;
case nir_deref_type_struct:
assert(deref->type ==
glsl_get_struct_field(parent->type,
nir_deref_as_struct(deref)->index));
break;
case nir_deref_type_var:
break;
default:
assert(!"Invalid deref type");
break;
}
parent = deref;
deref = deref->child;
}
}
示例14: bitfield_insert
ir_expression *
bitfield_insert(operand a, operand b, operand c, operand d)
{
void *mem_ctx = ralloc_parent(a.val);
return new(mem_ctx) ir_expression(ir_quadop_bitfield_insert,
a.val->type, a.val, b.val, c.val, d.val);
}
示例15: ralloc_parent
/**
* Replace any assignment having gl_ClipDistance (undereferenced) as its LHS
* or RHS with a sequence of assignments, one for each component of the array.
* Each of these assignments is lowered to refer to gl_ClipDistanceMESA as
* appropriate.
*/
ir_visitor_status
lower_clip_distance_visitor::visit_leave(ir_assignment *ir)
{
ir_dereference_variable *lhs_var = ir->lhs->as_dereference_variable();
ir_dereference_variable *rhs_var = ir->rhs->as_dereference_variable();
if ((lhs_var && lhs_var->var == this->old_clip_distance_var)
|| (rhs_var && rhs_var->var == this->old_clip_distance_var)) {
/* LHS or RHS of the assignment is the entire gl_ClipDistance array.
* Since we are reshaping gl_ClipDistance from an array of floats to an
* array of vec4's, this isn't going to work as a bulk assignment
* anymore, so unroll it to element-by-element assignments and lower
* each of them.
*
* Note: to unroll into element-by-element assignments, we need to make
* clones of the LHS and RHS. This is safe because expressions and
* l-values are side-effect free.
*/
void *ctx = ralloc_parent(ir);
int array_size = this->old_clip_distance_var->type->array_size();
for (int i = 0; i < array_size; ++i) {
ir_dereference_array *new_lhs = new(ctx) ir_dereference_array(
ir->lhs->clone(ctx, NULL), new(ctx) ir_constant(i));
ir_dereference_array *new_rhs = new(ctx) ir_dereference_array(
ir->rhs->clone(ctx, NULL), new(ctx) ir_constant(i));
this->handle_rvalue((ir_rvalue **) &new_rhs);
/* Handle the LHS after creating the new assignment. This must
* happen in this order because handle_rvalue may replace the old LHS
* with an ir_expression of ir_binop_vector_extract. Since this is
* not a valide l-value, this will cause an assertion in the
* ir_assignment constructor to fail.
*
* If this occurs, replace the mangled LHS with a dereference of the
* vector, and replace the RHS with an ir_triop_vector_insert.
*/
ir_assignment *const assign = new(ctx) ir_assignment(new_lhs, new_rhs);
this->handle_rvalue((ir_rvalue **) &assign->lhs);
this->fix_lhs(assign);
this->base_ir->insert_before(assign);
}
ir->remove();
return visit_continue;
}
/* Handle the LHS as if it were an r-value. Normally
* rvalue_visit(ir_assignment *) only visits the RHS, but we need to lower
* expressions in the LHS as well.
*
* This may cause the LHS to get replaced with an ir_expression of
* ir_binop_vector_extract. If this occurs, replace it with a dereference
* of the vector, and replace the RHS with an ir_triop_vector_insert.
*/
handle_rvalue((ir_rvalue **)&ir->lhs);
this->fix_lhs(ir);
return rvalue_visit(ir);
}