Mesa (master): zink: enable conditional rendering if available

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon May 11 09:21:42 UTC 2020


Module: Mesa
Branch: master
Commit: 5743fa6e709a01c5a6820320b2e87931af46e7cf
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=5743fa6e709a01c5a6820320b2e87931af46e7cf

Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Oct 15 00:15:50 2018 +0100

zink: enable conditional rendering if available

This doesn't seem to work perfect, but I'm not sure what is possible
in GL vs Vulkan here

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2867
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4835>

---

 src/gallium/drivers/zink/zink_blit.c   |  3 +-
 src/gallium/drivers/zink/zink_query.c  | 57 ++++++++++++++++++++++++++++++++++
 src/gallium/drivers/zink/zink_screen.c | 17 +++++++++-
 src/gallium/drivers/zink/zink_screen.h |  3 ++
 4 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_blit.c b/src/gallium/drivers/zink/zink_blit.c
index 2fa0c359cc0..d02d369514d 100644
--- a/src/gallium/drivers/zink/zink_blit.c
+++ b/src/gallium/drivers/zink/zink_blit.c
@@ -70,7 +70,8 @@ blit_native(struct zink_context *ctx, const struct pipe_blit_info *info)
    if (util_format_get_mask(info->dst.format) != info->mask ||
        util_format_get_mask(info->src.format) != info->mask ||
        info->scissor_enable ||
-       info->alpha_blend)
+       info->alpha_blend ||
+       info->render_condition_enable)
       return false;
 
    if (util_format_is_depth_or_stencil(info->dst.format) &&
diff --git a/src/gallium/drivers/zink/zink_query.c b/src/gallium/drivers/zink/zink_query.c
index e8ed72a1da5..344ed785be6 100644
--- a/src/gallium/drivers/zink/zink_query.c
+++ b/src/gallium/drivers/zink/zink_query.c
@@ -1,6 +1,7 @@
 #include "zink_query.h"
 
 #include "zink_context.h"
+#include "zink_resource.h"
 #include "zink_screen.h"
 
 #include "util/u_dump.h"
@@ -247,6 +248,61 @@ zink_set_active_query_state(struct pipe_context *pctx, bool enable)
       zink_resume_queries(ctx, batch);
 }
 
+static void
+zink_render_condition(struct pipe_context *pctx,
+                      struct pipe_query *pquery,
+                      bool condition,
+                      enum pipe_render_cond_flag mode)
+{
+   struct zink_context *ctx = zink_context(pctx);
+   struct zink_screen *screen = zink_screen(pctx->screen);
+   struct zink_query *query = (struct zink_query *)pquery;
+   struct zink_batch *batch = zink_curr_batch(ctx);
+   VkQueryResultFlagBits flags = 0;
+
+   if (query == NULL) {
+      screen->vk_CmdEndConditionalRenderingEXT(batch->cmdbuf);
+      return;
+   }
+
+   struct pipe_resource *pres;
+   struct zink_resource *res;
+   struct pipe_resource templ = {};
+   templ.width0 = 8;
+   templ.height0 = 1;
+   templ.depth0 = 1;
+   templ.format = PIPE_FORMAT_R8_UINT;
+   templ.target = PIPE_BUFFER;
+
+   /* need to create a vulkan buffer to copy the data into */
+   pres = pctx->screen->resource_create(pctx->screen, &templ);
+   if (!pres)
+      return;
+
+   res = (struct zink_resource *)pres;
+
+   if (mode == PIPE_RENDER_COND_WAIT || mode == PIPE_RENDER_COND_BY_REGION_WAIT)
+      flags |= VK_QUERY_RESULT_WAIT_BIT;
+
+   if (query->use_64bit)
+      flags |= VK_QUERY_RESULT_64_BIT;
+   vkCmdCopyQueryPoolResults(batch->cmdbuf, query->query_pool, 0, 1,
+                             res->buffer, 0, 0, flags);
+
+   VkConditionalRenderingFlagsEXT begin_flags = 0;
+   if (condition)
+      begin_flags = VK_CONDITIONAL_RENDERING_INVERTED_BIT_EXT;
+   VkConditionalRenderingBeginInfoEXT begin_info = {};
+   begin_info.sType = VK_STRUCTURE_TYPE_CONDITIONAL_RENDERING_BEGIN_INFO_EXT;
+   begin_info.buffer = res->buffer;
+   begin_info.flags = begin_flags;
+   screen->vk_CmdBeginConditionalRenderingEXT(batch->cmdbuf, &begin_info);
+
+   zink_batch_reference_resoure(batch, res);
+
+   pipe_resource_reference(&pres, NULL);
+}
+
 void
 zink_context_query_init(struct pipe_context *pctx)
 {
@@ -259,4 +315,5 @@ zink_context_query_init(struct pipe_context *pctx)
    pctx->end_query = zink_end_query;
    pctx->get_query_result = zink_get_query_result;
    pctx->set_active_query_state = zink_set_active_query_state;
+   pctx->render_condition = zink_render_condition;
 }
diff --git a/src/gallium/drivers/zink/zink_screen.c b/src/gallium/drivers/zink/zink_screen.c
index 53db925192d..92263a26eee 100644
--- a/src/gallium/drivers/zink/zink_screen.c
+++ b/src/gallium/drivers/zink/zink_screen.c
@@ -154,6 +154,9 @@ zink_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
       return 1;
 
+   case PIPE_CAP_CONDITIONAL_RENDER:
+     return screen->have_EXT_conditional_rendering;
+
    case PIPE_CAP_GLSL_FEATURE_LEVEL:
    case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
       return 120;
@@ -716,6 +719,11 @@ load_device_extensions(struct zink_screen *screen)
    if (screen->have_KHR_external_memory_fd)
       GET_PROC_ADDR(GetMemoryFdKHR);
 
+   if (screen->have_EXT_conditional_rendering) {
+      GET_PROC_ADDR(CmdBeginConditionalRenderingEXT);
+      GET_PROC_ADDR(CmdEndConditionalRenderingEXT);
+   }
+
 #undef GET_PROC_ADDR
 
    return true;
@@ -759,6 +767,9 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
             if (!strcmp(extensions[i].extensionName,
                         VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME))
                screen->have_KHR_external_memory_fd = true;
+            if (!strcmp(extensions[i].extensionName,
+                        VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME))
+               screen->have_EXT_conditional_rendering = true;
          }
          FREE(extensions);
       }
@@ -781,7 +792,7 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
    dci.queueCreateInfoCount = 1;
    dci.pQueueCreateInfos = &qci;
    dci.pEnabledFeatures = &screen->feats;
-   const char *extensions[3] = {
+   const char *extensions[4] = {
       VK_KHR_MAINTENANCE1_EXTENSION_NAME,
    };
    num_extensions = 1;
@@ -795,6 +806,10 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
       extensions[num_extensions++] = VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME;
       extensions[num_extensions++] = VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME;
    }
+
+   if (screen->have_EXT_conditional_rendering)
+      extensions[num_extensions++] = VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME;
+
    assert(num_extensions <= ARRAY_SIZE(extensions));
 
    dci.ppEnabledExtensionNames = extensions;
diff --git a/src/gallium/drivers/zink/zink_screen.h b/src/gallium/drivers/zink/zink_screen.h
index 09acb7f3e36..e50a5f32370 100644
--- a/src/gallium/drivers/zink/zink_screen.h
+++ b/src/gallium/drivers/zink/zink_screen.h
@@ -51,6 +51,7 @@ struct zink_screen {
 
    bool have_KHR_maintenance1;
    bool have_KHR_external_memory_fd;
+   bool have_EXT_conditional_rendering;
 
    bool have_X8_D24_UNORM_PACK32;
    bool have_D24_UNORM_S8_UINT;
@@ -59,6 +60,8 @@ struct zink_screen {
    VkDevice dev;
 
    PFN_vkGetMemoryFdKHR vk_GetMemoryFdKHR;
+   PFN_vkCmdBeginConditionalRenderingEXT vk_CmdBeginConditionalRenderingEXT;
+   PFN_vkCmdEndConditionalRenderingEXT vk_CmdEndConditionalRenderingEXT;
 };
 
 static inline struct zink_screen *



More information about the mesa-commit mailing list