2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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:
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
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.
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"
36 static void r600_destroy_context(struct pipe_context
*context
)
38 struct r600_context
*rctx
= r600_context(context
);
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
);
55 free(rctx
->ps_constant
);
56 free(rctx
->vs_constant
);
57 free(rctx
->vs_resource
);
59 radeon_ctx_fini(&rctx
->ctx
);
63 void r600_flush(struct pipe_context
*ctx
, unsigned flags
,
64 struct pipe_fence_handle
**fence
)
66 struct r600_context
*rctx
= r600_context(ctx
);
67 struct r600_query
*rquery
= NULL
;
72 r600_queries_suspend(ctx
);
73 /* FIXME dumping should be removed once shader support instructions
74 * without throwing bad code
76 if (!rctx
->ctx
.cdwords
)
79 sprintf(dname
, "gallium-%08d.bof", dc
);
81 radeon_ctx_dump_bof(&rctx
->ctx
, dname
);
82 R600_ERR("dumped %s\n", dname
);
86 radeon_ctx_submit(&rctx
->ctx
);
88 LIST_FOR_EACH_ENTRY(rquery
, &rctx
->query_list
, list
) {
89 rquery
->flushed
= true;
93 radeon_ctx_clear(&rctx
->ctx
);
95 r600_queries_resume(ctx
);
98 struct pipe_context
*r600_create_context(struct pipe_screen
*screen
, void *priv
)
100 struct r600_context
*rctx
= CALLOC_STRUCT(r600_context
);
101 struct r600_screen
* rscreen
= r600_screen(screen
);
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
;
112 /* Easy accessing of screen/winsys. */
113 rctx
->screen
= rscreen
;
114 rctx
->rw
= rscreen
->rw
;
116 if (rscreen
->chip_class
== EVERGREEN
)
117 rctx
->vtbl
= &eg_hw_state_vtbl
;
119 rctx
->vtbl
= &r600_hw_state_vtbl
;
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
);
126 rctx
->blitter
= util_blitter_create(&rctx
->context
);
127 if (rctx
->blitter
== NULL
) {
132 rctx
->vtbl
->init_config(rctx
);
134 rctx
->vs_constant
= (struct radeon_state
*)calloc(R600_MAX_CONSTANT
, sizeof(struct radeon_state
));
135 if (!rctx
->vs_constant
) {
140 rctx
->ps_constant
= (struct radeon_state
*)calloc(R600_MAX_CONSTANT
, sizeof(struct radeon_state
));
141 if (!rctx
->ps_constant
) {
146 rctx
->vs_resource
= (struct radeon_state
*)calloc(R600_MAX_RESOURCE
, sizeof(struct radeon_state
));
147 if (!rctx
->vs_resource
) {
152 radeon_ctx_init(&rctx
->ctx
, rscreen
->rw
);
153 radeon_draw_init(&rctx
->draw
, rscreen
->rw
);
154 return &rctx
->context
;