• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    /* Gen < 6 doesn't have layer specifier for render targets or depth. Driver
71     * needs to manually offset surfaces to correct level/layer. There are,
72     * however, alignment restrictions to respect as well and in come cases
73     * the only option is to use temporary single slice surface which driver
74     * copies after rendering to the full miptree.
75     *
76     * See intel_renderbuffer_move_to_temp().
77     */
78    struct intel_mipmap_tree *align_wa_mt;
79 
80    /**
81     * \name Miptree view
82     * \{
83     *
84     * Multiple renderbuffers may simultaneously wrap a single texture and each
85     * provide a different view into that texture. The fields below indicate
86     * which miptree slice is wrapped by this renderbuffer.  The fields' values
87     * are consistent with the 'level' and 'layer' parameters of
88     * glFramebufferTextureLayer().
89     *
90     * For renderbuffers not created with glFramebufferTexture*(), mt_level and
91     * mt_layer are 0.
92     */
93    unsigned int mt_level;
94    unsigned int mt_layer;
95 
96    /* The number of attached logical layers. */
97    unsigned int layer_count;
98    /** \} */
99 
100    GLuint draw_x, draw_y; /**< Offset of drawing within the region */
101 
102    /**
103     * Set to true at every draw call, to indicate if a window-system
104     * renderbuffer needs to be downsampled before using singlesample_mt.
105     */
106    bool need_downsample;
107 
108    /**
109     * Set to true when doing an intel_renderbuffer_map()/unmap() that requires
110     * an upsample at the end.
111     */
112    bool need_map_upsample;
113 
114    /**
115     * Set to true if singlesample_mt is temporary storage that persists only
116     * for the duration of a mapping.
117     */
118    bool singlesample_mt_is_tmp;
119 
120    /**
121     * Set to true when application specifically asked for a sRGB visual.
122     */
123    bool need_srgb;
124 };
125 
126 
127 /**
128  * gl_renderbuffer is a base class which we subclass.  The Class field
129  * is used for simple run-time type checking.
130  */
131 #define INTEL_RB_CLASS 0x12345678
132 
133 
134 /**
135  * Return a gl_renderbuffer ptr casted to intel_renderbuffer.
136  * NULL will be returned if the rb isn't really an intel_renderbuffer.
137  * This is determined by checking the ClassID.
138  */
139 static inline struct intel_renderbuffer *
intel_renderbuffer(struct gl_renderbuffer * rb)140 intel_renderbuffer(struct gl_renderbuffer *rb)
141 {
142    struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;
143    if (irb && irb->Base.Base.ClassID == INTEL_RB_CLASS)
144       return irb;
145    else
146       return NULL;
147 }
148 
149 static inline struct intel_mipmap_tree *
intel_renderbuffer_get_mt(struct intel_renderbuffer * irb)150 intel_renderbuffer_get_mt(struct intel_renderbuffer *irb)
151 {
152    if (!irb)
153       return NULL;
154 
155    return (irb->align_wa_mt) ? irb->align_wa_mt : irb->mt;
156 }
157 
158 /**
159  * \brief Return the framebuffer attachment specified by attIndex.
160  *
161  * If the framebuffer lacks the specified attachment, then return null.
162  *
163  * If the attached renderbuffer is a wrapper, then return wrapped
164  * renderbuffer.
165  */
166 static inline struct intel_renderbuffer *
intel_get_renderbuffer(struct gl_framebuffer * fb,gl_buffer_index attIndex)167 intel_get_renderbuffer(struct gl_framebuffer *fb, gl_buffer_index attIndex)
168 {
169    struct gl_renderbuffer *rb;
170 
171    assert((unsigned)attIndex < ARRAY_SIZE(fb->Attachment));
172 
173    rb = fb->Attachment[attIndex].Renderbuffer;
174    if (!rb)
175       return NULL;
176 
177    return intel_renderbuffer(rb);
178 }
179 
180 
181 static inline mesa_format
intel_rb_format(const struct intel_renderbuffer * rb)182 intel_rb_format(const struct intel_renderbuffer *rb)
183 {
184    return rb->Base.Base.Format;
185 }
186 
187 extern struct intel_renderbuffer *
188 intel_create_winsys_renderbuffer(struct intel_screen *screen,
189                                  mesa_format format, unsigned num_samples);
190 
191 struct intel_renderbuffer *
192 intel_create_private_renderbuffer(struct intel_screen *screen,
193                                   mesa_format format, unsigned num_samples);
194 
195 struct gl_renderbuffer*
196 intel_create_wrapped_renderbuffer(struct gl_context * ctx,
197 				  int width, int height,
198 				  mesa_format format);
199 
200 extern void
201 intel_fbo_init(struct brw_context *brw);
202 
203 void
204 intel_renderbuffer_set_draw_offset(struct intel_renderbuffer *irb);
205 
206 static inline uint32_t
intel_renderbuffer_get_tile_offsets(struct intel_renderbuffer * irb,uint32_t * tile_x,uint32_t * tile_y)207 intel_renderbuffer_get_tile_offsets(struct intel_renderbuffer *irb,
208                                     uint32_t *tile_x,
209                                     uint32_t *tile_y)
210 {
211    if (irb->align_wa_mt) {
212       *tile_x = 0;
213       *tile_y = 0;
214       return 0;
215    }
216 
217    return intel_miptree_get_tile_offsets(irb->mt, irb->mt_level, irb->mt_layer,
218                                          tile_x, tile_y);
219 }
220 
221 bool
222 intel_renderbuffer_has_hiz(struct intel_renderbuffer *irb);
223 
224 
225 void intel_renderbuffer_move_to_temp(struct brw_context *brw,
226                                      struct intel_renderbuffer *irb,
227                                      bool invalidate);
228 
229 void
230 intel_renderbuffer_downsample(struct brw_context *brw,
231                               struct intel_renderbuffer *irb);
232 
233 void
234 intel_renderbuffer_upsample(struct brw_context *brw,
235                             struct intel_renderbuffer *irb);
236 
237 void brw_cache_sets_clear(struct brw_context *brw);
238 void brw_cache_flush_for_read(struct brw_context *brw, struct brw_bo *bo);
239 void brw_cache_flush_for_render(struct brw_context *brw, struct brw_bo *bo,
240                                 enum isl_format format,
241                                 enum isl_aux_usage aux_usage);
242 void brw_cache_flush_for_depth(struct brw_context *brw, struct brw_bo *bo);
243 void brw_render_cache_add_bo(struct brw_context *brw, struct brw_bo *bo,
244                              enum isl_format format,
245                              enum isl_aux_usage aux_usage);
246 void brw_depth_cache_add_bo(struct brw_context *brw, struct brw_bo *bo);
247 
248 unsigned
249 intel_quantize_num_samples(struct intel_screen *intel, unsigned num_samples);
250 
251 #ifdef __cplusplus
252 }
253 #endif
254 
255 #endif /* INTEL_FBO_H */
256