glsl: Add helper methods to glsl_type for dealing with images.
Add predicates to query if a GLSL type is or contains an image. Rename sampler_coordinate_components() to coordinate_components(). v2: Use assert instead of unreachable. v3: No need to use a separate code-path for images in coordinate_components() after merging image and sampler fields in the glsl_type structure. Reviewed-by: Paul Berry <stereotype441@gmail.com>
This commit is contained in:
parent
8a2508ee07
commit
107d03a6d5
|
@ -3549,7 +3549,7 @@ builtin_builder::_texture(ir_texture_opcode opcode,
|
|||
ir_texture *tex = new(mem_ctx) ir_texture(opcode);
|
||||
tex->set_sampler(var_ref(s), return_type);
|
||||
|
||||
const int coord_size = sampler_type->sampler_coordinate_components();
|
||||
const int coord_size = sampler_type->coordinate_components();
|
||||
|
||||
if (coord_size == coord_type->vector_elements) {
|
||||
tex->coordinate = var_ref(P);
|
||||
|
|
|
@ -226,6 +226,21 @@ glsl_type::sampler_index() const
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
glsl_type::contains_image() const
|
||||
{
|
||||
if (this->is_array()) {
|
||||
return this->fields.array->contains_image();
|
||||
} else if (this->is_record()) {
|
||||
for (unsigned int i = 0; i < this->length; i++) {
|
||||
if (this->fields.structure[i].type->contains_image())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return this->is_image();
|
||||
}
|
||||
}
|
||||
|
||||
const glsl_type *glsl_type::get_base_type() const
|
||||
{
|
||||
|
@ -955,10 +970,8 @@ glsl_type::count_attribute_slots() const
|
|||
}
|
||||
|
||||
int
|
||||
glsl_type::sampler_coordinate_components() const
|
||||
glsl_type::coordinate_components() const
|
||||
{
|
||||
assert(is_sampler());
|
||||
|
||||
int size;
|
||||
|
||||
switch (sampler_dimensionality) {
|
||||
|
|
|
@ -403,6 +403,20 @@ struct glsl_type {
|
|||
*/
|
||||
gl_texture_index sampler_index() const;
|
||||
|
||||
/**
|
||||
* Query whether or not type is an image, or for struct and array
|
||||
* types, contains an image.
|
||||
*/
|
||||
bool contains_image() const;
|
||||
|
||||
/**
|
||||
* Query whether or not a type is an image
|
||||
*/
|
||||
bool is_image() const
|
||||
{
|
||||
return base_type == GLSL_TYPE_IMAGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query whether or not a type is an array
|
||||
*/
|
||||
|
@ -533,7 +547,8 @@ struct glsl_type {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the number of coordinate components needed for this sampler type.
|
||||
* Return the number of coordinate components needed for this
|
||||
* sampler or image type.
|
||||
*
|
||||
* This is based purely on the sampler's dimensionality. For example, this
|
||||
* returns 1 for sampler1D, and 3 for sampler2DArray.
|
||||
|
@ -542,7 +557,7 @@ struct glsl_type {
|
|||
* a texturing built-in function, since those pack additional values (such
|
||||
* as the shadow comparitor or projector) into the coordinate type.
|
||||
*/
|
||||
int sampler_coordinate_components() const;
|
||||
int coordinate_components() const;
|
||||
|
||||
/**
|
||||
* Compare a record type against another record type.
|
||||
|
|
|
@ -47,7 +47,7 @@ TEST(sampler_types, TYPE) \
|
|||
EXPECT_EQ(DATA_TYPE, type->sampler_type); \
|
||||
ARR; \
|
||||
SHAD; \
|
||||
EXPECT_EQ(COMPS, type->sampler_coordinate_components()); \
|
||||
EXPECT_EQ(COMPS, type->coordinate_components()); \
|
||||
}
|
||||
|
||||
T( sampler1D, GLSL_SAMPLER_DIM_1D, GLSL_TYPE_FLOAT, NONARRAY, COLOR, 1)
|
||||
|
|
Loading…
Reference in New Issue