vk: Emit color calc state
authorKristian Høgsberg <kristian.h.kristensen@intel.com>
Tue, 26 May 2015 18:22:12 +0000 (11:22 -0700)
committerKristian Høgsberg <kristian.h.kristensen@intel.com>
Tue, 26 May 2015 18:27:31 +0000 (11:27 -0700)
This involves pulling stencil ref values out of DS dynamic state and the
blend constant out of CB dynamic state.

src/vulkan/device.c
src/vulkan/private.h

index de68fa551a5f79a05ceb518765c65ff9b475cc06..4cdf3e2b8a6ef27ad1b5da27cdde4cc1703fe551 100644 (file)
@@ -2087,6 +2087,15 @@ VkResult anv_CreateDynamicColorBlendState(
    if (state == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
+   struct GEN8_COLOR_CALC_STATE color_calc_state = {
+      .BlendConstantColorRed = pCreateInfo->blendConst[0],
+      .BlendConstantColorGreen = pCreateInfo->blendConst[1],
+      .BlendConstantColorBlue = pCreateInfo->blendConst[2],
+      .BlendConstantColorAlpha = pCreateInfo->blendConst[3]
+   };
+
+   GEN8_COLOR_CALC_STATE_pack(NULL, state->state_color_calc, &color_calc_state);
+
    *pState = (VkDynamicCbState) state;
 
    return VK_SUCCESS;
@@ -2110,11 +2119,6 @@ VkResult anv_CreateDynamicDepthStencilState(
    struct GEN8_3DSTATE_WM_DEPTH_STENCIL wm_depth_stencil = {
       GEN8_3DSTATE_WM_DEPTH_STENCIL_header,
 
-      /* pCreateInfo->stencilFrontRef,
-       * pCreateInfo->stencilBackRef,
-       * go in cc state
-       */
-
       /* Is this what we need to do? */
       .StencilBufferWriteEnable = pCreateInfo->stencilWriteMask != 0,
 
@@ -2128,6 +2132,13 @@ VkResult anv_CreateDynamicDepthStencilState(
    GEN8_3DSTATE_WM_DEPTH_STENCIL_pack(NULL, state->state_wm_depth_stencil,
                                       &wm_depth_stencil);
 
+   struct GEN8_COLOR_CALC_STATE color_calc_state = {
+      .StencilReferenceValue = pCreateInfo->stencilFrontRef,
+      .BackFaceStencilReferenceValue = pCreateInfo->stencilBackRef
+   };
+
+   GEN8_COLOR_CALC_STATE_pack(NULL, state->state_color_calc, &color_calc_state);
+
    *pState = (VkDynamicDsState) state;
 
    return VK_SUCCESS;
@@ -2679,6 +2690,35 @@ flush_descriptor_sets(struct anv_cmd_buffer *cmd_buffer)
    }
 }
 
+static struct anv_state
+anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer *cmd_buffer,
+                             uint32_t *a, uint32_t dwords, uint32_t alignment)
+{
+   struct anv_device *device = cmd_buffer->device;
+   struct anv_state state;
+
+   state = anv_state_pool_alloc(&device->dynamic_state_pool, dwords * 4, alignment);
+   memcpy(state.map, a, dwords * 4);
+
+   return state;
+}
+
+static struct anv_state
+anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer *cmd_buffer,
+                             uint32_t *a, uint32_t *b, uint32_t dwords, uint32_t alignment)
+{
+   struct anv_device *device = cmd_buffer->device;
+   struct anv_state state;
+   uint32_t *p;
+
+   state = anv_state_pool_alloc(&device->dynamic_state_pool, dwords * 4, alignment);
+   p = state.map;
+   for (uint32_t i = 0; i < dwords; i++)
+      p[i] = a[i] | b[i];
+
+   return state;
+}
+
 static void
 anv_cmd_buffer_flush_state(struct anv_cmd_buffer *cmd_buffer)
 {
@@ -2731,6 +2771,24 @@ anv_cmd_buffer_flush_state(struct anv_cmd_buffer *cmd_buffer)
                            cmd_buffer->ds_state->state_wm_depth_stencil,
                            pipeline->state_wm_depth_stencil);
 
+   if (cmd_buffer->dirty & (ANV_CMD_BUFFER_CB_DIRTY | ANV_CMD_BUFFER_DS_DIRTY)) {
+      struct anv_state state;
+      if (cmd_buffer->ds_state)
+         state = anv_cmd_buffer_merge_dynamic(cmd_buffer,
+                                              cmd_buffer->ds_state->state_color_calc,
+                                              cmd_buffer->cb_state->state_color_calc,
+                                              GEN8_COLOR_CALC_STATE_length, 32);
+      else
+         state = anv_cmd_buffer_emit_dynamic(cmd_buffer,
+                                             cmd_buffer->cb_state->state_color_calc,
+                                             GEN8_COLOR_CALC_STATE_length, 32);
+
+      anv_batch_emit(&cmd_buffer->batch,
+                     GEN8_3DSTATE_CC_STATE_POINTERS,
+                     .ColorCalcStatePointer = state.offset,
+                     .ColorCalcStatePointerValid = true);
+   }
+
    cmd_buffer->vb_dirty &= ~vb_emit;
    cmd_buffer->dirty = 0;
 }
index 4e18a434828b6b6c1c7751577466f4b158a01aa2..d29b20ad6d8e749bd473ff8d736902a106b6fad8 100644 (file)
@@ -473,10 +473,12 @@ struct anv_dynamic_rs_state {
 
 struct anv_dynamic_ds_state {
    uint32_t state_wm_depth_stencil[GEN8_3DSTATE_WM_DEPTH_STENCIL_length];
+   uint32_t state_color_calc[GEN8_COLOR_CALC_STATE_length];
 };
 
 struct anv_dynamic_cb_state {
-   uint32_t blend_offset;
+   uint32_t                                     state_color_calc[GEN8_COLOR_CALC_STATE_length];
+
 };
 
 struct anv_query_pool_slot {
@@ -546,6 +548,7 @@ struct anv_buffer {
 #define ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY     (1 << 1)
 #define ANV_CMD_BUFFER_RS_DIRTY                 (1 << 2)
 #define ANV_CMD_BUFFER_DS_DIRTY                 (1 << 3)
+#define ANV_CMD_BUFFER_CB_DIRTY                 (1 << 4)
    
 struct anv_bindings {
    struct {
@@ -586,6 +589,7 @@ struct anv_cmd_buffer {
    struct anv_dynamic_rs_state *                rs_state;
    struct anv_dynamic_ds_state *                ds_state;
    struct anv_dynamic_vp_state *                vp_state;
+   struct anv_dynamic_cb_state *                cb_state;
    struct anv_bindings *                        bindings;
    struct anv_bindings                          default_bindings;
 };