turnip: basic msaa working
authorJonathan Marek <jonathan@marek.ca>
Mon, 14 Oct 2019 16:46:37 +0000 (12:46 -0400)
committerJonathan Marek <jonathan@marek.ca>
Tue, 15 Oct 2019 11:56:20 +0000 (07:56 -0400)
Not perfect but gets through some tests.

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
src/freedreno/vulkan/tu_cmd_buffer.c
src/freedreno/vulkan/tu_device.c
src/freedreno/vulkan/tu_image.c
src/freedreno/vulkan/tu_meta_resolve.c

index 3043740626f97d04bb650abd0ec9d3a619910a6c..9e8889a45b2e1853088ad52d884487a66c4575ce 100644 (file)
@@ -34,6 +34,7 @@
 #include "vk_format.h"
 
 #include "tu_cs.h"
+#include "tu_blit.h"
 
 void
 tu_bo_list_init(struct tu_bo_list *list)
@@ -515,28 +516,22 @@ tu6_emit_msaa(struct tu_cmd_buffer *cmd, struct tu_cs *cs)
 {
    const struct tu_subpass *subpass = cmd->state.subpass;
    const enum a3xx_msaa_samples samples =
-      tu6_msaa_samples(subpass->max_sample_count);
+      tu_msaa_samples(subpass->max_sample_count);
 
    tu_cs_emit_pkt4(cs, REG_A6XX_SP_TP_RAS_MSAA_CNTL, 2);
    tu_cs_emit(cs, A6XX_SP_TP_RAS_MSAA_CNTL_SAMPLES(samples));
-   tu_cs_emit(
-      cs, A6XX_SP_TP_DEST_MSAA_CNTL_SAMPLES(samples) |
-             ((samples == MSAA_ONE) ? A6XX_SP_TP_DEST_MSAA_CNTL_MSAA_DISABLE
-                                    : 0));
+   tu_cs_emit(cs, A6XX_SP_TP_DEST_MSAA_CNTL_SAMPLES(samples) |
+              COND(samples == MSAA_ONE, A6XX_SP_TP_DEST_MSAA_CNTL_MSAA_DISABLE));
 
    tu_cs_emit_pkt4(cs, REG_A6XX_GRAS_RAS_MSAA_CNTL, 2);
    tu_cs_emit(cs, A6XX_GRAS_RAS_MSAA_CNTL_SAMPLES(samples));
-   tu_cs_emit(
-      cs,
-      A6XX_GRAS_DEST_MSAA_CNTL_SAMPLES(samples) |
-         ((samples == MSAA_ONE) ? A6XX_GRAS_DEST_MSAA_CNTL_MSAA_DISABLE : 0));
+   tu_cs_emit(cs, A6XX_GRAS_DEST_MSAA_CNTL_SAMPLES(samples) |
+              COND(samples == MSAA_ONE, A6XX_GRAS_DEST_MSAA_CNTL_MSAA_DISABLE));
 
    tu_cs_emit_pkt4(cs, REG_A6XX_RB_RAS_MSAA_CNTL, 2);
    tu_cs_emit(cs, A6XX_RB_RAS_MSAA_CNTL_SAMPLES(samples));
-   tu_cs_emit(
-      cs,
-      A6XX_RB_DEST_MSAA_CNTL_SAMPLES(samples) |
-         ((samples == MSAA_ONE) ? A6XX_RB_DEST_MSAA_CNTL_MSAA_DISABLE : 0));
+   tu_cs_emit(cs, A6XX_RB_DEST_MSAA_CNTL_SAMPLES(samples) |
+              COND(samples == MSAA_ONE, A6XX_RB_DEST_MSAA_CNTL_MSAA_DISABLE));
 
    tu_cs_emit_pkt4(cs, REG_A6XX_RB_MSAA_CNTL, 1);
    tu_cs_emit(cs, A6XX_RB_MSAA_CNTL_SAMPLES(samples));
@@ -606,7 +601,6 @@ tu6_emit_blit_info(struct tu_cmd_buffer *cmd,
       &iview->image->levels[iview->base_mip];
    const uint32_t offset = slice->offset + slice->size * iview->base_layer;
    const uint32_t stride = slice->pitch * iview->image->cpp;
-   const enum a3xx_msaa_samples samples = tu6_msaa_samples(1);
 
    tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_INFO, 1);
    tu_cs_emit(cs, blit_info);
@@ -619,7 +613,7 @@ tu6_emit_blit_info(struct tu_cmd_buffer *cmd,
       tu6_get_image_tile_mode(iview->image, iview->base_mip);
    tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_DST_INFO, 5);
    tu_cs_emit(cs, A6XX_RB_BLIT_DST_INFO_TILE_MODE(tile_mode) |
-                     A6XX_RB_BLIT_DST_INFO_SAMPLES(samples) |
+                     A6XX_RB_BLIT_DST_INFO_SAMPLES(tu_msaa_samples(iview->image->samples)) |
                      A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(format->rb) |
                      A6XX_RB_BLIT_DST_INFO_COLOR_SWAP(format->swap));
    tu_cs_emit_qw(cs,
@@ -638,8 +632,6 @@ tu6_emit_blit_clear(struct tu_cmd_buffer *cmd,
                     uint32_t gmem_offset,
                     const VkClearValue *clear_value)
 {
-   const enum a3xx_msaa_samples samples = tu6_msaa_samples(1);
-
    const struct tu_native_format *format =
       tu6_get_native_format(iview->vk_format);
    assert(format && format->rb >= 0);
@@ -648,7 +640,7 @@ tu6_emit_blit_clear(struct tu_cmd_buffer *cmd,
 
    tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_DST_INFO, 1);
    tu_cs_emit(cs, A6XX_RB_BLIT_DST_INFO_TILE_MODE(TILE6_LINEAR) |
-                     A6XX_RB_BLIT_DST_INFO_SAMPLES(samples) |
+                     A6XX_RB_BLIT_DST_INFO_SAMPLES(tu_msaa_samples(iview->image->samples)) |
                      A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(format->rb) |
                      A6XX_RB_BLIT_DST_INFO_COLOR_SWAP(swap));
 
@@ -1074,6 +1066,9 @@ tu6_render_tile(struct tu_cmd_buffer *cmd,
 static void
 tu6_render_end(struct tu_cmd_buffer *cmd, struct tu_cs *cs)
 {
+   const struct tu_subpass *subpass = cmd->state.subpass;
+   const struct tu_framebuffer *fb = cmd->state.framebuffer;
+
    VkResult result = tu_cs_reserve_space(cmd->device, cs, 16);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
@@ -1087,6 +1082,31 @@ tu6_render_end(struct tu_cmd_buffer *cmd, struct tu_cs *cs)
 
    tu6_emit_event_write(cmd, cs, CACHE_FLUSH_TS, true);
 
+   if (subpass->has_resolve) {
+      for (uint32_t i = 0; i < subpass->color_count; ++i) {
+         struct tu_subpass_attachment src_att = subpass->color_attachments[i];
+         struct tu_subpass_attachment dst_att = subpass->resolve_attachments[i];
+
+         if (dst_att.attachment == VK_ATTACHMENT_UNUSED)
+            continue;
+
+         struct tu_image *src_img = fb->attachments[src_att.attachment].attachment->image;
+         struct tu_image *dst_img = fb->attachments[dst_att.attachment].attachment->image;
+
+         assert(src_img->extent.width == dst_img->extent.width);
+         assert(src_img->extent.height == dst_img->extent.height);
+
+         tu_bo_list_add(&cmd->bo_list, src_img->bo, MSM_SUBMIT_BO_READ);
+         tu_bo_list_add(&cmd->bo_list, dst_img->bo, MSM_SUBMIT_BO_WRITE);
+
+         tu_blit(cmd, &(struct tu_blit) {
+            .dst = tu_blit_surf_whole(dst_img),
+            .src = tu_blit_surf_whole(src_img),
+            .layers = 1,
+         }, false);
+      }
+   }
+
    tu_cs_sanity_check(cs);
 }
 
index 6f76a69b6320f45d9c7bd2aa93af5d656d86c60b..1635bfddb498ebec7b2007aac9cb3ce62a64d9b5 100644 (file)
@@ -703,7 +703,8 @@ tu_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
                                VkPhysicalDeviceProperties *pProperties)
 {
    TU_FROM_HANDLE(tu_physical_device, pdevice, physicalDevice);
-   VkSampleCountFlags sample_counts = 0xf;
+   VkSampleCountFlags sample_counts = VK_SAMPLE_COUNT_1_BIT |
+      VK_SAMPLE_COUNT_2_BIT | VK_SAMPLE_COUNT_4_BIT | VK_SAMPLE_COUNT_8_BIT;
 
    /* make sure that the entire descriptor set is addressable with a signed
     * 32-bit int. So the sum of all limits scaled by descriptor size has to
index 50bd1dbbb1929f219a8c90054eca47b785d25b4d..6c774de9f53c35ff63e264bf420785cb94187de8 100644 (file)
@@ -335,7 +335,7 @@ tu_image_view_init(struct tu_image_view *iview,
       A6XX_TEX_CONST_0_TILE_MODE(tile_mode) |
       COND(vk_format_is_srgb(iview->vk_format), A6XX_TEX_CONST_0_SRGB) |
       A6XX_TEX_CONST_0_FMT(fmt->tex) |
-      A6XX_TEX_CONST_0_SAMPLES(0) |
+      A6XX_TEX_CONST_0_SAMPLES(tu_msaa_samples(image->samples)) |
       A6XX_TEX_CONST_0_SWAP(image->tile_mode ? WZYX : fmt->swap) |
       tu6_texswiz(&pCreateInfo->components, vk_format_description(iview->vk_format)->swizzle) |
       A6XX_TEX_CONST_0_MIPLVLS(iview->level_count - 1);
index 4a9ebedfdabb62d275b454f886b8aced19ff7c35..74ce766aacf65d9547983dcab45348378fe5f89e 100644 (file)
 #include "nir/nir_builder.h"
 #include "vk_format.h"
 
+#include "tu_blit.h"
+
+static void
+tu_resolve_image(struct tu_cmd_buffer *cmdbuf,
+                 struct tu_image *src_image,
+                 struct tu_image *dst_image,
+                 const VkImageResolve *info)
+{
+   assert(info->dstSubresource.layerCount == info->srcSubresource.layerCount);
+
+   tu_blit(cmdbuf, &(struct tu_blit) {
+      .dst = tu_blit_surf_ext(dst_image, info->dstSubresource, info->dstOffset, info->extent),
+      .src = tu_blit_surf_ext(src_image, info->srcSubresource, info->srcOffset, info->extent),
+      .layers = MAX2(info->extent.depth, info->dstSubresource.layerCount)
+   }, false);
+}
+
 void
 tu_CmdResolveImage(VkCommandBuffer cmd_buffer_h,
                    VkImage src_image_h,
@@ -38,4 +55,13 @@ tu_CmdResolveImage(VkCommandBuffer cmd_buffer_h,
                    uint32_t region_count,
                    const VkImageResolve *regions)
 {
+   TU_FROM_HANDLE(tu_cmd_buffer, cmdbuf, cmd_buffer_h);
+   TU_FROM_HANDLE(tu_image, src_image, src_image_h);
+   TU_FROM_HANDLE(tu_image, dst_image, dest_image_h);
+
+   tu_bo_list_add(&cmdbuf->bo_list, src_image->bo, MSM_SUBMIT_BO_READ);
+   tu_bo_list_add(&cmdbuf->bo_list, dst_image->bo, MSM_SUBMIT_BO_WRITE);
+
+   for (uint32_t i = 0; i < region_count; ++i)
+      tu_resolve_image(cmdbuf, src_image, dst_image, regions + i);
 }