diff options
author | Dave Airlie <[email protected]> | 2019-09-05 15:47:39 +1000 |
---|---|---|
committer | Dave Airlie <[email protected]> | 2019-11-28 14:49:05 +1000 |
commit | 3eb27cfccddaca7bb46bc42e0c1832b3c1085542 (patch) | |
tree | d206966f7651877a1187c5d40e042697ed81bf28 /src/gallium/auxiliary/draw | |
parent | bf12bc2dd7a28844103bb30a07be0440e60c5864 (diff) |
gallium: add nir lowering passes for the draw pipe stages. (v2)
This transforms the NIR shaders like the TGSI transforms worked.
v2: fix some nir info requirements, use 32-bit bools
Acked-by: Roland Scheidegger <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/draw')
-rw-r--r-- | src/gallium/auxiliary/draw/draw_pipe_aaline.c | 58 | ||||
-rw-r--r-- | src/gallium/auxiliary/draw/draw_pipe_aapoint.c | 65 | ||||
-rw-r--r-- | src/gallium/auxiliary/draw/draw_pipe_pstipple.c | 33 |
3 files changed, 130 insertions, 26 deletions
diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c index e84fb5d6157..872b29e9c8d 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c +++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c @@ -48,6 +48,8 @@ #include "draw_private.h" #include "draw_pipe.h" +#include "nir.h" +#include "nir/nir_draw_helpers.h" /** Approx number of new tokens for instructions in aa_transform_inst() */ #define NUM_NEW_TOKENS 53 @@ -318,6 +320,30 @@ fail: return FALSE; } +static boolean +generate_aaline_fs_nir(struct aaline_stage *aaline) +{ +#ifdef LLVM_AVAILABLE + struct pipe_context *pipe = aaline->stage.draw->pipe; + const struct pipe_shader_state *orig_fs = &aaline->fs->state; + struct pipe_shader_state aaline_fs; + + aaline_fs = *orig_fs; /* copy to init */ + aaline_fs.ir.nir = nir_shader_clone(NULL, orig_fs->ir.nir); + if (!aaline_fs.ir.nir) + return FALSE; + + nir_lower_aaline_fs(aaline_fs.ir.nir, &aaline->fs->generic_attrib); + aaline->fs->aaline_fs = aaline->driver_create_fs_state(pipe, &aaline_fs); + if (aaline->fs->aaline_fs == NULL) + goto fail; + + return TRUE; + +fail: +#endif + return FALSE; +} /** * When we're about to draw our first AA line in a batch, this function is @@ -329,8 +355,14 @@ bind_aaline_fragment_shader(struct aaline_stage *aaline) struct draw_context *draw = aaline->stage.draw; struct pipe_context *pipe = draw->pipe; - if (!aaline->fs->aaline_fs && !generate_aaline_fs(aaline)) - return FALSE; + if (!aaline->fs->aaline_fs) { + if (aaline->fs->state.type == PIPE_SHADER_IR_NIR) { + if (!generate_aaline_fs_nir(aaline)) + return FALSE; + } else + if (!generate_aaline_fs(aaline)) + return FALSE; + } draw->suspend_flushing = TRUE; aaline->driver_bind_fs_state(pipe, aaline->fs->aaline_fs); @@ -618,7 +650,13 @@ aaline_create_fs_state(struct pipe_context *pipe, if (!aafs) return NULL; - aafs->state.tokens = tgsi_dup_tokens(fs->tokens); + aafs->state.type = fs->type; + if (fs->type == PIPE_SHADER_IR_TGSI) + aafs->state.tokens = tgsi_dup_tokens(fs->tokens); +#ifdef LLVM_AVAILABLE + else + aafs->state.ir.nir = nir_shader_clone(NULL, fs->ir.nir); +#endif /* pass-through */ aafs->driver_fs = aaline->driver_create_fs_state(pipe, fs); @@ -662,7 +700,10 @@ aaline_delete_fs_state(struct pipe_context *pipe, void *fs) aaline->driver_delete_fs_state(pipe, aafs->aaline_fs); } - FREE((void*)aafs->state.tokens); + if (aafs->state.type == PIPE_SHADER_IR_TGSI) + FREE((void*)aafs->state.tokens); + else + ralloc_free(aafs->state.ir.nir); FREE(aafs); } @@ -681,9 +722,12 @@ draw_aaline_prepare_outputs(struct draw_context *draw, return; /* allocate the extra post-transformed vertex attribute */ - aaline->coord_slot = draw_alloc_extra_vertex_attrib(draw, - TGSI_SEMANTIC_GENERIC, - aaline->fs->generic_attrib); + if (aaline->fs->aaline_fs) + aaline->coord_slot = draw_alloc_extra_vertex_attrib(draw, + TGSI_SEMANTIC_GENERIC, + aaline->fs->generic_attrib); + else + aaline->coord_slot = -1; } /** diff --git a/src/gallium/auxiliary/draw/draw_pipe_aapoint.c b/src/gallium/auxiliary/draw/draw_pipe_aapoint.c index dc22039b127..797e0d2d9c2 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_aapoint.c +++ b/src/gallium/auxiliary/draw/draw_pipe_aapoint.c @@ -52,6 +52,8 @@ #include "draw_vs.h" #include "draw_pipe.h" +#include "nir.h" +#include "nir/nir_draw_helpers.h" /** Approx number of new tokens for instructions in aa_transform_inst() */ #define NUM_NEW_TOKENS 200 @@ -364,6 +366,8 @@ generate_aapoint_fs(struct aapoint_stage *aapoint) struct pipe_context *pipe = aapoint->stage.draw->pipe; aapoint_fs = *orig_fs; /* copy to init */ + + assert(aapoint_fs.type == PIPE_SHADER_IR_TGSI); aapoint_fs.tokens = tgsi_alloc_tokens(newLen); if (aapoint_fs.tokens == NULL) return FALSE; @@ -404,6 +408,30 @@ fail: return FALSE; } +static boolean +generate_aapoint_fs_nir(struct aapoint_stage *aapoint) +{ +#ifdef LLVM_AVAILABLE + struct pipe_context *pipe = aapoint->stage.draw->pipe; + const struct pipe_shader_state *orig_fs = &aapoint->fs->state; + struct pipe_shader_state aapoint_fs; + + aapoint_fs = *orig_fs; /* copy to init */ + aapoint_fs.ir.nir = nir_shader_clone(NULL, orig_fs->ir.nir); + if (!aapoint_fs.ir.nir) + return FALSE; + + nir_lower_aapoint_fs(aapoint_fs.ir.nir, &aapoint->fs->generic_attrib); + aapoint->fs->aapoint_fs = aapoint->driver_create_fs_state(pipe, &aapoint_fs); + if (aapoint->fs->aapoint_fs == NULL) + goto fail; + + return TRUE; + +fail: +#endif + return FALSE; +} /** * When we're about to draw our first AA point in a batch, this function is @@ -415,9 +443,13 @@ bind_aapoint_fragment_shader(struct aapoint_stage *aapoint) struct draw_context *draw = aapoint->stage.draw; struct pipe_context *pipe = draw->pipe; - if (!aapoint->fs->aapoint_fs && - !generate_aapoint_fs(aapoint)) - return FALSE; + if (!aapoint->fs->aapoint_fs) { + if (aapoint->fs->state.type == PIPE_SHADER_IR_NIR) { + if (!generate_aapoint_fs_nir(aapoint)) + return FALSE; + } else if (!generate_aapoint_fs(aapoint)) + return FALSE; + } draw->suspend_flushing = TRUE; aapoint->driver_bind_fs_state(pipe, aapoint->fs->aapoint_fs); @@ -637,11 +669,14 @@ draw_aapoint_prepare_outputs(struct draw_context *draw, if (!rast->point_smooth) return; - /* allocate the extra post-transformed vertex attribute */ - aapoint->tex_slot = draw_alloc_extra_vertex_attrib(draw, - TGSI_SEMANTIC_GENERIC, - aapoint->fs->generic_attrib); - assert(aapoint->tex_slot > 0); /* output[0] is vertex pos */ + if (aapoint->fs->aapoint_fs) { + /* allocate the extra post-transformed vertex attribute */ + aapoint->tex_slot = draw_alloc_extra_vertex_attrib(draw, + TGSI_SEMANTIC_GENERIC, + aapoint->fs->generic_attrib); + assert(aapoint->tex_slot > 0); /* output[0] is vertex pos */ + } else + aapoint->tex_slot = -1; /* find psize slot in post-transform vertex */ aapoint->psize_slot = -1; @@ -710,8 +745,13 @@ aapoint_create_fs_state(struct pipe_context *pipe, if (!aafs) return NULL; - aafs->state.tokens = tgsi_dup_tokens(fs->tokens); - + aafs->state.type = fs->type; + if (fs->type == PIPE_SHADER_IR_TGSI) + aafs->state.tokens = tgsi_dup_tokens(fs->tokens); +#ifdef LLVM_AVAILABLE + else + aafs->state.ir.nir = nir_shader_clone(NULL, fs->ir.nir); +#endif /* pass-through */ aafs->driver_fs = aapoint->driver_create_fs_state(pipe, fs); @@ -744,7 +784,10 @@ aapoint_delete_fs_state(struct pipe_context *pipe, void *fs) if (aafs->aapoint_fs) aapoint->driver_delete_fs_state(pipe, aafs->aapoint_fs); - FREE((void*)aafs->state.tokens); + if (aafs->state.type == PIPE_SHADER_IR_TGSI) + FREE((void*)aafs->state.tokens); + else + ralloc_free(aafs->state.ir.nir); FREE(aafs); } diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index bd6637a6730..bd74cb42ada 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -51,6 +51,8 @@ #include "draw_context.h" #include "draw_pipe.h" +#include "nir.h" +#include "nir/nir_draw_helpers.h" /** Approx number of new tokens for instructions in pstip_transform_inst() */ #define NUM_NEW_TOKENS 53 @@ -133,12 +135,20 @@ generate_pstip_fs(struct pstip_stage *pstip) TGSI_FILE_SYSTEM_VALUE : TGSI_FILE_INPUT; pstip_fs = *orig_fs; /* copy to init */ - pstip_fs.tokens = util_pstipple_create_fragment_shader(orig_fs->tokens, - &pstip->fs->sampler_unit, - 0, - wincoord_file); - if (pstip_fs.tokens == NULL) - return FALSE; + if (orig_fs->type == PIPE_SHADER_IR_TGSI) { + pstip_fs.tokens = util_pstipple_create_fragment_shader(orig_fs->tokens, + &pstip->fs->sampler_unit, + 0, + wincoord_file); + if (pstip_fs.tokens == NULL) + return FALSE; + } else { +#ifdef LLVM_AVAILABLE + pstip_fs.ir.nir = nir_shader_clone(NULL, orig_fs->ir.nir); + nir_lower_pstipple_fs(pstip_fs.ir.nir, + &pstip->fs->sampler_unit, 0, wincoord_file == TGSI_FILE_SYSTEM_VALUE); +#endif + } assert(pstip->fs->sampler_unit < PIPE_MAX_SAMPLERS); @@ -334,7 +344,11 @@ pstip_create_fs_state(struct pipe_context *pipe, struct pstip_fragment_shader *pstipfs = CALLOC_STRUCT(pstip_fragment_shader); if (pstipfs) { - pstipfs->state.tokens = tgsi_dup_tokens(fs->tokens); + pstipfs->state.type = fs->type; + if (fs->type == PIPE_SHADER_IR_TGSI) + pstipfs->state.tokens = tgsi_dup_tokens(fs->tokens); + else + pstipfs->state.ir.nir = nir_shader_clone(NULL, fs->ir.nir); /* pass-through */ pstipfs->driver_fs = pstip->driver_create_fs_state(pstip->pipe, fs); @@ -368,7 +382,10 @@ pstip_delete_fs_state(struct pipe_context *pipe, void *fs) if (pstipfs->pstip_fs) pstip->driver_delete_fs_state(pstip->pipe, pstipfs->pstip_fs); - FREE((void*)pstipfs->state.tokens); + if (pstipfs->state.type == PIPE_SHADER_IR_TGSI) + FREE((void*)pstipfs->state.tokens); + else + ralloc_free(pstipfs->state.ir.nir); FREE(pstipfs); } |