<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 2, 2016 at 12:05 PM, Anuj Phogat <span dir="ltr"><<a href="mailto:anuj.phogat@gmail.com" target="_blank">anuj.phogat@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Wed, Aug 31, 2016 at 2:22 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
> ---<br>
> src/intel/vulkan/Makefile.<wbr>sources | 1 -<br>
> src/intel/vulkan/anv_blorp.c | 184 ++++++++++++++++++++++++++++++<wbr>++++++++<br>
> src/intel/vulkan/anv_meta_<wbr>copy.c | 180 ------------------------------<wbr>-------<br>
> 3 files changed, 184 insertions(+), 181 deletions(-)<br>
> delete mode 100644 src/intel/vulkan/anv_meta_<wbr>copy.c<br>
><br>
> diff --git a/src/intel/vulkan/Makefile.<wbr>sources b/src/intel/vulkan/Makefile.<wbr>sources<br>
> index 35e15f6..6c9853b 100644<br>
> --- a/src/intel/vulkan/Makefile.<wbr>sources<br>
> +++ b/src/intel/vulkan/Makefile.<wbr>sources<br>
> @@ -35,7 +35,6 @@ VULKAN_FILES := \<br>
> anv_meta.h \<br>
> anv_meta_blit2d.c \<br>
> anv_meta_clear.c \<br>
> - anv_meta_copy.c \<br>
> anv_meta_resolve.c \<br>
> anv_nir.h \<br>
> anv_nir_apply_dynamic_offsets.<wbr>c \<br>
> diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c<br>
> index 89ff3b3..e2b6672 100644<br>
> --- a/src/intel/vulkan/anv_blorp.c<br>
> +++ b/src/intel/vulkan/anv_blorp.c<br>
> @@ -479,3 +479,187 @@ void anv_CmdBlitImage(<br>
><br>
> blorp_batch_finish(&batch);<br>
> }<br>
> +<br>
> +static void<br>
> +do_buffer_copy(struct blorp_batch *batch,<br>
> + struct anv_bo *src, uint64_t src_offset,<br>
> + struct anv_bo *dst, uint64_t dst_offset,<br>
> + int width, int height, int block_size)<br>
> +{<br>
> + struct anv_device *device = batch->blorp->driver_ctx;<br>
> +<br>
> + /* The actual format we pick doesn't matter as blorp will throw it away.<br>
> + * The only thing that actually matters is the size.<br>
> + */<br>
> + enum isl_format format;<br>
> + switch (block_size) {<br>
> + case 1: format = ISL_FORMAT_R8_UINT; break;<br>
> + case 2: format = ISL_FORMAT_R8G8_UINT; break;<br>
> + case 4: format = ISL_FORMAT_R8G8B8A8_UNORM; break;<br>
> + case 8: format = ISL_FORMAT_R16G16B16A16_UNORM; break;<br>
> + case 16: format = ISL_FORMAT_R32G32B32A32_UINT; break;<br>
> + default:<br>
> + unreachable("Not a power-of-two format size");<br>
> + }<br>
> +<br>
> + struct isl_surf surf;<br>
> + isl_surf_init(&device->isl_<wbr>dev, &surf,<br>
> + .dim = ISL_SURF_DIM_2D,<br>
> + .format = format,<br>
> + .width = width,<br>
> + .height = height,<br>
> + .depth = 1,<br>
> + .levels = 1,<br>
> + .array_len = 1,<br>
> + .samples = 1,<br>
> + .usage = ISL_SURF_USAGE_TEXTURE_BIT,<br>
> + .tiling_flags = ISL_TILING_LINEAR_BIT);<br>
> + assert(surf.row_pitch == width * block_size);<br>
> +<br>
> + struct blorp_surf src_blorp_surf = {<br>
> + .surf = &surf,<br>
> + .addr = {<br>
> + .buffer = src,<br>
> + .offset = src_offset,<br>
> + },<br>
> + };<br>
> +<br>
> + struct blorp_surf dst_blorp_surf = {<br>
> + .surf = &surf,<br>
> + .addr = {<br>
> + .buffer = dst,<br>
> + .offset = dst_offset,<br>
> + },<br>
> + };<br>
> +<br>
> + blorp_copy(batch, &src_blorp_surf, 0, 0, &dst_blorp_surf, 0, 0,<br>
> + 0, 0, 0, 0, width, height);<br>
> +}<br>
> +<br>
> +void anv_CmdCopyBuffer(<br>
> + VkCommandBuffer commandBuffer,<br>
> + VkBuffer srcBuffer,<br>
> + VkBuffer dstBuffer,<br>
> + uint32_t regionCount,<br>
> + const VkBufferCopy* pRegions)<br>
> +{<br>
> + ANV_FROM_HANDLE(anv_cmd_<wbr>buffer, cmd_buffer, commandBuffer);<br>
> + ANV_FROM_HANDLE(anv_buffer, src_buffer, srcBuffer);<br>
> + ANV_FROM_HANDLE(anv_buffer, dst_buffer, dstBuffer);<br>
> +<br>
> + struct blorp_batch batch;<br>
> + blorp_batch_init(&cmd_buffer-><wbr>device->blorp, &batch, cmd_buffer);<br>
> +<br>
> + for (unsigned r = 0; r < regionCount; r++) {<br>
> + uint64_t src_offset = src_buffer->offset + pRegions[r].srcOffset;<br>
> + uint64_t dst_offset = dst_buffer->offset + pRegions[r].dstOffset;<br>
> + uint64_t copy_size = pRegions[r].size;<br>
> +<br>
> + /* First, we compute the biggest format that can be used with the<br>
> + * given offsets and size.<br>
> + */<br>
> + int bs = 16;<br>
> +<br>
> + int fs = ffs(src_offset) - 1;<br>
> + if (fs != -1)<br>
> + bs = MIN2(bs, 1 << fs);<br>
> + assert(src_offset % bs == 0);<br>
> +<br>
> + fs = ffs(dst_offset) - 1;<br>
> + if (fs != -1)<br>
> + bs = MIN2(bs, 1 << fs);<br>
> + assert(dst_offset % bs == 0);<br>
> +<br>
> + fs = ffs(pRegions[r].size) - 1;<br>
> + if (fs != -1)<br>
> + bs = MIN2(bs, 1 << fs);<br>
> + assert(pRegions[r].size % bs == 0);<br>
> +<br>
> + /* This is maximum possible width/height our HW can handle */<br>
> + uint64_t max_surface_dim = 1 << 14;<br>
> +<br>
> + /* First, we make a bunch of max-sized copies */<br>
> + uint64_t max_copy_size = max_surface_dim * max_surface_dim * bs;<br>
> + while (copy_size >= max_copy_size) {<br>
> + do_buffer_copy(&batch, src_buffer->bo, src_offset,<br>
> + dst_buffer->bo, dst_offset,<br>
> + max_surface_dim, max_surface_dim, bs);<br>
> + copy_size -= max_copy_size;<br>
> + src_offset += max_copy_size;<br>
> + dst_offset += max_copy_size;<br>
> + }<br>
> +<br>
> + uint64_t height = copy_size / (max_surface_dim * bs);<br>
> + assert(height < max_surface_dim);<br>
> + if (height != 0) {<br>
> + uint64_t rect_copy_size = height * max_surface_dim * bs;<br>
> + do_buffer_copy(&batch, src_buffer->bo, src_offset,<br>
> + dst_buffer->bo, dst_offset,<br>
> + max_surface_dim, height, bs);<br>
> + copy_size -= rect_copy_size;<br>
> + src_offset += rect_copy_size;<br>
> + dst_offset += rect_copy_size;<br>
> + }<br>
> +<br>
> + if (copy_size != 0) {<br>
> + do_buffer_copy(&batch, src_buffer->bo, src_offset,<br>
> + dst_buffer->bo, dst_offset,<br>
> + copy_size / bs, 1, bs);<br>
> + }<br>
> + }<br>
> +<br>
> + blorp_batch_finish(&batch);<br>
> +}<br>
> +<br>
> +void anv_CmdUpdateBuffer(<br>
> + VkCommandBuffer commandBuffer,<br>
> + VkBuffer dstBuffer,<br>
> + VkDeviceSize dstOffset,<br>
> + VkDeviceSize dataSize,<br>
> + const uint32_t* pData)<br>
> +{<br>
> + ANV_FROM_HANDLE(anv_cmd_<wbr>buffer, cmd_buffer, commandBuffer);<br>
> + ANV_FROM_HANDLE(anv_buffer, dst_buffer, dstBuffer);<br>
> +<br>
> + struct blorp_batch batch;<br>
> + blorp_batch_init(&cmd_buffer-><wbr>device->blorp, &batch, cmd_buffer);<br>
> +<br>
> + /* We can't quite grab a full block because the state stream needs a<br>
> + * little data at the top to build its linked list.<br>
> + */<br>
> + const uint32_t max_update_size =<br>
> + cmd_buffer->device->dynamic_<wbr>state_block_pool.block_size - 64;<br>
> +<br>
> + assert(max_update_size < (1 << 14) * 4);<br>
</div></div>It's not obvious how you came up with (1 << 14) * 4. Adding a comment<br>
or turning this in to a macro will help.<br></blockquote><div><br></div><div>I turned max_surface_dim from the previous function into a #define and then re-used it here.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
> +<br>
> + while (dataSize) {<br>
> + const uint32_t copy_size = MIN2(dataSize, max_update_size);<br>
> +<br>
> + struct anv_state tmp_data =<br>
> + anv_cmd_buffer_alloc_dynamic_<wbr>state(cmd_buffer, copy_size, 64);<br>
> +<br>
> + memcpy(tmp_data.map, pData, copy_size);<br>
> +<br>
> + int bs;<br>
> + if ((copy_size & 15) == 0 && (dstOffset & 15) == 0) {<br>
> + bs = 16;<br>
> + } else if ((copy_size & 7) == 0 && (dstOffset & 7) == 0) {<br>
> + bs = 8;<br>
> + } else {<br>
> + assert((copy_size & 3) == 0 && (dstOffset & 3) == 0);<br>
> + bs = 4;<br>
> + }<br>
> +<br>
> + do_buffer_copy(&batch,<br>
> + &cmd_buffer->device-><a href="http://dynamic_state_block_pool.bo" rel="noreferrer" target="_blank">dynamic_<wbr>state_block_pool.bo</a>,<br>
> + tmp_data.offset,<br>
> + dst_buffer->bo, dst_buffer->offset + dstOffset,<br>
> + copy_size / bs, 1, bs);<br>
> +<br>
> + dataSize -= copy_size;<br>
> + dstOffset += copy_size;<br>
> + pData = (void *)pData + copy_size;<br>
> + }<br>
> +<br>
> + blorp_batch_finish(&batch);<br>
> +}<br>
> diff --git a/src/intel/vulkan/anv_meta_<wbr>copy.c b/src/intel/vulkan/anv_meta_<wbr>copy.c<br>
> deleted file mode 100644<br>
> index b33273e..0000000<br>
> --- a/src/intel/vulkan/anv_meta_<wbr>copy.c<br>
> +++ /dev/null<br>
> @@ -1,180 +0,0 @@<br>
> -/*<br>
> - * Copyright © 2016 Intel Corporation<br>
> - *<br>
> - * Permission is hereby granted, free of charge, to any person obtaining a<br>
> - * copy of this software and associated documentation files (the "Software"),<br>
> - * to deal in the Software without restriction, including without limitation<br>
> - * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> - * and/or sell copies of the Software, and to permit persons to whom the<br>
> - * Software is furnished to do so, subject to the following conditions:<br>
> - *<br>
> - * The above copyright notice and this permission notice (including the next<br>
> - * paragraph) shall be included in all copies or substantial portions of the<br>
> - * Software.<br>
> - *<br>
> - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
> - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
> - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
> - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
> - * IN THE SOFTWARE.<br>
> - */<br>
> -<br>
> -#include "anv_meta.h"<br>
> -<br>
> -static void<br>
> -do_buffer_copy(struct anv_cmd_buffer *cmd_buffer,<br>
> - struct anv_bo *src, uint64_t src_offset,<br>
> - struct anv_bo *dest, uint64_t dest_offset,<br>
> - int width, int height, int bs)<br>
> -{<br>
> - struct anv_meta_blit2d_surf b_src = {<br>
> - .bo = src,<br>
> - .tiling = ISL_TILING_LINEAR,<br>
> - .base_offset = src_offset,<br>
> - .bs = bs,<br>
> - .pitch = width * bs,<br>
> - };<br>
> - struct anv_meta_blit2d_surf b_dst = {<br>
> - .bo = dest,<br>
> - .tiling = ISL_TILING_LINEAR,<br>
> - .base_offset = dest_offset,<br>
> - .bs = bs,<br>
> - .pitch = width * bs,<br>
> - };<br>
> - struct anv_meta_blit2d_rect rect = {<br>
> - .width = width,<br>
> - .height = height,<br>
> - };<br>
> - anv_meta_blit2d(cmd_buffer, &b_src, &b_dst, 1, &rect);<br>
> -}<br>
> -<br>
> -void anv_CmdCopyBuffer(<br>
> - VkCommandBuffer commandBuffer,<br>
> - VkBuffer srcBuffer,<br>
> - VkBuffer destBuffer,<br>
> - uint32_t regionCount,<br>
> - const VkBufferCopy* pRegions)<br>
> -{<br>
> - ANV_FROM_HANDLE(anv_cmd_<wbr>buffer, cmd_buffer, commandBuffer);<br>
> - ANV_FROM_HANDLE(anv_buffer, src_buffer, srcBuffer);<br>
> - ANV_FROM_HANDLE(anv_buffer, dest_buffer, destBuffer);<br>
> -<br>
> - struct anv_meta_saved_state saved_state;<br>
> -<br>
> - anv_meta_begin_blit2d(cmd_<wbr>buffer, &saved_state);<br>
> -<br>
> - for (unsigned r = 0; r < regionCount; r++) {<br>
> - uint64_t src_offset = src_buffer->offset + pRegions[r].srcOffset;<br>
> - uint64_t dest_offset = dest_buffer->offset + pRegions[r].dstOffset;<br>
> - uint64_t copy_size = pRegions[r].size;<br>
> -<br>
> - /* First, we compute the biggest format that can be used with the<br>
> - * given offsets and size.<br>
> - */<br>
> - int bs = 16;<br>
> -<br>
> - int fs = ffs(src_offset) - 1;<br>
> - if (fs != -1)<br>
> - bs = MIN2(bs, 1 << fs);<br>
> - assert(src_offset % bs == 0);<br>
> -<br>
> - fs = ffs(dest_offset) - 1;<br>
> - if (fs != -1)<br>
> - bs = MIN2(bs, 1 << fs);<br>
> - assert(dest_offset % bs == 0);<br>
> -<br>
> - fs = ffs(pRegions[r].size) - 1;<br>
> - if (fs != -1)<br>
> - bs = MIN2(bs, 1 << fs);<br>
> - assert(pRegions[r].size % bs == 0);<br>
> -<br>
> - /* This is maximum possible width/height our HW can handle */<br>
> - uint64_t max_surface_dim = 1 << 14;<br>
> -<br>
> - /* First, we make a bunch of max-sized copies */<br>
> - uint64_t max_copy_size = max_surface_dim * max_surface_dim * bs;<br>
> - while (copy_size >= max_copy_size) {<br>
> - do_buffer_copy(cmd_buffer, src_buffer->bo, src_offset,<br>
> - dest_buffer->bo, dest_offset,<br>
> - max_surface_dim, max_surface_dim, bs);<br>
> - copy_size -= max_copy_size;<br>
> - src_offset += max_copy_size;<br>
> - dest_offset += max_copy_size;<br>
> - }<br>
> -<br>
> - uint64_t height = copy_size / (max_surface_dim * bs);<br>
> - assert(height < max_surface_dim);<br>
> - if (height != 0) {<br>
> - uint64_t rect_copy_size = height * max_surface_dim * bs;<br>
> - do_buffer_copy(cmd_buffer, src_buffer->bo, src_offset,<br>
> - dest_buffer->bo, dest_offset,<br>
> - max_surface_dim, height, bs);<br>
> - copy_size -= rect_copy_size;<br>
> - src_offset += rect_copy_size;<br>
> - dest_offset += rect_copy_size;<br>
> - }<br>
> -<br>
> - if (copy_size != 0) {<br>
> - do_buffer_copy(cmd_buffer, src_buffer->bo, src_offset,<br>
> - dest_buffer->bo, dest_offset,<br>
> - copy_size / bs, 1, bs);<br>
> - }<br>
> - }<br>
> -<br>
> - anv_meta_end_blit2d(cmd_<wbr>buffer, &saved_state);<br>
> -}<br>
> -<br>
> -void anv_CmdUpdateBuffer(<br>
> - VkCommandBuffer commandBuffer,<br>
> - VkBuffer dstBuffer,<br>
> - VkDeviceSize dstOffset,<br>
> - VkDeviceSize dataSize,<br>
> - const uint32_t* pData)<br>
> -{<br>
> - ANV_FROM_HANDLE(anv_cmd_<wbr>buffer, cmd_buffer, commandBuffer);<br>
> - ANV_FROM_HANDLE(anv_buffer, dst_buffer, dstBuffer);<br>
> - struct anv_meta_saved_state saved_state;<br>
> -<br>
> - anv_meta_begin_blit2d(cmd_<wbr>buffer, &saved_state);<br>
> -<br>
> - /* We can't quite grab a full block because the state stream needs a<br>
> - * little data at the top to build its linked list.<br>
> - */<br>
> - const uint32_t max_update_size =<br>
> - cmd_buffer->device->dynamic_<wbr>state_block_pool.block_size - 64;<br>
> -<br>
> - assert(max_update_size < (1 << 14) * 4);<br>
> -<br>
> - while (dataSize) {<br>
> - const uint32_t copy_size = MIN2(dataSize, max_update_size);<br>
> -<br>
> - struct anv_state tmp_data =<br>
> - anv_cmd_buffer_alloc_dynamic_<wbr>state(cmd_buffer, copy_size, 64);<br>
> -<br>
> - memcpy(tmp_data.map, pData, copy_size);<br>
> -<br>
> - int bs;<br>
> - if ((copy_size & 15) == 0 && (dstOffset & 15) == 0) {<br>
> - bs = 16;<br>
> - } else if ((copy_size & 7) == 0 && (dstOffset & 7) == 0) {<br>
> - bs = 8;<br>
> - } else {<br>
> - assert((copy_size & 3) == 0 && (dstOffset & 3) == 0);<br>
> - bs = 4;<br>
> - }<br>
> -<br>
> - do_buffer_copy(cmd_buffer,<br>
> - &cmd_buffer->device-><a href="http://dynamic_state_block_pool.bo" rel="noreferrer" target="_blank">dynamic_<wbr>state_block_pool.bo</a>,<br>
> - tmp_data.offset,<br>
> - dst_buffer->bo, dst_buffer->offset + dstOffset,<br>
> - copy_size / bs, 1, bs);<br>
> -<br>
> - dataSize -= copy_size;<br>
> - dstOffset += copy_size;<br>
> - pData = (void *)pData + copy_size;<br>
> - }<br>
> -<br>
> - anv_meta_end_blit2d(cmd_<wbr>buffer, &saved_state);<br>
> -}<br>
> --<br>
> 2.5.0.400.gff86faf<br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</blockquote></div><br></div></div>