2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2010 Marek Olšák <maraeo@gmail.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
24 #include "draw/draw_context.h"
25 #include "draw/draw_private.h"
27 #include "util/u_simple_list.h"
29 #include "r300_context.h"
31 #include "r300_emit.h"
32 #include "r300_flush.h"
34 static void r300_flush(struct pipe_context
* pipe
,
36 struct pipe_fence_handle
** fence
)
38 struct r300_context
*r300
= r300_context(pipe
);
39 struct r300_query
*query
;
40 struct r300_atom
*atom
;
41 struct pipe_framebuffer_state
*fb
;
46 /* We probably need to flush Draw, but we may have been called from
47 * within Draw. This feels kludgy, but it might be the best thing.
49 * Of course, the best thing is to kill Draw with fire. :3 */
50 if (r300
->draw
&& !r300
->draw
->flushing
) {
51 draw_flush(r300
->draw
);
55 r300_emit_query_end(r300
);
60 /* New kitchen sink, baby. */
61 foreach(atom
, &r300
->atom_list
) {
62 if (atom
->state
|| atom
->allow_null_state
) {
67 /* Unmark HWTCL state for SWTCL. */
68 if (!r300
->screen
->caps
.has_tcl
) {
69 r300
->vs_state
.dirty
= FALSE
;
70 r300
->vs_constants
.dirty
= FALSE
;
74 /* reset flushed query */
75 foreach(query
, &r300
->query_list
) {
76 query
->flushed
= TRUE
;
81 * This is a preliminary implementation of glFinish. Note that st/mesa
82 * uses a non-null fence when glFinish is called and then waits for
83 * the fence. Instead of returning the actual fence, we do the sync
86 * The ideal implementation should use something like EmitIrqLocked and
87 * WaitIrq, or better, real fences.
89 * This feature degrades performance to the level of r300c for games that
90 * use glFinish a lot, even openarena does. Ideally we wouldn't need
91 * glFinish at all if we had proper throttling in swapbuffers so that
92 * the CPU wouldn't outrun the GPU by several frames, so this is basically
93 * a temporary fix for the input lag. Once swap&sync works with DRI2,
94 * I'll be happy to remove this code.
97 if (fence
&& r300
->fb_state
.state
) {
98 fb
= r300
->fb_state
.state
;
100 for (i
= 0; i
< fb
->nr_cbufs
; i
++) {
101 if (fb
->cbufs
[i
]->texture
) {
102 r300
->rws
->buffer_wait(r300
->rws
,
103 r300_texture(fb
->cbufs
[i
]->texture
)->buffer
);
106 r300
->rws
->buffer_wait(r300
->rws
,
107 r300_texture(fb
->zsbuf
->texture
)->buffer
);
113 void r300_init_flush_functions(struct r300_context
* r300
)
115 r300
->context
.flush
= r300_flush
;