From 5c1d91d5da45000a62b273ecfc8ac1c7f4bdc7ca Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Wed, 5 Jul 2023 12:48:34 +1000 Subject: [PATCH] st/glsl: merge st_glsl_to_ir.cpp with st_glsl_to_nir.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit There is no longer any other IR so lets finally merge these together to make the code easier to follow. Reviewed-by: Marek Olšák Part-of: --- src/mesa/main/shaderapi.c | 2 +- src/mesa/main/tests/disable_windows_include.c | 2 +- src/mesa/meson.build | 3 +- src/mesa/state_tracker/st_glsl_to_ir.cpp | 125 --------------------- src/mesa/state_tracker/st_glsl_to_nir.cpp | 90 ++++++++++++++- .../{st_glsl_to_ir.h => st_glsl_to_nir.h} | 0 src/mesa/state_tracker/st_nir.h | 4 - 7 files changed, 90 insertions(+), 136 deletions(-) delete mode 100644 src/mesa/state_tracker/st_glsl_to_ir.cpp rename src/mesa/state_tracker/{st_glsl_to_ir.h => st_glsl_to_nir.h} (100%) diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index 2fb8c2c..1b188a4 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -69,7 +69,7 @@ #include "api_exec_decl.h" #include "state_tracker/st_context.h" -#include "state_tracker/st_glsl_to_ir.h" +#include "state_tracker/st_glsl_to_nir.h" #include "state_tracker/st_program.h" #ifdef ENABLE_SHADER_CACHE diff --git a/src/mesa/main/tests/disable_windows_include.c b/src/mesa/main/tests/disable_windows_include.c index 41dd1ba..5ff65d7 100644 --- a/src/mesa/main/tests/disable_windows_include.c +++ b/src/mesa/main/tests/disable_windows_include.c @@ -169,7 +169,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mesa/meson.build b/src/mesa/meson.build index a44ca6e..12a0e74 100644 --- a/src/mesa/meson.build +++ b/src/mesa/meson.build @@ -344,9 +344,8 @@ files_libmesa = files( 'state_tracker/st_format.h', 'state_tracker/st_gen_mipmap.c', 'state_tracker/st_gen_mipmap.h', - 'state_tracker/st_glsl_to_ir.cpp', - 'state_tracker/st_glsl_to_ir.h', 'state_tracker/st_glsl_to_nir.cpp', + 'state_tracker/st_glsl_to_nir.h', 'state_tracker/st_interop.c', 'state_tracker/st_interop.h', 'state_tracker/st_manager.c', diff --git a/src/mesa/state_tracker/st_glsl_to_ir.cpp b/src/mesa/state_tracker/st_glsl_to_ir.cpp deleted file mode 100644 index 6b8a1d5..0000000 --- a/src/mesa/state_tracker/st_glsl_to_ir.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2005-2007 Brian Paul All Rights Reserved. - * Copyright (C) 2008 VMware, Inc. All Rights Reserved. - * Copyright © 2010 Intel Corporation - * Copyright © 2011 Bryan Cain - * - * 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, sublicense, - * 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 NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS 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. - */ - -#include "compiler/glsl/glsl_parser_extras.h" -#include "compiler/glsl/ir_optimization.h" -#include "compiler/glsl/linker_util.h" -#include "compiler/glsl/program.h" -#include "compiler/glsl/shader_cache.h" - -#include "st_nir.h" -#include "st_shader_cache.h" -#include "st_program.h" - -#include "main/glspirv.h" -#include "main/shaderapi.h" -#include "main/shaderobj.h" - -extern "C" { - -/** - * Link a GLSL shader program. Called via glLinkProgram(). - */ -void -st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog) -{ - unsigned int i; - bool spirv = false; - - MESA_TRACE_FUNC(); - - _mesa_clear_shader_program_data(ctx, prog); - - prog->data = _mesa_create_shader_program_data(); - - prog->data->LinkStatus = LINKING_SUCCESS; - - for (i = 0; i < prog->NumShaders; i++) { - if (!prog->Shaders[i]->CompileStatus) { - linker_error(prog, "linking with uncompiled/unspecialized shader"); - } - - if (!i) { - spirv = (prog->Shaders[i]->spirv_data != NULL); - } else if (spirv && !prog->Shaders[i]->spirv_data) { - /* The GL_ARB_gl_spirv spec adds a new bullet point to the list of - * reasons LinkProgram can fail: - * - * "All the shader objects attached to do not have the - * same value for the SPIR_V_BINARY_ARB state." - */ - linker_error(prog, - "not all attached shaders have the same " - "SPIR_V_BINARY_ARB state"); - } - } - prog->data->spirv = spirv; - - if (prog->data->LinkStatus) { - if (!spirv) - link_shaders(ctx, prog); - else - _mesa_spirv_link_shaders(ctx, prog); - } - - /* If LinkStatus is LINKING_SUCCESS, then reset sampler validated to true. - * Validation happens via the LinkShader call below. If LinkStatus is - * LINKING_SKIPPED, then SamplersValidated will have been restored from the - * shader cache. - */ - if (prog->data->LinkStatus == LINKING_SUCCESS) { - prog->SamplersValidated = GL_TRUE; - } - - if (prog->data->LinkStatus && !st_link_nir(ctx, prog)) { - prog->data->LinkStatus = LINKING_FAILURE; - } - - if (prog->data->LinkStatus != LINKING_FAILURE) - _mesa_create_program_resource_hash(prog); - - /* Return early if we are loading the shader from on-disk cache */ - if (prog->data->LinkStatus == LINKING_SKIPPED) - return; - - if (ctx->_Shader->Flags & GLSL_DUMP) { - if (!prog->data->LinkStatus) { - fprintf(stderr, "GLSL shader program %d failed to link\n", prog->Name); - } - - if (prog->data->InfoLog && prog->data->InfoLog[0] != 0) { - fprintf(stderr, "GLSL shader program %d info log:\n", prog->Name); - fprintf(stderr, "%s\n", prog->data->InfoLog); - } - } - -#ifdef ENABLE_SHADER_CACHE - if (prog->data->LinkStatus) - shader_cache_write_program_metadata(ctx, prog); -#endif -} - -} /* extern "C" */ diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index 712ee04..3af38da 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -51,6 +51,8 @@ #include "compiler/glsl/ir.h" #include "compiler/glsl/ir_optimization.h" #include "compiler/glsl/linker_util.h" +#include "compiler/glsl/program.h" +#include "compiler/glsl/shader_cache.h" #include "compiler/glsl/string_to_uint_map.h" static int @@ -481,9 +483,9 @@ st_nir_lower_wpos_ytransform(struct nir_shader *nir, } } -bool -st_link_nir(struct gl_context *ctx, - struct gl_shader_program *shader_program) +static bool +st_link_glsl_to_nir(struct gl_context *ctx, + struct gl_shader_program *shader_program) { struct st_context *st = st_context(ctx); struct pipe_screen *pscreen = st->screen; @@ -924,4 +926,86 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog, return msg; } +/** + * Link a GLSL shader program. Called via glLinkProgram(). + */ +void +st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog) +{ + unsigned int i; + bool spirv = false; + + MESA_TRACE_FUNC(); + + _mesa_clear_shader_program_data(ctx, prog); + + prog->data = _mesa_create_shader_program_data(); + + prog->data->LinkStatus = LINKING_SUCCESS; + + for (i = 0; i < prog->NumShaders; i++) { + if (!prog->Shaders[i]->CompileStatus) { + linker_error(prog, "linking with uncompiled/unspecialized shader"); + } + + if (!i) { + spirv = (prog->Shaders[i]->spirv_data != NULL); + } else if (spirv && !prog->Shaders[i]->spirv_data) { + /* The GL_ARB_gl_spirv spec adds a new bullet point to the list of + * reasons LinkProgram can fail: + * + * "All the shader objects attached to do not have the + * same value for the SPIR_V_BINARY_ARB state." + */ + linker_error(prog, + "not all attached shaders have the same " + "SPIR_V_BINARY_ARB state"); + } + } + prog->data->spirv = spirv; + + if (prog->data->LinkStatus) { + if (!spirv) + link_shaders(ctx, prog); + else + _mesa_spirv_link_shaders(ctx, prog); + } + + /* If LinkStatus is LINKING_SUCCESS, then reset sampler validated to true. + * Validation happens via the LinkShader call below. If LinkStatus is + * LINKING_SKIPPED, then SamplersValidated will have been restored from the + * shader cache. + */ + if (prog->data->LinkStatus == LINKING_SUCCESS) { + prog->SamplersValidated = GL_TRUE; + } + + if (prog->data->LinkStatus && !st_link_glsl_to_nir(ctx, prog)) { + prog->data->LinkStatus = LINKING_FAILURE; + } + + if (prog->data->LinkStatus != LINKING_FAILURE) + _mesa_create_program_resource_hash(prog); + + /* Return early if we are loading the shader from on-disk cache */ + if (prog->data->LinkStatus == LINKING_SKIPPED) + return; + + if (ctx->_Shader->Flags & GLSL_DUMP) { + if (!prog->data->LinkStatus) { + fprintf(stderr, "GLSL shader program %d failed to link\n", prog->Name); + } + + if (prog->data->InfoLog && prog->data->InfoLog[0] != 0) { + fprintf(stderr, "GLSL shader program %d info log:\n", prog->Name); + fprintf(stderr, "%s\n", prog->data->InfoLog); + } + } + +#ifdef ENABLE_SHADER_CACHE + if (prog->data->LinkStatus) + shader_cache_write_program_metadata(ctx, prog); +#endif +} + } /* extern "C" */ diff --git a/src/mesa/state_tracker/st_glsl_to_ir.h b/src/mesa/state_tracker/st_glsl_to_nir.h similarity index 100% rename from src/mesa/state_tracker/st_glsl_to_ir.h rename to src/mesa/state_tracker/st_glsl_to_nir.h diff --git a/src/mesa/state_tracker/st_nir.h b/src/mesa/state_tracker/st_nir.h index 3b69c52..b4598ad 100644 --- a/src/mesa/state_tracker/st_nir.h +++ b/src/mesa/state_tracker/st_nir.h @@ -48,10 +48,6 @@ char *st_finalize_nir(struct st_context *st, struct gl_program *prog, struct nir_shader *nir, bool finalize_by_driver, bool is_before_variants); -bool -st_link_nir(struct gl_context *ctx, - struct gl_shader_program *shader_program); - void st_nir_assign_vs_in_locations(struct nir_shader *nir); void st_nir_assign_varying_locations(struct st_context *st, struct nir_shader *nir); -- 2.7.4