mesa/i965/i915/r200: eliminate gl_vertex_program
[mesa.git] / src / mesa / drivers / dri / i965 / intel_fbo.h
1 /*
2 * Copyright 2006 VMware, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #ifndef INTEL_FBO_H
27 #define INTEL_FBO_H
28
29 #include <stdbool.h>
30 #include <assert.h>
31 #include "main/formats.h"
32 #include "main/macros.h"
33 #include "brw_context.h"
34 #include "intel_mipmap_tree.h"
35 #include "intel_screen.h"
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 struct intel_mipmap_tree;
42
43 /**
44 * Intel renderbuffer, derived from gl_renderbuffer.
45 */
46 struct intel_renderbuffer
47 {
48 struct swrast_renderbuffer Base;
49 /**
50 * The real renderbuffer storage.
51 *
52 * This is multisampled if NumSamples is > 1.
53 */
54 struct intel_mipmap_tree *mt;
55
56 /**
57 * Downsampled contents for window-system MSAA renderbuffers.
58 *
59 * For window system MSAA color buffers, the singlesample_mt is shared with
60 * other processes in DRI2 (and in DRI3, it's the image buffer managed by
61 * glx_dri3.c), while mt is private to our process. To do a swapbuffers,
62 * we have to downsample out of mt into singlesample_mt. For depth and
63 * stencil buffers, the singlesample_mt is also private, and since we don't
64 * expect to need to do resolves (except if someone does a glReadPixels()
65 * or glCopyTexImage()), we just temporarily allocate singlesample_mt when
66 * asked to map the renderbuffer.
67 */
68 struct intel_mipmap_tree *singlesample_mt;
69
70 /**
71 * \name Miptree view
72 * \{
73 *
74 * Multiple renderbuffers may simultaneously wrap a single texture and each
75 * provide a different view into that texture. The fields below indicate
76 * which miptree slice is wrapped by this renderbuffer. The fields' values
77 * are consistent with the 'level' and 'layer' parameters of
78 * glFramebufferTextureLayer().
79 *
80 * For renderbuffers not created with glFramebufferTexture*(), mt_level and
81 * mt_layer are 0.
82 *
83 * Note: for a 2D multisample array texture on Gen7+ using
84 * INTEL_MSAA_LAYOUT_UMS or INTEL_MSAA_LAYOUT_CMS, mt_layer is the physical
85 * layer holding sample 0. So, for example, if mt->num_samples == 4, then
86 * logical layer n corresponds to mt_layer == 4*n.
87 */
88 unsigned int mt_level;
89 unsigned int mt_layer;
90
91 /* The number of attached logical layers. */
92 unsigned int layer_count;
93 /** \} */
94
95 GLuint draw_x, draw_y; /**< Offset of drawing within the region */
96
97 /**
98 * Set to true at every draw call, to indicate if a window-system
99 * renderbuffer needs to be downsampled before using singlesample_mt.
100 */
101 bool need_downsample;
102
103 /**
104 * Set to true when doing an intel_renderbuffer_map()/unmap() that requires
105 * an upsample at the end.
106 */
107 bool need_map_upsample;
108
109 /**
110 * Set to true if singlesample_mt is temporary storage that persists only
111 * for the duration of a mapping.
112 */
113 bool singlesample_mt_is_tmp;
114 };
115
116
117 /**
118 * gl_renderbuffer is a base class which we subclass. The Class field
119 * is used for simple run-time type checking.
120 */
121 #define INTEL_RB_CLASS 0x12345678
122
123
124 /**
125 * Return a gl_renderbuffer ptr casted to intel_renderbuffer.
126 * NULL will be returned if the rb isn't really an intel_renderbuffer.
127 * This is determined by checking the ClassID.
128 */
129 static inline struct intel_renderbuffer *
130 intel_renderbuffer(struct gl_renderbuffer *rb)
131 {
132 struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;
133 if (irb && irb->Base.Base.ClassID == INTEL_RB_CLASS)
134 return irb;
135 else
136 return NULL;
137 }
138
139
140 /**
141 * \brief Return the framebuffer attachment specified by attIndex.
142 *
143 * If the framebuffer lacks the specified attachment, then return null.
144 *
145 * If the attached renderbuffer is a wrapper, then return wrapped
146 * renderbuffer.
147 */
148 static inline struct intel_renderbuffer *
149 intel_get_renderbuffer(struct gl_framebuffer *fb, gl_buffer_index attIndex)
150 {
151 struct gl_renderbuffer *rb;
152
153 assert((unsigned)attIndex < ARRAY_SIZE(fb->Attachment));
154
155 rb = fb->Attachment[attIndex].Renderbuffer;
156 if (!rb)
157 return NULL;
158
159 return intel_renderbuffer(rb);
160 }
161
162
163 static inline mesa_format
164 intel_rb_format(const struct intel_renderbuffer *rb)
165 {
166 return rb->Base.Base.Format;
167 }
168
169 extern struct intel_renderbuffer *
170 intel_create_renderbuffer(mesa_format format, unsigned num_samples);
171
172 struct intel_renderbuffer *
173 intel_create_private_renderbuffer(mesa_format format, unsigned num_samples);
174
175 struct gl_renderbuffer*
176 intel_create_wrapped_renderbuffer(struct gl_context * ctx,
177 int width, int height,
178 mesa_format format);
179
180 extern void
181 intel_fbo_init(struct brw_context *brw);
182
183 void
184 intel_renderbuffer_set_draw_offset(struct intel_renderbuffer *irb);
185
186 static inline uint32_t
187 intel_renderbuffer_get_tile_offsets(struct intel_renderbuffer *irb,
188 uint32_t *tile_x,
189 uint32_t *tile_y)
190 {
191 return intel_miptree_get_tile_offsets(irb->mt, irb->mt_level, irb->mt_layer,
192 tile_x, tile_y);
193 }
194
195 bool
196 intel_renderbuffer_has_hiz(struct intel_renderbuffer *irb);
197
198 void
199 intel_renderbuffer_att_set_needs_depth_resolve(struct gl_renderbuffer_attachment *att);
200
201
202 /**
203 * \brief Perform a HiZ resolve on the renderbuffer.
204 *
205 * It is safe to call this function on a renderbuffer without HiZ. In that
206 * case, the function is a no-op.
207 *
208 * \return false if no resolve was needed
209 */
210 bool
211 intel_renderbuffer_resolve_hiz(struct brw_context *brw,
212 struct intel_renderbuffer *irb);
213
214 /**
215 * \brief Perform a depth resolve on the renderbuffer.
216 *
217 * It is safe to call this function on a renderbuffer without HiZ. In that
218 * case, the function is a no-op.
219 *
220 * \return false if no resolve was needed
221 */
222 bool
223 intel_renderbuffer_resolve_depth(struct brw_context *brw,
224 struct intel_renderbuffer *irb);
225
226 void intel_renderbuffer_move_to_temp(struct brw_context *brw,
227 struct intel_renderbuffer *irb,
228 bool invalidate);
229
230 void
231 intel_renderbuffer_downsample(struct brw_context *brw,
232 struct intel_renderbuffer *irb);
233
234 void
235 intel_renderbuffer_upsample(struct brw_context *brw,
236 struct intel_renderbuffer *irb);
237
238 void brw_render_cache_set_clear(struct brw_context *brw);
239 void brw_render_cache_set_add_bo(struct brw_context *brw, drm_intel_bo *bo);
240 void brw_render_cache_set_check_flush(struct brw_context *brw, drm_intel_bo *bo);
241
242 unsigned
243 intel_quantize_num_samples(struct intel_screen *intel, unsigned num_samples);
244
245 #ifdef __cplusplus
246 }
247 #endif
248
249 #endif /* INTEL_FBO_H */