From: Tapani Pälli Date: Tue, 2 Jun 2020 07:02:25 +0000 (+0300) Subject: anv: dynamic vertex input binding stride and size support X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b9a05447a1976101c04a02f5588c51de0b0f6573;p=mesa.git anv: dynamic vertex input binding stride and size support If pStrides or Psizes are NULL we should use the values defined by the pipeline. v2: fix commit message and fix the code to set explicitly if we are using dynamic stride/size Signed-off-by: Tapani Pälli Reviewed-by: Lionel Landwerlin Part-of: --- diff --git a/src/intel/vulkan/anv_cmd_buffer.c b/src/intel/vulkan/anv_cmd_buffer.c index 39c8ee013ce..5d55e0c4177 100644 --- a/src/intel/vulkan/anv_cmd_buffer.c +++ b/src/intel/vulkan/anv_cmd_buffer.c @@ -98,6 +98,8 @@ const struct anv_dynamic_state default_dynamic_state = { .depth_compare_op = 0, .depth_bounds_test_enable = 0, .stencil_test_enable = 0, + .dyn_vbo_stride = 0, + .dyn_vbo_size = 0, }; /** @@ -183,6 +185,9 @@ anv_dynamic_state_copy(struct anv_dynamic_state *dest, ANV_CMP_COPY(stencil_op.back.compare_op, ANV_CMD_DIRTY_DYNAMIC_STENCIL_OP); } + ANV_CMP_COPY(dyn_vbo_stride, ANV_CMD_DIRTY_DYNAMIC_VERTEX_INPUT_BINDING_STRIDE); + ANV_CMP_COPY(dyn_vbo_size, ANV_CMD_DIRTY_DYNAMIC_VERTEX_INPUT_BINDING_STRIDE); + #undef ANV_CMP_COPY return changed; @@ -901,12 +906,14 @@ void anv_CmdBindDescriptorSets( } } -void anv_CmdBindVertexBuffers( - VkCommandBuffer commandBuffer, - uint32_t firstBinding, - uint32_t bindingCount, - const VkBuffer* pBuffers, - const VkDeviceSize* pOffsets) +void anv_CmdBindVertexBuffers2EXT( + VkCommandBuffer commandBuffer, + uint32_t firstBinding, + uint32_t bindingCount, + const VkBuffer* pBuffers, + const VkDeviceSize* pOffsets, + const VkDeviceSize* pSizes, + const VkDeviceSize* pStrides) { ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer); struct anv_vertex_binding *vb = cmd_buffer->state.vertex_bindings; @@ -914,14 +921,33 @@ void anv_CmdBindVertexBuffers( /* We have to defer setting up vertex buffer since we need the buffer * stride from the pipeline. */ + if (pSizes) + cmd_buffer->state.gfx.dynamic.dyn_vbo_size = true; + if (pStrides) + cmd_buffer->state.gfx.dynamic.dyn_vbo_stride = true; + assert(firstBinding + bindingCount <= MAX_VBS); for (uint32_t i = 0; i < bindingCount; i++) { vb[firstBinding + i].buffer = anv_buffer_from_handle(pBuffers[i]); vb[firstBinding + i].offset = pOffsets[i]; + vb[firstBinding + i].size = pSizes ? pSizes[i] : 0; + vb[firstBinding + i].stride = pStrides ? pStrides[i] : 0; cmd_buffer->state.gfx.vb_dirty |= 1 << (firstBinding + i); } } +void anv_CmdBindVertexBuffers( + VkCommandBuffer commandBuffer, + uint32_t firstBinding, + uint32_t bindingCount, + const VkBuffer* pBuffers, + const VkDeviceSize* pOffsets) +{ + return anv_CmdBindVertexBuffers2EXT(commandBuffer, firstBinding, + bindingCount, pBuffers, pOffsets, + NULL, NULL); +} + void anv_CmdBindTransformFeedbackBuffersEXT( VkCommandBuffer commandBuffer, uint32_t firstBinding, diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index db1b9f28753..a9d775d6369 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -2607,6 +2607,8 @@ anv_pipe_invalidate_bits_for_access_flags(VkAccessFlags flags) struct anv_vertex_binding { struct anv_buffer * buffer; VkDeviceSize offset; + VkDeviceSize stride; + VkDeviceSize size; }; struct anv_xfb_binding { @@ -2712,6 +2714,8 @@ struct anv_dynamic_state { VkCompareOp depth_compare_op; bool depth_bounds_test_enable; bool stencil_test_enable; + bool dyn_vbo_stride; + bool dyn_vbo_size; }; extern const struct anv_dynamic_state default_dynamic_state; diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c index 76a0aae1a1b..c3bf66df3d3 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -3320,6 +3320,17 @@ genX(cmd_buffer_flush_state)(struct anv_cmd_buffer *cmd_buffer) struct anv_buffer *buffer = cmd_buffer->state.vertex_bindings[vb].buffer; uint32_t offset = cmd_buffer->state.vertex_bindings[vb].offset; + /* If dynamic, use stride/size from vertex binding, otherwise use + * stride/size that was setup in the pipeline object. + */ + bool dynamic_stride = cmd_buffer->state.gfx.dynamic.dyn_vbo_stride; + bool dynamic_size = cmd_buffer->state.gfx.dynamic.dyn_vbo_size; + + uint32_t stride = dynamic_stride ? + cmd_buffer->state.vertex_bindings[vb].stride : pipeline->vb[vb].stride; + uint32_t size = dynamic_size ? + cmd_buffer->state.vertex_bindings[vb].size : buffer->size; + struct GENX(VERTEX_BUFFER_STATE) state; if (buffer) { state = (struct GENX(VERTEX_BUFFER_STATE)) { @@ -3330,16 +3341,15 @@ genX(cmd_buffer_flush_state)(struct anv_cmd_buffer *cmd_buffer) .BufferAccessType = pipeline->vb[vb].instanced ? INSTANCEDATA : VERTEXDATA, .InstanceDataStepRate = pipeline->vb[vb].instance_divisor, #endif - .AddressModifyEnable = true, - .BufferPitch = pipeline->vb[vb].stride, + .BufferPitch = stride, .BufferStartingAddress = anv_address_add(buffer->address, offset), .NullVertexBuffer = offset >= buffer->size, #if GEN_GEN >= 8 - .BufferSize = buffer->size - offset + .BufferSize = size - offset #else - .EndAddress = anv_address_add(buffer->address, buffer->size - 1), + .EndAddress = anv_address_add(buffer->address, size - 1), #endif }; } else {