summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2015-10-06 17:21:44 -0700
committerJason Ekstrand <[email protected]>2015-10-07 09:40:49 -0700
commitdaf68a9465050c798012125e7150017c09576e0f (patch)
treed453353b281b0ed1d7960234dbf88fe1f6ab4c83 /src
parent55fcca306b349a959feecae8f84a6b62f532114f (diff)
vk/0.170.2: Switch to the new dynamic state model
Diffstat (limited to 'src')
-rw-r--r--src/vulkan/anv_cmd_buffer.c272
-rw-r--r--src/vulkan/anv_device.c29
-rw-r--r--src/vulkan/anv_meta.c102
-rw-r--r--src/vulkan/anv_private.h73
-rw-r--r--src/vulkan/gen7_cmd_buffer.c121
-rw-r--r--src/vulkan/gen7_state.c72
-rw-r--r--src/vulkan/gen8_cmd_buffer.c116
-rw-r--r--src/vulkan/gen8_state.c83
8 files changed, 443 insertions, 425 deletions
diff --git a/src/vulkan/anv_cmd_buffer.c b/src/vulkan/anv_cmd_buffer.c
index 78b17ea15ee..8486bd05a2c 100644
--- a/src/vulkan/anv_cmd_buffer.c
+++ b/src/vulkan/anv_cmd_buffer.c
@@ -113,22 +113,16 @@ anv_dynamic_state_copy(struct anv_dynamic_state *dest,
static void
anv_cmd_state_init(struct anv_cmd_state *state)
{
- state->rs_state = NULL;
- state->vp_state = NULL;
- state->cb_state = NULL;
- state->ds_state = NULL;
memset(&state->state_vf, 0, sizeof(state->state_vf));
memset(&state->descriptors, 0, sizeof(state->descriptors));
memset(&state->push_constants, 0, sizeof(state->push_constants));
- state->dirty = 0;
+ state->dirty = ~0;
state->vb_dirty = 0;
state->descriptors_dirty = 0;
state->push_constants_dirty = 0;
state->pipeline = NULL;
- state->vp_state = NULL;
- state->rs_state = NULL;
- state->ds_state = NULL;
+ state->dynamic = default_dynamic_state;
state->gen7.index_buffer = NULL;
}
@@ -333,48 +327,128 @@ void anv_CmdBindPipeline(
}
}
-void anv_CmdBindDynamicViewportState(
+void anv_CmdSetViewport(
VkCmdBuffer cmdBuffer,
- VkDynamicViewportState dynamicViewportState)
+ uint32_t viewportCount,
+ const VkViewport* pViewports)
{
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
- ANV_FROM_HANDLE(anv_dynamic_vp_state, vp_state, dynamicViewportState);
- cmd_buffer->state.vp_state = vp_state;
- cmd_buffer->state.dirty |= ANV_CMD_BUFFER_VP_DIRTY;
+ cmd_buffer->state.dynamic.viewport.count = viewportCount;
+ memcpy(cmd_buffer->state.dynamic.viewport.viewports,
+ pViewports, viewportCount * sizeof(*pViewports));
+
+ cmd_buffer->state.dirty |= ANV_DYNAMIC_VIEWPORT_DIRTY;
+}
+
+void anv_CmdSetScissor(
+ VkCmdBuffer cmdBuffer,
+ uint32_t scissorCount,
+ const VkRect2D* pScissors)
+{
+ ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
+
+ cmd_buffer->state.dynamic.scissor.count = scissorCount;
+ memcpy(cmd_buffer->state.dynamic.scissor.scissors,
+ pScissors, scissorCount * sizeof(*pScissors));
+
+ cmd_buffer->state.dirty |= ANV_DYNAMIC_SCISSOR_DIRTY;
+}
+
+void anv_CmdSetLineWidth(
+ VkCmdBuffer cmdBuffer,
+ float lineWidth)
+{
+ ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
+
+ cmd_buffer->state.dynamic.line_width = lineWidth;
+
+ cmd_buffer->state.dirty |= ANV_DYNAMIC_LINE_WIDTH_DIRTY;
+}
+
+void anv_CmdSetDepthBias(
+ VkCmdBuffer cmdBuffer,
+ float depthBias,
+ float depthBiasClamp,
+ float slopeScaledDepthBias)
+{
+ ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
+
+ cmd_buffer->state.dynamic.depth_bias.bias = depthBias;
+ cmd_buffer->state.dynamic.depth_bias.clamp = depthBiasClamp;
+ cmd_buffer->state.dynamic.depth_bias.slope_scaled = slopeScaledDepthBias;
+
+ cmd_buffer->state.dirty |= ANV_DYNAMIC_DEPTH_BIAS_DIRTY;
+}
+
+void anv_CmdSetBlendConstants(
+ VkCmdBuffer cmdBuffer,
+ const float blendConst[4])
+{
+ ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
+
+ memcpy(cmd_buffer->state.dynamic.blend_constants,
+ blendConst, sizeof(float) * 4);
+
+ cmd_buffer->state.dirty |= ANV_DYNAMIC_BLEND_CONSTANTS_DIRTY;
+}
+
+void anv_CmdSetDepthBounds(
+ VkCmdBuffer cmdBuffer,
+ float minDepthBounds,
+ float maxDepthBounds)
+{
+ ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
+
+ cmd_buffer->state.dynamic.depth_bounds.min = minDepthBounds;
+ cmd_buffer->state.dynamic.depth_bounds.max = maxDepthBounds;
+
+ cmd_buffer->state.dirty |= ANV_DYNAMIC_DEPTH_BOUNDS_DIRTY;
}
-void anv_CmdBindDynamicRasterState(
+void anv_CmdSetStencilCompareMask(
VkCmdBuffer cmdBuffer,
- VkDynamicRasterState dynamicRasterState)
+ VkStencilFaceFlags faceMask,
+ uint32_t stencilCompareMask)
{
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
- ANV_FROM_HANDLE(anv_dynamic_rs_state, rs_state, dynamicRasterState);
- cmd_buffer->state.rs_state = rs_state;
- cmd_buffer->state.dirty |= ANV_CMD_BUFFER_RS_DIRTY;
+ if (faceMask & VK_STENCIL_FACE_FRONT_BIT)
+ cmd_buffer->state.dynamic.stencil_compare_mask.front = stencilCompareMask;
+ if (faceMask & VK_STENCIL_FACE_BACK_BIT)
+ cmd_buffer->state.dynamic.stencil_compare_mask.back = stencilCompareMask;
+
+ cmd_buffer->state.dirty |= ANV_DYNAMIC_STENCIL_COMPARE_MASK_DIRTY;
}
-void anv_CmdBindDynamicColorBlendState(
+void anv_CmdSetStencilWriteMask(
VkCmdBuffer cmdBuffer,
- VkDynamicColorBlendState dynamicColorBlendState)
+ VkStencilFaceFlags faceMask,
+ uint32_t stencilWriteMask)
{
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
- ANV_FROM_HANDLE(anv_dynamic_cb_state, cb_state, dynamicColorBlendState);
- cmd_buffer->state.cb_state = cb_state;
- cmd_buffer->state.dirty |= ANV_CMD_BUFFER_CB_DIRTY;
+ if (faceMask & VK_STENCIL_FACE_FRONT_BIT)
+ cmd_buffer->state.dynamic.stencil_write_mask.front = stencilWriteMask;
+ if (faceMask & VK_STENCIL_FACE_BACK_BIT)
+ cmd_buffer->state.dynamic.stencil_write_mask.back = stencilWriteMask;
+
+ cmd_buffer->state.dirty |= ANV_DYNAMIC_STENCIL_WRITE_MASK_DIRTY;
}
-void anv_CmdBindDynamicDepthStencilState(
+void anv_CmdSetStencilReference(
VkCmdBuffer cmdBuffer,
- VkDynamicDepthStencilState dynamicDepthStencilState)
+ VkStencilFaceFlags faceMask,
+ uint32_t stencilReference)
{
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
- ANV_FROM_HANDLE(anv_dynamic_ds_state, ds_state, dynamicDepthStencilState);
- cmd_buffer->state.ds_state = ds_state;
- cmd_buffer->state.dirty |= ANV_CMD_BUFFER_DS_DIRTY;
+ if (faceMask & VK_STENCIL_FACE_FRONT_BIT)
+ cmd_buffer->state.dynamic.stencil_reference.front = stencilReference;
+ if (faceMask & VK_STENCIL_FACE_BACK_BIT)
+ cmd_buffer->state.dynamic.stencil_reference.back = stencilReference;
+
+ cmd_buffer->state.dirty |= ANV_DYNAMIC_STENCIL_REFERENCE_DIRTY;
}
void anv_CmdBindDescriptorSets(
@@ -736,6 +810,148 @@ anv_cmd_buffer_begin_subpass(struct anv_cmd_buffer *cmd_buffer,
}
}
+static void
+emit_viewport_state(struct anv_cmd_buffer *cmd_buffer,
+ uint32_t count, const VkViewport *viewports)
+{
+ struct anv_state sf_clip_state =
+ anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, count * 64, 64);
+ struct anv_state cc_state =
+ anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, count * 8, 32);
+
+ for (uint32_t i = 0; i < count; i++) {
+ const VkViewport *vp = &viewports[i];
+
+ /* The gen7 state struct has just the matrix and guardband fields, the
+ * gen8 struct adds the min/max viewport fields. */
+ struct GEN8_SF_CLIP_VIEWPORT sf_clip_viewport = {
+ .ViewportMatrixElementm00 = vp->width / 2,
+ .ViewportMatrixElementm11 = vp->height / 2,
+ .ViewportMatrixElementm22 = (vp->maxDepth - vp->minDepth) / 2,
+ .ViewportMatrixElementm30 = vp->originX + vp->width / 2,
+ .ViewportMatrixElementm31 = vp->originY + vp->height / 2,
+ .ViewportMatrixElementm32 = (vp->maxDepth + vp->minDepth) / 2,
+ .XMinClipGuardband = -1.0f,
+ .XMaxClipGuardband = 1.0f,
+ .YMinClipGuardband = -1.0f,
+ .YMaxClipGuardband = 1.0f,
+ .XMinViewPort = vp->originX,
+ .XMaxViewPort = vp->originX + vp->width - 1,
+ .YMinViewPort = vp->originY,
+ .YMaxViewPort = vp->originY + vp->height - 1,
+ };
+
+ struct GEN7_CC_VIEWPORT cc_viewport = {
+ .MinimumDepth = vp->minDepth,
+ .MaximumDepth = vp->maxDepth
+ };
+
+ GEN8_SF_CLIP_VIEWPORT_pack(NULL, sf_clip_state.map + i * 64,
+ &sf_clip_viewport);
+ GEN7_CC_VIEWPORT_pack(NULL, cc_state.map + i * 32, &cc_viewport);
+ }
+
+ anv_batch_emit(&cmd_buffer->batch,
+ GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
+ .CCViewportPointer = cc_state.offset);
+ anv_batch_emit(&cmd_buffer->batch,
+ GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
+ .SFClipViewportPointer = sf_clip_state.offset);
+}
+
+void
+anv_cmd_buffer_emit_viewport(struct anv_cmd_buffer *cmd_buffer)
+{
+ if (cmd_buffer->state.dynamic.viewport.count > 0) {
+ emit_viewport_state(cmd_buffer, cmd_buffer->state.dynamic.viewport.count,
+ cmd_buffer->state.dynamic.viewport.viewports);
+ } else {
+ /* If viewport count is 0, this is taken to mean "use the default" */
+ emit_viewport_state(cmd_buffer, 1,
+ &(VkViewport) {
+ .originX = 0.0f,
+ .originY = 0.0f,
+ .width = cmd_buffer->state.framebuffer->width,
+ .height = cmd_buffer->state.framebuffer->height,
+ .minDepth = 0.0f,
+ .maxDepth = 1.0f,
+ });
+ }
+}
+
+static inline int64_t
+clamp_int64(int64_t x, int64_t min, int64_t max)
+{
+ if (x < min)
+ return min;
+ else if (x < max)
+ return x;
+ else
+ return max;
+}
+
+static void
+emit_scissor_state(struct anv_cmd_buffer *cmd_buffer,
+ uint32_t count, const VkRect2D *scissors)
+{
+ struct anv_state scissor_state =
+ anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, count * 32, 32);
+
+ for (uint32_t i = 0; i < count; i++) {
+ const VkRect2D *s = &scissors[i];
+
+ /* Since xmax and ymax are inclusive, we have to have xmax < xmin or
+ * ymax < ymin for empty clips. In case clip x, y, width height are all
+ * 0, the clamps below produce 0 for xmin, ymin, xmax, ymax, which isn't
+ * what we want. Just special case empty clips and produce a canonical
+ * empty clip. */
+ static const struct GEN7_SCISSOR_RECT empty_scissor = {
+ .ScissorRectangleYMin = 1,
+ .ScissorRectangleXMin = 1,
+ .ScissorRectangleYMax = 0,
+ .ScissorRectangleXMax = 0
+ };
+
+ const int max = 0xffff;
+ struct GEN7_SCISSOR_RECT scissor = {
+ /* Do this math using int64_t so overflow gets clamped correctly. */
+ .ScissorRectangleYMin = clamp_int64(s->offset.y, 0, max),
+ .ScissorRectangleXMin = clamp_int64(s->offset.x, 0, max),
+ .ScissorRectangleYMax = clamp_int64((uint64_t) s->offset.y + s->extent.height - 1, 0, max),
+ .ScissorRectangleXMax = clamp_int64((uint64_t) s->offset.x + s->extent.width - 1, 0, max)
+ };
+
+ if (s->extent.width <= 0 || s->extent.height <= 0) {
+ GEN7_SCISSOR_RECT_pack(NULL, scissor_state.map + i * 32,
+ &empty_scissor);
+ } else {
+ GEN7_SCISSOR_RECT_pack(NULL, scissor_state.map + i * 32, &scissor);
+ }
+ }
+
+ anv_batch_emit(&cmd_buffer->batch, GEN8_3DSTATE_SCISSOR_STATE_POINTERS,
+ .ScissorRectPointer = scissor_state.offset);
+}
+
+void
+anv_cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer)
+{
+ if (cmd_buffer->state.dynamic.scissor.count > 0) {
+ emit_scissor_state(cmd_buffer, cmd_buffer->state.dynamic.scissor.count,
+ cmd_buffer->state.dynamic.scissor.scissors);
+ } else {
+ /* Emit a default scissor based on the currently bound framebuffer */
+ emit_scissor_state(cmd_buffer, 1,
+ &(VkRect2D) {
+ .offset = { .x = 0, .y = 0, },
+ .extent = {
+ .width = cmd_buffer->state.framebuffer->width,
+ .height = cmd_buffer->state.framebuffer->height,
+ },
+ });
+ }
+}
+
void anv_CmdSetEvent(
VkCmdBuffer cmdBuffer,
VkEvent event,
diff --git a/src/vulkan/anv_device.c b/src/vulkan/anv_device.c
index b10cc4512b4..aec900065e6 100644
--- a/src/vulkan/anv_device.c
+++ b/src/vulkan/anv_device.c
@@ -389,7 +389,7 @@ VkResult anv_GetPhysicalDeviceLimits(
.primitiveRestartForPatches = UINT32_MAX,
.maxSamplerLodBias = 16,
.maxSamplerAnisotropy = 16,
- .maxViewports = 16,
+ .maxViewports = MAX_VIEWPORTS,
.maxDynamicViewportStates = UINT32_MAX,
.maxViewportDimensions = { (1 << 14), (1 << 14) },
.viewportBoundsRange = { -1.0, 1.0 }, /* FIXME */
@@ -1778,6 +1778,8 @@ VkResult anv_UpdateDescriptorSets(
// State object functions
+#if 0
+
static inline int64_t
clamp_int64(int64_t x, int64_t min, int64_t max)
{
@@ -1949,6 +1951,8 @@ void anv_DestroyDynamicDepthStencilState(
anv_device_free(device, ds_state);
}
+#endif
+
VkResult anv_CreateFramebuffer(
VkDevice _device,
const VkFramebufferCreateInfo* pCreateInfo,
@@ -1976,27 +1980,6 @@ VkResult anv_CreateFramebuffer(
framebuffer->height = pCreateInfo->height;
framebuffer->layers = pCreateInfo->layers;
- anv_CreateDynamicViewportState(anv_device_to_handle(device),
- &(VkDynamicViewportStateCreateInfo) {
- .sType = VK_STRUCTURE_TYPE_DYNAMIC_VIEWPORT_STATE_CREATE_INFO,
- .viewportAndScissorCount = 1,
- .pViewports = (VkViewport[]) {
- {
- .originX = 0,
- .originY = 0,
- .width = pCreateInfo->width,
- .height = pCreateInfo->height,
- .minDepth = 0,
- .maxDepth = 1
- },
- },
- .pScissors = (VkRect2D[]) {
- { { 0, 0 },
- { pCreateInfo->width, pCreateInfo->height } },
- }
- },
- &framebuffer->vp_state);
-
*pFramebuffer = anv_framebuffer_to_handle(framebuffer);
return VK_SUCCESS;
@@ -2009,8 +1992,6 @@ void anv_DestroyFramebuffer(
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_framebuffer, fb, _fb);
- anv_DestroyDynamicViewportState(anv_device_to_handle(device),
- fb->vp_state);
anv_device_free(device, fb);
}
diff --git a/src/vulkan/anv_meta.c b/src/vulkan/anv_meta.c
index c0e4112f363..565575ab219 100644
--- a/src/vulkan/anv_meta.c
+++ b/src/vulkan/anv_meta.c
@@ -293,20 +293,22 @@ struct anv_saved_state {
struct anv_vertex_binding old_vertex_bindings[NUM_VB_USED];
struct anv_descriptor_set *old_descriptor_set0;
struct anv_pipeline *old_pipeline;
- struct anv_dynamic_ds_state *old_ds_state;
- struct anv_dynamic_cb_state *old_cb_state;
+ uint32_t dynamic_flags;
+ struct anv_dynamic_state dynamic;
};
static void
anv_cmd_buffer_save(struct anv_cmd_buffer *cmd_buffer,
- struct anv_saved_state *state)
+ struct anv_saved_state *state,
+ uint32_t dynamic_state)
{
state->old_pipeline = cmd_buffer->state.pipeline;
state->old_descriptor_set0 = cmd_buffer->state.descriptors[0].set;
memcpy(state->old_vertex_bindings, cmd_buffer->state.vertex_bindings,
sizeof(state->old_vertex_bindings));
- state->old_ds_state = cmd_buffer->state.ds_state;
- state->old_cb_state = cmd_buffer->state.cb_state;
+ state->dynamic_flags = dynamic_state;
+ anv_dynamic_state_copy(&state->dynamic, &cmd_buffer->state.dynamic,
+ dynamic_state);
}
static void
@@ -322,15 +324,9 @@ anv_cmd_buffer_restore(struct anv_cmd_buffer *cmd_buffer,
cmd_buffer->state.dirty |= ANV_CMD_BUFFER_PIPELINE_DIRTY;
cmd_buffer->state.descriptors_dirty |= VK_SHADER_STAGE_VERTEX_BIT;
- if (cmd_buffer->state.ds_state != state->old_ds_state) {
- cmd_buffer->state.ds_state = state->old_ds_state;
- cmd_buffer->state.dirty |= ANV_CMD_BUFFER_DS_DIRTY;
- }
-
- if (cmd_buffer->state.cb_state != state->old_cb_state) {
- cmd_buffer->state.cb_state = state->old_cb_state;
- cmd_buffer->state.dirty |= ANV_CMD_BUFFER_CB_DIRTY;
- }
+ anv_dynamic_state_copy(&cmd_buffer->state.dynamic, &state->dynamic,
+ state->dynamic_flags);
+ cmd_buffer->state.dirty |= state->dynamic_flags;
}
struct vue_header {
@@ -396,23 +392,6 @@ meta_emit_clear(struct anv_cmd_buffer *cmd_buffer,
VK_PIPELINE_BIND_POINT_GRAPHICS,
device->meta_state.clear.pipeline);
- /* We don't need anything here, only set if not already set. */
- if (cmd_buffer->state.rs_state == NULL)
- anv_CmdBindDynamicRasterState(anv_cmd_buffer_to_handle(cmd_buffer),
- device->meta_state.shared.rs_state);
-
- if (cmd_buffer->state.vp_state == NULL)
- anv_CmdBindDynamicViewportState(anv_cmd_buffer_to_handle(cmd_buffer),
- cmd_buffer->state.framebuffer->vp_state);
-
- if (cmd_buffer->state.ds_state == NULL)
- anv_CmdBindDynamicDepthStencilState(anv_cmd_buffer_to_handle(cmd_buffer),
- device->meta_state.shared.ds_state);
-
- if (cmd_buffer->state.cb_state == NULL)
- anv_CmdBindDynamicColorBlendState(anv_cmd_buffer_to_handle(cmd_buffer),
- device->meta_state.shared.cb_state);
-
ANV_CALL(CmdDraw)(anv_cmd_buffer_to_handle(cmd_buffer),
3, num_instances, 0, 0);
}
@@ -466,7 +445,9 @@ anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer *cmd_buffer,
}
}
- anv_cmd_buffer_save(cmd_buffer, &saved_state);
+ anv_cmd_buffer_save(cmd_buffer, &saved_state,
+ (1 << VK_DYNAMIC_STATE_VIEWPORT));
+ cmd_buffer->state.dynamic.viewport.count = 0;
struct anv_subpass subpass = {
.input_count = 0,
@@ -703,20 +684,8 @@ static void
meta_prepare_blit(struct anv_cmd_buffer *cmd_buffer,
struct anv_saved_state *saved_state)
{
- struct anv_device *device = cmd_buffer->device;
-
- anv_cmd_buffer_save(cmd_buffer, saved_state);
-
- /* We don't need anything here, only set if not already set. */
- if (cmd_buffer->state.rs_state == NULL)
- anv_CmdBindDynamicRasterState(anv_cmd_buffer_to_handle(cmd_buffer),
- device->meta_state.shared.rs_state);
- if (cmd_buffer->state.ds_state == NULL)
- anv_CmdBindDynamicDepthStencilState(anv_cmd_buffer_to_handle(cmd_buffer),
- device->meta_state.shared.ds_state);
-
- anv_CmdBindDynamicColorBlendState(anv_cmd_buffer_to_handle(cmd_buffer),
- device->meta_state.shared.cb_state);
+ anv_cmd_buffer_save(cmd_buffer, saved_state,
+ (1 << VK_DYNAMIC_STATE_VIEWPORT));
}
struct blit_region {
@@ -913,8 +882,15 @@ meta_emit_blit(struct anv_cmd_buffer *cmd_buffer,
VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
}
- anv_CmdBindDynamicViewportState(anv_cmd_buffer_to_handle(cmd_buffer),
- anv_framebuffer_from_handle(fb)->vp_state);
+ anv_CmdSetViewport(anv_cmd_buffer_to_handle(cmd_buffer), 1,
+ &(VkViewport) {
+ .originX = 0.0f,
+ .originY = 0.0f,
+ .width = dest_iview->extent.width,
+ .height = dest_iview->extent.height,
+ .minDepth = 0.0f,
+ .maxDepth = 1.0f,
+ });
anv_CmdBindDescriptorSets(anv_cmd_buffer_to_handle(cmd_buffer),
VK_PIPELINE_BIND_POINT_GRAPHICS,
@@ -1604,7 +1580,9 @@ void anv_CmdClearColorImage(
ANV_FROM_HANDLE(anv_image, image, _image);
struct anv_saved_state saved_state;
- anv_cmd_buffer_save(cmd_buffer, &saved_state);
+ anv_cmd_buffer_save(cmd_buffer, &saved_state,
+ (1 << VK_DYNAMIC_STATE_VIEWPORT));
+ cmd_buffer->state.dynamic.viewport.count = 0;
for (uint32_t r = 0; r < rangeCount; r++) {
for (uint32_t l = 0; l < pRanges[r].mipLevels; l++) {
@@ -1769,24 +1747,6 @@ anv_device_init_meta(struct anv_device *device)
{
anv_device_init_meta_clear_state(device);
anv_device_init_meta_blit_state(device);
-
- ANV_CALL(CreateDynamicRasterState)(anv_device_to_handle(device),
- &(VkDynamicRasterStateCreateInfo) {
- .sType = VK_STRUCTURE_TYPE_DYNAMIC_RASTER_STATE_CREATE_INFO,
- },
- &device->meta_state.shared.rs_state);
-
- ANV_CALL(CreateDynamicColorBlendState)(anv_device_to_handle(device),
- &(VkDynamicColorBlendStateCreateInfo) {
- .sType = VK_STRUCTURE_TYPE_DYNAMIC_COLOR_BLEND_STATE_CREATE_INFO
- },
- &device->meta_state.shared.cb_state);
-
- ANV_CALL(CreateDynamicDepthStencilState)(anv_device_to_handle(device),
- &(VkDynamicDepthStencilStateCreateInfo) {
- .sType = VK_STRUCTURE_TYPE_DYNAMIC_DEPTH_STENCIL_STATE_CREATE_INFO
- },
- &device->meta_state.shared.ds_state);
}
void
@@ -1805,12 +1765,4 @@ anv_device_finish_meta(struct anv_device *device)
device->meta_state.blit.pipeline_layout);
anv_DestroyDescriptorSetLayout(anv_device_to_handle(device),
device->meta_state.blit.ds_layout);
-
- /* Shared */
- anv_DestroyDynamicRasterState(anv_device_to_handle(device),
- device->meta_state.shared.rs_state);
- anv_DestroyDynamicColorBlendState(anv_device_to_handle(device),
- device->meta_state.shared.cb_state);
- anv_DestroyDynamicDepthStencilState(anv_device_to_handle(device),
- device->meta_state.shared.ds_state);
}
diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h
index 047c1cf4355..3d47739aae7 100644
--- a/src/vulkan/anv_private.h
+++ b/src/vulkan/anv_private.h
@@ -450,12 +450,6 @@ struct anv_meta_state {
VkPipelineLayout pipeline_layout;
VkDescriptorSetLayout ds_layout;
} blit;
-
- struct {
- VkDynamicRasterState rs_state;
- VkDynamicColorBlendState cb_state;
- VkDynamicDepthStencilState ds_state;
- } shared;
};
struct anv_queue {
@@ -680,40 +674,6 @@ struct anv_device_memory {
void * map;
};
-struct anv_dynamic_vp_state {
- struct anv_state sf_clip_vp;
- struct anv_state cc_vp;
- struct anv_state scissor;
-};
-
-struct anv_dynamic_rs_state {
- struct {
- uint32_t sf[GEN7_3DSTATE_SF_length];
- } gen7;
-
- struct {
- uint32_t sf[GEN8_3DSTATE_SF_length];
- uint32_t raster[GEN8_3DSTATE_RASTER_length];
- } gen8;
-};
-
-struct anv_dynamic_ds_state {
- struct {
- uint32_t depth_stencil_state[GEN7_DEPTH_STENCIL_STATE_length];
- uint32_t color_calc_state[GEN8_COLOR_CALC_STATE_length];
- } gen7;
-
- struct {
- uint32_t wm_depth_stencil[GEN8_3DSTATE_WM_DEPTH_STENCIL_length];
- uint32_t color_calc_state[GEN8_COLOR_CALC_STATE_length];
- } gen8;
-};
-
-struct anv_dynamic_cb_state {
- uint32_t color_calc_state[GEN8_COLOR_CALC_STATE_length];
-
-};
-
struct anv_descriptor_slot {
int8_t dynamic_slot;
uint8_t index;
@@ -800,12 +760,18 @@ struct anv_buffer {
VkDeviceSize offset;
};
-#define ANV_CMD_BUFFER_PIPELINE_DIRTY (1 << 0)
-#define ANV_CMD_BUFFER_RS_DIRTY (1 << 2)
-#define ANV_CMD_BUFFER_DS_DIRTY (1 << 3)
-#define ANV_CMD_BUFFER_CB_DIRTY (1 << 4)
-#define ANV_CMD_BUFFER_VP_DIRTY (1 << 5)
-#define ANV_CMD_BUFFER_INDEX_BUFFER_DIRTY (1 << 6)
+/* The first 9 correspond to 1 << VK_DYNAMIC_STATE_FOO */
+#define ANV_DYNAMIC_VIEWPORT_DIRTY (1 << 0)
+#define ANV_DYNAMIC_SCISSOR_DIRTY (1 << 1)
+#define ANV_DYNAMIC_LINE_WIDTH_DIRTY (1 << 2)
+#define ANV_DYNAMIC_DEPTH_BIAS_DIRTY (1 << 3)
+#define ANV_DYNAMIC_BLEND_CONSTANTS_DIRTY (1 << 4)
+#define ANV_DYNAMIC_DEPTH_BOUNDS_DIRTY (1 << 5)
+#define ANV_DYNAMIC_STENCIL_COMPARE_MASK_DIRTY (1 << 6)
+#define ANV_DYNAMIC_STENCIL_WRITE_MASK_DIRTY (1 << 7)
+#define ANV_DYNAMIC_STENCIL_REFERENCE_DIRTY (1 << 8)
+#define ANV_CMD_BUFFER_PIPELINE_DIRTY (1 << 9)
+#define ANV_CMD_BUFFER_INDEX_BUFFER_DIRTY (1 << 10)
struct anv_vertex_binding {
struct anv_buffer * buffer;
@@ -903,14 +869,11 @@ struct anv_cmd_state {
struct anv_framebuffer * framebuffer;
struct anv_render_pass * pass;
struct anv_subpass * subpass;
- 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;
uint32_t state_vf[GEN8_3DSTATE_VF_length];
struct anv_vertex_binding vertex_bindings[MAX_VBS];
struct anv_descriptor_set_binding descriptors[MAX_SETS];
struct anv_push_constants * push_constants[VK_SHADER_STAGE_NUM];
+ struct anv_dynamic_state dynamic;
struct {
struct anv_buffer * index_buffer;
@@ -1028,6 +991,9 @@ anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer *cmd_buffer,
VkResult
anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer *cmd_buffer);
+void anv_cmd_buffer_emit_viewport(struct anv_cmd_buffer *cmd_buffer);
+void anv_cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer);
+
void gen7_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
void gen8_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
@@ -1369,9 +1335,6 @@ struct anv_framebuffer {
uint32_t height;
uint32_t layers;
- /* Viewport for clears */
- VkDynamicViewportState vp_state;
-
uint32_t attachment_count;
const struct anv_image_view * attachments[0];
};
@@ -1464,10 +1427,6 @@ ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view, VkBufferView);
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set, VkDescriptorSet)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout, VkDescriptorSetLayout)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory, VkDeviceMemory)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_cb_state, VkDynamicColorBlendState)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_ds_state, VkDynamicDepthStencilState)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_rs_state, VkDynamicRasterState)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_vp_state, VkDynamicViewportState)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence, VkFence)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer, VkFramebuffer)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image, VkImage)
diff --git a/src/vulkan/gen7_cmd_buffer.c b/src/vulkan/gen7_cmd_buffer.c
index 709e82e78a0..0106aa74aa6 100644
--- a/src/vulkan/gen7_cmd_buffer.c
+++ b/src/vulkan/gen7_cmd_buffer.c
@@ -256,60 +256,87 @@ gen7_cmd_buffer_flush_state(struct anv_cmd_buffer *cmd_buffer)
if (cmd_buffer->state.descriptors_dirty)
anv_flush_descriptor_sets(cmd_buffer);
- if (cmd_buffer->state.dirty & ANV_CMD_BUFFER_VP_DIRTY) {
- struct anv_dynamic_vp_state *vp_state = cmd_buffer->state.vp_state;
- anv_batch_emit(&cmd_buffer->batch, GEN7_3DSTATE_SCISSOR_STATE_POINTERS,
- .ScissorRectPointer = vp_state->scissor.offset);
- anv_batch_emit(&cmd_buffer->batch, GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
- .CCViewportPointer = vp_state->cc_vp.offset);
- anv_batch_emit(&cmd_buffer->batch, GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
- .SFClipViewportPointer = vp_state->sf_clip_vp.offset);
+ if (cmd_buffer->state.dirty & ANV_DYNAMIC_VIEWPORT_DIRTY)
+ anv_cmd_buffer_emit_viewport(cmd_buffer);
+
+ if (cmd_buffer->state.dirty & ANV_DYNAMIC_SCISSOR_DIRTY)
+ anv_cmd_buffer_emit_scissor(cmd_buffer);
+
+ if (cmd_buffer->state.dirty & (ANV_CMD_BUFFER_PIPELINE_DIRTY |
+ ANV_DYNAMIC_LINE_WIDTH_DIRTY |
+ ANV_DYNAMIC_DEPTH_BIAS_DIRTY)) {
+
+ bool enable_bias = cmd_buffer->state.dynamic.depth_bias.bias != 0.0f ||
+ cmd_buffer->state.dynamic.depth_bias.slope_scaled != 0.0f;
+
+ uint32_t sf_dw[GEN8_3DSTATE_SF_length];
+ struct GEN7_3DSTATE_SF sf = {
+ GEN7_3DSTATE_SF_header,
+ .LineWidth = cmd_buffer->state.dynamic.line_width,
+ .GlobalDepthOffsetEnableSolid = enable_bias,
+ .GlobalDepthOffsetEnableWireframe = enable_bias,
+ .GlobalDepthOffsetEnablePoint = enable_bias,
+ .GlobalDepthOffsetConstant = cmd_buffer->state.dynamic.depth_bias.bias,
+ .GlobalDepthOffsetScale = cmd_buffer->state.dynamic.depth_bias.slope_scaled,
+ .GlobalDepthOffsetClamp = cmd_buffer->state.dynamic.depth_bias.clamp
+ };
+ GEN7_3DSTATE_SF_pack(NULL, sf_dw, &sf);
+
+ anv_batch_emit_merge(&cmd_buffer->batch, sf_dw, pipeline->gen7.sf);
}
- if (cmd_buffer->state.dirty &
- (ANV_CMD_BUFFER_PIPELINE_DIRTY | ANV_CMD_BUFFER_RS_DIRTY)) {
- anv_batch_emit_merge(&cmd_buffer->batch,
- cmd_buffer->state.rs_state->gen7.sf,
- pipeline->gen7.sf);
- }
+ if (cmd_buffer->state.dirty & (ANV_DYNAMIC_BLEND_CONSTANTS_DIRTY |
+ ANV_DYNAMIC_STENCIL_REFERENCE_DIRTY)) {
+ struct anv_state cc_state =
+ anv_cmd_buffer_alloc_dynamic_state(cmd_buffer,
+ GEN7_COLOR_CALC_STATE_length, 64);
+ struct GEN7_COLOR_CALC_STATE cc = {
+ .BlendConstantColorRed = cmd_buffer->state.dynamic.blend_constants[0],
+ .BlendConstantColorGreen = cmd_buffer->state.dynamic.blend_constants[1],
+ .BlendConstantColorBlue = cmd_buffer->state.dynamic.blend_constants[2],
+ .BlendConstantColorAlpha = cmd_buffer->state.dynamic.blend_constants[3],
+ .StencilReferenceValue =
+ cmd_buffer->state.dynamic.stencil_reference.front,
+ .BackFaceStencilReferenceValue =
+ cmd_buffer->state.dynamic.stencil_reference.back,
+ };
+ GEN7_COLOR_CALC_STATE_pack(NULL, cc_state.map, &cc);
- if (cmd_buffer->state.dirty &
- (ANV_CMD_BUFFER_PIPELINE_DIRTY | ANV_CMD_BUFFER_DS_DIRTY)) {
- struct anv_state state;
-
- if (cmd_buffer->state.ds_state == NULL)
- state = anv_cmd_buffer_emit_dynamic(cmd_buffer,
- pipeline->gen7.depth_stencil_state,
- GEN7_COLOR_CALC_STATE_length, 64);
- else
- state = anv_cmd_buffer_merge_dynamic(cmd_buffer,
- cmd_buffer->state.ds_state->gen7.depth_stencil_state,
- pipeline->gen7.depth_stencil_state,
- GEN7_DEPTH_STENCIL_STATE_length, 64);
- anv_batch_emit(&cmd_buffer->batch, GEN7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
- .PointertoDEPTH_STENCIL_STATE = state.offset);
+ anv_batch_emit(&cmd_buffer->batch,
+ GEN7_3DSTATE_CC_STATE_POINTERS,
+ .ColorCalcStatePointer = cc_state.offset);
}
- if (cmd_buffer->state.dirty &
- (ANV_CMD_BUFFER_CB_DIRTY | ANV_CMD_BUFFER_DS_DIRTY)) {
- struct anv_state state;
- if (cmd_buffer->state.ds_state == NULL)
- state = anv_cmd_buffer_emit_dynamic(cmd_buffer,
- cmd_buffer->state.cb_state->color_calc_state,
- GEN7_COLOR_CALC_STATE_length, 64);
- else if (cmd_buffer->state.cb_state == NULL)
- state = anv_cmd_buffer_emit_dynamic(cmd_buffer,
- cmd_buffer->state.ds_state->gen7.color_calc_state,
- GEN7_COLOR_CALC_STATE_length, 64);
- else
- state = anv_cmd_buffer_merge_dynamic(cmd_buffer,
- cmd_buffer->state.ds_state->gen7.color_calc_state,
- cmd_buffer->state.cb_state->color_calc_state,
- GEN7_COLOR_CALC_STATE_length, 64);
+ if (cmd_buffer->state.dirty & (ANV_CMD_BUFFER_PIPELINE_DIRTY |
+ ANV_DYNAMIC_STENCIL_COMPARE_MASK_DIRTY |
+ ANV_DYNAMIC_STENCIL_WRITE_MASK_DIRTY)) {
+ uint32_t depth_stencil_dw[GEN7_DEPTH_STENCIL_STATE_length];
+
+ struct GEN7_DEPTH_STENCIL_STATE depth_stencil = {
+ /* Is this what we need to do? */
+ .StencilBufferWriteEnable =
+ cmd_buffer->state.dynamic.stencil_write_mask.front != 0,
+
+ .StencilTestMask =
+ cmd_buffer->state.dynamic.stencil_compare_mask.front & 0xff,
+ .StencilWriteMask =
+ cmd_buffer->state.dynamic.stencil_write_mask.front & 0xff,
+
+ .BackfaceStencilTestMask =
+ cmd_buffer->state.dynamic.stencil_compare_mask.back & 0xff,
+ .BackfaceStencilWriteMask =
+ cmd_buffer->state.dynamic.stencil_write_mask.back & 0xff,
+ };
+ GEN7_DEPTH_STENCIL_STATE_pack(NULL, depth_stencil_dw, &depth_stencil);
+
+ struct anv_state ds_state =
+ anv_cmd_buffer_merge_dynamic(cmd_buffer, depth_stencil_dw,
+ pipeline->gen7.depth_stencil_state,
+ GEN7_DEPTH_STENCIL_STATE_length, 64);
anv_batch_emit(&cmd_buffer->batch,
- GEN7_3DSTATE_CC_STATE_POINTERS,
- .ColorCalcStatePointer = state.offset);
+ GEN7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
+ .PointertoDEPTH_STENCIL_STATE = ds_state.offset);
}
if (cmd_buffer->state.gen7.index_buffer &&
diff --git a/src/vulkan/gen7_state.c b/src/vulkan/gen7_state.c
index 2497e39490d..d317fa4ec16 100644
--- a/src/vulkan/gen7_state.c
+++ b/src/vulkan/gen7_state.c
@@ -192,78 +192,6 @@ VkResult gen7_CreateSampler(
return VK_SUCCESS;
}
-VkResult gen7_CreateDynamicRasterState(
- VkDevice _device,
- const VkDynamicRasterStateCreateInfo* pCreateInfo,
- VkDynamicRasterState* pState)
-{
- ANV_FROM_HANDLE(anv_device, device, _device);
- struct anv_dynamic_rs_state *state;
-
- assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DYNAMIC_RASTER_STATE_CREATE_INFO);
-
- state = anv_device_alloc(device, sizeof(*state), 8,
- VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
- if (state == NULL)
- return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
-
- bool enable_bias = pCreateInfo->depthBias != 0.0f ||
- pCreateInfo->slopeScaledDepthBias != 0.0f;
-
- struct GEN7_3DSTATE_SF sf = {
- GEN7_3DSTATE_SF_header,
- .LineWidth = pCreateInfo->lineWidth,
- .GlobalDepthOffsetEnableSolid = enable_bias,
- .GlobalDepthOffsetEnableWireframe = enable_bias,
- .GlobalDepthOffsetEnablePoint = enable_bias,
- .GlobalDepthOffsetConstant = pCreateInfo->depthBias,
- .GlobalDepthOffsetScale = pCreateInfo->slopeScaledDepthBias,
- .GlobalDepthOffsetClamp = pCreateInfo->depthBiasClamp
- };
-
- GEN7_3DSTATE_SF_pack(NULL, state->gen7.sf, &sf);
-
- *pState = anv_dynamic_rs_state_to_handle(state);
-
- return VK_SUCCESS;
-}
-
-VkResult gen7_CreateDynamicDepthStencilState(
- VkDevice _device,
- const VkDynamicDepthStencilStateCreateInfo* pCreateInfo,
- VkDynamicDepthStencilState* pState)
-{
- ANV_FROM_HANDLE(anv_device, device, _device);
- struct anv_dynamic_ds_state *state;
-
- assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DYNAMIC_DEPTH_STENCIL_STATE_CREATE_INFO);
-
- state = anv_device_alloc(device, sizeof(*state), 8,
- VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
- if (state == NULL)
- return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
-
- struct GEN7_DEPTH_STENCIL_STATE depth_stencil_state = {
- .StencilTestMask = pCreateInfo->stencilReadMask & 0xff,
- .StencilWriteMask = pCreateInfo->stencilWriteMask & 0xff,
- .BackfaceStencilTestMask = pCreateInfo->stencilReadMask & 0xff,
- .BackfaceStencilWriteMask = pCreateInfo->stencilWriteMask & 0xff,
- };
-
- GEN7_DEPTH_STENCIL_STATE_pack(NULL, state->gen7.depth_stencil_state,
- &depth_stencil_state);
-
- struct GEN7_COLOR_CALC_STATE color_calc_state = {
- .StencilReferenceValue = pCreateInfo->stencilFrontRef,
- .BackFaceStencilReferenceValue = pCreateInfo->stencilBackRef
- };
-
- GEN7_COLOR_CALC_STATE_pack(NULL, state->gen7.color_calc_state, &color_calc_state);
-
- *pState = anv_dynamic_ds_state_to_handle(state);
-
- return VK_SUCCESS;
-}
static const uint8_t anv_halign[] = {
[4] = HALIGN_4,
diff --git a/src/vulkan/gen8_cmd_buffer.c b/src/vulkan/gen8_cmd_buffer.c
index 1cd4a8561e6..a1db0170c09 100644
--- a/src/vulkan/gen8_cmd_buffer.c
+++ b/src/vulkan/gen8_cmd_buffer.c
@@ -121,58 +121,96 @@ gen8_cmd_buffer_flush_state(struct anv_cmd_buffer *cmd_buffer)
if (cmd_buffer->state.push_constants_dirty)
gen8_cmd_buffer_flush_push_constants(cmd_buffer);
- if (cmd_buffer->state.dirty & ANV_CMD_BUFFER_VP_DIRTY) {
- struct anv_dynamic_vp_state *vp_state = cmd_buffer->state.vp_state;
- anv_batch_emit(&cmd_buffer->batch, GEN8_3DSTATE_SCISSOR_STATE_POINTERS,
- .ScissorRectPointer = vp_state->scissor.offset);
- anv_batch_emit(&cmd_buffer->batch, GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
- .CCViewportPointer = vp_state->cc_vp.offset);
- anv_batch_emit(&cmd_buffer->batch, GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
- .SFClipViewportPointer = vp_state->sf_clip_vp.offset);
- }
+ if (cmd_buffer->state.dirty & ANV_DYNAMIC_VIEWPORT_DIRTY)
+ anv_cmd_buffer_emit_viewport(cmd_buffer);
+
+ if (cmd_buffer->state.dirty & ANV_DYNAMIC_SCISSOR_DIRTY)
+ anv_cmd_buffer_emit_scissor(cmd_buffer);
if (cmd_buffer->state.dirty & (ANV_CMD_BUFFER_PIPELINE_DIRTY |
- ANV_CMD_BUFFER_RS_DIRTY)) {
- anv_batch_emit_merge(&cmd_buffer->batch,
- cmd_buffer->state.rs_state->gen8.sf,
- pipeline->gen8.sf);
- anv_batch_emit_merge(&cmd_buffer->batch,
- cmd_buffer->state.rs_state->gen8.raster,
- pipeline->gen8.raster);
+ ANV_DYNAMIC_LINE_WIDTH_DIRTY)) {
+ uint32_t sf_dw[GEN8_3DSTATE_SF_length];
+ struct GEN8_3DSTATE_SF sf = {
+ GEN8_3DSTATE_SF_header,
+ .LineWidth = cmd_buffer->state.dynamic.line_width,
+ };
+ GEN8_3DSTATE_SF_pack(NULL, sf_dw, &sf);
+ anv_batch_emit_merge(&cmd_buffer->batch, sf_dw, pipeline->gen8.sf);
}
- if (cmd_buffer->state.ds_state &&
- (cmd_buffer->state.dirty & (ANV_CMD_BUFFER_PIPELINE_DIRTY |
- ANV_CMD_BUFFER_DS_DIRTY))) {
- anv_batch_emit_merge(&cmd_buffer->batch,
- cmd_buffer->state.ds_state->gen8.wm_depth_stencil,
- pipeline->gen8.wm_depth_stencil);
+ if (cmd_buffer->state.dirty & (ANV_CMD_BUFFER_PIPELINE_DIRTY |
+ ANV_DYNAMIC_DEPTH_BIAS_DIRTY)) {
+ bool enable_bias = cmd_buffer->state.dynamic.depth_bias.bias != 0.0f ||
+ cmd_buffer->state.dynamic.depth_bias.slope_scaled != 0.0f;
+
+ uint32_t raster_dw[GEN8_3DSTATE_RASTER_length];
+ struct GEN8_3DSTATE_RASTER raster = {
+ GEN8_3DSTATE_RASTER_header,
+ .GlobalDepthOffsetEnableSolid = enable_bias,
+ .GlobalDepthOffsetEnableWireframe = enable_bias,
+ .GlobalDepthOffsetEnablePoint = enable_bias,
+ .GlobalDepthOffsetConstant = cmd_buffer->state.dynamic.depth_bias.bias,
+ .GlobalDepthOffsetScale = cmd_buffer->state.dynamic.depth_bias.slope_scaled,
+ .GlobalDepthOffsetClamp = cmd_buffer->state.dynamic.depth_bias.clamp
+ };
+ GEN8_3DSTATE_RASTER_pack(NULL, raster_dw, &raster);
+ anv_batch_emit_merge(&cmd_buffer->batch, raster_dw,
+ pipeline->gen8.raster);
}
- if (cmd_buffer->state.dirty & (ANV_CMD_BUFFER_CB_DIRTY |
- ANV_CMD_BUFFER_DS_DIRTY)) {
- struct anv_state state;
- if (cmd_buffer->state.ds_state == NULL)
- state = anv_cmd_buffer_emit_dynamic(cmd_buffer,
- cmd_buffer->state.cb_state->color_calc_state,
- GEN8_COLOR_CALC_STATE_length, 64);
- else if (cmd_buffer->state.cb_state == NULL)
- state = anv_cmd_buffer_emit_dynamic(cmd_buffer,
- cmd_buffer->state.ds_state->gen8.color_calc_state,
- GEN8_COLOR_CALC_STATE_length, 64);
- else
- state = anv_cmd_buffer_merge_dynamic(cmd_buffer,
- cmd_buffer->state.ds_state->gen8.color_calc_state,
- cmd_buffer->state.cb_state->color_calc_state,
- GEN8_COLOR_CALC_STATE_length, 64);
+ if (cmd_buffer->state.dirty & (ANV_DYNAMIC_BLEND_CONSTANTS_DIRTY |
+ ANV_DYNAMIC_STENCIL_REFERENCE_DIRTY)) {
+ struct anv_state cc_state =
+ anv_cmd_buffer_alloc_dynamic_state(cmd_buffer,
+ GEN8_COLOR_CALC_STATE_length, 64);
+ struct GEN8_COLOR_CALC_STATE cc = {
+ .BlendConstantColorRed = cmd_buffer->state.dynamic.blend_constants[0],
+ .BlendConstantColorGreen = cmd_buffer->state.dynamic.blend_constants[1],
+ .BlendConstantColorBlue = cmd_buffer->state.dynamic.blend_constants[2],
+ .BlendConstantColorAlpha = cmd_buffer->state.dynamic.blend_constants[3],
+ .StencilReferenceValue =
+ cmd_buffer->state.dynamic.stencil_reference.front,
+ .BackFaceStencilReferenceValue =
+ cmd_buffer->state.dynamic.stencil_reference.back,
+ };
+ GEN8_COLOR_CALC_STATE_pack(NULL, cc_state.map, &cc);
anv_batch_emit(&cmd_buffer->batch,
GEN8_3DSTATE_CC_STATE_POINTERS,
- .ColorCalcStatePointer = state.offset,
+ .ColorCalcStatePointer = cc_state.offset,
.ColorCalcStatePointerValid = true);
}
if (cmd_buffer->state.dirty & (ANV_CMD_BUFFER_PIPELINE_DIRTY |
+ ANV_DYNAMIC_STENCIL_COMPARE_MASK_DIRTY |
+ ANV_DYNAMIC_STENCIL_WRITE_MASK_DIRTY)) {
+ uint32_t wm_depth_stencil_dw[GEN8_3DSTATE_WM_DEPTH_STENCIL_length];
+
+ struct GEN8_3DSTATE_WM_DEPTH_STENCIL wm_depth_stencil = {
+ GEN8_3DSTATE_WM_DEPTH_STENCIL_header,
+
+ /* Is this what we need to do? */
+ .StencilBufferWriteEnable =
+ cmd_buffer->state.dynamic.stencil_write_mask.front != 0,
+
+ .StencilTestMask =
+ cmd_buffer->state.dynamic.stencil_compare_mask.front & 0xff,
+ .StencilWriteMask =
+ cmd_buffer->state.dynamic.stencil_write_mask.front & 0xff,
+
+ .BackfaceStencilTestMask =
+ cmd_buffer->state.dynamic.stencil_compare_mask.back & 0xff,
+ .BackfaceStencilWriteMask =
+ cmd_buffer->state.dynamic.stencil_write_mask.back & 0xff,
+ };
+ GEN8_3DSTATE_WM_DEPTH_STENCIL_pack(NULL, wm_depth_stencil_dw,
+ &wm_depth_stencil);
+
+ anv_batch_emit_merge(&cmd_buffer->batch, wm_depth_stencil_dw,
+ pipeline->gen8.wm_depth_stencil);
+ }
+
+ if (cmd_buffer->state.dirty & (ANV_CMD_BUFFER_PIPELINE_DIRTY |
ANV_CMD_BUFFER_INDEX_BUFFER_DIRTY)) {
anv_batch_emit_merge(&cmd_buffer->batch,
cmd_buffer->state.state_vf, pipeline->gen8.vf);
diff --git a/src/vulkan/gen8_state.c b/src/vulkan/gen8_state.c
index 5095ce060bf..9be3bf46021 100644
--- a/src/vulkan/gen8_state.c
+++ b/src/vulkan/gen8_state.c
@@ -29,46 +29,6 @@
#include "anv_private.h"
-VkResult gen8_CreateDynamicRasterState(
- VkDevice _device,
- const VkDynamicRasterStateCreateInfo* pCreateInfo,
- VkDynamicRasterState* pState)
-{
- ANV_FROM_HANDLE(anv_device, device, _device);
- struct anv_dynamic_rs_state *state;
-
- assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DYNAMIC_RASTER_STATE_CREATE_INFO);
-
- state = anv_device_alloc(device, sizeof(*state), 8,
- VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
- if (state == NULL)
- return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
-
- struct GEN8_3DSTATE_SF sf = {
- GEN8_3DSTATE_SF_header,
- .LineWidth = pCreateInfo->lineWidth,
- };
-
- GEN8_3DSTATE_SF_pack(NULL, state->gen8.sf, &sf);
-
- bool enable_bias = pCreateInfo->depthBias != 0.0f ||
- pCreateInfo->slopeScaledDepthBias != 0.0f;
- struct GEN8_3DSTATE_RASTER raster = {
- .GlobalDepthOffsetEnableSolid = enable_bias,
- .GlobalDepthOffsetEnableWireframe = enable_bias,
- .GlobalDepthOffsetEnablePoint = enable_bias,
- .GlobalDepthOffsetConstant = pCreateInfo->depthBias,
- .GlobalDepthOffsetScale = pCreateInfo->slopeScaledDepthBias,
- .GlobalDepthOffsetClamp = pCreateInfo->depthBiasClamp
- };
-
- GEN8_3DSTATE_RASTER_pack(NULL, state->gen8.raster, &raster);
-
- *pState = anv_dynamic_rs_state_to_handle(state);
-
- return VK_SUCCESS;
-}
-
void
gen8_fill_buffer_surface_state(void *state, const struct anv_format *format,
uint32_t offset, uint32_t range)
@@ -407,46 +367,3 @@ VkResult gen8_CreateSampler(
return VK_SUCCESS;
}
-
-VkResult gen8_CreateDynamicDepthStencilState(
- VkDevice _device,
- const VkDynamicDepthStencilStateCreateInfo* pCreateInfo,
- VkDynamicDepthStencilState* pState)
-{
- ANV_FROM_HANDLE(anv_device, device, _device);
- struct anv_dynamic_ds_state *state;
-
- assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DYNAMIC_DEPTH_STENCIL_STATE_CREATE_INFO);
-
- state = anv_device_alloc(device, sizeof(*state), 8,
- VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
- if (state == NULL)
- return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
-
- struct GEN8_3DSTATE_WM_DEPTH_STENCIL wm_depth_stencil = {
- GEN8_3DSTATE_WM_DEPTH_STENCIL_header,
-
- /* Is this what we need to do? */
- .StencilBufferWriteEnable = pCreateInfo->stencilWriteMask != 0,
-
- .StencilTestMask = pCreateInfo->stencilReadMask & 0xff,
- .StencilWriteMask = pCreateInfo->stencilWriteMask & 0xff,
-
- .BackfaceStencilTestMask = pCreateInfo->stencilReadMask & 0xff,
- .BackfaceStencilWriteMask = pCreateInfo->stencilWriteMask & 0xff,
- };
-
- GEN8_3DSTATE_WM_DEPTH_STENCIL_pack(NULL, state->gen8.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->gen8.color_calc_state, &color_calc_state);
-
- *pState = anv_dynamic_ds_state_to_handle(state);
-
- return VK_SUCCESS;
-}