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_framebuffer_stateobj
{
83 struct pipe_framebuffer_state base
;
84 uint16_t bin_h
, nbins_y
;
85 uint16_t bin_w
, nbins_x
;
86 uint32_t pa_su_sc_mode_cntl
;
90 struct pipe_context base
;
92 struct fd_screen
*screen
;
93 struct blitter_context
*blitter
;
95 struct util_slab_mempool transfer_pool
;
97 /* shaders used by clear, and gmem->mem blits: */
98 struct fd_program_stateobj solid_prog
; // TODO move to screen?
100 /* shaders used by mem->gmem blits: */
101 struct fd_program_stateobj blit_prog
; // TODO move to screen?
103 /* vertex buff used for clear/gmem->mem vertices, and mem->gmem
104 * vertices and tex coords:
106 struct pipe_resource
*solid_vertexbuf
;
108 /* do we need to mem2gmem before rendering. We don't, if for example,
109 * there was a glClear() that invalidated the entire previous buffer
110 * contents. Keep track of which buffer(s) are cleared, or needs
111 * restore. Masks of PIPE_CLEAR_*
114 /* align bitmask values w/ PIPE_CLEAR_*.. since that is convenient.. */
115 FD_BUFFER_COLOR
= PIPE_CLEAR_COLOR
,
116 FD_BUFFER_DEPTH
= PIPE_CLEAR_DEPTH
,
117 FD_BUFFER_STENCIL
= PIPE_CLEAR_STENCIL
,
118 FD_BUFFER_ALL
= FD_BUFFER_COLOR
| FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
,
119 } cleared
, restore
, resolve
;
123 struct fd_ringbuffer
*ring
;
124 struct fd_ringmarker
*draw_start
, *draw_end
;
126 /* scissor can't really be changed mid-render.. we probably need
127 * to flush out all pending draws and then start a new tile pass
128 * w/ new stencil state..
130 struct pipe_scissor_state scissor
;
132 /* which state objects need to be re-emit'd: */
134 FD_DIRTY_BLEND
= (1 << 0),
135 FD_DIRTY_RASTERIZER
= (1 << 1),
136 FD_DIRTY_ZSA
= (1 << 2),
137 FD_DIRTY_FRAGTEX
= (1 << 3),
138 FD_DIRTY_VERTTEX
= (1 << 4),
139 FD_DIRTY_PROG
= (1 << 5),
140 FD_DIRTY_VTX
= (1 << 6),
141 FD_DIRTY_BLEND_COLOR
= (1 << 7),
142 FD_DIRTY_STENCIL_REF
= (1 << 8),
143 FD_DIRTY_SAMPLE_MASK
= (1 << 9),
144 FD_DIRTY_FRAMEBUFFER
= (1 << 10),
145 FD_DIRTY_STIPPLE
= (1 << 12),
146 FD_DIRTY_VIEWPORT
= (1 << 12),
147 FD_DIRTY_CONSTBUF
= (1 << 13),
148 FD_DIRTY_VERTEXBUF
= (1 << 14),
149 FD_DIRTY_INDEXBUF
= (1 << 15),
150 FD_DIRTY_SCISSOR
= (1 << 16),
153 struct fd_blend_stateobj
*blend
;
154 struct fd_rasterizer_stateobj
*rasterizer
;
155 struct fd_zsa_stateobj
*zsa
;
157 struct fd_texture_stateobj verttex
, fragtex
;
159 struct fd_program_stateobj prog
;
161 struct fd_vertex_stateobj
*vtx
;
163 struct pipe_blend_color blend_color
;
164 struct pipe_stencil_ref stencil_ref
;
165 unsigned sample_mask
;
166 struct fd_framebuffer_stateobj framebuffer
;
167 struct pipe_poly_stipple stipple
;
168 struct pipe_viewport_state viewport
;
169 struct fd_constbuf_stateobj constbuf
[PIPE_SHADER_TYPES
];
170 struct fd_vertexbuf_stateobj vertexbuf
;
171 struct pipe_index_buffer indexbuf
;
174 static INLINE
struct fd_context
*
175 fd_context(struct pipe_context
*pctx
)
177 return (struct fd_context
*)pctx
;
180 struct pipe_context
* fd_context_create(struct pipe_screen
*pscreen
, void *priv
);
182 void fd_context_render(struct pipe_context
*pctx
);
184 #endif /* FREEDRENO_CONTEXT_H_ */