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 <michael.blumenkrantz@gmail.com>
25 */
26
27 #include "util/u_dynarray.h"
28 #include "pipe/p_state.h"
29 #include <vulkan/vulkan.h>
30 #include "util/u_rect.h"
31
32 struct zink_context;
33 struct zink_resource;
34
35 struct zink_framebuffer_clear_data {
36 union {
37 union pipe_color_union color;
38 struct {
39 float depth;
40 unsigned stencil;
41 uint8_t bits : 2; // PIPE_CLEAR_DEPTH, PIPE_CLEAR_STENCIL
42 } zs;
43 };
44 struct pipe_scissor_state scissor;
45 bool has_scissor;
46 bool conditional;
47 };
48
49 struct zink_framebuffer_clear {
50 struct util_dynarray clears;
51 };
52
53 void
54 zink_clear(struct pipe_context *pctx,
55 unsigned buffers,
56 const struct pipe_scissor_state *scissor_state,
57 const union pipe_color_union *pcolor,
58 double depth, unsigned stencil);
59 void
60 zink_clear_texture(struct pipe_context *ctx,
61 struct pipe_resource *p_res,
62 unsigned level,
63 const struct pipe_box *box,
64 const void *data);
65 void
66 zink_clear_buffer(struct pipe_context *pctx,
67 struct pipe_resource *pres,
68 unsigned offset,
69 unsigned size,
70 const void *clear_value,
71 int clear_value_size);
72
73 void
74 zink_clear_render_target(struct pipe_context *ctx, struct pipe_surface *dst,
75 const union pipe_color_union *color, unsigned dstx,
76 unsigned dsty, unsigned width, unsigned height,
77 bool render_condition_enabled);
78
79 void
80 zink_clear_depth_stencil(struct pipe_context *ctx, struct pipe_surface *dst,
81 unsigned clear_flags, double depth, unsigned stencil,
82 unsigned dstx, unsigned dsty, unsigned width, unsigned height,
83 bool render_condition_enabled);
84
85 bool
86 zink_fb_clear_needs_explicit(struct zink_framebuffer_clear *fb_clear);
87
88 bool
89 zink_fb_clear_first_needs_explicit(struct zink_framebuffer_clear *fb_clear);
90
91 void
92 zink_clear_framebuffer(struct zink_context *ctx, unsigned clear_buffers);
93
94 static inline struct zink_framebuffer_clear_data *
zink_fb_clear_element(struct zink_framebuffer_clear * fb_clear,int idx)95 zink_fb_clear_element(struct zink_framebuffer_clear *fb_clear, int idx)
96 {
97 return util_dynarray_element(&fb_clear->clears, struct zink_framebuffer_clear_data, idx);
98 }
99
100 static inline unsigned
zink_fb_clear_count(struct zink_framebuffer_clear * fb_clear)101 zink_fb_clear_count(struct zink_framebuffer_clear *fb_clear)
102 {
103 return fb_clear ? util_dynarray_num_elements(&fb_clear->clears, struct zink_framebuffer_clear_data) : 0;
104 }
105
106 void
107 zink_fb_clear_reset(struct zink_context *ctx, unsigned idx);
108
109 static inline bool
zink_fb_clear_element_needs_explicit(struct zink_framebuffer_clear_data * clear)110 zink_fb_clear_element_needs_explicit(struct zink_framebuffer_clear_data *clear)
111 {
112 return clear->has_scissor || clear->conditional;
113 }
114
115 void
116 zink_clear_apply_conditionals(struct zink_context *ctx);
117
118 void
119 zink_fb_clears_apply(struct zink_context *ctx, struct pipe_resource *pres);
120
121 void
122 zink_fb_clears_discard(struct zink_context *ctx, struct pipe_resource *pres);
123
124 void
125 zink_fb_clears_apply_or_discard(struct zink_context *ctx, struct pipe_resource *pres, struct u_rect region, bool discard_only);
126
127 void
128 zink_fb_clears_apply_region(struct zink_context *ctx, struct pipe_resource *pres, struct u_rect region);
129