[Mesa-dev] [PATCH 11/59] glsl: Add basic ARB_gpu_shader_int64 types
Ian Romanick
idr at freedesktop.org
Wed Oct 26 00:59:17 UTC 2016
From: Dave Airlie <airlied at redhat.com>
This adds the builtins and the lexer support.
To avoid too many warnings, it adds basic support to the type in a few
other places in mesa, mostly in the trivial places.
It also adds a query to be used later for if a type is an integer 32 or 64.
Signed-off-by: Dave Airlie <airlied at redhat.com>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
---
src/compiler/builtin_type_macros.h | 10 ++++++
src/compiler/glsl/ast_to_hir.cpp | 2 ++
src/compiler/glsl/builtin_types.cpp | 12 +++++++
src/compiler/glsl/glsl_lexer.ll | 10 ++++++
src/compiler/glsl/glsl_parser.yy | 9 +++++
src/compiler/glsl/ir_clone.cpp | 2 ++
src/compiler/glsl/link_uniform_initializers.cpp | 2 ++
src/compiler/glsl_types.cpp | 45 +++++++++++++++++++++++++
src/compiler/glsl_types.h | 19 +++++++++--
src/mesa/program/ir_to_mesa.cpp | 14 ++++++++
src/mesa/state_tracker/st_glsl_types.cpp | 6 ++++
11 files changed, 129 insertions(+), 2 deletions(-)
diff --git a/src/compiler/builtin_type_macros.h b/src/compiler/builtin_type_macros.h
index 3db3b76..6a1c3c5 100644
--- a/src/compiler/builtin_type_macros.h
+++ b/src/compiler/builtin_type_macros.h
@@ -78,6 +78,16 @@ 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(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 adedcbb..02f1ec4 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -1090,6 +1090,8 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
case GLSL_TYPE_INT:
case GLSL_TYPE_BOOL:
case GLSL_TYPE_DOUBLE:
+ case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_INT64:
return new(mem_ctx) ir_expression(operation, op0, op1);
case GLSL_TYPE_ARRAY: {
diff --git a/src/compiler/glsl/builtin_types.cpp b/src/compiler/glsl/builtin_types.cpp
index 000f811..a63d736 100644
--- a/src/compiler/glsl/builtin_types.cpp
+++ b/src/compiler/glsl/builtin_types.cpp
@@ -409,5 +409,17 @@ _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
add_type(symbols, glsl_type::dmat4x2_type);
add_type(symbols, glsl_type::dmat4x3_type);
}
+
+ if (state->ARB_gpu_shader_int64_enable) {
+ add_type(symbols, glsl_type::int64_t_type);
+ add_type(symbols, glsl_type::i64vec2_type);
+ add_type(symbols, glsl_type::i64vec3_type);
+ add_type(symbols, glsl_type::i64vec4_type);
+
+ add_type(symbols, glsl_type::uint64_t_type);
+ add_type(symbols, glsl_type::u64vec2_type);
+ add_type(symbols, glsl_type::u64vec3_type);
+ add_type(symbols, glsl_type::u64vec4_type);
+ }
}
/** @} */
diff --git a/src/compiler/glsl/glsl_lexer.ll b/src/compiler/glsl/glsl_lexer.ll
index d5e5d4c..37fce3f 100644
--- a/src/compiler/glsl/glsl_lexer.ll
+++ b/src/compiler/glsl/glsl_lexer.ll
@@ -587,6 +587,16 @@ resource KEYWORD(420, 300, 0, 0, RESOURCE);
sample KEYWORD_WITH_ALT(400, 300, 400, 320, yyextra->ARB_gpu_shader5_enable || yyextra->OES_shader_multisample_interpolation_enable, SAMPLE);
subroutine KEYWORD_WITH_ALT(400, 300, 400, 0, yyextra->ARB_shader_subroutine_enable, SUBROUTINE);
+ /* Additional words for ARB_gpu_shader_int64 */
+int64_t KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, INT64);
+i64vec2 KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, I64VEC2);
+i64vec3 KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, I64VEC3);
+i64vec4 KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, I64VEC4);
+
+uint64_t KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, UINT64);
+u64vec2 KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, U64VEC2);
+u64vec3 KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, U64VEC3);
+u64vec4 KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, U64VEC4);
[_a-zA-Z][_a-zA-Z0-9]* {
struct _mesa_glsl_parse_state *state = yyextra;
diff --git a/src/compiler/glsl/glsl_parser.yy b/src/compiler/glsl/glsl_parser.yy
index 38cbd3f..6a8055f 100644
--- a/src/compiler/glsl/glsl_parser.yy
+++ b/src/compiler/glsl/glsl_parser.yy
@@ -136,6 +136,7 @@ static bool match_layout_qualifier(const char *s1, const char *s2,
%token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK DOUBLE_TOK
%token BREAK BUFFER CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
%token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4 DVEC2 DVEC3 DVEC4
+%token INT64 UINT64 I64VEC2 I64VEC3 I64VEC4 U64VEC2 U64VEC3 U64VEC4
%token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
%token NOPERSPECTIVE FLAT SMOOTH
%token MAT2X2 MAT2X3 MAT2X4
@@ -2242,6 +2243,14 @@ basic_type_specifier_nonarray:
| UIMAGE2DMS { $$ = "uimage2DMS"; }
| UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
| ATOMIC_UINT { $$ = "atomic_uint"; }
+ | INT64 { $$ = "int64_t"; }
+ | I64VEC2 { $$ = "i64vec2"; }
+ | I64VEC3 { $$ = "i64vec3"; }
+ | I64VEC4 { $$ = "i64vec4"; }
+ | UINT64 { $$ = "uint64_t"; }
+ | U64VEC2 { $$ = "u64vec2"; }
+ | U64VEC3 { $$ = "u64vec3"; }
+ | U64VEC4 { $$ = "u64vec4"; }
;
precision_qualifier:
diff --git a/src/compiler/glsl/ir_clone.cpp b/src/compiler/glsl/ir_clone.cpp
index 0e50084..99082d9 100644
--- a/src/compiler/glsl/ir_clone.cpp
+++ b/src/compiler/glsl/ir_clone.cpp
@@ -337,6 +337,8 @@ ir_constant::clone(void *mem_ctx, struct hash_table *ht) const
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_BOOL:
+ case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_INT64:
return new(mem_ctx) ir_constant(this->type, &this->value);
case GLSL_TYPE_STRUCT: {
diff --git a/src/compiler/glsl/link_uniform_initializers.cpp b/src/compiler/glsl/link_uniform_initializers.cpp
index 68ba167..0d33b92 100644
--- a/src/compiler/glsl/link_uniform_initializers.cpp
+++ b/src/compiler/glsl/link_uniform_initializers.cpp
@@ -70,6 +70,8 @@ copy_constant_to_storage(union gl_constant_value *storage,
case GLSL_TYPE_BOOL:
storage[i].b = val->value.b[i] ? boolean_true : 0;
break;
+ case GLSL_TYPE_INT64:
+ case GLSL_TYPE_UINT64:
case GLSL_TYPE_ARRAY:
case GLSL_TYPE_STRUCT:
case GLSL_TYPE_IMAGE:
diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp
index 55e5285..b123294 100644
--- a/src/compiler/glsl_types.cpp
+++ b/src/compiler/glsl_types.cpp
@@ -387,6 +387,10 @@ const glsl_type *glsl_type::get_base_type() const
return double_type;
case GLSL_TYPE_BOOL:
return bool_type;
+ case GLSL_TYPE_UINT64:
+ return uint64_t_type;
+ case GLSL_TYPE_INT64:
+ return int64_t_type;
default:
return error_type;
}
@@ -413,6 +417,10 @@ const glsl_type *glsl_type::get_scalar_type() const
return double_type;
case GLSL_TYPE_BOOL:
return bool_type;
+ case GLSL_TYPE_UINT64:
+ return uint64_t_type;
+ case GLSL_TYPE_INT64:
+ return int64_t_type;
default:
/* Handle everything else */
return type;
@@ -553,6 +561,31 @@ glsl_type::bvec(unsigned components)
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];
+}
+
+
+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];
+}
+
+const glsl_type *
glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
{
if (base_type == GLSL_TYPE_VOID)
@@ -575,6 +608,10 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
return dvec(rows);
case GLSL_TYPE_BOOL:
return bvec(rows);
+ case GLSL_TYPE_UINT64:
+ return u64vec(rows);
+ case GLSL_TYPE_INT64:
+ return i64vec(rows);
default:
return error_type;
}
@@ -1262,6 +1299,8 @@ glsl_type::component_slots() const
return this->components();
case GLSL_TYPE_DOUBLE:
+ case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_INT64:
return 2 * this->components();
case GLSL_TYPE_STRUCT:
@@ -1344,6 +1383,8 @@ glsl_type::uniform_locations() const
case GLSL_TYPE_INT:
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_DOUBLE:
+ case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_INT64:
case GLSL_TYPE_BOOL:
case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_IMAGE:
@@ -1373,6 +1414,8 @@ glsl_type::varying_count() const
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_BOOL:
+ case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_INT64:
return 1;
case GLSL_TYPE_STRUCT:
@@ -1946,6 +1989,8 @@ glsl_type::count_attribute_slots(bool is_vertex_input) const
case GLSL_TYPE_BOOL:
return this->matrix_columns;
case GLSL_TYPE_DOUBLE:
+ case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_INT64:
if (this->vector_elements > 2 && !is_vertex_input)
return this->matrix_columns * 2;
else
diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
index e5b9f3b..a23ae9a 100644
--- a/src/compiler/glsl_types.h
+++ b/src/compiler/glsl_types.h
@@ -54,6 +54,8 @@ enum glsl_base_type {
GLSL_TYPE_INT,
GLSL_TYPE_FLOAT,
GLSL_TYPE_DOUBLE,
+ GLSL_TYPE_UINT64,
+ GLSL_TYPE_INT64,
GLSL_TYPE_BOOL,
GLSL_TYPE_SAMPLER,
GLSL_TYPE_IMAGE,
@@ -69,7 +71,9 @@ enum glsl_base_type {
static inline bool glsl_base_type_is_64bit(enum glsl_base_type type)
{
- return type == GLSL_TYPE_DOUBLE;
+ return type == GLSL_TYPE_DOUBLE ||
+ type == GLSL_TYPE_UINT64 ||
+ type == GLSL_TYPE_INT64;
}
enum glsl_sampler_dim {
@@ -224,6 +228,8 @@ struct glsl_type {
static const glsl_type *ivec(unsigned components);
static const glsl_type *uvec(unsigned components);
static const glsl_type *bvec(unsigned components);
+ static const glsl_type *i64vec(unsigned components);
+ static const glsl_type *u64vec(unsigned components);
/**@}*/
/**
@@ -461,7 +467,7 @@ struct glsl_type {
*/
bool is_numeric() const
{
- return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_DOUBLE);
+ return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_INT64);
}
/**
@@ -473,6 +479,15 @@ struct glsl_type {
}
/**
+ * Query whether or not a type is a 32-bit or 64-bit integer
+ */
+ bool is_integer_32_64() const
+ {
+ return (base_type == GLSL_TYPE_UINT) || (base_type == GLSL_TYPE_INT) ||
+ (base_type == GLSL_TYPE_UINT64) || (base_type == GLSL_TYPE_INT64);
+ }
+
+ /**
* Query whether or not type is an integral type, or for struct and array
* types, contains an integral type.
*/
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index bd65df2..1d5a32f 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -532,6 +532,12 @@ type_size(const struct glsl_type *type)
return 1;
}
break;
+ case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_INT64:
+ if (type->vector_elements > 2)
+ return 2;
+ else
+ return 1;
case GLSL_TYPE_ARRAY:
assert(type->length > 0);
return type_size(type->fields.array) * type->length;
@@ -2521,11 +2527,19 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
unsigned columns = 0;
int dmul = 4 * sizeof(float);
switch (storage->type->base_type) {
+ case GLSL_TYPE_UINT64:
+ if (storage->type->vector_elements > 2)
+ dmul *= 2;
+ /* fallthrough */
case GLSL_TYPE_UINT:
assert(ctx->Const.NativeIntegers);
format = uniform_native;
columns = 1;
break;
+ case GLSL_TYPE_INT64:
+ if (storage->type->vector_elements > 2)
+ dmul *= 2;
+ /* fallthrough */
case GLSL_TYPE_INT:
format =
(ctx->Const.NativeIntegers) ? uniform_native : uniform_int_float;
diff --git a/src/mesa/state_tracker/st_glsl_types.cpp b/src/mesa/state_tracker/st_glsl_types.cpp
index 857e143..37c3164 100644
--- a/src/mesa/state_tracker/st_glsl_types.cpp
+++ b/src/mesa/state_tracker/st_glsl_types.cpp
@@ -67,6 +67,12 @@ st_glsl_attrib_type_size(const struct glsl_type *type, bool is_vs_input)
return 2;
}
break;
+ case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_INT64:
+ if (type->vector_elements <= 2 || is_vs_input)
+ return 1;
+ else
+ return 2;
case GLSL_TYPE_ARRAY:
assert(type->length > 0);
return st_glsl_attrib_type_size(type->fields.array, is_vs_input) * type->length;
--
2.5.5
More information about the mesa-dev
mailing list