From: Rob Clark <robdclark@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: Jason Ekstrand <jason@jlekstrand.net>
Subject: [RFCv0 6/8] freedreno/ir3: add support for NIR as preferred IR
Date: Mon, 19 Oct 2015 15:47:59 -0400 [thread overview]
Message-ID: <1445284081-29532-7-git-send-email-robdclark@gmail.com> (raw)
In-Reply-To: <1445284081-29532-1-git-send-email-robdclark@gmail.com>
For now under debug flag, since only suitable for debugging/testing.
---
src/gallium/drivers/freedreno/freedreno_screen.c | 5 +++-
src/gallium/drivers/freedreno/freedreno_util.h | 1 +
.../drivers/freedreno/ir3/ir3_compiler_nir.c | 15 ++++++++++-
src/gallium/drivers/freedreno/ir3/ir3_shader.c | 30 +++++++++++++++++++---
src/gallium/drivers/freedreno/ir3/ir3_shader.h | 3 +++
5 files changed, 48 insertions(+), 6 deletions(-)
diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c b/src/gallium/drivers/freedreno/freedreno_screen.c
index b64f78c..30def8e 100644
--- a/src/gallium/drivers/freedreno/freedreno_screen.c
+++ b/src/gallium/drivers/freedreno/freedreno_screen.c
@@ -71,6 +71,7 @@ static const struct debug_named_value debug_options[] = {
{"glsl120", FD_DBG_GLSL120,"Temporary flag to force GLSL 1.20 (rather than 1.30) on a3xx+"},
{"shaderdb", FD_DBG_SHADERDB, "Enable shaderdb output"},
{"flush", FD_DBG_FLUSH, "Force flush after every draw"},
+ {"nir", FD_DBG_NIR, "Prefer NIR as native IR"},
DEBUG_NAMED_VALUE_END
};
@@ -398,7 +399,7 @@ fd_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader,
case PIPE_SHADER_CAP_TGSI_DROUND_SUPPORTED:
case PIPE_SHADER_CAP_TGSI_DFRACEXP_DLDEXP_SUPPORTED:
case PIPE_SHADER_CAP_TGSI_FMA_SUPPORTED:
- case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
+ case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
return 0;
case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
return 1;
@@ -410,6 +411,8 @@ fd_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader,
case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
return 16;
case PIPE_SHADER_CAP_PREFERRED_IR:
+ if ((fd_mesa_debug & FD_DBG_NIR) && is_ir3(screen))
+ return PIPE_SHADER_IR_NIR;
return PIPE_SHADER_IR_TGSI;
}
debug_printf("unknown shader param %d\n", param);
diff --git a/src/gallium/drivers/freedreno/freedreno_util.h b/src/gallium/drivers/freedreno/freedreno_util.h
index 0d2418e..56d3235 100644
--- a/src/gallium/drivers/freedreno/freedreno_util.h
+++ b/src/gallium/drivers/freedreno/freedreno_util.h
@@ -73,6 +73,7 @@ enum adreno_stencil_op fd_stencil_op(unsigned op);
#define FD_DBG_GLSL120 0x0400
#define FD_DBG_SHADERDB 0x0800
#define FD_DBG_FLUSH 0x1000
+#define FD_DBG_NIR 0x2000
extern int fd_mesa_debug;
extern bool fd_binning_enabled;
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c b/src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c
index b4e5483..5a53e32 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c
@@ -164,7 +164,14 @@ to_nir(struct ir3_compile *ctx, struct ir3_shader_variant *so)
tex_options.lower_txp = (1 << GLSL_SAMPLER_DIM_3D);
}
- struct nir_shader *s = tgsi_to_nir(so->shader->tokens, &options);
+ struct nir_shader *s;
+
+ if (so->shader->nir) {
+ // XXX need nir_clone() here..
+ s = so->shader->nir;
+ } else {
+ s = tgsi_to_nir(so->shader->tokens, &options);
+ }
if (fd_mesa_debug & FD_DBG_OPTMSGS) {
debug_printf("----------------------\n");
@@ -292,6 +299,12 @@ compile_error(struct ir3_compile *ctx, const char *format, ...)
static void
compile_free(struct ir3_compile *ctx)
{
+ /* TODO .. probably need a ralloc_free(ctx->s) here, at least
+ * for the tgsi_to_nir case.. right now in the case we get
+ * NIR directly, we want to skip this since the nir_shader isn't
+ * getting cloned.. and/or if it was we might be wanting to
+ * free it in ir3_shader_destroy()??
+ */
ralloc_free(ctx);
}
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_shader.c b/src/gallium/drivers/freedreno/ir3/ir3_shader.c
index 7b56533..0cbf8fe 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_shader.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3_shader.c
@@ -39,6 +39,7 @@
#include "ir3_shader.h"
#include "ir3_compiler.h"
+#include "ir3_nir.h"
static void
@@ -188,9 +189,15 @@ create_variant(struct ir3_shader *shader, struct ir3_shader_key key)
v->type = shader->type;
if (fd_mesa_debug & FD_DBG_DISASM) {
- DBG("dump tgsi: type=%d, k={bp=%u,cts=%u,hp=%u}", shader->type,
- key.binning_pass, key.color_two_side, key.half_precision);
- tgsi_dump(shader->tokens, 0);
+ if (shader->nir) {
+ DBG("dump nir: type=%d, k={bp=%u,cts=%u,hp=%u}", shader->type,
+ key.binning_pass, key.color_two_side, key.half_precision);
+ nir_print_shader(shader->nir, stderr);
+ } else {
+ DBG("dump tgsi: type=%d, k={bp=%u,cts=%u,hp=%u}", shader->type,
+ key.binning_pass, key.color_two_side, key.half_precision);
+ tgsi_dump(shader->tokens, 0);
+ }
}
ret = ir3_compile_shader_nir(shader->compiler, v);
@@ -267,7 +274,9 @@ ir3_shader_destroy(struct ir3_shader *shader)
v = v->next;
delete_variant(t);
}
+
free((void *)shader->tokens);
+ /* XXX ralloc_free(shader->nir); */
free(shader);
}
@@ -281,7 +290,20 @@ ir3_shader_create(struct pipe_context *pctx,
shader->id = ++shader->compiler->shader_count;
shader->pctx = pctx;
shader->type = type;
- shader->tokens = tgsi_dup_tokens(cso->tokens);
+ if (cso->ir == PIPE_SHADER_IR_NIR) {
+ /* TODO might need nir_clone() here.. Depends a bit on how we
+ * define the lifecycle of cso->nir. If we could assume that it
+ * always sticks around until the cso is destroyed, then we'd
+ * only need to clone in to_nir() (for the variant specific
+ * lowering), rather than both here and to_nir(). This is a bit
+ * different from the lifetime of cso->tokens which sometimes
+ * but not always goes away after the pipe->pipe_create_xyz_state()
+ * call (which is unfortunate, and maybe worth fixing).
+ */
+ shader->nir = cso->nir;
+ } else {
+ shader->tokens = tgsi_dup_tokens(cso->tokens);
+ }
shader->stream_output = cso->stream_output;
if (fd_mesa_debug & FD_DBG_SHADERDB) {
/* if shader-db run, create a standard variant immediately
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_shader.h b/src/gallium/drivers/freedreno/ir3/ir3_shader.h
index 7e2c27d..9ef3277 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_shader.h
+++ b/src/gallium/drivers/freedreno/ir3/ir3_shader.h
@@ -220,6 +220,8 @@ struct ir3_shader_variant {
struct ir3_shader *shader;
};
+typedef struct nir_shader nir_shader;
+
struct ir3_shader {
enum shader_t type;
@@ -230,6 +232,7 @@ struct ir3_shader {
struct ir3_compiler *compiler;
struct pipe_context *pctx;
+ nir_shader *nir;
const struct tgsi_token *tokens;
struct pipe_stream_output_info stream_output;
--
2.5.0
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2015-10-19 19:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-19 19:47 [RFCv0 0/8] gallium: add support for NIR as alternate IR Rob Clark
2015-10-19 19:47 ` [PATCH 1/8] nir: add nir_var_all enum Rob Clark
2015-10-19 19:47 ` [RFCv0 2/8] gallium: refactor pipe_shader_state to support multiple IR's Rob Clark
2015-10-19 19:47 ` [RFCv0 3/8] gallium: add NIR as a possible IR Rob Clark
2015-10-19 19:47 ` [RFCv0 4/8] mesa/st: add support for NIR as possible driver IR Rob Clark
2015-10-19 19:47 ` [RFCv0 5/8] freedreno/ir3: drop tokens arg Rob Clark
2015-10-19 19:47 ` Rob Clark [this message]
2015-10-19 19:48 ` [RFCv0 7/8] freedreno/ir3: fix const_index handling for uniforms Rob Clark
2015-10-19 19:48 ` [RFCv0 8/8] freedreno/ir3: hack for mismatch on varying slots for glsl->tgsi->nir vs glsl->nir Rob Clark
2015-10-19 19:51 ` [RFCv0 0/8] gallium: add support for NIR as alternate IR Ilia Mirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1445284081-29532-7-git-send-email-robdclark@gmail.com \
--to=robdclark@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jason@jlekstrand.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.