summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/uniform_query.cpp
diff options
context:
space:
mode:
authorDave Airlie <[email protected]>2014-06-11 13:28:32 +1000
committerIlia Mirkin <[email protected]>2015-02-19 00:28:33 -0500
commit5cc486b4e3a169fd2d82c463ca793e48343daef3 (patch)
tree143275fd7beee53c38a5be2ebee8dd618e9efe86 /src/mesa/main/uniform_query.cpp
parentbf257d2c909681139f6880555d896745289152e7 (diff)
mesa: add double uniform support. (v5)
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 <[email protected]> Reviewed-by: Ilia Mirkin <[email protected]>
Diffstat (limited to 'src/mesa/main/uniform_query.cpp')
-rw-r--r--src/mesa/main/uniform_query.cpp46
1 files changed, 35 insertions, 11 deletions
diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index d36f5067cbd..40327fba4b1 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:
+ printf("%g ", *(double* )&v[i * 2].f);
+ break;
default:
assert(!"Should not get here.");
break;
@@ -529,11 +532,12 @@ _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;
/* 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];
@@ -541,7 +545,7 @@ _mesa_propagate_uniforms_to_driver_storage(struct gl_uniform_storage *uni,
const unsigned extra_stride =
store->element_stride - (vectors * store->vector_stride);
const uint8_t *src =
- (uint8_t *) (&uni->storage[array_index * (components * vectors)].i);
+ (uint8_t *) (&uni->storage[array_index * (dmul * components * vectors)].i);
#if 0
printf("%s: %p[%d] components=%u vectors=%u count=%u vector_stride=%u "
@@ -608,6 +612,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,
@@ -623,7 +628,7 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
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 +715,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 +813,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 +833,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 +861,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 +888,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 +905,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;