From 9b961b9d1d5f4ea62df871819b6cc1ae0499c3ca Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 25 Jan 2022 13:39:02 +1000 Subject: [PATCH] mesa/st: refactor program translation into one file. This moves the notify callback into the file where it's all called from. Reviewed-by: Kristian H. Kristensen Part-of: --- src/mesa/main/arbprogram.c | 2 +- src/mesa/main/atifragshader.c | 2 +- src/mesa/main/ffvertex_prog.c | 2 +- src/mesa/main/glspirv.c | 2 - src/mesa/main/hint.c | 1 - src/mesa/main/shaderapi.c | 1 - src/mesa/meson.build | 2 - src/mesa/state_tracker/st_cb_program.c | 97 ---------------------- src/mesa/state_tracker/st_cb_program.h | 46 ---------- src/mesa/state_tracker/st_context.c | 3 +- src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 2 +- src/mesa/state_tracker/st_program.c | 45 +++++++++- src/mesa/state_tracker/st_program.h | 16 +--- 13 files changed, 51 insertions(+), 170 deletions(-) delete mode 100644 src/mesa/state_tracker/st_cb_program.c delete mode 100644 src/mesa/state_tracker/st_cb_program.h diff --git a/src/mesa/main/arbprogram.c b/src/mesa/main/arbprogram.c index be42cea2762..28102ebe09c 100644 --- a/src/mesa/main/arbprogram.c +++ b/src/mesa/main/arbprogram.c @@ -43,7 +43,7 @@ #include "program/prog_print.h" #include "api_exec_decl.h" -#include "state_tracker/st_cb_program.h" +#include "state_tracker/st_program.h" static void flush_vertices_for_program_constants(struct gl_context *ctx, GLenum target) diff --git a/src/mesa/main/atifragshader.c b/src/mesa/main/atifragshader.c index d6340977360..c3b370bab9f 100644 --- a/src/mesa/main/atifragshader.c +++ b/src/mesa/main/atifragshader.c @@ -34,7 +34,7 @@ #include "util/u_memory.h" #include "api_exec_decl.h" -#include "state_tracker/st_cb_program.h" +#include "state_tracker/st_program.h" #define MESA_DEBUG_ATI_FS 0 diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c index 24face21db3..c6f6234625e 100644 --- a/src/mesa/main/ffvertex_prog.c +++ b/src/mesa/main/ffvertex_prog.c @@ -47,7 +47,7 @@ #include "program/prog_statevars.h" #include "util/bitscan.h" -#include "state_tracker/st_cb_program.h" +#include "state_tracker/st_program.h" /** Max of number of lights and texture coord units */ #define NUM_UNITS MAX2(MAX_TEXTURE_COORD_UNITS, MAX_LIGHTS) diff --git a/src/mesa/main/glspirv.c b/src/mesa/main/glspirv.c index 3eeff7022de..c5c51174b64 100644 --- a/src/mesa/main/glspirv.c +++ b/src/mesa/main/glspirv.c @@ -34,8 +34,6 @@ #include "util/u_atomic.h" #include "api_exec_decl.h" -#include "state_tracker/st_cb_program.h" - void _mesa_spirv_module_reference(struct gl_spirv_module **dest, struct gl_spirv_module *src) diff --git a/src/mesa/main/hint.c b/src/mesa/main/hint.c index 1360796a66d..e329fc5c596 100644 --- a/src/mesa/main/hint.c +++ b/src/mesa/main/hint.c @@ -30,7 +30,6 @@ #include "hint.h" #include "mtypes.h" -#include "state_tracker/st_cb_program.h" #include "api_exec_decl.h" #include "pipe/p_screen.h" diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index d2479711c3f..bfc17b5deb9 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -67,7 +67,6 @@ #include "util/u_string.h" #include "api_exec_decl.h" -#include "state_tracker/st_cb_program.h" #include "state_tracker/st_context.h" #include "state_tracker/st_program.h" diff --git a/src/mesa/meson.build b/src/mesa/meson.build index af9a5fcac27..bc7963413ff 100644 --- a/src/mesa/meson.build +++ b/src/mesa/meson.build @@ -338,8 +338,6 @@ files_libmesa = files( 'state_tracker/st_cb_feedback.h', 'state_tracker/st_cb_flush.c', 'state_tracker/st_cb_flush.h', - 'state_tracker/st_cb_program.c', - 'state_tracker/st_cb_program.h', 'state_tracker/st_cb_rasterpos.c', 'state_tracker/st_cb_rasterpos.h', 'state_tracker/st_cb_readpixels.c', diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c deleted file mode 100644 index 7e43934d472..00000000000 --- a/src/mesa/state_tracker/st_cb_program.c +++ /dev/null @@ -1,97 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - /* - * Authors: - * Keith Whitwell - */ - -#include "main/glheader.h" -#include "main/macros.h" -#include "main/enums.h" -#include "main/shaderapi.h" -#include "program/prog_instruction.h" -#include "program/program.h" - -#include "cso_cache/cso_context.h" -#include "draw/draw_context.h" - -#include "st_context.h" -#include "st_debug.h" -#include "st_program.h" -#include "st_cb_program.h" -#include "st_glsl_to_ir.h" -#include "st_atifs_to_nir.h" -#include "st_util.h" - -/** - * Called when the program's text/code is changed. We have to free - * all shader variants and corresponding gallium shaders when this happens. - */ -GLboolean -st_program_string_notify( struct gl_context *ctx, - GLenum target, - struct gl_program *prog ) -{ - struct st_context *st = st_context(ctx); - - /* GLSL-to-NIR should not end up here. */ - assert(!prog->shader_program); - - st_release_variants(st, prog); - - if (target == GL_FRAGMENT_PROGRAM_ARB || - target == GL_FRAGMENT_SHADER_ATI) { - if (target == GL_FRAGMENT_SHADER_ATI) { - assert(prog->ati_fs); - assert(prog->ati_fs->Program == prog); - - st_init_atifs_prog(ctx, prog); - } - - if (!st_translate_fragment_program(st, prog)) - return false; - } else if (target == GL_VERTEX_PROGRAM_ARB) { - if (!st_translate_vertex_program(st, prog)) - return false; - } else { - if (!st_translate_common_program(st, prog)) - return false; - } - - st_finalize_program(st, prog); - return GL_TRUE; -} - -/** - * Plug in the program and shader-related device driver functions. - */ -void -st_init_program_functions(struct dd_function_table *functions) -{ - functions->NewProgram = _mesa_new_program; -} diff --git a/src/mesa/state_tracker/st_cb_program.h b/src/mesa/state_tracker/st_cb_program.h deleted file mode 100644 index 9bee1b9d861..00000000000 --- a/src/mesa/state_tracker/st_cb_program.h +++ /dev/null @@ -1,46 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef ST_CB_PROGRAM_H -#define ST_CB_PROGRAM_H - -#ifdef __cplusplus -extern "C" { -#endif - -struct dd_function_table; - -extern void -st_init_program_functions(struct dd_function_table *functions); -GLboolean st_program_string_notify(struct gl_context *ctx, - GLenum target, - struct gl_program *prog); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 5cd5407e73c..e1d75e583e2 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -47,7 +47,6 @@ #include "st_cb_drawtex.h" #include "st_cb_eglimage.h" #include "st_cb_feedback.h" -#include "st_cb_program.h" #include "st_cb_flush.h" #include "st_atom.h" #include "st_draw.h" @@ -812,7 +811,7 @@ st_init_driver_functions(struct pipe_screen *screen, st_init_eglimage_functions(functions, has_egl_image_validate); - st_init_program_functions(functions); + functions->NewProgram = _mesa_new_program; st_init_flush_functions(screen, functions); /* GL_ARB_get_program_binary */ diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 8cd4d1b0a63..ab794bf65b0 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -31,7 +31,7 @@ */ #include "st_glsl_to_tgsi.h" -#include "st_cb_program.h" +#include "st_program.h" #include "compiler/glsl/glsl_parser_extras.h" #include "compiler/glsl/ir_optimization.h" diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 36ff3c8eb8e..ad78069c3fc 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -577,7 +577,7 @@ st_create_nir_shader(struct st_context *st, struct pipe_shader_state *state) /** * Translate a vertex program. */ -bool +static bool st_translate_vertex_program(struct st_context *st, struct gl_program *prog) { @@ -994,7 +994,7 @@ st_get_common_variant(struct st_context *st, /** * Translate a Mesa fragment shader into a TGSI shader. */ -bool +static bool st_translate_fragment_program(struct st_context *st, struct gl_program *fp) { @@ -1685,7 +1685,7 @@ st_get_fp_variant(struct st_context *st, * Translate a program. This is common code for geometry and tessellation * shaders. */ -bool +static bool st_translate_common_program(struct st_context *st, struct gl_program *prog) { @@ -2052,3 +2052,42 @@ st_finalize_program(struct st_context *st, struct gl_program *prog) /* Always create the default variant of the program. */ st_precompile_shader_variant(st, prog); } + +/** + * Called when the program's text/code is changed. We have to free + * all shader variants and corresponding gallium shaders when this happens. + */ +GLboolean +st_program_string_notify( struct gl_context *ctx, + GLenum target, + struct gl_program *prog ) +{ + struct st_context *st = st_context(ctx); + + /* GLSL-to-NIR should not end up here. */ + assert(!prog->shader_program); + + st_release_variants(st, prog); + + if (target == GL_FRAGMENT_PROGRAM_ARB || + target == GL_FRAGMENT_SHADER_ATI) { + if (target == GL_FRAGMENT_SHADER_ATI) { + assert(prog->ati_fs); + assert(prog->ati_fs->Program == prog); + + st_init_atifs_prog(ctx, prog); + } + + if (!st_translate_fragment_program(st, prog)) + return false; + } else if (target == GL_VERTEX_PROGRAM_ARB) { + if (!st_translate_vertex_program(st, prog)) + return false; + } else { + if (!st_translate_common_program(st, prog)) + return false; + } + + st_finalize_program(st, prog); + return GL_TRUE; +} diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 9ee2a9485f4..a1dd6b10618 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -301,18 +301,6 @@ st_prepare_vertex_program(struct gl_program *stvp, uint8_t *attrib_to_index); extern void st_translate_stream_output_info(struct gl_program *prog); -extern bool -st_translate_vertex_program(struct st_context *st, - struct gl_program *stvp); - -extern bool -st_translate_fragment_program(struct st_context *st, - struct gl_program *stfp); - -extern bool -st_translate_common_program(struct st_context *st, - struct gl_program *stp); - extern void st_serialize_nir(struct gl_program *stp); @@ -322,6 +310,10 @@ st_finalize_program(struct st_context *st, struct gl_program *prog); struct pipe_shader_state * st_create_nir_shader(struct st_context *st, struct pipe_shader_state *state); +GLboolean st_program_string_notify(struct gl_context *ctx, + GLenum target, + struct gl_program *prog); + #ifdef __cplusplus } #endif