1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
/*
* Mesa 3-D graphics library
*
* Copyright (C) 2013 LunarG, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Authors:
* Chia-I Wu <olv@lunarg.com>
*/
#include "util/u_blitter.h"
#include "util/u_surface.h"
#include "ilo_context.h"
#include "ilo_blitter.h"
enum ilo_blitter_pipe_op {
ILO_BLITTER_PIPE_BLIT,
ILO_BLITTER_PIPE_COPY,
ILO_BLITTER_PIPE_CLEAR,
ILO_BLITTER_PIPE_CLEAR_FB,
};
static void
ilo_blitter_pipe_begin(struct ilo_blitter *blitter,
enum ilo_blitter_pipe_op op)
{
struct blitter_context *b = blitter->pipe_blitter;
struct ilo_context *ilo = blitter->ilo;
/* as documented in util/u_blitter.h */
util_blitter_save_vertex_buffer_slot(b, ilo->vb.states);
util_blitter_save_vertex_elements(b, (void *) ilo->ve);
util_blitter_save_vertex_shader(b, ilo->vs);
util_blitter_save_geometry_shader(b, ilo->gs);
util_blitter_save_so_targets(b, ilo->so.count, ilo->so.states);
util_blitter_save_fragment_shader(b, ilo->fs);
util_blitter_save_depth_stencil_alpha(b, (void *) ilo->dsa);
util_blitter_save_blend(b, (void *) ilo->blend);
/* undocumented? */
util_blitter_save_viewport(b, &ilo->viewport.viewport0);
util_blitter_save_stencil_ref(b, &ilo->stencil_ref);
util_blitter_save_sample_mask(b, ilo->sample_mask);
switch (op) {
case ILO_BLITTER_PIPE_BLIT:
case ILO_BLITTER_PIPE_COPY:
util_blitter_save_rasterizer(b, (void *) ilo->rasterizer);
util_blitter_save_framebuffer(b, &ilo->fb.state);
util_blitter_save_fragment_sampler_states(b,
ilo->sampler[PIPE_SHADER_FRAGMENT].count,
(void **) ilo->sampler[PIPE_SHADER_FRAGMENT].cso);
util_blitter_save_fragment_sampler_views(b,
ilo->view[PIPE_SHADER_FRAGMENT].count,
ilo->view[PIPE_SHADER_FRAGMENT].states);
/* disable render condition? */
break;
case ILO_BLITTER_PIPE_CLEAR:
util_blitter_save_rasterizer(b, (void *) ilo->rasterizer);
util_blitter_save_framebuffer(b, &ilo->fb.state);
/* disable render condition? */
break;
case ILO_BLITTER_PIPE_CLEAR_FB:
util_blitter_save_rasterizer(b, (void *) ilo->rasterizer);
break;
default:
break;
}
}
static void
ilo_blitter_pipe_end(struct ilo_blitter *blitter)
{
}
bool
ilo_blitter_pipe_blit(struct ilo_blitter *blitter,
const struct pipe_blit_info *info)
{
struct blitter_context *b = blitter->pipe_blitter;
struct pipe_blit_info skip_stencil;
if (util_try_blit_via_copy_region(&blitter->ilo->base, info))
return true;
if (!util_blitter_is_blit_supported(b, info)) {
/* try without stencil */
if (info->mask & PIPE_MASK_S) {
skip_stencil = *info;
skip_stencil.mask = info->mask & ~PIPE_MASK_S;
if (util_blitter_is_blit_supported(blitter->pipe_blitter,
&skip_stencil)) {
ilo_warn("ignore stencil buffer blitting\n");
info = &skip_stencil;
}
}
if (info != &skip_stencil) {
ilo_warn("failed to blit with pipe blitter\n");
return false;
}
}
ilo_blitter_pipe_begin(blitter, ILO_BLITTER_PIPE_BLIT);
util_blitter_blit(b, info);
ilo_blitter_pipe_end(blitter);
return true;
}
bool
ilo_blitter_pipe_copy_resource(struct ilo_blitter *blitter,
struct pipe_resource *dst, unsigned dst_level,
unsigned dst_x, unsigned dst_y, unsigned dst_z,
struct pipe_resource *src, unsigned src_level,
const struct pipe_box *src_box)
{
const unsigned mask = PIPE_MASK_RGBAZS;
const bool copy_all_samples = true;
/* not until we allow rendertargets to be buffers */
if (dst->target == PIPE_BUFFER || src->target == PIPE_BUFFER)
return false;
if (!util_blitter_is_copy_supported(blitter->pipe_blitter, dst, src, mask))
return false;
ilo_blitter_pipe_begin(blitter, ILO_BLITTER_PIPE_COPY);
util_blitter_copy_texture(blitter->pipe_blitter,
dst, dst_level, dst_x, dst_y, dst_z,
src, src_level, src_box,
mask, copy_all_samples);
ilo_blitter_pipe_end(blitter);
return true;
}
bool
ilo_blitter_pipe_clear_rt(struct ilo_blitter *blitter,
struct pipe_surface *rt,
const union pipe_color_union *color,
unsigned x, unsigned y,
unsigned width, unsigned height)
{
ilo_blitter_pipe_begin(blitter, ILO_BLITTER_PIPE_CLEAR);
util_blitter_clear_render_target(blitter->pipe_blitter,
rt, color, x, y, width, height);
ilo_blitter_pipe_end(blitter);
return true;
}
bool
ilo_blitter_pipe_clear_zs(struct ilo_blitter *blitter,
struct pipe_surface *zs,
unsigned clear_flags,
double depth, unsigned stencil,
unsigned x, unsigned y,
unsigned width, unsigned height)
{
ilo_blitter_pipe_begin(blitter, ILO_BLITTER_PIPE_CLEAR);
util_blitter_clear_depth_stencil(blitter->pipe_blitter,
zs, clear_flags, depth, stencil, x, y, width, height);
ilo_blitter_pipe_end(blitter);
return true;
}
bool
ilo_blitter_pipe_clear_fb(struct ilo_blitter *blitter,
unsigned buffers,
const union pipe_color_union *color,
double depth, unsigned stencil)
{
/* TODO we should pause/resume some queries */
ilo_blitter_pipe_begin(blitter, ILO_BLITTER_PIPE_CLEAR_FB);
util_blitter_clear(blitter->pipe_blitter,
blitter->ilo->fb.state.width, blitter->ilo->fb.state.height,
buffers, color, depth, stencil);
ilo_blitter_pipe_end(blitter);
return true;
}
|