Merge branch 'mesa_7_6_branch' into mesa_7_7_branch
[mesa.git] / src / gallium / drivers / svga / svga_pipe_fs.c
1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26 #include "pipe/p_inlines.h"
27 #include "util/u_math.h"
28 #include "util/u_memory.h"
29 #include "tgsi/tgsi_parse.h"
30 #include "tgsi/tgsi_text.h"
31
32 #include "svga_screen.h"
33 #include "svga_context.h"
34 #include "svga_state.h"
35 #include "svga_tgsi.h"
36 #include "svga_hw_reg.h"
37 #include "svga_cmd.h"
38 #include "svga_draw.h"
39 #include "svga_debug.h"
40
41
42 /***********************************************************************
43 * Fragment shaders
44 */
45
46 static void *
47 svga_create_fs_state(struct pipe_context *pipe,
48 const struct pipe_shader_state *templ)
49 {
50 struct svga_context *svga = svga_context(pipe);
51 struct svga_screen *svgascreen = svga_screen(pipe->screen);
52 struct svga_fragment_shader *fs;
53
54 fs = CALLOC_STRUCT(svga_fragment_shader);
55 if (!fs)
56 return NULL;
57
58 fs->base.tokens = tgsi_dup_tokens(templ->tokens);
59
60 /* Collect basic info that we'll need later:
61 */
62 tgsi_scan_shader(fs->base.tokens, &fs->base.info);
63
64 fs->base.id = svga->debug.shader_id++;
65 fs->base.use_sm30 = svgascreen->use_ps30;
66
67 if (SVGA_DEBUG & DEBUG_TGSI || 0) {
68 debug_printf("%s id: %u, inputs: %u, outputs: %u\n",
69 __FUNCTION__, fs->base.id,
70 fs->base.info.num_inputs, fs->base.info.num_outputs);
71 }
72
73 return fs;
74 }
75
76 static void
77 svga_bind_fs_state(struct pipe_context *pipe, void *shader)
78 {
79 struct svga_fragment_shader *fs = (struct svga_fragment_shader *) shader;
80 struct svga_context *svga = svga_context(pipe);
81
82 svga->curr.fs = fs;
83 svga->dirty |= SVGA_NEW_FS;
84 }
85
86 static
87 void svga_delete_fs_state(struct pipe_context *pipe, void *shader)
88 {
89 struct svga_context *svga = svga_context(pipe);
90 struct svga_fragment_shader *fs = (struct svga_fragment_shader *) shader;
91 struct svga_shader_result *result, *tmp;
92 enum pipe_error ret;
93
94 svga_hwtnl_flush_retry( svga );
95
96 for (result = fs->base.results; result; result = tmp ) {
97 tmp = result->next;
98
99 ret = SVGA3D_DestroyShader(svga->swc,
100 result->id,
101 SVGA3D_SHADERTYPE_PS );
102 if(ret != PIPE_OK) {
103 svga_context_flush(svga, NULL);
104 ret = SVGA3D_DestroyShader(svga->swc,
105 result->id,
106 SVGA3D_SHADERTYPE_PS );
107 assert(ret == PIPE_OK);
108 }
109
110 svga_destroy_shader_result( result );
111 }
112
113 FREE((void *)fs->base.tokens);
114 FREE(fs);
115 }
116
117
118 void svga_init_fs_functions( struct svga_context *svga )
119 {
120 svga->pipe.create_fs_state = svga_create_fs_state;
121 svga->pipe.bind_fs_state = svga_bind_fs_state;
122 svga->pipe.delete_fs_state = svga_delete_fs_state;
123 }
124