1 /* 2 * Copyright (C) 2019 Collabora, Ltd. 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 FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 * 23 * Authors (Collabora): 24 * Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> 25 * 26 */ 27 28 #ifndef __PAN_BLEND_H 29 #define __PAN_BLEND_H 30 31 #include "util/hash_table.h" 32 #include "nir.h" 33 34 struct panfrost_bo; 35 36 struct panfrost_blend_shader_key { 37 /* RT format */ 38 enum pipe_format format; 39 40 /* Render target */ 41 unsigned rt : 3; 42 43 /* Blend shader uses blend constants */ 44 unsigned has_constants : 1; 45 46 /* Logic Op info */ 47 unsigned logicop_enable : 1; 48 unsigned logicop_func:4; 49 50 struct pipe_rt_blend_state equation; 51 }; 52 53 /* An internal blend shader descriptor, from the compiler */ 54 55 struct panfrost_blend_shader { 56 struct panfrost_blend_shader_key key; 57 struct panfrost_context *ctx; 58 59 nir_shader *nir; 60 61 /* Blend constants */ 62 float constants[4]; 63 64 /* The compiled shader */ 65 void *buffer; 66 67 /* Byte count of the shader */ 68 unsigned size; 69 70 /* Number of 128-bit work registers required by the shader */ 71 unsigned work_count; 72 73 /* First instruction tag (for tagging the pointer) */ 74 unsigned first_tag; 75 }; 76 77 /* A blend shader descriptor ready for actual use */ 78 79 struct panfrost_blend_shader_final { 80 /* GPU address where we're compiled to */ 81 uint64_t gpu; 82 83 /* First instruction tag (for tagging the pointer) */ 84 unsigned first_tag; 85 86 /* Same meaning as panfrost_blend_shader */ 87 unsigned work_count; 88 }; 89 90 struct panfrost_blend_equation_final { 91 struct MALI_BLEND_EQUATION equation; 92 float constant; 93 }; 94 95 struct panfrost_blend_rt { 96 /* If has_fixed_function is set, equation is the 97 * fixed-function configuration for this blend state */ 98 99 bool has_fixed_function; 100 struct MALI_BLEND_EQUATION equation; 101 102 /* Mask of blend color components read */ 103 unsigned constant_mask; 104 105 /* Properties of the blend mode */ 106 bool opaque, load_dest, no_colour; 107 }; 108 109 struct panfrost_blend_state { 110 struct pipe_blend_state base; 111 112 struct panfrost_blend_rt rt[PIPE_MAX_COLOR_BUFS]; 113 }; 114 115 /* Container for a final blend state, specialized to constants and a 116 * framebuffer formats. */ 117 118 struct panfrost_blend_final { 119 /* Set for a shader, clear for an equation */ 120 bool is_shader; 121 122 /* Set if this is the replace mode */ 123 bool opaque; 124 125 /* Set if destination is loaded */ 126 bool load_dest; 127 128 /* Set if the colour mask is 0x0 (nothing is written) */ 129 bool no_colour; 130 131 union { 132 struct panfrost_blend_shader_final shader; 133 struct panfrost_blend_equation_final equation; 134 }; 135 }; 136 137 void 138 panfrost_blend_context_init(struct pipe_context *pipe); 139 140 struct panfrost_blend_final 141 panfrost_get_blend_for_context(struct panfrost_context *ctx, unsigned rt, struct panfrost_bo **bo, unsigned *shader_offset); 142 143 struct panfrost_blend_shader * 144 panfrost_get_blend_shader(struct panfrost_context *ctx, 145 struct panfrost_blend_state *blend, 146 enum pipe_format fmt, 147 unsigned rt, 148 const float *constants); 149 150 #endif 151