st/glsl: merge st_glsl_to_ir.cpp with st_glsl_to_nir.cpp
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 <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22846>
This commit is contained in:
committed by
Marge Bot
parent
c6fe8b7cba
commit
5c1d91d5da
@@ -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
|
||||
|
||||
@@ -169,7 +169,7 @@
|
||||
#include <mesa/state_tracker/st_extensions.h>
|
||||
#include <mesa/state_tracker/st_format.h>
|
||||
#include <mesa/state_tracker/st_gen_mipmap.h>
|
||||
#include <mesa/state_tracker/st_glsl_to_ir.h>
|
||||
#include <mesa/state_tracker/st_glsl_to_nir.h>
|
||||
#include <mesa/state_tracker/st_manager.h>
|
||||
#include <mesa/state_tracker/st_nir.h>
|
||||
#include <mesa/state_tracker/st_pbo.h>
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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 <program> 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" */
|
||||
@@ -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 <program> 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" */
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user