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_upload_mgr.h>
32 #include <util/u_blitter.h>
33 #include "r600_screen.h"
34 #include "r600_context.h"
35 #include "r600_resource.h"
37 static void r600_destroy_context(struct pipe_context
*context
)
39 struct r600_context
*rctx
= r600_context(context
);
41 rctx
->rasterizer
= r600_context_state_decref(rctx
->rasterizer
);
42 rctx
->poly_stipple
= r600_context_state_decref(rctx
->poly_stipple
);
43 rctx
->scissor
= r600_context_state_decref(rctx
->scissor
);
44 rctx
->clip
= r600_context_state_decref(rctx
->clip
);
45 rctx
->ps_shader
= r600_context_state_decref(rctx
->ps_shader
);
46 rctx
->vs_shader
= r600_context_state_decref(rctx
->vs_shader
);
47 rctx
->depth
= r600_context_state_decref(rctx
->depth
);
48 rctx
->stencil
= r600_context_state_decref(rctx
->stencil
);
49 rctx
->alpha
= r600_context_state_decref(rctx
->alpha
);
50 rctx
->dsa
= r600_context_state_decref(rctx
->dsa
);
51 rctx
->blend
= r600_context_state_decref(rctx
->blend
);
52 rctx
->stencil_ref
= r600_context_state_decref(rctx
->stencil_ref
);
53 rctx
->viewport
= r600_context_state_decref(rctx
->viewport
);
54 rctx
->framebuffer
= r600_context_state_decref(rctx
->framebuffer
);
56 free(rctx
->ps_constant
);
57 free(rctx
->vs_constant
);
58 free(rctx
->vs_resource
);
60 u_upload_destroy(rctx
->upload_vb
);
61 u_upload_destroy(rctx
->upload_ib
);
63 radeon_ctx_fini(rctx
->ctx
);
67 void r600_flush(struct pipe_context
*ctx
, unsigned flags
,
68 struct pipe_fence_handle
**fence
)
70 struct r600_context
*rctx
= r600_context(ctx
);
71 struct r600_query
*rquery
= NULL
;
77 /* flush upload buffers */
78 u_upload_flush(rctx
->upload_vb
);
79 u_upload_flush(rctx
->upload_ib
);
82 r600_queries_suspend(ctx
);
86 sprintf(dname
, "gallium-%08d.bof", dc
);
88 radeon_ctx_dump_bof(rctx
->ctx
, dname
);
89 R600_ERR("dumped %s\n", dname
);
94 radeon_ctx_submit(rctx
->ctx
);
96 LIST_FOR_EACH_ENTRY(rquery
, &rctx
->query_list
, list
) {
97 rquery
->flushed
= TRUE
;
100 radeon_ctx_clear(rctx
->ctx
);
102 r600_queries_resume(ctx
);
105 struct pipe_context
*r600_create_context(struct pipe_screen
*screen
, void *priv
)
107 struct r600_context
*rctx
= CALLOC_STRUCT(r600_context
);
108 struct r600_screen
* rscreen
= r600_screen(screen
);
112 rctx
->context
.winsys
= rscreen
->screen
.winsys
;
113 rctx
->context
.screen
= screen
;
114 rctx
->context
.priv
= priv
;
115 rctx
->context
.destroy
= r600_destroy_context
;
116 rctx
->context
.draw_vbo
= r600_draw_vbo
;
117 rctx
->context
.flush
= r600_flush
;
119 /* Easy accessing of screen/winsys. */
120 rctx
->screen
= rscreen
;
121 rctx
->rw
= rscreen
->rw
;
123 if (radeon_get_family_class(rscreen
->rw
) == EVERGREEN
)
124 rctx
->vtbl
= &eg_hw_state_vtbl
;
126 rctx
->vtbl
= &r600_hw_state_vtbl
;
128 r600_init_blit_functions(rctx
);
129 r600_init_query_functions(rctx
);
130 r600_init_state_functions(rctx
);
131 r600_init_context_resource_functions(rctx
);
133 rctx
->blitter
= util_blitter_create(&rctx
->context
);
134 if (rctx
->blitter
== NULL
) {
139 rctx
->vtbl
->init_config(rctx
);
141 rctx
->upload_ib
= u_upload_create(&rctx
->context
, 32 * 1024, 16,
142 PIPE_BIND_INDEX_BUFFER
);
143 if (rctx
->upload_ib
== NULL
) {
147 rctx
->upload_vb
= u_upload_create(&rctx
->context
, 128 * 1024, 16,
148 PIPE_BIND_VERTEX_BUFFER
);
149 if (rctx
->upload_vb
== NULL
) {
153 rctx
->vs_constant
= (struct radeon_state
*)calloc(R600_MAX_CONSTANT
, sizeof(struct radeon_state
));
154 if (!rctx
->vs_constant
) {
158 rctx
->ps_constant
= (struct radeon_state
*)calloc(R600_MAX_CONSTANT
, sizeof(struct radeon_state
));
159 if (!rctx
->ps_constant
) {
163 rctx
->vs_resource
= (struct radeon_state
*)calloc(R600_MAX_RESOURCE
, sizeof(struct radeon_state
));
164 if (!rctx
->vs_resource
) {
168 rctx
->ctx
= radeon_ctx_init(rscreen
->rw
);
169 radeon_draw_init(&rctx
->draw
, rscreen
->rw
);
170 return &rctx
->context
;