glsl: add capability to lower mediump array types
This is not needed for lowering expressions, because they always work with basic types, but it will be needed for lowering variables. Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5746>
This commit is contained in:
@@ -155,7 +155,7 @@ can_lower_type(const struct gl_shader_compiler_options *options,
|
|||||||
* boolean types so that it will do comparisons as 16-bit.
|
* boolean types so that it will do comparisons as 16-bit.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
switch (type->base_type) {
|
switch (type->without_array()->base_type) {
|
||||||
/* TODO: should we do anything for these two with regard to Int16 vs FP16
|
/* TODO: should we do anything for these two with regard to Int16 vs FP16
|
||||||
* support?
|
* support?
|
||||||
*/
|
*/
|
||||||
@@ -626,23 +626,46 @@ find_lowerable_rvalues(const struct gl_shader_compiler_options *options,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const glsl_type *
|
static const glsl_type *
|
||||||
lower_glsl_type(const glsl_type *type)
|
convert_type(bool up, const glsl_type *type)
|
||||||
{
|
{
|
||||||
|
if (type->is_array()) {
|
||||||
|
return glsl_type::get_array_instance(convert_type(up, type->fields.array),
|
||||||
|
type->array_size(),
|
||||||
|
type->explicit_stride);
|
||||||
|
}
|
||||||
|
|
||||||
glsl_base_type new_base_type;
|
glsl_base_type new_base_type;
|
||||||
|
|
||||||
switch (type->base_type) {
|
if (up) {
|
||||||
case GLSL_TYPE_FLOAT:
|
switch (type->base_type) {
|
||||||
new_base_type = GLSL_TYPE_FLOAT16;
|
case GLSL_TYPE_FLOAT16:
|
||||||
break;
|
new_base_type = GLSL_TYPE_FLOAT;
|
||||||
case GLSL_TYPE_INT:
|
break;
|
||||||
new_base_type = GLSL_TYPE_INT16;
|
case GLSL_TYPE_INT16:
|
||||||
break;
|
new_base_type = GLSL_TYPE_INT;
|
||||||
case GLSL_TYPE_UINT:
|
break;
|
||||||
new_base_type = GLSL_TYPE_UINT16;
|
case GLSL_TYPE_UINT16:
|
||||||
break;
|
new_base_type = GLSL_TYPE_UINT;
|
||||||
default:
|
break;
|
||||||
unreachable("invalid type");
|
default:
|
||||||
return NULL;
|
unreachable("invalid type");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (type->base_type) {
|
||||||
|
case GLSL_TYPE_FLOAT:
|
||||||
|
new_base_type = GLSL_TYPE_FLOAT16;
|
||||||
|
break;
|
||||||
|
case GLSL_TYPE_INT:
|
||||||
|
new_base_type = GLSL_TYPE_INT16;
|
||||||
|
break;
|
||||||
|
case GLSL_TYPE_UINT:
|
||||||
|
new_base_type = GLSL_TYPE_UINT16;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
unreachable("invalid type");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return glsl_type::get_instance(new_base_type,
|
return glsl_type::get_instance(new_base_type,
|
||||||
@@ -652,23 +675,26 @@ lower_glsl_type(const glsl_type *type)
|
|||||||
type->interface_row_major);
|
type->interface_row_major);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const glsl_type *
|
||||||
|
lower_glsl_type(const glsl_type *type)
|
||||||
|
{
|
||||||
|
return convert_type(false, type);
|
||||||
|
}
|
||||||
|
|
||||||
static ir_rvalue *
|
static ir_rvalue *
|
||||||
convert_precision(bool up, ir_rvalue *ir)
|
convert_precision(bool up, ir_rvalue *ir)
|
||||||
{
|
{
|
||||||
unsigned new_type, op;
|
unsigned op;
|
||||||
|
|
||||||
if (up) {
|
if (up) {
|
||||||
switch (ir->type->base_type) {
|
switch (ir->type->without_array()->base_type) {
|
||||||
case GLSL_TYPE_FLOAT16:
|
case GLSL_TYPE_FLOAT16:
|
||||||
new_type = GLSL_TYPE_FLOAT;
|
|
||||||
op = ir_unop_f162f;
|
op = ir_unop_f162f;
|
||||||
break;
|
break;
|
||||||
case GLSL_TYPE_INT16:
|
case GLSL_TYPE_INT16:
|
||||||
new_type = GLSL_TYPE_INT;
|
|
||||||
op = ir_unop_i2i;
|
op = ir_unop_i2i;
|
||||||
break;
|
break;
|
||||||
case GLSL_TYPE_UINT16:
|
case GLSL_TYPE_UINT16:
|
||||||
new_type = GLSL_TYPE_UINT;
|
|
||||||
op = ir_unop_u2u;
|
op = ir_unop_u2u;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -676,17 +702,14 @@ convert_precision(bool up, ir_rvalue *ir)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (ir->type->base_type) {
|
switch (ir->type->without_array()->base_type) {
|
||||||
case GLSL_TYPE_FLOAT:
|
case GLSL_TYPE_FLOAT:
|
||||||
new_type = GLSL_TYPE_FLOAT16;
|
|
||||||
op = ir_unop_f2fmp;
|
op = ir_unop_f2fmp;
|
||||||
break;
|
break;
|
||||||
case GLSL_TYPE_INT:
|
case GLSL_TYPE_INT:
|
||||||
new_type = GLSL_TYPE_INT16;
|
|
||||||
op = ir_unop_i2imp;
|
op = ir_unop_i2imp;
|
||||||
break;
|
break;
|
||||||
case GLSL_TYPE_UINT:
|
case GLSL_TYPE_UINT:
|
||||||
new_type = GLSL_TYPE_UINT16;
|
|
||||||
op = ir_unop_u2ump;
|
op = ir_unop_u2ump;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -695,11 +718,7 @@ convert_precision(bool up, ir_rvalue *ir)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const glsl_type *desired_type;
|
const glsl_type *desired_type = convert_type(up, ir->type);
|
||||||
desired_type = glsl_type::get_instance(new_type,
|
|
||||||
ir->type->vector_elements,
|
|
||||||
ir->type->matrix_columns);
|
|
||||||
|
|
||||||
void *mem_ctx = ralloc_parent(ir);
|
void *mem_ctx = ralloc_parent(ir);
|
||||||
return new(mem_ctx) ir_expression(op, desired_type, ir, NULL);
|
return new(mem_ctx) ir_expression(op, desired_type, ir, NULL);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user