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
;
73 /* flush upload buffers */
74 u_upload_flush(rctx
->upload_vb
);
75 u_upload_flush(rctx
->upload_ib
);
78 r600_queries_suspend(ctx
);
80 radeon_ctx_submit(rctx
->ctx
);
82 LIST_FOR_EACH_ENTRY(rquery
, &rctx
->query_list
, list
) {
83 rquery
->flushed
= TRUE
;
86 radeon_ctx_clear(rctx
->ctx
);
88 r600_queries_resume(ctx
);
91 void r600_flush_ctx(void *data
)
93 struct r600_context
*rctx
= data
;
95 rctx
->context
.flush(&rctx
->context
, 0, NULL
);
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
->upload_ib
= u_upload_create(&rctx
->context
, 32 * 1024, 16,
135 PIPE_BIND_INDEX_BUFFER
);
136 if (rctx
->upload_ib
== NULL
) {
140 rctx
->upload_vb
= u_upload_create(&rctx
->context
, 128 * 1024, 16,
141 PIPE_BIND_VERTEX_BUFFER
);
142 if (rctx
->upload_vb
== NULL
) {
146 rctx
->vs_constant
= (struct radeon_state
*)calloc(R600_MAX_CONSTANT
, sizeof(struct radeon_state
));
147 if (!rctx
->vs_constant
) {
151 rctx
->ps_constant
= (struct radeon_state
*)calloc(R600_MAX_CONSTANT
, sizeof(struct radeon_state
));
152 if (!rctx
->ps_constant
) {
156 rctx
->vs_resource
= (struct radeon_state
*)calloc(R600_MAX_RESOURCE
, sizeof(struct radeon_state
));
157 if (!rctx
->vs_resource
) {
161 rctx
->ctx
= radeon_ctx_init(rscreen
->rw
);
162 radeon_draw_init(&rctx
->draw
, rscreen
->rw
);
163 return &rctx
->context
;