checkpoint in constant tracking rework
[mesa.git] / src / mesa / state_tracker / st_atom_fs.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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 TUNGSTEN GRAPHICS 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.
25 *
26 **************************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32 #include "shader/prog_parameter.h"
33
34 #include "pipe/p_context.h"
35 #include "pipe/p_defines.h"
36 #include "pipe/p_winsys.h"
37 #include "pipe/tgsi/mesa/mesa_to_tgsi.h"
38 #include "pipe/tgsi/exec/tgsi_dump.h"
39
40 #include "st_context.h"
41 #include "st_atom.h"
42 #include "st_program.h"
43
44 #define TGSI_DEBUG 0
45
46 static void compile_fs( struct st_context *st )
47 {
48 struct st_fragment_program *fp = st->fp;
49
50 /* XXX: fix static allocation of tokens:
51 */
52 tgsi_mesa_compile_fp_program( &fp->Base, fp->tokens, ST_FP_MAX_TOKENS );
53
54 fp->fs.inputs_read
55 = tgsi_mesa_translate_vertex_input_mask(fp->Base.Base.InputsRead);
56 fp->fs.outputs_written
57 = tgsi_mesa_translate_vertex_output_mask(fp->Base.Base.OutputsWritten);
58 fp->fs.tokens = &fp->tokens[0];
59
60 if (TGSI_DEBUG)
61 tgsi_dump( fp->tokens, TGSI_DUMP_VERBOSE );
62
63 fp->dirty = 0;
64 }
65
66
67
68 static void update_fs( struct st_context *st )
69 {
70 struct st_fragment_program *fp = NULL;
71
72 /* find active shader and params. Changes to this Mesa state
73 * should be covered by ST_NEW_FRAGMENT_PROGRAM, thanks to the
74 * logic in st_cb_program.c
75 */
76 if (st->ctx->Shader.CurrentProgram &&
77 st->ctx->Shader.CurrentProgram->LinkStatus &&
78 st->ctx->Shader.CurrentProgram->FragmentProgram) {
79 struct gl_fragment_program *f
80 = st->ctx->Shader.CurrentProgram->FragmentProgram;
81 fp = st_fragment_program(f);
82 }
83 else {
84 assert(st->ctx->FragmentProgram._Current);
85 fp = st_fragment_program(st->ctx->FragmentProgram._Current);
86 }
87
88 /* translate shader to TGSI format */
89 if (st->fp != fp || fp->dirty) {
90 st->fp = fp;
91
92 if (fp->dirty)
93 compile_fs( st );
94
95 st->state.fs = fp->fs;
96 st->pipe->set_fs_state(st->pipe, &st->state.fs);
97 }
98 }
99
100
101 const struct st_tracked_state st_update_fs = {
102 .dirty = {
103 .mesa = 0,
104 .st = ST_NEW_FRAGMENT_PROGRAM,
105 },
106 .update = update_fs
107 };