1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Rob Clark <robclark@freedesktop.org>
29 #ifndef FREEDRENO_CONTEXT_H_
30 #define FREEDRENO_CONTEXT_H_
32 #include "draw/draw_context.h"
33 #include "pipe/p_context.h"
34 #include "util/u_blitter.h"
35 #include "util/u_slab.h"
36 #include "util/u_string.h"
38 #include "freedreno_screen.h"
40 struct fd_blend_stateobj
;
41 struct fd_rasterizer_stateobj
;
42 struct fd_zsa_stateobj
;
43 struct fd_sampler_stateobj
;
44 struct fd_vertex_stateobj
;
45 struct fd_shader_stateobj
;
47 struct fd_texture_stateobj
{
48 struct pipe_sampler_view
*textures
[PIPE_MAX_SAMPLERS
];
49 unsigned num_textures
;
50 struct fd_sampler_stateobj
*samplers
[PIPE_MAX_SAMPLERS
];
51 unsigned num_samplers
;
52 unsigned dirty_samplers
;
55 struct fd_program_stateobj
{
56 struct fd_shader_stateobj
*vp
, *fp
;
58 FD_SHADER_DIRTY_VP
= (1 << 0),
59 FD_SHADER_DIRTY_FP
= (1 << 1),
62 /* Indexed by semantic name or TGSI_SEMANTIC_COUNT + semantic index
63 * for TGSI_SEMANTIC_GENERIC. Special vs exports (position and point-
64 * size) are not included in this
66 uint8_t export_linkage
[63];
69 struct fd_constbuf_stateobj
{
70 struct pipe_constant_buffer cb
[PIPE_MAX_CONSTANT_BUFFERS
];
71 uint32_t enabled_mask
;
75 struct fd_vertexbuf_stateobj
{
76 struct pipe_vertex_buffer vb
[PIPE_MAX_ATTRIBS
];
78 uint32_t enabled_mask
;
82 struct fd_gmem_stateobj
{
83 struct pipe_scissor_state scissor
;
86 uint16_t bin_h
, nbins_y
;
87 uint16_t bin_w
, nbins_x
;
88 uint16_t width
, height
;
92 struct pipe_context base
;
94 struct fd_screen
*screen
;
95 struct blitter_context
*blitter
;
97 struct util_slab_mempool transfer_pool
;
99 /* shaders used by clear, and gmem->mem blits: */
100 struct fd_program_stateobj solid_prog
; // TODO move to screen?
102 /* shaders used by mem->gmem blits: */
103 struct fd_program_stateobj blit_prog
; // TODO move to screen?
105 /* vertex buff used for clear/gmem->mem vertices, and mem->gmem
106 * vertices and tex coords:
108 struct pipe_resource
*solid_vertexbuf
;
110 /* do we need to mem2gmem before rendering. We don't, if for example,
111 * there was a glClear() that invalidated the entire previous buffer
112 * contents. Keep track of which buffer(s) are cleared, or needs
113 * restore. Masks of PIPE_CLEAR_*
116 /* align bitmask values w/ PIPE_CLEAR_*.. since that is convenient.. */
117 FD_BUFFER_COLOR
= PIPE_CLEAR_COLOR
,
118 FD_BUFFER_DEPTH
= PIPE_CLEAR_DEPTH
,
119 FD_BUFFER_STENCIL
= PIPE_CLEAR_STENCIL
,
120 FD_BUFFER_ALL
= FD_BUFFER_COLOR
| FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
,
121 } cleared
, restore
, resolve
;
125 struct fd_ringbuffer
*ring
;
126 struct fd_ringmarker
*draw_start
, *draw_end
;
128 /* scissor can't really be changed mid-render.. we probably need
129 * to flush out all pending draws and then start a new tile pass
130 * w/ new stencil state..
132 struct pipe_scissor_state scissor
;
134 /* Track the maximal bounds of the scissor of all the draws within a
135 * batch. Used at the tile rendering step (fd_gmem_render_tiles(),
136 * mem2gmem/gmem2mem) to avoid needlessly moving data in/out of gmem.
138 struct pipe_scissor_state max_scissor
;
140 /* Current gmem/tiling configuration.. gets updated on render_tiles()
141 * if out of date with current maximal-scissor/cpp:
143 struct fd_gmem_stateobj gmem
;
145 /* which state objects need to be re-emit'd: */
147 FD_DIRTY_BLEND
= (1 << 0),
148 FD_DIRTY_RASTERIZER
= (1 << 1),
149 FD_DIRTY_ZSA
= (1 << 2),
150 FD_DIRTY_FRAGTEX
= (1 << 3),
151 FD_DIRTY_VERTTEX
= (1 << 4),
152 FD_DIRTY_TEXSTATE
= (1 << 5),
153 FD_DIRTY_PROG
= (1 << 6),
154 FD_DIRTY_BLEND_COLOR
= (1 << 7),
155 FD_DIRTY_STENCIL_REF
= (1 << 8),
156 FD_DIRTY_SAMPLE_MASK
= (1 << 9),
157 FD_DIRTY_FRAMEBUFFER
= (1 << 10),
158 FD_DIRTY_STIPPLE
= (1 << 11),
159 FD_DIRTY_VIEWPORT
= (1 << 12),
160 FD_DIRTY_CONSTBUF
= (1 << 13),
161 FD_DIRTY_VTXSTATE
= (1 << 14),
162 FD_DIRTY_VTXBUF
= (1 << 15),
163 FD_DIRTY_INDEXBUF
= (1 << 16),
164 FD_DIRTY_SCISSOR
= (1 << 17),
167 struct fd_blend_stateobj
*blend
;
168 struct fd_rasterizer_stateobj
*rasterizer
;
169 struct fd_zsa_stateobj
*zsa
;
171 struct fd_texture_stateobj verttex
, fragtex
;
173 struct fd_program_stateobj prog
;
175 struct fd_vertex_stateobj
*vtx
;
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 fd_constbuf_stateobj constbuf
[PIPE_SHADER_TYPES
];
184 struct fd_vertexbuf_stateobj vertexbuf
;
185 struct pipe_index_buffer indexbuf
;
188 static INLINE
struct fd_context
*
189 fd_context(struct pipe_context
*pctx
)
191 return (struct fd_context
*)pctx
;
194 struct pipe_context
* fd_context_create(struct pipe_screen
*pscreen
, void *priv
);
196 void fd_context_render(struct pipe_context
*pctx
);
198 #endif /* FREEDRENO_CONTEXT_H_ */