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
216
217
218
219
220
221
222
223
224
225
226
|
/*
* 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,
bool scissor_enable)
{
struct blitter_context *b = blitter->pipe_blitter;
struct ilo_state_vector *vec = &blitter->ilo->state_vector;
/* vertex states */
util_blitter_save_vertex_buffer_slot(b, vec->vb.states);
util_blitter_save_vertex_elements(b, (void *) vec->ve);
util_blitter_save_vertex_shader(b, vec->vs);
util_blitter_save_geometry_shader(b, vec->gs);
util_blitter_save_so_targets(b, vec->so.count, vec->so.states);
util_blitter_save_rasterizer(b, (void *) vec->rasterizer);
/* fragment states */
util_blitter_save_fragment_shader(b, vec->fs);
util_blitter_save_depth_stencil_alpha(b, (void *) vec->dsa);
util_blitter_save_blend(b, (void *) vec->blend);
util_blitter_save_sample_mask(b, vec->sample_mask);
util_blitter_save_stencil_ref(b, &vec->stencil_ref);
util_blitter_save_viewport(b, &vec->viewport.viewport0);
if (scissor_enable)
util_blitter_save_scissor(b, &vec->viewport.scissor0);
switch (op) {
case ILO_BLITTER_PIPE_BLIT:
case ILO_BLITTER_PIPE_COPY:
/*
* We are about to call util_blitter_blit() or
* util_blitter_copy_texture(). Note that util_blitter uses at most two
* textures.
*/
util_blitter_save_fragment_sampler_states(b,
2, (void **) vec->sampler[PIPE_SHADER_FRAGMENT].cso);
util_blitter_save_fragment_sampler_views(b,
vec->view[PIPE_SHADER_FRAGMENT].count,
vec->view[PIPE_SHADER_FRAGMENT].states);
util_blitter_save_framebuffer(b, &vec->fb.state);
/* resource_copy_region() or blit() does not honor render condition */
util_blitter_save_render_condition(b,
blitter->ilo->render_condition.query,
blitter->ilo->render_condition.condition,
blitter->ilo->render_condition.mode);
break;
case ILO_BLITTER_PIPE_CLEAR:
/*
* we are about to call util_blitter_clear_render_target() or
* util_blitter_clear_depth_stencil()
*/
util_blitter_save_framebuffer(b, &vec->fb.state);
break;
case ILO_BLITTER_PIPE_CLEAR_FB:
/* we are about to call util_blitter_clear() */
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,
info->scissor_enable);
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)
{
/* 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))
return false;
ilo_blitter_pipe_begin(blitter, ILO_BLITTER_PIPE_COPY, false);
util_blitter_copy_texture(blitter->pipe_blitter,
dst, dst_level, dst_x, dst_y, dst_z,
src, src_level, src_box);
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, false);
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, false);
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)
{
struct ilo_state_vector *vec = &blitter->ilo->state_vector;
/* TODO we should pause/resume some queries */
ilo_blitter_pipe_begin(blitter, ILO_BLITTER_PIPE_CLEAR_FB, false);
util_blitter_clear(blitter->pipe_blitter,
vec->fb.state.width, vec->fb.state.height, 1,
buffers, color, depth, stencil);
ilo_blitter_pipe_end(blitter);
return true;
}
|