replace _mesa_logbase2 with util_logbase2
[mesa.git] / src / mesa / state_tracker / st_atom_constbuf.c
index e4b585101da1ab04bbd9424eff2525a69e94a8dd..c1682544f497110d95495d32bbf330c0007342b9 100644 (file)
@@ -1,8 +1,8 @@
 /**************************************************************************
- * 
+ *
  * Copyright 2007 VMware, Inc.
  * All Rights Reserved.
- * 
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the
  * "Software"), to deal in the Software without restriction, including
  * distribute, sub license, and/or sell copies of the Software, and to
  * permit persons to whom the Software is furnished to do so, subject to
  * the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice (including the
  * next paragraph) shall be included in all copies or substantial portions
  * of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
@@ -22,7 +22,7 @@
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- * 
+ *
  **************************************************************************/
 
 /*
@@ -31,7 +31,7 @@
  *   Brian Paul
  */
 
-#include "main/imports.h"
+#include "util/imports.h"
 #include "program/prog_parameter.h"
 #include "program/prog_print.h"
 #include "main/shaderapi.h"
  * Pass the given program parameters to the graphics pipe as a
  * constant buffer.
  */
-void st_upload_constants(struct st_context *st, struct gl_program *prog)
+void
+st_upload_constants(struct st_context *st, struct gl_program *prog)
 {
    gl_shader_stage stage = prog->info.stage;
    struct gl_program_parameter_list *params = prog->Parameters;
-   enum pipe_shader_type shader_type = st_shader_stage_to_ptarget(stage);
+   enum pipe_shader_type shader_type = pipe_shader_type_from_mesa(stage);
 
    assert(shader_type == PIPE_SHADER_VERTEX ||
           shader_type == PIPE_SHADER_FRAGMENT ||
@@ -71,12 +72,14 @@ void st_upload_constants(struct st_context *st, struct gl_program *prog)
       unsigned c;
 
       for (c = 0; c < MAX_NUM_FRAGMENT_CONSTANTS_ATI; c++) {
+         unsigned offset = params->ParameterValueOffset[c];
          if (ati_fs->LocalConstDef & (1 << c))
-            memcpy(params->ParameterValues[c],
+            memcpy(params->ParameterValues + offset,
                    ati_fs->Constants[c], sizeof(GLfloat) * 4);
          else
-            memcpy(params->ParameterValues[c],
-                   st->ctx->ATIFragmentShader.GlobalConstants[c], sizeof(GLfloat) * 4);
+            memcpy(params->ParameterValues + offset,
+                   st->ctx->ATIFragmentShader.GlobalConstants[c],
+                   sizeof(GLfloat) * 4);
       }
    }
 
@@ -89,7 +92,7 @@ void st_upload_constants(struct st_context *st, struct gl_program *prog)
    /* update constants */
    if (params && params->NumParameters) {
       struct pipe_constant_buffer cb;
-      const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4;
+      const uint paramBytes = params->NumParameterValues * sizeof(GLfloat);
 
       /* Update the constants which come from fixed-function state, such as
        * transformation matrices, fog factors, etc.  The rest of the values in
@@ -101,22 +104,9 @@ void st_upload_constants(struct st_context *st, struct gl_program *prog)
 
       _mesa_shader_write_subroutine_indices(st->ctx, stage);
 
-      /* We always need to get a new buffer, to keep the drivers simple and
-       * avoid gratuitous rendering synchronization.
-       * Let's use a user buffer to avoid an unnecessary copy.
-       */
-      if (!st->has_user_constbuf) {
-         cb.buffer = NULL;
-         cb.user_buffer = NULL;
-         u_upload_data(st->pipe->const_uploader, 0, paramBytes,
-                       st->ctx->Const.UniformBufferOffsetAlignment,
-                       params->ParameterValues, &cb.buffer_offset, &cb.buffer);
-         u_upload_unmap(st->pipe->const_uploader);
-      } else {
-         cb.buffer = NULL;
-         cb.user_buffer = params->ParameterValues;
-         cb.buffer_offset = 0;
-      }
+      cb.buffer = NULL;
+      cb.user_buffer = params->ParameterValues;
+      cb.buffer_offset = 0;
       cb.buffer_size = paramBytes;
 
       if (ST_DEBUG & DEBUG_CONSTANTS) {
@@ -144,7 +134,8 @@ void st_upload_constants(struct st_context *st, struct gl_program *prog)
 /**
  * Vertex shader:
  */
-void st_update_vs_constants(struct st_context *st )
+void
+st_update_vs_constants(struct st_context *st)
 {
    st_upload_constants(st, &st->vp->Base);
 }
@@ -152,7 +143,8 @@ void st_update_vs_constants(struct st_context *st )
 /**
  * Fragment shader:
  */
-void st_update_fs_constants(struct st_context *st )
+void
+st_update_fs_constants(struct st_context *st)
 {
    st_upload_constants(st, &st->fp->Base);
 }
@@ -160,9 +152,10 @@ void st_update_fs_constants(struct st_context *st )
 
 /* Geometry shader:
  */
-void st_update_gs_constants(struct st_context *st )
+void
+st_update_gs_constants(struct st_context *st)
 {
-   struct st_common_program *gp = st->gp;
+   struct st_program *gp = st->gp;
 
    if (gp)
       st_upload_constants(st, &gp->Base);
@@ -170,9 +163,10 @@ void st_update_gs_constants(struct st_context *st )
 
 /* Tessellation control shader:
  */
-void st_update_tcs_constants(struct st_context *st )
+void
+st_update_tcs_constants(struct st_context *st)
 {
-   struct st_common_program *tcp = st->tcp;
+   struct st_program *tcp = st->tcp;
 
    if (tcp)
       st_upload_constants(st, &tcp->Base);
@@ -180,9 +174,10 @@ void st_update_tcs_constants(struct st_context *st )
 
 /* Tessellation evaluation shader:
  */
-void st_update_tes_constants(struct st_context *st )
+void
+st_update_tes_constants(struct st_context *st)
 {
-   struct st_common_program *tep = st->tep;
+   struct st_program *tep = st->tep;
 
    if (tep)
       st_upload_constants(st, &tep->Base);
@@ -190,16 +185,18 @@ void st_update_tes_constants(struct st_context *st )
 
 /* Compute shader:
  */
-void st_update_cs_constants(struct st_context *st )
+void
+st_update_cs_constants(struct st_context *st)
 {
-   struct st_compute_program *cp = st->cp;
+   struct st_program *cp = st->cp;
 
    if (cp)
       st_upload_constants(st, &cp->Base);
 }
 
-static void st_bind_ubos(struct st_context *st, struct gl_program *prog,
-                         unsigned shader_type)
+static void
+st_bind_ubos(struct st_context *st, struct gl_program *prog,
+             enum pipe_shader_type shader_type)
 {
    unsigned i;
    struct pipe_constant_buffer cb = { 0 };
@@ -208,14 +205,14 @@ static void st_bind_ubos(struct st_context *st, struct gl_program *prog,
       return;
 
    for (i = 0; i < prog->info.num_ubos; i++) {
-      struct gl_uniform_buffer_binding *binding;
+      struct gl_buffer_binding *binding;
       struct st_buffer_object *st_obj;
 
       binding =
          &st->ctx->UniformBufferBindings[prog->sh.UniformBlocks[i]->Binding];
       st_obj = st_buffer_object(binding->BufferObject);
 
-      cb.buffer = st_obj->buffer;
+      cb.buffer = st_obj ? st_obj->buffer : NULL;
 
       if (cb.buffer) {
          cb.buffer_offset = binding->Offset;
@@ -236,7 +233,8 @@ static void st_bind_ubos(struct st_context *st, struct gl_program *prog,
    }
 }
 
-void st_bind_vs_ubos(struct st_context *st)
+void
+st_bind_vs_ubos(struct st_context *st)
 {
    struct gl_program *prog =
       st->ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
@@ -244,7 +242,8 @@ void st_bind_vs_ubos(struct st_context *st)
    st_bind_ubos(st, prog, PIPE_SHADER_VERTEX);
 }
 
-void st_bind_fs_ubos(struct st_context *st)
+void
+st_bind_fs_ubos(struct st_context *st)
 {
    struct gl_program *prog =
       st->ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT];
@@ -252,7 +251,8 @@ void st_bind_fs_ubos(struct st_context *st)
    st_bind_ubos(st, prog, PIPE_SHADER_FRAGMENT);
 }
 
-void st_bind_gs_ubos(struct st_context *st)
+void
+st_bind_gs_ubos(struct st_context *st)
 {
    struct gl_program *prog =
       st->ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
@@ -260,7 +260,8 @@ void st_bind_gs_ubos(struct st_context *st)
    st_bind_ubos(st, prog, PIPE_SHADER_GEOMETRY);
 }
 
-void st_bind_tcs_ubos(struct st_context *st)
+void
+st_bind_tcs_ubos(struct st_context *st)
 {
    struct gl_program *prog =
       st->ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_CTRL];
@@ -268,7 +269,8 @@ void st_bind_tcs_ubos(struct st_context *st)
    st_bind_ubos(st, prog, PIPE_SHADER_TESS_CTRL);
 }
 
-void st_bind_tes_ubos(struct st_context *st)
+void
+st_bind_tes_ubos(struct st_context *st)
 {
    struct gl_program *prog =
       st->ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
@@ -276,7 +278,8 @@ void st_bind_tes_ubos(struct st_context *st)
    st_bind_ubos(st, prog, PIPE_SHADER_TESS_EVAL);
 }
 
-void st_bind_cs_ubos(struct st_context *st)
+void
+st_bind_cs_ubos(struct st_context *st)
 {
    struct gl_program *prog =
       st->ctx->_Shader->CurrentProgram[MESA_SHADER_COMPUTE];