From 645ba24e7b8bf6bf29fa1955d84925ec72ffc7e5 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sat, 18 Nov 2023 22:00:54 -0400 Subject: [PATCH] gallium: add pipe_shader_from_nir helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit useful for nir-based gallium meta, we have a tgsi equivalent already. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Eric Engestrom Reviewed-by: Marek Olšák Part-of: --- src/gallium/auxiliary/nir/pipe_nir.h | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/gallium/auxiliary/nir/pipe_nir.h 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