Module: Mesa
Branch: main
Commit: 645ba24e7b8bf6bf29fa1955d84925ec72ffc7e5
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=645ba24e7b8bf6bf29fa1955d84925ec72ffc7e5

Author: Alyssa Rosenzweig <[email protected]>
Date:   Sat Nov 18 22:00:54 2023 -0400

gallium: add pipe_shader_from_nir helper

useful for nir-based gallium meta, we have a tgsi equivalent already.

Signed-off-by: Alyssa Rosenzweig <[email protected]>
Reviewed-by: Eric Engestrom <[email protected]>
Reviewed-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26272>

---

 src/gallium/auxiliary/nir/pipe_nir.h | 50 ++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/src/gallium/auxiliary/nir/pipe_nir.h 
b/src/gallium/auxiliary/nir/pipe_nir.h
new file mode 100644
index 00000000000..b01d4984a90
--- /dev/null
+++ b/src/gallium/auxiliary/nir/pipe_nir.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2023 Valve Corporation
+ * SPDX-License-Identifier: MIT
+ */
+#ifndef PIPE_NIR_H
+#define PIPE_NIR_H
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_state.h"
+#include "nir.h"
+#include "shader_enums.h"
+
+static inline void *
+pipe_shader_from_nir(struct pipe_context *pipe, nir_shader *nir)
+{
+   struct pipe_shader_state state = {
+      .type = PIPE_SHADER_IR_NIR,
+      .ir.nir = nir,
+   };
+
+   switch (nir->info.stage) {
+   case MESA_SHADER_VERTEX:
+      return pipe->create_vs_state(pipe, &state);
+   case MESA_SHADER_TESS_CTRL:
+      return pipe->create_tcs_state(pipe, &state);
+   case MESA_SHADER_TESS_EVAL:
+      return pipe->create_tes_state(pipe, &state);
+   case MESA_SHADER_GEOMETRY:
+      return pipe->create_gs_state(pipe, &state);
+   case MESA_SHADER_FRAGMENT:
+      return pipe->create_fs_state(pipe, &state);
+
+   case MESA_SHADER_COMPUTE:
+   case MESA_SHADER_KERNEL: {
+      struct pipe_compute_state compute = {
+         .ir_type = PIPE_SHADER_IR_NIR,
+         .prog = nir,
+         .static_shared_mem = nir->info.shared_size,
+      };
+
+      return pipe->create_compute_state(pipe, &compute);
+   }
+
+   default:
+      unreachable("unexpected shader stage");
+   }
+}
+
+#endif

Reply via email to