1 /*
2 * Copyright © 2020 Mike Blumenkrantz
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Mike Blumenkrantz <[email protected]>
25 */
26
27 #include "util/u_rect.h"
28 #include "zink_types.h"
29 #include "zink_screen.h"
30
31 void
32 zink_clear(struct pipe_context *pctx,
33 unsigned buffers,
34 const struct pipe_scissor_state *scissor_state,
35 const union pipe_color_union *pcolor,
36 double depth, unsigned stencil);
37 void
38 zink_clear_texture(struct pipe_context *ctx,
39 struct pipe_resource *p_res,
40 unsigned level,
41 const struct pipe_box *box,
42 const void *data);
43 void
44 zink_clear_texture_dynamic(struct pipe_context *ctx,
45 struct pipe_resource *p_res,
46 unsigned level,
47 const struct pipe_box *box,
48 const void *data);
49 void
50 zink_clear_buffer(struct pipe_context *pctx,
51 struct pipe_resource *pres,
52 unsigned offset,
53 unsigned size,
54 const void *clear_value,
55 int clear_value_size);
56
57 void
58 zink_clear_render_target(struct pipe_context *ctx, struct pipe_surface *dst,
59 const union pipe_color_union *color, unsigned dstx,
60 unsigned dsty, unsigned width, unsigned height,
61 bool render_condition_enabled);
62
63 void
64 zink_clear_depth_stencil(struct pipe_context *ctx, struct pipe_surface *dst,
65 unsigned clear_flags, double depth, unsigned stencil,
66 unsigned dstx, unsigned dsty, unsigned width, unsigned height,
67 bool render_condition_enabled);
68
69 bool
70 zink_fb_clear_needs_explicit(struct zink_framebuffer_clear *fb_clear);
71
72 bool
73 zink_fb_clear_first_needs_explicit(struct zink_framebuffer_clear *fb_clear);
74
75 void
76 zink_clear_framebuffer(struct zink_context *ctx, unsigned clear_buffers);
77
78 static inline struct zink_framebuffer_clear_data *
zink_fb_clear_element(struct zink_framebuffer_clear * fb_clear,int idx)79 zink_fb_clear_element(struct zink_framebuffer_clear *fb_clear, int idx)
80 {
81 return util_dynarray_element(&fb_clear->clears, struct zink_framebuffer_clear_data, idx);
82 }
83
84 static inline unsigned
zink_fb_clear_count(struct zink_framebuffer_clear * fb_clear)85 zink_fb_clear_count(struct zink_framebuffer_clear *fb_clear)
86 {
87 return fb_clear ? util_dynarray_num_elements(&fb_clear->clears, struct zink_framebuffer_clear_data) : 0;
88 }
89
90 void
91 zink_fb_clear_reset(struct zink_context *ctx, unsigned idx);
92
93 static inline bool
zink_fb_clear_element_needs_explicit(struct zink_framebuffer_clear_data * clear)94 zink_fb_clear_element_needs_explicit(struct zink_framebuffer_clear_data *clear)
95 {
96 return clear->has_scissor || clear->conditional;
97 }
98
99 static inline bool
zink_fb_clear_full_exists(struct zink_context * ctx,unsigned clear_buffer)100 zink_fb_clear_full_exists(struct zink_context *ctx, unsigned clear_buffer)
101 {
102 struct zink_framebuffer_clear *fb_clear = &ctx->fb_clears[clear_buffer];
103 return zink_fb_clear_count(fb_clear) && !zink_fb_clear_first_needs_explicit(fb_clear);
104 }
105
106 void
107 zink_clear_apply_conditionals(struct zink_context *ctx);
108
109 void
110 zink_fb_clears_apply(struct zink_context *ctx, struct pipe_resource *pres);
111
112 void
113 zink_fb_clears_discard(struct zink_context *ctx, struct pipe_resource *pres);
114
115 void
116 zink_fb_clears_apply_or_discard(struct zink_context *ctx, struct pipe_resource *pres, struct u_rect region, bool discard_only);
117
118 void
119 zink_fb_clears_apply_region(struct zink_context *ctx, struct pipe_resource *pres, struct u_rect region);
120
121 void
122 zink_fb_clear_rewrite(struct zink_context *ctx, unsigned idx, enum pipe_format before, enum pipe_format after);
123