lavapipe: move noop fs creation to device
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 1 Feb 2023 14:58:33 +0000 (09:58 -0500)
committerMarge Bot <emma+marge@anholt.net>
Thu, 2 Feb 2023 04:49:42 +0000 (04:49 +0000)
this avoids creating a separate noop fs for every pipeline

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21051>

src/gallium/frontends/lavapipe/lvp_device.c
src/gallium/frontends/lavapipe/lvp_pipeline.c
src/gallium/frontends/lavapipe/lvp_private.h

index f33a902..7826c69 100644 (file)
@@ -42,6 +42,8 @@
 #include "util/u_atomic.h"
 #include "util/timespec.h"
 #include "util/ptralloc.h"
+#include "nir.h"
+#include "nir_builder.h"
 
 #if defined(VK_USE_PLATFORM_WAYLAND_KHR) || \
     defined(VK_USE_PLATFORM_WIN32_KHR) || \
@@ -1632,6 +1634,12 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateDevice(
       return result;
    }
 
+   nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL, "dummy_frag");
+   struct pipe_shader_state shstate = {0};
+   shstate.type = PIPE_SHADER_IR_NIR;
+   shstate.ir.nir = b.shader;
+   device->noop_fs = device->queue.ctx->create_fs_state(device->queue.ctx, &shstate);
+
    *pDevice = lvp_device_to_handle(device);
 
    return VK_SUCCESS;
@@ -1644,6 +1652,8 @@ VKAPI_ATTR void VKAPI_CALL lvp_DestroyDevice(
 {
    LVP_FROM_HANDLE(lvp_device, device, _device);
 
+   device->queue.ctx->delete_fs_state(device->queue.ctx, device->noop_fs);
+
    if (device->queue.last_fence)
       device->pscreen->fence_reference(device->pscreen, &device->queue.last_fence, NULL);
    lvp_queue_finish(&device->queue);
index 69b83fc..f63d220 100644 (file)
@@ -44,7 +44,7 @@ lvp_pipeline_destroy(struct lvp_device *device, struct lvp_pipeline *pipeline)
 {
    if (pipeline->shader_cso[PIPE_SHADER_VERTEX])
       device->queue.ctx->delete_vs_state(device->queue.ctx, pipeline->shader_cso[PIPE_SHADER_VERTEX]);
-   if (pipeline->shader_cso[PIPE_SHADER_FRAGMENT])
+   if (pipeline->shader_cso[PIPE_SHADER_FRAGMENT] && !pipeline->noop_fs)
       device->queue.ctx->delete_fs_state(device->queue.ctx, pipeline->shader_cso[PIPE_SHADER_FRAGMENT]);
    if (pipeline->shader_cso[PIPE_SHADER_GEOMETRY])
       device->queue.ctx->delete_gs_state(device->queue.ctx, pipeline->shader_cso[PIPE_SHADER_GEOMETRY]);
@@ -888,15 +888,8 @@ lvp_graphics_pipeline_init(struct lvp_pipeline *pipeline,
       }
 
       if (has_fragment_shader == false) {
-         /* create a dummy fragment shader for this pipeline. */
-         nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL,
-                                                        "dummy_frag");
-
-         pipeline->pipeline_nir[MESA_SHADER_FRAGMENT] = b.shader;
-         struct pipe_shader_state shstate = {0};
-         shstate.type = PIPE_SHADER_IR_NIR;
-         shstate.ir.nir = nir_shader_clone(NULL, pipeline->pipeline_nir[MESA_SHADER_FRAGMENT]);
-         pipeline->shader_cso[PIPE_SHADER_FRAGMENT] = device->queue.ctx->create_fs_state(device->queue.ctx, &shstate);
+         pipeline->noop_fs = true;
+         pipeline->shader_cso[PIPE_SHADER_FRAGMENT] = device->noop_fs;
       }
    }
    return VK_SUCCESS;
index 96e32f1..6eca1c8 100644 (file)
@@ -179,6 +179,7 @@ struct lvp_device {
    struct lvp_instance *                       instance;
    struct lvp_physical_device *physical_device;
    struct pipe_screen *pscreen;
+   void *noop_fs;
    bool poison_mem;
 };
 
@@ -433,6 +434,7 @@ struct lvp_pipeline {
    bool line_rectangular;
    bool gs_output_lines;
    bool library;
+   bool noop_fs;
 };
 
 struct lvp_event {