u_upload_mgr: pass alignment to u_upload_alloc manually
[mesa.git] / src / gallium / drivers / svga / svga_pipe_gs.c
1 /**********************************************************
2 * Copyright 2014 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 "draw/draw_context.h"
27 #include "util/u_inlines.h"
28 #include "util/u_memory.h"
29 #include "util/u_bitmask.h"
30 #include "tgsi/tgsi_parse.h"
31 #include "tgsi/tgsi_text.h"
32
33 #include "svga_context.h"
34 #include "svga_cmd.h"
35 #include "svga_debug.h"
36 #include "svga_shader.h"
37 #include "svga_streamout.h"
38
39 static void *
40 svga_create_gs_state(struct pipe_context *pipe,
41 const struct pipe_shader_state *templ)
42 {
43 struct svga_context *svga = svga_context(pipe);
44 struct svga_geometry_shader *gs = CALLOC_STRUCT(svga_geometry_shader);
45
46 if (!gs)
47 return NULL;
48
49 gs->base.tokens = tgsi_dup_tokens(templ->tokens);
50
51 /* Collect basic info that we'll need later:
52 */
53 tgsi_scan_shader(gs->base.tokens, &gs->base.info);
54
55 gs->draw_shader = draw_create_geometry_shader(svga->swtnl.draw, templ);
56
57 gs->base.id = svga->debug.shader_id++;
58
59 gs->generic_outputs = svga_get_generic_outputs_mask(&gs->base.info);
60
61 /* check for any stream output declarations */
62 if (templ->stream_output.num_outputs) {
63 gs->base.stream_output = svga_create_stream_output(svga, &gs->base,
64 &templ->stream_output);
65 }
66
67 return gs;
68 }
69
70
71 static void
72 svga_bind_gs_state(struct pipe_context *pipe, void *shader)
73 {
74 struct svga_geometry_shader *gs = (struct svga_geometry_shader *)shader;
75 struct svga_context *svga = svga_context(pipe);
76
77 svga->curr.user_gs = gs;
78 svga->dirty |= SVGA_NEW_GS;
79 }
80
81
82 static void
83 svga_delete_gs_state(struct pipe_context *pipe, void *shader)
84 {
85 struct svga_context *svga = svga_context(pipe);
86 struct svga_geometry_shader *gs = (struct svga_geometry_shader *)shader;
87 struct svga_geometry_shader *next_gs;
88 struct svga_shader_variant *variant, *tmp;
89 enum pipe_error ret;
90
91 svga_hwtnl_flush_retry(svga);
92
93 /* Start deletion from the original geometry shader state */
94 if (gs->base.parent != NULL)
95 gs = (struct svga_geometry_shader *)gs->base.parent;
96
97 /* Free the list of geometry shaders */
98 while (gs) {
99 next_gs = (struct svga_geometry_shader *)gs->base.next;
100
101 if (gs->base.stream_output != NULL)
102 svga_delete_stream_output(svga, gs->base.stream_output);
103
104 draw_delete_geometry_shader(svga->swtnl.draw, gs->draw_shader);
105
106 for (variant = gs->base.variants; variant; variant = tmp) {
107 tmp = variant->next;
108
109 /* Check if deleting currently bound shader */
110 if (variant == svga->state.hw_draw.gs) {
111 ret = svga_set_shader(svga, SVGA3D_SHADERTYPE_GS, NULL);
112 if (ret != PIPE_OK) {
113 svga_context_flush(svga, NULL);
114 ret = svga_set_shader(svga, SVGA3D_SHADERTYPE_GS, NULL);
115 assert(ret == PIPE_OK);
116 }
117 svga->state.hw_draw.gs = NULL;
118 }
119
120 ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_GS, variant);
121 if (ret != PIPE_OK) {
122 svga_context_flush(svga, NULL);
123 ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_GS,
124 variant);
125 assert(ret == PIPE_OK);
126 }
127 }
128
129 FREE((void *)gs->base.tokens);
130 FREE(gs);
131 gs = next_gs;
132 }
133 }
134
135
136 void
137 svga_init_gs_functions(struct svga_context *svga)
138 {
139 svga->pipe.create_gs_state = svga_create_gs_state;
140 svga->pipe.bind_gs_state = svga_bind_gs_state;
141 svga->pipe.delete_gs_state = svga_delete_gs_state;
142 }