c94afeddd1639273044c32314816b6c4500afd34
[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 #include "lp_debug.h"
32
33 #include "pipe/p_defines.h"
34 #include "util/u_memory.h"
35 #include "util/u_inlines.h"
36 #include "draw/draw_context.h"
37 #include "tgsi/tgsi_dump.h"
38 #include "tgsi/tgsi_scan.h"
39 #include "tgsi/tgsi_parse.h"
40
41
42 static void *
43 llvmpipe_create_gs_state(struct pipe_context *pipe,
44 const struct pipe_shader_state *templ)
45 {
46 struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
47 struct lp_geometry_shader *state;
48
49 state = CALLOC_STRUCT(lp_geometry_shader);
50 if (state == NULL )
51 goto no_state;
52
53 /* debug */
54 if (LP_DEBUG & DEBUG_TGSI) {
55 debug_printf("llvmpipe: Create geometry shader %p:\n", (void *)state);
56 tgsi_dump(templ->tokens, 0);
57 }
58
59 /* copy stream output info */
60 state->no_tokens = !templ->tokens;
61 memcpy(&state->stream_output, &templ->stream_output, sizeof state->stream_output);
62
63 state->dgs = draw_create_geometry_shader(llvmpipe->draw, templ);
64 if (state->dgs == NULL) {
65 goto no_dgs;
66 }
67
68 return state;
69
70 no_dgs:
71 FREE( state );
72 no_state:
73 return NULL;
74 }
75
76
77 static void
78 llvmpipe_bind_gs_state(struct pipe_context *pipe, void *gs)
79 {
80 struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
81
82 llvmpipe->gs = (struct lp_geometry_shader *)gs;
83
84 draw_bind_geometry_shader(llvmpipe->draw,
85 (llvmpipe->gs ? llvmpipe->gs->dgs : NULL));
86
87 llvmpipe->dirty |= LP_NEW_GS;
88 }
89
90
91 static void
92 llvmpipe_delete_gs_state(struct pipe_context *pipe, void *gs)
93 {
94 struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
95
96 struct lp_geometry_shader *state =
97 (struct lp_geometry_shader *)gs;
98
99 if (!state) {
100 return;
101 }
102
103 draw_delete_geometry_shader(llvmpipe->draw, state->dgs);
104 FREE(state);
105 }
106
107
108 void
109 llvmpipe_init_gs_funcs(struct llvmpipe_context *llvmpipe)
110 {
111 llvmpipe->pipe.create_gs_state = llvmpipe_create_gs_state;
112 llvmpipe->pipe.bind_gs_state = llvmpipe_bind_gs_state;
113 llvmpipe->pipe.delete_gs_state = llvmpipe_delete_gs_state;
114 }