intel/compiler/gen10: Disable push constants.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_context.c
1 /*
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.
6
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:
14
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.
18
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.
26
27 **********************************************************************/
28 /*
29 * Authors:
30 * Keith Whitwell <keithw@vmware.com>
31 */
32
33
34 #include "compiler/nir/nir.h"
35 #include "main/api_exec.h"
36 #include "main/context.h"
37 #include "main/fbobject.h"
38 #include "main/extensions.h"
39 #include "main/imports.h"
40 #include "main/macros.h"
41 #include "main/points.h"
42 #include "main/version.h"
43 #include "main/vtxfmt.h"
44 #include "main/texobj.h"
45 #include "main/framebuffer.h"
46 #include "main/stencil.h"
47 #include "main/state.h"
48
49 #include "vbo/vbo_context.h"
50
51 #include "drivers/common/driverfuncs.h"
52 #include "drivers/common/meta.h"
53 #include "utils.h"
54
55 #include "brw_context.h"
56 #include "brw_defines.h"
57 #include "brw_blorp.h"
58 #include "brw_draw.h"
59 #include "brw_state.h"
60
61 #include "intel_batchbuffer.h"
62 #include "intel_buffer_objects.h"
63 #include "intel_buffers.h"
64 #include "intel_fbo.h"
65 #include "intel_mipmap_tree.h"
66 #include "intel_pixel.h"
67 #include "intel_image.h"
68 #include "intel_tex.h"
69 #include "intel_tex_obj.h"
70
71 #include "swrast_setup/swrast_setup.h"
72 #include "tnl/tnl.h"
73 #include "tnl/t_pipeline.h"
74 #include "util/ralloc.h"
75 #include "util/debug.h"
76 #include "isl/isl.h"
77
78 /***************************************
79 * Mesa's Driver Functions
80 ***************************************/
81
82 const char *const brw_vendor_string = "Intel Open Source Technology Center";
83
84 static const char *
85 get_bsw_model(const struct intel_screen *screen)
86 {
87 switch (screen->eu_total) {
88 case 16:
89 return "405";
90 case 12:
91 return "400";
92 default:
93 return " ";
94 }
95 }
96
97 const char *
98 brw_get_renderer_string(const struct intel_screen *screen)
99 {
100 const char *chipset;
101 static char buffer[128];
102 char *bsw = NULL;
103
104 switch (screen->deviceID) {
105 #undef CHIPSET
106 #define CHIPSET(id, symbol, str) case id: chipset = str; break;
107 #include "pci_ids/i965_pci_ids.h"
108 default:
109 chipset = "Unknown Intel Chipset";
110 break;
111 }
112
113 /* Braswell branding is funny, so we have to fix it up here */
114 if (screen->deviceID == 0x22B1) {
115 bsw = strdup(chipset);
116 char *needle = strstr(bsw, "XXX");
117 if (needle) {
118 memcpy(needle, get_bsw_model(screen), 3);
119 chipset = bsw;
120 }
121 }
122
123 (void) driGetRendererString(buffer, chipset, 0);
124 free(bsw);
125 return buffer;
126 }
127
128 static const GLubyte *
129 intel_get_string(struct gl_context * ctx, GLenum name)
130 {
131 const struct brw_context *const brw = brw_context(ctx);
132
133 switch (name) {
134 case GL_VENDOR:
135 return (GLubyte *) brw_vendor_string;
136
137 case GL_RENDERER:
138 return
139 (GLubyte *) brw_get_renderer_string(brw->screen);
140
141 default:
142 return NULL;
143 }
144 }
145
146 static void
147 intel_viewport(struct gl_context *ctx)
148 {
149 struct brw_context *brw = brw_context(ctx);
150 __DRIcontext *driContext = brw->driContext;
151
152 if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) {
153 if (driContext->driDrawablePriv)
154 dri2InvalidateDrawable(driContext->driDrawablePriv);
155 if (driContext->driReadablePriv)
156 dri2InvalidateDrawable(driContext->driReadablePriv);
157 }
158 }
159
160 static void
161 intel_update_framebuffer(struct gl_context *ctx,
162 struct gl_framebuffer *fb)
163 {
164 struct brw_context *brw = brw_context(ctx);
165
166 /* Quantize the derived default number of samples
167 */
168 fb->DefaultGeometry._NumSamples =
169 intel_quantize_num_samples(brw->screen,
170 fb->DefaultGeometry.NumSamples);
171 }
172
173 static void
174 intel_update_state(struct gl_context * ctx)
175 {
176 GLuint new_state = ctx->NewState;
177 struct brw_context *brw = brw_context(ctx);
178
179 if (ctx->swrast_context)
180 _swrast_InvalidateState(ctx, new_state);
181
182 brw->NewGLState |= new_state;
183
184 if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
185 _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
186
187 if (new_state & (_NEW_STENCIL | _NEW_BUFFERS)) {
188 brw->stencil_enabled = _mesa_stencil_is_enabled(ctx);
189 brw->stencil_two_sided = _mesa_stencil_is_two_sided(ctx);
190 brw->stencil_write_enabled =
191 _mesa_stencil_is_write_enabled(ctx, brw->stencil_two_sided);
192 }
193
194 if (new_state & _NEW_POLYGON)
195 brw->polygon_front_bit = _mesa_polygon_get_front_bit(ctx);
196
197 if (new_state & _NEW_BUFFERS) {
198 intel_update_framebuffer(ctx, ctx->DrawBuffer);
199 if (ctx->DrawBuffer != ctx->ReadBuffer)
200 intel_update_framebuffer(ctx, ctx->ReadBuffer);
201 }
202 }
203
204 #define flushFront(screen) ((screen)->image.loader ? (screen)->image.loader->flushFrontBuffer : (screen)->dri2.loader->flushFrontBuffer)
205
206 static void
207 intel_flush_front(struct gl_context *ctx)
208 {
209 struct brw_context *brw = brw_context(ctx);
210 __DRIcontext *driContext = brw->driContext;
211 __DRIdrawable *driDrawable = driContext->driDrawablePriv;
212 __DRIscreen *const dri_screen = brw->screen->driScrnPriv;
213
214 if (brw->front_buffer_dirty && _mesa_is_winsys_fbo(ctx->DrawBuffer)) {
215 if (flushFront(dri_screen) && driDrawable &&
216 driDrawable->loaderPrivate) {
217
218 /* Resolve before flushing FAKE_FRONT_LEFT to FRONT_LEFT.
219 *
220 * This potentially resolves both front and back buffer. It
221 * is unnecessary to resolve the back, but harms nothing except
222 * performance. And no one cares about front-buffer render
223 * performance.
224 */
225 intel_resolve_for_dri2_flush(brw, driDrawable);
226 intel_batchbuffer_flush(brw);
227
228 flushFront(dri_screen)(driDrawable, driDrawable->loaderPrivate);
229
230 /* We set the dirty bit in intel_prepare_render() if we're
231 * front buffer rendering once we get there.
232 */
233 brw->front_buffer_dirty = false;
234 }
235 }
236 }
237
238 static void
239 intel_glFlush(struct gl_context *ctx)
240 {
241 struct brw_context *brw = brw_context(ctx);
242
243 intel_batchbuffer_flush(brw);
244 intel_flush_front(ctx);
245
246 brw->need_flush_throttle = true;
247 }
248
249 static void
250 intel_finish(struct gl_context * ctx)
251 {
252 struct brw_context *brw = brw_context(ctx);
253
254 intel_glFlush(ctx);
255
256 if (brw->batch.last_bo)
257 brw_bo_wait_rendering(brw->batch.last_bo);
258 }
259
260 static void
261 brw_init_driver_functions(struct brw_context *brw,
262 struct dd_function_table *functions)
263 {
264 const struct gen_device_info *devinfo = &brw->screen->devinfo;
265
266 _mesa_init_driver_functions(functions);
267
268 /* GLX uses DRI2 invalidate events to handle window resizing.
269 * Unfortunately, EGL does not - libEGL is written in XCB (not Xlib),
270 * which doesn't provide a mechanism for snooping the event queues.
271 *
272 * So EGL still relies on viewport hacks to handle window resizing.
273 * This should go away with DRI3000.
274 */
275 if (!brw->driContext->driScreenPriv->dri2.useInvalidate)
276 functions->Viewport = intel_viewport;
277
278 functions->Flush = intel_glFlush;
279 functions->Finish = intel_finish;
280 functions->GetString = intel_get_string;
281 functions->UpdateState = intel_update_state;
282
283 intelInitTextureFuncs(functions);
284 intelInitTextureImageFuncs(functions);
285 intelInitTextureCopyImageFuncs(functions);
286 intelInitCopyImageFuncs(functions);
287 intelInitClearFuncs(functions);
288 intelInitBufferFuncs(functions);
289 intelInitPixelFuncs(functions);
290 intelInitBufferObjectFuncs(functions);
291 brw_init_syncobj_functions(functions);
292 brw_init_object_purgeable_functions(functions);
293
294 brwInitFragProgFuncs( functions );
295 brw_init_common_queryobj_functions(functions);
296 if (devinfo->gen >= 8 || devinfo->is_haswell)
297 hsw_init_queryobj_functions(functions);
298 else if (devinfo->gen >= 6)
299 gen6_init_queryobj_functions(functions);
300 else
301 gen4_init_queryobj_functions(functions);
302 brw_init_compute_functions(functions);
303 brw_init_conditional_render_functions(functions);
304
305 functions->QueryInternalFormat = brw_query_internal_format;
306
307 functions->NewTransformFeedback = brw_new_transform_feedback;
308 functions->DeleteTransformFeedback = brw_delete_transform_feedback;
309 if (can_do_mi_math_and_lrr(brw->screen)) {
310 functions->BeginTransformFeedback = hsw_begin_transform_feedback;
311 functions->EndTransformFeedback = hsw_end_transform_feedback;
312 functions->PauseTransformFeedback = hsw_pause_transform_feedback;
313 functions->ResumeTransformFeedback = hsw_resume_transform_feedback;
314 } else if (devinfo->gen >= 7) {
315 functions->BeginTransformFeedback = gen7_begin_transform_feedback;
316 functions->EndTransformFeedback = gen7_end_transform_feedback;
317 functions->PauseTransformFeedback = gen7_pause_transform_feedback;
318 functions->ResumeTransformFeedback = gen7_resume_transform_feedback;
319 functions->GetTransformFeedbackVertexCount =
320 brw_get_transform_feedback_vertex_count;
321 } else {
322 functions->BeginTransformFeedback = brw_begin_transform_feedback;
323 functions->EndTransformFeedback = brw_end_transform_feedback;
324 functions->PauseTransformFeedback = brw_pause_transform_feedback;
325 functions->ResumeTransformFeedback = brw_resume_transform_feedback;
326 functions->GetTransformFeedbackVertexCount =
327 brw_get_transform_feedback_vertex_count;
328 }
329
330 if (devinfo->gen >= 6)
331 functions->GetSamplePosition = gen6_get_sample_position;
332
333 /* GL_ARB_get_program_binary */
334 brw_program_binary_init(brw->screen->deviceID);
335 functions->GetProgramBinaryDriverSHA1 = brw_get_program_binary_driver_sha1;
336 functions->ProgramBinarySerializeDriverBlob = brw_program_serialize_nir;
337 functions->ProgramBinaryDeserializeDriverBlob =
338 brw_deserialize_program_binary;
339 }
340
341 static void
342 brw_initialize_context_constants(struct brw_context *brw)
343 {
344 const struct gen_device_info *devinfo = &brw->screen->devinfo;
345 struct gl_context *ctx = &brw->ctx;
346 const struct brw_compiler *compiler = brw->screen->compiler;
347
348 const bool stage_exists[MESA_SHADER_STAGES] = {
349 [MESA_SHADER_VERTEX] = true,
350 [MESA_SHADER_TESS_CTRL] = devinfo->gen >= 7,
351 [MESA_SHADER_TESS_EVAL] = devinfo->gen >= 7,
352 [MESA_SHADER_GEOMETRY] = devinfo->gen >= 6,
353 [MESA_SHADER_FRAGMENT] = true,
354 [MESA_SHADER_COMPUTE] =
355 (_mesa_is_desktop_gl(ctx) &&
356 ctx->Const.MaxComputeWorkGroupSize[0] >= 1024) ||
357 (ctx->API == API_OPENGLES2 &&
358 ctx->Const.MaxComputeWorkGroupSize[0] >= 128),
359 };
360
361 unsigned num_stages = 0;
362 for (int i = 0; i < MESA_SHADER_STAGES; i++) {
363 if (stage_exists[i])
364 num_stages++;
365 }
366
367 unsigned max_samplers =
368 devinfo->gen >= 8 || devinfo->is_haswell ? BRW_MAX_TEX_UNIT : 16;
369
370 ctx->Const.MaxDualSourceDrawBuffers = 1;
371 ctx->Const.MaxDrawBuffers = BRW_MAX_DRAW_BUFFERS;
372 ctx->Const.MaxCombinedShaderOutputResources =
373 MAX_IMAGE_UNITS + BRW_MAX_DRAW_BUFFERS;
374
375 /* The timestamp register we can read for glGetTimestamp() is
376 * sometimes only 32 bits, before scaling to nanoseconds (depending
377 * on kernel).
378 *
379 * Once scaled to nanoseconds the timestamp would roll over at a
380 * non-power-of-two, so an application couldn't use
381 * GL_QUERY_COUNTER_BITS to handle rollover correctly. Instead, we
382 * report 36 bits and truncate at that (rolling over 5 times as
383 * often as the HW counter), and when the 32-bit counter rolls
384 * over, it happens to also be at a rollover in the reported value
385 * from near (1<<36) to 0.
386 *
387 * The low 32 bits rolls over in ~343 seconds. Our 36-bit result
388 * rolls over every ~69 seconds.
389 */
390 ctx->Const.QueryCounterBits.Timestamp = 36;
391
392 ctx->Const.MaxTextureCoordUnits = 8; /* Mesa limit */
393 ctx->Const.MaxImageUnits = MAX_IMAGE_UNITS;
394 if (devinfo->gen >= 7) {
395 ctx->Const.MaxRenderbufferSize = 16384;
396 ctx->Const.MaxTextureLevels = MIN2(15 /* 16384 */, MAX_TEXTURE_LEVELS);
397 ctx->Const.MaxCubeTextureLevels = 15; /* 16384 */
398 } else {
399 ctx->Const.MaxRenderbufferSize = 8192;
400 ctx->Const.MaxTextureLevels = MIN2(14 /* 8192 */, MAX_TEXTURE_LEVELS);
401 ctx->Const.MaxCubeTextureLevels = 14; /* 8192 */
402 }
403 ctx->Const.Max3DTextureLevels = 12; /* 2048 */
404 ctx->Const.MaxArrayTextureLayers = devinfo->gen >= 7 ? 2048 : 512;
405 ctx->Const.MaxTextureMbytes = 1536;
406 ctx->Const.MaxTextureRectSize = devinfo->gen >= 7 ? 16384 : 8192;
407 ctx->Const.MaxTextureMaxAnisotropy = 16.0;
408 ctx->Const.MaxTextureLodBias = 15.0;
409 ctx->Const.StripTextureBorder = true;
410 if (devinfo->gen >= 7) {
411 ctx->Const.MaxProgramTextureGatherComponents = 4;
412 ctx->Const.MinProgramTextureGatherOffset = -32;
413 ctx->Const.MaxProgramTextureGatherOffset = 31;
414 } else if (devinfo->gen == 6) {
415 ctx->Const.MaxProgramTextureGatherComponents = 1;
416 ctx->Const.MinProgramTextureGatherOffset = -8;
417 ctx->Const.MaxProgramTextureGatherOffset = 7;
418 }
419
420 ctx->Const.MaxUniformBlockSize = 65536;
421
422 for (int i = 0; i < MESA_SHADER_STAGES; i++) {
423 struct gl_program_constants *prog = &ctx->Const.Program[i];
424
425 if (!stage_exists[i])
426 continue;
427
428 prog->MaxTextureImageUnits = max_samplers;
429
430 prog->MaxUniformBlocks = BRW_MAX_UBO;
431 prog->MaxCombinedUniformComponents =
432 prog->MaxUniformComponents +
433 ctx->Const.MaxUniformBlockSize / 4 * prog->MaxUniformBlocks;
434
435 prog->MaxAtomicCounters = MAX_ATOMIC_COUNTERS;
436 prog->MaxAtomicBuffers = BRW_MAX_ABO;
437 prog->MaxImageUniforms = compiler->scalar_stage[i] ? BRW_MAX_IMAGES : 0;
438 prog->MaxShaderStorageBlocks = BRW_MAX_SSBO;
439 }
440
441 ctx->Const.MaxTextureUnits =
442 MIN2(ctx->Const.MaxTextureCoordUnits,
443 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits);
444
445 ctx->Const.MaxUniformBufferBindings = num_stages * BRW_MAX_UBO;
446 ctx->Const.MaxCombinedUniformBlocks = num_stages * BRW_MAX_UBO;
447 ctx->Const.MaxCombinedAtomicBuffers = num_stages * BRW_MAX_ABO;
448 ctx->Const.MaxCombinedShaderStorageBlocks = num_stages * BRW_MAX_SSBO;
449 ctx->Const.MaxShaderStorageBufferBindings = num_stages * BRW_MAX_SSBO;
450 ctx->Const.MaxCombinedTextureImageUnits = num_stages * max_samplers;
451 ctx->Const.MaxCombinedImageUniforms = num_stages * BRW_MAX_IMAGES;
452
453
454 /* Hardware only supports a limited number of transform feedback buffers.
455 * So we need to override the Mesa default (which is based only on software
456 * limits).
457 */
458 ctx->Const.MaxTransformFeedbackBuffers = BRW_MAX_SOL_BUFFERS;
459
460 /* On Gen6, in the worst case, we use up one binding table entry per
461 * transform feedback component (see comments above the definition of
462 * BRW_MAX_SOL_BINDINGS, in brw_context.h), so we need to advertise a value
463 * for MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS equal to
464 * BRW_MAX_SOL_BINDINGS.
465 *
466 * In "separate components" mode, we need to divide this value by
467 * BRW_MAX_SOL_BUFFERS, so that the total number of binding table entries
468 * used up by all buffers will not exceed BRW_MAX_SOL_BINDINGS.
469 */
470 ctx->Const.MaxTransformFeedbackInterleavedComponents = BRW_MAX_SOL_BINDINGS;
471 ctx->Const.MaxTransformFeedbackSeparateComponents =
472 BRW_MAX_SOL_BINDINGS / BRW_MAX_SOL_BUFFERS;
473
474 ctx->Const.AlwaysUseGetTransformFeedbackVertexCount =
475 !can_do_mi_math_and_lrr(brw->screen);
476
477 int max_samples;
478 const int *msaa_modes = intel_supported_msaa_modes(brw->screen);
479 const int clamp_max_samples =
480 driQueryOptioni(&brw->optionCache, "clamp_max_samples");
481
482 if (clamp_max_samples < 0) {
483 max_samples = msaa_modes[0];
484 } else {
485 /* Select the largest supported MSAA mode that does not exceed
486 * clamp_max_samples.
487 */
488 max_samples = 0;
489 for (int i = 0; msaa_modes[i] != 0; ++i) {
490 if (msaa_modes[i] <= clamp_max_samples) {
491 max_samples = msaa_modes[i];
492 break;
493 }
494 }
495 }
496
497 ctx->Const.MaxSamples = max_samples;
498 ctx->Const.MaxColorTextureSamples = max_samples;
499 ctx->Const.MaxDepthTextureSamples = max_samples;
500 ctx->Const.MaxIntegerSamples = max_samples;
501 ctx->Const.MaxImageSamples = 0;
502
503 /* gen6_set_sample_maps() sets SampleMap{2,4,8}x variables which are used
504 * to map indices of rectangular grid to sample numbers within a pixel.
505 * These variables are used by GL_EXT_framebuffer_multisample_blit_scaled
506 * extension implementation. For more details see the comment above
507 * gen6_set_sample_maps() definition.
508 */
509 gen6_set_sample_maps(ctx);
510
511 ctx->Const.MinLineWidth = 1.0;
512 ctx->Const.MinLineWidthAA = 1.0;
513 if (devinfo->gen >= 6) {
514 ctx->Const.MaxLineWidth = 7.375;
515 ctx->Const.MaxLineWidthAA = 7.375;
516 ctx->Const.LineWidthGranularity = 0.125;
517 } else {
518 ctx->Const.MaxLineWidth = 7.0;
519 ctx->Const.MaxLineWidthAA = 7.0;
520 ctx->Const.LineWidthGranularity = 0.5;
521 }
522
523 /* For non-antialiased lines, we have to round the line width to the
524 * nearest whole number. Make sure that we don't advertise a line
525 * width that, when rounded, will be beyond the actual hardware
526 * maximum.
527 */
528 assert(roundf(ctx->Const.MaxLineWidth) <= ctx->Const.MaxLineWidth);
529
530 ctx->Const.MinPointSize = 1.0;
531 ctx->Const.MinPointSizeAA = 1.0;
532 ctx->Const.MaxPointSize = 255.0;
533 ctx->Const.MaxPointSizeAA = 255.0;
534 ctx->Const.PointSizeGranularity = 1.0;
535
536 if (devinfo->gen >= 5 || devinfo->is_g4x)
537 ctx->Const.MaxClipPlanes = 8;
538
539 ctx->Const.GLSLTessLevelsAsInputs = true;
540 ctx->Const.LowerTCSPatchVerticesIn = devinfo->gen >= 8;
541 ctx->Const.LowerTESPatchVerticesIn = true;
542 ctx->Const.PrimitiveRestartForPatches = true;
543
544 ctx->Const.Program[MESA_SHADER_VERTEX].MaxNativeInstructions = 16 * 1024;
545 ctx->Const.Program[MESA_SHADER_VERTEX].MaxAluInstructions = 0;
546 ctx->Const.Program[MESA_SHADER_VERTEX].MaxTexInstructions = 0;
547 ctx->Const.Program[MESA_SHADER_VERTEX].MaxTexIndirections = 0;
548 ctx->Const.Program[MESA_SHADER_VERTEX].MaxNativeAluInstructions = 0;
549 ctx->Const.Program[MESA_SHADER_VERTEX].MaxNativeTexInstructions = 0;
550 ctx->Const.Program[MESA_SHADER_VERTEX].MaxNativeTexIndirections = 0;
551 ctx->Const.Program[MESA_SHADER_VERTEX].MaxNativeAttribs = 16;
552 ctx->Const.Program[MESA_SHADER_VERTEX].MaxNativeTemps = 256;
553 ctx->Const.Program[MESA_SHADER_VERTEX].MaxNativeAddressRegs = 1;
554 ctx->Const.Program[MESA_SHADER_VERTEX].MaxNativeParameters = 1024;
555 ctx->Const.Program[MESA_SHADER_VERTEX].MaxEnvParams =
556 MIN2(ctx->Const.Program[MESA_SHADER_VERTEX].MaxNativeParameters,
557 ctx->Const.Program[MESA_SHADER_VERTEX].MaxEnvParams);
558
559 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeInstructions = 1024;
560 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeAluInstructions = 1024;
561 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeTexInstructions = 1024;
562 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeTexIndirections = 1024;
563 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeAttribs = 12;
564 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeTemps = 256;
565 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeAddressRegs = 0;
566 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeParameters = 1024;
567 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxEnvParams =
568 MIN2(ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeParameters,
569 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxEnvParams);
570
571 /* Fragment shaders use real, 32-bit twos-complement integers for all
572 * integer types.
573 */
574 ctx->Const.Program[MESA_SHADER_FRAGMENT].LowInt.RangeMin = 31;
575 ctx->Const.Program[MESA_SHADER_FRAGMENT].LowInt.RangeMax = 30;
576 ctx->Const.Program[MESA_SHADER_FRAGMENT].LowInt.Precision = 0;
577 ctx->Const.Program[MESA_SHADER_FRAGMENT].HighInt = ctx->Const.Program[MESA_SHADER_FRAGMENT].LowInt;
578 ctx->Const.Program[MESA_SHADER_FRAGMENT].MediumInt = ctx->Const.Program[MESA_SHADER_FRAGMENT].LowInt;
579
580 ctx->Const.Program[MESA_SHADER_VERTEX].LowInt.RangeMin = 31;
581 ctx->Const.Program[MESA_SHADER_VERTEX].LowInt.RangeMax = 30;
582 ctx->Const.Program[MESA_SHADER_VERTEX].LowInt.Precision = 0;
583 ctx->Const.Program[MESA_SHADER_VERTEX].HighInt = ctx->Const.Program[MESA_SHADER_VERTEX].LowInt;
584 ctx->Const.Program[MESA_SHADER_VERTEX].MediumInt = ctx->Const.Program[MESA_SHADER_VERTEX].LowInt;
585
586 /* Gen6 converts quads to polygon in beginning of 3D pipeline,
587 * but we're not sure how it's actually done for vertex order,
588 * that affect provoking vertex decision. Always use last vertex
589 * convention for quad primitive which works as expected for now.
590 */
591 if (devinfo->gen >= 6)
592 ctx->Const.QuadsFollowProvokingVertexConvention = false;
593
594 ctx->Const.NativeIntegers = true;
595 ctx->Const.VertexID_is_zero_based = true;
596
597 /* Regarding the CMP instruction, the Ivybridge PRM says:
598 *
599 * "For each enabled channel 0b or 1b is assigned to the appropriate flag
600 * bit and 0/all zeros or all ones (e.g, byte 0xFF, word 0xFFFF, DWord
601 * 0xFFFFFFFF) is assigned to dst."
602 *
603 * but PRMs for earlier generations say
604 *
605 * "In dword format, one GRF may store up to 8 results. When the register
606 * is used later as a vector of Booleans, as only LSB at each channel
607 * contains meaning [sic] data, software should make sure all higher bits
608 * are masked out (e.g. by 'and-ing' an [sic] 0x01 constant)."
609 *
610 * We select the representation of a true boolean uniform to be ~0, and fix
611 * the results of Gen <= 5 CMP instruction's with -(result & 1).
612 */
613 ctx->Const.UniformBooleanTrue = ~0;
614
615 /* From the gen4 PRM, volume 4 page 127:
616 *
617 * "For SURFTYPE_BUFFER non-rendertarget surfaces, this field specifies
618 * the base address of the first element of the surface, computed in
619 * software by adding the surface base address to the byte offset of
620 * the element in the buffer."
621 *
622 * However, unaligned accesses are slower, so enforce buffer alignment.
623 *
624 * In order to push UBO data, 3DSTATE_CONSTANT_XS imposes an additional
625 * restriction: the start of the buffer needs to be 32B aligned.
626 */
627 ctx->Const.UniformBufferOffsetAlignment = 32;
628
629 /* ShaderStorageBufferOffsetAlignment should be a cacheline (64 bytes) so
630 * that we can safely have the CPU and GPU writing the same SSBO on
631 * non-cachecoherent systems (our Atom CPUs). With UBOs, the GPU never
632 * writes, so there's no problem. For an SSBO, the GPU and the CPU can
633 * be updating disjoint regions of the buffer simultaneously and that will
634 * break if the regions overlap the same cacheline.
635 */
636 ctx->Const.ShaderStorageBufferOffsetAlignment = 64;
637 ctx->Const.TextureBufferOffsetAlignment = 16;
638 ctx->Const.MaxTextureBufferSize = 128 * 1024 * 1024;
639
640 if (devinfo->gen >= 6) {
641 ctx->Const.MaxVarying = 32;
642 ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents = 128;
643 ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxInputComponents =
644 compiler->scalar_stage[MESA_SHADER_GEOMETRY] ? 128 : 64;
645 ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxOutputComponents = 128;
646 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents = 128;
647 ctx->Const.Program[MESA_SHADER_TESS_CTRL].MaxInputComponents = 128;
648 ctx->Const.Program[MESA_SHADER_TESS_CTRL].MaxOutputComponents = 128;
649 ctx->Const.Program[MESA_SHADER_TESS_EVAL].MaxInputComponents = 128;
650 ctx->Const.Program[MESA_SHADER_TESS_EVAL].MaxOutputComponents = 128;
651 }
652
653 /* We want the GLSL compiler to emit code that uses condition codes */
654 for (int i = 0; i < MESA_SHADER_STAGES; i++) {
655 ctx->Const.ShaderCompilerOptions[i] =
656 brw->screen->compiler->glsl_compiler_options[i];
657 }
658
659 if (devinfo->gen >= 7) {
660 ctx->Const.MaxViewportWidth = 32768;
661 ctx->Const.MaxViewportHeight = 32768;
662 }
663
664 /* ARB_viewport_array, OES_viewport_array */
665 if (devinfo->gen >= 6) {
666 ctx->Const.MaxViewports = GEN6_NUM_VIEWPORTS;
667 ctx->Const.ViewportSubpixelBits = 0;
668
669 /* Cast to float before negating because MaxViewportWidth is unsigned.
670 */
671 ctx->Const.ViewportBounds.Min = -(float)ctx->Const.MaxViewportWidth;
672 ctx->Const.ViewportBounds.Max = ctx->Const.MaxViewportWidth;
673 }
674
675 /* ARB_gpu_shader5 */
676 if (devinfo->gen >= 7)
677 ctx->Const.MaxVertexStreams = MIN2(4, MAX_VERTEX_STREAMS);
678
679 /* ARB_framebuffer_no_attachments */
680 ctx->Const.MaxFramebufferWidth = 16384;
681 ctx->Const.MaxFramebufferHeight = 16384;
682 ctx->Const.MaxFramebufferLayers = ctx->Const.MaxArrayTextureLayers;
683 ctx->Const.MaxFramebufferSamples = max_samples;
684
685 /* OES_primitive_bounding_box */
686 ctx->Const.NoPrimitiveBoundingBoxOutput = true;
687
688 /* TODO: We should be able to use STD430 packing by default on all hardware
689 * but some piglit tests [1] currently fail on SNB when this is enabled.
690 * The problem is the messages we're using for doing uniform pulls
691 * in the vec4 back-end on SNB is the OWORD block load instruction, which
692 * takes its offset in units of OWORDS (16 bytes). On IVB+, we use the
693 * sampler which doesn't have these restrictions.
694 *
695 * In the scalar back-end, we use the sampler for dynamic uniform loads and
696 * pull an entire cache line at a time for constant offset loads both of
697 * which support almost any alignment.
698 *
699 * [1] glsl-1.40/uniform_buffer/vs-float-array-variable-index.shader_test
700 */
701 if (devinfo->gen >= 7)
702 ctx->Const.UseSTD430AsDefaultPacking = true;
703
704 if (!(ctx->Const.ContextFlags & GL_CONTEXT_FLAG_DEBUG_BIT))
705 ctx->Const.AllowMappedBuffersDuringExecution = true;
706
707 /* GL_ARB_get_program_binary */
708 ctx->Const.NumProgramBinaryFormats = 1;
709 }
710
711 static void
712 brw_initialize_cs_context_constants(struct brw_context *brw)
713 {
714 struct gl_context *ctx = &brw->ctx;
715 const struct intel_screen *screen = brw->screen;
716 struct gen_device_info *devinfo = &brw->screen->devinfo;
717
718 /* FINISHME: Do this for all platforms that the kernel supports */
719 if (devinfo->is_cherryview &&
720 screen->subslice_total > 0 && screen->eu_total > 0) {
721 /* Logical CS threads = EUs per subslice * 7 threads per EU */
722 uint32_t max_cs_threads = screen->eu_total / screen->subslice_total * 7;
723
724 /* Fuse configurations may give more threads than expected, never less. */
725 if (max_cs_threads > devinfo->max_cs_threads)
726 devinfo->max_cs_threads = max_cs_threads;
727 }
728
729 /* Maximum number of scalar compute shader invocations that can be run in
730 * parallel in the same subslice assuming SIMD32 dispatch.
731 *
732 * We don't advertise more than 64 threads, because we are limited to 64 by
733 * our usage of thread_width_max in the gpgpu walker command. This only
734 * currently impacts Haswell, which otherwise might be able to advertise 70
735 * threads. With SIMD32 and 64 threads, Haswell still provides twice the
736 * required the number of invocation needed for ARB_compute_shader.
737 */
738 const unsigned max_threads = MIN2(64, devinfo->max_cs_threads);
739 const uint32_t max_invocations = 32 * max_threads;
740 ctx->Const.MaxComputeWorkGroupSize[0] = max_invocations;
741 ctx->Const.MaxComputeWorkGroupSize[1] = max_invocations;
742 ctx->Const.MaxComputeWorkGroupSize[2] = max_invocations;
743 ctx->Const.MaxComputeWorkGroupInvocations = max_invocations;
744 ctx->Const.MaxComputeSharedMemorySize = 64 * 1024;
745 }
746
747 /**
748 * Process driconf (drirc) options, setting appropriate context flags.
749 *
750 * intelInitExtensions still pokes at optionCache directly, in order to
751 * avoid advertising various extensions. No flags are set, so it makes
752 * sense to continue doing that there.
753 */
754 static void
755 brw_process_driconf_options(struct brw_context *brw)
756 {
757 const struct gen_device_info *devinfo = &brw->screen->devinfo;
758 struct gl_context *ctx = &brw->ctx;
759
760 driOptionCache *options = &brw->optionCache;
761 driParseConfigFiles(options, &brw->screen->optionCache,
762 brw->driContext->driScreenPriv->myNum, "i965");
763
764 int bo_reuse_mode = driQueryOptioni(options, "bo_reuse");
765 switch (bo_reuse_mode) {
766 case DRI_CONF_BO_REUSE_DISABLED:
767 break;
768 case DRI_CONF_BO_REUSE_ALL:
769 brw_bufmgr_enable_reuse(brw->bufmgr);
770 break;
771 }
772
773 if (INTEL_DEBUG & DEBUG_NO_HIZ) {
774 brw->has_hiz = false;
775 /* On gen6, you can only do separate stencil with HIZ. */
776 if (devinfo->gen == 6)
777 brw->has_separate_stencil = false;
778 }
779
780 if (driQueryOptionb(options, "mesa_no_error"))
781 ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR;
782
783 if (driQueryOptionb(options, "always_flush_batch")) {
784 fprintf(stderr, "flushing batchbuffer before/after each draw call\n");
785 brw->always_flush_batch = true;
786 }
787
788 if (driQueryOptionb(options, "always_flush_cache")) {
789 fprintf(stderr, "flushing GPU caches before/after each draw call\n");
790 brw->always_flush_cache = true;
791 }
792
793 if (driQueryOptionb(options, "disable_throttling")) {
794 fprintf(stderr, "disabling flush throttling\n");
795 brw->disable_throttling = true;
796 }
797
798 brw->precompile = driQueryOptionb(&brw->optionCache, "shader_precompile");
799
800 if (driQueryOptionb(&brw->optionCache, "precise_trig"))
801 brw->screen->compiler->precise_trig = true;
802
803 ctx->Const.ForceGLSLExtensionsWarn =
804 driQueryOptionb(options, "force_glsl_extensions_warn");
805
806 ctx->Const.ForceGLSLVersion =
807 driQueryOptioni(options, "force_glsl_version");
808
809 ctx->Const.DisableGLSLLineContinuations =
810 driQueryOptionb(options, "disable_glsl_line_continuations");
811
812 ctx->Const.AllowGLSLExtensionDirectiveMidShader =
813 driQueryOptionb(options, "allow_glsl_extension_directive_midshader");
814
815 ctx->Const.AllowGLSLBuiltinVariableRedeclaration =
816 driQueryOptionb(options, "allow_glsl_builtin_variable_redeclaration");
817
818 ctx->Const.AllowHigherCompatVersion =
819 driQueryOptionb(options, "allow_higher_compat_version");
820
821 ctx->Const.ForceGLSLAbsSqrt =
822 driQueryOptionb(options, "force_glsl_abs_sqrt");
823
824 ctx->Const.GLSLZeroInit = driQueryOptionb(options, "glsl_zero_init");
825
826 brw->dual_color_blend_by_location =
827 driQueryOptionb(options, "dual_color_blend_by_location");
828
829 ctx->Const.AllowGLSLCrossStageInterpolationMismatch =
830 driQueryOptionb(options, "allow_glsl_cross_stage_interpolation_mismatch");
831
832 ctx->Const.dri_config_options_sha1 = ralloc_array(brw, unsigned char, 20);
833 driComputeOptionsSha1(&brw->screen->optionCache,
834 ctx->Const.dri_config_options_sha1);
835 }
836
837 GLboolean
838 brwCreateContext(gl_api api,
839 const struct gl_config *mesaVis,
840 __DRIcontext *driContextPriv,
841 const struct __DriverContextConfig *ctx_config,
842 unsigned *dri_ctx_error,
843 void *sharedContextPrivate)
844 {
845 struct gl_context *shareCtx = (struct gl_context *) sharedContextPrivate;
846 struct intel_screen *screen = driContextPriv->driScreenPriv->driverPrivate;
847 const struct gen_device_info *devinfo = &screen->devinfo;
848 struct dd_function_table functions;
849
850 /* Only allow the __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS flag if the kernel
851 * provides us with context reset notifications.
852 */
853 uint32_t allowed_flags = __DRI_CTX_FLAG_DEBUG |
854 __DRI_CTX_FLAG_FORWARD_COMPATIBLE |
855 __DRI_CTX_FLAG_NO_ERROR;
856
857 if (screen->has_context_reset_notification)
858 allowed_flags |= __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS;
859
860 if (ctx_config->flags & ~allowed_flags) {
861 *dri_ctx_error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
862 return false;
863 }
864
865 if (ctx_config->attribute_mask &
866 ~(__DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY |
867 __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR)) {
868 *dri_ctx_error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
869 return false;
870 }
871
872 bool notify_reset =
873 ((ctx_config->attribute_mask & __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY) &&
874 ctx_config->reset_strategy != __DRI_CTX_RESET_NO_NOTIFICATION);
875
876 GLenum release_behavior = GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH;
877 if (ctx_config->attribute_mask & __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR) {
878 switch (ctx_config->release_behavior) {
879 case __DRI_CTX_RELEASE_BEHAVIOR_NONE:
880 release_behavior = GL_NONE;
881 break;
882 case __DRI_CTX_RELEASE_BEHAVIOR_FLUSH:
883 break;
884 default:
885 *dri_ctx_error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
886 return false;
887 }
888 }
889
890 struct brw_context *brw = rzalloc(NULL, struct brw_context);
891 if (!brw) {
892 fprintf(stderr, "%s: failed to alloc context\n", __func__);
893 *dri_ctx_error = __DRI_CTX_ERROR_NO_MEMORY;
894 return false;
895 }
896
897 driContextPriv->driverPrivate = brw;
898 brw->driContext = driContextPriv;
899 brw->screen = screen;
900 brw->bufmgr = screen->bufmgr;
901
902 brw->has_hiz = devinfo->has_hiz_and_separate_stencil;
903 brw->has_separate_stencil = devinfo->has_hiz_and_separate_stencil;
904
905 brw->has_swizzling = screen->hw_has_swizzling;
906
907 brw->isl_dev = screen->isl_dev;
908
909 brw->vs.base.stage = MESA_SHADER_VERTEX;
910 brw->tcs.base.stage = MESA_SHADER_TESS_CTRL;
911 brw->tes.base.stage = MESA_SHADER_TESS_EVAL;
912 brw->gs.base.stage = MESA_SHADER_GEOMETRY;
913 brw->wm.base.stage = MESA_SHADER_FRAGMENT;
914 brw->cs.base.stage = MESA_SHADER_COMPUTE;
915 if (devinfo->gen >= 8) {
916 brw->vtbl.emit_depth_stencil_hiz = gen8_emit_depth_stencil_hiz;
917 } else if (devinfo->gen >= 7) {
918 brw->vtbl.emit_depth_stencil_hiz = gen7_emit_depth_stencil_hiz;
919 } else if (devinfo->gen >= 6) {
920 brw->vtbl.emit_depth_stencil_hiz = gen6_emit_depth_stencil_hiz;
921 } else {
922 brw->vtbl.emit_depth_stencil_hiz = brw_emit_depth_stencil_hiz;
923 }
924
925 brw_init_driver_functions(brw, &functions);
926
927 if (notify_reset)
928 functions.GetGraphicsResetStatus = brw_get_graphics_reset_status;
929
930 struct gl_context *ctx = &brw->ctx;
931
932 if (!_mesa_initialize_context(ctx, api, mesaVis, shareCtx, &functions)) {
933 *dri_ctx_error = __DRI_CTX_ERROR_NO_MEMORY;
934 fprintf(stderr, "%s: failed to init mesa context\n", __func__);
935 intelDestroyContext(driContextPriv);
936 return false;
937 }
938
939 driContextSetFlags(ctx, ctx_config->flags);
940
941 /* Initialize the software rasterizer and helper modules.
942 *
943 * As of GL 3.1 core, the gen4+ driver doesn't need the swrast context for
944 * software fallbacks (which we have to support on legacy GL to do weird
945 * glDrawPixels(), glBitmap(), and other functions).
946 */
947 if (api != API_OPENGL_CORE && api != API_OPENGLES2) {
948 _swrast_CreateContext(ctx);
949 }
950
951 _vbo_CreateContext(ctx);
952 if (ctx->swrast_context) {
953 _tnl_CreateContext(ctx);
954 TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;
955 _swsetup_CreateContext(ctx);
956
957 /* Configure swrast to match hardware characteristics: */
958 _swrast_allow_pixel_fog(ctx, false);
959 _swrast_allow_vertex_fog(ctx, true);
960 }
961
962 _mesa_meta_init(ctx);
963
964 brw_process_driconf_options(brw);
965
966 if (INTEL_DEBUG & DEBUG_PERF)
967 brw->perf_debug = true;
968
969 brw_initialize_cs_context_constants(brw);
970 brw_initialize_context_constants(brw);
971
972 ctx->Const.ResetStrategy = notify_reset
973 ? GL_LOSE_CONTEXT_ON_RESET_ARB : GL_NO_RESET_NOTIFICATION_ARB;
974
975 /* Reinitialize the context point state. It depends on ctx->Const values. */
976 _mesa_init_point(ctx);
977
978 intel_fbo_init(brw);
979
980 intel_batchbuffer_init(brw);
981
982 if (devinfo->gen >= 6) {
983 /* Create a new hardware context. Using a hardware context means that
984 * our GPU state will be saved/restored on context switch, allowing us
985 * to assume that the GPU is in the same state we left it in.
986 *
987 * This is required for transform feedback buffer offsets, query objects,
988 * and also allows us to reduce how much state we have to emit.
989 */
990 brw->hw_ctx = brw_create_hw_context(brw->bufmgr);
991
992 if (!brw->hw_ctx) {
993 fprintf(stderr, "Failed to create hardware context.\n");
994 intelDestroyContext(driContextPriv);
995 return false;
996 }
997
998 int hw_priority = BRW_CONTEXT_MEDIUM_PRIORITY;
999 if (ctx_config->attribute_mask & __DRIVER_CONTEXT_ATTRIB_PRIORITY) {
1000 switch (ctx_config->priority) {
1001 case __DRI_CTX_PRIORITY_LOW:
1002 hw_priority = BRW_CONTEXT_LOW_PRIORITY;
1003 break;
1004 case __DRI_CTX_PRIORITY_HIGH:
1005 hw_priority = BRW_CONTEXT_HIGH_PRIORITY;
1006 break;
1007 }
1008 }
1009 if (hw_priority != I915_CONTEXT_DEFAULT_PRIORITY &&
1010 brw_hw_context_set_priority(brw->bufmgr, brw->hw_ctx, hw_priority)) {
1011 fprintf(stderr,
1012 "Failed to set priority [%d:%d] for hardware context.\n",
1013 ctx_config->priority, hw_priority);
1014 intelDestroyContext(driContextPriv);
1015 return false;
1016 }
1017 }
1018
1019 if (brw_init_pipe_control(brw, devinfo)) {
1020 *dri_ctx_error = __DRI_CTX_ERROR_NO_MEMORY;
1021 intelDestroyContext(driContextPriv);
1022 return false;
1023 }
1024
1025 if (devinfo->gen == 10) {
1026 fprintf(stderr,
1027 "WARNING: i965 does not fully support Gen10 yet.\n"
1028 "Instability or lower performance might occur.\n");
1029
1030 }
1031
1032 brw_init_state(brw);
1033
1034 intelInitExtensions(ctx);
1035
1036 brw_init_surface_formats(brw);
1037
1038 brw_blorp_init(brw);
1039
1040 brw->urb.size = devinfo->urb.size;
1041
1042 if (devinfo->gen == 6)
1043 brw->urb.gs_present = false;
1044
1045 brw->prim_restart.in_progress = false;
1046 brw->prim_restart.enable_cut_index = false;
1047 brw->gs.enabled = false;
1048 brw->clip.viewport_count = 1;
1049
1050 brw->predicate.state = BRW_PREDICATE_STATE_RENDER;
1051
1052 brw->max_gtt_map_object_size = screen->max_gtt_map_object_size;
1053
1054 ctx->VertexProgram._MaintainTnlProgram = true;
1055 ctx->FragmentProgram._MaintainTexEnvProgram = true;
1056
1057 brw_draw_init( brw );
1058
1059 if ((ctx_config->flags & __DRI_CTX_FLAG_DEBUG) != 0) {
1060 /* Turn on some extra GL_ARB_debug_output generation. */
1061 brw->perf_debug = true;
1062 }
1063
1064 if ((ctx_config->flags & __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS) != 0) {
1065 ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB;
1066 ctx->Const.RobustAccess = GL_TRUE;
1067 }
1068
1069 ctx->Const.ContextReleaseBehavior = release_behavior;
1070
1071 if (INTEL_DEBUG & DEBUG_SHADER_TIME)
1072 brw_init_shader_time(brw);
1073
1074 _mesa_override_extensions(ctx);
1075 _mesa_compute_version(ctx);
1076
1077 _mesa_initialize_dispatch_tables(ctx);
1078 _mesa_initialize_vbo_vtxfmt(ctx);
1079
1080 if (ctx->Extensions.INTEL_performance_query)
1081 brw_init_performance_queries(brw);
1082
1083 vbo_use_buffer_objects(ctx);
1084 vbo_always_unmap_buffers(ctx);
1085
1086 brw_disk_cache_init(brw);
1087
1088 return true;
1089 }
1090
1091 void
1092 intelDestroyContext(__DRIcontext * driContextPriv)
1093 {
1094 struct brw_context *brw =
1095 (struct brw_context *) driContextPriv->driverPrivate;
1096 struct gl_context *ctx = &brw->ctx;
1097 const struct gen_device_info *devinfo = &brw->screen->devinfo;
1098
1099 _mesa_meta_free(&brw->ctx);
1100
1101 if (INTEL_DEBUG & DEBUG_SHADER_TIME) {
1102 /* Force a report. */
1103 brw->shader_time.report_time = 0;
1104
1105 brw_collect_and_report_shader_time(brw);
1106 brw_destroy_shader_time(brw);
1107 }
1108
1109 if (devinfo->gen >= 6)
1110 blorp_finish(&brw->blorp);
1111
1112 brw_destroy_state(brw);
1113 brw_draw_destroy(brw);
1114
1115 brw_bo_unreference(brw->curbe.curbe_bo);
1116
1117 brw_bo_unreference(brw->vs.base.scratch_bo);
1118 brw_bo_unreference(brw->tcs.base.scratch_bo);
1119 brw_bo_unreference(brw->tes.base.scratch_bo);
1120 brw_bo_unreference(brw->gs.base.scratch_bo);
1121 brw_bo_unreference(brw->wm.base.scratch_bo);
1122
1123 brw_bo_unreference(brw->vs.base.push_const_bo);
1124 brw_bo_unreference(brw->tcs.base.push_const_bo);
1125 brw_bo_unreference(brw->tes.base.push_const_bo);
1126 brw_bo_unreference(brw->gs.base.push_const_bo);
1127 brw_bo_unreference(brw->wm.base.push_const_bo);
1128
1129 brw_destroy_hw_context(brw->bufmgr, brw->hw_ctx);
1130
1131 if (ctx->swrast_context) {
1132 _swsetup_DestroyContext(&brw->ctx);
1133 _tnl_DestroyContext(&brw->ctx);
1134 }
1135 _vbo_DestroyContext(&brw->ctx);
1136
1137 if (ctx->swrast_context)
1138 _swrast_DestroyContext(&brw->ctx);
1139
1140 brw_fini_pipe_control(brw);
1141 intel_batchbuffer_free(&brw->batch);
1142
1143 brw_bo_unreference(brw->throttle_batch[1]);
1144 brw_bo_unreference(brw->throttle_batch[0]);
1145 brw->throttle_batch[1] = NULL;
1146 brw->throttle_batch[0] = NULL;
1147
1148 driDestroyOptionCache(&brw->optionCache);
1149
1150 /* free the Mesa context */
1151 _mesa_free_context_data(&brw->ctx);
1152
1153 ralloc_free(brw);
1154 driContextPriv->driverPrivate = NULL;
1155 }
1156
1157 GLboolean
1158 intelUnbindContext(__DRIcontext * driContextPriv)
1159 {
1160 /* Unset current context and dispath table */
1161 _mesa_make_current(NULL, NULL, NULL);
1162
1163 return true;
1164 }
1165
1166 /**
1167 * Fixes up the context for GLES23 with our default-to-sRGB-capable behavior
1168 * on window system framebuffers.
1169 *
1170 * Desktop GL is fairly reasonable in its handling of sRGB: You can ask if
1171 * your renderbuffer can do sRGB encode, and you can flip a switch that does
1172 * sRGB encode if the renderbuffer can handle it. You can ask specifically
1173 * for a visual where you're guaranteed to be capable, but it turns out that
1174 * everyone just makes all their ARGB8888 visuals capable and doesn't offer
1175 * incapable ones, because there's no difference between the two in resources
1176 * used. Applications thus get built that accidentally rely on the default
1177 * visual choice being sRGB, so we make ours sRGB capable. Everything sounds
1178 * great...
1179 *
1180 * But for GLES2/3, they decided that it was silly to not turn on sRGB encode
1181 * for sRGB renderbuffers you made with the GL_EXT_texture_sRGB equivalent.
1182 * So they removed the enable knob and made it "if the renderbuffer is sRGB
1183 * capable, do sRGB encode". Then, for your window system renderbuffers, you
1184 * can ask for sRGB visuals and get sRGB encode, or not ask for sRGB visuals
1185 * and get no sRGB encode (assuming that both kinds of visual are available).
1186 * Thus our choice to support sRGB by default on our visuals for desktop would
1187 * result in broken rendering of GLES apps that aren't expecting sRGB encode.
1188 *
1189 * Unfortunately, renderbuffer setup happens before a context is created. So
1190 * in intel_screen.c we always set up sRGB, and here, if you're a GLES2/3
1191 * context (without an sRGB visual), we go turn that back off before anyone
1192 * finds out.
1193 */
1194 static void
1195 intel_gles3_srgb_workaround(struct brw_context *brw,
1196 struct gl_framebuffer *fb)
1197 {
1198 struct gl_context *ctx = &brw->ctx;
1199
1200 if (_mesa_is_desktop_gl(ctx) || !fb->Visual.sRGBCapable)
1201 return;
1202
1203 for (int i = 0; i < BUFFER_COUNT; i++) {
1204 struct gl_renderbuffer *rb = fb->Attachment[i].Renderbuffer;
1205
1206 /* Check if sRGB was specifically asked for. */
1207 struct intel_renderbuffer *irb = intel_get_renderbuffer(fb, i);
1208 if (irb && irb->need_srgb)
1209 return;
1210
1211 if (rb)
1212 rb->Format = _mesa_get_srgb_format_linear(rb->Format);
1213 }
1214 /* Disable sRGB from framebuffers that are not compatible. */
1215 fb->Visual.sRGBCapable = false;
1216 }
1217
1218 GLboolean
1219 intelMakeCurrent(__DRIcontext * driContextPriv,
1220 __DRIdrawable * driDrawPriv,
1221 __DRIdrawable * driReadPriv)
1222 {
1223 struct brw_context *brw;
1224
1225 if (driContextPriv)
1226 brw = (struct brw_context *) driContextPriv->driverPrivate;
1227 else
1228 brw = NULL;
1229
1230 if (driContextPriv) {
1231 struct gl_context *ctx = &brw->ctx;
1232 struct gl_framebuffer *fb, *readFb;
1233
1234 if (driDrawPriv == NULL) {
1235 fb = _mesa_get_incomplete_framebuffer();
1236 } else {
1237 fb = driDrawPriv->driverPrivate;
1238 driContextPriv->dri2.draw_stamp = driDrawPriv->dri2.stamp - 1;
1239 }
1240
1241 if (driReadPriv == NULL) {
1242 readFb = _mesa_get_incomplete_framebuffer();
1243 } else {
1244 readFb = driReadPriv->driverPrivate;
1245 driContextPriv->dri2.read_stamp = driReadPriv->dri2.stamp - 1;
1246 }
1247
1248 /* The sRGB workaround changes the renderbuffer's format. We must change
1249 * the format before the renderbuffer's miptree get's allocated, otherwise
1250 * the formats of the renderbuffer and its miptree will differ.
1251 */
1252 intel_gles3_srgb_workaround(brw, fb);
1253 intel_gles3_srgb_workaround(brw, readFb);
1254
1255 /* If the context viewport hasn't been initialized, force a call out to
1256 * the loader to get buffers so we have a drawable size for the initial
1257 * viewport. */
1258 if (!brw->ctx.ViewportInitialized)
1259 intel_prepare_render(brw);
1260
1261 _mesa_make_current(ctx, fb, readFb);
1262 } else {
1263 _mesa_make_current(NULL, NULL, NULL);
1264 }
1265
1266 return true;
1267 }
1268
1269 void
1270 intel_resolve_for_dri2_flush(struct brw_context *brw,
1271 __DRIdrawable *drawable)
1272 {
1273 const struct gen_device_info *devinfo = &brw->screen->devinfo;
1274
1275 if (devinfo->gen < 6) {
1276 /* MSAA and fast color clear are not supported, so don't waste time
1277 * checking whether a resolve is needed.
1278 */
1279 return;
1280 }
1281
1282 struct gl_framebuffer *fb = drawable->driverPrivate;
1283 struct intel_renderbuffer *rb;
1284
1285 /* Usually, only the back buffer will need to be downsampled. However,
1286 * the front buffer will also need it if the user has rendered into it.
1287 */
1288 static const gl_buffer_index buffers[2] = {
1289 BUFFER_BACK_LEFT,
1290 BUFFER_FRONT_LEFT,
1291 };
1292
1293 for (int i = 0; i < 2; ++i) {
1294 rb = intel_get_renderbuffer(fb, buffers[i]);
1295 if (rb == NULL || rb->mt == NULL)
1296 continue;
1297 if (rb->mt->surf.samples == 1) {
1298 assert(rb->mt_layer == 0 && rb->mt_level == 0 &&
1299 rb->layer_count == 1);
1300 intel_miptree_prepare_external(brw, rb->mt);
1301 } else {
1302 intel_renderbuffer_downsample(brw, rb);
1303 }
1304 }
1305 }
1306
1307 static unsigned
1308 intel_bits_per_pixel(const struct intel_renderbuffer *rb)
1309 {
1310 return _mesa_get_format_bytes(intel_rb_format(rb)) * 8;
1311 }
1312
1313 static void
1314 intel_query_dri2_buffers(struct brw_context *brw,
1315 __DRIdrawable *drawable,
1316 __DRIbuffer **buffers,
1317 int *count);
1318
1319 static void
1320 intel_process_dri2_buffer(struct brw_context *brw,
1321 __DRIdrawable *drawable,
1322 __DRIbuffer *buffer,
1323 struct intel_renderbuffer *rb,
1324 const char *buffer_name);
1325
1326 static void
1327 intel_update_image_buffers(struct brw_context *brw, __DRIdrawable *drawable);
1328
1329 static void
1330 intel_update_dri2_buffers(struct brw_context *brw, __DRIdrawable *drawable)
1331 {
1332 struct gl_framebuffer *fb = drawable->driverPrivate;
1333 struct intel_renderbuffer *rb;
1334 __DRIbuffer *buffers = NULL;
1335 int count;
1336 const char *region_name;
1337
1338 /* Set this up front, so that in case our buffers get invalidated
1339 * while we're getting new buffers, we don't clobber the stamp and
1340 * thus ignore the invalidate. */
1341 drawable->lastStamp = drawable->dri2.stamp;
1342
1343 if (unlikely(INTEL_DEBUG & DEBUG_DRI))
1344 fprintf(stderr, "enter %s, drawable %p\n", __func__, drawable);
1345
1346 intel_query_dri2_buffers(brw, drawable, &buffers, &count);
1347
1348 if (buffers == NULL)
1349 return;
1350
1351 for (int i = 0; i < count; i++) {
1352 switch (buffers[i].attachment) {
1353 case __DRI_BUFFER_FRONT_LEFT:
1354 rb = intel_get_renderbuffer(fb, BUFFER_FRONT_LEFT);
1355 region_name = "dri2 front buffer";
1356 break;
1357
1358 case __DRI_BUFFER_FAKE_FRONT_LEFT:
1359 rb = intel_get_renderbuffer(fb, BUFFER_FRONT_LEFT);
1360 region_name = "dri2 fake front buffer";
1361 break;
1362
1363 case __DRI_BUFFER_BACK_LEFT:
1364 rb = intel_get_renderbuffer(fb, BUFFER_BACK_LEFT);
1365 region_name = "dri2 back buffer";
1366 break;
1367
1368 case __DRI_BUFFER_DEPTH:
1369 case __DRI_BUFFER_HIZ:
1370 case __DRI_BUFFER_DEPTH_STENCIL:
1371 case __DRI_BUFFER_STENCIL:
1372 case __DRI_BUFFER_ACCUM:
1373 default:
1374 fprintf(stderr,
1375 "unhandled buffer attach event, attachment type %d\n",
1376 buffers[i].attachment);
1377 return;
1378 }
1379
1380 intel_process_dri2_buffer(brw, drawable, &buffers[i], rb, region_name);
1381 }
1382
1383 }
1384
1385 void
1386 intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
1387 {
1388 struct brw_context *brw = context->driverPrivate;
1389 __DRIscreen *dri_screen = brw->screen->driScrnPriv;
1390
1391 /* Set this up front, so that in case our buffers get invalidated
1392 * while we're getting new buffers, we don't clobber the stamp and
1393 * thus ignore the invalidate. */
1394 drawable->lastStamp = drawable->dri2.stamp;
1395
1396 if (unlikely(INTEL_DEBUG & DEBUG_DRI))
1397 fprintf(stderr, "enter %s, drawable %p\n", __func__, drawable);
1398
1399 if (dri_screen->image.loader)
1400 intel_update_image_buffers(brw, drawable);
1401 else
1402 intel_update_dri2_buffers(brw, drawable);
1403
1404 driUpdateFramebufferSize(&brw->ctx, drawable);
1405 }
1406
1407 /**
1408 * intel_prepare_render should be called anywhere that curent read/drawbuffer
1409 * state is required.
1410 */
1411 void
1412 intel_prepare_render(struct brw_context *brw)
1413 {
1414 struct gl_context *ctx = &brw->ctx;
1415 __DRIcontext *driContext = brw->driContext;
1416 __DRIdrawable *drawable;
1417
1418 drawable = driContext->driDrawablePriv;
1419 if (drawable && drawable->dri2.stamp != driContext->dri2.draw_stamp) {
1420 if (drawable->lastStamp != drawable->dri2.stamp)
1421 intel_update_renderbuffers(driContext, drawable);
1422 driContext->dri2.draw_stamp = drawable->dri2.stamp;
1423 }
1424
1425 drawable = driContext->driReadablePriv;
1426 if (drawable && drawable->dri2.stamp != driContext->dri2.read_stamp) {
1427 if (drawable->lastStamp != drawable->dri2.stamp)
1428 intel_update_renderbuffers(driContext, drawable);
1429 driContext->dri2.read_stamp = drawable->dri2.stamp;
1430 }
1431
1432 /* If we're currently rendering to the front buffer, the rendering
1433 * that will happen next will probably dirty the front buffer. So
1434 * mark it as dirty here.
1435 */
1436 if (_mesa_is_front_buffer_drawing(ctx->DrawBuffer))
1437 brw->front_buffer_dirty = true;
1438 }
1439
1440 /**
1441 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
1442 *
1443 * To determine which DRI buffers to request, examine the renderbuffers
1444 * attached to the drawable's framebuffer. Then request the buffers with
1445 * DRI2GetBuffers() or DRI2GetBuffersWithFormat().
1446 *
1447 * This is called from intel_update_renderbuffers().
1448 *
1449 * \param drawable Drawable whose buffers are queried.
1450 * \param buffers [out] List of buffers returned by DRI2 query.
1451 * \param buffer_count [out] Number of buffers returned.
1452 *
1453 * \see intel_update_renderbuffers()
1454 * \see DRI2GetBuffers()
1455 * \see DRI2GetBuffersWithFormat()
1456 */
1457 static void
1458 intel_query_dri2_buffers(struct brw_context *brw,
1459 __DRIdrawable *drawable,
1460 __DRIbuffer **buffers,
1461 int *buffer_count)
1462 {
1463 __DRIscreen *dri_screen = brw->screen->driScrnPriv;
1464 struct gl_framebuffer *fb = drawable->driverPrivate;
1465 int i = 0;
1466 unsigned attachments[8];
1467
1468 struct intel_renderbuffer *front_rb;
1469 struct intel_renderbuffer *back_rb;
1470
1471 front_rb = intel_get_renderbuffer(fb, BUFFER_FRONT_LEFT);
1472 back_rb = intel_get_renderbuffer(fb, BUFFER_BACK_LEFT);
1473
1474 memset(attachments, 0, sizeof(attachments));
1475 if ((_mesa_is_front_buffer_drawing(fb) ||
1476 _mesa_is_front_buffer_reading(fb) ||
1477 !back_rb) && front_rb) {
1478 /* If a fake front buffer is in use, then querying for
1479 * __DRI_BUFFER_FRONT_LEFT will cause the server to copy the image from
1480 * the real front buffer to the fake front buffer. So before doing the
1481 * query, we need to make sure all the pending drawing has landed in the
1482 * real front buffer.
1483 */
1484 intel_batchbuffer_flush(brw);
1485 intel_flush_front(&brw->ctx);
1486
1487 attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
1488 attachments[i++] = intel_bits_per_pixel(front_rb);
1489 } else if (front_rb && brw->front_buffer_dirty) {
1490 /* We have pending front buffer rendering, but we aren't querying for a
1491 * front buffer. If the front buffer we have is a fake front buffer,
1492 * the X server is going to throw it away when it processes the query.
1493 * So before doing the query, make sure all the pending drawing has
1494 * landed in the real front buffer.
1495 */
1496 intel_batchbuffer_flush(brw);
1497 intel_flush_front(&brw->ctx);
1498 }
1499
1500 if (back_rb) {
1501 attachments[i++] = __DRI_BUFFER_BACK_LEFT;
1502 attachments[i++] = intel_bits_per_pixel(back_rb);
1503 }
1504
1505 assert(i <= ARRAY_SIZE(attachments));
1506
1507 *buffers =
1508 dri_screen->dri2.loader->getBuffersWithFormat(drawable,
1509 &drawable->w,
1510 &drawable->h,
1511 attachments, i / 2,
1512 buffer_count,
1513 drawable->loaderPrivate);
1514 }
1515
1516 /**
1517 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
1518 *
1519 * This is called from intel_update_renderbuffers().
1520 *
1521 * \par Note:
1522 * DRI buffers whose attachment point is DRI2BufferStencil or
1523 * DRI2BufferDepthStencil are handled as special cases.
1524 *
1525 * \param buffer_name is a human readable name, such as "dri2 front buffer",
1526 * that is passed to brw_bo_gem_create_from_name().
1527 *
1528 * \see intel_update_renderbuffers()
1529 */
1530 static void
1531 intel_process_dri2_buffer(struct brw_context *brw,
1532 __DRIdrawable *drawable,
1533 __DRIbuffer *buffer,
1534 struct intel_renderbuffer *rb,
1535 const char *buffer_name)
1536 {
1537 struct gl_framebuffer *fb = drawable->driverPrivate;
1538 struct brw_bo *bo;
1539
1540 if (!rb)
1541 return;
1542
1543 unsigned num_samples = rb->Base.Base.NumSamples;
1544
1545 /* We try to avoid closing and reopening the same BO name, because the first
1546 * use of a mapping of the buffer involves a bunch of page faulting which is
1547 * moderately expensive.
1548 */
1549 struct intel_mipmap_tree *last_mt;
1550 if (num_samples == 0)
1551 last_mt = rb->mt;
1552 else
1553 last_mt = rb->singlesample_mt;
1554
1555 uint32_t old_name = 0;
1556 if (last_mt) {
1557 /* The bo already has a name because the miptree was created by a
1558 * previous call to intel_process_dri2_buffer(). If a bo already has a
1559 * name, then brw_bo_flink() is a low-cost getter. It does not
1560 * create a new name.
1561 */
1562 brw_bo_flink(last_mt->bo, &old_name);
1563 }
1564
1565 if (old_name == buffer->name)
1566 return;
1567
1568 if (unlikely(INTEL_DEBUG & DEBUG_DRI)) {
1569 fprintf(stderr,
1570 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
1571 buffer->name, buffer->attachment,
1572 buffer->cpp, buffer->pitch);
1573 }
1574
1575 bo = brw_bo_gem_create_from_name(brw->bufmgr, buffer_name,
1576 buffer->name);
1577 if (!bo) {
1578 fprintf(stderr,
1579 "Failed to open BO for returned DRI2 buffer "
1580 "(%dx%d, %s, named %d).\n"
1581 "This is likely a bug in the X Server that will lead to a "
1582 "crash soon.\n",
1583 drawable->w, drawable->h, buffer_name, buffer->name);
1584 return;
1585 }
1586
1587 struct intel_mipmap_tree *mt =
1588 intel_miptree_create_for_bo(brw,
1589 bo,
1590 intel_rb_format(rb),
1591 0,
1592 drawable->w,
1593 drawable->h,
1594 1,
1595 buffer->pitch,
1596 MIPTREE_CREATE_DEFAULT);
1597 if (!mt) {
1598 brw_bo_unreference(bo);
1599 return;
1600 }
1601
1602 /* We got this BO from X11. We cana't assume that we have coherent texture
1603 * access because X may suddenly decide to use it for scan-out which would
1604 * destroy coherency.
1605 */
1606 bo->cache_coherent = false;
1607
1608 if (!intel_update_winsys_renderbuffer_miptree(brw, rb, mt,
1609 drawable->w, drawable->h,
1610 buffer->pitch)) {
1611 brw_bo_unreference(bo);
1612 intel_miptree_release(&mt);
1613 return;
1614 }
1615
1616 if (_mesa_is_front_buffer_drawing(fb) &&
1617 (buffer->attachment == __DRI_BUFFER_FRONT_LEFT ||
1618 buffer->attachment == __DRI_BUFFER_FAKE_FRONT_LEFT) &&
1619 rb->Base.Base.NumSamples > 1) {
1620 intel_renderbuffer_upsample(brw, rb);
1621 }
1622
1623 assert(rb->mt);
1624
1625 brw_bo_unreference(bo);
1626 }
1627
1628 /**
1629 * \brief Query DRI image loader to obtain a DRIdrawable's buffers.
1630 *
1631 * To determine which DRI buffers to request, examine the renderbuffers
1632 * attached to the drawable's framebuffer. Then request the buffers from
1633 * the image loader
1634 *
1635 * This is called from intel_update_renderbuffers().
1636 *
1637 * \param drawable Drawable whose buffers are queried.
1638 * \param buffers [out] List of buffers returned by DRI2 query.
1639 * \param buffer_count [out] Number of buffers returned.
1640 *
1641 * \see intel_update_renderbuffers()
1642 */
1643
1644 static void
1645 intel_update_image_buffer(struct brw_context *intel,
1646 __DRIdrawable *drawable,
1647 struct intel_renderbuffer *rb,
1648 __DRIimage *buffer,
1649 enum __DRIimageBufferMask buffer_type)
1650 {
1651 struct gl_framebuffer *fb = drawable->driverPrivate;
1652
1653 if (!rb || !buffer->bo)
1654 return;
1655
1656 unsigned num_samples = rb->Base.Base.NumSamples;
1657
1658 /* Check and see if we're already bound to the right
1659 * buffer object
1660 */
1661 struct intel_mipmap_tree *last_mt;
1662 if (num_samples == 0)
1663 last_mt = rb->mt;
1664 else
1665 last_mt = rb->singlesample_mt;
1666
1667 if (last_mt && last_mt->bo == buffer->bo)
1668 return;
1669
1670 struct intel_mipmap_tree *mt =
1671 intel_miptree_create_for_dri_image(intel, buffer, GL_TEXTURE_2D,
1672 intel_rb_format(rb), true);
1673 if (!mt)
1674 return;
1675
1676 if (!intel_update_winsys_renderbuffer_miptree(intel, rb, mt,
1677 buffer->width, buffer->height,
1678 buffer->pitch)) {
1679 intel_miptree_release(&mt);
1680 return;
1681 }
1682
1683 if (_mesa_is_front_buffer_drawing(fb) &&
1684 buffer_type == __DRI_IMAGE_BUFFER_FRONT &&
1685 rb->Base.Base.NumSamples > 1) {
1686 intel_renderbuffer_upsample(intel, rb);
1687 }
1688 }
1689
1690 static void
1691 intel_update_image_buffers(struct brw_context *brw, __DRIdrawable *drawable)
1692 {
1693 struct gl_framebuffer *fb = drawable->driverPrivate;
1694 __DRIscreen *dri_screen = brw->screen->driScrnPriv;
1695 struct intel_renderbuffer *front_rb;
1696 struct intel_renderbuffer *back_rb;
1697 struct __DRIimageList images;
1698 mesa_format format;
1699 uint32_t buffer_mask = 0;
1700 int ret;
1701
1702 front_rb = intel_get_renderbuffer(fb, BUFFER_FRONT_LEFT);
1703 back_rb = intel_get_renderbuffer(fb, BUFFER_BACK_LEFT);
1704
1705 if (back_rb)
1706 format = intel_rb_format(back_rb);
1707 else if (front_rb)
1708 format = intel_rb_format(front_rb);
1709 else
1710 return;
1711
1712 if (front_rb && (_mesa_is_front_buffer_drawing(fb) ||
1713 _mesa_is_front_buffer_reading(fb) || !back_rb)) {
1714 buffer_mask |= __DRI_IMAGE_BUFFER_FRONT;
1715 }
1716
1717 if (back_rb)
1718 buffer_mask |= __DRI_IMAGE_BUFFER_BACK;
1719
1720 ret = dri_screen->image.loader->getBuffers(drawable,
1721 driGLFormatToImageFormat(format),
1722 &drawable->dri2.stamp,
1723 drawable->loaderPrivate,
1724 buffer_mask,
1725 &images);
1726 if (!ret)
1727 return;
1728
1729 if (images.image_mask & __DRI_IMAGE_BUFFER_FRONT) {
1730 drawable->w = images.front->width;
1731 drawable->h = images.front->height;
1732 intel_update_image_buffer(brw,
1733 drawable,
1734 front_rb,
1735 images.front,
1736 __DRI_IMAGE_BUFFER_FRONT);
1737 }
1738
1739 if (images.image_mask & __DRI_IMAGE_BUFFER_BACK) {
1740 drawable->w = images.back->width;
1741 drawable->h = images.back->height;
1742 intel_update_image_buffer(brw,
1743 drawable,
1744 back_rb,
1745 images.back,
1746 __DRI_IMAGE_BUFFER_BACK);
1747 }
1748 }