73bf05bce193c0ed178a56f526cf1b8223d39e4f
[mesa.git] / src / gallium / drivers / vc4 / vc4_context.h
1 /*
2 * Copyright © 2014 Broadcom
3 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25 #ifndef VC4_CONTEXT_H
26 #define VC4_CONTEXT_H
27
28 #include "pipe/p_context.h"
29 #include "pipe/p_state.h"
30 #include "util/u_slab.h"
31
32 #include "vc4_bufmgr.h"
33 #include "vc4_resource.h"
34 #include "vc4_cl.h"
35
36 #define VC4_DIRTY_BLEND (1 << 0)
37 #define VC4_DIRTY_RASTERIZER (1 << 1)
38 #define VC4_DIRTY_ZSA (1 << 2)
39 #define VC4_DIRTY_FRAGTEX (1 << 3)
40 #define VC4_DIRTY_VERTTEX (1 << 4)
41 #define VC4_DIRTY_TEXSTATE (1 << 5)
42 #define VC4_DIRTY_PROG (1 << 6)
43 #define VC4_DIRTY_BLEND_COLOR (1 << 7)
44 #define VC4_DIRTY_STENCIL_REF (1 << 8)
45 #define VC4_DIRTY_SAMPLE_MASK (1 << 9)
46 #define VC4_DIRTY_FRAMEBUFFER (1 << 10)
47 #define VC4_DIRTY_STIPPLE (1 << 11)
48 #define VC4_DIRTY_VIEWPORT (1 << 12)
49 #define VC4_DIRTY_CONSTBUF (1 << 13)
50 #define VC4_DIRTY_VTXSTATE (1 << 14)
51 #define VC4_DIRTY_VTXBUF (1 << 15)
52 #define VC4_DIRTY_INDEXBUF (1 << 16)
53 #define VC4_DIRTY_SCISSOR (1 << 17)
54
55 #define VC4_SHADER_DIRTY_VP (1 << 0)
56 #define VC4_SHADER_DIRTY_FP (1 << 1)
57
58 struct vc4_texture_stateobj {
59 struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS];
60 unsigned num_textures;
61 struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
62 unsigned num_samplers;
63 unsigned dirty_samplers;
64 };
65
66 struct vc4_shader_state {
67 struct pipe_shader_state base;
68 struct vc4_bo *bo;
69 };
70
71 struct vc4_program_stateobj {
72 struct vc4_shader_state *vs, *fs;
73 uint32_t dirty;
74 uint8_t num_exports;
75 /* Indexed by semantic name or TGSI_SEMANTIC_COUNT + semantic index
76 * for TGSI_SEMANTIC_GENERIC. Special vs exports (position and point-
77 * size) are not included in this
78 */
79 uint8_t export_linkage[63];
80 };
81
82 struct vc4_constbuf_stateobj {
83 struct pipe_constant_buffer cb[PIPE_MAX_CONSTANT_BUFFERS];
84 uint32_t enabled_mask;
85 uint32_t dirty_mask;
86 };
87
88 struct vc4_vertexbuf_stateobj {
89 struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
90 unsigned count;
91 uint32_t enabled_mask;
92 uint32_t dirty_mask;
93 };
94
95 struct vc4_vertex_stateobj {
96 struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];
97 unsigned num_elements;
98 };
99
100 struct vc4_context {
101 struct pipe_context base;
102
103 int fd;
104 struct vc4_screen *screen;
105
106 struct vc4_cl bcl;
107 struct vc4_cl rcl;
108 struct vc4_cl shader_rec;
109 struct vc4_cl bo_handles;
110 uint32_t shader_rec_count;
111
112 struct util_slab_mempool transfer_pool;
113 struct blitter_context *blitter;
114
115 /** bitfield of VC4_DIRTY_* */
116 uint32_t dirty;
117
118 /**
119 * Set if some drawing (triangles, blits, or just a glClear()) has
120 * been done to the FBO, meaning that we need to
121 * DRM_IOCTL_VC4_SUBMIT_CL.
122 */
123 bool needs_flush;
124
125 /** @{ Current pipeline state objects */
126 struct pipe_scissor_state scissor;
127 struct pipe_blend_state *blend;
128 struct vc4_rasterizer_state *rasterizer;
129 struct pipe_depth_stencil_alpha_state *zsa;
130
131 struct vc4_texture_stateobj verttex, fragtex;
132
133 struct vc4_program_stateobj prog;
134
135 struct vc4_vertex_stateobj *vtx;
136
137 struct pipe_blend_color blend_color;
138 struct pipe_stencil_ref stencil_ref;
139 unsigned sample_mask;
140 struct pipe_framebuffer_state framebuffer;
141 struct pipe_poly_stipple stipple;
142 struct pipe_viewport_state viewport;
143 struct vc4_constbuf_stateobj constbuf[PIPE_SHADER_TYPES];
144 struct vc4_vertexbuf_stateobj vertexbuf;
145 struct pipe_index_buffer indexbuf;
146 /** @} */
147 };
148
149 struct vc4_rasterizer_state {
150 struct pipe_rasterizer_state base;
151
152 /* VC4_CONFIGURATION_BITS */
153 uint8_t config_bits[3];
154
155 float point_size;
156 };
157
158 static inline struct vc4_context *
159 vc4_context(struct pipe_context *pcontext)
160 {
161 return (struct vc4_context *)pcontext;
162 }
163
164 struct pipe_context *vc4_context_create(struct pipe_screen *pscreen,
165 void *priv);
166 void vc4_draw_init(struct pipe_context *pctx);
167 void vc4_state_init(struct pipe_context *pctx);
168 void vc4_program_init(struct pipe_context *pctx);
169 void vc4_simulator_init(struct vc4_screen *screen);
170 void vc4_simulator_flush(struct vc4_context *vc4,
171 struct vc4_surface *color_surf);
172 void *vc4_simulator_alloc(struct vc4_screen *screen, uint32_t size);
173
174 void vc4_flush(struct pipe_context *pctx);
175 void vc4_emit_state(struct pipe_context *pctx);
176
177 #endif /* VC4_CONTEXT_H */