From e481d3e2ed02f965bdacf9c7518158ef495c850a Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Sat, 13 Jun 2020 10:45:22 -0400 Subject: [PATCH] zink: move shader state methods for pipe_context into zink_program.c just moving these so all the shader code can be in one place Acked-by: Erik Faye-Lund Part-of: --- src/gallium/drivers/zink/zink_context.c | 72 +---------------------- src/gallium/drivers/zink/zink_program.c | 77 +++++++++++++++++++++++++ src/gallium/drivers/zink/zink_program.h | 2 + 3 files changed, 81 insertions(+), 70 deletions(-) diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 792027ceb93..2f9a38573d4 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -28,6 +28,7 @@ #include "zink_fence.h" #include "zink_framebuffer.h" #include "zink_helpers.h" +#include "zink_program.h" #include "zink_pipeline.h" #include "zink_query.h" #include "zink_render_pass.h" @@ -292,69 +293,6 @@ zink_sampler_view_destroy(struct pipe_context *pctx, FREE(view); } -static void * -zink_create_vs_state(struct pipe_context *pctx, - const struct pipe_shader_state *shader) -{ - struct nir_shader *nir; - if (shader->type != PIPE_SHADER_IR_NIR) - nir = zink_tgsi_to_nir(pctx->screen, shader->tokens); - else - nir = (struct nir_shader *)shader->ir.nir; - - return zink_compile_nir(zink_screen(pctx->screen), nir, &shader->stream_output); -} - -static void -bind_stage(struct zink_context *ctx, enum pipe_shader_type stage, - struct zink_shader *shader) -{ - assert(stage < PIPE_SHADER_COMPUTE); - ctx->gfx_stages[stage] = shader; - ctx->dirty_program = true; -} - -static void -zink_bind_vs_state(struct pipe_context *pctx, - void *cso) -{ - bind_stage(zink_context(pctx), PIPE_SHADER_VERTEX, cso); -} - -static void -zink_delete_vs_state(struct pipe_context *pctx, - void *cso) -{ - zink_shader_free(zink_context(pctx), cso); -} - -static void * -zink_create_fs_state(struct pipe_context *pctx, - const struct pipe_shader_state *shader) -{ - struct nir_shader *nir; - if (shader->type != PIPE_SHADER_IR_NIR) - nir = zink_tgsi_to_nir(pctx->screen, shader->tokens); - else - nir = (struct nir_shader *)shader->ir.nir; - - return zink_compile_nir(zink_screen(pctx->screen), nir, NULL); -} - -static void -zink_bind_fs_state(struct pipe_context *pctx, - void *cso) -{ - bind_stage(zink_context(pctx), PIPE_SHADER_FRAGMENT, cso); -} - -static void -zink_delete_fs_state(struct pipe_context *pctx, - void *cso) -{ - zink_shader_free(zink_context(pctx), cso); -} - static void zink_set_polygon_stipple(struct pipe_context *pctx, const struct pipe_poly_stipple *ps) @@ -1127,13 +1065,7 @@ zink_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags) ctx->base.set_sampler_views = zink_set_sampler_views; ctx->base.sampler_view_destroy = zink_sampler_view_destroy; - ctx->base.create_vs_state = zink_create_vs_state; - ctx->base.bind_vs_state = zink_bind_vs_state; - ctx->base.delete_vs_state = zink_delete_vs_state; - - ctx->base.create_fs_state = zink_create_fs_state; - ctx->base.bind_fs_state = zink_bind_fs_state; - ctx->base.delete_fs_state = zink_delete_fs_state; + zink_program_init(ctx); ctx->base.set_polygon_stipple = zink_set_polygon_stipple; ctx->base.set_vertex_buffers = zink_set_vertex_buffers; diff --git a/src/gallium/drivers/zink/zink_program.c b/src/gallium/drivers/zink/zink_program.c index 341c3293ac2..4bc1b21988c 100644 --- a/src/gallium/drivers/zink/zink_program.c +++ b/src/gallium/drivers/zink/zink_program.c @@ -278,3 +278,80 @@ zink_get_gfx_pipeline(struct zink_screen *screen, return ((struct pipeline_cache_entry *)(entry->data))->pipeline; } + + +static void * +zink_create_vs_state(struct pipe_context *pctx, + const struct pipe_shader_state *shader) +{ + struct nir_shader *nir; + if (shader->type != PIPE_SHADER_IR_NIR) + nir = zink_tgsi_to_nir(pctx->screen, shader->tokens); + else + nir = (struct nir_shader *)shader->ir.nir; + + return zink_compile_nir(zink_screen(pctx->screen), nir, &shader->stream_output); +} + +static void +bind_stage(struct zink_context *ctx, enum pipe_shader_type stage, + struct zink_shader *shader) +{ + assert(stage < PIPE_SHADER_COMPUTE); + ctx->gfx_stages[stage] = shader; + ctx->dirty_program = true; +} + +static void +zink_bind_vs_state(struct pipe_context *pctx, + void *cso) +{ + bind_stage(zink_context(pctx), PIPE_SHADER_VERTEX, cso); +} + +static void +zink_delete_vs_state(struct pipe_context *pctx, + void *cso) +{ + zink_shader_free(zink_context(pctx), cso); +} + +static void * +zink_create_fs_state(struct pipe_context *pctx, + const struct pipe_shader_state *shader) +{ + struct nir_shader *nir; + if (shader->type != PIPE_SHADER_IR_NIR) + nir = zink_tgsi_to_nir(pctx->screen, shader->tokens); + else + nir = (struct nir_shader *)shader->ir.nir; + + return zink_compile_nir(zink_screen(pctx->screen), nir, NULL); +} + +static void +zink_bind_fs_state(struct pipe_context *pctx, + void *cso) +{ + bind_stage(zink_context(pctx), PIPE_SHADER_FRAGMENT, cso); +} + +static void +zink_delete_fs_state(struct pipe_context *pctx, + void *cso) +{ + zink_shader_free(zink_context(pctx), cso); +} + + +void +zink_program_init(struct zink_context *ctx) +{ + ctx->base.create_vs_state = zink_create_vs_state; + ctx->base.bind_vs_state = zink_bind_vs_state; + ctx->base.delete_vs_state = zink_delete_vs_state; + + ctx->base.create_fs_state = zink_create_fs_state; + ctx->base.bind_fs_state = zink_bind_fs_state; + ctx->base.delete_fs_state = zink_delete_fs_state; +} diff --git a/src/gallium/drivers/zink/zink_program.h b/src/gallium/drivers/zink/zink_program.h index 91460aa2341..aaad9f31a93 100644 --- a/src/gallium/drivers/zink/zink_program.h +++ b/src/gallium/drivers/zink/zink_program.h @@ -59,4 +59,6 @@ zink_get_gfx_pipeline(struct zink_screen *screen, struct zink_gfx_pipeline_state *state, enum pipe_prim_type mode); +void +zink_program_init(struct zink_context *ctx); #endif -- 2.30.2