2 Copyright 2003 VMware, Inc.
3 Copyright (C) Intel Corp. 2006. All Rights Reserved.
4 Intel funded Tungsten Graphics to
5 develop this 3D driver.
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice (including the
16 next paragraph) shall be included in all copies or substantial
17 portions of the Software.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
23 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **********************************************************************/
30 * Keith Whitwell <keithw@vmware.com>
34 #include "main/api_exec.h"
35 #include "main/context.h"
36 #include "main/fbobject.h"
37 #include "main/extensions.h"
38 #include "main/imports.h"
39 #include "main/macros.h"
40 #include "main/points.h"
41 #include "main/version.h"
42 #include "main/vtxfmt.h"
43 #include "main/texobj.h"
45 #include "vbo/vbo_context.h"
47 #include "drivers/common/driverfuncs.h"
48 #include "drivers/common/meta.h"
51 #include "brw_context.h"
52 #include "brw_defines.h"
54 #include "brw_state.h"
56 #include "intel_batchbuffer.h"
57 #include "intel_buffer_objects.h"
58 #include "intel_buffers.h"
59 #include "intel_fbo.h"
60 #include "intel_mipmap_tree.h"
61 #include "intel_pixel.h"
62 #include "intel_image.h"
63 #include "intel_tex.h"
64 #include "intel_tex_obj.h"
66 #include "swrast_setup/swrast_setup.h"
68 #include "tnl/t_pipeline.h"
69 #include "util/ralloc.h"
71 /***************************************
72 * Mesa's Driver Functions
73 ***************************************/
76 brw_query_samples_for_format(struct gl_context
*ctx
, GLenum target
,
77 GLenum internalFormat
, int samples
[16])
79 struct brw_context
*brw
= brw_context(ctx
);
105 const char *const brw_vendor_string
= "Intel Open Source Technology Center";
108 brw_get_renderer_string(unsigned deviceID
)
111 static char buffer
[128];
115 #define CHIPSET(id, symbol, str) case id: chipset = str; break;
116 #include "pci_ids/i965_pci_ids.h"
118 chipset
= "Unknown Intel Chipset";
122 (void) driGetRendererString(buffer
, chipset
, 0);
126 static const GLubyte
*
127 intel_get_string(struct gl_context
* ctx
, GLenum name
)
129 const struct brw_context
*const brw
= brw_context(ctx
);
133 return (GLubyte
*) brw_vendor_string
;
137 (GLubyte
*) brw_get_renderer_string(brw
->intelScreen
->deviceID
);
145 intel_viewport(struct gl_context
*ctx
)
147 struct brw_context
*brw
= brw_context(ctx
);
148 __DRIcontext
*driContext
= brw
->driContext
;
150 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
151 dri2InvalidateDrawable(driContext
->driDrawablePriv
);
152 dri2InvalidateDrawable(driContext
->driReadablePriv
);
157 intel_update_state(struct gl_context
* ctx
, GLuint new_state
)
159 struct brw_context
*brw
= brw_context(ctx
);
160 struct intel_texture_object
*tex_obj
;
161 struct intel_renderbuffer
*depth_irb
;
163 if (ctx
->swrast_context
)
164 _swrast_InvalidateState(ctx
, new_state
);
165 _vbo_InvalidateState(ctx
, new_state
);
167 brw
->NewGLState
|= new_state
;
169 _mesa_unlock_context_textures(ctx
);
171 /* Resolve the depth buffer's HiZ buffer. */
172 depth_irb
= intel_get_renderbuffer(ctx
->DrawBuffer
, BUFFER_DEPTH
);
174 intel_renderbuffer_resolve_hiz(brw
, depth_irb
);
176 /* Resolve depth buffer and render cache of each enabled texture. */
177 int maxEnabledUnit
= ctx
->Texture
._MaxEnabledTexImageUnit
;
178 for (int i
= 0; i
<= maxEnabledUnit
; i
++) {
179 if (!ctx
->Texture
.Unit
[i
]._Current
)
181 tex_obj
= intel_texture_object(ctx
->Texture
.Unit
[i
]._Current
);
182 if (!tex_obj
|| !tex_obj
->mt
)
184 intel_miptree_all_slices_resolve_depth(brw
, tex_obj
->mt
);
185 intel_miptree_resolve_color(brw
, tex_obj
->mt
);
186 brw_render_cache_set_check_flush(brw
, tex_obj
->mt
->bo
);
189 _mesa_lock_context_textures(ctx
);
192 #define flushFront(screen) ((screen)->image.loader ? (screen)->image.loader->flushFrontBuffer : (screen)->dri2.loader->flushFrontBuffer)
195 intel_flush_front(struct gl_context
*ctx
)
197 struct brw_context
*brw
= brw_context(ctx
);
198 __DRIcontext
*driContext
= brw
->driContext
;
199 __DRIdrawable
*driDrawable
= driContext
->driDrawablePriv
;
200 __DRIscreen
*const screen
= brw
->intelScreen
->driScrnPriv
;
202 if (brw
->front_buffer_dirty
&& _mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
203 if (flushFront(screen
) && driDrawable
&&
204 driDrawable
->loaderPrivate
) {
206 /* Resolve before flushing FAKE_FRONT_LEFT to FRONT_LEFT.
208 * This potentially resolves both front and back buffer. It
209 * is unnecessary to resolve the back, but harms nothing except
210 * performance. And no one cares about front-buffer render
213 intel_resolve_for_dri2_flush(brw
, driDrawable
);
214 intel_batchbuffer_flush(brw
);
216 flushFront(screen
)(driDrawable
, driDrawable
->loaderPrivate
);
218 /* We set the dirty bit in intel_prepare_render() if we're
219 * front buffer rendering once we get there.
221 brw
->front_buffer_dirty
= false;
227 intel_glFlush(struct gl_context
*ctx
)
229 struct brw_context
*brw
= brw_context(ctx
);
231 intel_batchbuffer_flush(brw
);
232 intel_flush_front(ctx
);
233 if (brw_is_front_buffer_drawing(ctx
->DrawBuffer
))
234 brw
->need_throttle
= true;
238 intel_finish(struct gl_context
* ctx
)
240 struct brw_context
*brw
= brw_context(ctx
);
244 if (brw
->batch
.last_bo
)
245 drm_intel_bo_wait_rendering(brw
->batch
.last_bo
);
249 brw_init_driver_functions(struct brw_context
*brw
,
250 struct dd_function_table
*functions
)
252 _mesa_init_driver_functions(functions
);
254 /* GLX uses DRI2 invalidate events to handle window resizing.
255 * Unfortunately, EGL does not - libEGL is written in XCB (not Xlib),
256 * which doesn't provide a mechanism for snooping the event queues.
258 * So EGL still relies on viewport hacks to handle window resizing.
259 * This should go away with DRI3000.
261 if (!brw
->driContext
->driScreenPriv
->dri2
.useInvalidate
)
262 functions
->Viewport
= intel_viewport
;
264 functions
->Flush
= intel_glFlush
;
265 functions
->Finish
= intel_finish
;
266 functions
->GetString
= intel_get_string
;
267 functions
->UpdateState
= intel_update_state
;
269 intelInitTextureFuncs(functions
);
270 intelInitTextureImageFuncs(functions
);
271 intelInitTextureSubImageFuncs(functions
);
272 intelInitTextureCopyImageFuncs(functions
);
273 intelInitCopyImageFuncs(functions
);
274 intelInitClearFuncs(functions
);
275 intelInitBufferFuncs(functions
);
276 intelInitPixelFuncs(functions
);
277 intelInitBufferObjectFuncs(functions
);
278 intel_init_syncobj_functions(functions
);
279 brw_init_object_purgeable_functions(functions
);
281 brwInitFragProgFuncs( functions
);
282 brw_init_common_queryobj_functions(functions
);
284 gen6_init_queryobj_functions(functions
);
286 gen4_init_queryobj_functions(functions
);
288 functions
->QuerySamplesForFormat
= brw_query_samples_for_format
;
290 functions
->NewTransformFeedback
= brw_new_transform_feedback
;
291 functions
->DeleteTransformFeedback
= brw_delete_transform_feedback
;
292 functions
->GetTransformFeedbackVertexCount
=
293 brw_get_transform_feedback_vertex_count
;
295 functions
->BeginTransformFeedback
= gen7_begin_transform_feedback
;
296 functions
->EndTransformFeedback
= gen7_end_transform_feedback
;
297 functions
->PauseTransformFeedback
= gen7_pause_transform_feedback
;
298 functions
->ResumeTransformFeedback
= gen7_resume_transform_feedback
;
300 functions
->BeginTransformFeedback
= brw_begin_transform_feedback
;
301 functions
->EndTransformFeedback
= brw_end_transform_feedback
;
305 functions
->GetSamplePosition
= gen6_get_sample_position
;
309 brw_initialize_context_constants(struct brw_context
*brw
)
311 struct gl_context
*ctx
= &brw
->ctx
;
313 unsigned max_samplers
=
314 brw
->gen
>= 8 || brw
->is_haswell
? BRW_MAX_TEX_UNIT
: 16;
316 ctx
->Const
.QueryCounterBits
.Timestamp
= 36;
318 ctx
->Const
.StripTextureBorder
= true;
320 ctx
->Const
.MaxDualSourceDrawBuffers
= 1;
321 ctx
->Const
.MaxDrawBuffers
= BRW_MAX_DRAW_BUFFERS
;
322 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
= max_samplers
;
323 ctx
->Const
.MaxTextureCoordUnits
= 8; /* Mesa limit */
324 ctx
->Const
.MaxTextureUnits
=
325 MIN2(ctx
->Const
.MaxTextureCoordUnits
,
326 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
);
327 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= max_samplers
;
329 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxTextureImageUnits
= max_samplers
;
331 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxTextureImageUnits
= 0;
332 if (_mesa_extension_override_enables
.ARB_compute_shader
) {
333 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxTextureImageUnits
= BRW_MAX_TEX_UNIT
;
334 ctx
->Const
.MaxUniformBufferBindings
+= 12;
336 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxTextureImageUnits
= 0;
338 ctx
->Const
.MaxCombinedTextureImageUnits
=
339 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
+
340 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
+
341 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxTextureImageUnits
+
342 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxTextureImageUnits
;
344 ctx
->Const
.MaxTextureLevels
= 14; /* 8192 */
345 if (ctx
->Const
.MaxTextureLevels
> MAX_TEXTURE_LEVELS
)
346 ctx
->Const
.MaxTextureLevels
= MAX_TEXTURE_LEVELS
;
347 ctx
->Const
.Max3DTextureLevels
= 12; /* 2048 */
348 ctx
->Const
.MaxCubeTextureLevels
= 14; /* 8192 */
349 ctx
->Const
.MaxTextureMbytes
= 1536;
352 ctx
->Const
.MaxArrayTextureLayers
= 2048;
354 ctx
->Const
.MaxArrayTextureLayers
= 512;
356 ctx
->Const
.MaxTextureRectSize
= 1 << 12;
358 ctx
->Const
.MaxTextureMaxAnisotropy
= 16.0;
360 ctx
->Const
.MaxRenderbufferSize
= 8192;
362 /* Hardware only supports a limited number of transform feedback buffers.
363 * So we need to override the Mesa default (which is based only on software
366 ctx
->Const
.MaxTransformFeedbackBuffers
= BRW_MAX_SOL_BUFFERS
;
368 /* On Gen6, in the worst case, we use up one binding table entry per
369 * transform feedback component (see comments above the definition of
370 * BRW_MAX_SOL_BINDINGS, in brw_context.h), so we need to advertise a value
371 * for MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS equal to
372 * BRW_MAX_SOL_BINDINGS.
374 * In "separate components" mode, we need to divide this value by
375 * BRW_MAX_SOL_BUFFERS, so that the total number of binding table entries
376 * used up by all buffers will not exceed BRW_MAX_SOL_BINDINGS.
378 ctx
->Const
.MaxTransformFeedbackInterleavedComponents
= BRW_MAX_SOL_BINDINGS
;
379 ctx
->Const
.MaxTransformFeedbackSeparateComponents
=
380 BRW_MAX_SOL_BINDINGS
/ BRW_MAX_SOL_BUFFERS
;
382 ctx
->Const
.AlwaysUseGetTransformFeedbackVertexCount
= true;
385 const int *msaa_modes
= intel_supported_msaa_modes(brw
->intelScreen
);
386 const int clamp_max_samples
=
387 driQueryOptioni(&brw
->optionCache
, "clamp_max_samples");
389 if (clamp_max_samples
< 0) {
390 max_samples
= msaa_modes
[0];
392 /* Select the largest supported MSAA mode that does not exceed
396 for (int i
= 0; msaa_modes
[i
] != 0; ++i
) {
397 if (msaa_modes
[i
] <= clamp_max_samples
) {
398 max_samples
= msaa_modes
[i
];
404 ctx
->Const
.MaxSamples
= max_samples
;
405 ctx
->Const
.MaxColorTextureSamples
= max_samples
;
406 ctx
->Const
.MaxDepthTextureSamples
= max_samples
;
407 ctx
->Const
.MaxIntegerSamples
= max_samples
;
410 ctx
->Const
.MaxProgramTextureGatherComponents
= 4;
411 else if (brw
->gen
== 6)
412 ctx
->Const
.MaxProgramTextureGatherComponents
= 1;
414 ctx
->Const
.MinLineWidth
= 1.0;
415 ctx
->Const
.MinLineWidthAA
= 1.0;
416 ctx
->Const
.MaxLineWidth
= 5.0;
417 ctx
->Const
.MaxLineWidthAA
= 5.0;
418 ctx
->Const
.LineWidthGranularity
= 0.5;
420 ctx
->Const
.MinPointSize
= 1.0;
421 ctx
->Const
.MinPointSizeAA
= 1.0;
422 ctx
->Const
.MaxPointSize
= 255.0;
423 ctx
->Const
.MaxPointSizeAA
= 255.0;
424 ctx
->Const
.PointSizeGranularity
= 1.0;
426 if (brw
->gen
>= 5 || brw
->is_g4x
)
427 ctx
->Const
.MaxClipPlanes
= 8;
429 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxNativeInstructions
= 16 * 1024;
430 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAluInstructions
= 0;
431 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTexInstructions
= 0;
432 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTexIndirections
= 0;
433 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxNativeAluInstructions
= 0;
434 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxNativeTexInstructions
= 0;
435 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxNativeTexIndirections
= 0;
436 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxNativeAttribs
= 16;
437 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxNativeTemps
= 256;
438 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxNativeAddressRegs
= 1;
439 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxNativeParameters
= 1024;
440 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxEnvParams
=
441 MIN2(ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxNativeParameters
,
442 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxEnvParams
);
444 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxNativeInstructions
= 1024;
445 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxNativeAluInstructions
= 1024;
446 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxNativeTexInstructions
= 1024;
447 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxNativeTexIndirections
= 1024;
448 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxNativeAttribs
= 12;
449 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxNativeTemps
= 256;
450 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxNativeAddressRegs
= 0;
451 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxNativeParameters
= 1024;
452 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxEnvParams
=
453 MIN2(ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxNativeParameters
,
454 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxEnvParams
);
456 /* Fragment shaders use real, 32-bit twos-complement integers for all
459 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].LowInt
.RangeMin
= 31;
460 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].LowInt
.RangeMax
= 30;
461 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].LowInt
.Precision
= 0;
462 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].HighInt
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].LowInt
;
463 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MediumInt
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].LowInt
;
466 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxAtomicCounters
= MAX_ATOMIC_COUNTERS
;
467 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAtomicCounters
= MAX_ATOMIC_COUNTERS
;
468 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxAtomicCounters
= MAX_ATOMIC_COUNTERS
;
469 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxAtomicCounters
= MAX_ATOMIC_COUNTERS
;
470 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxAtomicBuffers
= BRW_MAX_ABO
;
471 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAtomicBuffers
= BRW_MAX_ABO
;
472 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxAtomicBuffers
= BRW_MAX_ABO
;
473 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxAtomicBuffers
= BRW_MAX_ABO
;
474 ctx
->Const
.MaxCombinedAtomicBuffers
= 3 * BRW_MAX_ABO
;
477 /* Gen6 converts quads to polygon in beginning of 3D pipeline,
478 * but we're not sure how it's actually done for vertex order,
479 * that affect provoking vertex decision. Always use last vertex
480 * convention for quad primitive which works as expected for now.
483 ctx
->Const
.QuadsFollowProvokingVertexConvention
= false;
485 ctx
->Const
.NativeIntegers
= true;
486 ctx
->Const
.UniformBooleanTrue
= 1;
488 /* From the gen4 PRM, volume 4 page 127:
490 * "For SURFTYPE_BUFFER non-rendertarget surfaces, this field specifies
491 * the base address of the first element of the surface, computed in
492 * software by adding the surface base address to the byte offset of
493 * the element in the buffer."
495 * However, unaligned accesses are slower, so enforce buffer alignment.
497 ctx
->Const
.UniformBufferOffsetAlignment
= 16;
498 ctx
->Const
.TextureBufferOffsetAlignment
= 16;
501 ctx
->Const
.MaxVarying
= 32;
502 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 128;
503 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxInputComponents
= 64;
504 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxOutputComponents
= 128;
505 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
= 128;
508 /* We want the GLSL compiler to emit code that uses condition codes */
509 for (int i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
510 ctx
->Const
.ShaderCompilerOptions
[i
].MaxIfDepth
= brw
->gen
< 6 ? 16 : UINT_MAX
;
511 ctx
->Const
.ShaderCompilerOptions
[i
].EmitCondCodes
= true;
512 ctx
->Const
.ShaderCompilerOptions
[i
].EmitNoNoise
= true;
513 ctx
->Const
.ShaderCompilerOptions
[i
].EmitNoMainReturn
= true;
514 ctx
->Const
.ShaderCompilerOptions
[i
].EmitNoIndirectInput
= true;
515 ctx
->Const
.ShaderCompilerOptions
[i
].EmitNoIndirectOutput
=
516 (i
== MESA_SHADER_FRAGMENT
);
517 ctx
->Const
.ShaderCompilerOptions
[i
].EmitNoIndirectTemp
=
518 (i
== MESA_SHADER_FRAGMENT
);
519 ctx
->Const
.ShaderCompilerOptions
[i
].EmitNoIndirectUniform
= false;
520 ctx
->Const
.ShaderCompilerOptions
[i
].LowerClipDistance
= true;
523 ctx
->Const
.ShaderCompilerOptions
[MESA_SHADER_VERTEX
].OptimizeForAOS
= true;
524 ctx
->Const
.ShaderCompilerOptions
[MESA_SHADER_GEOMETRY
].OptimizeForAOS
= true;
526 /* ARB_viewport_array */
527 if (brw
->gen
>= 7 && ctx
->API
== API_OPENGL_CORE
) {
528 ctx
->Const
.MaxViewports
= GEN7_NUM_VIEWPORTS
;
529 ctx
->Const
.ViewportSubpixelBits
= 0;
531 /* Cast to float before negating becuase MaxViewportWidth is unsigned.
533 ctx
->Const
.ViewportBounds
.Min
= -(float)ctx
->Const
.MaxViewportWidth
;
534 ctx
->Const
.ViewportBounds
.Max
= ctx
->Const
.MaxViewportWidth
;
537 /* ARB_gpu_shader5 */
539 ctx
->Const
.MaxVertexStreams
= MIN2(4, MAX_VERTEX_STREAMS
);
543 * Process driconf (drirc) options, setting appropriate context flags.
545 * intelInitExtensions still pokes at optionCache directly, in order to
546 * avoid advertising various extensions. No flags are set, so it makes
547 * sense to continue doing that there.
550 brw_process_driconf_options(struct brw_context
*brw
)
552 struct gl_context
*ctx
= &brw
->ctx
;
554 driOptionCache
*options
= &brw
->optionCache
;
555 driParseConfigFiles(options
, &brw
->intelScreen
->optionCache
,
556 brw
->driContext
->driScreenPriv
->myNum
, "i965");
558 int bo_reuse_mode
= driQueryOptioni(options
, "bo_reuse");
559 switch (bo_reuse_mode
) {
560 case DRI_CONF_BO_REUSE_DISABLED
:
562 case DRI_CONF_BO_REUSE_ALL
:
563 intel_bufmgr_gem_enable_reuse(brw
->bufmgr
);
567 if (!driQueryOptionb(options
, "hiz")) {
568 brw
->has_hiz
= false;
569 /* On gen6, you can only do separate stencil with HIZ. */
571 brw
->has_separate_stencil
= false;
574 if (driQueryOptionb(options
, "always_flush_batch")) {
575 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
576 brw
->always_flush_batch
= true;
579 if (driQueryOptionb(options
, "always_flush_cache")) {
580 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
581 brw
->always_flush_cache
= true;
584 if (driQueryOptionb(options
, "disable_throttling")) {
585 fprintf(stderr
, "disabling flush throttling\n");
586 brw
->disable_throttling
= true;
589 brw
->disable_derivative_optimization
=
590 driQueryOptionb(&brw
->optionCache
, "disable_derivative_optimization");
592 brw
->precompile
= driQueryOptionb(&brw
->optionCache
, "shader_precompile");
594 ctx
->Const
.ForceGLSLExtensionsWarn
=
595 driQueryOptionb(options
, "force_glsl_extensions_warn");
597 ctx
->Const
.DisableGLSLLineContinuations
=
598 driQueryOptionb(options
, "disable_glsl_line_continuations");
600 ctx
->Const
.AllowGLSLExtensionDirectiveMidShader
=
601 driQueryOptionb(options
, "allow_glsl_extension_directive_midshader");
605 brwCreateContext(gl_api api
,
606 const struct gl_config
*mesaVis
,
607 __DRIcontext
*driContextPriv
,
608 unsigned major_version
,
609 unsigned minor_version
,
612 unsigned *dri_ctx_error
,
613 void *sharedContextPrivate
)
615 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
616 struct gl_context
*shareCtx
= (struct gl_context
*) sharedContextPrivate
;
617 struct intel_screen
*screen
= sPriv
->driverPrivate
;
618 const struct brw_device_info
*devinfo
= screen
->devinfo
;
619 struct dd_function_table functions
;
621 /* Only allow the __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS flag if the kernel
622 * provides us with context reset notifications.
624 uint32_t allowed_flags
= __DRI_CTX_FLAG_DEBUG
625 | __DRI_CTX_FLAG_FORWARD_COMPATIBLE
;
627 if (screen
->has_context_reset_notification
)
628 allowed_flags
|= __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
;
630 if (flags
& ~allowed_flags
) {
631 *dri_ctx_error
= __DRI_CTX_ERROR_UNKNOWN_FLAG
;
635 struct brw_context
*brw
= rzalloc(NULL
, struct brw_context
);
637 fprintf(stderr
, "%s: failed to alloc context\n", __FUNCTION__
);
638 *dri_ctx_error
= __DRI_CTX_ERROR_NO_MEMORY
;
642 driContextPriv
->driverPrivate
= brw
;
643 brw
->driContext
= driContextPriv
;
644 brw
->intelScreen
= screen
;
645 brw
->bufmgr
= screen
->bufmgr
;
647 brw
->gen
= devinfo
->gen
;
648 brw
->gt
= devinfo
->gt
;
649 brw
->is_g4x
= devinfo
->is_g4x
;
650 brw
->is_baytrail
= devinfo
->is_baytrail
;
651 brw
->is_haswell
= devinfo
->is_haswell
;
652 brw
->is_cherryview
= devinfo
->is_cherryview
;
653 brw
->has_llc
= devinfo
->has_llc
;
654 brw
->has_hiz
= devinfo
->has_hiz_and_separate_stencil
;
655 brw
->has_separate_stencil
= devinfo
->has_hiz_and_separate_stencil
;
656 brw
->has_pln
= devinfo
->has_pln
;
657 brw
->has_compr4
= devinfo
->has_compr4
;
658 brw
->has_surface_tile_offset
= devinfo
->has_surface_tile_offset
;
659 brw
->has_negative_rhw_bug
= devinfo
->has_negative_rhw_bug
;
660 brw
->needs_unlit_centroid_workaround
=
661 devinfo
->needs_unlit_centroid_workaround
;
663 brw
->must_use_separate_stencil
= screen
->hw_must_use_separate_stencil
;
664 brw
->has_swizzling
= screen
->hw_has_swizzling
;
666 brw
->vs
.base
.stage
= MESA_SHADER_VERTEX
;
667 brw
->gs
.base
.stage
= MESA_SHADER_GEOMETRY
;
668 brw
->wm
.base
.stage
= MESA_SHADER_FRAGMENT
;
670 gen8_init_vtable_surface_functions(brw
);
671 brw
->vtbl
.emit_depth_stencil_hiz
= gen8_emit_depth_stencil_hiz
;
672 } else if (brw
->gen
>= 7) {
673 gen7_init_vtable_surface_functions(brw
);
674 brw
->vtbl
.emit_depth_stencil_hiz
= gen7_emit_depth_stencil_hiz
;
676 gen4_init_vtable_surface_functions(brw
);
677 brw
->vtbl
.emit_depth_stencil_hiz
= brw_emit_depth_stencil_hiz
;
680 brw_init_driver_functions(brw
, &functions
);
683 functions
.GetGraphicsResetStatus
= brw_get_graphics_reset_status
;
685 struct gl_context
*ctx
= &brw
->ctx
;
687 if (!_mesa_initialize_context(ctx
, api
, mesaVis
, shareCtx
, &functions
)) {
688 *dri_ctx_error
= __DRI_CTX_ERROR_NO_MEMORY
;
689 fprintf(stderr
, "%s: failed to init mesa context\n", __FUNCTION__
);
690 intelDestroyContext(driContextPriv
);
694 driContextSetFlags(ctx
, flags
);
696 /* Initialize the software rasterizer and helper modules.
698 * As of GL 3.1 core, the gen4+ driver doesn't need the swrast context for
699 * software fallbacks (which we have to support on legacy GL to do weird
700 * glDrawPixels(), glBitmap(), and other functions).
702 if (api
!= API_OPENGL_CORE
&& api
!= API_OPENGLES2
) {
703 _swrast_CreateContext(ctx
);
706 _vbo_CreateContext(ctx
);
707 if (ctx
->swrast_context
) {
708 _tnl_CreateContext(ctx
);
709 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= _tnl_run_pipeline
;
710 _swsetup_CreateContext(ctx
);
712 /* Configure swrast to match hardware characteristics: */
713 _swrast_allow_pixel_fog(ctx
, false);
714 _swrast_allow_vertex_fog(ctx
, true);
717 _mesa_meta_init(ctx
);
719 brw_process_driconf_options(brw
);
720 brw_process_intel_debug_variable(brw
);
721 brw_initialize_context_constants(brw
);
723 ctx
->Const
.ResetStrategy
= notify_reset
724 ? GL_LOSE_CONTEXT_ON_RESET_ARB
: GL_NO_RESET_NOTIFICATION_ARB
;
726 /* Reinitialize the context point state. It depends on ctx->Const values. */
727 _mesa_init_point(ctx
);
731 intel_batchbuffer_init(brw
);
734 /* Create a new hardware context. Using a hardware context means that
735 * our GPU state will be saved/restored on context switch, allowing us
736 * to assume that the GPU is in the same state we left it in.
738 * This is required for transform feedback buffer offsets, query objects,
739 * and also allows us to reduce how much state we have to emit.
741 brw
->hw_ctx
= drm_intel_gem_context_create(brw
->bufmgr
);
744 fprintf(stderr
, "Gen6+ requires Kernel 3.6 or later.\n");
745 intelDestroyContext(driContextPriv
);
752 intelInitExtensions(ctx
);
754 brw_init_surface_formats(brw
);
756 brw
->max_vs_threads
= devinfo
->max_vs_threads
;
757 brw
->max_gs_threads
= devinfo
->max_gs_threads
;
758 brw
->max_wm_threads
= devinfo
->max_wm_threads
;
759 brw
->urb
.size
= devinfo
->urb
.size
;
760 brw
->urb
.min_vs_entries
= devinfo
->urb
.min_vs_entries
;
761 brw
->urb
.max_vs_entries
= devinfo
->urb
.max_vs_entries
;
762 brw
->urb
.max_gs_entries
= devinfo
->urb
.max_gs_entries
;
764 /* Estimate the size of the mappable aperture into the GTT. There's an
765 * ioctl to get the whole GTT size, but not one to get the mappable subset.
766 * It turns out it's basically always 256MB, though some ancient hardware
769 uint32_t gtt_size
= 256 * 1024 * 1024;
771 /* We don't want to map two objects such that a memcpy between them would
772 * just fault one mapping in and then the other over and over forever. So
773 * we would need to divide the GTT size by 2. Additionally, some GTT is
774 * taken up by things like the framebuffer and the ringbuffer and such, so
775 * be more conservative.
777 brw
->max_gtt_map_object_size
= gtt_size
/ 4;
780 brw
->urb
.gen6_gs_previously_active
= false;
782 brw
->prim_restart
.in_progress
= false;
783 brw
->prim_restart
.enable_cut_index
= false;
784 brw
->gs
.enabled
= false;
785 brw
->sf
.viewport_transform_enable
= true;
787 ctx
->VertexProgram
._MaintainTnlProgram
= true;
788 ctx
->FragmentProgram
._MaintainTexEnvProgram
= true;
790 brw_draw_init( brw
);
792 if ((flags
& __DRI_CTX_FLAG_DEBUG
) != 0) {
793 /* Turn on some extra GL_ARB_debug_output generation. */
794 brw
->perf_debug
= true;
797 if ((flags
& __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
) != 0)
798 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB
;
800 if (INTEL_DEBUG
& DEBUG_SHADER_TIME
)
801 brw_init_shader_time(brw
);
803 _mesa_compute_version(ctx
);
805 _mesa_initialize_dispatch_tables(ctx
);
806 _mesa_initialize_vbo_vtxfmt(ctx
);
808 if (ctx
->Extensions
.AMD_performance_monitor
) {
809 brw_init_performance_monitors(brw
);
812 vbo_use_buffer_objects(ctx
);
813 vbo_always_unmap_buffers(ctx
);
819 intelDestroyContext(__DRIcontext
* driContextPriv
)
821 struct brw_context
*brw
=
822 (struct brw_context
*) driContextPriv
->driverPrivate
;
823 struct gl_context
*ctx
= &brw
->ctx
;
825 assert(brw
); /* should never be null */
829 /* Dump a final BMP in case the application doesn't call SwapBuffers */
830 if (INTEL_DEBUG
& DEBUG_AUB
) {
831 intel_batchbuffer_flush(brw
);
832 aub_dump_bmp(&brw
->ctx
);
835 _mesa_meta_free(&brw
->ctx
);
836 brw_meta_fast_clear_free(brw
);
838 if (INTEL_DEBUG
& DEBUG_SHADER_TIME
) {
839 /* Force a report. */
840 brw
->shader_time
.report_time
= 0;
842 brw_collect_and_report_shader_time(brw
);
843 brw_destroy_shader_time(brw
);
846 brw_destroy_state(brw
);
847 brw_draw_destroy(brw
);
849 drm_intel_bo_unreference(brw
->curbe
.curbe_bo
);
851 drm_intel_gem_context_destroy(brw
->hw_ctx
);
853 if (ctx
->swrast_context
) {
854 _swsetup_DestroyContext(&brw
->ctx
);
855 _tnl_DestroyContext(&brw
->ctx
);
857 _vbo_DestroyContext(&brw
->ctx
);
859 if (ctx
->swrast_context
)
860 _swrast_DestroyContext(&brw
->ctx
);
862 intel_batchbuffer_free(brw
);
864 drm_intel_bo_unreference(brw
->first_post_swapbuffers_batch
);
865 brw
->first_post_swapbuffers_batch
= NULL
;
867 driDestroyOptionCache(&brw
->optionCache
);
869 /* free the Mesa context */
870 _mesa_free_context_data(&brw
->ctx
);
873 driContextPriv
->driverPrivate
= NULL
;
877 intelUnbindContext(__DRIcontext
* driContextPriv
)
879 /* Unset current context and dispath table */
880 _mesa_make_current(NULL
, NULL
, NULL
);
886 * Fixes up the context for GLES23 with our default-to-sRGB-capable behavior
887 * on window system framebuffers.
889 * Desktop GL is fairly reasonable in its handling of sRGB: You can ask if
890 * your renderbuffer can do sRGB encode, and you can flip a switch that does
891 * sRGB encode if the renderbuffer can handle it. You can ask specifically
892 * for a visual where you're guaranteed to be capable, but it turns out that
893 * everyone just makes all their ARGB8888 visuals capable and doesn't offer
894 * incapable ones, becuase there's no difference between the two in resources
895 * used. Applications thus get built that accidentally rely on the default
896 * visual choice being sRGB, so we make ours sRGB capable. Everything sounds
899 * But for GLES2/3, they decided that it was silly to not turn on sRGB encode
900 * for sRGB renderbuffers you made with the GL_EXT_texture_sRGB equivalent.
901 * So they removed the enable knob and made it "if the renderbuffer is sRGB
902 * capable, do sRGB encode". Then, for your window system renderbuffers, you
903 * can ask for sRGB visuals and get sRGB encode, or not ask for sRGB visuals
904 * and get no sRGB encode (assuming that both kinds of visual are available).
905 * Thus our choice to support sRGB by default on our visuals for desktop would
906 * result in broken rendering of GLES apps that aren't expecting sRGB encode.
908 * Unfortunately, renderbuffer setup happens before a context is created. So
909 * in intel_screen.c we always set up sRGB, and here, if you're a GLES2/3
910 * context (without an sRGB visual, though we don't have sRGB visuals exposed
911 * yet), we go turn that back off before anyone finds out.
914 intel_gles3_srgb_workaround(struct brw_context
*brw
,
915 struct gl_framebuffer
*fb
)
917 struct gl_context
*ctx
= &brw
->ctx
;
919 if (_mesa_is_desktop_gl(ctx
) || !fb
->Visual
.sRGBCapable
)
922 /* Some day when we support the sRGB capable bit on visuals available for
923 * GLES, we'll need to respect that and not disable things here.
925 fb
->Visual
.sRGBCapable
= false;
926 for (int i
= 0; i
< BUFFER_COUNT
; i
++) {
927 if (fb
->Attachment
[i
].Renderbuffer
&&
928 fb
->Attachment
[i
].Renderbuffer
->Format
== MESA_FORMAT_B8G8R8A8_SRGB
) {
929 fb
->Attachment
[i
].Renderbuffer
->Format
= MESA_FORMAT_B8G8R8A8_UNORM
;
935 intelMakeCurrent(__DRIcontext
* driContextPriv
,
936 __DRIdrawable
* driDrawPriv
,
937 __DRIdrawable
* driReadPriv
)
939 struct brw_context
*brw
;
940 GET_CURRENT_CONTEXT(curCtx
);
943 brw
= (struct brw_context
*) driContextPriv
->driverPrivate
;
947 /* According to the glXMakeCurrent() man page: "Pending commands to
948 * the previous context, if any, are flushed before it is released."
949 * But only flush if we're actually changing contexts.
951 if (brw_context(curCtx
) && brw_context(curCtx
) != brw
) {
955 if (driContextPriv
) {
956 struct gl_context
*ctx
= &brw
->ctx
;
957 struct gl_framebuffer
*fb
, *readFb
;
959 if (driDrawPriv
== NULL
&& driReadPriv
== NULL
) {
960 fb
= _mesa_get_incomplete_framebuffer();
961 readFb
= _mesa_get_incomplete_framebuffer();
963 fb
= driDrawPriv
->driverPrivate
;
964 readFb
= driReadPriv
->driverPrivate
;
965 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
966 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
969 /* The sRGB workaround changes the renderbuffer's format. We must change
970 * the format before the renderbuffer's miptree get's allocated, otherwise
971 * the formats of the renderbuffer and its miptree will differ.
973 intel_gles3_srgb_workaround(brw
, fb
);
974 intel_gles3_srgb_workaround(brw
, readFb
);
976 /* If the context viewport hasn't been initialized, force a call out to
977 * the loader to get buffers so we have a drawable size for the initial
979 if (!brw
->ctx
.ViewportInitialized
)
980 intel_prepare_render(brw
);
982 _mesa_make_current(ctx
, fb
, readFb
);
984 _mesa_make_current(NULL
, NULL
, NULL
);
991 intel_resolve_for_dri2_flush(struct brw_context
*brw
,
992 __DRIdrawable
*drawable
)
995 /* MSAA and fast color clear are not supported, so don't waste time
996 * checking whether a resolve is needed.
1001 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1002 struct intel_renderbuffer
*rb
;
1004 /* Usually, only the back buffer will need to be downsampled. However,
1005 * the front buffer will also need it if the user has rendered into it.
1007 static const gl_buffer_index buffers
[2] = {
1012 for (int i
= 0; i
< 2; ++i
) {
1013 rb
= intel_get_renderbuffer(fb
, buffers
[i
]);
1014 if (rb
== NULL
|| rb
->mt
== NULL
)
1016 if (rb
->mt
->num_samples
<= 1)
1017 intel_miptree_resolve_color(brw
, rb
->mt
);
1019 intel_renderbuffer_downsample(brw
, rb
);
1024 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
1026 return _mesa_get_format_bytes(intel_rb_format(rb
)) * 8;
1030 intel_query_dri2_buffers(struct brw_context
*brw
,
1031 __DRIdrawable
*drawable
,
1032 __DRIbuffer
**buffers
,
1036 intel_process_dri2_buffer(struct brw_context
*brw
,
1037 __DRIdrawable
*drawable
,
1038 __DRIbuffer
*buffer
,
1039 struct intel_renderbuffer
*rb
,
1040 const char *buffer_name
);
1043 intel_update_image_buffers(struct brw_context
*brw
, __DRIdrawable
*drawable
);
1046 intel_update_dri2_buffers(struct brw_context
*brw
, __DRIdrawable
*drawable
)
1048 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1049 struct intel_renderbuffer
*rb
;
1050 __DRIbuffer
*buffers
= NULL
;
1052 const char *region_name
;
1054 /* Set this up front, so that in case our buffers get invalidated
1055 * while we're getting new buffers, we don't clobber the stamp and
1056 * thus ignore the invalidate. */
1057 drawable
->lastStamp
= drawable
->dri2
.stamp
;
1059 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
1060 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
1062 intel_query_dri2_buffers(brw
, drawable
, &buffers
, &count
);
1064 if (buffers
== NULL
)
1067 for (i
= 0; i
< count
; i
++) {
1068 switch (buffers
[i
].attachment
) {
1069 case __DRI_BUFFER_FRONT_LEFT
:
1070 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
1071 region_name
= "dri2 front buffer";
1074 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
1075 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
1076 region_name
= "dri2 fake front buffer";
1079 case __DRI_BUFFER_BACK_LEFT
:
1080 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
1081 region_name
= "dri2 back buffer";
1084 case __DRI_BUFFER_DEPTH
:
1085 case __DRI_BUFFER_HIZ
:
1086 case __DRI_BUFFER_DEPTH_STENCIL
:
1087 case __DRI_BUFFER_STENCIL
:
1088 case __DRI_BUFFER_ACCUM
:
1091 "unhandled buffer attach event, attachment type %d\n",
1092 buffers
[i
].attachment
);
1096 intel_process_dri2_buffer(brw
, drawable
, &buffers
[i
], rb
, region_name
);
1102 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
1104 struct brw_context
*brw
= context
->driverPrivate
;
1105 __DRIscreen
*screen
= brw
->intelScreen
->driScrnPriv
;
1107 /* Set this up front, so that in case our buffers get invalidated
1108 * while we're getting new buffers, we don't clobber the stamp and
1109 * thus ignore the invalidate. */
1110 drawable
->lastStamp
= drawable
->dri2
.stamp
;
1112 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
1113 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
1115 if (screen
->image
.loader
)
1116 intel_update_image_buffers(brw
, drawable
);
1118 intel_update_dri2_buffers(brw
, drawable
);
1120 driUpdateFramebufferSize(&brw
->ctx
, drawable
);
1124 * intel_prepare_render should be called anywhere that curent read/drawbuffer
1125 * state is required.
1128 intel_prepare_render(struct brw_context
*brw
)
1130 struct gl_context
*ctx
= &brw
->ctx
;
1131 __DRIcontext
*driContext
= brw
->driContext
;
1132 __DRIdrawable
*drawable
;
1134 drawable
= driContext
->driDrawablePriv
;
1135 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
1136 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
1137 intel_update_renderbuffers(driContext
, drawable
);
1138 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
1141 drawable
= driContext
->driReadablePriv
;
1142 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
1143 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
1144 intel_update_renderbuffers(driContext
, drawable
);
1145 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
1148 /* If we're currently rendering to the front buffer, the rendering
1149 * that will happen next will probably dirty the front buffer. So
1150 * mark it as dirty here.
1152 if (brw_is_front_buffer_drawing(ctx
->DrawBuffer
))
1153 brw
->front_buffer_dirty
= true;
1155 /* Wait for the swapbuffers before the one we just emitted, so we
1156 * don't get too many swaps outstanding for apps that are GPU-heavy
1157 * but not CPU-heavy.
1159 * We're using intelDRI2Flush (called from the loader before
1160 * swapbuffer) and glFlush (for front buffer rendering) as the
1161 * indicator that a frame is done and then throttle when we get
1162 * here as we prepare to render the next frame. At this point for
1163 * round trips for swap/copy and getting new buffers are done and
1164 * we'll spend less time waiting on the GPU.
1166 * Unfortunately, we don't have a handle to the batch containing
1167 * the swap, and getting our hands on that doesn't seem worth it,
1168 * so we just us the first batch we emitted after the last swap.
1170 if (brw
->need_throttle
&& brw
->first_post_swapbuffers_batch
) {
1171 if (!brw
->disable_throttling
)
1172 drm_intel_bo_wait_rendering(brw
->first_post_swapbuffers_batch
);
1173 drm_intel_bo_unreference(brw
->first_post_swapbuffers_batch
);
1174 brw
->first_post_swapbuffers_batch
= NULL
;
1175 brw
->need_throttle
= false;
1180 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
1182 * To determine which DRI buffers to request, examine the renderbuffers
1183 * attached to the drawable's framebuffer. Then request the buffers with
1184 * DRI2GetBuffers() or DRI2GetBuffersWithFormat().
1186 * This is called from intel_update_renderbuffers().
1188 * \param drawable Drawable whose buffers are queried.
1189 * \param buffers [out] List of buffers returned by DRI2 query.
1190 * \param buffer_count [out] Number of buffers returned.
1192 * \see intel_update_renderbuffers()
1193 * \see DRI2GetBuffers()
1194 * \see DRI2GetBuffersWithFormat()
1197 intel_query_dri2_buffers(struct brw_context
*brw
,
1198 __DRIdrawable
*drawable
,
1199 __DRIbuffer
**buffers
,
1202 __DRIscreen
*screen
= brw
->intelScreen
->driScrnPriv
;
1203 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1205 unsigned attachments
[8];
1207 struct intel_renderbuffer
*front_rb
;
1208 struct intel_renderbuffer
*back_rb
;
1210 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
1211 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
1213 memset(attachments
, 0, sizeof(attachments
));
1214 if ((brw_is_front_buffer_drawing(fb
) ||
1215 brw_is_front_buffer_reading(fb
) ||
1216 !back_rb
) && front_rb
) {
1217 /* If a fake front buffer is in use, then querying for
1218 * __DRI_BUFFER_FRONT_LEFT will cause the server to copy the image from
1219 * the real front buffer to the fake front buffer. So before doing the
1220 * query, we need to make sure all the pending drawing has landed in the
1221 * real front buffer.
1223 intel_batchbuffer_flush(brw
);
1224 intel_flush_front(&brw
->ctx
);
1226 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
1227 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
1228 } else if (front_rb
&& brw
->front_buffer_dirty
) {
1229 /* We have pending front buffer rendering, but we aren't querying for a
1230 * front buffer. If the front buffer we have is a fake front buffer,
1231 * the X server is going to throw it away when it processes the query.
1232 * So before doing the query, make sure all the pending drawing has
1233 * landed in the real front buffer.
1235 intel_batchbuffer_flush(brw
);
1236 intel_flush_front(&brw
->ctx
);
1240 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
1241 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
1244 assert(i
<= ARRAY_SIZE(attachments
));
1246 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
1251 drawable
->loaderPrivate
);
1255 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
1257 * This is called from intel_update_renderbuffers().
1260 * DRI buffers whose attachment point is DRI2BufferStencil or
1261 * DRI2BufferDepthStencil are handled as special cases.
1263 * \param buffer_name is a human readable name, such as "dri2 front buffer",
1264 * that is passed to drm_intel_bo_gem_create_from_name().
1266 * \see intel_update_renderbuffers()
1269 intel_process_dri2_buffer(struct brw_context
*brw
,
1270 __DRIdrawable
*drawable
,
1271 __DRIbuffer
*buffer
,
1272 struct intel_renderbuffer
*rb
,
1273 const char *buffer_name
)
1275 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1281 unsigned num_samples
= rb
->Base
.Base
.NumSamples
;
1283 /* We try to avoid closing and reopening the same BO name, because the first
1284 * use of a mapping of the buffer involves a bunch of page faulting which is
1285 * moderately expensive.
1287 struct intel_mipmap_tree
*last_mt
;
1288 if (num_samples
== 0)
1291 last_mt
= rb
->singlesample_mt
;
1293 uint32_t old_name
= 0;
1295 /* The bo already has a name because the miptree was created by a
1296 * previous call to intel_process_dri2_buffer(). If a bo already has a
1297 * name, then drm_intel_bo_flink() is a low-cost getter. It does not
1298 * create a new name.
1300 drm_intel_bo_flink(last_mt
->bo
, &old_name
);
1303 if (old_name
== buffer
->name
)
1306 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
1308 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
1309 buffer
->name
, buffer
->attachment
,
1310 buffer
->cpp
, buffer
->pitch
);
1313 intel_miptree_release(&rb
->mt
);
1314 bo
= drm_intel_bo_gem_create_from_name(brw
->bufmgr
, buffer_name
,
1318 "Failed to open BO for returned DRI2 buffer "
1319 "(%dx%d, %s, named %d).\n"
1320 "This is likely a bug in the X Server that will lead to a "
1322 drawable
->w
, drawable
->h
, buffer_name
, buffer
->name
);
1326 intel_update_winsys_renderbuffer_miptree(brw
, rb
, bo
,
1327 drawable
->w
, drawable
->h
,
1330 if (brw_is_front_buffer_drawing(fb
) &&
1331 (buffer
->attachment
== __DRI_BUFFER_FRONT_LEFT
||
1332 buffer
->attachment
== __DRI_BUFFER_FAKE_FRONT_LEFT
) &&
1333 rb
->Base
.Base
.NumSamples
> 1) {
1334 intel_renderbuffer_upsample(brw
, rb
);
1339 drm_intel_bo_unreference(bo
);
1343 * \brief Query DRI image loader to obtain a DRIdrawable's buffers.
1345 * To determine which DRI buffers to request, examine the renderbuffers
1346 * attached to the drawable's framebuffer. Then request the buffers from
1349 * This is called from intel_update_renderbuffers().
1351 * \param drawable Drawable whose buffers are queried.
1352 * \param buffers [out] List of buffers returned by DRI2 query.
1353 * \param buffer_count [out] Number of buffers returned.
1355 * \see intel_update_renderbuffers()
1359 intel_update_image_buffer(struct brw_context
*intel
,
1360 __DRIdrawable
*drawable
,
1361 struct intel_renderbuffer
*rb
,
1363 enum __DRIimageBufferMask buffer_type
)
1365 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1367 if (!rb
|| !buffer
->bo
)
1370 unsigned num_samples
= rb
->Base
.Base
.NumSamples
;
1372 /* Check and see if we're already bound to the right
1375 struct intel_mipmap_tree
*last_mt
;
1376 if (num_samples
== 0)
1379 last_mt
= rb
->singlesample_mt
;
1381 if (last_mt
&& last_mt
->bo
== buffer
->bo
)
1384 intel_update_winsys_renderbuffer_miptree(intel
, rb
, buffer
->bo
,
1385 buffer
->width
, buffer
->height
,
1388 if (brw_is_front_buffer_drawing(fb
) &&
1389 buffer_type
== __DRI_IMAGE_BUFFER_FRONT
&&
1390 rb
->Base
.Base
.NumSamples
> 1) {
1391 intel_renderbuffer_upsample(intel
, rb
);
1396 intel_update_image_buffers(struct brw_context
*brw
, __DRIdrawable
*drawable
)
1398 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1399 __DRIscreen
*screen
= brw
->intelScreen
->driScrnPriv
;
1400 struct intel_renderbuffer
*front_rb
;
1401 struct intel_renderbuffer
*back_rb
;
1402 struct __DRIimageList images
;
1403 unsigned int format
;
1404 uint32_t buffer_mask
= 0;
1406 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
1407 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
1410 format
= intel_rb_format(back_rb
);
1412 format
= intel_rb_format(front_rb
);
1416 if (front_rb
&& (brw_is_front_buffer_drawing(fb
) ||
1417 brw_is_front_buffer_reading(fb
) || !back_rb
)) {
1418 buffer_mask
|= __DRI_IMAGE_BUFFER_FRONT
;
1422 buffer_mask
|= __DRI_IMAGE_BUFFER_BACK
;
1424 (*screen
->image
.loader
->getBuffers
) (drawable
,
1425 driGLFormatToImageFormat(format
),
1426 &drawable
->dri2
.stamp
,
1427 drawable
->loaderPrivate
,
1431 if (images
.image_mask
& __DRI_IMAGE_BUFFER_FRONT
) {
1432 drawable
->w
= images
.front
->width
;
1433 drawable
->h
= images
.front
->height
;
1434 intel_update_image_buffer(brw
,
1438 __DRI_IMAGE_BUFFER_FRONT
);
1440 if (images
.image_mask
& __DRI_IMAGE_BUFFER_BACK
) {
1441 drawable
->w
= images
.back
->width
;
1442 drawable
->h
= images
.back
->height
;
1443 intel_update_image_buffer(brw
,
1447 __DRI_IMAGE_BUFFER_BACK
);