<div dir="ltr">Both are<br><br>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br><div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 25, 2016 at 4:38 PM, Nanley Chery <span dir="ltr"><<a href="mailto:nanleychery@gmail.com" target="_blank">nanleychery@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Nanley Chery <<a href="mailto:nanley.g.chery@intel.com">nanley.g.chery@intel.com</a>><br>
<br>
This function differs from the open-coded implementation in that the<br>
ImageView's width is determined by the caller and is not unconditionally<br>
set to match the number of texels within the surface's pitch.<br>
<br>
Signed-off-by: Nanley Chery <<a href="mailto:nanley.g.chery@intel.com">nanley.g.chery@intel.com</a>><br>
---<br>
src/intel/vulkan/anv_meta_blit2d.c | 196 ++++++++++++++++---------------------<br>
1 file changed, 83 insertions(+), 113 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_meta_blit2d.c b/src/intel/vulkan/anv_meta_blit2d.c<br>
index 87c3358..734ba8e 100644<br>
--- a/src/intel/vulkan/anv_meta_blit2d.c<br>
+++ b/src/intel/vulkan/anv_meta_blit2d.c<br>
@@ -55,6 +55,81 @@ vk_format_for_size(int bs)<br>
}<br>
<br>
static void<br>
+create_iview(struct anv_cmd_buffer *cmd_buffer,<br>
+ struct anv_meta_blit2d_surf *surf,<br>
+ struct anv_meta_blit2d_rect *rect,<br>
+ VkImageUsageFlags usage,<br>
+ VkImage *img,<br>
+ struct anv_image_view *iview)<br>
+{<br>
+ struct isl_tile_info tile_info;<br>
+ isl_tiling_get_info(&cmd_buffer->device->isl_dev,<br>
+ surf->tiling, surf->bs, &tile_info);<br>
+ const unsigned tile_width_px = tile_info.width > surf->bs ?<br>
+ tile_info.width / surf->bs : 1;<br>
+ uint32_t *rect_y = (usage == VK_IMAGE_USAGE_SAMPLED_BIT) ?<br>
+ &rect->src_y : &rect->dst_y;<br>
+ uint32_t *rect_x = (usage == VK_IMAGE_USAGE_SAMPLED_BIT) ?<br>
+ &rect->src_x : &rect->dst_x;<br>
+<br>
+ /* Define the shared state among all created image views */<br>
+ const VkImageCreateInfo image_info = {<br>
+ .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,<br>
+ .imageType = VK_IMAGE_TYPE_2D,<br>
+ .format = vk_format_for_size(surf->bs),<br>
+ .extent = {<br>
+ .width = rect->width + (*rect_x) % tile_width_px,<br>
+ .height = rect->height + (*rect_y) % tile_info.height, <br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ .depth = 1,<br>
+ },<br>
+ .mipLevels = 1,<br>
+ .arrayLayers = 1,<br>
+ .samples = 1,<br>
+ .tiling = surf->tiling == ISL_TILING_LINEAR ?<br>
+ VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL,<br>
+ .usage = usage,<br>
+ };<br>
+<br>
+ /* Create the VkImage that is bound to the surface's memory. */<br>
+ anv_image_create(anv_device_to_handle(cmd_buffer->device),<br>
+ &(struct anv_image_create_info) {<br>
+ .vk_info = &image_info,<br>
+ .isl_tiling_flags = 1 << surf->tiling,<br>
+ .stride = surf->pitch,<br>
+ }, &cmd_buffer->pool->alloc, img);<br>
+<br>
+ /* We could use a vk call to bind memory, but that would require<br>
+ * creating a dummy memory object etc. so there's really no point.<br>
+ */<br>
+ anv_image_from_handle(*img)->bo = surf->bo;<br>
+ anv_image_from_handle(*img)->offset = surf->base_offset;<br>
+<br>
+ /* Create a VkImageView that starts at the tile aligned offset closest<br>
+ * to the provided x/y offset into the surface.<br>
+ */<br>
+ uint32_t img_o = 0;<br>
+ isl_surf_get_image_intratile_offset_el_xy(&cmd_buffer->device->isl_dev,<br>
+ &anv_image_from_handle(*img)-><br>
+ color_surface.isl,<br>
+ *rect_x, *rect_y,<br>
+ &img_o, rect_x, rect_y);<br>
+ anv_image_view_init(iview, cmd_buffer->device,<br>
+ &(VkImageViewCreateInfo) {<br>
+ .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,<br>
+ .image = *img,<br>
+ .viewType = VK_IMAGE_VIEW_TYPE_2D,<br>
+ .format = image_info.format,<br>
+ .subresourceRange = {<br>
+ .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,<br>
+ .baseMipLevel = 0,<br>
+ .levelCount = 1,<br>
+ .baseArrayLayer = 0,<br>
+ .layerCount = 1<br>
+ },<br>
+ }, cmd_buffer, img_o, usage);<br>
+}<br>
+<br>
+static void<br>
meta_emit_blit2d(struct anv_cmd_buffer *cmd_buffer,<br>
struct anv_image_view *src_iview,<br>
VkOffset3D src_offset,<br>
@@ -260,132 +335,27 @@ anv_meta_blit2d(struct anv_cmd_buffer *cmd_buffer,<br>
struct anv_meta_blit2d_rect *rects)<br>
{<br>
VkDevice vk_device = anv_device_to_handle(cmd_buffer->device);<br>
- VkFormat src_format = vk_format_for_size(src->bs);<br>
- VkFormat dst_format = vk_format_for_size(dst->bs);<br>
VkImageUsageFlags src_usage = VK_IMAGE_USAGE_SAMPLED_BIT;<br>
VkImageUsageFlags dst_usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;<br>
<br>
for (unsigned r = 0; r < num_rects; ++r) {<br>
-<br>
- /* Create VkImages */<br>
- VkImageCreateInfo image_info = {<br>
- .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,<br>
- .imageType = VK_IMAGE_TYPE_2D,<br>
- .format = 0, /* TEMPLATE */<br>
- .extent = {<br>
- .width = 0, /* TEMPLATE */<br>
- .height = 0, /* TEMPLATE */<br>
- .depth = 1,<br>
- },<br>
- .mipLevels = 1,<br>
- .arrayLayers = 1,<br>
- .samples = 1,<br>
- .tiling = 0, /* TEMPLATE */<br>
- .usage = 0, /* TEMPLATE */<br>
- };<br>
- struct anv_image_create_info anv_image_info = {<br>
- .vk_info = &image_info,<br>
- .isl_tiling_flags = 0, /* TEMPLATE */<br>
- };<br>
-<br>
- /* The image height is the rect height + src/dst y-offset from the<br>
- * tile-aligned base address.<br>
- */<br>
- struct isl_tile_info tile_info;<br>
-<br>
- anv_image_info.isl_tiling_flags = 1 << src->tiling;<br>
- image_info.tiling = src->tiling == ISL_TILING_LINEAR ?<br>
- VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL;<br>
- image_info.usage = src_usage;<br>
- image_info.format = src_format,<br>
- isl_tiling_get_info(&cmd_buffer->device->isl_dev, src->tiling, src->bs,<br>
- &tile_info);<br>
- image_info.extent.height = rects[r].height +<br>
- rects[r].src_y % tile_info.height;<br>
- image_info.extent.width = src->pitch / src->bs;<br>
- VkImage src_image;<br>
- anv_image_create(vk_device, &anv_image_info,<br>
- &cmd_buffer->pool->alloc, &src_image);<br>
-<br>
- anv_image_info.isl_tiling_flags = 1 << dst->tiling;<br>
- image_info.tiling = dst->tiling == ISL_TILING_LINEAR ?<br>
- VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL;<br>
- image_info.usage = dst_usage;<br>
- image_info.format = dst_format,<br>
- isl_tiling_get_info(&cmd_buffer->device->isl_dev, dst->tiling, dst->bs,<br>
- &tile_info);<br>
- image_info.extent.height = rects[r].height +<br>
- rects[r].dst_y % tile_info.height;<br>
- image_info.extent.width = dst->pitch / dst->bs;<br>
- VkImage dst_image;<br>
- anv_image_create(vk_device, &anv_image_info,<br>
- &cmd_buffer->pool->alloc, &dst_image);<br>
-<br>
- /* We could use a vk call to bind memory, but that would require<br>
- * creating a dummy memory object etc. so there's really no point.<br>
- */<br>
- anv_image_from_handle(src_image)->bo = src->bo;<br>
- anv_image_from_handle(src_image)->offset = src->base_offset;<br>
- anv_image_from_handle(dst_image)->bo = dst->bo;<br>
- anv_image_from_handle(dst_image)->offset = dst->base_offset;<br>
-<br>
- /* Create VkImageViews */<br>
- VkImageViewCreateInfo iview_info = {<br>
- .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,<br>
- .image = 0, /* TEMPLATE */<br>
- .viewType = VK_IMAGE_VIEW_TYPE_2D,<br>
- .format = 0, /* TEMPLATE */<br>
- .subresourceRange = {<br>
- .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,<br>
- .baseMipLevel = 0,<br>
- .levelCount = 1,<br>
- .baseArrayLayer = 0,<br>
- .layerCount = 1<br>
- },<br>
- };<br>
- uint32_t img_o = 0;<br>
-<br>
- iview_info.image = src_image;<br>
- iview_info.format = src_format;<br>
- VkOffset3D src_offset_el = {0};<br>
- isl_surf_get_image_intratile_offset_el_xy(&cmd_buffer->device->isl_dev,<br>
- &anv_image_from_handle(src_image)-><br>
- color_surface.isl,<br>
- rects[r].src_x,<br>
- rects[r].src_y,<br>
- &img_o,<br>
- (uint32_t*)&src_offset_el.x,<br>
- (uint32_t*)&src_offset_el.y);<br>
-<br>
+ VkImage src_img;<br>
+ VkImage dst_img;<br>
struct anv_image_view src_iview;<br>
- anv_image_view_init(&src_iview, cmd_buffer->device,<br>
- &iview_info, cmd_buffer, img_o, src_usage);<br>
-<br>
- iview_info.image = dst_image;<br>
- iview_info.format = dst_format;<br>
- VkOffset3D dst_offset_el = {0};<br>
- isl_surf_get_image_intratile_offset_el_xy(&cmd_buffer->device->isl_dev,<br>
- &anv_image_from_handle(dst_image)-><br>
- color_surface.isl,<br>
- rects[r].dst_x,<br>
- rects[r].dst_y,<br>
- &img_o,<br>
- (uint32_t*)&dst_offset_el.x,<br>
- (uint32_t*)&dst_offset_el.y);<br>
struct anv_image_view dst_iview;<br>
- anv_image_view_init(&dst_iview, cmd_buffer->device,<br>
- &iview_info, cmd_buffer, img_o, dst_usage);<br>
+ create_iview(cmd_buffer, src, &rects[r], src_usage, &src_img, &src_iview);<br>
+ create_iview(cmd_buffer, dst, &rects[r], dst_usage, &dst_img, &dst_iview);<br>
<br>
/* Perform blit */<br>
meta_emit_blit2d(cmd_buffer,<br>
&src_iview,<br>
- src_offset_el,<br>
+ (VkOffset3D){rects[r].src_x, rects[r].src_y, 0},<br>
&dst_iview,<br>
- dst_offset_el,<br>
+ (VkOffset3D){rects[r].dst_x, rects[r].dst_y, 0},<br>
(VkExtent3D){rects[r].width, rects[r].height, 1});<br>
<br>
- anv_DestroyImage(vk_device, src_image, &cmd_buffer->pool->alloc);<br>
- anv_DestroyImage(vk_device, dst_image, &cmd_buffer->pool->alloc);<br>
+ anv_DestroyImage(vk_device, src_img, &cmd_buffer->pool->alloc);<br>
+ anv_DestroyImage(vk_device, dst_img, &cmd_buffer->pool->alloc);<br>
}<br>
}<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
2.7.4<br>
<br>
_______________________________________________<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/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div></div>