2 Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
3 Copyright (C) Intel Corp. 2006. All Rights Reserved.
4 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) 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 <keith@tungstengraphics.com>
34 #include "main/api_exec.h"
35 #include "main/context.h"
36 #include "main/fbobject.h"
37 #include "main/imports.h"
38 #include "main/macros.h"
39 #include "main/points.h"
40 #include "main/version.h"
41 #include "main/vtxfmt.h"
43 #include "vbo/vbo_context.h"
45 #include "drivers/common/driverfuncs.h"
46 #include "drivers/common/meta.h"
49 #include "brw_context.h"
50 #include "brw_defines.h"
52 #include "brw_state.h"
54 #include "intel_batchbuffer.h"
55 #include "intel_buffer_objects.h"
56 #include "intel_buffers.h"
57 #include "intel_fbo.h"
58 #include "intel_mipmap_tree.h"
59 #include "intel_pixel.h"
60 #include "intel_regions.h"
61 #include "intel_tex.h"
62 #include "intel_tex_obj.h"
64 #include "swrast_setup/swrast_setup.h"
66 #include "tnl/t_pipeline.h"
67 #include "glsl/ralloc.h"
69 /***************************************
70 * Mesa's Driver Functions
71 ***************************************/
74 brw_query_samples_for_format(struct gl_context
*ctx
, GLenum target
,
75 GLenum internalFormat
, int samples
[16])
77 struct brw_context
*brw
= brw_context(ctx
);
97 const char *const brw_vendor_string
= "Intel Open Source Technology Center";
100 brw_get_renderer_string(unsigned deviceID
)
103 static char buffer
[128];
107 #define CHIPSET(id, symbol, str) case id: chipset = str; break;
108 #include "pci_ids/i965_pci_ids.h"
110 chipset
= "Unknown Intel Chipset";
114 (void) driGetRendererString(buffer
, chipset
, 0);
118 static const GLubyte
*
119 intelGetString(struct gl_context
* ctx
, GLenum name
)
121 const struct brw_context
*const brw
= brw_context(ctx
);
125 return (GLubyte
*) brw_vendor_string
;
129 (GLubyte
*) brw_get_renderer_string(brw
->intelScreen
->deviceID
);
137 intel_viewport(struct gl_context
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
139 struct brw_context
*brw
= brw_context(ctx
);
140 __DRIcontext
*driContext
= brw
->driContext
;
147 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
148 dri2InvalidateDrawable(driContext
->driDrawablePriv
);
149 dri2InvalidateDrawable(driContext
->driReadablePriv
);
154 intelInvalidateState(struct gl_context
* ctx
, GLuint new_state
)
156 struct brw_context
*brw
= brw_context(ctx
);
158 if (ctx
->swrast_context
)
159 _swrast_InvalidateState(ctx
, new_state
);
160 _vbo_InvalidateState(ctx
, new_state
);
162 brw
->NewGLState
|= new_state
;
165 #define flushFront(screen) ((screen)->image.loader ? (screen)->image.loader->flushFrontBuffer : (screen)->dri2.loader->flushFrontBuffer)
168 intel_flush_front(struct gl_context
*ctx
)
170 struct brw_context
*brw
= brw_context(ctx
);
171 __DRIcontext
*driContext
= brw
->driContext
;
172 __DRIdrawable
*driDrawable
= driContext
->driDrawablePriv
;
173 __DRIscreen
*const screen
= brw
->intelScreen
->driScrnPriv
;
175 if (brw
->front_buffer_dirty
&& _mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
176 if (flushFront(screen
) && driDrawable
&&
177 driDrawable
->loaderPrivate
) {
179 /* Resolve before flushing FAKE_FRONT_LEFT to FRONT_LEFT.
181 * This potentially resolves both front and back buffer. It
182 * is unnecessary to resolve the back, but harms nothing except
183 * performance. And no one cares about front-buffer render
186 intel_resolve_for_dri2_flush(brw
, driDrawable
);
187 intel_batchbuffer_flush(brw
);
189 flushFront(screen
)(driDrawable
, driDrawable
->loaderPrivate
);
191 /* We set the dirty bit in intel_prepare_render() if we're
192 * front buffer rendering once we get there.
194 brw
->front_buffer_dirty
= false;
200 intel_glFlush(struct gl_context
*ctx
)
202 struct brw_context
*brw
= brw_context(ctx
);
204 intel_batchbuffer_flush(brw
);
205 intel_flush_front(ctx
);
206 if (brw
->is_front_buffer_rendering
)
207 brw
->need_throttle
= true;
211 intelFinish(struct gl_context
* ctx
)
213 struct brw_context
*brw
= brw_context(ctx
);
217 if (brw
->batch
.last_bo
)
218 drm_intel_bo_wait_rendering(brw
->batch
.last_bo
);
222 brw_init_driver_functions(struct brw_context
*brw
,
223 struct dd_function_table
*functions
)
225 _mesa_init_driver_functions(functions
);
227 /* GLX uses DRI2 invalidate events to handle window resizing.
228 * Unfortunately, EGL does not - libEGL is written in XCB (not Xlib),
229 * which doesn't provide a mechanism for snooping the event queues.
231 * So EGL still relies on viewport hacks to handle window resizing.
232 * This should go away with DRI3000.
234 if (!brw
->driContext
->driScreenPriv
->dri2
.useInvalidate
)
235 functions
->Viewport
= intel_viewport
;
237 functions
->Flush
= intel_glFlush
;
238 functions
->Finish
= intelFinish
;
239 functions
->GetString
= intelGetString
;
240 functions
->UpdateState
= intelInvalidateState
;
242 intelInitTextureFuncs(functions
);
243 intelInitTextureImageFuncs(functions
);
244 intelInitTextureSubImageFuncs(functions
);
245 intelInitTextureCopyImageFuncs(functions
);
246 intelInitClearFuncs(functions
);
247 intelInitBufferFuncs(functions
);
248 intelInitPixelFuncs(functions
);
249 intelInitBufferObjectFuncs(functions
);
250 intel_init_syncobj_functions(functions
);
251 brw_init_object_purgeable_functions(functions
);
253 brwInitFragProgFuncs( functions
);
254 brw_init_common_queryobj_functions(functions
);
256 gen6_init_queryobj_functions(functions
);
258 gen4_init_queryobj_functions(functions
);
260 functions
->QuerySamplesForFormat
= brw_query_samples_for_format
;
262 functions
->NewTransformFeedback
= brw_new_transform_feedback
;
263 functions
->DeleteTransformFeedback
= brw_delete_transform_feedback
;
264 functions
->GetTransformFeedbackVertexCount
=
265 brw_get_transform_feedback_vertex_count
;
267 functions
->BeginTransformFeedback
= gen7_begin_transform_feedback
;
268 functions
->EndTransformFeedback
= gen7_end_transform_feedback
;
269 functions
->PauseTransformFeedback
= gen7_pause_transform_feedback
;
270 functions
->ResumeTransformFeedback
= gen7_resume_transform_feedback
;
272 functions
->BeginTransformFeedback
= brw_begin_transform_feedback
;
273 functions
->EndTransformFeedback
= brw_end_transform_feedback
;
277 functions
->GetSamplePosition
= gen6_get_sample_position
;
281 * Return array of MSAA modes supported by the hardware. The array is
282 * terminated by -1 and sorted in decreasing order.
285 brw_supported_msaa_modes(const struct brw_context
*brw
)
287 static const int gen7_samples
[] = {8, 4, 0, -1};
288 static const int gen6_samples
[] = {4, 0, -1};
289 static const int gen4_samples
[] = {0, -1};
293 } else if (brw
->gen
== 6) {
301 * Override GL_MAX_SAMPLES and related constants according to value of driconf
302 * option 'clamp_max_samples'.
305 brw_override_max_samples(struct brw_context
*brw
)
307 const int clamp_max_samples
= driQueryOptioni(&brw
->optionCache
,
308 "clamp_max_samples");
309 if (clamp_max_samples
< 0)
312 const int *supported_msaa_modes
= brw_supported_msaa_modes(brw
);
315 /* Select the largest supported MSAA mode that does not exceed
318 for (int i
= 0; supported_msaa_modes
[i
] != -1; ++i
) {
319 if (supported_msaa_modes
[i
] <= clamp_max_samples
) {
320 max_samples
= supported_msaa_modes
[i
];
325 brw
->ctx
.Const
.MaxSamples
= max_samples
;
326 brw
->ctx
.Const
.MaxColorTextureSamples
= max_samples
;
327 brw
->ctx
.Const
.MaxDepthTextureSamples
= max_samples
;
328 brw
->ctx
.Const
.MaxIntegerSamples
= max_samples
;
332 brw_initialize_context_constants(struct brw_context
*brw
)
334 struct gl_context
*ctx
= &brw
->ctx
;
336 ctx
->Const
.QueryCounterBits
.Timestamp
= 36;
338 ctx
->Const
.StripTextureBorder
= true;
340 ctx
->Const
.MaxDualSourceDrawBuffers
= 1;
341 ctx
->Const
.MaxDrawBuffers
= BRW_MAX_DRAW_BUFFERS
;
342 ctx
->Const
.FragmentProgram
.MaxTextureImageUnits
= BRW_MAX_TEX_UNIT
;
343 ctx
->Const
.MaxTextureCoordUnits
= 8; /* Mesa limit */
344 ctx
->Const
.MaxTextureUnits
=
345 MIN2(ctx
->Const
.MaxTextureCoordUnits
,
346 ctx
->Const
.FragmentProgram
.MaxTextureImageUnits
);
347 ctx
->Const
.VertexProgram
.MaxTextureImageUnits
= BRW_MAX_TEX_UNIT
;
349 ctx
->Const
.GeometryProgram
.MaxTextureImageUnits
= BRW_MAX_TEX_UNIT
;
351 ctx
->Const
.GeometryProgram
.MaxTextureImageUnits
= 0;
352 ctx
->Const
.MaxCombinedTextureImageUnits
=
353 ctx
->Const
.VertexProgram
.MaxTextureImageUnits
+
354 ctx
->Const
.FragmentProgram
.MaxTextureImageUnits
+
355 ctx
->Const
.GeometryProgram
.MaxTextureImageUnits
;
357 ctx
->Const
.MaxTextureLevels
= 14; /* 8192 */
358 if (ctx
->Const
.MaxTextureLevels
> MAX_TEXTURE_LEVELS
)
359 ctx
->Const
.MaxTextureLevels
= MAX_TEXTURE_LEVELS
;
360 ctx
->Const
.Max3DTextureLevels
= 9;
361 ctx
->Const
.MaxCubeTextureLevels
= 12;
364 ctx
->Const
.MaxArrayTextureLayers
= 2048;
366 ctx
->Const
.MaxArrayTextureLayers
= 512;
368 ctx
->Const
.MaxTextureRectSize
= 1 << 12;
370 ctx
->Const
.MaxTextureMaxAnisotropy
= 16.0;
372 ctx
->Const
.MaxRenderbufferSize
= 8192;
374 /* Hardware only supports a limited number of transform feedback buffers.
375 * So we need to override the Mesa default (which is based only on software
378 ctx
->Const
.MaxTransformFeedbackBuffers
= BRW_MAX_SOL_BUFFERS
;
380 /* On Gen6, in the worst case, we use up one binding table entry per
381 * transform feedback component (see comments above the definition of
382 * BRW_MAX_SOL_BINDINGS, in brw_context.h), so we need to advertise a value
383 * for MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS equal to
384 * BRW_MAX_SOL_BINDINGS.
386 * In "separate components" mode, we need to divide this value by
387 * BRW_MAX_SOL_BUFFERS, so that the total number of binding table entries
388 * used up by all buffers will not exceed BRW_MAX_SOL_BINDINGS.
390 ctx
->Const
.MaxTransformFeedbackInterleavedComponents
= BRW_MAX_SOL_BINDINGS
;
391 ctx
->Const
.MaxTransformFeedbackSeparateComponents
=
392 BRW_MAX_SOL_BINDINGS
/ BRW_MAX_SOL_BUFFERS
;
394 ctx
->Const
.AlwaysUseGetTransformFeedbackVertexCount
= true;
396 const int max_samples
= brw_supported_msaa_modes(brw
)[0];
397 ctx
->Const
.MaxSamples
= max_samples
;
398 ctx
->Const
.MaxColorTextureSamples
= max_samples
;
399 ctx
->Const
.MaxDepthTextureSamples
= max_samples
;
400 ctx
->Const
.MaxIntegerSamples
= max_samples
;
403 ctx
->Const
.MaxProgramTextureGatherComponents
= 4;
405 ctx
->Const
.MinLineWidth
= 1.0;
406 ctx
->Const
.MinLineWidthAA
= 1.0;
407 ctx
->Const
.MaxLineWidth
= 5.0;
408 ctx
->Const
.MaxLineWidthAA
= 5.0;
409 ctx
->Const
.LineWidthGranularity
= 0.5;
411 ctx
->Const
.MinPointSize
= 1.0;
412 ctx
->Const
.MinPointSizeAA
= 1.0;
413 ctx
->Const
.MaxPointSize
= 255.0;
414 ctx
->Const
.MaxPointSizeAA
= 255.0;
415 ctx
->Const
.PointSizeGranularity
= 1.0;
417 if (brw
->gen
>= 5 || brw
->is_g4x
)
418 ctx
->Const
.MaxClipPlanes
= 8;
420 ctx
->Const
.VertexProgram
.MaxNativeInstructions
= 16 * 1024;
421 ctx
->Const
.VertexProgram
.MaxAluInstructions
= 0;
422 ctx
->Const
.VertexProgram
.MaxTexInstructions
= 0;
423 ctx
->Const
.VertexProgram
.MaxTexIndirections
= 0;
424 ctx
->Const
.VertexProgram
.MaxNativeAluInstructions
= 0;
425 ctx
->Const
.VertexProgram
.MaxNativeTexInstructions
= 0;
426 ctx
->Const
.VertexProgram
.MaxNativeTexIndirections
= 0;
427 ctx
->Const
.VertexProgram
.MaxNativeAttribs
= 16;
428 ctx
->Const
.VertexProgram
.MaxNativeTemps
= 256;
429 ctx
->Const
.VertexProgram
.MaxNativeAddressRegs
= 1;
430 ctx
->Const
.VertexProgram
.MaxNativeParameters
= 1024;
431 ctx
->Const
.VertexProgram
.MaxEnvParams
=
432 MIN2(ctx
->Const
.VertexProgram
.MaxNativeParameters
,
433 ctx
->Const
.VertexProgram
.MaxEnvParams
);
435 ctx
->Const
.FragmentProgram
.MaxNativeInstructions
= 1024;
436 ctx
->Const
.FragmentProgram
.MaxNativeAluInstructions
= 1024;
437 ctx
->Const
.FragmentProgram
.MaxNativeTexInstructions
= 1024;
438 ctx
->Const
.FragmentProgram
.MaxNativeTexIndirections
= 1024;
439 ctx
->Const
.FragmentProgram
.MaxNativeAttribs
= 12;
440 ctx
->Const
.FragmentProgram
.MaxNativeTemps
= 256;
441 ctx
->Const
.FragmentProgram
.MaxNativeAddressRegs
= 0;
442 ctx
->Const
.FragmentProgram
.MaxNativeParameters
= 1024;
443 ctx
->Const
.FragmentProgram
.MaxEnvParams
=
444 MIN2(ctx
->Const
.FragmentProgram
.MaxNativeParameters
,
445 ctx
->Const
.FragmentProgram
.MaxEnvParams
);
447 /* Fragment shaders use real, 32-bit twos-complement integers for all
450 ctx
->Const
.FragmentProgram
.LowInt
.RangeMin
= 31;
451 ctx
->Const
.FragmentProgram
.LowInt
.RangeMax
= 30;
452 ctx
->Const
.FragmentProgram
.LowInt
.Precision
= 0;
453 ctx
->Const
.FragmentProgram
.HighInt
= ctx
->Const
.FragmentProgram
.LowInt
;
454 ctx
->Const
.FragmentProgram
.MediumInt
= ctx
->Const
.FragmentProgram
.LowInt
;
457 ctx
->Const
.FragmentProgram
.MaxAtomicCounters
= MAX_ATOMIC_COUNTERS
;
458 ctx
->Const
.VertexProgram
.MaxAtomicCounters
= MAX_ATOMIC_COUNTERS
;
459 ctx
->Const
.GeometryProgram
.MaxAtomicCounters
= MAX_ATOMIC_COUNTERS
;
460 ctx
->Const
.FragmentProgram
.MaxAtomicBuffers
= BRW_MAX_ABO
;
461 ctx
->Const
.VertexProgram
.MaxAtomicBuffers
= BRW_MAX_ABO
;
462 ctx
->Const
.GeometryProgram
.MaxAtomicBuffers
= BRW_MAX_ABO
;
463 ctx
->Const
.MaxCombinedAtomicBuffers
= 3 * BRW_MAX_ABO
;
466 /* Gen6 converts quads to polygon in beginning of 3D pipeline,
467 * but we're not sure how it's actually done for vertex order,
468 * that affect provoking vertex decision. Always use last vertex
469 * convention for quad primitive which works as expected for now.
472 ctx
->Const
.QuadsFollowProvokingVertexConvention
= false;
474 ctx
->Const
.NativeIntegers
= true;
475 ctx
->Const
.UniformBooleanTrue
= 1;
477 /* From the gen4 PRM, volume 4 page 127:
479 * "For SURFTYPE_BUFFER non-rendertarget surfaces, this field specifies
480 * the base address of the first element of the surface, computed in
481 * software by adding the surface base address to the byte offset of
482 * the element in the buffer."
484 * However, unaligned accesses are slower, so enforce buffer alignment.
486 ctx
->Const
.UniformBufferOffsetAlignment
= 16;
487 ctx
->Const
.TextureBufferOffsetAlignment
= 16;
490 ctx
->Const
.MaxVarying
= 32;
491 ctx
->Const
.VertexProgram
.MaxOutputComponents
= 128;
492 ctx
->Const
.GeometryProgram
.MaxInputComponents
= 64;
493 ctx
->Const
.GeometryProgram
.MaxOutputComponents
= 128;
494 ctx
->Const
.FragmentProgram
.MaxInputComponents
= 128;
497 /* We want the GLSL compiler to emit code that uses condition codes */
498 for (int i
= 0; i
< MESA_SHADER_TYPES
; i
++) {
499 ctx
->ShaderCompilerOptions
[i
].MaxIfDepth
= brw
->gen
< 6 ? 16 : UINT_MAX
;
500 ctx
->ShaderCompilerOptions
[i
].EmitCondCodes
= true;
501 ctx
->ShaderCompilerOptions
[i
].EmitNoNoise
= true;
502 ctx
->ShaderCompilerOptions
[i
].EmitNoMainReturn
= true;
503 ctx
->ShaderCompilerOptions
[i
].EmitNoIndirectInput
= true;
504 ctx
->ShaderCompilerOptions
[i
].EmitNoIndirectOutput
= true;
506 ctx
->ShaderCompilerOptions
[i
].EmitNoIndirectUniform
=
507 (i
== MESA_SHADER_FRAGMENT
);
508 ctx
->ShaderCompilerOptions
[i
].EmitNoIndirectTemp
=
509 (i
== MESA_SHADER_FRAGMENT
);
510 ctx
->ShaderCompilerOptions
[i
].LowerClipDistance
= true;
513 ctx
->ShaderCompilerOptions
[MESA_SHADER_VERTEX
].PreferDP4
= true;
517 * Process driconf (drirc) options, setting appropriate context flags.
519 * intelInitExtensions still pokes at optionCache directly, in order to
520 * avoid advertising various extensions. No flags are set, so it makes
521 * sense to continue doing that there.
524 brw_process_driconf_options(struct brw_context
*brw
)
526 struct gl_context
*ctx
= &brw
->ctx
;
528 driOptionCache
*options
= &brw
->optionCache
;
529 driParseConfigFiles(options
, &brw
->intelScreen
->optionCache
,
530 brw
->driContext
->driScreenPriv
->myNum
, "i965");
532 int bo_reuse_mode
= driQueryOptioni(options
, "bo_reuse");
533 switch (bo_reuse_mode
) {
534 case DRI_CONF_BO_REUSE_DISABLED
:
536 case DRI_CONF_BO_REUSE_ALL
:
537 intel_bufmgr_gem_enable_reuse(brw
->bufmgr
);
541 if (!driQueryOptionb(options
, "hiz")) {
542 brw
->has_hiz
= false;
543 /* On gen6, you can only do separate stencil with HIZ. */
545 brw
->has_separate_stencil
= false;
548 if (driQueryOptionb(options
, "always_flush_batch")) {
549 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
550 brw
->always_flush_batch
= true;
553 if (driQueryOptionb(options
, "always_flush_cache")) {
554 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
555 brw
->always_flush_cache
= true;
558 if (driQueryOptionb(options
, "disable_throttling")) {
559 fprintf(stderr
, "disabling flush throttling\n");
560 brw
->disable_throttling
= true;
563 brw
->disable_derivative_optimization
=
564 driQueryOptionb(&brw
->optionCache
, "disable_derivative_optimization");
566 brw
->precompile
= driQueryOptionb(&brw
->optionCache
, "shader_precompile");
568 ctx
->Const
.ForceGLSLExtensionsWarn
=
569 driQueryOptionb(options
, "force_glsl_extensions_warn");
571 ctx
->Const
.DisableGLSLLineContinuations
=
572 driQueryOptionb(options
, "disable_glsl_line_continuations");
576 brwCreateContext(gl_api api
,
577 const struct gl_config
*mesaVis
,
578 __DRIcontext
*driContextPriv
,
579 unsigned major_version
,
580 unsigned minor_version
,
583 unsigned *dri_ctx_error
,
584 void *sharedContextPrivate
)
586 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
587 struct gl_context
*shareCtx
= (struct gl_context
*) sharedContextPrivate
;
588 struct intel_screen
*screen
= sPriv
->driverPrivate
;
589 const struct brw_device_info
*devinfo
= screen
->devinfo
;
590 struct dd_function_table functions
;
591 struct gl_config visual
;
593 if (flags
& ~(__DRI_CTX_FLAG_DEBUG
594 | __DRI_CTX_FLAG_FORWARD_COMPATIBLE
595 | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
)) {
596 *dri_ctx_error
= __DRI_CTX_ERROR_UNKNOWN_FLAG
;
600 struct brw_context
*brw
= rzalloc(NULL
, struct brw_context
);
602 printf("%s: failed to alloc context\n", __FUNCTION__
);
603 *dri_ctx_error
= __DRI_CTX_ERROR_NO_MEMORY
;
607 driContextPriv
->driverPrivate
= brw
;
608 brw
->driContext
= driContextPriv
;
609 brw
->intelScreen
= screen
;
610 brw
->bufmgr
= screen
->bufmgr
;
612 brw
->gen
= devinfo
->gen
;
613 brw
->gt
= devinfo
->gt
;
614 brw
->is_g4x
= devinfo
->is_g4x
;
615 brw
->is_baytrail
= devinfo
->is_baytrail
;
616 brw
->is_haswell
= devinfo
->is_haswell
;
617 brw
->has_llc
= devinfo
->has_llc
;
618 brw
->has_hiz
= devinfo
->has_hiz_and_separate_stencil
&& brw
->gen
< 8;
619 brw
->has_separate_stencil
= devinfo
->has_hiz_and_separate_stencil
;
620 brw
->has_pln
= devinfo
->has_pln
;
621 brw
->has_compr4
= devinfo
->has_compr4
;
622 brw
->has_surface_tile_offset
= devinfo
->has_surface_tile_offset
;
623 brw
->has_negative_rhw_bug
= devinfo
->has_negative_rhw_bug
;
624 brw
->needs_unlit_centroid_workaround
=
625 devinfo
->needs_unlit_centroid_workaround
;
627 brw
->must_use_separate_stencil
= screen
->hw_must_use_separate_stencil
;
628 brw
->has_swizzling
= screen
->hw_has_swizzling
;
631 gen7_init_vtable_surface_functions(brw
);
632 gen7_init_vtable_sampler_functions(brw
);
633 brw
->vtbl
.emit_depth_stencil_hiz
= gen7_emit_depth_stencil_hiz
;
635 gen4_init_vtable_surface_functions(brw
);
636 gen4_init_vtable_sampler_functions(brw
);
637 brw
->vtbl
.emit_depth_stencil_hiz
= brw_emit_depth_stencil_hiz
;
640 brw_init_driver_functions(brw
, &functions
);
643 functions
.GetGraphicsResetStatus
= brw_get_graphics_reset_status
;
645 struct gl_context
*ctx
= &brw
->ctx
;
647 if (mesaVis
== NULL
) {
648 memset(&visual
, 0, sizeof visual
);
652 if (!_mesa_initialize_context(ctx
, api
, mesaVis
, shareCtx
, &functions
)) {
653 *dri_ctx_error
= __DRI_CTX_ERROR_NO_MEMORY
;
654 printf("%s: failed to init mesa context\n", __FUNCTION__
);
655 intelDestroyContext(driContextPriv
);
659 /* Initialize the software rasterizer and helper modules.
661 * As of GL 3.1 core, the gen4+ driver doesn't need the swrast context for
662 * software fallbacks (which we have to support on legacy GL to do weird
663 * glDrawPixels(), glBitmap(), and other functions).
665 if (api
!= API_OPENGL_CORE
&& api
!= API_OPENGLES2
) {
666 _swrast_CreateContext(ctx
);
669 _vbo_CreateContext(ctx
);
670 if (ctx
->swrast_context
) {
671 _tnl_CreateContext(ctx
);
672 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= _tnl_run_pipeline
;
673 _swsetup_CreateContext(ctx
);
675 /* Configure swrast to match hardware characteristics: */
676 _swrast_allow_pixel_fog(ctx
, false);
677 _swrast_allow_vertex_fog(ctx
, true);
680 _mesa_meta_init(ctx
);
682 brw_process_driconf_options(brw
);
683 brw_process_intel_debug_variable(brw
);
684 brw_initialize_context_constants(brw
);
686 ctx
->Const
.ResetStrategy
= notify_reset
687 ? GL_LOSE_CONTEXT_ON_RESET_ARB
: GL_NO_RESET_NOTIFICATION_ARB
;
689 /* Reinitialize the context point state. It depends on ctx->Const values. */
690 _mesa_init_point(ctx
);
692 intel_batchbuffer_init(brw
);
696 intelInitExtensions(ctx
);
701 /* Create a new hardware context. Using a hardware context means that
702 * our GPU state will be saved/restored on context switch, allowing us
703 * to assume that the GPU is in the same state we left it in.
705 * This is required for transform feedback buffer offsets, query objects,
706 * and also allows us to reduce how much state we have to emit.
708 brw
->hw_ctx
= drm_intel_gem_context_create(brw
->bufmgr
);
711 fprintf(stderr
, "Gen6+ requires Kernel 3.6 or later.\n");
712 intelDestroyContext(driContextPriv
);
717 /* Notification of GPU resets requires hardware contexts and a kernel new
718 * enough to support DRM_IOCTL_I915_GET_RESET_STATS, which isn't upstream
722 /* This is the wrong error code, but the correct error code (one that
723 * will cause EGL to generate EGL_BAD_MATCH) doesn't seem to exist.
725 *dri_ctx_error
= __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE
;
726 intelDestroyContext(driContextPriv
);
730 brw_init_surface_formats(brw
);
732 if (brw
->is_g4x
|| brw
->gen
>= 5) {
733 brw
->CMD_VF_STATISTICS
= GM45_3DSTATE_VF_STATISTICS
;
734 brw
->CMD_PIPELINE_SELECT
= CMD_PIPELINE_SELECT_GM45
;
736 brw
->CMD_VF_STATISTICS
= GEN4_3DSTATE_VF_STATISTICS
;
737 brw
->CMD_PIPELINE_SELECT
= CMD_PIPELINE_SELECT_965
;
740 brw
->max_vs_threads
= devinfo
->max_vs_threads
;
741 brw
->max_gs_threads
= devinfo
->max_gs_threads
;
742 brw
->max_wm_threads
= devinfo
->max_wm_threads
;
743 brw
->urb
.size
= devinfo
->urb
.size
;
744 brw
->urb
.min_vs_entries
= devinfo
->urb
.min_vs_entries
;
745 brw
->urb
.max_vs_entries
= devinfo
->urb
.max_vs_entries
;
746 brw
->urb
.max_gs_entries
= devinfo
->urb
.max_gs_entries
;
748 /* Estimate the size of the mappable aperture into the GTT. There's an
749 * ioctl to get the whole GTT size, but not one to get the mappable subset.
750 * It turns out it's basically always 256MB, though some ancient hardware
753 uint32_t gtt_size
= 256 * 1024 * 1024;
755 /* We don't want to map two objects such that a memcpy between them would
756 * just fault one mapping in and then the other over and over forever. So
757 * we would need to divide the GTT size by 2. Additionally, some GTT is
758 * taken up by things like the framebuffer and the ringbuffer and such, so
759 * be more conservative.
761 brw
->max_gtt_map_object_size
= gtt_size
/ 4;
764 brw
->urb
.gen6_gs_previously_active
= false;
766 brw
->prim_restart
.in_progress
= false;
767 brw
->prim_restart
.enable_cut_index
= false;
768 brw
->gs
.enabled
= false;
771 brw
->curbe
.last_buf
= calloc(1, 4096);
772 brw
->curbe
.next_buf
= calloc(1, 4096);
775 ctx
->VertexProgram
._MaintainTnlProgram
= true;
776 ctx
->FragmentProgram
._MaintainTexEnvProgram
= true;
778 brw_draw_init( brw
);
780 if ((flags
& __DRI_CTX_FLAG_DEBUG
) != 0) {
781 /* Turn on some extra GL_ARB_debug_output generation. */
782 brw
->perf_debug
= true;
785 if ((flags
& __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
) != 0)
786 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB
;
788 brw_fs_alloc_reg_sets(brw
);
789 brw_vec4_alloc_reg_set(brw
);
791 if (INTEL_DEBUG
& DEBUG_SHADER_TIME
)
792 brw_init_shader_time(brw
);
794 _mesa_compute_version(ctx
);
796 /* Here we override context constants. We apply the overrides after
797 * calculation of the context version because we do not want the overridden
798 * constants to change the version.
800 brw_override_max_samples(brw
);
802 _mesa_initialize_dispatch_tables(ctx
);
803 _mesa_initialize_vbo_vtxfmt(ctx
);
805 if (ctx
->Extensions
.AMD_performance_monitor
) {
806 brw_init_performance_monitors(brw
);
813 intelDestroyContext(__DRIcontext
* driContextPriv
)
815 struct brw_context
*brw
=
816 (struct brw_context
*) driContextPriv
->driverPrivate
;
817 struct gl_context
*ctx
= &brw
->ctx
;
819 assert(brw
); /* should never be null */
823 /* Dump a final BMP in case the application doesn't call SwapBuffers */
824 if (INTEL_DEBUG
& DEBUG_AUB
) {
825 intel_batchbuffer_flush(brw
);
826 aub_dump_bmp(&brw
->ctx
);
829 _mesa_meta_free(&brw
->ctx
);
831 if (INTEL_DEBUG
& DEBUG_SHADER_TIME
) {
832 /* Force a report. */
833 brw
->shader_time
.report_time
= 0;
835 brw_collect_and_report_shader_time(brw
);
836 brw_destroy_shader_time(brw
);
839 brw_destroy_state(brw
);
840 brw_draw_destroy(brw
);
842 drm_intel_bo_unreference(brw
->curbe
.curbe_bo
);
843 drm_intel_bo_unreference(brw
->vs
.base
.const_bo
);
844 drm_intel_bo_unreference(brw
->wm
.base
.const_bo
);
846 free(brw
->curbe
.last_buf
);
847 free(brw
->curbe
.next_buf
);
849 drm_intel_gem_context_destroy(brw
->hw_ctx
);
851 if (ctx
->swrast_context
) {
852 _swsetup_DestroyContext(&brw
->ctx
);
853 _tnl_DestroyContext(&brw
->ctx
);
855 _vbo_DestroyContext(&brw
->ctx
);
857 if (ctx
->swrast_context
)
858 _swrast_DestroyContext(&brw
->ctx
);
860 intel_batchbuffer_free(brw
);
862 drm_intel_bo_unreference(brw
->first_post_swapbuffers_batch
);
863 brw
->first_post_swapbuffers_batch
= NULL
;
865 driDestroyOptionCache(&brw
->optionCache
);
867 /* free the Mesa context */
868 _mesa_free_context_data(&brw
->ctx
);
871 driContextPriv
->driverPrivate
= NULL
;
875 intelUnbindContext(__DRIcontext
* driContextPriv
)
877 /* Unset current context and dispath table */
878 _mesa_make_current(NULL
, NULL
, NULL
);
884 * Fixes up the context for GLES23 with our default-to-sRGB-capable behavior
885 * on window system framebuffers.
887 * Desktop GL is fairly reasonable in its handling of sRGB: You can ask if
888 * your renderbuffer can do sRGB encode, and you can flip a switch that does
889 * sRGB encode if the renderbuffer can handle it. You can ask specifically
890 * for a visual where you're guaranteed to be capable, but it turns out that
891 * everyone just makes all their ARGB8888 visuals capable and doesn't offer
892 * incapable ones, becuase there's no difference between the two in resources
893 * used. Applications thus get built that accidentally rely on the default
894 * visual choice being sRGB, so we make ours sRGB capable. Everything sounds
897 * But for GLES2/3, they decided that it was silly to not turn on sRGB encode
898 * for sRGB renderbuffers you made with the GL_EXT_texture_sRGB equivalent.
899 * So they removed the enable knob and made it "if the renderbuffer is sRGB
900 * capable, do sRGB encode". Then, for your window system renderbuffers, you
901 * can ask for sRGB visuals and get sRGB encode, or not ask for sRGB visuals
902 * and get no sRGB encode (assuming that both kinds of visual are available).
903 * Thus our choice to support sRGB by default on our visuals for desktop would
904 * result in broken rendering of GLES apps that aren't expecting sRGB encode.
906 * Unfortunately, renderbuffer setup happens before a context is created. So
907 * in intel_screen.c we always set up sRGB, and here, if you're a GLES2/3
908 * context (without an sRGB visual, though we don't have sRGB visuals exposed
909 * yet), we go turn that back off before anyone finds out.
912 intel_gles3_srgb_workaround(struct brw_context
*brw
,
913 struct gl_framebuffer
*fb
)
915 struct gl_context
*ctx
= &brw
->ctx
;
917 if (_mesa_is_desktop_gl(ctx
) || !fb
->Visual
.sRGBCapable
)
920 /* Some day when we support the sRGB capable bit on visuals available for
921 * GLES, we'll need to respect that and not disable things here.
923 fb
->Visual
.sRGBCapable
= false;
924 for (int i
= 0; i
< BUFFER_COUNT
; i
++) {
925 if (fb
->Attachment
[i
].Renderbuffer
&&
926 fb
->Attachment
[i
].Renderbuffer
->Format
== MESA_FORMAT_SARGB8
) {
927 fb
->Attachment
[i
].Renderbuffer
->Format
= MESA_FORMAT_ARGB8888
;
933 intelMakeCurrent(__DRIcontext
* driContextPriv
,
934 __DRIdrawable
* driDrawPriv
,
935 __DRIdrawable
* driReadPriv
)
937 struct brw_context
*brw
;
938 GET_CURRENT_CONTEXT(curCtx
);
941 brw
= (struct brw_context
*) driContextPriv
->driverPrivate
;
945 /* According to the glXMakeCurrent() man page: "Pending commands to
946 * the previous context, if any, are flushed before it is released."
947 * But only flush if we're actually changing contexts.
949 if (brw_context(curCtx
) && brw_context(curCtx
) != brw
) {
953 if (driContextPriv
) {
954 struct gl_context
*ctx
= &brw
->ctx
;
955 struct gl_framebuffer
*fb
, *readFb
;
957 if (driDrawPriv
== NULL
&& driReadPriv
== NULL
) {
958 fb
= _mesa_get_incomplete_framebuffer();
959 readFb
= _mesa_get_incomplete_framebuffer();
961 fb
= driDrawPriv
->driverPrivate
;
962 readFb
= driReadPriv
->driverPrivate
;
963 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
964 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
967 /* The sRGB workaround changes the renderbuffer's format. We must change
968 * the format before the renderbuffer's miptree get's allocated, otherwise
969 * the formats of the renderbuffer and its miptree will differ.
971 intel_gles3_srgb_workaround(brw
, fb
);
972 intel_gles3_srgb_workaround(brw
, readFb
);
974 intel_prepare_render(brw
);
975 _mesa_make_current(ctx
, fb
, readFb
);
977 _mesa_make_current(NULL
, NULL
, NULL
);
984 intel_resolve_for_dri2_flush(struct brw_context
*brw
,
985 __DRIdrawable
*drawable
)
988 /* MSAA and fast color clear are not supported, so don't waste time
989 * checking whether a resolve is needed.
994 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
995 struct intel_renderbuffer
*rb
;
997 /* Usually, only the back buffer will need to be downsampled. However,
998 * the front buffer will also need it if the user has rendered into it.
1000 static const gl_buffer_index buffers
[2] = {
1005 for (int i
= 0; i
< 2; ++i
) {
1006 rb
= intel_get_renderbuffer(fb
, buffers
[i
]);
1007 if (rb
== NULL
|| rb
->mt
== NULL
)
1009 if (rb
->mt
->num_samples
<= 1)
1010 intel_miptree_resolve_color(brw
, rb
->mt
);
1012 intel_miptree_downsample(brw
, rb
->mt
);
1017 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
1019 return _mesa_get_format_bytes(intel_rb_format(rb
)) * 8;
1023 intel_query_dri2_buffers(struct brw_context
*brw
,
1024 __DRIdrawable
*drawable
,
1025 __DRIbuffer
**buffers
,
1029 intel_process_dri2_buffer(struct brw_context
*brw
,
1030 __DRIdrawable
*drawable
,
1031 __DRIbuffer
*buffer
,
1032 struct intel_renderbuffer
*rb
,
1033 const char *buffer_name
);
1036 intel_update_image_buffers(struct brw_context
*brw
, __DRIdrawable
*drawable
);
1039 intel_update_dri2_buffers(struct brw_context
*brw
, __DRIdrawable
*drawable
)
1041 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1042 struct intel_renderbuffer
*rb
;
1043 __DRIbuffer
*buffers
= NULL
;
1045 const char *region_name
;
1047 /* Set this up front, so that in case our buffers get invalidated
1048 * while we're getting new buffers, we don't clobber the stamp and
1049 * thus ignore the invalidate. */
1050 drawable
->lastStamp
= drawable
->dri2
.stamp
;
1052 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
1053 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
1055 intel_query_dri2_buffers(brw
, drawable
, &buffers
, &count
);
1057 if (buffers
== NULL
)
1060 for (i
= 0; i
< count
; i
++) {
1061 switch (buffers
[i
].attachment
) {
1062 case __DRI_BUFFER_FRONT_LEFT
:
1063 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
1064 region_name
= "dri2 front buffer";
1067 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
1068 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
1069 region_name
= "dri2 fake front buffer";
1072 case __DRI_BUFFER_BACK_LEFT
:
1073 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
1074 region_name
= "dri2 back buffer";
1077 case __DRI_BUFFER_DEPTH
:
1078 case __DRI_BUFFER_HIZ
:
1079 case __DRI_BUFFER_DEPTH_STENCIL
:
1080 case __DRI_BUFFER_STENCIL
:
1081 case __DRI_BUFFER_ACCUM
:
1084 "unhandled buffer attach event, attachment type %d\n",
1085 buffers
[i
].attachment
);
1089 intel_process_dri2_buffer(brw
, drawable
, &buffers
[i
], rb
, region_name
);
1095 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
1097 struct brw_context
*brw
= context
->driverPrivate
;
1098 __DRIscreen
*screen
= brw
->intelScreen
->driScrnPriv
;
1100 /* Set this up front, so that in case our buffers get invalidated
1101 * while we're getting new buffers, we don't clobber the stamp and
1102 * thus ignore the invalidate. */
1103 drawable
->lastStamp
= drawable
->dri2
.stamp
;
1105 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
1106 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
1108 if (screen
->image
.loader
)
1109 intel_update_image_buffers(brw
, drawable
);
1111 intel_update_dri2_buffers(brw
, drawable
);
1113 driUpdateFramebufferSize(&brw
->ctx
, drawable
);
1117 * intel_prepare_render should be called anywhere that curent read/drawbuffer
1118 * state is required.
1121 intel_prepare_render(struct brw_context
*brw
)
1123 __DRIcontext
*driContext
= brw
->driContext
;
1124 __DRIdrawable
*drawable
;
1126 drawable
= driContext
->driDrawablePriv
;
1127 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
1128 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
1129 intel_update_renderbuffers(driContext
, drawable
);
1130 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
1133 drawable
= driContext
->driReadablePriv
;
1134 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
1135 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
1136 intel_update_renderbuffers(driContext
, drawable
);
1137 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
1140 /* If we're currently rendering to the front buffer, the rendering
1141 * that will happen next will probably dirty the front buffer. So
1142 * mark it as dirty here.
1144 if (brw
->is_front_buffer_rendering
)
1145 brw
->front_buffer_dirty
= true;
1147 /* Wait for the swapbuffers before the one we just emitted, so we
1148 * don't get too many swaps outstanding for apps that are GPU-heavy
1149 * but not CPU-heavy.
1151 * We're using intelDRI2Flush (called from the loader before
1152 * swapbuffer) and glFlush (for front buffer rendering) as the
1153 * indicator that a frame is done and then throttle when we get
1154 * here as we prepare to render the next frame. At this point for
1155 * round trips for swap/copy and getting new buffers are done and
1156 * we'll spend less time waiting on the GPU.
1158 * Unfortunately, we don't have a handle to the batch containing
1159 * the swap, and getting our hands on that doesn't seem worth it,
1160 * so we just us the first batch we emitted after the last swap.
1162 if (brw
->need_throttle
&& brw
->first_post_swapbuffers_batch
) {
1163 if (!brw
->disable_throttling
)
1164 drm_intel_bo_wait_rendering(brw
->first_post_swapbuffers_batch
);
1165 drm_intel_bo_unreference(brw
->first_post_swapbuffers_batch
);
1166 brw
->first_post_swapbuffers_batch
= NULL
;
1167 brw
->need_throttle
= false;
1172 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
1174 * To determine which DRI buffers to request, examine the renderbuffers
1175 * attached to the drawable's framebuffer. Then request the buffers with
1176 * DRI2GetBuffers() or DRI2GetBuffersWithFormat().
1178 * This is called from intel_update_renderbuffers().
1180 * \param drawable Drawable whose buffers are queried.
1181 * \param buffers [out] List of buffers returned by DRI2 query.
1182 * \param buffer_count [out] Number of buffers returned.
1184 * \see intel_update_renderbuffers()
1185 * \see DRI2GetBuffers()
1186 * \see DRI2GetBuffersWithFormat()
1189 intel_query_dri2_buffers(struct brw_context
*brw
,
1190 __DRIdrawable
*drawable
,
1191 __DRIbuffer
**buffers
,
1194 __DRIscreen
*screen
= brw
->intelScreen
->driScrnPriv
;
1195 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1197 unsigned attachments
[8];
1199 struct intel_renderbuffer
*front_rb
;
1200 struct intel_renderbuffer
*back_rb
;
1202 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
1203 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
1205 memset(attachments
, 0, sizeof(attachments
));
1206 if ((brw
->is_front_buffer_rendering
||
1207 brw
->is_front_buffer_reading
||
1208 !back_rb
) && front_rb
) {
1209 /* If a fake front buffer is in use, then querying for
1210 * __DRI_BUFFER_FRONT_LEFT will cause the server to copy the image from
1211 * the real front buffer to the fake front buffer. So before doing the
1212 * query, we need to make sure all the pending drawing has landed in the
1213 * real front buffer.
1215 intel_batchbuffer_flush(brw
);
1216 intel_flush_front(&brw
->ctx
);
1218 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
1219 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
1220 } else if (front_rb
&& brw
->front_buffer_dirty
) {
1221 /* We have pending front buffer rendering, but we aren't querying for a
1222 * front buffer. If the front buffer we have is a fake front buffer,
1223 * the X server is going to throw it away when it processes the query.
1224 * So before doing the query, make sure all the pending drawing has
1225 * landed in the real front buffer.
1227 intel_batchbuffer_flush(brw
);
1228 intel_flush_front(&brw
->ctx
);
1232 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
1233 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
1236 assert(i
<= ARRAY_SIZE(attachments
));
1238 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
1243 drawable
->loaderPrivate
);
1247 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
1249 * This is called from intel_update_renderbuffers().
1252 * DRI buffers whose attachment point is DRI2BufferStencil or
1253 * DRI2BufferDepthStencil are handled as special cases.
1255 * \param buffer_name is a human readable name, such as "dri2 front buffer",
1256 * that is passed to intel_region_alloc_for_handle().
1258 * \see intel_update_renderbuffers()
1259 * \see intel_region_alloc_for_handle()
1262 intel_process_dri2_buffer(struct brw_context
*brw
,
1263 __DRIdrawable
*drawable
,
1264 __DRIbuffer
*buffer
,
1265 struct intel_renderbuffer
*rb
,
1266 const char *buffer_name
)
1268 struct intel_region
*region
= NULL
;
1273 unsigned num_samples
= rb
->Base
.Base
.NumSamples
;
1275 /* We try to avoid closing and reopening the same BO name, because the first
1276 * use of a mapping of the buffer involves a bunch of page faulting which is
1277 * moderately expensive.
1279 if (num_samples
== 0) {
1282 rb
->mt
->region
->name
== buffer
->name
)
1286 rb
->mt
->singlesample_mt
&&
1287 rb
->mt
->singlesample_mt
->region
&&
1288 rb
->mt
->singlesample_mt
->region
->name
== buffer
->name
)
1292 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
1294 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
1295 buffer
->name
, buffer
->attachment
,
1296 buffer
->cpp
, buffer
->pitch
);
1299 intel_miptree_release(&rb
->mt
);
1300 region
= intel_region_alloc_for_handle(brw
->intelScreen
,
1310 rb
->mt
= intel_miptree_create_for_dri2_buffer(brw
,
1312 intel_rb_format(rb
),
1315 intel_region_release(®ion
);
1319 * \brief Query DRI image loader to obtain a DRIdrawable's buffers.
1321 * To determine which DRI buffers to request, examine the renderbuffers
1322 * attached to the drawable's framebuffer. Then request the buffers from
1325 * This is called from intel_update_renderbuffers().
1327 * \param drawable Drawable whose buffers are queried.
1328 * \param buffers [out] List of buffers returned by DRI2 query.
1329 * \param buffer_count [out] Number of buffers returned.
1331 * \see intel_update_renderbuffers()
1335 intel_update_image_buffer(struct brw_context
*intel
,
1336 __DRIdrawable
*drawable
,
1337 struct intel_renderbuffer
*rb
,
1339 enum __DRIimageBufferMask buffer_type
)
1341 struct intel_region
*region
= buffer
->region
;
1346 unsigned num_samples
= rb
->Base
.Base
.NumSamples
;
1350 rb
->mt
->region
== region
)
1353 intel_miptree_release(&rb
->mt
);
1354 rb
->mt
= intel_miptree_create_for_image_buffer(intel
,
1356 intel_rb_format(rb
),
1362 intel_update_image_buffers(struct brw_context
*brw
, __DRIdrawable
*drawable
)
1364 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
1365 __DRIscreen
*screen
= brw
->intelScreen
->driScrnPriv
;
1366 struct intel_renderbuffer
*front_rb
;
1367 struct intel_renderbuffer
*back_rb
;
1368 struct __DRIimageList images
;
1369 unsigned int format
;
1370 uint32_t buffer_mask
= 0;
1372 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
1373 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
1376 format
= intel_rb_format(back_rb
);
1378 format
= intel_rb_format(front_rb
);
1382 if ((brw
->is_front_buffer_rendering
|| brw
->is_front_buffer_reading
|| !back_rb
) && front_rb
)
1383 buffer_mask
|= __DRI_IMAGE_BUFFER_FRONT
;
1386 buffer_mask
|= __DRI_IMAGE_BUFFER_BACK
;
1388 (*screen
->image
.loader
->getBuffers
) (drawable
,
1389 driGLFormatToImageFormat(format
),
1390 &drawable
->dri2
.stamp
,
1391 drawable
->loaderPrivate
,
1395 if (images
.image_mask
& __DRI_IMAGE_BUFFER_FRONT
) {
1396 drawable
->w
= images
.front
->width
;
1397 drawable
->h
= images
.front
->height
;
1398 intel_update_image_buffer(brw
,
1402 __DRI_IMAGE_BUFFER_FRONT
);
1404 if (images
.image_mask
& __DRI_IMAGE_BUFFER_BACK
) {
1405 drawable
->w
= images
.back
->width
;
1406 drawable
->h
= images
.back
->height
;
1407 intel_update_image_buffer(brw
,
1411 __DRI_IMAGE_BUFFER_BACK
);