draw: corrections to allow for different cliptest cases
[mesa.git] / src / mesa / drivers / dri / intel / intel_buffer_objects.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "main/imports.h"
30 #include "main/mtypes.h"
31 #include "main/macros.h"
32 #include "main/bufferobj.h"
33
34 #include "intel_blit.h"
35 #include "intel_buffer_objects.h"
36 #include "intel_batchbuffer.h"
37 #include "intel_context.h"
38 #include "intel_fbo.h"
39 #include "intel_mipmap_tree.h"
40 #include "intel_regions.h"
41
42 static GLboolean
43 intel_bufferobj_unmap(GLcontext * ctx,
44 GLenum target, struct gl_buffer_object *obj);
45
46 /** Allocates a new drm_intel_bo to store the data for the buffer object. */
47 static void
48 intel_bufferobj_alloc_buffer(struct intel_context *intel,
49 struct intel_buffer_object *intel_obj)
50 {
51 intel_obj->buffer = drm_intel_bo_alloc(intel->bufmgr, "bufferobj",
52 intel_obj->Base.Size, 64);
53 }
54
55 /**
56 * There is some duplication between mesa's bufferobjects and our
57 * bufmgr buffers. Both have an integer handle and a hashtable to
58 * lookup an opaque structure. It would be nice if the handles and
59 * internal structure where somehow shared.
60 */
61 static struct gl_buffer_object *
62 intel_bufferobj_alloc(GLcontext * ctx, GLuint name, GLenum target)
63 {
64 struct intel_buffer_object *obj = CALLOC_STRUCT(intel_buffer_object);
65
66 _mesa_initialize_buffer_object(&obj->Base, name, target);
67
68 obj->buffer = NULL;
69
70 return &obj->Base;
71 }
72
73 /* Break the COW tie to the region. The region gets to keep the data.
74 */
75 void
76 intel_bufferobj_release_region(struct intel_context *intel,
77 struct intel_buffer_object *intel_obj)
78 {
79 assert(intel_obj->region->buffer == intel_obj->buffer);
80 intel_obj->region->pbo = NULL;
81 intel_obj->region = NULL;
82
83 drm_intel_bo_unreference(intel_obj->buffer);
84 intel_obj->buffer = NULL;
85 }
86
87 /* Break the COW tie to the region. Both the pbo and the region end
88 * up with a copy of the data.
89 */
90 void
91 intel_bufferobj_cow(struct intel_context *intel,
92 struct intel_buffer_object *intel_obj)
93 {
94 assert(intel_obj->region);
95 intel_region_cow(intel, intel_obj->region);
96 }
97
98
99 /**
100 * Deallocate/free a vertex/pixel buffer object.
101 * Called via glDeleteBuffersARB().
102 */
103 static void
104 intel_bufferobj_free(GLcontext * ctx, struct gl_buffer_object *obj)
105 {
106 struct intel_context *intel = intel_context(ctx);
107 struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
108
109 assert(intel_obj);
110
111 /* Buffer objects are automatically unmapped when deleting according
112 * to the spec, but Mesa doesn't do UnmapBuffer for us at context destroy
113 * (though it does if you call glDeleteBuffers)
114 */
115 if (obj->Pointer)
116 intel_bufferobj_unmap(ctx, 0, obj);
117
118 free(intel_obj->sys_buffer);
119 if (intel_obj->region) {
120 intel_bufferobj_release_region(intel, intel_obj);
121 }
122 else if (intel_obj->buffer) {
123 drm_intel_bo_unreference(intel_obj->buffer);
124 }
125
126 free(intel_obj);
127 }
128
129
130
131 /**
132 * Allocate space for and store data in a buffer object. Any data that was
133 * previously stored in the buffer object is lost. If data is NULL,
134 * memory will be allocated, but no copy will occur.
135 * Called via ctx->Driver.BufferData().
136 * \return GL_TRUE for success, GL_FALSE if out of memory
137 */
138 static GLboolean
139 intel_bufferobj_data(GLcontext * ctx,
140 GLenum target,
141 GLsizeiptrARB size,
142 const GLvoid * data,
143 GLenum usage, struct gl_buffer_object *obj)
144 {
145 struct intel_context *intel = intel_context(ctx);
146 struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
147
148 intel_obj->Base.Size = size;
149 intel_obj->Base.Usage = usage;
150
151 assert(!obj->Pointer); /* Mesa should have unmapped it */
152
153 if (intel_obj->region)
154 intel_bufferobj_release_region(intel, intel_obj);
155
156 if (intel_obj->buffer != NULL) {
157 drm_intel_bo_unreference(intel_obj->buffer);
158 intel_obj->buffer = NULL;
159 }
160 free(intel_obj->sys_buffer);
161 intel_obj->sys_buffer = NULL;
162
163 if (size != 0) {
164 #ifdef I915
165 /* On pre-965, stick VBOs in system memory, as we're always doing swtnl
166 * with their contents anyway.
167 */
168 if (target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER) {
169 intel_obj->sys_buffer = malloc(size);
170 if (intel_obj->sys_buffer != NULL) {
171 if (data != NULL)
172 memcpy(intel_obj->sys_buffer, data, size);
173 return GL_TRUE;
174 }
175 }
176 #endif
177 intel_bufferobj_alloc_buffer(intel, intel_obj);
178 if (!intel_obj->buffer)
179 return GL_FALSE;
180
181 if (data != NULL)
182 drm_intel_bo_subdata(intel_obj->buffer, 0, size, data);
183 }
184
185 return GL_TRUE;
186 }
187
188
189 /**
190 * Replace data in a subrange of buffer object. If the data range
191 * specified by size + offset extends beyond the end of the buffer or
192 * if data is NULL, no copy is performed.
193 * Called via glBufferSubDataARB().
194 */
195 static void
196 intel_bufferobj_subdata(GLcontext * ctx,
197 GLenum target,
198 GLintptrARB offset,
199 GLsizeiptrARB size,
200 const GLvoid * data, struct gl_buffer_object *obj)
201 {
202 struct intel_context *intel = intel_context(ctx);
203 struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
204
205 if (size == 0)
206 return;
207
208 assert(intel_obj);
209
210 if (intel_obj->region)
211 intel_bufferobj_cow(intel, intel_obj);
212
213 if (intel_obj->sys_buffer)
214 memcpy((char *)intel_obj->sys_buffer + offset, data, size);
215 else {
216 /* Flush any existing batchbuffer that might reference this data. */
217 if (drm_intel_bo_busy(intel_obj->buffer) ||
218 drm_intel_bo_references(intel->batch->buf, intel_obj->buffer)) {
219 drm_intel_bo *temp_bo;
220
221 temp_bo = drm_intel_bo_alloc(intel->bufmgr, "subdata temp", size, 64);
222
223 drm_intel_bo_subdata(temp_bo, 0, size, data);
224
225 intel_emit_linear_blit(intel,
226 intel_obj->buffer, offset,
227 temp_bo, 0,
228 size);
229
230 drm_intel_bo_unreference(temp_bo);
231 } else {
232 drm_intel_bo_subdata(intel_obj->buffer, offset, size, data);
233 }
234 }
235 }
236
237
238 /**
239 * Called via glGetBufferSubDataARB().
240 */
241 static void
242 intel_bufferobj_get_subdata(GLcontext * ctx,
243 GLenum target,
244 GLintptrARB offset,
245 GLsizeiptrARB size,
246 GLvoid * data, struct gl_buffer_object *obj)
247 {
248 struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
249
250 assert(intel_obj);
251 if (intel_obj->sys_buffer)
252 memcpy(data, (char *)intel_obj->sys_buffer + offset, size);
253 else
254 drm_intel_bo_get_subdata(intel_obj->buffer, offset, size, data);
255 }
256
257
258
259 /**
260 * Called via glMapBufferARB().
261 */
262 static void *
263 intel_bufferobj_map(GLcontext * ctx,
264 GLenum target,
265 GLenum access, struct gl_buffer_object *obj)
266 {
267 struct intel_context *intel = intel_context(ctx);
268 struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
269 GLboolean read_only = (access == GL_READ_ONLY_ARB);
270 GLboolean write_only = (access == GL_WRITE_ONLY_ARB);
271
272 assert(intel_obj);
273
274 if (intel_obj->sys_buffer) {
275 obj->Pointer = intel_obj->sys_buffer;
276 obj->Length = obj->Size;
277 obj->Offset = 0;
278 return obj->Pointer;
279 }
280
281 /* Flush any existing batchbuffer that might reference this data. */
282 if (drm_intel_bo_references(intel->batch->buf, intel_obj->buffer))
283 intel_flush(ctx);
284
285 if (intel_obj->region)
286 intel_bufferobj_cow(intel, intel_obj);
287
288 if (intel_obj->buffer == NULL) {
289 obj->Pointer = NULL;
290 return NULL;
291 }
292
293 if (write_only) {
294 drm_intel_gem_bo_map_gtt(intel_obj->buffer);
295 intel_obj->mapped_gtt = GL_TRUE;
296 } else {
297 drm_intel_bo_map(intel_obj->buffer, !read_only);
298 intel_obj->mapped_gtt = GL_FALSE;
299 }
300
301 obj->Pointer = intel_obj->buffer->virtual;
302 obj->Length = obj->Size;
303 obj->Offset = 0;
304
305 return obj->Pointer;
306 }
307
308 /**
309 * Called via glMapBufferRange().
310 *
311 * The goal of this extension is to allow apps to accumulate their rendering
312 * at the same time as they accumulate their buffer object. Without it,
313 * you'd end up blocking on execution of rendering every time you mapped
314 * the buffer to put new data in.
315 *
316 * We support it in 3 ways: If unsynchronized, then don't bother
317 * flushing the batchbuffer before mapping the buffer, which can save blocking
318 * in many cases. If we would still block, and they allow the whole buffer
319 * to be invalidated, then just allocate a new buffer to replace the old one.
320 * If not, and we'd block, and they allow the subrange of the buffer to be
321 * invalidated, then we can make a new little BO, let them write into that,
322 * and blit it into the real BO at unmap time.
323 */
324 static void *
325 intel_bufferobj_map_range(GLcontext * ctx,
326 GLenum target, GLintptr offset, GLsizeiptr length,
327 GLbitfield access, struct gl_buffer_object *obj)
328 {
329 struct intel_context *intel = intel_context(ctx);
330 struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
331
332 assert(intel_obj);
333
334 /* _mesa_MapBufferRange (GL entrypoint) sets these, but the vbo module also
335 * internally uses our functions directly.
336 */
337 obj->Offset = offset;
338 obj->Length = length;
339 obj->AccessFlags = access;
340
341 if (intel_obj->sys_buffer) {
342 obj->Pointer = intel_obj->sys_buffer + offset;
343 return obj->Pointer;
344 }
345
346 if (intel_obj->region)
347 intel_bufferobj_cow(intel, intel_obj);
348
349 /* If the mapping is synchronized with other GL operations, flush
350 * the batchbuffer so that GEM knows about the buffer access for later
351 * syncing.
352 */
353 if (!(access & GL_MAP_UNSYNCHRONIZED_BIT) &&
354 drm_intel_bo_references(intel->batch->buf, intel_obj->buffer))
355 intel_flush(ctx);
356
357 if (intel_obj->buffer == NULL) {
358 obj->Pointer = NULL;
359 return NULL;
360 }
361
362 /* If the user doesn't care about existing buffer contents and mapping
363 * would cause us to block, then throw out the old buffer.
364 */
365 if (!(access & GL_MAP_UNSYNCHRONIZED_BIT) &&
366 (access & GL_MAP_INVALIDATE_BUFFER_BIT) &&
367 drm_intel_bo_busy(intel_obj->buffer)) {
368 drm_intel_bo_unreference(intel_obj->buffer);
369 intel_obj->buffer = drm_intel_bo_alloc(intel->bufmgr, "bufferobj",
370 intel_obj->Base.Size, 64);
371 }
372
373 /* If the user is mapping a range of an active buffer object but
374 * doesn't require the current contents of that range, make a new
375 * BO, and we'll copy what they put in there out at unmap or
376 * FlushRange time.
377 */
378 if ((access & GL_MAP_INVALIDATE_RANGE_BIT) &&
379 drm_intel_bo_busy(intel_obj->buffer)) {
380 if (access & GL_MAP_FLUSH_EXPLICIT_BIT) {
381 intel_obj->range_map_buffer = malloc(length);
382 obj->Pointer = intel_obj->range_map_buffer;
383 } else {
384 intel_obj->range_map_bo = drm_intel_bo_alloc(intel->bufmgr,
385 "range map",
386 length, 64);
387 if (!(access & GL_MAP_READ_BIT)) {
388 drm_intel_gem_bo_map_gtt(intel_obj->range_map_bo);
389 intel_obj->mapped_gtt = GL_TRUE;
390 } else {
391 drm_intel_bo_map(intel_obj->range_map_bo,
392 (access & GL_MAP_WRITE_BIT) != 0);
393 intel_obj->mapped_gtt = GL_FALSE;
394 }
395 obj->Pointer = intel_obj->range_map_bo->virtual;
396 }
397 return obj->Pointer;
398 }
399
400 if (!(access & GL_MAP_READ_BIT)) {
401 drm_intel_gem_bo_map_gtt(intel_obj->buffer);
402 intel_obj->mapped_gtt = GL_TRUE;
403 } else {
404 drm_intel_bo_map(intel_obj->buffer, (access & GL_MAP_WRITE_BIT) != 0);
405 intel_obj->mapped_gtt = GL_FALSE;
406 }
407
408 obj->Pointer = intel_obj->buffer->virtual + offset;
409 return obj->Pointer;
410 }
411
412 /* Ideally we'd use a BO to avoid taking up cache space for the temporary
413 * data, but FlushMappedBufferRange may be followed by further writes to
414 * the pointer, so we would have to re-map after emitting our blit, which
415 * would defeat the point.
416 */
417 static void
418 intel_bufferobj_flush_mapped_range(GLcontext *ctx, GLenum target,
419 GLintptr offset, GLsizeiptr length,
420 struct gl_buffer_object *obj)
421 {
422 struct intel_context *intel = intel_context(ctx);
423 struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
424 drm_intel_bo *temp_bo;
425
426 /* Unless we're in the range map using a temporary system buffer,
427 * there's no work to do.
428 */
429 if (intel_obj->range_map_buffer == NULL)
430 return;
431
432 if (length == 0)
433 return;
434
435 temp_bo = drm_intel_bo_alloc(intel->bufmgr, "range map flush", length, 64);
436
437 drm_intel_bo_subdata(temp_bo, 0, length, intel_obj->range_map_buffer);
438
439 intel_emit_linear_blit(intel,
440 intel_obj->buffer, obj->Offset + offset,
441 temp_bo, 0,
442 length);
443
444 drm_intel_bo_unreference(temp_bo);
445 }
446
447
448 /**
449 * Called via glUnmapBuffer().
450 */
451 static GLboolean
452 intel_bufferobj_unmap(GLcontext * ctx,
453 GLenum target, struct gl_buffer_object *obj)
454 {
455 struct intel_context *intel = intel_context(ctx);
456 struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
457
458 assert(intel_obj);
459 assert(obj->Pointer);
460 if (intel_obj->sys_buffer != NULL) {
461 /* always keep the mapping around. */
462 } else if (intel_obj->range_map_buffer != NULL) {
463 /* Since we've emitted some blits to buffers that will (likely) be used
464 * in rendering operations in other cache domains in this batch, emit a
465 * flush. Once again, we wish for a domain tracker in libdrm to cover
466 * usage inside of a batchbuffer.
467 */
468 intel_batchbuffer_emit_mi_flush(intel->batch);
469 free(intel_obj->range_map_buffer);
470 intel_obj->range_map_buffer = NULL;
471 } else if (intel_obj->range_map_bo != NULL) {
472 if (intel_obj->mapped_gtt) {
473 drm_intel_gem_bo_unmap_gtt(intel_obj->range_map_bo);
474 } else {
475 drm_intel_bo_unmap(intel_obj->range_map_bo);
476 }
477
478 intel_emit_linear_blit(intel,
479 intel_obj->buffer, obj->Offset,
480 intel_obj->range_map_bo, 0,
481 obj->Length);
482
483 /* Since we've emitted some blits to buffers that will (likely) be used
484 * in rendering operations in other cache domains in this batch, emit a
485 * flush. Once again, we wish for a domain tracker in libdrm to cover
486 * usage inside of a batchbuffer.
487 */
488 intel_batchbuffer_emit_mi_flush(intel->batch);
489
490 drm_intel_bo_unreference(intel_obj->range_map_bo);
491 intel_obj->range_map_bo = NULL;
492 } else if (intel_obj->buffer != NULL) {
493 if (intel_obj->mapped_gtt) {
494 drm_intel_gem_bo_unmap_gtt(intel_obj->buffer);
495 } else {
496 drm_intel_bo_unmap(intel_obj->buffer);
497 }
498 }
499 obj->Pointer = NULL;
500 obj->Offset = 0;
501 obj->Length = 0;
502
503 return GL_TRUE;
504 }
505
506 drm_intel_bo *
507 intel_bufferobj_buffer(struct intel_context *intel,
508 struct intel_buffer_object *intel_obj, GLuint flag)
509 {
510 if (intel_obj->region) {
511 if (flag == INTEL_WRITE_PART)
512 intel_bufferobj_cow(intel, intel_obj);
513 else if (flag == INTEL_WRITE_FULL) {
514 intel_bufferobj_release_region(intel, intel_obj);
515 intel_bufferobj_alloc_buffer(intel, intel_obj);
516 }
517 }
518
519 if (intel_obj->buffer == NULL) {
520 void *sys_buffer = intel_obj->sys_buffer;
521
522 /* only one of buffer and sys_buffer could be non-NULL */
523 intel_bufferobj_alloc_buffer(intel, intel_obj);
524 intel_obj->sys_buffer = NULL;
525
526 intel_bufferobj_subdata(&intel->ctx,
527 GL_ARRAY_BUFFER_ARB,
528 0,
529 intel_obj->Base.Size,
530 sys_buffer,
531 &intel_obj->Base);
532 free(sys_buffer);
533 intel_obj->sys_buffer = NULL;
534 }
535
536 return intel_obj->buffer;
537 }
538
539 static void
540 intel_bufferobj_copy_subdata(GLcontext *ctx,
541 struct gl_buffer_object *src,
542 struct gl_buffer_object *dst,
543 GLintptr read_offset, GLintptr write_offset,
544 GLsizeiptr size)
545 {
546 struct intel_context *intel = intel_context(ctx);
547 struct intel_buffer_object *intel_src = intel_buffer_object(src);
548 struct intel_buffer_object *intel_dst = intel_buffer_object(dst);
549 drm_intel_bo *src_bo, *dst_bo;
550
551 if (size == 0)
552 return;
553
554 /* If we're in system memory, just map and memcpy. */
555 if (intel_src->sys_buffer || intel_dst->sys_buffer) {
556 /* The same buffer may be used, but note that regions copied may
557 * not overlap.
558 */
559 if (src == dst) {
560 char *ptr = intel_bufferobj_map(ctx, GL_COPY_WRITE_BUFFER,
561 GL_READ_WRITE, dst);
562 memcpy(ptr + write_offset, ptr + read_offset, size);
563 intel_bufferobj_unmap(ctx, GL_COPY_WRITE_BUFFER, dst);
564 } else {
565 const char *src_ptr;
566 char *dst_ptr;
567
568 src_ptr = intel_bufferobj_map(ctx, GL_COPY_READ_BUFFER,
569 GL_READ_ONLY, src);
570 dst_ptr = intel_bufferobj_map(ctx, GL_COPY_WRITE_BUFFER,
571 GL_WRITE_ONLY, dst);
572
573 memcpy(dst_ptr + write_offset, src_ptr + read_offset, size);
574
575 intel_bufferobj_unmap(ctx, GL_COPY_READ_BUFFER, src);
576 intel_bufferobj_unmap(ctx, GL_COPY_WRITE_BUFFER, dst);
577 }
578 }
579
580 /* Otherwise, we have real BOs, so blit them. */
581
582 dst_bo = intel_bufferobj_buffer(intel, intel_dst, INTEL_WRITE_PART);
583 src_bo = intel_bufferobj_buffer(intel, intel_src, INTEL_READ);
584
585 intel_emit_linear_blit(intel,
586 dst_bo, write_offset,
587 src_bo, read_offset, size);
588
589 /* Since we've emitted some blits to buffers that will (likely) be used
590 * in rendering operations in other cache domains in this batch, emit a
591 * flush. Once again, we wish for a domain tracker in libdrm to cover
592 * usage inside of a batchbuffer.
593 */
594 intel_batchbuffer_emit_mi_flush(intel->batch);
595 }
596
597 #if FEATURE_APPLE_object_purgeable
598 static GLenum
599 intel_buffer_purgeable(GLcontext * ctx,
600 drm_intel_bo *buffer,
601 GLenum option)
602 {
603 int retained = 0;
604
605 if (buffer != NULL)
606 retained = drm_intel_bo_madvise (buffer, I915_MADV_DONTNEED);
607
608 return retained ? GL_VOLATILE_APPLE : GL_RELEASED_APPLE;
609 }
610
611 static GLenum
612 intel_buffer_object_purgeable(GLcontext * ctx,
613 struct gl_buffer_object *obj,
614 GLenum option)
615 {
616 struct intel_buffer_object *intel;
617
618 intel = intel_buffer_object (obj);
619 if (intel->buffer != NULL)
620 return intel_buffer_purgeable (ctx, intel->buffer, option);
621
622 if (option == GL_RELEASED_APPLE) {
623 if (intel->sys_buffer != NULL) {
624 free(intel->sys_buffer);
625 intel->sys_buffer = NULL;
626 }
627
628 return GL_RELEASED_APPLE;
629 } else {
630 /* XXX Create the buffer and madvise(MADV_DONTNEED)? */
631 return intel_buffer_purgeable (ctx,
632 intel_bufferobj_buffer(intel_context(ctx),
633 intel, INTEL_READ),
634 option);
635 }
636 }
637
638 static GLenum
639 intel_texture_object_purgeable(GLcontext * ctx,
640 struct gl_texture_object *obj,
641 GLenum option)
642 {
643 struct intel_texture_object *intel;
644
645 intel = intel_texture_object(obj);
646 if (intel->mt == NULL || intel->mt->region == NULL)
647 return GL_RELEASED_APPLE;
648
649 return intel_buffer_purgeable (ctx, intel->mt->region->buffer, option);
650 }
651
652 static GLenum
653 intel_render_object_purgeable(GLcontext * ctx,
654 struct gl_renderbuffer *obj,
655 GLenum option)
656 {
657 struct intel_renderbuffer *intel;
658
659 intel = intel_renderbuffer(obj);
660 if (intel->region == NULL)
661 return GL_RELEASED_APPLE;
662
663 return intel_buffer_purgeable (ctx, intel->region->buffer, option);
664 }
665
666 static GLenum
667 intel_buffer_unpurgeable(GLcontext * ctx,
668 drm_intel_bo *buffer,
669 GLenum option)
670 {
671 int retained;
672
673 retained = 0;
674 if (buffer != NULL)
675 retained = drm_intel_bo_madvise (buffer, I915_MADV_WILLNEED);
676
677 return retained ? GL_RETAINED_APPLE : GL_UNDEFINED_APPLE;
678 }
679
680 static GLenum
681 intel_buffer_object_unpurgeable(GLcontext * ctx,
682 struct gl_buffer_object *obj,
683 GLenum option)
684 {
685 return intel_buffer_unpurgeable (ctx, intel_buffer_object (obj)->buffer, option);
686 }
687
688 static GLenum
689 intel_texture_object_unpurgeable(GLcontext * ctx,
690 struct gl_texture_object *obj,
691 GLenum option)
692 {
693 struct intel_texture_object *intel;
694
695 intel = intel_texture_object(obj);
696 if (intel->mt == NULL || intel->mt->region == NULL)
697 return GL_UNDEFINED_APPLE;
698
699 return intel_buffer_unpurgeable (ctx, intel->mt->region->buffer, option);
700 }
701
702 static GLenum
703 intel_render_object_unpurgeable(GLcontext * ctx,
704 struct gl_renderbuffer *obj,
705 GLenum option)
706 {
707 struct intel_renderbuffer *intel;
708
709 intel = intel_renderbuffer(obj);
710 if (intel->region == NULL)
711 return GL_UNDEFINED_APPLE;
712
713 return intel_buffer_unpurgeable (ctx, intel->region->buffer, option);
714 }
715 #endif
716
717 void
718 intelInitBufferObjectFuncs(struct dd_function_table *functions)
719 {
720 functions->NewBufferObject = intel_bufferobj_alloc;
721 functions->DeleteBuffer = intel_bufferobj_free;
722 functions->BufferData = intel_bufferobj_data;
723 functions->BufferSubData = intel_bufferobj_subdata;
724 functions->GetBufferSubData = intel_bufferobj_get_subdata;
725 functions->MapBuffer = intel_bufferobj_map;
726 functions->MapBufferRange = intel_bufferobj_map_range;
727 functions->FlushMappedBufferRange = intel_bufferobj_flush_mapped_range;
728 functions->UnmapBuffer = intel_bufferobj_unmap;
729 functions->CopyBufferSubData = intel_bufferobj_copy_subdata;
730
731 #if FEATURE_APPLE_object_purgeable
732 functions->BufferObjectPurgeable = intel_buffer_object_purgeable;
733 functions->TextureObjectPurgeable = intel_texture_object_purgeable;
734 functions->RenderObjectPurgeable = intel_render_object_purgeable;
735
736 functions->BufferObjectUnpurgeable = intel_buffer_object_unpurgeable;
737 functions->TextureObjectUnpurgeable = intel_texture_object_unpurgeable;
738 functions->RenderObjectUnpurgeable = intel_render_object_unpurgeable;
739 #endif
740 }