vc4_context.h revision 848b8605
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#define __user
33#include "vc4_drm.h"
34#include "vc4_bufmgr.h"
35#include "vc4_resource.h"
36#include "vc4_cl.h"
37#include "vc4_qir.h"
38
39#define VC4_DIRTY_BLEND         (1 <<  0)
40#define VC4_DIRTY_RASTERIZER    (1 <<  1)
41#define VC4_DIRTY_ZSA           (1 <<  2)
42#define VC4_DIRTY_FRAGTEX       (1 <<  3)
43#define VC4_DIRTY_VERTTEX       (1 <<  4)
44#define VC4_DIRTY_TEXSTATE      (1 <<  5)
45#define VC4_DIRTY_PROG          (1 <<  6)
46#define VC4_DIRTY_BLEND_COLOR   (1 <<  7)
47#define VC4_DIRTY_STENCIL_REF   (1 <<  8)
48#define VC4_DIRTY_SAMPLE_MASK   (1 <<  9)
49#define VC4_DIRTY_FRAMEBUFFER   (1 << 10)
50#define VC4_DIRTY_STIPPLE       (1 << 11)
51#define VC4_DIRTY_VIEWPORT      (1 << 12)
52#define VC4_DIRTY_CONSTBUF      (1 << 13)
53#define VC4_DIRTY_VTXSTATE      (1 << 14)
54#define VC4_DIRTY_VTXBUF        (1 << 15)
55#define VC4_DIRTY_INDEXBUF      (1 << 16)
56#define VC4_DIRTY_SCISSOR       (1 << 17)
57
58#define VC4_SHADER_DIRTY_VP     (1 << 0)
59#define VC4_SHADER_DIRTY_FP     (1 << 1)
60
61struct vc4_texture_stateobj {
62        struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS];
63        unsigned num_textures;
64        struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
65        unsigned num_samplers;
66        unsigned dirty_samplers;
67};
68
69struct vc4_shader_uniform_info {
70        enum quniform_contents *contents;
71        uint32_t *data;
72        uint32_t count;
73        uint32_t num_texture_samples;
74};
75
76struct vc4_compiled_shader {
77        struct vc4_bo *bo;
78
79        struct vc4_shader_uniform_info uniforms[2];
80
81        uint32_t coord_shader_offset;
82        uint8_t num_inputs;
83};
84
85struct vc4_program_stateobj {
86        struct pipe_shader_state *bind_vs, *bind_fs;
87        struct vc4_compiled_shader *vs, *fs;
88        uint32_t dirty;
89        uint8_t num_exports;
90        /* Indexed by semantic name or TGSI_SEMANTIC_COUNT + semantic index
91         * for TGSI_SEMANTIC_GENERIC.  Special vs exports (position and point-
92         * size) are not included in this
93         */
94        uint8_t export_linkage[63];
95};
96
97struct vc4_constbuf_stateobj {
98        struct pipe_constant_buffer cb[PIPE_MAX_CONSTANT_BUFFERS];
99        uint32_t enabled_mask;
100        uint32_t dirty_mask;
101};
102
103struct vc4_vertexbuf_stateobj {
104        struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
105        unsigned count;
106        uint32_t enabled_mask;
107        uint32_t dirty_mask;
108};
109
110struct vc4_vertex_stateobj {
111        struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];
112        unsigned num_elements;
113};
114
115struct vc4_context {
116        struct pipe_context base;
117
118        int fd;
119        struct vc4_screen *screen;
120
121        struct vc4_cl bcl;
122        struct vc4_cl rcl;
123        struct vc4_cl shader_rec;
124        struct vc4_cl uniforms;
125        struct vc4_cl bo_handles;
126        struct vc4_cl bo_pointers;
127        uint32_t shader_rec_count;
128
129        struct vc4_bo *tile_alloc;
130        struct vc4_bo *tile_state;
131
132        struct util_slab_mempool transfer_pool;
133        struct blitter_context *blitter;
134
135        /** bitfield of VC4_DIRTY_* */
136        uint32_t dirty;
137        /* Bitmask of PIPE_CLEAR_* of buffers that were cleared before the
138         * first rendering.
139         */
140        uint32_t cleared;
141        /* Bitmask of PIPE_CLEAR_* of buffers that have been rendered to
142         * (either clears or draws).
143         */
144        uint32_t resolve;
145        uint32_t clear_color[2];
146        uint32_t clear_depth; /**< 24-bit unorm depth */
147
148        /**
149         * Set if some drawing (triangles, blits, or just a glClear()) has
150         * been done to the FBO, meaning that we need to
151         * DRM_IOCTL_VC4_SUBMIT_CL.
152         */
153        bool needs_flush;
154
155        /**
156         * Set when needs_flush, and the queued rendering is not just composed
157         * of full-buffer clears.
158         */
159        bool draw_call_queued;
160
161        struct primconvert_context *primconvert;
162
163        struct util_hash_table *fs_cache, *vs_cache;
164
165        /** @{ Current pipeline state objects */
166        struct pipe_scissor_state scissor;
167        struct pipe_blend_state *blend;
168        struct vc4_rasterizer_state *rasterizer;
169        struct vc4_depth_stencil_alpha_state *zsa;
170
171        struct vc4_texture_stateobj verttex, fragtex;
172
173        struct vc4_program_stateobj prog;
174
175        struct vc4_vertex_stateobj *vtx;
176
177        struct pipe_blend_color blend_color;
178        struct pipe_stencil_ref stencil_ref;
179        unsigned sample_mask;
180        struct pipe_framebuffer_state framebuffer;
181        struct pipe_poly_stipple stipple;
182        struct pipe_viewport_state viewport;
183        struct vc4_constbuf_stateobj constbuf[PIPE_SHADER_TYPES];
184        struct vc4_vertexbuf_stateobj vertexbuf;
185        struct pipe_index_buffer indexbuf;
186        /** @} */
187};
188
189struct vc4_rasterizer_state {
190        struct pipe_rasterizer_state base;
191
192        /* VC4_CONFIGURATION_BITS */
193        uint8_t config_bits[3];
194
195        float point_size;
196};
197
198struct vc4_depth_stencil_alpha_state {
199        struct pipe_depth_stencil_alpha_state base;
200
201        /* VC4_CONFIGURATION_BITS */
202        uint8_t config_bits[3];
203};
204
205static inline struct vc4_context *
206vc4_context(struct pipe_context *pcontext)
207{
208        return (struct vc4_context *)pcontext;
209}
210
211struct pipe_context *vc4_context_create(struct pipe_screen *pscreen,
212                                        void *priv);
213void vc4_draw_init(struct pipe_context *pctx);
214void vc4_state_init(struct pipe_context *pctx);
215void vc4_program_init(struct pipe_context *pctx);
216void vc4_simulator_init(struct vc4_screen *screen);
217int vc4_simulator_flush(struct vc4_context *vc4,
218                        struct drm_vc4_submit_cl *args);
219
220void vc4_write_uniforms(struct vc4_context *vc4,
221                        struct vc4_compiled_shader *shader,
222                        struct vc4_constbuf_stateobj *cb,
223                        struct vc4_texture_stateobj *texstate,
224                        int shader_index);
225
226void vc4_flush(struct pipe_context *pctx);
227void vc4_flush_for_bo(struct pipe_context *pctx, struct vc4_bo *bo);
228void vc4_emit_state(struct pipe_context *pctx);
229void vc4_generate_code(struct qcompile *c);
230void vc4_update_compiled_shaders(struct vc4_context *vc4, uint8_t prim_mode);
231
232#endif /* VC4_CONTEXT_H */
233