[Mesa-dev] [PATCH] anv: Add a helper for working with VK_WHOLE_SIZE for buffers
Jason Ekstrand
jason at jlekstrand.net
Sat Mar 4 18:47:11 UTC 2017
---
src/intel/vulkan/anv_blorp.c | 16 +++++++++++-----
src/intel/vulkan/anv_descriptor_set.c | 7 +++----
src/intel/vulkan/anv_image.c | 4 ++--
src/intel/vulkan/anv_private.h | 12 ++++++++++++
4 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c
index d79c5e0..05790d2 100644
--- a/src/intel/vulkan/anv_blorp.c
+++ b/src/intel/vulkan/anv_blorp.c
@@ -722,11 +722,17 @@ void anv_CmdFillBuffer(
struct blorp_batch batch;
blorp_batch_init(&cmd_buffer->device->blorp, &batch, cmd_buffer, 0);
- if (fillSize == VK_WHOLE_SIZE) {
- fillSize = dst_buffer->size - dstOffset;
- /* Make sure fillSize is a multiple of 4 */
- fillSize &= ~3ull;
- }
+ fillSize = anv_buffer_get_range(dst_buffer, dstOffset, fillSize);
+
+ /* From the Vulkan spec:
+ *
+ * "size is the number of bytes to fill, and must be either a multiple
+ * of 4, or VK_WHOLE_SIZE to fill the range from offset to the end of
+ * the buffer. If VK_WHOLE_SIZE is used and the remaining size of the
+ * buffer is not a multiple of 4, then the nearest smaller multiple is
+ * used."
+ */
+ fillSize &= ~3ull;
/* First, we compute the biggest format that can be used with the
* given offsets and size.
diff --git a/src/intel/vulkan/anv_descriptor_set.c b/src/intel/vulkan/anv_descriptor_set.c
index 1e8991b..2a37d7d 100644
--- a/src/intel/vulkan/anv_descriptor_set.c
+++ b/src/intel/vulkan/anv_descriptor_set.c
@@ -672,10 +672,9 @@ anv_descriptor_set_write_buffer(struct anv_descriptor_set *set,
/* For buffers with dynamic offsets, we use the full possible range in the
* surface state and do the actual range-checking in the shader.
*/
- if (bind_layout->dynamic_offset_index >= 0 || range == VK_WHOLE_SIZE)
- bview->range = buffer->size - offset;
- else
- bview->range = range;
+ if (bind_layout->dynamic_offset_index >= 0)
+ range = VK_WHOLE_SIZE;
+ bview->range = anv_buffer_get_range(buffer, offset, range);
/* If we're writing descriptors through a push command, we need to allocate
* the surface state from the command buffer. Otherwise it will be
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index 59f730c..f54c8ea 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -837,8 +837,8 @@ anv_CreateBufferView(VkDevice _device,
const uint32_t format_bs = isl_format_get_layout(view->format)->bpb / 8;
view->bo = buffer->bo;
view->offset = buffer->offset + pCreateInfo->offset;
- view->range = pCreateInfo->range == VK_WHOLE_SIZE ?
- buffer->size - pCreateInfo->offset : pCreateInfo->range;
+ view->range = anv_buffer_get_range(buffer, pCreateInfo->offset,
+ pCreateInfo->range);
view->range = align_down_npot_u32(view->range, format_bs);
if (buffer->usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) {
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index c73196a..cf9874e 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -1090,6 +1090,18 @@ struct anv_buffer {
VkDeviceSize offset;
};
+static inline uint64_t
+anv_buffer_get_range(struct anv_buffer *buffer, uint64_t offset, uint64_t range)
+{
+ assert(offset <= buffer->size);
+ if (range == VK_WHOLE_SIZE) {
+ return buffer->size - offset;
+ } else {
+ assert(range <= buffer->size);
+ return range;
+ }
+}
+
enum anv_cmd_dirty_bits {
ANV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
ANV_CMD_DIRTY_DYNAMIC_SCISSOR = 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
--
2.5.0.400.gff86faf
More information about the mesa-dev
mailing list