r600g: Silence uninitialized variable warning.
[mesa.git] / src / gallium / drivers / r600 / r600_context.c
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Jerome Glisse
25 * Corbin Simpson
26 */
27 #include <stdio.h>
28 #include <util/u_inlines.h>
29 #include <util/u_format.h>
30 #include <util/u_memory.h>
31 #include <util/u_blitter.h>
32 #include "r600_screen.h"
33 #include "r600_context.h"
34 #include "r600_resource.h"
35
36 static void r600_destroy_context(struct pipe_context *context)
37 {
38 struct r600_context *rctx = r600_context(context);
39
40 rctx->rasterizer = r600_context_state_decref(rctx->rasterizer);
41 rctx->poly_stipple = r600_context_state_decref(rctx->poly_stipple);
42 rctx->scissor = r600_context_state_decref(rctx->scissor);
43 rctx->clip = r600_context_state_decref(rctx->clip);
44 rctx->ps_shader = r600_context_state_decref(rctx->ps_shader);
45 rctx->vs_shader = r600_context_state_decref(rctx->vs_shader);
46 rctx->depth = r600_context_state_decref(rctx->depth);
47 rctx->stencil = r600_context_state_decref(rctx->stencil);
48 rctx->alpha = r600_context_state_decref(rctx->alpha);
49 rctx->dsa = r600_context_state_decref(rctx->dsa);
50 rctx->blend = r600_context_state_decref(rctx->blend);
51 rctx->stencil_ref = r600_context_state_decref(rctx->stencil_ref);
52 rctx->viewport = r600_context_state_decref(rctx->viewport);
53 rctx->framebuffer = r600_context_state_decref(rctx->framebuffer);
54
55 free(rctx->ps_constant);
56 free(rctx->vs_constant);
57 free(rctx->vs_resource);
58
59 radeon_ctx_fini(&rctx->ctx);
60 FREE(rctx);
61 }
62
63 void r600_flush(struct pipe_context *ctx, unsigned flags,
64 struct pipe_fence_handle **fence)
65 {
66 struct r600_context *rctx = r600_context(ctx);
67 struct r600_query *rquery = NULL;
68 static int dc = 0;
69 char dname[256];
70
71 /* suspend queries */
72 r600_queries_suspend(ctx);
73 /* FIXME dumping should be removed once shader support instructions
74 * without throwing bad code
75 */
76 if (!rctx->ctx.cdwords)
77 goto out;
78 #if 0
79 sprintf(dname, "gallium-%08d.bof", dc);
80 if (dc < 2) {
81 radeon_ctx_dump_bof(&rctx->ctx, dname);
82 R600_ERR("dumped %s\n", dname);
83 }
84 #endif
85 #if 1
86 radeon_ctx_submit(&rctx->ctx);
87 #endif
88 LIST_FOR_EACH_ENTRY(rquery, &rctx->query_list, list) {
89 rquery->flushed = true;
90 }
91 dc++;
92 out:
93 radeon_ctx_clear(&rctx->ctx);
94 /* resume queries */
95 r600_queries_resume(ctx);
96 }
97
98 struct pipe_context *r600_create_context(struct pipe_screen *screen, void *priv)
99 {
100 struct r600_context *rctx = CALLOC_STRUCT(r600_context);
101 struct r600_screen* rscreen = r600_screen(screen);
102
103 if (rctx == NULL)
104 return NULL;
105 rctx->context.winsys = rscreen->screen.winsys;
106 rctx->context.screen = screen;
107 rctx->context.priv = priv;
108 rctx->context.destroy = r600_destroy_context;
109 rctx->context.draw_vbo = r600_draw_vbo;
110 rctx->context.flush = r600_flush;
111
112 /* Easy accessing of screen/winsys. */
113 rctx->screen = rscreen;
114 rctx->rw = rscreen->rw;
115
116 if (rscreen->chip_class == EVERGREEN)
117 rctx->vtbl = &eg_hw_state_vtbl;
118 else
119 rctx->vtbl = &r600_hw_state_vtbl;
120
121 r600_init_blit_functions(rctx);
122 r600_init_query_functions(rctx);
123 r600_init_state_functions(rctx);
124 r600_init_context_resource_functions(rctx);
125
126 rctx->blitter = util_blitter_create(&rctx->context);
127 if (rctx->blitter == NULL) {
128 FREE(rctx);
129 return NULL;
130 }
131
132 rctx->vtbl->init_config(rctx);
133
134 rctx->vs_constant = (struct radeon_state *)calloc(R600_MAX_CONSTANT, sizeof(struct radeon_state));
135 if (!rctx->vs_constant) {
136 FREE(rctx);
137 return NULL;
138 }
139
140 rctx->ps_constant = (struct radeon_state *)calloc(R600_MAX_CONSTANT, sizeof(struct radeon_state));
141 if (!rctx->ps_constant) {
142 FREE(rctx);
143 return NULL;
144 }
145
146 rctx->vs_resource = (struct radeon_state *)calloc(R600_MAX_RESOURCE, sizeof(struct radeon_state));
147 if (!rctx->vs_resource) {
148 FREE(rctx);
149 return NULL;
150 }
151
152 radeon_ctx_init(&rctx->ctx, rscreen->rw);
153 radeon_draw_init(&rctx->draw, rscreen->rw);
154 return &rctx->context;
155 }