1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Keith Whitwell <keithw@vmware.com>
33 #include "main/glheader.h"
34 #include "main/macros.h"
35 #include "main/enums.h"
36 #include "main/shaderapi.h"
37 #include "program/prog_instruction.h"
38 #include "program/program.h"
40 #include "cso_cache/cso_context.h"
41 #include "draw/draw_context.h"
43 #include "st_context.h"
45 #include "st_program.h"
46 #include "st_mesa_to_tgsi.h"
47 #include "st_cb_program.h"
48 #include "st_glsl_to_ir.h"
49 #include "st_atifs_to_tgsi.h"
54 * Called via ctx->Driver.NewProgram() to allocate a new vertex or
57 static struct gl_program
*
58 st_new_program(struct gl_context
*ctx
, GLenum target
, GLuint id
,
62 case GL_VERTEX_PROGRAM_ARB
: {
63 struct st_vertex_program
*prog
= rzalloc(NULL
, struct st_vertex_program
);
64 return _mesa_init_gl_program(&prog
->Base
.Base
, target
, id
, is_arb_asm
);
66 case GL_TESS_CONTROL_PROGRAM_NV
:
67 case GL_TESS_EVALUATION_PROGRAM_NV
:
68 case GL_GEOMETRY_PROGRAM_NV
:
69 case GL_FRAGMENT_PROGRAM_ARB
:
70 case GL_COMPUTE_PROGRAM_NV
: {
71 struct st_program
*prog
= rzalloc(NULL
, struct st_program
);
72 return _mesa_init_gl_program(&prog
->Base
, target
, id
, is_arb_asm
);
82 * Called via ctx->Driver.DeleteProgram()
85 st_delete_program(struct gl_context
*ctx
, struct gl_program
*prog
)
87 struct st_context
*st
= st_context(ctx
);
88 struct st_program
*stp
= st_program(prog
);
90 st_release_variants(st
, stp
);
92 if (stp
->glsl_to_tgsi
)
93 free_glsl_to_tgsi_visitor(stp
->glsl_to_tgsi
);
95 free(stp
->serialized_nir
);
97 /* delete base class */
98 _mesa_delete_program( ctx
, prog
);
102 * Called via ctx->Driver.ProgramStringNotify()
103 * Called when the program's text/code is changed. We have to free
104 * all shader variants and corresponding gallium shaders when this happens.
107 st_program_string_notify( struct gl_context
*ctx
,
109 struct gl_program
*prog
)
111 struct st_context
*st
= st_context(ctx
);
112 struct st_program
*stp
= (struct st_program
*) prog
;
114 /* GLSL-to-NIR should not end up here. */
115 assert(!stp
->shader_program
);
117 st_release_variants(st
, stp
);
119 if (target
== GL_FRAGMENT_PROGRAM_ARB
||
120 target
== GL_FRAGMENT_SHADER_ATI
) {
121 if (target
== GL_FRAGMENT_SHADER_ATI
) {
123 assert(stp
->ati_fs
->Program
== prog
);
125 st_init_atifs_prog(ctx
, prog
);
128 if (!st_translate_fragment_program(st
, stp
))
130 } else if (target
== GL_VERTEX_PROGRAM_ARB
) {
131 if (!st_translate_vertex_program(st
, stp
))
134 if (!st_translate_common_program(st
, stp
))
138 st_finalize_program(st
, prog
);
143 * Called via ctx->Driver.NewATIfs()
144 * Called in glEndFragmentShaderATI()
146 static struct gl_program
*
147 st_new_ati_fs(struct gl_context
*ctx
, struct ati_fragment_shader
*curProg
)
149 struct gl_program
*prog
= ctx
->Driver
.NewProgram(ctx
, GL_FRAGMENT_PROGRAM_ARB
,
151 struct st_program
*stfp
= (struct st_program
*)prog
;
152 stfp
->ati_fs
= curProg
;
157 st_max_shader_compiler_threads(struct gl_context
*ctx
, unsigned count
)
159 struct pipe_screen
*screen
= st_context(ctx
)->pipe
->screen
;
161 if (screen
->set_max_shader_compiler_threads
)
162 screen
->set_max_shader_compiler_threads(screen
, count
);
166 st_get_shader_program_completion_status(struct gl_context
*ctx
,
167 struct gl_shader_program
*shprog
)
169 struct pipe_screen
*screen
= st_context(ctx
)->pipe
->screen
;
171 if (!screen
->is_parallel_shader_compilation_finished
)
174 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
175 struct gl_linked_shader
*linked
= shprog
->_LinkedShaders
[i
];
178 if (!linked
|| !linked
->Program
)
181 if (st_program(linked
->Program
)->variants
)
182 sh
= st_program(linked
->Program
)->variants
->driver_shader
;
184 unsigned type
= pipe_shader_type_from_mesa(i
);
187 !screen
->is_parallel_shader_compilation_finished(screen
, sh
, type
))
194 * Plug in the program and shader-related device driver functions.
197 st_init_program_functions(struct dd_function_table
*functions
)
199 functions
->NewProgram
= st_new_program
;
200 functions
->DeleteProgram
= st_delete_program
;
201 functions
->ProgramStringNotify
= st_program_string_notify
;
202 functions
->NewATIfs
= st_new_ati_fs
;
203 functions
->LinkShader
= st_link_shader
;
204 functions
->SetMaxShaderCompilerThreads
= st_max_shader_compiler_threads
;
205 functions
->GetShaderProgramCompletionStatus
=
206 st_get_shader_program_completion_status
;