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

Author: M Henning <[email protected]>
Date:   Sun Jul 16 20:56:59 2023 -0400

nv50: Keep nir directly in nv50_program

Reviewed-by: Karol Herbst <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24175>

---

 src/gallium/drivers/nouveau/nv50/nv50_program.c | 23 ++++++-----------------
 src/gallium/drivers/nouveau/nv50/nv50_program.h |  4 +++-
 src/gallium/drivers/nouveau/nv50/nv50_state.c   | 19 ++++++-------------
 src/gallium/drivers/nouveau/nv50/nv50_surface.c |  2 +-
 src/gallium/drivers/nouveau/nv50/nv50_vbo.c     |  4 ++--
 5 files changed, 18 insertions(+), 34 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_program.c 
b/src/gallium/drivers/nouveau/nv50/nv50_program.c
index 4a3e744dbb4..bbfed6df9a9 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_program.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_program.c
@@ -340,19 +340,8 @@ nv50_program_translate(struct nv50_program *prog, uint16_t 
chipset,
    info->type = prog->type;
    info->target = chipset;
 
-   info->bin.sourceRep = prog->pipe.type;
-   switch (prog->pipe.type) {
-   case PIPE_SHADER_IR_TGSI:
-      info->bin.source = (void *)prog->pipe.tokens;
-      break;
-   case PIPE_SHADER_IR_NIR:
-      info->bin.source = (void *)nir_shader_clone(NULL, prog->pipe.ir.nir);
-      break;
-   default:
-      assert(!"unsupported IR!");
-      free(info);
-      return false;
-   }
+   info->bin.sourceRep = PIPE_SHADER_IR_NIR;
+   info->bin.source = (void *)nir_shader_clone(NULL, prog->nir);
 
    info->bin.smemSize = prog->cp.smem_size;
    info->io.auxCBSlot = 15;
@@ -451,9 +440,9 @@ nv50_program_translate(struct nv50_program *prog, uint16_t 
chipset,
       }
    }
 
-   if (prog->pipe.stream_output.num_outputs)
+   if (prog->stream_output.num_outputs)
       prog->so = nv50_program_create_strmout_state(&info_out,
-                                                   &prog->pipe.stream_output);
+                                                   &prog->stream_output);
 
    util_debug_message(debug, SHADER_INFO,
                       "type: %d, local: %d, shared: %d, gpr: %d, inst: %d, 
loops: %d, bytes: %d",
@@ -543,7 +532,7 @@ nv50_program_upload_code(struct nv50_context *nv50, struct 
nv50_program *prog)
 void
 nv50_program_destroy(struct nv50_context *nv50, struct nv50_program *p)
 {
-   const struct pipe_shader_state pipe = p->pipe;
+   struct nir_shader *nir = p->nir;
    const uint8_t type = p->type;
 
    if (p->mem) {
@@ -560,6 +549,6 @@ nv50_program_destroy(struct nv50_context *nv50, struct 
nv50_program *p)
 
    memset(p, 0, sizeof(*p));
 
-   p->pipe = pipe;
+   p->nir = nir;
    p->type = type;
 }
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_program.h 
b/src/gallium/drivers/nouveau/nv50/nv50_program.h
index ef632b7df7b..d4900a2390f 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_program.h
+++ b/src/gallium/drivers/nouveau/nv50/nv50_program.h
@@ -24,6 +24,7 @@
 #define __NV50_PROG_H__
 
 struct nv50_context;
+struct nir_shader;
 
 #include "pipe/p_state.h"
 
@@ -55,7 +56,8 @@ struct nv50_gmem_state {
 };
 
 struct nv50_program {
-   struct pipe_shader_state pipe;
+   struct nir_shader *nir;
+   struct pipe_stream_output_info stream_output;
 
    uint8_t type;
    bool translated;
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_state.c 
b/src/gallium/drivers/nouveau/nv50/nv50_state.c
index 37912401449..7cde8e4b283 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_state.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_state.c
@@ -747,15 +747,13 @@ nv50_sp_state_create(struct pipe_context *pipe,
       return NULL;
 
    prog->type = type;
-   prog->pipe.type = cso->type;
 
    switch (cso->type) {
    case PIPE_SHADER_IR_TGSI:
-      prog->pipe.type = PIPE_SHADER_IR_NIR;
-      prog->pipe.ir.nir = tgsi_to_nir(cso->tokens, pipe->screen, false);
+      prog->nir = tgsi_to_nir(cso->tokens, pipe->screen, false);
       break;
    case PIPE_SHADER_IR_NIR:
-      prog->pipe.ir.nir = cso->ir.nir;
+      prog->nir = cso->ir.nir;
       break;
    default:
       assert(!"unsupported IR!");
@@ -764,7 +762,7 @@ nv50_sp_state_create(struct pipe_context *pipe,
    }
 
    if (cso->stream_output.num_outputs)
-      prog->pipe.stream_output = cso->stream_output;
+      prog->stream_output = cso->stream_output;
 
    prog->translated = nv50_program_translate(
          prog, nv50_context(pipe)->screen->base.device->chipset,
@@ -783,10 +781,7 @@ nv50_sp_state_delete(struct pipe_context *pipe, void 
*hwcso)
    nv50_program_destroy(nv50, prog);
    simple_mtx_unlock(&nv50->screen->state_lock);
 
-   if (prog->pipe.type == PIPE_SHADER_IR_TGSI)
-      FREE((void *)prog->pipe.tokens);
-   else if (prog->pipe.type == PIPE_SHADER_IR_NIR)
-      ralloc_free(prog->pipe.ir.nir);
+   ralloc_free(prog->nir);
    FREE(prog);
 }
 
@@ -848,17 +843,15 @@ nv50_cp_state_create(struct pipe_context *pipe,
    if (!prog)
       return NULL;
    prog->type = PIPE_SHADER_COMPUTE;
-   prog->pipe.type = cso->ir_type;
 
    switch(cso->ir_type) {
    case PIPE_SHADER_IR_TGSI: {
       const struct tgsi_token *tokens = cso->prog;
-      prog->pipe.type = PIPE_SHADER_IR_NIR;
-      prog->pipe.ir.nir = tgsi_to_nir(tokens, pipe->screen, false);
+      prog->nir = tgsi_to_nir(tokens, pipe->screen, false);
       break;
    }
    case PIPE_SHADER_IR_NIR:
-      prog->pipe.ir.nir = (nir_shader *)cso->prog;
+      prog->nir = (nir_shader *)cso->prog;
       break;
    default:
       assert(!"unsupported IR!");
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_surface.c 
b/src/gallium/drivers/nouveau/nv50/nv50_surface.c
index c990155e138..b8b07ccaca8 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_surface.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_surface.c
@@ -1798,7 +1798,7 @@ nv50_blitter_destroy(struct nv50_screen *screen)
          struct nv50_program *prog = blitter->fp[i][m];
          if (prog) {
             nv50_program_destroy(NULL, prog);
-            ralloc_free((void *)prog->pipe.ir.nir);
+            ralloc_free((void *)prog->nir);
             FREE(prog);
          }
       }
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_vbo.c 
b/src/gallium/drivers/nouveau/nv50/nv50_vbo.c
index 682ed61fa60..15645f94705 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_vbo.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_vbo.c
@@ -855,11 +855,11 @@ nv50_draw_vbo(struct pipe_context *pipe, const struct 
pipe_draw_info *info,
     * means counting vertices in a vertex shader when it has so outputs.
     */
    if (nv50->screen->base.class_3d < NVA0_3D_CLASS &&
-       nv50->vertprog->pipe.stream_output.num_outputs) {
+       nv50->vertprog->stream_output.num_outputs) {
       for (int i = 0; i < nv50->num_so_targets; i++) {
          nv50->so_used[i] += info->instance_count *
             u_stream_outputs_for_vertices(info->mode, draws[0].count) *
-            nv50->vertprog->pipe.stream_output.stride[i] * 4;
+            nv50->vertprog->stream_output.stride[i] * 4;
       }
    }
 

Reply via email to