2 * Copyright 2009 Marek Olšák <maraeo@gmail.com>
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.
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"
35 static void r600_blitter_save_states(struct pipe_context
*ctx
)
37 struct r600_context
*rctx
= r600_context(ctx
);
39 util_blitter_save_blend(rctx
->blitter
, rctx
->blend
);
40 util_blitter_save_depth_stencil_alpha(rctx
->blitter
, rctx
->dsa
);
41 if (rctx
->stencil_ref
) {
42 util_blitter_save_stencil_ref(rctx
->blitter
,
43 &rctx
->stencil_ref
->state
.stencil_ref
);
45 util_blitter_save_rasterizer(rctx
->blitter
, rctx
->rasterizer
);
46 util_blitter_save_fragment_shader(rctx
->blitter
, rctx
->ps_shader
);
47 util_blitter_save_vertex_shader(rctx
->blitter
, rctx
->vs_shader
);
48 util_blitter_save_vertex_elements(rctx
->blitter
, rctx
->vertex_elements
);
50 util_blitter_save_viewport(rctx
->blitter
, &rctx
->viewport
->state
.viewport
);
53 util_blitter_save_clip(rctx
->blitter
, &rctx
->clip
->state
.clip
);
55 util_blitter_save_vertex_buffers(rctx
->blitter
, rctx
->nvertex_buffer
,
58 /* remove ptr so they don't get deleted */
61 rctx
->vs_shader
= NULL
;
62 rctx
->ps_shader
= NULL
;
63 rctx
->rasterizer
= NULL
;
65 rctx
->vertex_elements
= NULL
;
68 r600_queries_suspend(ctx
);
71 static void r600_clear(struct pipe_context
*ctx
, unsigned buffers
,
72 const float *rgba
, double depth
, unsigned stencil
)
74 struct r600_context
*rctx
= r600_context(ctx
);
75 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
->state
.framebuffer
;
77 r600_blitter_save_states(ctx
);
78 util_blitter_clear(rctx
->blitter
, fb
->width
, fb
->height
,
79 fb
->nr_cbufs
, buffers
, rgba
, depth
,
82 r600_queries_resume(ctx
);
85 static void r600_clear_render_target(struct pipe_context
*ctx
,
86 struct pipe_surface
*dst
,
88 unsigned dstx
, unsigned dsty
,
89 unsigned width
, unsigned height
)
91 struct r600_context
*rctx
= r600_context(ctx
);
92 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
->state
.framebuffer
;
94 r600_blitter_save_states(ctx
);
95 util_blitter_save_framebuffer(rctx
->blitter
, fb
);
97 util_blitter_clear_render_target(rctx
->blitter
, dst
, rgba
,
98 dstx
, dsty
, width
, height
);
100 r600_queries_resume(ctx
);
103 static void r600_clear_depth_stencil(struct pipe_context
*ctx
,
104 struct pipe_surface
*dst
,
105 unsigned clear_flags
,
108 unsigned dstx
, unsigned dsty
,
109 unsigned width
, unsigned height
)
111 struct r600_context
*rctx
= r600_context(ctx
);
112 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
->state
.framebuffer
;
114 r600_blitter_save_states(ctx
);
115 util_blitter_save_framebuffer(rctx
->blitter
, fb
);
117 util_blitter_clear_depth_stencil(rctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
118 dstx
, dsty
, width
, height
);
120 r600_queries_resume(ctx
);
124 static void r600_resource_copy_region(struct pipe_context
*ctx
,
125 struct pipe_resource
*dst
,
126 struct pipe_subresource subdst
,
127 unsigned dstx
, unsigned dsty
, unsigned dstz
,
128 struct pipe_resource
*src
,
129 struct pipe_subresource subsrc
,
130 unsigned srcx
, unsigned srcy
, unsigned srcz
,
131 unsigned width
, unsigned height
)
133 struct r600_context
*rctx
= r600_context(ctx
);
134 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
->state
.framebuffer
;
135 struct pipe_sampler_state
*samplers
[PIPE_MAX_ATTRIBS
];
136 struct pipe_sampler_view_state
*sampler_views
[PIPE_MAX_ATTRIBS
];
139 for (i
= 0; i
< rctx
->ps_nsampler_view
; i
++) {
140 sampler_views
[i
] = &rctx
->ps_sampler_view
[i
]->state
.sampler_view
;
142 for (i
= 0; i
< rctx
->ps_nsampler
; i
++) {
143 samplers
[i
] = &rctx
->ps_sampler
[i
]->state
.sampler
;
145 r600_blitter_save_states(ctx
);
146 util_blitter_save_framebuffer(rctx
->blitter
, fb
);
147 util_blitter_save_fragment_sampler_states(rctx
->blitter
, rctx
->ps_nsampler
, samplers
);
148 util_blitter_save_fragment_sampler_views(rctx
->blitter
, rctx
->ps_nsampler_view
, sampler_views
);
150 util_blitter_copy_region(rctx
->blitter
, dst
, subdst
, dstx
, dsty
, dstz
,
151 src
, subsrc
, srcx
, srcy
, srcz
, width
, height
,
154 r600_queries_resume(ctx
);
157 void r600_init_blit_functions(struct r600_context
*rctx
)
159 rctx
->context
.clear
= r600_clear
;
160 rctx
->context
.clear_render_target
= r600_clear_render_target
;
161 rctx
->context
.clear_depth_stencil
= r600_clear_depth_stencil
;
162 rctx
->context
.resource_copy_region
= r600_resource_copy_region
;