i965/miptree: Set refcount before failing via _release()
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vs_surface_state.c
index 709cb438f81d0d37d990f58c8f3c4fe4a274d5c0..016da7456af2d81d02665e97b324d1ae0bf2a802 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "main/mtypes.h"
 #include "program/prog_parameter.h"
+#include "main/shaderapi.h"
 
 #include "brw_context.h"
 #include "brw_state.h"
  */
 void
 brw_upload_pull_constants(struct brw_context *brw,
-                          GLbitfield brw_new_constbuf,
+                          GLbitfield64 brw_new_constbuf,
                           const struct gl_program *prog,
                           struct brw_stage_state *stage_state,
-                          const struct brw_stage_prog_data *prog_data,
-                          bool dword_pitch)
+                          const struct brw_stage_prog_data *prog_data)
 {
-   int i;
+   unsigned i;
    uint32_t surf_index = prog_data->binding_table.pull_constants_start;
 
    if (!prog_data->nr_pull_params) {
       if (stage_state->surf_offset[surf_index]) {
         stage_state->surf_offset[surf_index] = 0;
-        brw->state.dirty.brw |= brw_new_constbuf;
+        brw->ctx.NewDriverState |= brw_new_constbuf;
       }
       return;
    }
@@ -74,7 +74,7 @@ brw_upload_pull_constants(struct brw_context *brw,
 
    /* BRW_NEW_*_PROG_DATA | _NEW_PROGRAM_CONSTANTS */
    uint32_t size = prog_data->nr_pull_params * 4;
-   drm_intel_bo *const_bo = NULL;
+   struct brw_bo *const_bo = NULL;
    uint32_t const_offset;
    gl_constant_value *constants = intel_upload_space(brw, size, 64,
                                                      &const_bo, &const_offset);
@@ -94,11 +94,10 @@ brw_upload_pull_constants(struct brw_context *brw,
    }
 
    brw_create_constant_surface(brw, const_bo, const_offset, size,
-                               &stage_state->surf_offset[surf_index],
-                               dword_pitch);
-   drm_intel_bo_unreference(const_bo);
+                               &stage_state->surf_offset[surf_index]);
+   brw_bo_unreference(const_bo);
 
-   brw->state.dirty.brw |= brw_new_constbuf;
+   brw->ctx.NewDriverState |= brw_new_constbuf;
 }
 
 
@@ -112,26 +111,24 @@ static void
 brw_upload_vs_pull_constants(struct brw_context *brw)
 {
    struct brw_stage_state *stage_state = &brw->vs.base;
-   bool dword_pitch;
 
    /* BRW_NEW_VERTEX_PROGRAM */
-   struct brw_vertex_program *vp =
-      (struct brw_vertex_program *) brw->vertex_program;
+   struct brw_program *vp = (struct brw_program *) brw->vertex_program;
 
    /* BRW_NEW_VS_PROG_DATA */
-   const struct brw_stage_prog_data *prog_data = &brw->vs.prog_data->base.base;
-
-   dword_pitch = brw->vs.prog_data->base.simd8;
+   const struct brw_stage_prog_data *prog_data = brw->vs.base.prog_data;
 
+   _mesa_shader_write_subroutine_indices(&brw->ctx, MESA_SHADER_VERTEX);
    /* _NEW_PROGRAM_CONSTANTS */
-   brw_upload_pull_constants(brw, BRW_NEW_VS_CONSTBUF, &vp->program.Base,
-                             stage_state, prog_data, dword_pitch);
+   brw_upload_pull_constants(brw, BRW_NEW_VS_CONSTBUF, &vp->program,
+                             stage_state, prog_data);
 }
 
 const struct brw_tracked_state brw_vs_pull_constants = {
    .dirty = {
       .mesa = _NEW_PROGRAM_CONSTANTS,
       .brw = BRW_NEW_BATCH |
+             BRW_NEW_BLORP |
              BRW_NEW_VERTEX_PROGRAM |
              BRW_NEW_VS_PROG_DATA,
    },
@@ -143,24 +140,17 @@ brw_upload_vs_ubo_surfaces(struct brw_context *brw)
 {
    struct gl_context *ctx = &brw->ctx;
    /* _NEW_PROGRAM */
-   struct gl_shader_program *prog =
-      ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
-   bool dword_pitch;
-
-   if (!prog)
-      return;
+   struct gl_program *prog = ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
 
    /* BRW_NEW_VS_PROG_DATA */
-   dword_pitch = brw->vs.prog_data->base.simd8;
-   brw_upload_ubo_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_VERTEX],
-                           &brw->vs.base, &brw->vs.prog_data->base.base,
-                           dword_pitch);
+   brw_upload_ubo_surfaces(brw, prog, &brw->vs.base, brw->vs.base.prog_data);
 }
 
 const struct brw_tracked_state brw_vs_ubo_surfaces = {
    .dirty = {
       .mesa = _NEW_PROGRAM,
       .brw = BRW_NEW_BATCH |
+             BRW_NEW_BLORP |
              BRW_NEW_UNIFORM_BUFFER |
              BRW_NEW_VS_PROG_DATA,
    },
@@ -170,15 +160,12 @@ const struct brw_tracked_state brw_vs_ubo_surfaces = {
 static void
 brw_upload_vs_abo_surfaces(struct brw_context *brw)
 {
-   struct gl_context *ctx = &brw->ctx;
    /* _NEW_PROGRAM */
-   struct gl_shader_program *prog =
-      ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
+   const struct gl_program *vp = brw->vertex_program;
 
-   if (prog) {
+   if (vp) {
       /* BRW_NEW_VS_PROG_DATA */
-      brw_upload_abo_surfaces(brw, prog, &brw->vs.base,
-                              &brw->vs.prog_data->base.base);
+      brw_upload_abo_surfaces(brw, vp, &brw->vs.base, brw->vs.base.prog_data);
    }
 }
 
@@ -187,7 +174,33 @@ const struct brw_tracked_state brw_vs_abo_surfaces = {
       .mesa = _NEW_PROGRAM,
       .brw = BRW_NEW_ATOMIC_BUFFER |
              BRW_NEW_BATCH |
+             BRW_NEW_BLORP |
              BRW_NEW_VS_PROG_DATA,
    },
    .emit = brw_upload_vs_abo_surfaces,
 };
+
+static void
+brw_upload_vs_image_surfaces(struct brw_context *brw)
+{
+   /* BRW_NEW_VERTEX_PROGRAM */
+   const struct gl_program *vp = brw->vertex_program;
+
+   if (vp) {
+      /* BRW_NEW_VS_PROG_DATA, BRW_NEW_IMAGE_UNITS, _NEW_TEXTURE */
+      brw_upload_image_surfaces(brw, vp, &brw->vs.base,
+                                brw->vs.base.prog_data);
+   }
+}
+
+const struct brw_tracked_state brw_vs_image_surfaces = {
+   .dirty = {
+      .mesa = _NEW_TEXTURE,
+      .brw = BRW_NEW_BATCH |
+             BRW_NEW_BLORP |
+             BRW_NEW_IMAGE_UNITS |
+             BRW_NEW_VERTEX_PROGRAM |
+             BRW_NEW_VS_PROG_DATA,
+   },
+   .emit = brw_upload_vs_image_surfaces,
+};