panfrost: Stop passing screen around for BO operations
[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 /* The compiled shader in GPU memory, possibly patched */
59 struct panfrost_bo *bo;
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 /* Regardless of fixed-function blending, this is a map of pipe_format
84 * to panfrost_blend_shader */
85
86 struct hash_table_u64 *shaders;
87 };
88
89 struct panfrost_blend_state {
90 struct pipe_blend_state base;
91
92 struct panfrost_blend_rt rt[PIPE_MAX_COLOR_BUFS];
93 };
94
95 /* Container for a final blend state, specialized to constants and a
96 * framebuffer formats. */
97
98 struct panfrost_blend_final {
99 /* Set for a shader, clear for an equation */
100 bool is_shader;
101
102 /* Set if the destination needs to be loaded from the tilebuffer,
103 * basically (for an equation) or if a shader is present */
104 bool no_blending;
105
106 union {
107 struct panfrost_blend_shader_final shader;
108 struct panfrost_blend_equation_final equation;
109 };
110 };
111
112 void
113 panfrost_blend_context_init(struct pipe_context *pipe);
114
115 struct panfrost_blend_final
116 panfrost_get_blend_for_context(struct panfrost_context *ctx, unsigned rt);
117
118 #endif