i915g: Reduce state emission by using a index bias
[mesa.git] / src / gallium / drivers / r600 / r600_blit.c
1 /*
2 * Copyright 2009 Marek Olšák <maraeo@gmail.com>
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 * Marek Olšák
26 */
27 #include <pipe/p_screen.h>
28 #include <util/u_blitter.h>
29 #include <util/u_inlines.h>
30 #include <util/u_memory.h>
31 #include "util/u_surface.h"
32 #include "r600_screen.h"
33 #include "r600_context.h"
34
35 static void r600_blitter_save_states(struct r600_context *rctx)
36 {
37 util_blitter_save_blend(rctx->blitter,
38 rctx->draw->state[R600_BLEND]);
39 util_blitter_save_depth_stencil_alpha(rctx->blitter,
40 rctx->draw->state[R600_DSA]);
41 util_blitter_save_stencil_ref(rctx->blitter, &rctx->stencil_ref);
42 util_blitter_save_rasterizer(rctx->blitter,
43 rctx->draw->state[R600_RASTERIZER]);
44 util_blitter_save_fragment_shader(rctx->blitter,
45 rctx->ps_shader);
46 util_blitter_save_vertex_shader(rctx->blitter,
47 rctx->vs_shader);
48 util_blitter_save_vertex_elements(rctx->blitter,
49 rctx->vertex_elements);
50 util_blitter_save_viewport(rctx->blitter,
51 &rctx->viewport);
52 /* XXX util_blitter_save_clip(rctx->blitter, &rctx->clip); */
53 util_blitter_save_vertex_buffers(rctx->blitter, rctx->nvertex_buffer,
54 rctx->vertex_buffer);
55 }
56
57 static void r600_clear(struct pipe_context *ctx, unsigned buffers,
58 const float *rgba, double depth, unsigned stencil)
59 {
60 struct r600_context *rctx = r600_context(ctx);
61 struct pipe_framebuffer_state *fb = &rctx->fb_state;
62
63 r600_blitter_save_states(rctx);
64 util_blitter_clear(rctx->blitter, fb->width, fb->height,
65 fb->nr_cbufs, buffers, rgba, depth,
66 stencil);
67 }
68
69 static void r600_clear_render_target(struct pipe_context *pipe,
70 struct pipe_surface *dst,
71 const float *rgba,
72 unsigned dstx, unsigned dsty,
73 unsigned width, unsigned height)
74 {
75 struct r600_context *rctx = r600_context(pipe);
76
77 r600_blitter_save_states(rctx);
78 util_blitter_save_framebuffer(rctx->blitter, &rctx->fb_state);
79
80 util_blitter_clear_render_target(rctx->blitter, dst, rgba,
81 dstx, dsty, width, height);
82 }
83
84 static void r600_clear_depth_stencil(struct pipe_context *pipe,
85 struct pipe_surface *dst,
86 unsigned clear_flags,
87 double depth,
88 unsigned stencil,
89 unsigned dstx, unsigned dsty,
90 unsigned width, unsigned height)
91 {
92 struct r600_context *rctx = r600_context(pipe);
93
94 r600_blitter_save_states(rctx);
95 util_blitter_save_framebuffer(rctx->blitter, &rctx->fb_state);
96
97 util_blitter_clear_depth_stencil(rctx->blitter, dst, clear_flags, depth, stencil,
98 dstx, dsty, width, height);
99 }
100
101 static void r600_resource_copy_region(struct pipe_context *pipe,
102 struct pipe_resource *dst,
103 struct pipe_subresource subdst,
104 unsigned dstx, unsigned dsty, unsigned dstz,
105 struct pipe_resource *src,
106 struct pipe_subresource subsrc,
107 unsigned srcx, unsigned srcy, unsigned srcz,
108 unsigned width, unsigned height)
109 {
110 util_resource_copy_region(pipe, dst, subdst, dstx, dsty, dstz,
111 src, subsrc, srcx, srcy, srcz, width, height);
112 }
113
114 void r600_init_blit_functions(struct r600_context *rctx)
115 {
116 rctx->context.clear = r600_clear;
117 rctx->context.clear_render_target = r600_clear_render_target;
118 rctx->context.clear_depth_stencil = r600_clear_depth_stencil;
119 rctx->context.resource_copy_region = r600_resource_copy_region;
120 }