17ec681f3Smrg/* 27ec681f3Smrg * Copyright © 2020 Mike Blumenkrantz 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 67ec681f3Smrg * to deal in the Software without restriction, including without limitation 77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the 97ec681f3Smrg * Software is furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice (including the next 127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 137ec681f3Smrg * Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 207ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 217ec681f3Smrg * IN THE SOFTWARE. 227ec681f3Smrg * 237ec681f3Smrg * Authors: 247ec681f3Smrg * Mike Blumenkrantz <michael.blumenkrantz@gmail.com> 257ec681f3Smrg */ 267ec681f3Smrg 277ec681f3Smrg#include "util/u_dynarray.h" 287ec681f3Smrg#include "pipe/p_state.h" 297ec681f3Smrg#include <vulkan/vulkan.h> 307ec681f3Smrg#include "util/u_rect.h" 317ec681f3Smrg 327ec681f3Smrgstruct zink_context; 337ec681f3Smrgstruct zink_resource; 347ec681f3Smrg 357ec681f3Smrgstruct zink_framebuffer_clear_data { 367ec681f3Smrg union { 377ec681f3Smrg struct { 387ec681f3Smrg union pipe_color_union color; 397ec681f3Smrg bool srgb; 407ec681f3Smrg } color; 417ec681f3Smrg struct { 427ec681f3Smrg float depth; 437ec681f3Smrg unsigned stencil; 447ec681f3Smrg uint8_t bits : 2; // PIPE_CLEAR_DEPTH, PIPE_CLEAR_STENCIL 457ec681f3Smrg } zs; 467ec681f3Smrg }; 477ec681f3Smrg struct pipe_scissor_state scissor; 487ec681f3Smrg bool has_scissor; 497ec681f3Smrg bool conditional; 507ec681f3Smrg}; 517ec681f3Smrg 527ec681f3Smrgstruct zink_framebuffer_clear { 537ec681f3Smrg struct util_dynarray clears; 547ec681f3Smrg}; 557ec681f3Smrg 567ec681f3Smrgvoid 577ec681f3Smrgzink_clear(struct pipe_context *pctx, 587ec681f3Smrg unsigned buffers, 597ec681f3Smrg const struct pipe_scissor_state *scissor_state, 607ec681f3Smrg const union pipe_color_union *pcolor, 617ec681f3Smrg double depth, unsigned stencil); 627ec681f3Smrgvoid 637ec681f3Smrgzink_clear_texture(struct pipe_context *ctx, 647ec681f3Smrg struct pipe_resource *p_res, 657ec681f3Smrg unsigned level, 667ec681f3Smrg const struct pipe_box *box, 677ec681f3Smrg const void *data); 687ec681f3Smrgvoid 697ec681f3Smrgzink_clear_buffer(struct pipe_context *pctx, 707ec681f3Smrg struct pipe_resource *pres, 717ec681f3Smrg unsigned offset, 727ec681f3Smrg unsigned size, 737ec681f3Smrg const void *clear_value, 747ec681f3Smrg int clear_value_size); 757ec681f3Smrg 767ec681f3Smrgvoid 777ec681f3Smrgzink_clear_render_target(struct pipe_context *ctx, struct pipe_surface *dst, 787ec681f3Smrg const union pipe_color_union *color, unsigned dstx, 797ec681f3Smrg unsigned dsty, unsigned width, unsigned height, 807ec681f3Smrg bool render_condition_enabled); 817ec681f3Smrg 827ec681f3Smrgvoid 837ec681f3Smrgzink_clear_depth_stencil(struct pipe_context *ctx, struct pipe_surface *dst, 847ec681f3Smrg unsigned clear_flags, double depth, unsigned stencil, 857ec681f3Smrg unsigned dstx, unsigned dsty, unsigned width, unsigned height, 867ec681f3Smrg bool render_condition_enabled); 877ec681f3Smrg 887ec681f3Smrgbool 897ec681f3Smrgzink_fb_clear_needs_explicit(struct zink_framebuffer_clear *fb_clear); 907ec681f3Smrg 917ec681f3Smrgbool 927ec681f3Smrgzink_fb_clear_first_needs_explicit(struct zink_framebuffer_clear *fb_clear); 937ec681f3Smrg 947ec681f3Smrgvoid 957ec681f3Smrgzink_clear_framebuffer(struct zink_context *ctx, unsigned clear_buffers); 967ec681f3Smrg 977ec681f3Smrgstatic inline struct zink_framebuffer_clear_data * 987ec681f3Smrgzink_fb_clear_element(struct zink_framebuffer_clear *fb_clear, int idx) 997ec681f3Smrg{ 1007ec681f3Smrg return util_dynarray_element(&fb_clear->clears, struct zink_framebuffer_clear_data, idx); 1017ec681f3Smrg} 1027ec681f3Smrg 1037ec681f3Smrgstatic inline unsigned 1047ec681f3Smrgzink_fb_clear_count(struct zink_framebuffer_clear *fb_clear) 1057ec681f3Smrg{ 1067ec681f3Smrg return fb_clear ? util_dynarray_num_elements(&fb_clear->clears, struct zink_framebuffer_clear_data) : 0; 1077ec681f3Smrg} 1087ec681f3Smrg 1097ec681f3Smrgvoid 1107ec681f3Smrgzink_fb_clear_reset(struct zink_context *ctx, unsigned idx); 1117ec681f3Smrg 1127ec681f3Smrgstatic inline bool 1137ec681f3Smrgzink_fb_clear_element_needs_explicit(struct zink_framebuffer_clear_data *clear) 1147ec681f3Smrg{ 1157ec681f3Smrg return clear->has_scissor || clear->conditional; 1167ec681f3Smrg} 1177ec681f3Smrg 1187ec681f3Smrgvoid 1197ec681f3Smrgzink_clear_apply_conditionals(struct zink_context *ctx); 1207ec681f3Smrg 1217ec681f3Smrgvoid 1227ec681f3Smrgzink_fb_clears_apply(struct zink_context *ctx, struct pipe_resource *pres); 1237ec681f3Smrg 1247ec681f3Smrgvoid 1257ec681f3Smrgzink_fb_clears_discard(struct zink_context *ctx, struct pipe_resource *pres); 1267ec681f3Smrg 1277ec681f3Smrgvoid 1287ec681f3Smrgzink_fb_clears_apply_or_discard(struct zink_context *ctx, struct pipe_resource *pres, struct u_rect region, bool discard_only); 1297ec681f3Smrg 1307ec681f3Smrgvoid 1317ec681f3Smrgzink_fb_clears_apply_region(struct zink_context *ctx, struct pipe_resource *pres, struct u_rect region); 1327ec681f3Smrg 1337ec681f3Smrgvoid 1347ec681f3Smrgzink_fb_clear_util_unpack_clear_color(struct zink_framebuffer_clear_data *clear, enum pipe_format format, union pipe_color_union *color); 135