panfrost: Honour load_dest/opaque flags
[mesa.git] / src / gallium / drivers / panfrost / pan_blend.h
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
33 /* An internal blend shader descriptor, from the compiler */
34
35 struct panfrost_blend_shader {
36 struct panfrost_context *ctx;
37
38 /* The compiled shader */
39 void *buffer;
40
41 /* Byte count of the shader */
42 unsigned size;
43
44 /* Number of 128-bit work registers required by the shader */
45 unsigned work_count;
46
47 /* Offset into the shader to patch constants. Zero to disable patching
48 * (it is illogical to have constants at offset 0). */
49 unsigned patch_index;
50
51 /* First instruction tag (for tagging the pointer) */
52 unsigned first_tag;
53 };
54
55 /* A blend shader descriptor ready for actual use */
56
57 struct panfrost_blend_shader_final {
58 /* GPU address where we're compiled to */
59 uint64_t gpu;
60
61 /* First instruction tag (for tagging the pointer) */
62 unsigned first_tag;
63
64 /* Same meaning as panfrost_blend_shader */
65 unsigned work_count;
66 };
67
68 struct panfrost_blend_equation_final {
69 struct mali_blend_equation *equation;
70 float constant;
71 };
72
73 struct panfrost_blend_rt {
74 /* If has_fixed_function is set, equation is the
75 * fixed-function configuration for this blend state */
76
77 bool has_fixed_function;
78 struct mali_blend_equation equation;
79
80 /* Mask of blend color components read */
81 unsigned constant_mask;
82
83 /* Properties of the blend mode */
84 bool opaque, load_dest, no_colour;
85
86 /* Regardless of fixed-function blending, this is a map of pipe_format
87 * to panfrost_blend_shader */
88
89 struct hash_table_u64 *shaders;
90 };
91
92 struct panfrost_blend_state {
93 struct pipe_blend_state base;
94
95 struct panfrost_blend_rt rt[PIPE_MAX_COLOR_BUFS];
96 };
97
98 /* Container for a final blend state, specialized to constants and a
99 * framebuffer formats. */
100
101 struct panfrost_blend_final {
102 /* Set for a shader, clear for an equation */
103 bool is_shader;
104
105 /* Set if this is the replace mode */
106 bool opaque;
107
108 /* Set if destination is loaded */
109 bool load_dest;
110
111 /* Set if the colour mask is 0x0 (nothing is written) */
112 bool no_colour;
113
114 union {
115 struct panfrost_blend_shader_final shader;
116 struct panfrost_blend_equation_final equation;
117 };
118 };
119
120 void
121 panfrost_blend_context_init(struct pipe_context *pipe);
122
123 struct panfrost_blend_final
124 panfrost_get_blend_for_context(struct panfrost_context *ctx, unsigned rt);
125
126 struct panfrost_blend_shader *
127 panfrost_get_blend_shader(
128 struct panfrost_context *ctx,
129 struct panfrost_blend_state *blend,
130 enum pipe_format fmt,
131 unsigned rt);
132
133 #endif