s/Tungsten Graphics/VMware/
[mesa.git] / src / gallium / drivers / llvmpipe / lp_state_gs.c
1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
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 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.
25 *
26 **************************************************************************/
27
28 #include "lp_context.h"
29 #include "lp_state.h"
30 #include "lp_texture.h"
31
32 #include "pipe/p_defines.h"
33 #include "util/u_memory.h"
34 #include "util/u_inlines.h"
35 #include "draw/draw_context.h"
36 #include "tgsi/tgsi_dump.h"
37 #include "tgsi/tgsi_scan.h"
38 #include "tgsi/tgsi_parse.h"
39
40
41 static void *
42 llvmpipe_create_gs_state(struct pipe_context *pipe,
43 const struct pipe_shader_state *templ)
44 {
45 struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
46 struct lp_geometry_shader *state;
47
48 state = CALLOC_STRUCT(lp_geometry_shader);
49 if (state == NULL )
50 goto fail;
51
52 /* debug */
53 if (0)
54 tgsi_dump(templ->tokens, 0);
55
56 /* copy stream output info */
57 state->shader = *templ;
58 if (templ->tokens) {
59 /* copy shader tokens, the ones passed in will go away. */
60 state->shader.tokens = tgsi_dup_tokens(templ->tokens);
61 if (state->shader.tokens == NULL)
62 goto fail;
63
64 state->draw_data = draw_create_geometry_shader(llvmpipe->draw, templ);
65 if (state->draw_data == NULL)
66 goto fail;
67 }
68
69 return state;
70
71 fail:
72 if (state) {
73 FREE( (void *)state->shader.tokens );
74 FREE( state->draw_data );
75 FREE( state );
76 }
77 return NULL;
78 }
79
80
81 static void
82 llvmpipe_bind_gs_state(struct pipe_context *pipe, void *gs)
83 {
84 struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
85
86 llvmpipe->gs = (struct lp_geometry_shader *)gs;
87
88 draw_bind_geometry_shader(llvmpipe->draw,
89 (llvmpipe->gs ? llvmpipe->gs->draw_data : NULL));
90
91 llvmpipe->dirty |= LP_NEW_GS;
92 }
93
94
95 static void
96 llvmpipe_delete_gs_state(struct pipe_context *pipe, void *gs)
97 {
98 struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
99
100 struct lp_geometry_shader *state =
101 (struct lp_geometry_shader *)gs;
102
103 if (!state) {
104 return;
105 }
106
107 draw_delete_geometry_shader(llvmpipe->draw, state->draw_data);
108 FREE( (void *)state->shader.tokens );
109 FREE(state);
110 }
111
112
113 void
114 llvmpipe_init_gs_funcs(struct llvmpipe_context *llvmpipe)
115 {
116 llvmpipe->pipe.create_gs_state = llvmpipe_create_gs_state;
117 llvmpipe->pipe.bind_gs_state = llvmpipe_bind_gs_state;
118 llvmpipe->pipe.delete_gs_state = llvmpipe_delete_gs_state;
119 }