+ cmd_buffer->state.gfx.dirty |= ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE;
+}
+
+static void
+anv_cmd_buffer_bind_descriptor_set(struct anv_cmd_buffer *cmd_buffer,
+ VkPipelineBindPoint bind_point,
+ struct anv_pipeline_layout *layout,
+ uint32_t set_index,
+ struct anv_descriptor_set *set,
+ uint32_t *dynamic_offset_count,
+ const uint32_t **dynamic_offsets)
+{
+ struct anv_descriptor_set_layout *set_layout =
+ layout->set[set_index].layout;
+
+ struct anv_cmd_pipeline_state *pipe_state;
+ if (bind_point == VK_PIPELINE_BIND_POINT_COMPUTE) {
+ pipe_state = &cmd_buffer->state.compute.base;
+ } else {
+ assert(bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS);
+ pipe_state = &cmd_buffer->state.gfx.base;
+ }
+ pipe_state->descriptors[set_index] = set;
+
+ if (dynamic_offsets) {
+ if (set_layout->dynamic_offset_count > 0) {
+ uint32_t dynamic_offset_start =
+ layout->set[set_index].dynamic_offset_start;
+
+ /* Assert that everything is in range */
+ assert(set_layout->dynamic_offset_count <= *dynamic_offset_count);
+ assert(dynamic_offset_start + set_layout->dynamic_offset_count <=
+ ARRAY_SIZE(pipe_state->dynamic_offsets));
+
+ typed_memcpy(&pipe_state->dynamic_offsets[dynamic_offset_start],
+ *dynamic_offsets, set_layout->dynamic_offset_count);
+
+ *dynamic_offsets += set_layout->dynamic_offset_count;
+ *dynamic_offset_count -= set_layout->dynamic_offset_count;
+ }
+ }
+
+ if (bind_point == VK_PIPELINE_BIND_POINT_COMPUTE) {
+ cmd_buffer->state.descriptors_dirty |= VK_SHADER_STAGE_COMPUTE_BIT;
+ } else {
+ assert(bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS);
+ cmd_buffer->state.descriptors_dirty |=
+ set_layout->shader_stages & VK_SHADER_STAGE_ALL_GRAPHICS;
+ }
+
+ /* Pipeline layout objects are required to live at least while any command
+ * buffers that use them are in recording state. We need to grab a reference
+ * to the pipeline layout being bound here so we can compute correct dynamic
+ * offsets for VK_DESCRIPTOR_TYPE_*_DYNAMIC in dynamic_offset_for_binding()
+ * when we record draw commands that come after this.
+ */
+ pipe_state->layout = layout;