mesa/st: move program calls to direct call

Can't move NewProgram yet as the GLSL standalone compiler relies
on it, can probably fix that up later.

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14100>
This commit is contained in:
Dave Airlie 2021-12-07 14:46:02 +10:00 committed by Marge Bot
parent 878cf8cae9
commit f60add48ee
13 changed files with 54 additions and 88 deletions

View File

@ -43,6 +43,8 @@
#include "program/program.h"
#include "program/prog_print.h"
#include "state_tracker/st_cb_program.h"
static void
flush_vertices_for_program_constants(struct gl_context *ctx, GLenum target)
{
@ -408,7 +410,7 @@ set_program_string(struct gl_program *prog, GLenum target, GLenum format, GLsize
if (!failed) {
/* finally, give the program to the driver for translation/checking */
if (!ctx->Driver.ProgramStringNotify(ctx, target, prog)) {
if (!st_program_string_notify(ctx, target, prog)) {
failed = true;
_mesa_error(ctx, GL_INVALID_OPERATION,
"glProgramStringARB(rejected by driver");

View File

@ -33,6 +33,8 @@
#include "program/prog_instruction.h"
#include "util/u_memory.h"
#include "state_tracker/st_cb_program.h"
#define MESA_DEBUG_ATI_FS 0
static struct ati_fragment_shader DummyShader;
@ -412,17 +414,15 @@ _mesa_EndFragmentShaderATI(void)
}
#endif
if (ctx->Driver.NewATIfs) {
struct gl_program *prog = ctx->Driver.NewATIfs(ctx,
ctx->ATIFragmentShader.Current);
_mesa_reference_program(ctx, &ctx->ATIFragmentShader.Current->Program,
NULL);
/* Don't use _mesa_reference_program(), just take ownership */
ctx->ATIFragmentShader.Current->Program = prog;
}
struct gl_program *prog = st_new_ati_fs(ctx,
ctx->ATIFragmentShader.Current);
_mesa_reference_program(ctx, &ctx->ATIFragmentShader.Current->Program,
NULL);
/* Don't use _mesa_reference_program(), just take ownership */
ctx->ATIFragmentShader.Current->Program = prog;
if (!ctx->Driver.ProgramStringNotify(ctx, GL_FRAGMENT_SHADER_ATI,
curProg->Program)) {
if (!st_program_string_notify(ctx, GL_FRAGMENT_SHADER_ATI,
curProg->Program)) {
ctx->ATIFragmentShader.Current->isValid = GL_FALSE;
/* XXX is this the right error? */
_mesa_error(ctx, GL_INVALID_OPERATION,

View File

@ -119,43 +119,10 @@ struct dd_function_table {
/**
* \name Vertex/fragment program functions
*/
/*@{*/
/** Allocate a new program */
struct gl_program * (*NewProgram)(struct gl_context *ctx,
gl_shader_stage stage,
GLuint id, bool is_arb_asm);
/** Delete a program */
void (*DeleteProgram)(struct gl_context *ctx, struct gl_program *prog);
/**
* Allocate a program to associate with the new ATI fragment shader (optional)
*/
struct gl_program * (*NewATIfs)(struct gl_context *ctx,
struct ati_fragment_shader *curProg);
/**
* Notify driver that a program string (and GPU code) has been specified
* or modified. Return GL_TRUE or GL_FALSE to indicate if the program is
* supported by the driver.
*/
GLboolean (*ProgramStringNotify)(struct gl_context *ctx, GLenum target,
struct gl_program *prog);
/*@}*/
/**
* \name GLSL shader/program functions.
*/
/*@{*/
/**
* Called when a shader program is linked.
*
* This gives drivers an opportunity to clone the IR and make their
* own transformations on it for the purposes of code generation.
*/
GLboolean (*LinkShader)(struct gl_context *ctx,
struct gl_shader_program *shader);
/*@}*/
/**
* \name Draw functions.
*/
@ -542,13 +509,6 @@ struct dd_function_table {
struct gl_program *prog);
/*@}*/
/**
* \name Set the number of compiler threads for ARB_parallel_shader_compile
*/
void (*SetMaxShaderCompilerThreads)(struct gl_context *ctx, unsigned count);
bool (*GetShaderProgramCompletionStatus)(struct gl_context *ctx,
struct gl_shader_program *shprog);
void (*PinDriverToL3Cache)(struct gl_context *ctx, unsigned L3_cache);
GLboolean (*ValidateEGLImage)(struct gl_context *ctx, GLeglImageOES image_handle);

View File

@ -47,6 +47,7 @@
#include "program/prog_statevars.h"
#include "util/bitscan.h"
#include "state_tracker/st_cb_program.h"
/** Max of number of lights and texture coord units */
#define NUM_UNITS MAX2(MAX_TEXTURE_COORD_UNITS, MAX_LIGHTS)
@ -1729,8 +1730,7 @@ _mesa_get_fixed_func_vertex_program(struct gl_context *ctx)
ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].OptimizeForAOS,
ctx->Const.Program[MESA_SHADER_VERTEX].MaxTemps );
if (ctx->Driver.ProgramStringNotify)
ctx->Driver.ProgramStringNotify(ctx, GL_VERTEX_PROGRAM_ARB, prog);
st_program_string_notify(ctx, GL_VERTEX_PROGRAM_ARB, prog);
_mesa_program_cache_insert(ctx, ctx->VertexProgram.Cache, &key,
sizeof(key), prog);

View File

@ -33,6 +33,8 @@
#include "util/u_atomic.h"
#include "state_tracker/st_cb_program.h"
void
_mesa_spirv_module_reference(struct gl_spirv_module **dest,
struct gl_spirv_module *src)

View File

@ -30,7 +30,7 @@
#include "hint.h"
#include "mtypes.h"
#include "state_tracker/st_cb_program.h"
void GLAPIENTRY
@ -138,8 +138,7 @@ _mesa_MaxShaderCompilerThreadsKHR(GLuint count)
ctx->Hint.MaxShaderCompilerThreads = count;
if (ctx->Driver.SetMaxShaderCompilerThreads)
ctx->Driver.SetMaxShaderCompilerThreads(ctx, count);
st_max_shader_compiler_threads(ctx, count);
}
/**********************************************************************/

View File

@ -66,6 +66,8 @@
#include "util/u_process.h"
#include "util/u_string.h"
#include "state_tracker/st_cb_program.h"
#ifdef ENABLE_SHADER_CACHE
#if CUSTOM_SHADER_REPLACEMENT
#include "shader_replacement.h"
@ -751,10 +753,7 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname,
*params = shProg->DeletePending;
return;
case GL_COMPLETION_STATUS_ARB:
if (ctx->Driver.GetShaderProgramCompletionStatus)
*params = ctx->Driver.GetShaderProgramCompletionStatus(ctx, shProg);
else
*params = GL_TRUE;
*params = st_get_shader_program_completion_status(ctx, shProg);
return;
case GL_LINK_STATUS:
*params = shProg->data->LinkStatus ? GL_TRUE : GL_FALSE;

View File

@ -48,6 +48,7 @@
#include "state_tracker/st_cb_memoryobjects.h"
#include "state_tracker/st_cb_semaphoreobjects.h"
#include "state_tracker/st_cb_texture.h"
#include "state_tracker/st_cb_program.h"
static void
free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared);
@ -195,7 +196,7 @@ delete_program_cb(void *data, void *userData)
if(prog != &_mesa_DummyProgram) {
assert(prog->RefCount == 1); /* should only be referenced by hash table */
prog->RefCount = 0; /* now going away */
ctx->Driver.DeleteProgram(ctx, prog);
st_delete_program(ctx, prog);
}
}

View File

@ -32,6 +32,7 @@
#include "compiler/glsl/program.h"
#include "compiler/glsl/shader_cache.h"
#include "state_tracker/st_glsl_to_ir.h"
extern "C" {
@ -87,7 +88,7 @@ _mesa_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
prog->SamplersValidated = GL_TRUE;
}
if (prog->data->LinkStatus && !ctx->Driver.LinkShader(ctx, prog)) {
if (prog->data->LinkStatus && !st_link_shader(ctx, prog)) {
prog->data->LinkStatus = LINKING_FAILURE;
}

View File

@ -44,6 +44,7 @@
#include "util/ralloc.h"
#include "util/u_atomic.h"
#include "state_tracker/st_cb_program.h"
/**
* A pointer to this dummy program is put into the hash table when
@ -242,8 +243,6 @@ _mesa_new_program(struct gl_context *ctx, gl_shader_stage stage, GLuint id,
/**
* Delete a program and remove it from the hash table, ignoring the
* reference count.
* Called via ctx->Driver.DeleteProgram. May be wrapped (OO deriviation)
* by a device driver function.
*/
void
_mesa_delete_program(struct gl_context *ctx, struct gl_program *prog)
@ -326,7 +325,7 @@ _mesa_reference_program_(struct gl_context *ctx,
if (p_atomic_dec_zero(&oldProg->RefCount)) {
assert(ctx);
_mesa_reference_shader_program_data(ctx, &oldProg->sh.data, NULL);
ctx->Driver.DeleteProgram(ctx, oldProg);
st_delete_program(ctx, oldProg);
}
*ptr = NULL;

View File

@ -72,10 +72,7 @@ st_new_program(struct gl_context *ctx, gl_shader_stage stage, GLuint id,
}
/**
* Called via ctx->Driver.DeleteProgram()
*/
static void
void
st_delete_program(struct gl_context *ctx, struct gl_program *prog)
{
struct st_context *st = st_context(ctx);
@ -93,14 +90,13 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog)
}
/**
* Called via ctx->Driver.ProgramStringNotify()
* Called when the program's text/code is changed. We have to free
* all shader variants and corresponding gallium shaders when this happens.
*/
static GLboolean
GLboolean
st_program_string_notify( struct gl_context *ctx,
GLenum target,
struct gl_program *prog )
GLenum target,
struct gl_program *prog )
{
struct st_context *st = st_context(ctx);
struct st_program *stp = (struct st_program *) prog;
@ -134,20 +130,19 @@ st_program_string_notify( struct gl_context *ctx,
}
/**
* Called via ctx->Driver.NewATIfs()
* Called in glEndFragmentShaderATI()
*/
static struct gl_program *
struct gl_program *
st_new_ati_fs(struct gl_context *ctx, struct ati_fragment_shader *curProg)
{
struct gl_program *prog = ctx->Driver.NewProgram(ctx, MESA_SHADER_FRAGMENT,
struct gl_program *prog = st_new_program(ctx, MESA_SHADER_FRAGMENT,
curProg->Id, true);
struct st_program *stfp = (struct st_program *)prog;
stfp->ati_fs = curProg;
return prog;
}
static void
void
st_max_shader_compiler_threads(struct gl_context *ctx, unsigned count)
{
struct pipe_screen *screen = st_context(ctx)->screen;
@ -156,7 +151,7 @@ st_max_shader_compiler_threads(struct gl_context *ctx, unsigned count)
screen->set_max_shader_compiler_threads(screen, count);
}
static bool
bool
st_get_shader_program_completion_status(struct gl_context *ctx,
struct gl_shader_program *shprog)
{
@ -191,11 +186,4 @@ void
st_init_program_functions(struct dd_function_table *functions)
{
functions->NewProgram = st_new_program;
functions->DeleteProgram = st_delete_program;
functions->ProgramStringNotify = st_program_string_notify;
functions->NewATIfs = st_new_ati_fs;
functions->LinkShader = st_link_shader;
functions->SetMaxShaderCompilerThreads = st_max_shader_compiler_threads;
functions->GetShaderProgramCompletionStatus =
st_get_shader_program_completion_status;
}

View File

@ -28,11 +28,25 @@
#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);
void st_delete_program(struct gl_context *ctx, struct gl_program *prog);
GLboolean st_program_string_notify(struct gl_context *ctx,
GLenum target,
struct gl_program *prog);
struct gl_program *st_new_ati_fs(struct gl_context *ctx, struct ati_fragment_shader *curProg);
void st_max_shader_compiler_threads(struct gl_context *ctx, unsigned count);
bool st_get_shader_program_completion_status(struct gl_context *ctx,
struct gl_shader_program *shprog);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -31,6 +31,7 @@
*/
#include "st_glsl_to_tgsi.h"
#include "st_cb_program.h"
#include "compiler/glsl/glsl_parser_extras.h"
#include "compiler/glsl/ir_optimization.h"
@ -7519,9 +7520,9 @@ st_link_tgsi(struct gl_context *ctx, struct gl_shader_program *prog)
(linked_prog->sh.LinkedTransformFeedback &&
linked_prog->sh.LinkedTransformFeedback->NumVarying);
if (!ctx->Driver.ProgramStringNotify(ctx,
_mesa_shader_stage_to_program(i),
linked_prog)) {
if (!st_program_string_notify(ctx,
_mesa_shader_stage_to_program(i),
linked_prog)) {
_mesa_reference_program(ctx, &shader->Program, NULL);
return GL_FALSE;
}