Mesa (master): freedreno/a6xx: Share shader state constructor and destructor

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Sep 19 00:32:50 UTC 2019


Module: Mesa
Branch: master
Commit: 1cb9534434cdce4378eac4baedaf99ee466b2936
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1cb9534434cdce4378eac4baedaf99ee466b2936

Author: Kristian H. Kristensen <hoegsberg at google.com>
Date:   Mon Jun 10 12:04:21 2019 -0700

freedreno/a6xx: Share shader state constructor and destructor

Also, swap vs and fs constructor or so fs comes first.

Signed-off-by: Kristian H. Kristensen <hoegsberg at google.com>
Reviewed-by: Eric Anholt <eric at anholt.net>

---

 src/gallium/drivers/freedreno/a3xx/fd3_program.c | 44 +----------
 src/gallium/drivers/freedreno/a4xx/fd4_program.c | 44 +----------
 src/gallium/drivers/freedreno/a5xx/fd5_program.c | 44 +----------
 src/gallium/drivers/freedreno/a6xx/fd6_program.c | 94 +++++++++---------------
 src/gallium/drivers/freedreno/ir3/ir3_gallium.c  | 36 ++++++++-
 src/gallium/drivers/freedreno/ir3/ir3_gallium.h  |  4 +-
 6 files changed, 76 insertions(+), 190 deletions(-)

diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_program.c b/src/gallium/drivers/freedreno/a3xx/fd3_program.c
index af7f19d59ba..a9d4fd0784f 100644
--- a/src/gallium/drivers/freedreno/a3xx/fd3_program.c
+++ b/src/gallium/drivers/freedreno/a3xx/fd3_program.c
@@ -38,43 +38,6 @@
 #include "fd3_texture.h"
 #include "fd3_format.h"
 
-static struct ir3_shader *
-create_shader_stateobj(struct pipe_context *pctx, const struct pipe_shader_state *cso,
-		gl_shader_stage type)
-{
-	struct fd_context *ctx = fd_context(pctx);
-	struct ir3_compiler *compiler = ctx->screen->compiler;
-	return ir3_shader_create(compiler, cso, type, &ctx->debug, pctx->screen);
-}
-
-static void *
-fd3_fp_state_create(struct pipe_context *pctx,
-		const struct pipe_shader_state *cso)
-{
-	return create_shader_stateobj(pctx, cso, MESA_SHADER_FRAGMENT);
-}
-
-static void
-fd3_fp_state_delete(struct pipe_context *pctx, void *hwcso)
-{
-	struct ir3_shader *so = hwcso;
-	ir3_shader_destroy(so);
-}
-
-static void *
-fd3_vp_state_create(struct pipe_context *pctx,
-		const struct pipe_shader_state *cso)
-{
-	return create_shader_stateobj(pctx, cso, MESA_SHADER_VERTEX);
-}
-
-static void
-fd3_vp_state_delete(struct pipe_context *pctx, void *hwcso)
-{
-	struct ir3_shader *so = hwcso;
-	ir3_shader_destroy(so);
-}
-
 bool
 fd3_needs_manual_clipping(const struct ir3_shader *shader,
 						  const struct pipe_rasterizer_state *rast)
@@ -485,11 +448,6 @@ fd3_program_emit(struct fd_ringbuffer *ring, struct fd3_emit *emit,
 void
 fd3_prog_init(struct pipe_context *pctx)
 {
-	pctx->create_fs_state = fd3_fp_state_create;
-	pctx->delete_fs_state = fd3_fp_state_delete;
-
-	pctx->create_vs_state = fd3_vp_state_create;
-	pctx->delete_vs_state = fd3_vp_state_delete;
-
+	ir3_prog_init(pctx);
 	fd_prog_init(pctx);
 }
diff --git a/src/gallium/drivers/freedreno/a4xx/fd4_program.c b/src/gallium/drivers/freedreno/a4xx/fd4_program.c
index 5fa1f8e0200..b982d5d06e7 100644
--- a/src/gallium/drivers/freedreno/a4xx/fd4_program.c
+++ b/src/gallium/drivers/freedreno/a4xx/fd4_program.c
@@ -37,43 +37,6 @@
 #include "fd4_texture.h"
 #include "fd4_format.h"
 
-static struct ir3_shader *
-create_shader_stateobj(struct pipe_context *pctx, const struct pipe_shader_state *cso,
-		gl_shader_stage type)
-{
-	struct fd_context *ctx = fd_context(pctx);
-	struct ir3_compiler *compiler = ctx->screen->compiler;
-	return ir3_shader_create(compiler, cso, type, &ctx->debug, pctx->screen);
-}
-
-static void *
-fd4_fp_state_create(struct pipe_context *pctx,
-		const struct pipe_shader_state *cso)
-{
-	return create_shader_stateobj(pctx, cso, MESA_SHADER_FRAGMENT);
-}
-
-static void
-fd4_fp_state_delete(struct pipe_context *pctx, void *hwcso)
-{
-	struct ir3_shader *so = hwcso;
-	ir3_shader_destroy(so);
-}
-
-static void *
-fd4_vp_state_create(struct pipe_context *pctx,
-		const struct pipe_shader_state *cso)
-{
-	return create_shader_stateobj(pctx, cso, MESA_SHADER_VERTEX);
-}
-
-static void
-fd4_vp_state_delete(struct pipe_context *pctx, void *hwcso)
-{
-	struct ir3_shader *so = hwcso;
-	ir3_shader_destroy(so);
-}
-
 static void
 emit_shader(struct fd_ringbuffer *ring, const struct ir3_shader_variant *so)
 {
@@ -569,11 +532,6 @@ fd4_program_emit(struct fd_ringbuffer *ring, struct fd4_emit *emit,
 void
 fd4_prog_init(struct pipe_context *pctx)
 {
-	pctx->create_fs_state = fd4_fp_state_create;
-	pctx->delete_fs_state = fd4_fp_state_delete;
-
-	pctx->create_vs_state = fd4_vp_state_create;
-	pctx->delete_vs_state = fd4_vp_state_delete;
-
+	ir3_prog_init(pctx);
 	fd_prog_init(pctx);
 }
diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_program.c b/src/gallium/drivers/freedreno/a5xx/fd5_program.c
index e52ba900e05..8f6ee9a687e 100644
--- a/src/gallium/drivers/freedreno/a5xx/fd5_program.c
+++ b/src/gallium/drivers/freedreno/a5xx/fd5_program.c
@@ -40,43 +40,6 @@
 
 #include "ir3_cache.h"
 
-static struct ir3_shader *
-create_shader_stateobj(struct pipe_context *pctx, const struct pipe_shader_state *cso,
-		gl_shader_stage type)
-{
-	struct fd_context *ctx = fd_context(pctx);
-	struct ir3_compiler *compiler = ctx->screen->compiler;
-	return ir3_shader_create(compiler, cso, type, &ctx->debug, pctx->screen);
-}
-
-static void *
-fd5_fp_state_create(struct pipe_context *pctx,
-		const struct pipe_shader_state *cso)
-{
-	return create_shader_stateobj(pctx, cso, MESA_SHADER_FRAGMENT);
-}
-
-static void
-fd5_fp_state_delete(struct pipe_context *pctx, void *hwcso)
-{
-	struct ir3_shader *so = hwcso;
-	ir3_shader_destroy(so);
-}
-
-static void *
-fd5_vp_state_create(struct pipe_context *pctx,
-		const struct pipe_shader_state *cso)
-{
-	return create_shader_stateobj(pctx, cso, MESA_SHADER_VERTEX);
-}
-
-static void
-fd5_vp_state_delete(struct pipe_context *pctx, void *hwcso)
-{
-	struct ir3_shader *so = hwcso;
-	ir3_shader_destroy(so);
-}
-
 void
 fd5_emit_shader(struct fd_ringbuffer *ring, const struct ir3_shader_variant *so)
 {
@@ -722,11 +685,6 @@ fd5_program_emit(struct fd_context *ctx, struct fd_ringbuffer *ring,
 void
 fd5_prog_init(struct pipe_context *pctx)
 {
-	pctx->create_fs_state = fd5_fp_state_create;
-	pctx->delete_fs_state = fd5_fp_state_delete;
-
-	pctx->create_vs_state = fd5_vp_state_create;
-	pctx->delete_vs_state = fd5_vp_state_delete;
-
+	ir3_prog_init(pctx);
 	fd_prog_init(pctx);
 }
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_program.c b/src/gallium/drivers/freedreno/a6xx/fd6_program.c
index 47ba86353b1..26be370833d 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_program.c
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_program.c
@@ -39,61 +39,6 @@
 #include "fd6_texture.h"
 #include "fd6_format.h"
 
-static struct ir3_shader *
-create_shader_stateobj(struct pipe_context *pctx, const struct pipe_shader_state *cso,
-		gl_shader_stage type)
-{
-	struct fd_context *ctx = fd_context(pctx);
-	struct ir3_compiler *compiler = ctx->screen->compiler;
-	struct ir3_shader *shader =
-		ir3_shader_create(compiler, cso, type, &ctx->debug, pctx->screen);
-	unsigned packets, size;
-
-	/* pre-calculate size required for userconst stateobj: */
-	ir3_user_consts_size(&shader->ubo_state, &packets, &size);
-
-	/* also account for UBO addresses: */
-	packets += 1;
-	size += 2 * shader->const_state.num_ubos;
-
-	unsigned sizedwords = (4 * packets) + size;
-	shader->ubo_state.cmdstream_size = sizedwords * 4;
-
-	return shader;
-}
-
-static void *
-fd6_fp_state_create(struct pipe_context *pctx,
-		const struct pipe_shader_state *cso)
-{
-	return create_shader_stateobj(pctx, cso, MESA_SHADER_FRAGMENT);
-}
-
-static void
-fd6_fp_state_delete(struct pipe_context *pctx, void *hwcso)
-{
-	struct ir3_shader *so = hwcso;
-	struct fd_context *ctx = fd_context(pctx);
-	ir3_cache_invalidate(fd6_context(ctx)->shader_cache, hwcso);
-	ir3_shader_destroy(so);
-}
-
-static void *
-fd6_vp_state_create(struct pipe_context *pctx,
-		const struct pipe_shader_state *cso)
-{
-	return create_shader_stateobj(pctx, cso, MESA_SHADER_VERTEX);
-}
-
-static void
-fd6_vp_state_delete(struct pipe_context *pctx, void *hwcso)
-{
-	struct ir3_shader *so = hwcso;
-	struct fd_context *ctx = fd_context(pctx);
-	ir3_cache_invalidate(fd6_context(ctx)->shader_cache, hwcso);
-	ir3_shader_destroy(so);
-}
-
 void
 fd6_emit_shader(struct fd_ringbuffer *ring, const struct ir3_shader_variant *so)
 {
@@ -749,6 +694,37 @@ static const struct ir3_cache_funcs cache_funcs = {
 	.destroy_state = fd6_program_destroy,
 };
 
+static void *
+fd6_shader_state_create(struct pipe_context *pctx, const struct pipe_shader_state *cso)
+{
+	struct fd_context *ctx = fd_context(pctx);
+	struct ir3_compiler *compiler = ctx->screen->compiler;
+	struct ir3_shader *shader =
+		ir3_shader_create(compiler, cso, &ctx->debug, pctx->screen);
+	unsigned packets, size;
+
+	/* pre-calculate size required for userconst stateobj: */
+	ir3_user_consts_size(&shader->ubo_state, &packets, &size);
+
+	/* also account for UBO addresses: */
+	packets += 1;
+	size += 2 * shader->const_state.num_ubos;
+
+	unsigned sizedwords = (4 * packets) + size;
+	shader->ubo_state.cmdstream_size = sizedwords * 4;
+
+	return shader;
+}
+
+static void
+fd6_shader_state_delete(struct pipe_context *pctx, void *hwcso)
+{
+	struct ir3_shader *so = hwcso;
+	struct fd_context *ctx = fd_context(pctx);
+	ir3_cache_invalidate(fd6_context(ctx)->shader_cache, hwcso);
+	ir3_shader_destroy(so);
+}
+
 void
 fd6_prog_init(struct pipe_context *pctx)
 {
@@ -756,11 +732,11 @@ fd6_prog_init(struct pipe_context *pctx)
 
 	fd6_context(ctx)->shader_cache = ir3_cache_create(&cache_funcs, ctx);
 
-	pctx->create_fs_state = fd6_fp_state_create;
-	pctx->delete_fs_state = fd6_fp_state_delete;
+	pctx->create_vs_state = fd6_shader_state_create;
+	pctx->delete_vs_state = fd6_shader_state_delete;
 
-	pctx->create_vs_state = fd6_vp_state_create;
-	pctx->delete_vs_state = fd6_vp_state_delete;
+	pctx->create_fs_state = fd6_shader_state_create;
+	pctx->delete_fs_state = fd6_shader_state_delete;
 
 	fd_prog_init(pctx);
 }
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c
index 7456a82ed7b..11a4dc78161 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c
@@ -110,7 +110,7 @@ copy_stream_out(struct ir3_stream_output_info *i,
 
 struct ir3_shader *
 ir3_shader_create(struct ir3_compiler *compiler,
-		const struct pipe_shader_state *cso, gl_shader_stage type,
+		const struct pipe_shader_state *cso,
 		struct pipe_debug_callback *debug,
 		struct pipe_screen *screen)
 {
@@ -689,3 +689,37 @@ ir3_emit_cs_consts(const struct ir3_shader_variant *v, struct fd_ringbuffer *rin
 		}
 	}
 }
+
+static void *
+ir3_shader_state_create(struct pipe_context *pctx, const struct pipe_shader_state *cso)
+{
+	struct fd_context *ctx = fd_context(pctx);
+	struct ir3_compiler *compiler = ctx->screen->compiler;
+	return ir3_shader_create(compiler, cso, &ctx->debug, pctx->screen);
+}
+
+static void
+ir3_shader_state_delete(struct pipe_context *pctx, void *hwcso)
+{
+	struct ir3_shader *so = hwcso;
+	ir3_shader_destroy(so);
+}
+
+void
+ir3_prog_init(struct pipe_context *pctx)
+{
+	pctx->create_vs_state = ir3_shader_state_create;
+	pctx->delete_vs_state = ir3_shader_state_delete;
+
+	pctx->create_tcs_state = ir3_shader_state_create;
+	pctx->delete_tcs_state = ir3_shader_state_delete;
+
+	pctx->create_tes_state = ir3_shader_state_create;
+	pctx->delete_tes_state = ir3_shader_state_delete;
+
+	pctx->create_gs_state = ir3_shader_state_create;
+	pctx->delete_gs_state = ir3_shader_state_delete;
+
+	pctx->create_fs_state = ir3_shader_state_create;
+	pctx->delete_fs_state = ir3_shader_state_delete;
+}
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_gallium.h b/src/gallium/drivers/freedreno/ir3/ir3_gallium.h
index b0cf7ed9805..5352df51990 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_gallium.h
+++ b/src/gallium/drivers/freedreno/ir3/ir3_gallium.h
@@ -32,7 +32,7 @@
 #include "ir3/ir3_shader.h"
 
 struct ir3_shader * ir3_shader_create(struct ir3_compiler *compiler,
-		const struct pipe_shader_state *cso, gl_shader_stage type,
+		const struct pipe_shader_state *cso,
 		struct pipe_debug_callback *debug,
 		struct pipe_screen *screen);
 struct ir3_shader *
@@ -83,4 +83,6 @@ void ir3_emit_fs_consts(const struct ir3_shader_variant *v, struct fd_ringbuffer
 void ir3_emit_cs_consts(const struct ir3_shader_variant *v, struct fd_ringbuffer *ring,
 		struct fd_context *ctx, const struct pipe_grid_info *info);
 
+void ir3_prog_init(struct pipe_context *pctx);
+
 #endif /* IR3_GALLIUM_H_ */




More information about the mesa-commit mailing list