u_upload_mgr: pass alignment to u_upload_alloc manually
[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 "util/u_inlines.h"
27 #include "util/u_math.h"
28 #include "util/u_memory.h"
29 #include "util/u_bitmask.h"
30 #include "tgsi/tgsi_parse.h"
31 #include "draw/draw_context.h"
32
33 #include "svga_context.h"
34 #include "svga_hw_reg.h"
35 #include "svga_cmd.h"
36 #include "svga_debug.h"
37 #include "svga_shader.h"
38
39
40 static void *
41 svga_create_fs_state(struct pipe_context *pipe,
42 const struct pipe_shader_state *templ)
43 {
44 struct svga_context *svga = svga_context(pipe);
45 struct svga_fragment_shader *fs;
46
47 fs = CALLOC_STRUCT(svga_fragment_shader);
48 if (!fs)
49 return NULL;
50
51 fs->base.tokens = tgsi_dup_tokens(templ->tokens);
52
53 /* Collect basic info that we'll need later:
54 */
55 tgsi_scan_shader(fs->base.tokens, &fs->base.info);
56
57 fs->base.id = svga->debug.shader_id++;
58
59 fs->generic_inputs = svga_get_generic_inputs_mask(&fs->base.info);
60
61 svga_remap_generics(fs->generic_inputs, fs->generic_remap_table);
62
63 fs->draw_shader = draw_create_fragment_shader(svga->swtnl.draw, templ);
64
65 return fs;
66 }
67
68
69 static void
70 svga_bind_fs_state(struct pipe_context *pipe, void *shader)
71 {
72 struct svga_fragment_shader *fs = (struct svga_fragment_shader *) shader;
73 struct svga_context *svga = svga_context(pipe);
74
75 svga->curr.fs = fs;
76 svga->dirty |= SVGA_NEW_FS;
77 }
78
79
80 static void
81 svga_delete_fs_state(struct pipe_context *pipe, void *shader)
82 {
83 struct svga_context *svga = svga_context(pipe);
84 struct svga_fragment_shader *fs = (struct svga_fragment_shader *) shader;
85 struct svga_shader_variant *variant, *tmp;
86 enum pipe_error ret;
87
88 svga_hwtnl_flush_retry(svga);
89
90 assert(fs->base.parent == NULL);
91
92 draw_delete_fragment_shader(svga->swtnl.draw, fs->draw_shader);
93
94 for (variant = fs->base.variants; variant; variant = tmp) {
95 tmp = variant->next;
96
97 /* Check if deleting currently bound shader */
98 if (variant == svga->state.hw_draw.fs) {
99 ret = svga_set_shader(svga, SVGA3D_SHADERTYPE_PS, NULL);
100 if (ret != PIPE_OK) {
101 svga_context_flush(svga, NULL);
102 ret = svga_set_shader(svga, SVGA3D_SHADERTYPE_PS, NULL);
103 assert(ret == PIPE_OK);
104 }
105 svga->state.hw_draw.fs = NULL;
106 }
107
108 ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant);
109 if (ret != PIPE_OK) {
110 svga_context_flush(svga, NULL);
111 ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant);
112 assert(ret == PIPE_OK);
113 }
114 }
115
116 FREE((void *)fs->base.tokens);
117 FREE(fs);
118 }
119
120
121 void
122 svga_init_fs_functions(struct svga_context *svga)
123 {
124 svga->pipe.create_fs_state = svga_create_fs_state;
125 svga->pipe.bind_fs_state = svga_bind_fs_state;
126 svga->pipe.delete_fs_state = svga_delete_fs_state;
127 }