[Mesa-dev] [PATCH v4 01/44] glsl: Add 16-bit types
From: Eduardo Lima Mitev 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). Signed-off-by: Jose Maria Casanova Crespo Signed-off-by: Eduardo Lima Signed-off-by: Alejandro Piñeiro Reviewed-by: Jason Ekstrand Reviewed-by: Nicolai Hähnle --- src/compiler/builtin_type_macros.h | 26 +++ src/compiler/glsl/ast_to_hir.cpp| 3 + src/compiler/glsl/glsl_to_nir.cpp | 6 +- src/compiler/glsl/ir_clone.cpp | 3 + src/compiler/glsl/link_uniform_initializers.cpp | 3 + src/compiler/glsl/lower_buffer_access.cpp | 3 +- src/compiler/glsl_types.cpp | 93 - src/compiler/glsl_types.h | 10 ++- src/mesa/program/ir_to_mesa.cpp | 6 ++ 9 files changed, 145 insertions(+), 8 deletions(-) diff --git a/src/compiler/builtin_type_macros.h b/src/compiler/builtin_type_macros.h index a275617b34..e3a1cd29c8 100644 --- a/src/compiler/builtin_type_macros.h +++ b/src/compiler/builtin_type_macros.h @@ -62,6 +62,22 @@ DECL_TYPE(mat3x4, GL_FLOAT_MAT3x4, GLSL_TYPE_FLOAT, 4, 3) DECL_TYPE(mat4x2, GL_FLOAT_MAT4x2, GLSL_TYPE_FLOAT, 2, 4) DECL_TYPE(mat4x3, GL_FLOAT_MAT4x3, GLSL_TYPE_FLOAT, 3, 4) +DECL_TYPE(float16_t, GL_FLOAT16_NV,GLSL_TYPE_FLOAT16, 1, 1) +DECL_TYPE(f16vec2, GL_FLOAT16_VEC2_NV, GLSL_TYPE_FLOAT16, 2, 1) +DECL_TYPE(f16vec3, GL_FLOAT16_VEC3_NV, GLSL_TYPE_FLOAT16, 3, 1) +DECL_TYPE(f16vec4, GL_FLOAT16_VEC4_NV, GLSL_TYPE_FLOAT16, 4, 1) + +DECL_TYPE(f16mat2, GL_FLOAT16_MAT2_AMD, GLSL_TYPE_FLOAT16, 2, 2) +DECL_TYPE(f16mat3, GL_FLOAT16_MAT3_AMD, GLSL_TYPE_FLOAT16, 3, 3) +DECL_TYPE(f16mat4, GL_FLOAT16_MAT4_AMD, GLSL_TYPE_FLOAT16, 4, 4) + +DECL_TYPE(f16mat2x3, GL_FLOAT16_MAT2x3_AMD, GLSL_TYPE_FLOAT16, 3, 2) +DECL_TYPE(f16mat2x4, GL_FLOAT16_MAT2x4_AMD, GLSL_TYPE_FLOAT16, 4, 2) +DECL_TYPE(f16mat3x2, GL_FLOAT16_MAT3x2_AMD, GLSL_TYPE_FLOAT16, 2, 3) +DECL_TYPE(f16mat3x4, GL_FLOAT16_MAT3x4_AMD, GLSL_TYPE_FLOAT16, 4, 3) +DECL_TYPE(f16mat4x2, GL_FLOAT16_MAT4x2_AMD, GLSL_TYPE_FLOAT16, 2, 4) +DECL_TYPE(f16mat4x3, GL_FLOAT16_MAT4x3_AMD, GLSL_TYPE_FLOAT16, 3, 4) + DECL_TYPE(double, GL_DOUBLE,GLSL_TYPE_DOUBLE, 1, 1) DECL_TYPE(dvec2, GL_DOUBLE_VEC2, GLSL_TYPE_DOUBLE, 2, 1) DECL_TYPE(dvec3, GL_DOUBLE_VEC3, GLSL_TYPE_DOUBLE, 3, 1) @@ -88,6 +104,16 @@ DECL_TYPE(u64vec2, GL_UNSIGNED_INT64_VEC2_ARB, GLSL_TYPE_UINT64, 2, 1) DECL_TYPE(u64vec3, GL_UNSIGNED_INT64_VEC3_ARB, GLSL_TYPE_UINT64, 3, 1) DECL_TYPE(u64vec4, GL_UNSIGNED_INT64_VEC4_ARB, GLSL_TYPE_UINT64, 4, 1) +DECL_TYPE(int16_t, GL_INT16_NV, GLSL_TYPE_INT16, 1, 1) +DECL_TYPE(i16vec2, GL_INT16_VEC2_NV, GLSL_TYPE_INT16, 2, 1) +DECL_TYPE(i16vec3, GL_INT16_VEC3_NV, GLSL_TYPE_INT16, 3, 1) +DECL_TYPE(i16vec4, GL_INT16_VEC4_NV, GLSL_TYPE_INT16, 4, 1) + +DECL_TYPE(uint16_t, GL_UNSIGNED_INT16_NV, GLSL_TYPE_UINT16, 1, 1) +DECL_TYPE(u16vec2, GL_UNSIGNED_INT16_VEC2_NV, GLSL_TYPE_UINT16, 2, 1) +DECL_TYPE(u16vec3, GL_UNSIGNED_INT16_VEC3_NV, GLSL_TYPE_UINT16, 3, 1) +DECL_TYPE(u16vec4, GL_UNSIGNED_INT16_VEC4_NV, GLSL_TYPE_UINT16, 4, 1) + DECL_TYPE(sampler, GL_SAMPLER_1D, GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_VOID) DECL_TYPE(sampler1D, GL_SAMPLER_1D, GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT) DECL_TYPE(sampler2D, GL_SAMPLER_2D, GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT) diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp index 5cdeb94720..7abb8199e1 100644 --- a/src/compiler/glsl/ast_to_hir.cpp +++ b/src/compiler/glsl/ast_to_hir.cpp @@ -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
Re: [Mesa-dev] [PATCH v4 01/44] glsl: Add 16-bit types
On Thu, Nov 30, 2017 at 03:07:45AM +0100, Jose Maria Casanova Crespo wrote: > From: Eduardo Lima Mitev Just a few style nits, see below. > > 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). > > Signed-off-by: Jose Maria Casanova Crespo > Signed-off-by: Eduardo Lima > Signed-off-by: Alejandro Piñeiro > Reviewed-by: Jason Ekstrand > Reviewed-by: Nicolai Hähnle > --- > src/compiler/builtin_type_macros.h | 26 +++ > src/compiler/glsl/ast_to_hir.cpp| 3 + > src/compiler/glsl/glsl_to_nir.cpp | 6 +- > src/compiler/glsl/ir_clone.cpp | 3 + > src/compiler/glsl/link_uniform_initializers.cpp | 3 + > src/compiler/glsl/lower_buffer_access.cpp | 3 +- > src/compiler/glsl_types.cpp | 93 > - > src/compiler/glsl_types.h | 10 ++- > src/mesa/program/ir_to_mesa.cpp | 6 ++ > 9 files changed, 145 insertions(+), 8 deletions(-) > > diff --git a/src/compiler/builtin_type_macros.h > b/src/compiler/builtin_type_macros.h > index a275617b34..e3a1cd29c8 100644 > --- a/src/compiler/builtin_type_macros.h > +++ b/src/compiler/builtin_type_macros.h > @@ -62,6 +62,22 @@ DECL_TYPE(mat3x4, GL_FLOAT_MAT3x4, GLSL_TYPE_FLOAT, 4, 3) > DECL_TYPE(mat4x2, GL_FLOAT_MAT4x2, GLSL_TYPE_FLOAT, 2, 4) > DECL_TYPE(mat4x3, GL_FLOAT_MAT4x3, GLSL_TYPE_FLOAT, 3, 4) > > +DECL_TYPE(float16_t, GL_FLOAT16_NV,GLSL_TYPE_FLOAT16, 1, 1) > +DECL_TYPE(f16vec2, GL_FLOAT16_VEC2_NV, GLSL_TYPE_FLOAT16, 2, 1) > +DECL_TYPE(f16vec3, GL_FLOAT16_VEC3_NV, GLSL_TYPE_FLOAT16, 3, 1) > +DECL_TYPE(f16vec4, GL_FLOAT16_VEC4_NV, GLSL_TYPE_FLOAT16, 4, 1) > + > +DECL_TYPE(f16mat2, GL_FLOAT16_MAT2_AMD, GLSL_TYPE_FLOAT16, 2, 2) > +DECL_TYPE(f16mat3, GL_FLOAT16_MAT3_AMD, GLSL_TYPE_FLOAT16, 3, 3) > +DECL_TYPE(f16mat4, GL_FLOAT16_MAT4_AMD, GLSL_TYPE_FLOAT16, 4, 4) > + > +DECL_TYPE(f16mat2x3, GL_FLOAT16_MAT2x3_AMD, GLSL_TYPE_FLOAT16, 3, 2) > +DECL_TYPE(f16mat2x4, GL_FLOAT16_MAT2x4_AMD, GLSL_TYPE_FLOAT16, 4, 2) > +DECL_TYPE(f16mat3x2, GL_FLOAT16_MAT3x2_AMD, GLSL_TYPE_FLOAT16, 2, 3) > +DECL_TYPE(f16mat3x4, GL_FLOAT16_MAT3x4_AMD, GLSL_TYPE_FLOAT16, 4, 3) > +DECL_TYPE(f16mat4x2, GL_FLOAT16_MAT4x2_AMD, GLSL_TYPE_FLOAT16, 2, 4) > +DECL_TYPE(f16mat4x3, GL_FLOAT16_MAT4x3_AMD, GLSL_TYPE_FLOAT16, 3, 4) > + > DECL_TYPE(double, GL_DOUBLE,GLSL_TYPE_DOUBLE, 1, 1) > DECL_TYPE(dvec2, GL_DOUBLE_VEC2, GLSL_TYPE_DOUBLE, 2, 1) > DECL_TYPE(dvec3, GL_DOUBLE_VEC3, GLSL_TYPE_DOUBLE, 3, 1) > @@ -88,6 +104,16 @@ DECL_TYPE(u64vec2, GL_UNSIGNED_INT64_VEC2_ARB, > GLSL_TYPE_UINT64, 2, 1) > DECL_TYPE(u64vec3, GL_UNSIGNED_INT64_VEC3_ARB, GLSL_TYPE_UINT64, 3, 1) > DECL_TYPE(u64vec4, GL_UNSIGNED_INT64_VEC4_ARB, GLSL_TYPE_UINT64, 4, 1) > > +DECL_TYPE(int16_t, GL_INT16_NV, GLSL_TYPE_INT16, 1, 1) > +DECL_TYPE(i16vec2, GL_INT16_VEC2_NV, GLSL_TYPE_INT16, 2, 1) > +DECL_TYPE(i16vec3, GL_INT16_VEC3_NV, GLSL_TYPE_INT16, 3, 1) > +DECL_TYPE(i16vec4, GL_INT16_VEC4_NV, GLSL_TYPE_INT16, 4, 1) > + > +DECL_TYPE(uint16_t, GL_UNSIGNED_INT16_NV, GLSL_TYPE_UINT16, 1, 1) > +DECL_TYPE(u16vec2, GL_UNSIGNED_INT16_VEC2_NV, GLSL_TYPE_UINT16, 2, 1) > +DECL_TYPE(u16vec3, GL_UNSIGNED_INT16_VEC3_NV, GLSL_TYPE_UINT16, 3, 1) > +DECL_TYPE(u16vec4, GL_UNSIGNED_INT16_VEC4_NV, GLSL_TYPE_UINT16, 4, 1) > + > DECL_TYPE(sampler, GL_SAMPLER_1D, > GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_VOID) > DECL_TYPE(sampler1D, GL_SAMPLER_1D, > GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT) > DECL_TYPE(sampler2D, GL_SAMPLER_2D, > GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT) > diff --git a/src/compiler/glsl/ast_to_hir.cpp > b/src/compiler/glsl/ast_to_hir.cpp > index 5cdeb94720..7abb8199e1 100644 > --- a/src/compiler/glsl/ast_to_hir.cpp > +++ b/src/compiler/glsl/ast_t
Re: [Mesa-dev] [PATCH v4 01/44] glsl: Add 16-bit types
El 30/11/17 a las 10:25, Pohjolainen, Topi escribió: > On Thu, Nov 30, 2017 at 03:07:45AM +0100, Jose Maria Casanova Crespo wrote: >> From: Eduardo Lima Mitev > Just a few style nits, see below. > >> 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). >> >> Signed-off-by: Jose Maria Casanova Crespo >> Signed-off-by: Eduardo Lima >> Signed-off-by: Alejandro Piñeiro >> Reviewed-by: Jason Ekstrand >> Reviewed-by: Nicolai Hähnle >> --- >> src/compiler/builtin_type_macros.h | 26 +++ >> src/compiler/glsl/ast_to_hir.cpp| 3 + >> src/compiler/glsl/glsl_to_nir.cpp | 6 +- >> src/compiler/glsl/ir_clone.cpp | 3 + >> src/compiler/glsl/link_uniform_initializers.cpp | 3 + >> src/compiler/glsl/lower_buffer_access.cpp | 3 +- >> src/compiler/glsl_types.cpp | 93 >> - >> src/compiler/glsl_types.h | 10 ++- >> src/mesa/program/ir_to_mesa.cpp | 6 ++ >> 9 files changed, 145 insertions(+), 8 deletions(-) >> >> diff --git a/src/compiler/builtin_type_macros.h >> b/src/compiler/builtin_type_macros.h >> index a275617b34..e3a1cd29c8 100644 >> --- a/src/compiler/builtin_type_macros.h >> +++ b/src/compiler/builtin_type_macros.h >> @@ -62,6 +62,22 @@ DECL_TYPE(mat3x4, GL_FLOAT_MAT3x4, GLSL_TYPE_FLOAT, 4, 3) >> DECL_TYPE(mat4x2, GL_FLOAT_MAT4x2, GLSL_TYPE_FLOAT, 2, 4) >> DECL_TYPE(mat4x3, GL_FLOAT_MAT4x3, GLSL_TYPE_FLOAT, 3, 4) >> >> +DECL_TYPE(float16_t, GL_FLOAT16_NV,GLSL_TYPE_FLOAT16, 1, 1) >> +DECL_TYPE(f16vec2, GL_FLOAT16_VEC2_NV, GLSL_TYPE_FLOAT16, 2, 1) >> +DECL_TYPE(f16vec3, GL_FLOAT16_VEC3_NV, GLSL_TYPE_FLOAT16, 3, 1) >> +DECL_TYPE(f16vec4, GL_FLOAT16_VEC4_NV, GLSL_TYPE_FLOAT16, 4, 1) >> + >> +DECL_TYPE(f16mat2, GL_FLOAT16_MAT2_AMD, GLSL_TYPE_FLOAT16, 2, 2) >> +DECL_TYPE(f16mat3, GL_FLOAT16_MAT3_AMD, GLSL_TYPE_FLOAT16, 3, 3) >> +DECL_TYPE(f16mat4, GL_FLOAT16_MAT4_AMD, GLSL_TYPE_FLOAT16, 4, 4) >> + >> +DECL_TYPE(f16mat2x3, GL_FLOAT16_MAT2x3_AMD, GLSL_TYPE_FLOAT16, 3, 2) >> +DECL_TYPE(f16mat2x4, GL_FLOAT16_MAT2x4_AMD, GLSL_TYPE_FLOAT16, 4, 2) >> +DECL_TYPE(f16mat3x2, GL_FLOAT16_MAT3x2_AMD, GLSL_TYPE_FLOAT16, 2, 3) >> +DECL_TYPE(f16mat3x4, GL_FLOAT16_MAT3x4_AMD, GLSL_TYPE_FLOAT16, 4, 3) >> +DECL_TYPE(f16mat4x2, GL_FLOAT16_MAT4x2_AMD, GLSL_TYPE_FLOAT16, 2, 4) >> +DECL_TYPE(f16mat4x3, GL_FLOAT16_MAT4x3_AMD, GLSL_TYPE_FLOAT16, 3, 4) >> + >> DECL_TYPE(double, GL_DOUBLE,GLSL_TYPE_DOUBLE, 1, 1) >> DECL_TYPE(dvec2, GL_DOUBLE_VEC2, GLSL_TYPE_DOUBLE, 2, 1) >> DECL_TYPE(dvec3, GL_DOUBLE_VEC3, GLSL_TYPE_DOUBLE, 3, 1) >> @@ -88,6 +104,16 @@ DECL_TYPE(u64vec2, GL_UNSIGNED_INT64_VEC2_ARB, >> GLSL_TYPE_UINT64, 2, 1) >> DECL_TYPE(u64vec3, GL_UNSIGNED_INT64_VEC3_ARB, GLSL_TYPE_UINT64, 3, 1) >> DECL_TYPE(u64vec4, GL_UNSIGNED_INT64_VEC4_ARB, GLSL_TYPE_UINT64, 4, 1) >> >> +DECL_TYPE(int16_t, GL_INT16_NV, GLSL_TYPE_INT16, 1, 1) >> +DECL_TYPE(i16vec2, GL_INT16_VEC2_NV, GLSL_TYPE_INT16, 2, 1) >> +DECL_TYPE(i16vec3, GL_INT16_VEC3_NV, GLSL_TYPE_INT16, 3, 1) >> +DECL_TYPE(i16vec4, GL_INT16_VEC4_NV, GLSL_TYPE_INT16, 4, 1) >> + >> +DECL_TYPE(uint16_t, GL_UNSIGNED_INT16_NV, GLSL_TYPE_UINT16, 1, 1) >> +DECL_TYPE(u16vec2, GL_UNSIGNED_INT16_VEC2_NV, GLSL_TYPE_UINT16, 2, 1) >> +DECL_TYPE(u16vec3, GL_UNSIGNED_INT16_VEC3_NV, GLSL_TYPE_UINT16, 3, 1) >> +DECL_TYPE(u16vec4, GL_UNSIGNED_INT16_VEC4_NV, GLSL_TYPE_UINT16, 4, 1) >> + >> DECL_TYPE(sampler, GL_SAMPLER_1D, >> GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_VOID) >> DECL_TYPE(sampler1D, GL_SAMPLER_1D, >> GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT) >> DECL_TYPE(sampler2D, GL_SAMPLER_2D, >> GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT) >> diff --git a/src/compiler/glsl/ast_to_hir.cpp >> b