From: Rob Clark Date: Mon, 12 Mar 2018 18:54:56 +0000 (-0400) Subject: glsl_types: refactor/prep for vec8/vec16 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f407edf3407396379e16b0be74b8d3b85d2ad7f0;p=mesa.git glsl_types: refactor/prep for vec8/vec16 Refactor things so there isn't so much typing involved to add new things. Also drops a pointless conditional (out of bounds rows or columns already returns error_type in all paths.. might as well drop it rather than make the check more convoluted in the next patch by adding the vec8/vec16 case). Signed-off-by: Rob Clark Reviewed-by: Timothy Arceri --- diff --git a/src/compiler/builtin_type_macros.h b/src/compiler/builtin_type_macros.h index 807691824d3..dd8204a1981 100644 --- a/src/compiler/builtin_type_macros.h +++ b/src/compiler/builtin_type_macros.h @@ -31,25 +31,24 @@ DECL_TYPE(error, GL_INVALID_ENUM, GLSL_TYPE_ERROR, 0, 0) DECL_TYPE(void, GL_INVALID_ENUM, GLSL_TYPE_VOID, 0, 0) -DECL_TYPE(bool, GL_BOOL, GLSL_TYPE_BOOL, 1, 1) -DECL_TYPE(bvec2, GL_BOOL_VEC2, GLSL_TYPE_BOOL, 2, 1) -DECL_TYPE(bvec3, GL_BOOL_VEC3, GLSL_TYPE_BOOL, 3, 1) -DECL_TYPE(bvec4, GL_BOOL_VEC4, GLSL_TYPE_BOOL, 4, 1) - -DECL_TYPE(int, GL_INT, GLSL_TYPE_INT, 1, 1) -DECL_TYPE(ivec2, GL_INT_VEC2, GLSL_TYPE_INT, 2, 1) -DECL_TYPE(ivec3, GL_INT_VEC3, GLSL_TYPE_INT, 3, 1) -DECL_TYPE(ivec4, GL_INT_VEC4, GLSL_TYPE_INT, 4, 1) - -DECL_TYPE(uint, GL_UNSIGNED_INT, GLSL_TYPE_UINT, 1, 1) -DECL_TYPE(uvec2, GL_UNSIGNED_INT_VEC2, GLSL_TYPE_UINT, 2, 1) -DECL_TYPE(uvec3, GL_UNSIGNED_INT_VEC3, GLSL_TYPE_UINT, 3, 1) -DECL_TYPE(uvec4, GL_UNSIGNED_INT_VEC4, GLSL_TYPE_UINT, 4, 1) - -DECL_TYPE(float, GL_FLOAT, GLSL_TYPE_FLOAT, 1, 1) -DECL_TYPE(vec2, GL_FLOAT_VEC2, GLSL_TYPE_FLOAT, 2, 1) -DECL_TYPE(vec3, GL_FLOAT_VEC3, GLSL_TYPE_FLOAT, 3, 1) -DECL_TYPE(vec4, GL_FLOAT_VEC4, GLSL_TYPE_FLOAT, 4, 1) +#define DECL_VEC_TYPE(stype, vtype, btype, etype, ...) \ + DECL_TYPE(stype, etype ##__VA_ARGS__, btype, 1, 1) \ + DECL_TYPE(vtype ## 2, etype ##_VEC2 ##__VA_ARGS__, btype, 2, 1) \ + DECL_TYPE(vtype ## 3, etype ##_VEC3 ##__VA_ARGS__, btype, 3, 1) \ + DECL_TYPE(vtype ## 4, etype ##_VEC4 ##__VA_ARGS__, btype, 4, 1) + +DECL_VEC_TYPE(bool, bvec, GLSL_TYPE_BOOL, GL_BOOL) +DECL_VEC_TYPE(int, ivec, GLSL_TYPE_INT, GL_INT) +DECL_VEC_TYPE(uint, uvec, GLSL_TYPE_UINT, GL_UNSIGNED_INT) +DECL_VEC_TYPE(float, vec, GLSL_TYPE_FLOAT, GL_FLOAT) +DECL_VEC_TYPE(float16_t, f16vec, GLSL_TYPE_FLOAT16, GL_FLOAT16, _NV) +DECL_VEC_TYPE(double, dvec, GLSL_TYPE_DOUBLE, GL_DOUBLE) +DECL_VEC_TYPE(int64_t, i64vec, GLSL_TYPE_INT64, GL_INT64, _ARB) +DECL_VEC_TYPE(uint64_t, u64vec, GLSL_TYPE_UINT64, GL_UNSIGNED_INT64, _ARB) +DECL_VEC_TYPE(int16_t, i16vec, GLSL_TYPE_INT16, GL_INT16, _NV) +DECL_VEC_TYPE(uint16_t, u16vec, GLSL_TYPE_UINT16, GL_UNSIGNED_INT16, _NV) +DECL_VEC_TYPE(int8_t, i8vec, GLSL_TYPE_INT8, GL_INT8, _NV) +DECL_VEC_TYPE(uint8_t, u8vec, GLSL_TYPE_UINT8, GL_UNSIGNED_INT8, _NV) DECL_TYPE(mat2, GL_FLOAT_MAT2, GLSL_TYPE_FLOAT, 2, 2) DECL_TYPE(mat3, GL_FLOAT_MAT3, GLSL_TYPE_FLOAT, 3, 3) @@ -62,11 +61,6 @@ 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) @@ -78,11 +72,6 @@ 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) -DECL_TYPE(dvec4, GL_DOUBLE_VEC4, GLSL_TYPE_DOUBLE, 4, 1) - DECL_TYPE(dmat2, GL_DOUBLE_MAT2, GLSL_TYPE_DOUBLE, 2, 2) DECL_TYPE(dmat3, GL_DOUBLE_MAT3, GLSL_TYPE_DOUBLE, 3, 3) DECL_TYPE(dmat4, GL_DOUBLE_MAT4, GLSL_TYPE_DOUBLE, 4, 4) @@ -94,36 +83,6 @@ DECL_TYPE(dmat3x4, GL_DOUBLE_MAT3x4, GLSL_TYPE_DOUBLE, 4, 3) DECL_TYPE(dmat4x2, GL_DOUBLE_MAT4x2, GLSL_TYPE_DOUBLE, 2, 4) DECL_TYPE(dmat4x3, GL_DOUBLE_MAT4x3, GLSL_TYPE_DOUBLE, 3, 4) -DECL_TYPE(int64_t, GL_INT64_ARB, GLSL_TYPE_INT64, 1, 1) -DECL_TYPE(i64vec2, GL_INT64_VEC2_ARB, GLSL_TYPE_INT64, 2, 1) -DECL_TYPE(i64vec3, GL_INT64_VEC3_ARB, GLSL_TYPE_INT64, 3, 1) -DECL_TYPE(i64vec4, GL_INT64_VEC4_ARB, GLSL_TYPE_INT64, 4, 1) - -DECL_TYPE(uint64_t, GL_UNSIGNED_INT64_ARB, GLSL_TYPE_UINT64, 1, 1) -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(int8_t, GL_INT8_NV, GLSL_TYPE_INT8, 1, 1) -DECL_TYPE(i8vec2, GL_INT8_VEC2_NV, GLSL_TYPE_INT8, 2, 1) -DECL_TYPE(i8vec3, GL_INT8_VEC3_NV, GLSL_TYPE_INT8, 3, 1) -DECL_TYPE(i8vec4, GL_INT8_VEC4_NV, GLSL_TYPE_INT8, 4, 1) - -DECL_TYPE(uint8_t, GL_UNSIGNED_INT8_NV, GLSL_TYPE_UINT8, 1, 1) -DECL_TYPE(u8vec2, GL_UNSIGNED_INT8_VEC2_NV, GLSL_TYPE_UINT8, 2, 1) -DECL_TYPE(u8vec3, GL_UNSIGNED_INT8_VEC3_NV, GLSL_TYPE_UINT8, 3, 1) -DECL_TYPE(u8vec4, GL_UNSIGNED_INT8_VEC4_NV, GLSL_TYPE_UINT8, 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_types.cpp b/src/compiler/glsl_types.cpp index a73caa908bf..8b18f2f3210 100644 --- a/src/compiler/glsl_types.cpp +++ b/src/compiler/glsl_types.cpp @@ -493,155 +493,98 @@ glsl_type::glsl_type(const glsl_type *array, unsigned length) : this->name = n; } - const glsl_type * -glsl_type::vec(unsigned components) +glsl_type::vec(unsigned components, const glsl_type *const ts[]) { - if (components == 0 || components > 4) + unsigned n = components; + + if (n == 0 || n > 4) return error_type; - static const glsl_type *const ts[] = { - float_type, vec2_type, vec3_type, vec4_type - }; - return ts[components - 1]; + return ts[n - 1]; } +#define VECN(components, sname, vname) ({ \ + static const glsl_type *const ts[] = { \ + sname ## _type, vname ## 2_type, \ + vname ## 3_type, vname ## 4_type, \ + }; \ + glsl_type::vec(components, ts); \ + }) + const glsl_type * -glsl_type::f16vec(unsigned components) +glsl_type::vec(unsigned components) { - if (components == 0 || components > 4) - return error_type; + return VECN(components, float, vec); +} - static const glsl_type *const ts[] = { - float16_t_type, f16vec2_type, f16vec3_type, f16vec4_type - }; - return ts[components - 1]; +const glsl_type * +glsl_type::f16vec(unsigned components) +{ + return VECN(components, float16_t, f16vec); } const glsl_type * glsl_type::dvec(unsigned components) { - if (components == 0 || components > 4) - return error_type; - - static const glsl_type *const ts[] = { - double_type, dvec2_type, dvec3_type, dvec4_type - }; - return ts[components - 1]; + return VECN(components, double, dvec); } const glsl_type * glsl_type::ivec(unsigned components) { - if (components == 0 || components > 4) - return error_type; - - static const glsl_type *const ts[] = { - int_type, ivec2_type, ivec3_type, ivec4_type - }; - return ts[components - 1]; + return VECN(components, int, ivec); } - const glsl_type * glsl_type::uvec(unsigned components) { - if (components == 0 || components > 4) - return error_type; - - static const glsl_type *const ts[] = { - uint_type, uvec2_type, uvec3_type, uvec4_type - }; - return ts[components - 1]; + return VECN(components, uint, uvec); } - const glsl_type * glsl_type::bvec(unsigned components) { - if (components == 0 || components > 4) - return error_type; - - static const glsl_type *const ts[] = { - bool_type, bvec2_type, bvec3_type, bvec4_type - }; - return ts[components - 1]; + return VECN(components, bool, bvec); } - const glsl_type * glsl_type::i64vec(unsigned components) { - if (components == 0 || components > 4) - return error_type; - - static const glsl_type *const ts[] = { - int64_t_type, i64vec2_type, i64vec3_type, i64vec4_type - }; - return ts[components - 1]; + return VECN(components, int64_t, i64vec); } const glsl_type * glsl_type::u64vec(unsigned components) { - if (components == 0 || components > 4) - return error_type; - - static const glsl_type *const ts[] = { - uint64_t_type, u64vec2_type, u64vec3_type, u64vec4_type - }; - return ts[components - 1]; + return VECN(components, uint64_t, u64vec); } const glsl_type * glsl_type::i16vec(unsigned components) { - if (components == 0 || components > 4) - return error_type; - - static const glsl_type *const ts[] = { - int16_t_type, i16vec2_type, i16vec3_type, i16vec4_type - }; - return ts[components - 1]; + return VECN(components, int16_t, i16vec); } const glsl_type * glsl_type::u16vec(unsigned components) { - if (components == 0 || components > 4) - return error_type; - - static const glsl_type *const ts[] = { - uint16_t_type, u16vec2_type, u16vec3_type, u16vec4_type - }; - return ts[components - 1]; + return VECN(components, uint16_t, u16vec); } const glsl_type * glsl_type::i8vec(unsigned components) { - if (components == 0 || components > 4) - return error_type; - - static const glsl_type *const ts[] = { - int8_t_type, i8vec2_type, i8vec3_type, i8vec4_type - }; - return ts[components - 1]; + return VECN(components, int8_t, i8vec); } const glsl_type * glsl_type::u8vec(unsigned components) { - if (components == 0 || components > 4) - return error_type; - - static const glsl_type *const ts[] = { - uint8_t_type, u8vec2_type, u8vec3_type, u8vec4_type - }; - return ts[components - 1]; + return VECN(components, uint8_t, u8vec); } const glsl_type * @@ -650,9 +593,6 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns) if (base_type == GLSL_TYPE_VOID) return void_type; - if ((rows < 1) || (rows > 4) || (columns < 1) || (columns > 4)) - return error_type; - /* Treat GLSL vectors as Nx1 matrices. */ if (columns == 1) { diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h index 6982d52e392..88f987fabee 100644 --- a/src/compiler/glsl_types.h +++ b/src/compiler/glsl_types.h @@ -223,6 +223,7 @@ public: * Convenience accessors for vector types (shorter than get_instance()). * @{ */ + static const glsl_type *vec(unsigned components, const glsl_type *const ts[]); static const glsl_type *vec(unsigned components); static const glsl_type *f16vec(unsigned components); static const glsl_type *dvec(unsigned components);