glsl: Add 16-bit types

Adds new INT16, UINT16 and FLOAT16 base types.

The corresponding GL types for half floats were reused from the
AMD_gpu_shader_half_float extension. The int16 and uint16 types come from
NV_gpu_shader_5 extension.

This adds the builtins and the lexer support.

To avoid a bunch of warnings due to cases not handled in switch, the
new types have been added to a few places using same behavior as
their 32-bit counterparts, except for a few trivial cases where they are
already handled properly. Subsequent patches in this set will provide
correct 16-bit implementations when needed.

v2: * Use FLOAT16 instead of HALF_FLOAT as name of the base type.
    * Removed float16_t from builtin types.
    * Don't copy 16-bit types as if they were 32-bit values in
      copy_constant_to_storage().
    * Use get_scalar_type() instead of adding a new custom switch
      statement.
    (Jason Ekstrand)
v3: Use GL_FLOAT16_NV instead of GL_HALF_FLOAT for consistency
    (Ilia Mirkin)
v4: Add missing 16-bit base types support in glsl_to_nir (Eduardo Lima).
v5: Fix coding style (Topi Poholainen).

Signed-off-by: Jose Maria Casanova Crespo <jmcasanova@igalia.com>
Signed-off-by: Eduardo Lima <elima@igalia.com>
Signed-off-by: Alejandro Piñeiro <apinheiro@igalia.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
This commit is contained in:
Eduardo Lima Mitev
2017-07-01 07:46:41 +02:00
committed by Jose Maria Casanova Crespo
parent 8761a04d0d
commit 59f458cd87
9 changed files with 145 additions and 8 deletions

View File

@@ -1108,12 +1108,15 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
switch (op0->type->base_type) {
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_FLOAT16:
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
case GLSL_TYPE_BOOL:
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_UINT64:
case GLSL_TYPE_INT64:
case GLSL_TYPE_UINT16:
case GLSL_TYPE_INT16:
return new(mem_ctx) ir_expression(operation, op0, op1);
case GLSL_TYPE_ARRAY: {

View File

@@ -1378,13 +1378,15 @@ nir_visitor::evaluate_rvalue(ir_rvalue* ir)
static bool
type_is_float(glsl_base_type type)
{
return type == GLSL_TYPE_FLOAT || type == GLSL_TYPE_DOUBLE;
return type == GLSL_TYPE_FLOAT || type == GLSL_TYPE_DOUBLE ||
type == GLSL_TYPE_FLOAT16;
}
static bool
type_is_signed(glsl_base_type type)
{
return type == GLSL_TYPE_INT || type == GLSL_TYPE_INT64;
return type == GLSL_TYPE_INT || type == GLSL_TYPE_INT64 ||
type == GLSL_TYPE_INT16;
}
void

View File

@@ -337,10 +337,13 @@ ir_constant::clone(void *mem_ctx, struct hash_table *ht) const
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_FLOAT16:
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_BOOL:
case GLSL_TYPE_UINT64:
case GLSL_TYPE_INT64:
case GLSL_TYPE_UINT16:
case GLSL_TYPE_INT16:
case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_IMAGE:
return new(mem_ctx) ir_constant(this->type, &this->value);

View File

@@ -81,6 +81,9 @@ copy_constant_to_storage(union gl_constant_value *storage,
case GLSL_TYPE_SUBROUTINE:
case GLSL_TYPE_FUNCTION:
case GLSL_TYPE_ERROR:
case GLSL_TYPE_UINT16:
case GLSL_TYPE_INT16:
case GLSL_TYPE_FLOAT16:
/* All other types should have already been filtered by other
* paths in the caller.
*/

View File

@@ -144,8 +144,7 @@ lower_buffer_access::emit_access(void *mem_ctx,
const unsigned matrix_stride =
link_calculate_matrix_stride(matrix_type, row_major, packing);
const glsl_type *deref_type = deref->type->is_float() ?
glsl_type::float_type : glsl_type::double_type;
const glsl_type *deref_type = deref->type->get_scalar_type();
for (unsigned i = 0; i < deref->type->vector_elements; i++) {
ir_rvalue *chan_offset =