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.
23 #include <util/u_surface.h>
24 #include <util/u_blitter.h>
25 #include "r600_pipe.h"
27 static void r600_blitter_save_states(struct pipe_context
*ctx
)
29 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
31 util_blitter_save_blend(rctx
->blitter
, rctx
->states
[R600_PIPE_STATE_BLEND
]);
32 util_blitter_save_depth_stencil_alpha(rctx
->blitter
, rctx
->states
[R600_PIPE_STATE_DSA
]);
33 if (rctx
->states
[R600_PIPE_STATE_STENCIL_REF
]) {
34 util_blitter_save_stencil_ref(rctx
->blitter
, &rctx
->stencil_ref
);
36 util_blitter_save_rasterizer(rctx
->blitter
, rctx
->states
[R600_PIPE_STATE_RASTERIZER
]);
37 util_blitter_save_fragment_shader(rctx
->blitter
, rctx
->ps_shader
);
38 util_blitter_save_vertex_shader(rctx
->blitter
, rctx
->vs_shader
);
39 util_blitter_save_vertex_elements(rctx
->blitter
, rctx
->vertex_elements
);
40 if (rctx
->states
[R600_PIPE_STATE_VIEWPORT
]) {
41 util_blitter_save_viewport(rctx
->blitter
, &rctx
->viewport
);
43 if (rctx
->states
[R600_PIPE_STATE_CLIP
]) {
44 util_blitter_save_clip(rctx
->blitter
, &rctx
->clip
);
46 util_blitter_save_vertex_buffers(rctx
->blitter
, rctx
->nvertex_buffer
, rctx
->vertex_buffer
);
48 rctx
->vertex_elements
= NULL
;
53 int r600_blit_uncompress_depth2(struct pipe_context
*ctx
, struct r600_resource_texture
*texture
)
55 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
56 struct pipe_framebuffer_state fb
= *rctx
->pframebuffer
;
57 struct pipe_surface
*zsurf
, *cbsurf
;
61 r600_context_queries_suspend(&rctx
->ctx
);
62 for (int i
= 0; i
< fb
.nr_cbufs
; i
++) {
64 pipe_surface_reference(&fb
.cbufs
[i
], rctx
->pframebuffer
->cbufs
[i
]);
67 pipe_surface_reference(&fb
.zsbuf
, rctx
->pframebuffer
->zsbuf
);
69 zsurf
= ctx
->screen
->get_tex_surface(ctx
->screen
, &texture
->resource
.base
.b
, 0, level
, 0,
70 PIPE_BIND_DEPTH_STENCIL
);
72 cbsurf
= ctx
->screen
->get_tex_surface(ctx
->screen
,
73 (struct pipe_resource
*)texture
->flushed_depth_texture
,
74 0, level
, 0, PIPE_BIND_RENDER_TARGET
);
76 r600_blitter_save_states(ctx
);
77 util_blitter_save_framebuffer(rctx
->blitter
, &fb
);
79 if (rctx
->family
== CHIP_RV610
|| rctx
->family
== CHIP_RV630
||
80 rctx
->family
== CHIP_RV620
|| rctx
->family
== CHIP_RV635
)
83 util_blitter_custom_depth_stencil(rctx
->blitter
, zsurf
, cbsurf
, rctx
->custom_dsa_flush
, depth
);
85 pipe_surface_reference(&zsurf
, NULL
);
86 pipe_surface_reference(&cbsurf
, NULL
);
87 for (int i
= 0; i
< fb
.nr_cbufs
; i
++) {
88 pipe_surface_reference(&fb
.cbufs
[i
], NULL
);
90 pipe_surface_reference(&fb
.zsbuf
, NULL
);
91 r600_context_queries_resume(&rctx
->ctx
);
96 static void r600_clear(struct pipe_context
*ctx
, unsigned buffers
,
97 const float *rgba
, double depth
, unsigned stencil
)
99 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
100 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
;
102 r600_context_queries_suspend(&rctx
->ctx
);
103 r600_blitter_save_states(ctx
);
104 util_blitter_clear(rctx
->blitter
, fb
->width
, fb
->height
,
105 fb
->nr_cbufs
, buffers
, rgba
, depth
,
107 r600_context_queries_resume(&rctx
->ctx
);
110 static void r600_clear_render_target(struct pipe_context
*ctx
,
111 struct pipe_surface
*dst
,
113 unsigned dstx
, unsigned dsty
,
114 unsigned width
, unsigned height
)
116 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
117 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
;
119 r600_context_queries_suspend(&rctx
->ctx
);
120 util_blitter_save_framebuffer(rctx
->blitter
, fb
);
121 util_blitter_clear_render_target(rctx
->blitter
, dst
, rgba
,
122 dstx
, dsty
, width
, height
);
123 r600_context_queries_resume(&rctx
->ctx
);
126 static void r600_clear_depth_stencil(struct pipe_context
*ctx
,
127 struct pipe_surface
*dst
,
128 unsigned clear_flags
,
131 unsigned dstx
, unsigned dsty
,
132 unsigned width
, unsigned height
)
134 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
135 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
;
137 r600_context_queries_suspend(&rctx
->ctx
);
138 util_blitter_save_framebuffer(rctx
->blitter
, fb
);
139 util_blitter_clear_depth_stencil(rctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
140 dstx
, dsty
, width
, height
);
141 r600_context_queries_resume(&rctx
->ctx
);
145 static void r600_resource_copy_region(struct pipe_context
*ctx
,
146 struct pipe_resource
*dst
,
147 struct pipe_subresource subdst
,
148 unsigned dstx
, unsigned dsty
, unsigned dstz
,
149 struct pipe_resource
*src
,
150 struct pipe_subresource subsrc
,
151 unsigned srcx
, unsigned srcy
, unsigned srcz
,
152 unsigned width
, unsigned height
)
154 util_resource_copy_region(ctx
, dst
, subdst
, dstx
, dsty
, dstz
,
155 src
, subsrc
, srcx
, srcy
, srcz
, width
, height
);
158 void r600_init_blit_functions2(struct r600_pipe_context
*rctx
)
160 rctx
->context
.clear
= r600_clear
;
161 rctx
->context
.clear_render_target
= r600_clear_render_target
;
162 rctx
->context
.clear_depth_stencil
= r600_clear_depth_stencil
;
163 rctx
->context
.resource_copy_region
= r600_resource_copy_region
;