From 453f49ce6d14ce101d047dc6a0847dd3cbb04a33 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 1 Feb 2023 09:58:33 -0500 Subject: [PATCH] lavapipe: move noop fs creation to device this avoids creating a separate noop fs for every pipeline Reviewed-by: Dave Airlie Part-of: --- src/gallium/frontends/lavapipe/lvp_device.c | 10 ++++++++++ src/gallium/frontends/lavapipe/lvp_pipeline.c | 13 +++---------- src/gallium/frontends/lavapipe/lvp_private.h | 2 ++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c index f33a902..7826c69 100644 --- a/src/gallium/frontends/lavapipe/lvp_device.c +++ b/src/gallium/frontends/lavapipe/lvp_device.c @@ -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); diff --git a/src/gallium/frontends/lavapipe/lvp_pipeline.c b/src/gallium/frontends/lavapipe/lvp_pipeline.c index 69b83fc..f63d220 100644 --- a/src/gallium/frontends/lavapipe/lvp_pipeline.c +++ b/src/gallium/frontends/lavapipe/lvp_pipeline.c @@ -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; diff --git a/src/gallium/frontends/lavapipe/lvp_private.h b/src/gallium/frontends/lavapipe/lvp_private.h index 96e32f1..6eca1c8 100644 --- a/src/gallium/frontends/lavapipe/lvp_private.h +++ b/src/gallium/frontends/lavapipe/lvp_private.h @@ -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 { -- 2.7.4