Browse Source

nir: glsl_get_bit_size() should take glsl_type

It's what all the call-sites once, so gets rid of a bunch of inlined
glsl_get_base_type() at the call-sites.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
tags/12.0-branchpoint
Rob Clark 9 years ago
parent
commit
9d3cc80b75

+ 8
- 8
src/compiler/nir/glsl_to_nir.cpp View File

instr->num_components = type->vector_elements; instr->num_components = type->vector_elements;


/* Setup destination register */ /* Setup destination register */
unsigned bit_size = glsl_get_bit_size(type->base_type);
unsigned bit_size = glsl_get_bit_size(type);
nir_ssa_dest_init(&instr->instr, &instr->dest, nir_ssa_dest_init(&instr->instr, &instr->dest,
type->vector_elements, bit_size, NULL); type->vector_elements, bit_size, NULL);


instr->num_components = type->vector_elements; instr->num_components = type->vector_elements;


/* Setup destination register */ /* Setup destination register */
unsigned bit_size = glsl_get_bit_size(type->base_type);
unsigned bit_size = glsl_get_bit_size(type);
nir_ssa_dest_init(&instr->instr, &instr->dest, nir_ssa_dest_init(&instr->instr, &instr->dest,
type->vector_elements, bit_size, NULL); type->vector_elements, bit_size, NULL);




/* Atomic result */ /* Atomic result */
assert(ir->return_deref); assert(ir->return_deref);
unsigned bit_size = glsl_get_bit_size(ir->return_deref->type->base_type);
unsigned bit_size = glsl_get_bit_size(ir->return_deref->type);
nir_ssa_dest_init(&instr->instr, &instr->dest, nir_ssa_dest_init(&instr->instr, &instr->dest,
ir->return_deref->type->vector_elements, ir->return_deref->type->vector_elements,
bit_size, NULL); bit_size, NULL);
load_instr->num_components = ir->type->vector_elements; load_instr->num_components = ir->type->vector_elements;
load_instr->variables[0] = this->deref_head; load_instr->variables[0] = this->deref_head;
ralloc_steal(load_instr, load_instr->variables[0]); ralloc_steal(load_instr, load_instr->variables[0]);
unsigned bit_size = glsl_get_bit_size(ir->type->base_type);
unsigned bit_size = glsl_get_bit_size(ir->type);
add_instr(&load_instr->instr, ir->type->vector_elements, bit_size); add_instr(&load_instr->instr, ir->type->vector_elements, bit_size);
} }


case ir_binop_ubo_load: { case ir_binop_ubo_load: {
nir_intrinsic_instr *load = nir_intrinsic_instr *load =
nir_intrinsic_instr_create(this->shader, nir_intrinsic_load_ubo); nir_intrinsic_instr_create(this->shader, nir_intrinsic_load_ubo);
unsigned bit_size = glsl_get_bit_size(ir->type->base_type);
unsigned bit_size = glsl_get_bit_size(ir->type);
load->num_components = ir->type->vector_elements; load->num_components = ir->type->vector_elements;
load->src[0] = nir_src_for_ssa(evaluate_rvalue(ir->operands[0])); load->src[0] = nir_src_for_ssa(evaluate_rvalue(ir->operands[0]));
load->src[1] = nir_src_for_ssa(evaluate_rvalue(ir->operands[1])); load->src[1] = nir_src_for_ssa(evaluate_rvalue(ir->operands[1]));
intrin->intrinsic == nir_intrinsic_interp_var_at_sample) intrin->intrinsic == nir_intrinsic_interp_var_at_sample)
intrin->src[0] = nir_src_for_ssa(evaluate_rvalue(ir->operands[1])); intrin->src[0] = nir_src_for_ssa(evaluate_rvalue(ir->operands[1]));


unsigned bit_size = glsl_get_bit_size(deref->type->base_type);
unsigned bit_size = glsl_get_bit_size(deref->type);
add_instr(&intrin->instr, deref->type->vector_elements, bit_size); add_instr(&intrin->instr, deref->type->vector_elements, bit_size);


if (swizzle) { if (swizzle) {
nir_intrinsic_get_buffer_size); nir_intrinsic_get_buffer_size);
load->num_components = ir->type->vector_elements; load->num_components = ir->type->vector_elements;
load->src[0] = nir_src_for_ssa(evaluate_rvalue(ir->operands[0])); load->src[0] = nir_src_for_ssa(evaluate_rvalue(ir->operands[0]));
unsigned bit_size = glsl_get_bit_size(ir->type->base_type);
unsigned bit_size = glsl_get_bit_size(ir->type);
add_instr(&load->instr, ir->type->vector_elements, bit_size); add_instr(&load->instr, ir->type->vector_elements, bit_size);
return; return;
} }


assert(src_number == num_srcs); assert(src_number == num_srcs);


unsigned bit_size = glsl_get_bit_size(ir->type->base_type);
unsigned bit_size = glsl_get_bit_size(ir->type);
add_instr(&instr->instr, nir_tex_instr_dest_size(instr), bit_size); add_instr(&instr->instr, nir_tex_instr_dest_size(instr), bit_size);
} }



+ 1
- 1
src/compiler/nir/nir.c View File

tail = tail->child; tail = tail->child;
} }


unsigned bit_size = glsl_get_bit_size(glsl_get_base_type(tail->type));
unsigned bit_size = glsl_get_bit_size(tail->type);
nir_load_const_instr *load = nir_load_const_instr *load =
nir_load_const_instr_create(shader, glsl_get_vector_elements(tail->type), nir_load_const_instr_create(shader, glsl_get_vector_elements(tail->type),
bit_size); bit_size);

+ 1
- 1
src/compiler/nir/nir_builder.h View File

load->num_components = num_components; load->num_components = num_components;
load->variables[0] = nir_deref_var_create(load, var); load->variables[0] = nir_deref_var_create(load, var);
nir_ssa_dest_init(&load->instr, &load->dest, num_components, nir_ssa_dest_init(&load->instr, &load->dest, num_components,
glsl_get_bit_size(glsl_get_base_type(var->type)), NULL);
glsl_get_bit_size(var->type), NULL);
nir_builder_instr_insert(build, &load->instr); nir_builder_instr_insert(build, &load->instr);
return &load->dest.ssa; return &load->dest.ssa;
} }

+ 1
- 1
src/compiler/nir/nir_lower_locals_to_regs.c View File

nir_register *reg = nir_local_reg_create(state->impl); nir_register *reg = nir_local_reg_create(state->impl);
reg->num_components = glsl_get_vector_elements(tail->type); reg->num_components = glsl_get_vector_elements(tail->type);
reg->num_array_elems = array_size > 1 ? array_size : 0; reg->num_array_elems = array_size > 1 ? array_size : 0;
reg->bit_size = glsl_get_bit_size(glsl_get_base_type(tail->type));
reg->bit_size = glsl_get_bit_size(tail->type);


_mesa_hash_table_insert_pre_hashed(state->regs_table, hash, deref, reg); _mesa_hash_table_insert_pre_hashed(state->regs_table, hash, deref, reg);
nir_array_add(&state->derefs_array, nir_deref_var *, deref); nir_array_add(&state->derefs_array, nir_deref_var *, deref);

+ 1
- 2
src/compiler/nir/nir_lower_var_copies.c View File

assert(src_tail->type == dest_tail->type); assert(src_tail->type == dest_tail->type);


unsigned num_components = glsl_get_vector_elements(src_tail->type); unsigned num_components = glsl_get_vector_elements(src_tail->type);
unsigned bit_size =
glsl_get_bit_size(glsl_get_base_type(src_tail->type));
unsigned bit_size = glsl_get_bit_size(src_tail->type);


nir_intrinsic_instr *load = nir_intrinsic_instr *load =
nir_intrinsic_instr_create(mem_ctx, nir_intrinsic_load_var); nir_intrinsic_instr_create(mem_ctx, nir_intrinsic_load_var);

+ 1
- 1
src/compiler/nir/nir_lower_vars_to_ssa.c View File

node->pb_value = node->pb_value =
nir_phi_builder_add_value(state.phi_builder, nir_phi_builder_add_value(state.phi_builder,
glsl_get_vector_elements(node->type), glsl_get_vector_elements(node->type),
glsl_get_bit_size(glsl_get_base_type(node->type)),
glsl_get_bit_size(node->type),
store_blocks); store_blocks);


if (node->deref->var->constant_initializer) { if (node->deref->var->constant_initializer) {

+ 2
- 2
src/compiler/nir_types.h View File

unsigned length); unsigned length);


static inline unsigned static inline unsigned
glsl_get_bit_size(enum glsl_base_type type)
glsl_get_bit_size(const struct glsl_type *type)
{ {
switch (type) {
switch (glsl_get_base_type(type)) {
case GLSL_TYPE_INT: case GLSL_TYPE_INT:
case GLSL_TYPE_UINT: case GLSL_TYPE_UINT:
case GLSL_TYPE_BOOL: case GLSL_TYPE_BOOL:

+ 3
- 3
src/compiler/spirv/spirv_to_nir.c View File



if (glsl_type_is_vector_or_scalar(type)) { if (glsl_type_is_vector_or_scalar(type)) {
unsigned num_components = glsl_get_vector_elements(val->type); unsigned num_components = glsl_get_vector_elements(val->type);
unsigned bit_size = glsl_get_bit_size(glsl_get_base_type(val->type));
unsigned bit_size = glsl_get_bit_size(val->type);
val->def = nir_ssa_undef(&b->nb, num_components, bit_size); val->def = nir_ssa_undef(&b->nb, num_components, bit_size);
} else { } else {
unsigned elems = glsl_get_length(val->type); unsigned elems = glsl_get_length(val->type);


unsigned num_components = glsl_get_vector_elements(val->const_type); unsigned num_components = glsl_get_vector_elements(val->const_type);
unsigned bit_size = unsigned bit_size =
glsl_get_bit_size(glsl_get_base_type(val->const_type));
glsl_get_bit_size(val->const_type);


nir_const_value src[3]; nir_const_value src[3];
assert(count <= 7); assert(count <= 7);
for (unsigned i = 0; i < glsl_get_matrix_columns(dest->type); i++) { for (unsigned i = 0; i < glsl_get_matrix_columns(dest->type); i++) {
nir_alu_instr *vec = create_vec(b->shader, nir_alu_instr *vec = create_vec(b->shader,
glsl_get_matrix_columns(src->type), glsl_get_matrix_columns(src->type),
glsl_get_bit_size(glsl_get_base_type(src->type)));
glsl_get_bit_size(src->type));
if (glsl_type_is_vector_or_scalar(src->type)) { if (glsl_type_is_vector_or_scalar(src->type)) {
vec->src[0].src = nir_src_for_ssa(src->def); vec->src[0].src = nir_src_for_ssa(src->def);
vec->src[0].swizzle[0] = i; vec->src[0].swizzle[0] = i;

+ 2
- 2
src/compiler/spirv/vtn_variables.c View File

if (load) { if (load) {
nir_ssa_dest_init(&intrin->instr, &intrin->dest, nir_ssa_dest_init(&intrin->instr, &intrin->dest,
intrin->num_components, intrin->num_components,
glsl_get_bit_size(glsl_get_base_type(tail->type)),
glsl_get_bit_size(tail->type),
NULL); NULL);
inout->def = &intrin->dest.ssa; inout->def = &intrin->dest.ssa;
} else { } else {
if (load) { if (load) {
nir_ssa_dest_init(&instr->instr, &instr->dest, nir_ssa_dest_init(&instr->instr, &instr->dest,
instr->num_components, instr->num_components,
glsl_get_bit_size(glsl_get_base_type(type)), NULL);
glsl_get_bit_size(type), NULL);
(*inout)->def = &instr->dest.ssa; (*inout)->def = &instr->dest.ssa;
} }



Loading…
Cancel
Save