2 * Copyright 2006 VMware, Inc.
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:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
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.
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"
41 struct intel_mipmap_tree
;
42 struct intel_texture_image
;
45 * Intel renderbuffer, derived from gl_renderbuffer.
47 struct intel_renderbuffer
49 struct swrast_renderbuffer Base
;
51 * The real renderbuffer storage.
53 * This is multisampled if NumSamples is > 1.
55 struct intel_mipmap_tree
*mt
;
58 * Downsampled contents for window-system MSAA renderbuffers.
60 * For window system MSAA color buffers, the singlesample_mt is shared with
61 * other processes in DRI2 (and in DRI3, it's the image buffer managed by
62 * glx_dri3.c), while mt is private to our process. To do a swapbuffers,
63 * we have to downsample out of mt into singlesample_mt. For depth and
64 * stencil buffers, the singlesample_mt is also private, and since we don't
65 * expect to need to do resolves (except if someone does a glReadPixels()
66 * or glCopyTexImage()), we just temporarily allocate singlesample_mt when
67 * asked to map the renderbuffer.
69 struct intel_mipmap_tree
*singlesample_mt
;
75 * Multiple renderbuffers may simultaneously wrap a single texture and each
76 * provide a different view into that texture. The fields below indicate
77 * which miptree slice is wrapped by this renderbuffer. The fields' values
78 * are consistent with the 'level' and 'layer' parameters of
79 * glFramebufferTextureLayer().
81 * For renderbuffers not created with glFramebufferTexture*(), mt_level and
84 * Note: for a 2D multisample array texture on Gen7+ using
85 * INTEL_MSAA_LAYOUT_UMS or INTEL_MSAA_LAYOUT_CMS, mt_layer is the physical
86 * layer holding sample 0. So, for example, if mt->num_samples == 4, then
87 * logical layer n corresponds to mt_layer == 4*n.
89 unsigned int mt_level
;
90 unsigned int mt_layer
;
92 /* The number of attached logical layers. */
93 unsigned int layer_count
;
96 GLuint draw_x
, draw_y
; /**< Offset of drawing within the region */
99 * Set to true at every draw call, to indicate if a window-system
100 * renderbuffer needs to be downsampled before using singlesample_mt.
102 bool need_downsample
;
105 * Set to true when doing an intel_renderbuffer_map()/unmap() that requires
106 * an upsample at the end.
108 bool need_map_upsample
;
111 * Set to true if singlesample_mt is temporary storage that persists only
112 * for the duration of a mapping.
114 bool singlesample_mt_is_tmp
;
119 * gl_renderbuffer is a base class which we subclass. The Class field
120 * is used for simple run-time type checking.
122 #define INTEL_RB_CLASS 0x12345678
126 * Return a gl_renderbuffer ptr casted to intel_renderbuffer.
127 * NULL will be returned if the rb isn't really an intel_renderbuffer.
128 * This is determined by checking the ClassID.
130 static inline struct intel_renderbuffer
*
131 intel_renderbuffer(struct gl_renderbuffer
*rb
)
133 struct intel_renderbuffer
*irb
= (struct intel_renderbuffer
*) rb
;
134 if (irb
&& irb
->Base
.Base
.ClassID
== INTEL_RB_CLASS
) {
135 /*_mesa_warning(NULL, "Returning non-intel Rb\n");*/
144 * \brief Return the framebuffer attachment specified by attIndex.
146 * If the framebuffer lacks the specified attachment, then return null.
148 * If the attached renderbuffer is a wrapper, then return wrapped
151 static inline struct intel_renderbuffer
*
152 intel_get_renderbuffer(struct gl_framebuffer
*fb
, gl_buffer_index attIndex
)
154 struct gl_renderbuffer
*rb
;
156 assert((unsigned)attIndex
< ARRAY_SIZE(fb
->Attachment
));
158 rb
= fb
->Attachment
[attIndex
].Renderbuffer
;
162 return intel_renderbuffer(rb
);
166 static inline mesa_format
167 intel_rb_format(const struct intel_renderbuffer
*rb
)
169 return rb
->Base
.Base
.Format
;
172 extern struct intel_renderbuffer
*
173 intel_create_renderbuffer(mesa_format format
, unsigned num_samples
);
175 struct intel_renderbuffer
*
176 intel_create_private_renderbuffer(mesa_format format
, unsigned num_samples
);
178 struct gl_renderbuffer
*
179 intel_create_wrapped_renderbuffer(struct gl_context
* ctx
,
180 int width
, int height
,
184 intel_fbo_init(struct brw_context
*brw
);
187 intel_renderbuffer_set_draw_offset(struct intel_renderbuffer
*irb
);
189 static inline uint32_t
190 intel_renderbuffer_get_tile_offsets(struct intel_renderbuffer
*irb
,
194 return intel_miptree_get_tile_offsets(irb
->mt
, irb
->mt_level
, irb
->mt_layer
,
199 intel_renderbuffer_has_hiz(struct intel_renderbuffer
*irb
);
202 intel_renderbuffer_att_set_needs_depth_resolve(struct gl_renderbuffer_attachment
*att
);
206 * \brief Perform a HiZ resolve on the renderbuffer.
208 * It is safe to call this function on a renderbuffer without HiZ. In that
209 * case, the function is a no-op.
211 * \return false if no resolve was needed
214 intel_renderbuffer_resolve_hiz(struct brw_context
*brw
,
215 struct intel_renderbuffer
*irb
);
218 * \brief Perform a depth resolve on the renderbuffer.
220 * It is safe to call this function on a renderbuffer without HiZ. In that
221 * case, the function is a no-op.
223 * \return false if no resolve was needed
226 intel_renderbuffer_resolve_depth(struct brw_context
*brw
,
227 struct intel_renderbuffer
*irb
);
229 void intel_renderbuffer_move_to_temp(struct brw_context
*brw
,
230 struct intel_renderbuffer
*irb
,
234 intel_renderbuffer_downsample(struct brw_context
*brw
,
235 struct intel_renderbuffer
*irb
);
238 intel_renderbuffer_upsample(struct brw_context
*brw
,
239 struct intel_renderbuffer
*irb
);
241 void brw_render_cache_set_clear(struct brw_context
*brw
);
242 void brw_render_cache_set_add_bo(struct brw_context
*brw
, drm_intel_bo
*bo
);
243 void brw_render_cache_set_check_flush(struct brw_context
*brw
, drm_intel_bo
*bo
);
246 intel_quantize_num_samples(struct intel_screen
*intel
, unsigned num_samples
);
252 #endif /* INTEL_FBO_H */