From b29f44218d611dc7179a55a22ca71ff3a1624d71 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Tue, 26 May 2015 11:22:12 -0700 Subject: [PATCH] vk: Emit color calc state This involves pulling stencil ref values out of DS dynamic state and the blend constant out of CB dynamic state. --- src/vulkan/device.c | 68 ++++++++++++++++++++++++++++++++++++++++---- src/vulkan/private.h | 6 +++- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/vulkan/device.c b/src/vulkan/device.c index de68fa551a5..4cdf3e2b8a6 100644 --- a/src/vulkan/device.c +++ b/src/vulkan/device.c @@ -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; } diff --git a/src/vulkan/private.h b/src/vulkan/private.h index 4e18a434828..d29b20ad6d8 100644 --- a/src/vulkan/private.h +++ b/src/vulkan/private.h @@ -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; }; -- 2.30.2