turnip: compute render_components/srgb_cntl at renderpass creation time
authorJonathan Marek <jonathan@marek.ca>
Wed, 15 Apr 2020 18:38:04 +0000 (14:38 -0400)
committerMarge Bot <eric+marge@anholt.net>
Thu, 16 Apr 2020 14:04:18 +0000 (14:04 +0000)
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4581>

src/freedreno/vulkan/tu_cmd_buffer.c
src/freedreno/vulkan/tu_pass.c
src/freedreno/vulkan/tu_private.h

index 941f4ba6be76aa957117a7467b6bcfa15aa4b475..179abefbdd25dfb5458698dea65270c6c0f756fd 100644 (file)
@@ -421,8 +421,6 @@ tu6_emit_mrt(struct tu_cmd_buffer *cmd,
              struct tu_cs *cs)
 {
    const struct tu_framebuffer *fb = cmd->state.framebuffer;
-   unsigned char mrt_comp[MAX_RTS] = { 0 };
-   unsigned srgb_cntl = 0;
 
    for (uint32_t i = 0; i < subpass->color_count; ++i) {
       uint32_t a = subpass->color_attachments[i].attachment;
@@ -431,10 +429,6 @@ tu6_emit_mrt(struct tu_cmd_buffer *cmd,
 
       const struct tu_image_view *iview = fb->attachments[a].attachment;
 
-      mrt_comp[i] = 0xf;
-
-      if (vk_format_is_srgb(iview->vk_format))
-         srgb_cntl |= (1 << i);
 
       struct tu_native_format format =
          tu6_format_image(iview->image, iview->vk_format, iview->base_mip);
@@ -462,32 +456,14 @@ tu6_emit_mrt(struct tu_cmd_buffer *cmd,
    }
 
    tu_cs_emit_regs(cs,
-                   A6XX_RB_SRGB_CNTL(.dword = srgb_cntl));
-
+                   A6XX_RB_SRGB_CNTL(.dword = subpass->srgb_cntl));
    tu_cs_emit_regs(cs,
-                   A6XX_SP_SRGB_CNTL(.dword = srgb_cntl));
+                   A6XX_SP_SRGB_CNTL(.dword = subpass->srgb_cntl));
 
    tu_cs_emit_regs(cs,
-                   A6XX_RB_RENDER_COMPONENTS(
-                      .rt0 = mrt_comp[0],
-                      .rt1 = mrt_comp[1],
-                      .rt2 = mrt_comp[2],
-                      .rt3 = mrt_comp[3],
-                      .rt4 = mrt_comp[4],
-                      .rt5 = mrt_comp[5],
-                      .rt6 = mrt_comp[6],
-                      .rt7 = mrt_comp[7]));
-
+                   A6XX_RB_RENDER_COMPONENTS(.dword = subpass->render_components));
    tu_cs_emit_regs(cs,
-                   A6XX_SP_FS_RENDER_COMPONENTS(
-                      .rt0 = mrt_comp[0],
-                      .rt1 = mrt_comp[1],
-                      .rt2 = mrt_comp[2],
-                      .rt3 = mrt_comp[3],
-                      .rt4 = mrt_comp[4],
-                      .rt5 = mrt_comp[5],
-                      .rt6 = mrt_comp[6],
-                      .rt7 = mrt_comp[7]));
+                   A6XX_SP_FS_RENDER_COMPONENTS(.dword = subpass->render_components));
 
    tu_cs_emit_regs(cs, A6XX_GRAS_MAX_LAYER_INDEX(fb->layers - 1));
 }
index 4f075e173e2d64b2e2f8cd74b9ac19d9ee8466c4..b14eab022fa6704e33d4a69a72103c0006d63ff6 100644 (file)
@@ -39,8 +39,8 @@ static void update_samples(struct tu_subpass *subpass,
 #define GMEM_ALIGN 0x4000
 
 static void
-compute_gmem_offsets(struct tu_render_pass *pass,
-                     const struct tu_physical_device *phys_dev)
+create_render_pass_common(struct tu_render_pass *pass,
+                          const struct tu_physical_device *phys_dev)
 {
    /* calculate total bytes per pixel */
    uint32_t cpp_total = 0;
@@ -84,6 +84,24 @@ compute_gmem_offsets(struct tu_render_pass *pass,
    }
 
    pass->gmem_pixels = pixels;
+
+   for (uint32_t i = 0; i < pass->subpass_count; i++) {
+      struct tu_subpass *subpass = &pass->subpasses[i];
+
+      subpass->srgb_cntl = 0;
+      subpass->render_components = 0;
+
+      for (uint32_t i = 0; i < subpass->color_count; ++i) {
+         uint32_t a = subpass->color_attachments[i].attachment;
+         if (a == VK_ATTACHMENT_UNUSED)
+            continue;
+
+         subpass->render_components |= 0xf << (i * 4);
+
+         if (vk_format_is_srgb(pass->attachments[a].format))
+            subpass->srgb_cntl |= 1 << i;
+      }
+   }
 }
 
 VkResult
@@ -209,7 +227,7 @@ tu_CreateRenderPass(VkDevice _device,
 
    *pRenderPass = tu_render_pass_to_handle(pass);
 
-   compute_gmem_offsets(pass, device->physical_device);
+   create_render_pass_common(pass, device->physical_device);
 
    return VK_SUCCESS;
 }
@@ -338,7 +356,7 @@ tu_CreateRenderPass2(VkDevice _device,
 
    *pRenderPass = tu_render_pass_to_handle(pass);
 
-   compute_gmem_offsets(pass, device->physical_device);
+   create_render_pass_common(pass, device->physical_device);
 
    return VK_SUCCESS;
 }
index 656f63f8d84eece7ddefbb5a42e04344f70e54f0..1c081a2ddda55de65e3acb674fa2b2ec87498f07 100644 (file)
@@ -1648,6 +1648,10 @@ struct tu_subpass
    struct tu_subpass_attachment depth_stencil_attachment;
 
    VkSampleCountFlagBits samples;
+
+   /* pre-filled register values */
+   uint32_t render_components;
+   uint32_t srgb_cntl;
 };
 
 struct tu_render_pass_attachment