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