tex->texture = nir_deref_var_create(tex, sampler);
tex->sampler = nir_deref_var_create(tex, sampler);
- nir_ssa_dest_init(&tex->instr, &tex->dest, 4, "tex");
+ nir_ssa_dest_init(&tex->instr, &tex->dest, 4, 32, "tex");
nir_builder_instr_insert(&b, &tex->instr);
nir_variable *color_out = nir_variable_create(b.shader, nir_var_shader_out,
meta_prepare_blit(struct anv_cmd_buffer *cmd_buffer,
struct anv_meta_saved_state *saved_state)
{
- anv_meta_save(saved_state, cmd_buffer,
- (1 << VK_DYNAMIC_STATE_VIEWPORT));
-}
-
-void
-anv_meta_begin_blit2d(struct anv_cmd_buffer *cmd_buffer,
- struct anv_meta_saved_state *save)
-{
- meta_prepare_blit(cmd_buffer, save);
-}
-
-
-/* Returns the user-provided VkBufferImageCopy::imageOffset in units of
- * elements rather than texels. One element equals one texel or one block
- * if Image is uncompressed or compressed, respectively.
- */
-static struct VkOffset3D
-meta_region_offset_el(const struct anv_image * image,
- const struct VkOffset3D * offset)
-{
- const struct isl_format_layout * isl_layout = image->format->isl_layout;
- return (VkOffset3D) {
- .x = offset->x / isl_layout->bw,
- .y = offset->y / isl_layout->bh,
- .z = offset->z / isl_layout->bd,
- };
-}
-
-/* Returns the user-provided VkBufferImageCopy::imageExtent in units of
- * elements rather than texels. One element equals one texel or one block
- * if Image is uncompressed or compressed, respectively.
- */
-static struct VkExtent3D
-meta_region_extent_el(const VkFormat format,
- const struct VkExtent3D * extent)
-{
- const struct isl_format_layout * isl_layout =
- anv_format_for_vk_format(format)->isl_layout;
- return (VkExtent3D) {
- .width = DIV_ROUND_UP(extent->width , isl_layout->bw),
- .height = DIV_ROUND_UP(extent->height, isl_layout->bh),
- .depth = DIV_ROUND_UP(extent->depth , isl_layout->bd),
- };
+ anv_meta_save(saved_state, cmd_buffer, 0);
}
static void
dest_offset.y + dest_extent.height,
},
.tex_coord = {
- (float)(src_offset.x + src_extent.width) / (float)src_iview->extent.width,
- (float)(src_offset.y + src_extent.height) / (float)src_iview->extent.height,
+ (float)(src_offset.x + src_extent.width)
+ / (float)src_iview->extent.width,
+ (float)(src_offset.y + src_extent.height)
+ / (float)src_iview->extent.height,
(float)src_offset.z / (float)src_iview->extent.depth,
},
};
},
.tex_coord = {
(float)src_offset.x / (float)src_iview->extent.width,
- (float)(src_offset.y + src_extent.height) / (float)src_iview->extent.height,
+ (float)(src_offset.y + src_extent.height) /
+ (float)src_iview->extent.height,
(float)src_offset.z / (float)src_iview->extent.depth,
},
};
},
};
- anv_state_clflush(vb_state);
+ if (!device->info.has_llc)
+ anv_state_clflush(vb_state);
struct anv_buffer vertex_buffer = {
.device = device,
VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
}
- anv_CmdSetViewport(anv_cmd_buffer_to_handle(cmd_buffer), 0, 1,
- &(VkViewport) {
- .x = 0.0f,
- .y = 0.0f,
- .width = dest_iview->extent.width,
- .height = dest_iview->extent.height,
- .minDepth = 0.0f,
- .maxDepth = 1.0f,
- });
-
anv_CmdBindDescriptorSets(anv_cmd_buffer_to_handle(cmd_buffer),
VK_PIPELINE_BIND_POINT_GRAPHICS,
device->meta_state.blit.pipeline_layout, 0, 1,
anv_meta_restore(saved_state, cmd_buffer);
}
-void
-anv_meta_end_blit2d(struct anv_cmd_buffer *cmd_buffer,
- struct anv_meta_saved_state *save)
-{
- meta_finish_blit(cmd_buffer, save);
-}
-
-static VkFormat
-vk_format_for_size(int bs)
-{
- /* The choice of UNORM and UINT formats is very intentional here. Most of
- * the time, we want to use a UINT format to avoid any rounding error in
- * the blit. For stencil blits, R8_UINT is required by the hardware.
- * (It's the only format allowed in conjunction with W-tiling.) Also we
- * intentionally use the 4-channel formats whenever we can. This is so
- * that, when we do a RGB <-> RGBX copy, the two formats will line up even
- * though one of them is 3/4 the size of the other. The choice of UNORM
- * vs. UINT is also very intentional because Haswell doesn't handle 8 or
- * 16-bit RGB UINT formats at all so we have to use UNORM there.
- * Fortunately, the only time we should ever use two different formats in
- * the table below is for RGB -> RGBA blits and so we will never have any
- * UNORM/UINT mismatch.
- */
- switch (bs) {
- case 1: return VK_FORMAT_R8_UINT;
- case 2: return VK_FORMAT_R8G8_UINT;
- case 3: return VK_FORMAT_R8G8B8_UNORM;
- case 4: return VK_FORMAT_R8G8B8A8_UNORM;
- case 6: return VK_FORMAT_R16G16B16_UNORM;
- case 8: return VK_FORMAT_R16G16B16A16_UNORM;
- case 12: return VK_FORMAT_R32G32B32_UINT;
- case 16: return VK_FORMAT_R32G32B32A32_UINT;
- default:
- unreachable("Invalid format block size");
- }
-}
-
-static struct anv_meta_blit2d_surf
-blit_surf_for_image(const struct anv_image* image,
- const struct isl_surf *img_isl_surf)
-{
- return (struct anv_meta_blit2d_surf) {
- .bo = image->bo,
- .tiling = img_isl_surf->tiling,
- .base_offset = image->offset,
- .bs = isl_format_get_layout(img_isl_surf->format)->bs,
- .pitch = isl_surf_get_row_pitch(img_isl_surf),
- };
-}
-
-void
-anv_meta_blit2d(struct anv_cmd_buffer *cmd_buffer,
- struct anv_meta_blit2d_surf *src,
- struct anv_meta_blit2d_surf *dst,
- unsigned num_rects,
- struct anv_meta_blit2d_rect *rects)
-{
- VkDevice vk_device = anv_device_to_handle(cmd_buffer->device);
- VkFormat src_format = vk_format_for_size(src->bs);
- VkFormat dst_format = vk_format_for_size(dst->bs);
-
- for (unsigned r = 0; r < num_rects; ++r) {
-
- /* Create VkImages */
- VkImageCreateInfo image_info = {
- .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
- .imageType = VK_IMAGE_TYPE_2D,
- .format = 0, /* TEMPLATE */
- .extent = {
- .width = 0, /* TEMPLATE */
- /* Pad to highest tile height to compensate for a vertical intratile offset */
- .height = MIN(rects[r].height + 64, 1 << 14),
- .depth = 1,
- },
- .mipLevels = 1,
- .arrayLayers = 1,
- .samples = 1,
- .tiling = 0, /* TEMPLATE */
- .usage = 0, /* TEMPLATE */
- };
- struct anv_image_create_info anv_image_info = {
- .vk_info = &image_info,
- .isl_tiling_flags = 0, /* TEMPLATE */
- };
-
- anv_image_info.isl_tiling_flags = 1 << src->tiling;
- image_info.tiling = anv_image_info.isl_tiling_flags == ISL_TILING_LINEAR_BIT ?
- VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL;
- image_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
- image_info.format = src_format,
- image_info.extent.width = src->pitch / src->bs;
- VkImage src_image;
- anv_image_create(vk_device, &anv_image_info,
- &cmd_buffer->pool->alloc, &src_image);
-
- anv_image_info.isl_tiling_flags = 1 << dst->tiling;
- image_info.tiling = anv_image_info.isl_tiling_flags == ISL_TILING_LINEAR_BIT ?
- VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL;
- image_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
- image_info.format = dst_format,
- image_info.extent.width = dst->pitch / dst->bs;
- VkImage dst_image;
- anv_image_create(vk_device, &anv_image_info,
- &cmd_buffer->pool->alloc, &dst_image);
-
- /* We could use a vk call to bind memory, but that would require
- * creating a dummy memory object etc. so there's really no point.
- */
- anv_image_from_handle(src_image)->bo = src->bo;
- anv_image_from_handle(src_image)->offset = src->base_offset;
- anv_image_from_handle(dst_image)->bo = dst->bo;
- anv_image_from_handle(dst_image)->offset = dst->base_offset;
-
- /* Create VkImageViews */
- VkImageViewCreateInfo iview_info = {
- .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
- .image = 0, /* TEMPLATE */
- .viewType = VK_IMAGE_VIEW_TYPE_2D,
- .format = 0, /* TEMPLATE */
- .subresourceRange = {
- .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
- .baseMipLevel = 0,
- .levelCount = 1,
- .baseArrayLayer = 0,
- .layerCount = 1
- },
- };
- uint32_t img_o = 0;
-
- iview_info.image = src_image;
- iview_info.format = src_format;
- VkOffset3D src_offset_el = {0};
- isl_surf_get_image_intratile_offset_el_xy(&cmd_buffer->device->isl_dev,
- &anv_image_from_handle(src_image)->
- color_surface.isl,
- rects[r].src_x,
- rects[r].src_y,
- &img_o,
- (uint32_t*)&src_offset_el.x,
- (uint32_t*)&src_offset_el.y);
-
- struct anv_image_view src_iview;
- anv_image_view_init(&src_iview, cmd_buffer->device,
- &iview_info, cmd_buffer, img_o, VK_IMAGE_USAGE_SAMPLED_BIT);
-
- iview_info.image = dst_image;
- iview_info.format = dst_format;
- VkOffset3D dst_offset_el = {0};
- isl_surf_get_image_intratile_offset_el_xy(&cmd_buffer->device->isl_dev,
- &anv_image_from_handle(dst_image)->
- color_surface.isl,
- rects[r].dst_x,
- rects[r].dst_y,
- &img_o,
- (uint32_t*)&dst_offset_el.x,
- (uint32_t*)&dst_offset_el.y);
- struct anv_image_view dst_iview;
- anv_image_view_init(&dst_iview, cmd_buffer->device,
- &iview_info, cmd_buffer, img_o, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
-
- /* Perform blit */
- meta_emit_blit(cmd_buffer,
- anv_image_from_handle(src_image),
- &src_iview,
- src_offset_el,
- (VkExtent3D){rects[r].width, rects[r].height, 1},
- anv_image_from_handle(dst_image),
- &dst_iview,
- dst_offset_el,
- (VkExtent3D){rects[r].width, rects[r].height, 1},
- VK_FILTER_NEAREST);
-
- anv_DestroyImage(vk_device, src_image, &cmd_buffer->pool->alloc);
- anv_DestroyImage(vk_device, dst_image, &cmd_buffer->pool->alloc);
- }
-}
-
-static void
-do_buffer_copy(struct anv_cmd_buffer *cmd_buffer,
- struct anv_bo *src, uint64_t src_offset,
- struct anv_bo *dest, uint64_t dest_offset,
- int width, int height, int bs)
-{
- VkDevice vk_device = anv_device_to_handle(cmd_buffer->device);
- VkFormat copy_format = vk_format_for_size(bs);
-
- VkImageCreateInfo image_info = {
- .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
- .imageType = VK_IMAGE_TYPE_2D,
- .format = copy_format,
- .extent = {
- .width = width,
- .height = height,
- .depth = 1,
- },
- .mipLevels = 1,
- .arrayLayers = 1,
- .samples = 1,
- .tiling = VK_IMAGE_TILING_LINEAR,
- .usage = 0,
- .flags = 0,
- };
-
- VkImage src_image;
- image_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
- anv_CreateImage(vk_device, &image_info,
- &cmd_buffer->pool->alloc, &src_image);
-
- VkImage dest_image;
- image_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
- anv_CreateImage(vk_device, &image_info,
- &cmd_buffer->pool->alloc, &dest_image);
-
- /* We could use a vk call to bind memory, but that would require
- * creating a dummy memory object etc. so there's really no point.
- */
- anv_image_from_handle(src_image)->bo = src;
- anv_image_from_handle(src_image)->offset = src_offset;
- anv_image_from_handle(dest_image)->bo = dest;
- anv_image_from_handle(dest_image)->offset = dest_offset;
-
- VkImageViewCreateInfo iview_info = {
- .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
- .image = 0, /* TEMPLATE */
- .viewType = VK_IMAGE_VIEW_TYPE_2D,
- .format = copy_format,
- .subresourceRange = {
- .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
- .baseMipLevel = 0,
- .levelCount = 1,
- .baseArrayLayer = 0,
- .layerCount = 1
- },
- };
-
- struct anv_image_view src_iview;
- iview_info.image = src_image;
- anv_image_view_init(&src_iview, cmd_buffer->device,
- &iview_info, cmd_buffer, 0, VK_IMAGE_USAGE_SAMPLED_BIT);
-
- struct anv_image_view dest_iview;
- iview_info.image = dest_image;
- anv_image_view_init(&dest_iview, cmd_buffer->device,
- &iview_info, cmd_buffer, 0, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
-
- meta_emit_blit(cmd_buffer,
- anv_image_from_handle(src_image),
- &src_iview,
- (VkOffset3D) { 0, 0, 0 },
- (VkExtent3D) { width, height, 1 },
- anv_image_from_handle(dest_image),
- &dest_iview,
- (VkOffset3D) { 0, 0, 0 },
- (VkExtent3D) { width, height, 1 },
- VK_FILTER_NEAREST);
-
- anv_DestroyImage(vk_device, src_image, &cmd_buffer->pool->alloc);
- anv_DestroyImage(vk_device, dest_image, &cmd_buffer->pool->alloc);
-}
-
-void anv_CmdCopyBuffer(
- VkCommandBuffer commandBuffer,
- VkBuffer srcBuffer,
- VkBuffer destBuffer,
- uint32_t regionCount,
- const VkBufferCopy* pRegions)
-{
- ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
- ANV_FROM_HANDLE(anv_buffer, src_buffer, srcBuffer);
- ANV_FROM_HANDLE(anv_buffer, dest_buffer, destBuffer);
-
- struct anv_meta_saved_state saved_state;
-
- meta_prepare_blit(cmd_buffer, &saved_state);
-
- for (unsigned r = 0; r < regionCount; r++) {
- uint64_t src_offset = src_buffer->offset + pRegions[r].srcOffset;
- uint64_t dest_offset = dest_buffer->offset + pRegions[r].dstOffset;
- uint64_t copy_size = pRegions[r].size;
-
- /* First, we compute the biggest format that can be used with the
- * given offsets and size.
- */
- int bs = 16;
-
- int fs = ffs(src_offset) - 1;
- if (fs != -1)
- bs = MIN2(bs, 1 << fs);
- assert(src_offset % bs == 0);
-
- fs = ffs(dest_offset) - 1;
- if (fs != -1)
- bs = MIN2(bs, 1 << fs);
- assert(dest_offset % bs == 0);
-
- fs = ffs(pRegions[r].size) - 1;
- if (fs != -1)
- bs = MIN2(bs, 1 << fs);
- assert(pRegions[r].size % bs == 0);
-
- /* This is maximum possible width/height our HW can handle */
- uint64_t max_surface_dim = 1 << 14;
-
- /* First, we make a bunch of max-sized copies */
- uint64_t max_copy_size = max_surface_dim * max_surface_dim * bs;
- while (copy_size >= max_copy_size) {
- do_buffer_copy(cmd_buffer, src_buffer->bo, src_offset,
- dest_buffer->bo, dest_offset,
- max_surface_dim, max_surface_dim, bs);
- copy_size -= max_copy_size;
- src_offset += max_copy_size;
- dest_offset += max_copy_size;
- }
-
- uint64_t height = copy_size / (max_surface_dim * bs);
- assert(height < max_surface_dim);
- if (height != 0) {
- uint64_t rect_copy_size = height * max_surface_dim * bs;
- do_buffer_copy(cmd_buffer, src_buffer->bo, src_offset,
- dest_buffer->bo, dest_offset,
- max_surface_dim, height, bs);
- copy_size -= rect_copy_size;
- src_offset += rect_copy_size;
- dest_offset += rect_copy_size;
- }
-
- if (copy_size != 0) {
- do_buffer_copy(cmd_buffer, src_buffer->bo, src_offset,
- dest_buffer->bo, dest_offset,
- copy_size / bs, 1, bs);
- }
- }
-
- meta_finish_blit(cmd_buffer, &saved_state);
-}
-
-void anv_CmdUpdateBuffer(
- VkCommandBuffer commandBuffer,
- VkBuffer dstBuffer,
- VkDeviceSize dstOffset,
- VkDeviceSize dataSize,
- const uint32_t* pData)
-{
- ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
- ANV_FROM_HANDLE(anv_buffer, dst_buffer, dstBuffer);
- struct anv_meta_saved_state saved_state;
-
- meta_prepare_blit(cmd_buffer, &saved_state);
-
- /* We can't quite grab a full block because the state stream needs a
- * little data at the top to build its linked list.
- */
- const uint32_t max_update_size =
- cmd_buffer->device->dynamic_state_block_pool.block_size - 64;
-
- assert(max_update_size < (1 << 14) * 4);
-
- while (dataSize) {
- const uint32_t copy_size = MIN2(dataSize, max_update_size);
-
- struct anv_state tmp_data =
- anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, copy_size, 64);
-
- memcpy(tmp_data.map, pData, copy_size);
-
- int bs;
- if ((copy_size & 15) == 0 && (dstOffset & 15) == 0) {
- bs = 16;
- } else if ((copy_size & 7) == 0 && (dstOffset & 7) == 0) {
- bs = 8;
- } else {
- assert((copy_size & 3) == 0 && (dstOffset & 3) == 0);
- bs = 4;
- }
-
- do_buffer_copy(cmd_buffer,
- &cmd_buffer->device->dynamic_state_block_pool.bo,
- tmp_data.offset,
- dst_buffer->bo, dst_buffer->offset + dstOffset,
- copy_size / bs, 1, bs);
-
- dataSize -= copy_size;
- dstOffset += copy_size;
- pData = (void *)pData + copy_size;
- }
-
- meta_finish_blit(cmd_buffer, &saved_state);
-}
-
-static VkFormat
-choose_iview_format(struct anv_image *image, VkImageAspectFlagBits aspect)
-{
- assert(__builtin_popcount(aspect) == 1);
-
- struct isl_surf *surf =
- &anv_image_get_surface_for_aspect_mask(image, aspect)->isl;
-
- /* vkCmdCopyImage behaves like memcpy. Therefore we choose identical UINT
- * formats for the source and destination image views.
- *
- * From the Vulkan spec (2015-12-30):
- *
- * vkCmdCopyImage performs image copies in a similar manner to a host
- * memcpy. It does not perform general-purpose conversions such as
- * scaling, resizing, blending, color-space conversion, or format
- * conversions. Rather, it simply copies raw image data. vkCmdCopyImage
- * can copy between images with different formats, provided the formats
- * are compatible as defined below.
- *
- * [The spec later defines compatibility as having the same number of
- * bytes per block].
- */
- return vk_format_for_size(isl_format_layouts[surf->format].bs);
-}
-
-static VkFormat
-choose_buffer_format(VkFormat format, VkImageAspectFlagBits aspect)
-{
- assert(__builtin_popcount(aspect) == 1);
-
- /* vkCmdCopy* commands behave like memcpy. Therefore we choose
- * compatable UINT formats for the source and destination image views.
- *
- * For the buffer, we go back to the original image format and get a
- * the format as if it were linear. This way, for RGB formats, we get
- * an RGB format here even if the tiled image is RGBA. XXX: This doesn't
- * work if the buffer is the destination.
- */
- enum isl_format linear_format = anv_get_isl_format(format, aspect,
- VK_IMAGE_TILING_LINEAR,
- NULL);
-
- return vk_format_for_size(isl_format_layouts[linear_format].bs);
-}
-
-void anv_CmdCopyImage(
- VkCommandBuffer commandBuffer,
- VkImage srcImage,
- VkImageLayout srcImageLayout,
- VkImage destImage,
- VkImageLayout destImageLayout,
- uint32_t regionCount,
- const VkImageCopy* pRegions)
-{
- ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
- ANV_FROM_HANDLE(anv_image, src_image, srcImage);
- ANV_FROM_HANDLE(anv_image, dest_image, destImage);
- struct anv_meta_saved_state saved_state;
-
- /* From the Vulkan 1.0 spec:
- *
- * vkCmdCopyImage can be used to copy image data between multisample
- * images, but both images must have the same number of samples.
- */
- assert(src_image->samples == dest_image->samples);
-
- meta_prepare_blit(cmd_buffer, &saved_state);
-
- for (unsigned r = 0; r < regionCount; r++) {
- assert(pRegions[r].srcSubresource.aspectMask ==
- pRegions[r].dstSubresource.aspectMask);
-
- VkImageAspectFlags aspect = pRegions[r].srcSubresource.aspectMask;
-
- VkFormat src_format = choose_iview_format(src_image, aspect);
- VkFormat dst_format = choose_iview_format(dest_image, aspect);
-
- struct anv_image_view src_iview;
- anv_image_view_init(&src_iview, cmd_buffer->device,
- &(VkImageViewCreateInfo) {
- .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
- .image = srcImage,
- .viewType = anv_meta_get_view_type(src_image),
- .format = src_format,
- .subresourceRange = {
- .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
- .baseMipLevel = pRegions[r].srcSubresource.mipLevel,
- .levelCount = 1,
- .baseArrayLayer = pRegions[r].srcSubresource.baseArrayLayer,
- .layerCount = pRegions[r].dstSubresource.layerCount,
- },
- },
- cmd_buffer, 0, VK_IMAGE_USAGE_SAMPLED_BIT);
-
- const uint32_t dest_base_array_slice =
- anv_meta_get_iview_layer(dest_image, &pRegions[r].dstSubresource,
- &pRegions[r].dstOffset);
-
-
- unsigned num_slices_3d = pRegions[r].extent.depth;
- unsigned num_slices_array = pRegions[r].dstSubresource.layerCount;
- unsigned slice_3d = 0;
- unsigned slice_array = 0;
- while (slice_3d < num_slices_3d && slice_array < num_slices_array) {
- VkOffset3D src_offset = pRegions[r].srcOffset;
- src_offset.z += slice_3d + slice_array;
-
- uint32_t img_x = 0;
- uint32_t img_y = 0;
- uint32_t img_o = 0;
- if (isl_format_is_compressed(dest_image->format->isl_format))
- isl_surf_get_image_intratile_offset_el(&cmd_buffer->device->isl_dev,
- &dest_image->color_surface.isl,
- pRegions[r].dstSubresource.mipLevel,
- pRegions[r].dstSubresource.baseArrayLayer + slice_array,
- pRegions[r].dstOffset.z + slice_3d,
- &img_o, &img_x, &img_y);
-
- VkOffset3D dest_offset_el = meta_region_offset_el(dest_image, &pRegions[r].dstOffset);
- dest_offset_el.x += img_x;
- dest_offset_el.y += img_y;
- dest_offset_el.z = 0;
-
- struct anv_image_view dest_iview;
- anv_image_view_init(&dest_iview, cmd_buffer->device,
- &(VkImageViewCreateInfo) {
- .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
- .image = destImage,
- .viewType = anv_meta_get_view_type(dest_image),
- .format = dst_format,
- .subresourceRange = {
- .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
- .baseMipLevel = pRegions[r].dstSubresource.mipLevel,
- .levelCount = 1,
- .baseArrayLayer = dest_base_array_slice +
- slice_array + slice_3d,
- .layerCount = 1
- },
- },
- cmd_buffer, img_o, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
-
- const VkExtent3D img_extent_el = meta_region_extent_el(dest_image->vk_format,
- &pRegions[r].extent);
-
- meta_emit_blit(cmd_buffer,
- src_image, &src_iview,
- src_offset,
- img_extent_el,
- dest_image, &dest_iview,
- dest_offset_el,
- img_extent_el,
- VK_FILTER_NEAREST);
-
- if (dest_image->type == VK_IMAGE_TYPE_3D)
- slice_3d++;
- else
- slice_array++;
- }
- }
-
- meta_finish_blit(cmd_buffer, &saved_state);
-}
-
void anv_CmdBlitImage(
VkCommandBuffer commandBuffer,
VkImage srcImage,
assert(src_image->samples == 1);
assert(dest_image->samples == 1);
- anv_finishme("respect VkFilter");
-
meta_prepare_blit(cmd_buffer, &saved_state);
for (unsigned r = 0; r < regionCount; r++) {
.layerCount = 1
},
},
- cmd_buffer, 0, VK_IMAGE_USAGE_SAMPLED_BIT);
+ cmd_buffer, VK_IMAGE_USAGE_SAMPLED_BIT);
const VkOffset3D dest_offset = {
.x = pRegions[r].dstOffsets[0].x,
.layerCount = 1
},
},
- cmd_buffer, 0, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
+ cmd_buffer, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
meta_emit_blit(cmd_buffer,
src_image, &src_iview,
meta_finish_blit(cmd_buffer, &saved_state);
}
-static void
-meta_copy_buffer_to_image(struct anv_cmd_buffer *cmd_buffer,
- struct anv_buffer* buffer,
- struct anv_image* image,
- uint32_t regionCount,
- const VkBufferImageCopy* pRegions,
- bool forward)
-{
- struct anv_meta_saved_state saved_state;
-
- /* The Vulkan 1.0 spec says "dstImage must have a sample count equal to
- * VK_SAMPLE_COUNT_1_BIT."
- */
- assert(image->samples == 1);
-
- anv_meta_begin_blit2d(cmd_buffer, &saved_state);
-
- for (unsigned r = 0; r < regionCount; r++) {
-
- /* Start creating blit rect */
- const VkOffset3D img_offset_el = meta_region_offset_el(image, &pRegions[r].imageOffset);
- const VkExtent3D bufferExtent = {
- .width = pRegions[r].bufferRowLength,
- .height = pRegions[r].bufferImageHeight,
- };
- const VkExtent3D buf_extent_el = meta_region_extent_el(image->vk_format, &bufferExtent);
- const VkExtent3D img_extent_el = meta_region_extent_el(image->vk_format,
- &pRegions[r].imageExtent);
- struct anv_meta_blit2d_rect rect = {
- .width = MAX2(buf_extent_el.width, img_extent_el.width),
- .height = MAX2(buf_extent_el.height, img_extent_el.height),
- };
-
- /* Create blit surfaces */
- VkImageAspectFlags aspect = pRegions[r].imageSubresource.aspectMask;
- const struct isl_surf *img_isl_surf =
- &anv_image_get_surface_for_aspect_mask(image, aspect)->isl;
- struct anv_meta_blit2d_surf img_bsurf = blit_surf_for_image(image, img_isl_surf);
- struct anv_meta_blit2d_surf buf_bsurf = {
- .bo = buffer->bo,
- .tiling = ISL_TILING_LINEAR,
- .base_offset = buffer->offset + pRegions[r].bufferOffset,
- .bs = forward ? image->format->isl_layout->bs : img_bsurf.bs,
- .pitch = rect.width * buf_bsurf.bs,
- };
-
- /* Set direction-dependent variables */
- struct anv_meta_blit2d_surf *dst_bsurf = forward ? &img_bsurf : &buf_bsurf;
- struct anv_meta_blit2d_surf *src_bsurf = forward ? &buf_bsurf : &img_bsurf;
- uint32_t *x_offset = forward ? &rect.dst_x : &rect.src_x;
- uint32_t *y_offset = forward ? &rect.dst_y : &rect.src_y;
-
- /* Loop through each 3D or array slice */
- unsigned num_slices_3d = pRegions[r].imageExtent.depth;
- unsigned num_slices_array = pRegions[r].imageSubresource.layerCount;
- unsigned slice_3d = 0;
- unsigned slice_array = 0;
- while (slice_3d < num_slices_3d && slice_array < num_slices_array) {
-
- /* Finish creating blit rect */
- isl_surf_get_image_offset_el(img_isl_surf,
- pRegions[r].imageSubresource.mipLevel,
- pRegions[r].imageSubresource.baseArrayLayer + slice_array,
- pRegions[r].imageOffset.z + slice_3d,
- x_offset,
- y_offset);
- *x_offset += img_offset_el.x;
- *y_offset += img_offset_el.y;
-
- /* Perform Blit */
- anv_meta_blit2d(cmd_buffer,
- src_bsurf,
- dst_bsurf,
- 1,
- &rect);
-
- /* Once we've done the blit, all of the actual information about
- * the image is embedded in the command buffer so we can just
- * increment the offset directly in the image effectively
- * re-binding it to different backing memory.
- */
- buf_bsurf.base_offset += rect.width * rect.height * buf_bsurf.bs;
-
- if (image->type == VK_IMAGE_TYPE_3D)
- slice_3d++;
- else
- slice_array++;
- }
- }
- anv_meta_end_blit2d(cmd_buffer, &saved_state);
-}
-
-static struct anv_image *
-make_image_for_buffer(VkDevice vk_device, VkBuffer vk_buffer, VkFormat format,
- VkImageUsageFlags usage,
- VkImageType image_type,
- const VkAllocationCallbacks *alloc,
- const VkBufferImageCopy *copy)
-{
- ANV_FROM_HANDLE(anv_buffer, buffer, vk_buffer);
-
- VkExtent3D extent = copy->imageExtent;
- if (copy->bufferRowLength)
- extent.width = copy->bufferRowLength;
- if (copy->bufferImageHeight)
- extent.height = copy->bufferImageHeight;
- extent.depth = 1;
- extent = meta_region_extent_el(format, &extent);
-
- VkImageAspectFlags aspect = copy->imageSubresource.aspectMask;
- VkFormat buffer_format = choose_buffer_format(format, aspect);
-
- VkImage vk_image;
- VkResult result = anv_CreateImage(vk_device,
- &(VkImageCreateInfo) {
- .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
- .imageType = VK_IMAGE_TYPE_2D,
- .format = buffer_format,
- .extent = extent,
- .mipLevels = 1,
- .arrayLayers = 1,
- .samples = 1,
- .tiling = VK_IMAGE_TILING_LINEAR,
- .usage = usage,
- .flags = 0,
- }, alloc, &vk_image);
- assert(result == VK_SUCCESS);
-
- ANV_FROM_HANDLE(anv_image, image, vk_image);
-
- /* We could use a vk call to bind memory, but that would require
- * creating a dummy memory object etc. so there's really no point.
- */
- image->bo = buffer->bo;
- image->offset = buffer->offset + copy->bufferOffset;
-
- return image;
-}
-
-void anv_CmdCopyBufferToImage(
- VkCommandBuffer commandBuffer,
- VkBuffer srcBuffer,
- VkImage destImage,
- VkImageLayout destImageLayout,
- uint32_t regionCount,
- const VkBufferImageCopy* pRegions)
-{
- ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
- ANV_FROM_HANDLE(anv_image, dest_image, destImage);
- ANV_FROM_HANDLE(anv_buffer, src_buffer, srcBuffer);
-
- meta_copy_buffer_to_image(cmd_buffer, src_buffer, dest_image,
- regionCount, pRegions, true);
-}
-
-void anv_CmdCopyImageToBuffer(
- VkCommandBuffer commandBuffer,
- VkImage srcImage,
- VkImageLayout srcImageLayout,
- VkBuffer destBuffer,
- uint32_t regionCount,
- const VkBufferImageCopy* pRegions)
-{
- ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
- ANV_FROM_HANDLE(anv_image, src_image, srcImage);
- ANV_FROM_HANDLE(anv_buffer, dst_buffer, destBuffer);
-
- meta_copy_buffer_to_image(cmd_buffer, dst_buffer, src_image,
- regionCount, pRegions, false);
-}
-
void
anv_device_finish_meta_blit_state(struct anv_device *device)
{
{
.binding = 0,
.stride = 0,
- .inputRate = VK_VERTEX_INPUT_RATE_VERTEX
+ .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
},
{
.binding = 1,
const struct anv_graphics_pipeline_create_info anv_pipeline_info = {
.color_attachment_count = -1,
.use_repclear = false,
- .disable_viewport = true,
- .disable_scissor = true,
.disable_vs = true,
.use_rectlist = true
};