[4/8] radv: handle sample locations during explicit depth/stencil transitions

Submitted by Samuel Pitoiset on May 30, 2019, 2:05 p.m.

Details

Message ID 20190530140521.31502-5-samuel.pitoiset@gmail.com
State New
Headers show
Series "radv: add support for sample locations during layout transitions" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Samuel Pitoiset May 30, 2019, 2:05 p.m.
From the Vulkan spec 1.1.109,

   "Some implementations may need to evaluate depth image values
    while performing image layout transitions. To accommodate this,
    instances of the VkSampleLocationsInfoEXT structure can be
    specified for each situation where an explicit or automatic
    layout transition has to take place. VkSampleLocationsInfoEXT
    can be chained from VkImageMemoryBarrier structures to provide
    sample locations for layout transitions performed by
    vkCmdWaitEvents and vkCmdPipelineBarrier calls."

This handles explicit depth/stencil layout transitions performed
with CmdWaitEvents() or CmdPipelineBarrier().

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
---
 src/amd/vulkan/radv_cmd_buffer.c | 35 +++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/amd/vulkan/radv_cmd_buffer.c b/src/amd/vulkan/radv_cmd_buffer.c
index 8db4fcdbdc1..570acaa0905 100644
--- a/src/amd/vulkan/radv_cmd_buffer.c
+++ b/src/amd/vulkan/radv_cmd_buffer.c
@@ -32,6 +32,7 @@ 
 #include "sid.h"
 #include "gfx9d.h"
 #include "vk_format.h"
+#include "vk_util.h"
 #include "radv_debug.h"
 #include "radv_meta.h"
 
@@ -57,7 +58,8 @@  static void radv_handle_image_transition(struct radv_cmd_buffer *cmd_buffer,
 					 VkImageLayout dst_layout,
 					 uint32_t src_family,
 					 uint32_t dst_family,
-					 const VkImageSubresourceRange *range);
+					 const VkImageSubresourceRange *range,
+					 struct radv_sample_locations_state *sample_locs);
 
 const struct radv_dynamic_state default_dynamic_state = {
 	.viewport = {
@@ -2669,7 +2671,7 @@  static void radv_handle_subpass_image_transition(struct radv_cmd_buffer *cmd_buf
 	radv_handle_image_transition(cmd_buffer,
 				     view->image,
 				     cmd_buffer->state.attachments[idx].current_layout,
-				     att.layout, 0, 0, &range);
+				     att.layout, 0, 0, &range, NULL);
 
 	cmd_buffer->state.attachments[idx].current_layout = att.layout;
 
@@ -4651,7 +4653,8 @@  static void radv_handle_depth_image_transition(struct radv_cmd_buffer *cmd_buffe
 					       VkImageLayout dst_layout,
 					       unsigned src_queue_mask,
 					       unsigned dst_queue_mask,
-					       const VkImageSubresourceRange *range)
+					       const VkImageSubresourceRange *range,
+					       struct radv_sample_locations_state *sample_locs)
 {
 	if (!radv_image_has_htile(image))
 		return;
@@ -4680,7 +4683,7 @@  static void radv_handle_depth_image_transition(struct radv_cmd_buffer *cmd_buffe
 		                                RADV_CMD_FLAG_FLUSH_AND_INV_DB_META;
 
 		radv_decompress_depth_image_inplace(cmd_buffer, image,
-						    &local_range, NULL);
+						    &local_range, sample_locs);
 
 		cmd_buffer->state.flush_bits |= RADV_CMD_FLAG_FLUSH_AND_INV_DB |
 		                                RADV_CMD_FLAG_FLUSH_AND_INV_DB_META;
@@ -4842,7 +4845,8 @@  static void radv_handle_image_transition(struct radv_cmd_buffer *cmd_buffer,
 					 VkImageLayout dst_layout,
 					 uint32_t src_family,
 					 uint32_t dst_family,
-					 const VkImageSubresourceRange *range)
+					 const VkImageSubresourceRange *range,
+					 struct radv_sample_locations_state *sample_locs)
 {
 	if (image->exclusive && src_family != dst_family) {
 		/* This is an acquire or a release operation and there will be
@@ -4875,7 +4879,7 @@  static void radv_handle_image_transition(struct radv_cmd_buffer *cmd_buffer,
 		radv_handle_depth_image_transition(cmd_buffer, image,
 						   src_layout, dst_layout,
 						   src_queue_mask, dst_queue_mask,
-						   range);
+						   range, sample_locs);
 	} else {
 		radv_handle_color_image_transition(cmd_buffer, image,
 						   src_layout, dst_layout,
@@ -4957,12 +4961,29 @@  radv_barrier(struct radv_cmd_buffer *cmd_buffer,
 
 	for (uint32_t i = 0; i < imageMemoryBarrierCount; i++) {
 		RADV_FROM_HANDLE(radv_image, image, pImageMemoryBarriers[i].image);
+
+		const struct VkSampleLocationsInfoEXT *sample_locs_info =
+			vk_find_struct_const(pImageMemoryBarriers[i].pNext,
+					     SAMPLE_LOCATIONS_INFO_EXT);
+		struct radv_sample_locations_state sample_locations = {};
+
+		if (sample_locs_info) {
+			assert(image->flags & VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT);
+			sample_locations.per_pixel = sample_locs_info->sampleLocationsPerPixel;
+			sample_locations.grid_size = sample_locs_info->sampleLocationGridSize;
+			sample_locations.count = sample_locs_info->sampleLocationsCount;
+			typed_memcpy(&sample_locations.locations[0],
+				     sample_locs_info->pSampleLocations,
+				     sample_locs_info->sampleLocationsCount);
+		}
+
 		radv_handle_image_transition(cmd_buffer, image,
 					     pImageMemoryBarriers[i].oldLayout,
 					     pImageMemoryBarriers[i].newLayout,
 					     pImageMemoryBarriers[i].srcQueueFamilyIndex,
 					     pImageMemoryBarriers[i].dstQueueFamilyIndex,
-					     &pImageMemoryBarriers[i].subresourceRange);
+					     &pImageMemoryBarriers[i].subresourceRange,
+					     sample_locs_info ? &sample_locations : NULL);
 	}
 
 	/* Make sure CP DMA is idle because the driver might have performed a