case GLSL_TYPE_IMAGE:
case GLSL_TYPE_INTERFACE:
case GLSL_TYPE_ATOMIC_UINT:
+ case GLSL_TYPE_SUBROUTINE:
/* I assume a comparison of a struct containing a sampler just
* ignores the sampler present in the type.
*/
hash_table *glsl_type::array_types = NULL;
hash_table *glsl_type::record_types = NULL;
hash_table *glsl_type::interface_types = NULL;
+hash_table *glsl_type::subroutine_types = NULL;
void *glsl_type::mem_ctx = NULL;
void
mtx_unlock(&glsl_type::mutex);
}
+glsl_type::glsl_type(const char *subroutine_name) :
+ gl_type(0),
+ base_type(GLSL_TYPE_SUBROUTINE),
+ sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
+ sampler_type(0), interface_packing(0),
+ vector_elements(0), matrix_columns(0),
+ length(0)
+{
+ mtx_lock(&glsl_type::mutex);
+
+ init_ralloc_type_ctx();
+ assert(subroutine_name != NULL);
+ this->name = ralloc_strdup(this->mem_ctx, subroutine_name);
+ this->vector_elements = 1;
+ mtx_unlock(&glsl_type::mutex);
+}
bool
glsl_type::contains_sampler() const
}
}
+bool
+glsl_type::contains_subroutine() const
+{
+ if (this->is_array()) {
+ return this->fields.array->contains_subroutine();
+ } else if (this->is_record()) {
+ for (unsigned int i = 0; i < this->length; i++) {
+ if (this->fields.structure[i].type->contains_subroutine())
+ return true;
+ }
+ return false;
+ } else {
+ return this->is_subroutine();
+ }
+}
+
gl_texture_index
glsl_type::sampler_index() const
{
return (glsl_type *) entry->data;
}
+const glsl_type *
+glsl_type::get_subroutine_instance(const char *subroutine_name)
+{
+ const glsl_type key(subroutine_name);
+
+ mtx_lock(&glsl_type::mutex);
+
+ if (subroutine_types == NULL) {
+ subroutine_types = _mesa_hash_table_create(NULL, record_key_hash,
+ record_key_compare);
+ }
+
+ const struct hash_entry *entry = _mesa_hash_table_search(subroutine_types,
+ &key);
+ if (entry == NULL) {
+ mtx_unlock(&glsl_type::mutex);
+ const glsl_type *t = new glsl_type(subroutine_name);
+ mtx_lock(&glsl_type::mutex);
+
+ entry = _mesa_hash_table_insert(subroutine_types, t, (void *) t);
+ }
+
+ assert(((glsl_type *) entry->data)->base_type == GLSL_TYPE_SUBROUTINE);
+ assert(strcmp(((glsl_type *) entry->data)->name, subroutine_name) == 0);
+
+ mtx_unlock(&glsl_type::mutex);
+
+ return (glsl_type *) entry->data;
+}
+
const glsl_type *
glsl_type::get_mul_type(const glsl_type *type_a, const glsl_type *type_b)
case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_VOID:
+ case GLSL_TYPE_SUBROUTINE:
case GLSL_TYPE_ERROR:
break;
}
case GLSL_TYPE_BOOL:
case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_IMAGE:
+ case GLSL_TYPE_SUBROUTINE:
return 1;
case GLSL_TYPE_STRUCT:
case GLSL_TYPE_IMAGE:
case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_VOID:
+ case GLSL_TYPE_SUBROUTINE:
case GLSL_TYPE_ERROR:
break;
}
GLSL_TYPE_INTERFACE,
GLSL_TYPE_ARRAY,
GLSL_TYPE_VOID,
+ GLSL_TYPE_SUBROUTINE,
GLSL_TYPE_ERROR
};
enum glsl_interface_packing packing,
const char *block_name);
+ /**
+ * Get the instance of an subroutine type
+ */
+ static const glsl_type *get_subroutine_instance(const char *subroutine_name);
+
/**
* Get the type resulting from a multiplication of \p type_a * \p type_b
*/
/**
* Query if a type is unnamed/anonymous (named by the parser)
*/
+
+ bool is_subroutine() const
+ {
+ return base_type == GLSL_TYPE_SUBROUTINE;
+ }
+ bool contains_subroutine() const;
+
bool is_anonymous() const
{
return !strncmp(name, "#anon", 5);
/** Constructor for array types */
glsl_type(const glsl_type *array, unsigned length);
+ /** Constructor for subroutine types */
+ glsl_type(const char *name);
+
/** Hash table containing the known array types. */
static struct hash_table *array_types;
/** Hash table containing the known interface types. */
static struct hash_table *interface_types;
+ /** Hash table containing the known subroutine types. */
+ static struct hash_table *subroutine_types;
+
static bool record_key_compare(const void *a, const void *b);
static unsigned record_key_hash(const void *key);
case ir_unop_bit_count:
case ir_unop_find_msb:
case ir_unop_find_lsb:
+ case ir_unop_subroutine_to_int:
this->type = glsl_type::get_instance(GLSL_TYPE_INT,
op0->type->vector_elements, 1);
break;
"frexp_sig",
"frexp_exp",
"noise",
+ "subroutine_to_int",
"interpolate_at_centroid",
"+",
"-",
ir_unop_noise,
+ ir_unop_subroutine_to_int,
/**
* Interpolate fs input at centroid
*
return expr(ir_unop_sign, a);
}
+ir_expression *
+subr_to_int(operand a)
+{
+ return expr(ir_unop_subroutine_to_int, a);
+}
+
ir_expression*
equal(operand a, operand b)
{
ir_expression *log(operand a);
ir_expression *sign(operand a);
+ir_expression *subr_to_int(operand a);
ir_expression *equal(operand a, operand b);
ir_expression *nequal(operand a, operand b);
ir_expression *less(operand a, operand b);
case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
+ case GLSL_TYPE_SUBROUTINE:
case GLSL_TYPE_INTERFACE:
assert(!"Should not get here.");
break;
ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
assert(ir->type->base_type == GLSL_TYPE_INT);
break;
+ case ir_unop_subroutine_to_int:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_SUBROUTINE);
+ assert(ir->type->base_type == GLSL_TYPE_INT);
+ break;
case ir_binop_add:
case ir_binop_sub:
case ir_binop_mul:
case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_INTERFACE:
case GLSL_TYPE_VOID:
+ case GLSL_TYPE_SUBROUTINE:
case GLSL_TYPE_ERROR:
/* All other types should have already been filtered by other
* paths in the caller.
size += type_size(glsl_get_struct_field(type, i));
}
return size;
+ case GLSL_TYPE_SUBROUTINE:
+ return 1;
case GLSL_TYPE_SAMPLER:
return 0;
case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
case GLSL_TYPE_INTERFACE:
+ case GLSL_TYPE_SUBROUTINE:
ASSERT_TRUE(false);
break;
}
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
case GLSL_TYPE_INTERFACE:
+ case GLSL_TYPE_SUBROUTINE:
ASSERT_TRUE(false);
break;
}
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
case GLSL_TYPE_INTERFACE:
+ case GLSL_TYPE_SUBROUTINE:
ASSERT_TRUE(false);
break;
}
return size;
case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_IMAGE:
+ case GLSL_TYPE_SUBROUTINE:
/* Samplers take up one slot in UNIFORMS[], but they're baked in
* at link time.
*/
result_src = op[0];
}
break;
+ case ir_unop_subroutine_to_int:
+ emit_asm(ir, TGSI_OPCODE_MOV, result_dst, op[0]);
+ break;
case ir_unop_abs:
emit_asm(ir, TGSI_OPCODE_ABS, result_dst, op[0]);
break;