[Mesa-dev] [PATCH v2 04/28] mesa: add double uniform support. (v5)

Pohjolainen, Topi topi.pohjolainen at intel.com
Thu Feb 5 23:50:12 PST 2015


On Fri, Feb 06, 2015 at 09:18:35AM +0200, Ian Romanick wrote:
> On 02/06/2015 06:56 AM, Ilia Mirkin wrote:
> > From: Dave Airlie <airlied at redhat.com>
> > 
> > This adds support for the new uniform interfaces
> > from ARB_gpu_shader_fp64.
> > 
> > v2:
> > support ARB_separate_shader_objects ProgramUniform*d* (Ian)
> > don't allow boolean uniforms to be updated (issue 15) (Ian)
> > 
> > v3: fix size_mul
> > v4: Teach uniform update to take into account double precision (Topi)
> > v5: add transpose for double case (Ilia)
> > 
> > Signed-off-by: Dave Airlie <airlied at redhat.com>
> > ---
> >  src/mesa/main/uniform_query.cpp   |  47 +++++++---
> >  src/mesa/main/uniforms.c          | 185 ++++++++++++++++++++++++++++++++++----
> >  src/mesa/main/uniforms.h          |   3 +-
> >  src/mesa/program/ir_to_mesa.cpp   |  17 +++-
> >  src/mesa/program/prog_parameter.c |  16 ++--
> >  5 files changed, 229 insertions(+), 39 deletions(-)
> > 
> > diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
> > index d36f506..2dc272e 100644
> > --- a/src/mesa/main/uniform_query.cpp
> > +++ b/src/mesa/main/uniform_query.cpp
> > @@ -469,6 +469,9 @@ log_uniform(const void *values, enum glsl_base_type basicType,
> >        case GLSL_TYPE_FLOAT:
> >  	 printf("%g ", v[i].f);
> >  	 break;
> > +      case GLSL_TYPE_DOUBLE:

This won't compile, GLSL_TYPE_DOUBLE is not introduced until
"glsl: Add double builtin type". There are some more occurences in the rest
of the patch. It looks to me we need to split this in two, one dealing with
core state handling (src/mesa/main/uniforms.c) and another updating the
compiler frontend, and moving the latter further in the series.

> > +	 printf("%g ", *(double* )&v[i * 2].f);
> > +	 break;
> 
> I know the rest of the code here uses tabs, but new code should not.
> 
> >        default:
> >  	 assert(!"Should not get here.");
> >  	 break;
> > @@ -529,11 +532,11 @@ _mesa_propagate_uniforms_to_driver_storage(struct gl_uniform_storage *uni,
> >      */
> >     const unsigned components = MAX2(1, uni->type->vector_elements);
> >     const unsigned vectors = MAX2(1, uni->type->matrix_columns);
> > -
> > +   const int dmul = uni->type->base_type == GLSL_TYPE_DOUBLE ? 2 : 1;
> 
> Blank line here.
> 
> >     /* Store the data in the driver's requested type in the driver's storage
> >      * areas.
> >      */
> > -   unsigned src_vector_byte_stride = components * 4;
> > +   unsigned src_vector_byte_stride = components * 4 * dmul;
> >  
> >     for (i = 0; i < uni->num_driver_storage; i++) {
> >        struct gl_uniform_driver_storage *const store = &uni->driver_storage[i];
> > @@ -608,6 +611,7 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
> >                unsigned src_components)
> >  {
> >     unsigned offset;
> > +   int size_mul = basicType == GLSL_TYPE_DOUBLE ? 2 : 1;
> >  
> >     struct gl_uniform_storage *const uni =
> >        validate_uniform_parameters(ctx, shProg, location, count,
> > @@ -615,15 +619,13 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
> >     if (uni == NULL)
> >        return;
> >  
> > -   /* Verify that the types are compatible.
> > -    */
> 
> Why is this comment removed?  We're still verifying that the types are
> compatible.  Right?
> 
> >     const unsigned components = uni->type->is_sampler()
> >        ? 1 : uni->type->vector_elements;
> >  
> >     bool match;
> >     switch (uni->type->base_type) {
> >     case GLSL_TYPE_BOOL:
> > -      match = true;
> > +      match = (basicType != GLSL_TYPE_DOUBLE);
> >        break;
> >     case GLSL_TYPE_SAMPLER:
> >     case GLSL_TYPE_IMAGE:
> > @@ -710,8 +712,8 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
> >     /* Store the data in the "actual type" backing storage for the uniform.
> >      */
> >     if (!uni->type->is_boolean()) {
> > -      memcpy(&uni->storage[components * offset], values,
> > -	     sizeof(uni->storage[0]) * components * count);
> > +      memcpy(&uni->storage[size_mul * components * offset], values,
> > +	     sizeof(uni->storage[0]) * components * count * size_mul);
> >     } else {
> >        const union gl_constant_value *src =
> >  	 (const union gl_constant_value *) values;
> > @@ -808,13 +810,14 @@ extern "C" void
> >  _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
> >  		     GLuint cols, GLuint rows,
> >                       GLint location, GLsizei count,
> > -                     GLboolean transpose, const GLfloat *values)
> > +                     GLboolean transpose,
> > +                     const GLvoid *values, GLenum type)
> >  {
> >     unsigned offset;
> >     unsigned vectors;
> >     unsigned components;
> >     unsigned elements;
> > -
> > +   int size_mul;
> >     struct gl_uniform_storage *const uni =
> >        validate_uniform_parameters(ctx, shProg, location, count,
> >                                    &offset, "glUniformMatrix");
> > @@ -827,6 +830,9 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
> >        return;
> >     }
> >  
> > +   assert(type == GL_FLOAT || type == GL_DOUBLE);
> > +   size_mul = type == GL_DOUBLE ? 2 : 1;
> > +
> >     assert(!uni->type->is_sampler());
> >     vectors = uni->type->matrix_columns;
> >     components = uni->type->vector_elements;
> > @@ -852,7 +858,7 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
> >     }
> >  
> >     if (unlikely(ctx->_Shader->Flags & GLSL_UNIFORMS)) {
> > -      log_uniform(values, GLSL_TYPE_FLOAT, components, vectors, count,
> > +      log_uniform(values, uni->type->base_type, components, vectors, count,
> >  		  bool(transpose), shProg, location, uni);
> >     }
> >  
> > @@ -879,11 +885,11 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
> >  
> >     if (!transpose) {
> >        memcpy(&uni->storage[elements * offset], values,
> > -	     sizeof(uni->storage[0]) * elements * count);
> > -   } else {
> > +	     sizeof(uni->storage[0]) * elements * count * size_mul);
> > +   } else if (type == GL_FLOAT) {
> >        /* Copy and transpose the matrix.
> >         */
> > -      const float *src = values;
> > +      const float *src = (const float *)values;
> >        float *dst = &uni->storage[elements * offset].f;
> >  
> >        for (int i = 0; i < count; i++) {
> > @@ -896,6 +902,21 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
> >  	 dst += elements;
> >  	 src += elements;
> >        }
> > +   } else {
> > +      assert(type == GL_DOUBLE);
> > +      const double *src = (const double *)values;
> > +      double *dst = (double *)&uni->storage[elements * offset].f;
> > +
> > +      for (int i = 0; i < count; i++) {
> > +	 for (unsigned r = 0; r < rows; r++) {
> > +	    for (unsigned c = 0; c < cols; c++) {
> > +	       dst[(c * components) + r] = src[c + (r * vectors)];
> > +	    }
> > +	 }
> > +
> > +	 dst += elements;
> > +	 src += elements;
> > +      }
> >     }
> >  
> >     uni->initialized = true;
> > diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
> > index 4e3c1ab..e471b87 100644
> > --- a/src/mesa/main/uniforms.c
> > +++ b/src/mesa/main/uniforms.c
> > @@ -553,7 +553,7 @@ _mesa_UniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose,
> >  {
> >     GET_CURRENT_CONTEXT(ctx);
> >     _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > -			2, 2, location, count, transpose, value);
> > +			2, 2, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  void GLAPIENTRY
> > @@ -562,7 +562,7 @@ _mesa_UniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose,
> >  {
> >     GET_CURRENT_CONTEXT(ctx);
> >     _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > -			3, 3, location, count, transpose, value);
> > +			3, 3, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  void GLAPIENTRY
> > @@ -571,7 +571,7 @@ _mesa_UniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose,
> >  {
> >     GET_CURRENT_CONTEXT(ctx);
> >     _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > -			4, 4, location, count, transpose, value);
> > +			4, 4, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  /** Same as above with direct state access **/
> > @@ -683,7 +683,7 @@ _mesa_ProgramUniformMatrix2fv(GLuint program, GLint location, GLsizei count,
> >     struct gl_shader_program *shProg =
> >        _mesa_lookup_shader_program_err(ctx, program,
> >              "glProgramUniformMatrix2fv");
> > -   _mesa_uniform_matrix(ctx, shProg, 2, 2, location, count, transpose, value);
> > +   _mesa_uniform_matrix(ctx, shProg, 2, 2, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  void GLAPIENTRY
> > @@ -694,7 +694,7 @@ _mesa_ProgramUniformMatrix3fv(GLuint program, GLint location, GLsizei count,
> >     struct gl_shader_program *shProg =
> >        _mesa_lookup_shader_program_err(ctx, program,
> >              "glProgramUniformMatrix3fv");
> > -   _mesa_uniform_matrix(ctx, shProg, 3, 3, location, count, transpose, value);
> > +   _mesa_uniform_matrix(ctx, shProg, 3, 3, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  void GLAPIENTRY
> > @@ -705,7 +705,7 @@ _mesa_ProgramUniformMatrix4fv(GLuint program, GLint location, GLsizei count,
> >     struct gl_shader_program *shProg =
> >        _mesa_lookup_shader_program_err(ctx, program,
> >              "glProgramUniformMatrix4fv");
> > -   _mesa_uniform_matrix(ctx, shProg, 4, 4, location, count, transpose, value);
> > +   _mesa_uniform_matrix(ctx, shProg, 4, 4, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  
> > @@ -718,7 +718,7 @@ _mesa_UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose,
> >  {
> >     GET_CURRENT_CONTEXT(ctx);
> >     _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > -			2, 3, location, count, transpose, value);
> > +			2, 3, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  void GLAPIENTRY
> > @@ -727,7 +727,7 @@ _mesa_UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose,
> >  {
> >     GET_CURRENT_CONTEXT(ctx);
> >     _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > -			3, 2, location, count, transpose, value);
> > +			3, 2, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  void GLAPIENTRY
> > @@ -736,7 +736,7 @@ _mesa_UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose,
> >  {
> >     GET_CURRENT_CONTEXT(ctx);
> >     _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > -			2, 4, location, count, transpose, value);
> > +			2, 4, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  void GLAPIENTRY
> > @@ -745,7 +745,7 @@ _mesa_UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose,
> >  {
> >     GET_CURRENT_CONTEXT(ctx);
> >     _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > -			4, 2, location, count, transpose, value);
> > +			4, 2, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  void GLAPIENTRY
> > @@ -754,7 +754,7 @@ _mesa_UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose,
> >  {
> >     GET_CURRENT_CONTEXT(ctx);
> >     _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > -			3, 4, location, count, transpose, value);
> > +			3, 4, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  void GLAPIENTRY
> > @@ -763,7 +763,7 @@ _mesa_UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose,
> >  {
> >     GET_CURRENT_CONTEXT(ctx);
> >     _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > -			4, 3, location, count, transpose, value);
> > +			4, 3, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  /** Same as above with direct state access **/
> > @@ -776,7 +776,7 @@ _mesa_ProgramUniformMatrix2x3fv(GLuint program, GLint location, GLsizei count,
> >     struct gl_shader_program *shProg =
> >        _mesa_lookup_shader_program_err(ctx, program,
> >              "glProgramUniformMatrix2x3fv");
> > -   _mesa_uniform_matrix(ctx, shProg, 2, 3, location, count, transpose, value);
> > +   _mesa_uniform_matrix(ctx, shProg, 2, 3, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  void GLAPIENTRY
> > @@ -787,7 +787,7 @@ _mesa_ProgramUniformMatrix3x2fv(GLuint program, GLint location, GLsizei count,
> >     struct gl_shader_program *shProg =
> >        _mesa_lookup_shader_program_err(ctx, program,
> >              "glProgramUniformMatrix3x2fv");
> > -   _mesa_uniform_matrix(ctx, shProg, 3, 2, location, count, transpose, value);
> > +   _mesa_uniform_matrix(ctx, shProg, 3, 2, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  void GLAPIENTRY
> > @@ -798,7 +798,7 @@ _mesa_ProgramUniformMatrix2x4fv(GLuint program, GLint location, GLsizei count,
> >     struct gl_shader_program *shProg =
> >        _mesa_lookup_shader_program_err(ctx, program,
> >              "glProgramUniformMatrix2x4fv");
> > -   _mesa_uniform_matrix(ctx, shProg, 2, 4, location, count, transpose, value);
> > +   _mesa_uniform_matrix(ctx, shProg, 2, 4, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  void GLAPIENTRY
> > @@ -809,7 +809,7 @@ _mesa_ProgramUniformMatrix4x2fv(GLuint program, GLint location, GLsizei count,
> >     struct gl_shader_program *shProg =
> >        _mesa_lookup_shader_program_err(ctx, program,
> >              "glProgramUniformMatrix4x2fv");
> > -   _mesa_uniform_matrix(ctx, shProg, 4, 2, location, count, transpose, value);
> > +   _mesa_uniform_matrix(ctx, shProg, 4, 2, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  void GLAPIENTRY
> > @@ -820,7 +820,7 @@ _mesa_ProgramUniformMatrix3x4fv(GLuint program, GLint location, GLsizei count,
> >     struct gl_shader_program *shProg =
> >        _mesa_lookup_shader_program_err(ctx, program,
> >              "glProgramUniformMatrix3x4fv");
> > -   _mesa_uniform_matrix(ctx, shProg, 3, 4, location, count, transpose, value);
> > +   _mesa_uniform_matrix(ctx, shProg, 3, 4, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  void GLAPIENTRY
> > @@ -831,7 +831,7 @@ _mesa_ProgramUniformMatrix4x3fv(GLuint program, GLint location, GLsizei count,
> >     struct gl_shader_program *shProg =
> >        _mesa_lookup_shader_program_err(ctx, program,
> >              "glProgramUniformMatrix4x3fv");
> > -   _mesa_uniform_matrix(ctx, shProg, 4, 3, location, count, transpose, value);
> > +   _mesa_uniform_matrix(ctx, shProg, 4, 3, location, count, transpose, value, GL_FLOAT);
> >  }
> >  
> >  
> > @@ -1342,194 +1342,343 @@ _mesa_GetActiveAtomicCounterBufferiv(GLuint program, GLuint bufferIndex,
> >  void GLAPIENTRY
> >  _mesa_Uniform1d(GLint location, GLdouble v0)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, &v0, GLSL_TYPE_DOUBLE, 1);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_Uniform2d(GLint location, GLdouble v0, GLdouble v1)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   GLdouble v[2];
> > +   v[0] = v0;
> > +   v[1] = v1;
> > +   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_DOUBLE, 2);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_Uniform3d(GLint location, GLdouble v0, GLdouble v1, GLdouble v2)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   GLdouble v[3];
> > +   v[0] = v0;
> > +   v[1] = v1;
> > +   v[2] = v2;
> > +   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_DOUBLE, 3);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_Uniform4d(GLint location, GLdouble v0, GLdouble v1, GLdouble v2,
> >                  GLdouble v3)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   GLdouble 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_DOUBLE, 4);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_Uniform1dv(GLint location, GLsizei count, const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_DOUBLE, 1);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_Uniform2dv(GLint location, GLsizei count, const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_DOUBLE, 2);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_Uniform3dv(GLint location, GLsizei count, const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_DOUBLE, 3);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_Uniform4dv(GLint location, GLsizei count, const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_DOUBLE, 4);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_UniformMatrix2dv(GLint location, GLsizei count, GLboolean transpose,
> >                         const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > +			2, 2, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_UniformMatrix3dv(GLint location, GLsizei count, GLboolean transpose,
> >                         const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > +			3, 3, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_UniformMatrix4dv(GLint location, GLsizei count, GLboolean transpose,
> >                         const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > +			4, 4, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_UniformMatrix2x3dv(GLint location, GLsizei count, GLboolean transpose,
> >                           const GLdouble *value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > +			2, 3, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_UniformMatrix3x2dv(GLint location, GLsizei count, GLboolean transpose,
> >                           const GLdouble *value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > +			3, 2, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_UniformMatrix2x4dv(GLint location, GLsizei count, GLboolean transpose,
> >                           const GLdouble *value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > +			2, 4, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_UniformMatrix4x2dv(GLint location, GLsizei count, GLboolean transpose,
> >                           const GLdouble *value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > +			4, 2, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_UniformMatrix3x4dv(GLint location, GLsizei count, GLboolean transpose,
> >                           const GLdouble *value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > +			3, 4, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_UniformMatrix4x3dv(GLint location, GLsizei count, GLboolean transpose,
> >                           const GLdouble *value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
> > +			4, 3, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniform1d(GLuint program, GLint location, GLdouble v0)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   struct gl_shader_program *shProg =
> > +      _mesa_lookup_shader_program_err(ctx, program,
> > +            "glProgramUniform1d");
> > +   _mesa_uniform(ctx, shProg, location, 1, &v0, GLSL_TYPE_DOUBLE, 1);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniform2d(GLuint program, GLint location, GLdouble v0, GLdouble v1)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   GLdouble v[2];
> > +   struct gl_shader_program *shProg;
> > +   v[0] = v0;
> > +   v[1] = v1;
> > +   shProg = _mesa_lookup_shader_program_err(ctx, program, "glProgramUniform2d");
> > +   _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_DOUBLE, 2);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniform3d(GLuint program, GLint location, GLdouble v0, GLdouble v1,
> >                         GLdouble v2)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   GLdouble v[3];
> > +   struct gl_shader_program *shProg;
> > +   v[0] = v0;
> > +   v[1] = v1;
> > +   v[2] = v2;
> > +   shProg = _mesa_lookup_shader_program_err(ctx, program, "glProgramUniform3d");
> > +   _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_DOUBLE, 3);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniform4d(GLuint program, GLint location, GLdouble v0, GLdouble v1,
> >                         GLdouble v2, GLdouble v3)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   GLdouble v[4];
> > +   struct gl_shader_program *shProg;
> > +   v[0] = v0;
> > +   v[1] = v1;
> > +   v[2] = v2;
> > +   v[3] = v3;
> > +   shProg = _mesa_lookup_shader_program_err(ctx, program, "glProgramUniform4d");
> > +   _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_DOUBLE, 4);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniform1dv(GLuint program, GLint location, GLsizei count,
> >                          const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   struct gl_shader_program *shProg =
> > +      _mesa_lookup_shader_program_err(ctx, program,
> > +            "glProgramUniform1dv");
> > +   _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_DOUBLE, 1);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniform2dv(GLuint program, GLint location, GLsizei count,
> >                          const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   struct gl_shader_program *shProg =
> > +      _mesa_lookup_shader_program_err(ctx, program,
> > +            "glProgramUniform2dv");
> > +   _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_DOUBLE, 2);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniform3dv(GLuint program, GLint location, GLsizei count,
> >                          const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   struct gl_shader_program *shProg =
> > +      _mesa_lookup_shader_program_err(ctx, program,
> > +            "glProgramUniform3dv");
> > +   _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_DOUBLE, 3);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniform4dv(GLuint program, GLint location, GLsizei count,
> >                          const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   struct gl_shader_program *shProg =
> > +      _mesa_lookup_shader_program_err(ctx, program,
> > +            "glProgramUniform4dv");
> > +   _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_DOUBLE, 4);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniformMatrix2dv(GLuint program, GLint location, GLsizei count,
> >                                GLboolean transpose, const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   struct gl_shader_program *shProg =
> > +      _mesa_lookup_shader_program_err(ctx, program,
> > +            "glProgramUniformMatrix2dv");
> > +   _mesa_uniform_matrix(ctx, shProg, 2, 2, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniformMatrix3dv(GLuint program, GLint location, GLsizei count,
> >                                GLboolean transpose, const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   struct gl_shader_program *shProg =
> > +      _mesa_lookup_shader_program_err(ctx, program,
> > +            "glProgramUniformMatrix3dv");
> > +   _mesa_uniform_matrix(ctx, shProg, 3, 3, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniformMatrix4dv(GLuint program, GLint location, GLsizei count,
> >                                GLboolean transpose, const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   struct gl_shader_program *shProg =
> > +      _mesa_lookup_shader_program_err(ctx, program,
> > +            "glProgramUniformMatrix4dv");
> > +   _mesa_uniform_matrix(ctx, shProg, 4, 4, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniformMatrix2x3dv(GLuint program, GLint location, GLsizei count,
> >                                  GLboolean transpose, const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   struct gl_shader_program *shProg =
> > +      _mesa_lookup_shader_program_err(ctx, program,
> > +            "glProgramUniformMatrix2x3dv");
> > +   _mesa_uniform_matrix(ctx, shProg, 2, 3, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniformMatrix3x2dv(GLuint program, GLint location, GLsizei count,
> >                                  GLboolean transpose, const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   struct gl_shader_program *shProg =
> > +      _mesa_lookup_shader_program_err(ctx, program,
> > +            "glProgramUniformMatrix3x2dv");
> > +   _mesa_uniform_matrix(ctx, shProg, 3, 2, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniformMatrix2x4dv(GLuint program, GLint location, GLsizei count,
> >                                  GLboolean transpose, const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   struct gl_shader_program *shProg =
> > +      _mesa_lookup_shader_program_err(ctx, program,
> > +            "glProgramUniformMatrix2x4dv");
> > +   _mesa_uniform_matrix(ctx, shProg, 2, 4, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniformMatrix4x2dv(GLuint program, GLint location, GLsizei count,
> >                                  GLboolean transpose, const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   struct gl_shader_program *shProg =
> > +      _mesa_lookup_shader_program_err(ctx, program,
> > +            "glProgramUniformMatrix4x2dv");
> > +   _mesa_uniform_matrix(ctx, shProg, 4, 2, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniformMatrix3x4dv(GLuint program, GLint location, GLsizei count,
> >                                  GLboolean transpose, const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   struct gl_shader_program *shProg =
> > +      _mesa_lookup_shader_program_err(ctx, program,
> > +            "glProgramUniformMatrix3x4dv");
> > +   _mesa_uniform_matrix(ctx, shProg, 3, 4, location, count, transpose, value, GL_DOUBLE);
> >  }
> >  
> >  void GLAPIENTRY
> >  _mesa_ProgramUniformMatrix4x3dv(GLuint program, GLint location, GLsizei count,
> >                                  GLboolean transpose, const GLdouble * value)
> >  {
> > +   GET_CURRENT_CONTEXT(ctx);
> > +   struct gl_shader_program *shProg =
> > +      _mesa_lookup_shader_program_err(ctx, program,
> > +            "glProgramUniformMatrix4x3dv");
> > +   _mesa_uniform_matrix(ctx, shProg, 4, 3, location, count, transpose, value, GL_DOUBLE);
> >  }
> > diff --git a/src/mesa/main/uniforms.h b/src/mesa/main/uniforms.h
> > index 520fbbf..0e6113f 100644
> > --- a/src/mesa/main/uniforms.h
> > +++ b/src/mesa/main/uniforms.h
> > @@ -362,7 +362,8 @@ void
> >  _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
> >  		     GLuint cols, GLuint rows,
> >                       GLint location, GLsizei count,
> > -                     GLboolean transpose, const GLfloat *values);
> > +                     GLboolean transpose,
> > +                     const GLvoid *values, GLenum type);
> >  
> >  void
> >  _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
> > diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
> > index 725e51d..f917681 100644
> > --- a/src/mesa/program/ir_to_mesa.cpp
> > +++ b/src/mesa/program/ir_to_mesa.cpp
> > @@ -606,6 +606,14 @@ type_size(const struct glsl_type *type)
> >  	  */
> >  	 return 1;
> >        }
> > +      break;
> > +   case GLSL_TYPE_DOUBLE:
> > +      if (type->is_matrix()) {
> > +         return type->matrix_columns * 2;
> > +      } else {
> > +         return 2;
> > +      }
> > +      break;
> >     case GLSL_TYPE_ARRAY:
> >        assert(type->length > 0);
> >        return type_size(type->fields.array) * type->length;
> > @@ -2489,6 +2497,7 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
> >  	 enum gl_uniform_driver_format format = uniform_native;
> >  
> >  	 unsigned columns = 0;
> > +	 int dmul = 4 * sizeof(float);
> >  	 switch (storage->type->base_type) {
> >  	 case GLSL_TYPE_UINT:
> >  	    assert(ctx->Const.NativeIntegers);
> > @@ -2500,6 +2509,10 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
> >  	       (ctx->Const.NativeIntegers) ? uniform_native : uniform_int_float;
> >  	    columns = 1;
> >  	    break;
> > +
> > +	 case GLSL_TYPE_DOUBLE:
> > +	    dmul = 4 * sizeof(GLdouble);
> > +	    /* fallthrough */
> >  	 case GLSL_TYPE_FLOAT:
> >  	    format = uniform_native;
> >  	    columns = storage->type->matrix_columns;
> > @@ -2524,8 +2537,8 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
> >  	 }
> >  
> >  	 _mesa_uniform_attach_driver_storage(storage,
> > -					     4 * sizeof(float) * columns,
> > -					     4 * sizeof(float),
> > +					     dmul * columns,
> > +					     dmul,
> >  					     format,
> >  					     &params->ParameterValues[i]);
> >  
> > diff --git a/src/mesa/program/prog_parameter.c b/src/mesa/program/prog_parameter.c
> > index 0ef4641..06f3c04 100644
> > --- a/src/mesa/program/prog_parameter.c
> > +++ b/src/mesa/program/prog_parameter.c
> > @@ -111,7 +111,13 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
> >                      const gl_state_index state[STATE_LENGTH])
> >  {
> >     const GLuint oldNum = paramList->NumParameters;
> > -   const GLuint sz4 = (size + 3) / 4; /* no. of new param slots needed */
> > +   GLuint sz4 = (size + 3) / 4; /* no. of new param slots needed */
> > +   int actual_size = size;
> > +
> > +   if (_mesa_type_is_double(datatype)) {
> > +      actual_size *= 2;
> > +      sz4 = ((actual_size + 3) / 4);
> > +   }
> >  
> >     assert(size > 0);
> >  
> > @@ -150,15 +156,15 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
> >           struct gl_program_parameter *p = paramList->Parameters + oldNum + i;
> >           p->Name = name ? _mesa_strdup(name) : NULL;
> >           p->Type = type;
> > -         p->Size = size;
> > +         p->Size = actual_size;
> >           p->DataType = datatype;
> >           if (values) {
> > -            if (size >= 4) {
> > +            if (actual_size >= 4) {
> >                 COPY_4V(paramList->ParameterValues[oldNum + i], values);
> >              }
> >              else {
> >                 /* copy 1, 2 or 3 values */
> > -               GLuint remaining = size % 4;
> > +               GLuint remaining = actual_size % 4;
> >                 assert(remaining < 4);
> >                 for (j = 0; j < remaining; j++) {
> >                    paramList->ParameterValues[oldNum + i][j].f = values[j].f;
> > @@ -176,7 +182,7 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
> >              for (j = 0; j < 4; j++)
> >              	paramList->ParameterValues[oldNum + i][j].f = 0;
> >           }
> > -         size -= 4;
> > +         actual_size -= 4;
> >        }
> >  
> >        if (state) {
> > 
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list