mesa: Add support for 64-bit integer uniforms
authorDave Airlie <airlied@redhat.com>
Wed, 8 Jun 2016 23:20:19 +0000 (09:20 +1000)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 20 Jan 2017 23:41:23 +0000 (15:41 -0800)
This hooks up the API to the internals for 64-bit integer uniforms.

v2: update to use non-strict aliased alternatives

Signed-off-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
src/mesa/main/uniform_query.cpp
src/mesa/main/uniforms.c

index 145eff01756cc9918911ceb9c26f417d43d0cb71..f505986fcfc31cb4b2bbf9edc21db24390895b87 100644 (file)
@@ -332,7 +332,8 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
         &uni->storage[offset * elements * dmul];
 
       assert(returnType == GLSL_TYPE_FLOAT || returnType == GLSL_TYPE_INT ||
-             returnType == GLSL_TYPE_UINT || returnType == GLSL_TYPE_DOUBLE);
+             returnType == GLSL_TYPE_UINT || returnType == GLSL_TYPE_DOUBLE ||
+             returnType == GLSL_TYPE_UINT64 || returnType == GLSL_TYPE_INT64);
 
       /* doubles have a different size than the other 3 types */
       unsigned bytes = sizeof(src[0]) * elements * rmul;
@@ -354,7 +355,11 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
              (uni->type->base_type == GLSL_TYPE_INT
               || uni->type->base_type == GLSL_TYPE_UINT
                || uni->type->base_type == GLSL_TYPE_SAMPLER
-               || uni->type->base_type == GLSL_TYPE_IMAGE))) {
+               || uni->type->base_type == GLSL_TYPE_IMAGE))
+          || ((returnType == GLSL_TYPE_UINT64 ||
+               returnType == GLSL_TYPE_INT64 ) &&
+              (uni->type->base_type == GLSL_TYPE_UINT64 ||
+               uni->type->base_type == GLSL_TYPE_INT64))) {
         memcpy(paramsOut, src, bytes);
       } else {
         union gl_constant_value *const dst =
@@ -387,6 +392,18 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
                   dst[didx].f = tmp;
                  break;
                }
+               case GLSL_TYPE_UINT64: {
+                  uint64_t tmp;
+                  memcpy(&tmp, &src[sidx].u, sizeof(tmp));
+                  dst[didx].f = tmp;
+                  break;
+               }
+               case GLSL_TYPE_INT64: {
+                  uint64_t tmp;
+                  memcpy(&tmp, &src[sidx].i, sizeof(tmp));
+                  dst[didx].f = tmp;
+                  break;
+               }
               default:
                  assert(!"Should not get here.");
                  break;
@@ -416,6 +433,22 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
                   memcpy(&dst[didx].f, &tmp, sizeof(tmp));
                  break;
                }
+               case GLSL_TYPE_UINT64: {
+                  uint64_t tmpu;
+                  double tmp;
+                  memcpy(&tmpu, &src[sidx].u, sizeof(tmpu));
+                  tmp = tmpu;
+                  memcpy(&dst[didx].f, &tmp, sizeof(tmp));
+                  break;
+               }
+               case GLSL_TYPE_INT64: {
+                  int64_t tmpi;
+                  double tmp;
+                  memcpy(&tmpi, &src[sidx].i, sizeof(tmpi));
+                  tmp = tmpi;
+                  memcpy(&dst[didx].f, &tmp, sizeof(tmp));
+                  break;
+               }
               default:
                  assert(!"Should not get here.");
                  break;
@@ -453,12 +486,45 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
                   dst[didx].i = IROUNDD(tmp);
                  break;
                }
+               case GLSL_TYPE_UINT64: {
+                  uint64_t tmp;
+                  memcpy(&tmp, &src[sidx].u, sizeof(tmp));
+                  dst[didx].i = tmp;
+                  break;
+               }
+               case GLSL_TYPE_INT64: {
+                  int64_t tmp;
+                  memcpy(&tmp, &src[sidx].i, sizeof(tmp));
+                  dst[didx].i = tmp;
+                  break;
+               }
               default:
                  assert(!"Should not get here.");
                  break;
               }
               break;
-
+            case GLSL_TYPE_INT64:
+            case GLSL_TYPE_UINT64:
+               switch (uni->type->base_type) {
+               case GLSL_TYPE_UINT:
+                  *(int64_t *)&dst[didx].u = (int64_t) src[sidx].u;
+                  break;
+               case GLSL_TYPE_INT:
+               case GLSL_TYPE_SAMPLER:
+               case GLSL_TYPE_IMAGE:
+                  *(int64_t *)&dst[didx].u = (int64_t) src[sidx].i;
+                  break;
+               case GLSL_TYPE_BOOL:
+                  *(int64_t *)&dst[didx].u = src[sidx].i ? 1.0f : 0.0f;
+                  break;
+               case GLSL_TYPE_FLOAT:
+                  *(int64_t *)&dst[didx].u = (int64_t) src[sidx].f;
+                  break;
+               default:
+                  assert(!"Should not get here.");
+                  break;
+               }
+               break;
            default:
               assert(!"Should not get here.");
               break;
@@ -496,6 +562,12 @@ log_uniform(const void *values, enum glsl_base_type basicType,
       case GLSL_TYPE_INT:
         printf("%d ", v[i].i);
         break;
+      case GLSL_TYPE_UINT64:
+         printf("%lu ", *(uint64_t* )&v[i * 2].u);
+         break;
+      case GLSL_TYPE_INT64:
+         printf("%ld ", *(int64_t* )&v[i * 2].u);
+         break;
       case GLSL_TYPE_FLOAT:
         printf("%g ", v[i].f);
         break;
@@ -667,6 +739,10 @@ glsl_type_name(enum glsl_base_type type)
       return "float";
    case GLSL_TYPE_DOUBLE:
       return "double";
+   case GLSL_TYPE_UINT64:
+      return "uint64";
+   case GLSL_TYPE_INT64:
+      return "int64";
    case GLSL_TYPE_BOOL:
       return "bool";
    case GLSL_TYPE_SAMPLER:
index b3d640ed20d8933720bbb7c989be816edc4bac5e..29a11551348d47c15bc29767570544016b055c6c 100644 (file)
@@ -900,21 +900,27 @@ void GLAPIENTRY
 _mesa_GetnUniformi64vARB(GLuint program, GLint location,
                          GLsizei bufSize, GLint64 *params)
 {
-
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_get_uniform(ctx, program, location, bufSize, GLSL_TYPE_INT64, params);
 }
 void GLAPIENTRY
 _mesa_GetUniformi64vARB(GLuint program, GLint location, GLint64 *params)
 {
+   _mesa_GetnUniformi64vARB(program, location, INT_MAX, params);
 }
 
 void GLAPIENTRY
 _mesa_GetnUniformui64vARB(GLuint program, GLint location,
                          GLsizei bufSize, GLuint64 *params)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_get_uniform(ctx, program, location, bufSize, GLSL_TYPE_UINT64, params);
 }
+
 void GLAPIENTRY
 _mesa_GetUniformui64vARB(GLuint program, GLint location, GLuint64 *params)
 {
+   _mesa_GetnUniformui64vARB(program, location, INT_MAX, params);
 }
 
 
@@ -1636,160 +1642,320 @@ _mesa_ProgramUniformMatrix4x3dv(GLuint program, GLint location, GLsizei count,
 void GLAPIENTRY
 _mesa_Uniform1i64ARB(GLint location, GLint64 v0)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, &v0, GLSL_TYPE_INT64, 1);
 }
 
 void GLAPIENTRY
 _mesa_Uniform2i64ARB(GLint location, GLint64 v0, GLint64 v1)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   int64_t v[2];
+   v[0] = v0;
+   v[1] = v1;
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_INT64, 2);
 }
 
 void GLAPIENTRY
 _mesa_Uniform3i64ARB(GLint location, GLint64 v0, GLint64 v1, GLint64 v2)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   int64_t v[3];
+   v[0] = v0;
+   v[1] = v1;
+   v[2] = v2;
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_INT64, 3);
 }
 
 void GLAPIENTRY
 _mesa_Uniform4i64ARB(GLint location,  GLint64 v0, GLint64 v1, GLint64 v2, GLint64 v3)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   int64_t v[4];
+   v[0] = v0;
+   v[1] = v1;
+   v[2] = v2;
+   v[3] = v3;
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_INT64, 4);
 }
 
 void GLAPIENTRY
 _mesa_Uniform1i64vARB(GLint location, GLsizei count, const GLint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, value, GLSL_TYPE_INT64, 1);
 }
 
 void GLAPIENTRY
 _mesa_Uniform2i64vARB(GLint location,  GLsizei count, const GLint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, value, GLSL_TYPE_INT64, 2);
 }
 
 void GLAPIENTRY
 _mesa_Uniform3i64vARB(GLint location,  GLsizei count, const GLint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, value, GLSL_TYPE_INT64, 3);
 }
 
 void GLAPIENTRY
 _mesa_Uniform4i64vARB(GLint location,  GLsizei count, const GLint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, value, GLSL_TYPE_INT64, 4);
 }
 
 void GLAPIENTRY
 _mesa_Uniform1ui64ARB(GLint location,  GLuint64 v0)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, &v0, GLSL_TYPE_UINT64, 1);
 }
 
 void GLAPIENTRY
 _mesa_Uniform2ui64ARB(GLint location,  GLuint64 v0, GLuint64 v1)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   uint64_t v[2];
+   v[0] = v0;
+   v[1] = v1;
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_UINT64, 2);
 }
 
 void GLAPIENTRY
 _mesa_Uniform3ui64ARB(GLint location, GLuint64 v0, GLuint64 v1, GLuint64 v2)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   uint64_t v[3];
+   v[0] = v0;
+   v[1] = v1;
+   v[2] = v2;
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_UINT64, 3);
 }
 
 void GLAPIENTRY
 _mesa_Uniform4ui64ARB(GLint location,  GLuint64 v0, GLuint64 v1, GLuint64 v2, GLuint64 v3)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   uint64_t v[4];
+   v[0] = v0;
+   v[1] = v1;
+   v[2] = v2;
+   v[3] = v3;
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_UINT64, 4);
 }
 
 void GLAPIENTRY
 _mesa_Uniform1ui64vARB(GLint location,  GLsizei count, const GLuint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, value, GLSL_TYPE_UINT64, 1);
 }
 
 void GLAPIENTRY
 _mesa_Uniform2ui64vARB(GLint location,  GLsizei count, const GLuint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, value, GLSL_TYPE_UINT64, 2);
 }
 
 void GLAPIENTRY
 _mesa_Uniform3ui64vARB(GLint location,  GLsizei count, const GLuint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, value, GLSL_TYPE_UINT64, 3);
 }
 
 void GLAPIENTRY
 _mesa_Uniform4ui64vARB(GLint location,  GLsizei count, const GLuint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, value, GLSL_TYPE_UINT64, 4);
 }
 
-/* DSA int64 entrypoints */
+/* DSA entrypoints */
 void GLAPIENTRY
 _mesa_ProgramUniform1i64ARB(GLuint program, GLint location, GLint64 v0)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+            "glProgramUniform1i64ARB");
+   _mesa_uniform(ctx, shProg, location, 1, &v0, GLSL_TYPE_INT64, 1);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform2i64ARB(GLuint program, GLint location, GLint64 v0, GLint64 v1)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform2i64ARB");
+   int64_t v[2];
+   v[0] = v0;
+   v[1] = v1;
+   _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_INT64, 2);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform3i64ARB(GLuint program, GLint location, GLint64 v0, GLint64 v1, GLint64 v2)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform3i64ARB");
+   int64_t v[3];
+   v[0] = v0;
+   v[1] = v1;
+   v[2] = v2;
+   _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_INT64, 3);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform4i64ARB(GLuint program, GLint location,  GLint64 v0, GLint64 v1, GLint64 v2, GLint64 v3)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform4i64ARB");
+   int64_t v[4];
+   v[0] = v0;
+   v[1] = v1;
+   v[2] = v2;
+   v[3] = v3;
+   _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_INT64, 4);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform1i64vARB(GLuint program, GLint location, GLsizei count, const GLint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform1i64vARB");
+   _mesa_uniform(ctx, shProg, location, 1, value, GLSL_TYPE_INT64, 1);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform2i64vARB(GLuint program, GLint location,  GLsizei count, const GLint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform2i64vARB");
+   _mesa_uniform(ctx, shProg, location, 1, value, GLSL_TYPE_INT64, 2);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform3i64vARB(GLuint program, GLint location,  GLsizei count, const GLint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform3i64vARB");
+   _mesa_uniform(ctx, shProg, location, 1, value, GLSL_TYPE_INT64, 3);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform4i64vARB(GLuint program, GLint location,  GLsizei count, const GLint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform4i64vARB");
+   _mesa_uniform(ctx, shProg, location, 1, value, GLSL_TYPE_INT64, 4);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform1ui64ARB(GLuint program, GLint location,  GLuint64 v0)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform1ui64ARB");
+   _mesa_uniform(ctx, shProg, location, 1, &v0, GLSL_TYPE_UINT64, 1);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform2ui64ARB(GLuint program, GLint location,  GLuint64 v0, GLuint64 v1)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform2ui64ARB");
+   uint64_t v[2];
+   v[0] = v0;
+   v[1] = v1;
+   _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_UINT64, 2);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform3ui64ARB(GLuint program, GLint location, GLuint64 v0, GLuint64 v1, GLuint64 v2)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform3ui64ARB");
+   uint64_t v[3];
+   v[0] = v0;
+   v[1] = v1;
+   v[2] = v2;
+   _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_UINT64, 3);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform4ui64ARB(GLuint program, GLint location,  GLuint64 v0, GLuint64 v1, GLuint64 v2, GLuint64 v3)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform4ui64ARB");
+   uint64_t v[4];
+   v[0] = v0;
+   v[1] = v1;
+   v[2] = v2;
+   v[3] = v3;
+   _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_UINT64, 4);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform1ui64vARB(GLuint program, GLint location,  GLsizei count, const GLuint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform1ui64vARB");
+   _mesa_uniform(ctx, shProg, location, 1, value, GLSL_TYPE_UINT64, 1);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform2ui64vARB(GLuint program, GLint location,  GLsizei count, const GLuint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform2ui64vARB");
+   _mesa_uniform(ctx, shProg, location, 1, value, GLSL_TYPE_UINT64, 2);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform3ui64vARB(GLuint program, GLint location,  GLsizei count, const GLuint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform3ui64vARB");
+   _mesa_uniform(ctx, shProg, location, 1, value, GLSL_TYPE_UINT64, 3);
 }
 
 void GLAPIENTRY
 _mesa_ProgramUniform4ui64vARB(GLuint program, GLint location,  GLsizei count, const GLuint64 *value)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program,
+                                      "glProgramUniform4ui64vARB");
+   _mesa_uniform(ctx, shProg, location, 1, value, GLSL_TYPE_UINT64, 4);
 }