From b82004d9609fa6323fcd68862c7164f73e37267b Mon Sep 17 00:00:00 2001 From: M Henning Date: Sat, 22 Apr 2023 00:47:28 -0400 Subject: [PATCH] gallium: Add pipe_shader_state_from_nir and use it in nouveau Reviewed-by: Alyssa Rosenzweig Reviewed-by: Karol Herbst Part-of: --- src/gallium/drivers/nouveau/nv50/nv50_surface.c | 5 ++--- src/gallium/drivers/nouveau/nvc0/nvc0_program.c | 5 ++--- src/gallium/drivers/nouveau/nvc0/nvc0_surface.c | 5 ++--- src/gallium/include/pipe/p_state.h | 10 ++++++++++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/gallium/drivers/nouveau/nv50/nv50_surface.c b/src/gallium/drivers/nouveau/nv50/nv50_surface.c index 347559fec59..787fad52da3 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_surface.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_surface.c @@ -1067,9 +1067,8 @@ nv50_blitter_make_fp(struct pipe_context *pipe, /* return shader */ NIR_PASS_V(b.shader, nir_lower_samplers); - struct pipe_shader_state state = {}; - state.type = PIPE_SHADER_IR_NIR; - state.ir.nir = b.shader; + struct pipe_shader_state state; + pipe_shader_state_from_nir(&state, b.shader); return pipe->create_fs_state(pipe, &state); } diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_program.c b/src/gallium/drivers/nouveau/nvc0/nvc0_program.c index 92b070e179c..d3b6b9fdcb3 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_program.c +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_program.c @@ -1025,8 +1025,7 @@ nvc0_program_init_tcp_empty(struct nvc0_context *nvc0) nir_validate_shader(b.shader, "in nvc0_program_init_tcp_empty"); - struct pipe_shader_state state = {0}; - state.type = PIPE_SHADER_IR_NIR; - state.ir.nir = b.shader; + struct pipe_shader_state state; + pipe_shader_state_from_nir(&state, b.shader); nvc0->tcp_empty = nvc0->base.pipe.create_tcs_state(&nvc0->base.pipe, &state); } diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c b/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c index 93437d8b47d..9e415f12991 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c @@ -888,9 +888,8 @@ nvc0_blitter_make_vp(struct pipe_context *pipe) NIR_PASS_V(b.shader, nir_lower_var_copies); - struct pipe_shader_state state = {}; - state.type = PIPE_SHADER_IR_NIR; - state.ir.nir = b.shader; + struct pipe_shader_state state; + pipe_shader_state_from_nir(&state, b.shader); return pipe->create_vs_state(pipe, &state); } diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index b84a333f2a0..04a60f8d60f 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -318,6 +318,16 @@ pipe_shader_state_from_tgsi(struct pipe_shader_state *state, memset(&state->stream_output, 0, sizeof(state->stream_output)); } +static inline void +pipe_shader_state_from_nir(struct pipe_shader_state *state, + void *nir) +{ + state->type = PIPE_SHADER_IR_NIR; + state->ir.nir = nir; + state->tokens = NULL; + memset(&state->stream_output, 0, sizeof(state->stream_output)); +} + struct pipe_stencil_state {