1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 #include "main/imports.h"
30 #include "main/mfeatures.h"
31 #include "main/mtypes.h"
32 #include "main/macros.h"
33 #include "main/bufferobj.h"
35 #include "intel_blit.h"
36 #include "intel_buffer_objects.h"
37 #include "intel_batchbuffer.h"
38 #include "intel_context.h"
39 #include "intel_fbo.h"
40 #include "intel_mipmap_tree.h"
41 #include "intel_regions.h"
44 intel_bufferobj_unmap(struct gl_context
* ctx
, struct gl_buffer_object
*obj
);
46 /** Allocates a new drm_intel_bo to store the data for the buffer object. */
48 intel_bufferobj_alloc_buffer(struct intel_context
*intel
,
49 struct intel_buffer_object
*intel_obj
)
51 intel_obj
->buffer
= drm_intel_bo_alloc(intel
->bufmgr
, "bufferobj",
52 intel_obj
->Base
.Size
, 64);
56 release_buffer(struct intel_buffer_object
*intel_obj
)
58 drm_intel_bo_unreference(intel_obj
->buffer
);
59 intel_obj
->buffer
= NULL
;
60 intel_obj
->offset
= 0;
61 intel_obj
->source
= 0;
65 * There is some duplication between mesa's bufferobjects and our
66 * bufmgr buffers. Both have an integer handle and a hashtable to
67 * lookup an opaque structure. It would be nice if the handles and
68 * internal structure where somehow shared.
70 static struct gl_buffer_object
*
71 intel_bufferobj_alloc(struct gl_context
* ctx
, GLuint name
, GLenum target
)
73 struct intel_buffer_object
*obj
= CALLOC_STRUCT(intel_buffer_object
);
75 _mesa_initialize_buffer_object(ctx
, &obj
->Base
, name
, target
);
83 * Deallocate/free a vertex/pixel buffer object.
84 * Called via glDeleteBuffersARB().
87 intel_bufferobj_free(struct gl_context
* ctx
, struct gl_buffer_object
*obj
)
89 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
93 /* Buffer objects are automatically unmapped when deleting according
94 * to the spec, but Mesa doesn't do UnmapBuffer for us at context destroy
95 * (though it does if you call glDeleteBuffers)
98 intel_bufferobj_unmap(ctx
, obj
);
100 free(intel_obj
->sys_buffer
);
102 drm_intel_bo_unreference(intel_obj
->buffer
);
109 * Allocate space for and store data in a buffer object. Any data that was
110 * previously stored in the buffer object is lost. If data is NULL,
111 * memory will be allocated, but no copy will occur.
112 * Called via ctx->Driver.BufferData().
113 * \return true for success, false if out of memory
116 intel_bufferobj_data(struct gl_context
* ctx
,
120 GLenum usage
, struct gl_buffer_object
*obj
)
122 struct intel_context
*intel
= intel_context(ctx
);
123 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
125 /* Part of the ABI, but this function doesn't use it.
131 intel_obj
->Base
.Size
= size
;
132 intel_obj
->Base
.Usage
= usage
;
134 assert(!obj
->Pointer
); /* Mesa should have unmapped it */
136 if (intel_obj
->buffer
!= NULL
)
137 release_buffer(intel_obj
);
139 free(intel_obj
->sys_buffer
);
140 intel_obj
->sys_buffer
= NULL
;
143 if (usage
== GL_DYNAMIC_DRAW
145 /* On pre-965, stick VBOs in system memory, as we're always doing
146 * swtnl with their contents anyway.
148 || target
== GL_ARRAY_BUFFER
|| target
== GL_ELEMENT_ARRAY_BUFFER
152 intel_obj
->sys_buffer
= malloc(size
);
153 if (intel_obj
->sys_buffer
!= NULL
) {
155 memcpy(intel_obj
->sys_buffer
, data
, size
);
159 intel_bufferobj_alloc_buffer(intel
, intel_obj
);
160 if (!intel_obj
->buffer
)
164 drm_intel_bo_subdata(intel_obj
->buffer
, 0, size
, data
);
172 * Replace data in a subrange of buffer object. If the data range
173 * specified by size + offset extends beyond the end of the buffer or
174 * if data is NULL, no copy is performed.
175 * Called via glBufferSubDataARB().
178 intel_bufferobj_subdata(struct gl_context
* ctx
,
181 const GLvoid
* data
, struct gl_buffer_object
*obj
)
183 struct intel_context
*intel
= intel_context(ctx
);
184 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
192 /* If we have a single copy in system memory, update that */
193 if (intel_obj
->sys_buffer
) {
194 if (intel_obj
->source
)
195 release_buffer(intel_obj
);
197 if (intel_obj
->buffer
== NULL
) {
198 memcpy((char *)intel_obj
->sys_buffer
+ offset
, data
, size
);
202 free(intel_obj
->sys_buffer
);
203 intel_obj
->sys_buffer
= NULL
;
206 /* Otherwise we need to update the copy in video memory. */
208 drm_intel_bo_busy(intel_obj
->buffer
) ||
209 drm_intel_bo_references(intel
->batch
.bo
, intel_obj
->buffer
);
211 /* replace the current busy bo with fresh data */
212 if (busy
&& size
== intel_obj
->Base
.Size
) {
213 drm_intel_bo_unreference(intel_obj
->buffer
);
214 intel_bufferobj_alloc_buffer(intel
, intel_obj
);
215 drm_intel_bo_subdata(intel_obj
->buffer
, 0, size
, data
);
216 } else if (intel
->gen
< 6) {
218 drm_intel_bo
*temp_bo
;
220 temp_bo
= drm_intel_bo_alloc(intel
->bufmgr
, "subdata temp", size
, 64);
222 drm_intel_bo_subdata(temp_bo
, 0, size
, data
);
224 intel_emit_linear_blit(intel
,
225 intel_obj
->buffer
, offset
,
229 drm_intel_bo_unreference(temp_bo
);
231 drm_intel_bo_subdata(intel_obj
->buffer
, offset
, size
, data
);
234 /* Can't use the blit to modify the buffer in the middle of batch. */
235 if (drm_intel_bo_references(intel
->batch
.bo
, intel_obj
->buffer
)) {
236 intel_batchbuffer_flush(intel
);
238 drm_intel_bo_subdata(intel_obj
->buffer
, offset
, size
, data
);
244 * Called via glGetBufferSubDataARB().
247 intel_bufferobj_get_subdata(struct gl_context
* ctx
,
250 GLvoid
* data
, struct gl_buffer_object
*obj
)
252 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
253 struct intel_context
*intel
= intel_context(ctx
);
256 if (intel_obj
->sys_buffer
)
257 memcpy(data
, (char *)intel_obj
->sys_buffer
+ offset
, size
);
259 if (drm_intel_bo_references(intel
->batch
.bo
, intel_obj
->buffer
)) {
260 intel_batchbuffer_flush(intel
);
262 drm_intel_bo_get_subdata(intel_obj
->buffer
, offset
, size
, data
);
269 * Called via glMapBufferRange and glMapBuffer
271 * The goal of this extension is to allow apps to accumulate their rendering
272 * at the same time as they accumulate their buffer object. Without it,
273 * you'd end up blocking on execution of rendering every time you mapped
274 * the buffer to put new data in.
276 * We support it in 3 ways: If unsynchronized, then don't bother
277 * flushing the batchbuffer before mapping the buffer, which can save blocking
278 * in many cases. If we would still block, and they allow the whole buffer
279 * to be invalidated, then just allocate a new buffer to replace the old one.
280 * If not, and we'd block, and they allow the subrange of the buffer to be
281 * invalidated, then we can make a new little BO, let them write into that,
282 * and blit it into the real BO at unmap time.
285 intel_bufferobj_map_range(struct gl_context
* ctx
,
286 GLintptr offset
, GLsizeiptr length
,
287 GLbitfield access
, struct gl_buffer_object
*obj
)
289 struct intel_context
*intel
= intel_context(ctx
);
290 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
294 /* _mesa_MapBufferRange (GL entrypoint) sets these, but the vbo module also
295 * internally uses our functions directly.
297 obj
->Offset
= offset
;
298 obj
->Length
= length
;
299 obj
->AccessFlags
= access
;
301 if (intel_obj
->sys_buffer
) {
302 const bool read_only
=
303 (access
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) == GL_MAP_READ_BIT
;
305 if (!read_only
&& intel_obj
->source
)
306 release_buffer(intel_obj
);
308 if (!intel_obj
->buffer
|| intel_obj
->source
) {
309 obj
->Pointer
= intel_obj
->sys_buffer
+ offset
;
313 free(intel_obj
->sys_buffer
);
314 intel_obj
->sys_buffer
= NULL
;
317 if (intel_obj
->buffer
== NULL
) {
322 /* If the access is synchronized (like a normal buffer mapping), then get
323 * things flushed out so the later mapping syncs appropriately through GEM.
324 * If the user doesn't care about existing buffer contents and mapping would
325 * cause us to block, then throw out the old buffer.
327 * If they set INVALIDATE_BUFFER, we can pitch the current contents to
328 * achieve the required synchronization.
330 if (!(access
& GL_MAP_UNSYNCHRONIZED_BIT
)) {
331 if (drm_intel_bo_references(intel
->batch
.bo
, intel_obj
->buffer
)) {
332 if (access
& GL_MAP_INVALIDATE_BUFFER_BIT
) {
333 drm_intel_bo_unreference(intel_obj
->buffer
);
334 intel_bufferobj_alloc_buffer(intel
, intel_obj
);
338 } else if (drm_intel_bo_busy(intel_obj
->buffer
) &&
339 (access
& GL_MAP_INVALIDATE_BUFFER_BIT
)) {
340 drm_intel_bo_unreference(intel_obj
->buffer
);
341 intel_bufferobj_alloc_buffer(intel
, intel_obj
);
345 /* If the user is mapping a range of an active buffer object but
346 * doesn't require the current contents of that range, make a new
347 * BO, and we'll copy what they put in there out at unmap or
350 if ((access
& GL_MAP_INVALIDATE_RANGE_BIT
) &&
351 drm_intel_bo_busy(intel_obj
->buffer
)) {
352 if (access
& GL_MAP_FLUSH_EXPLICIT_BIT
) {
353 intel_obj
->range_map_buffer
= malloc(length
);
354 obj
->Pointer
= intel_obj
->range_map_buffer
;
356 intel_obj
->range_map_bo
= drm_intel_bo_alloc(intel
->bufmgr
,
359 if (!(access
& GL_MAP_READ_BIT
)) {
360 drm_intel_gem_bo_map_gtt(intel_obj
->range_map_bo
);
362 drm_intel_bo_map(intel_obj
->range_map_bo
,
363 (access
& GL_MAP_WRITE_BIT
) != 0);
365 obj
->Pointer
= intel_obj
->range_map_bo
->virtual;
370 if (access
& GL_MAP_UNSYNCHRONIZED_BIT
)
371 drm_intel_gem_bo_map_unsynchronized(intel_obj
->buffer
);
372 else if (!(access
& GL_MAP_READ_BIT
)) {
373 drm_intel_gem_bo_map_gtt(intel_obj
->buffer
);
375 drm_intel_bo_map(intel_obj
->buffer
, (access
& GL_MAP_WRITE_BIT
) != 0);
378 obj
->Pointer
= intel_obj
->buffer
->virtual + offset
;
382 /* Ideally we'd use a BO to avoid taking up cache space for the temporary
383 * data, but FlushMappedBufferRange may be followed by further writes to
384 * the pointer, so we would have to re-map after emitting our blit, which
385 * would defeat the point.
388 intel_bufferobj_flush_mapped_range(struct gl_context
*ctx
,
389 GLintptr offset
, GLsizeiptr length
,
390 struct gl_buffer_object
*obj
)
392 struct intel_context
*intel
= intel_context(ctx
);
393 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
394 drm_intel_bo
*temp_bo
;
396 /* Unless we're in the range map using a temporary system buffer,
397 * there's no work to do.
399 if (intel_obj
->range_map_buffer
== NULL
)
405 temp_bo
= drm_intel_bo_alloc(intel
->bufmgr
, "range map flush", length
, 64);
407 drm_intel_bo_subdata(temp_bo
, 0, length
, intel_obj
->range_map_buffer
);
409 intel_emit_linear_blit(intel
,
410 intel_obj
->buffer
, obj
->Offset
+ offset
,
414 drm_intel_bo_unreference(temp_bo
);
419 * Called via glUnmapBuffer().
422 intel_bufferobj_unmap(struct gl_context
* ctx
, struct gl_buffer_object
*obj
)
424 struct intel_context
*intel
= intel_context(ctx
);
425 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
428 assert(obj
->Pointer
);
429 if (intel_obj
->sys_buffer
!= NULL
) {
430 /* always keep the mapping around. */
431 } else if (intel_obj
->range_map_buffer
!= NULL
) {
432 /* Since we've emitted some blits to buffers that will (likely) be used
433 * in rendering operations in other cache domains in this batch, emit a
434 * flush. Once again, we wish for a domain tracker in libdrm to cover
435 * usage inside of a batchbuffer.
437 intel_batchbuffer_emit_mi_flush(intel
);
438 free(intel_obj
->range_map_buffer
);
439 intel_obj
->range_map_buffer
= NULL
;
440 } else if (intel_obj
->range_map_bo
!= NULL
) {
441 drm_intel_bo_unmap(intel_obj
->range_map_bo
);
443 intel_emit_linear_blit(intel
,
444 intel_obj
->buffer
, obj
->Offset
,
445 intel_obj
->range_map_bo
, 0,
448 /* Since we've emitted some blits to buffers that will (likely) be used
449 * in rendering operations in other cache domains in this batch, emit a
450 * flush. Once again, we wish for a domain tracker in libdrm to cover
451 * usage inside of a batchbuffer.
453 intel_batchbuffer_emit_mi_flush(intel
);
455 drm_intel_bo_unreference(intel_obj
->range_map_bo
);
456 intel_obj
->range_map_bo
= NULL
;
457 } else if (intel_obj
->buffer
!= NULL
) {
458 drm_intel_bo_unmap(intel_obj
->buffer
);
468 intel_bufferobj_buffer(struct intel_context
*intel
,
469 struct intel_buffer_object
*intel_obj
,
472 if (intel_obj
->source
)
473 release_buffer(intel_obj
);
475 if (intel_obj
->buffer
== NULL
) {
476 intel_bufferobj_alloc_buffer(intel
, intel_obj
);
477 drm_intel_bo_subdata(intel_obj
->buffer
,
478 0, intel_obj
->Base
.Size
,
479 intel_obj
->sys_buffer
);
481 free(intel_obj
->sys_buffer
);
482 intel_obj
->sys_buffer
= NULL
;
483 intel_obj
->offset
= 0;
486 return intel_obj
->buffer
;
489 #define INTEL_UPLOAD_SIZE (64*1024)
492 intel_upload_finish(struct intel_context
*intel
)
494 if (!intel
->upload
.bo
)
497 if (intel
->upload
.buffer_len
) {
498 drm_intel_bo_subdata(intel
->upload
.bo
,
499 intel
->upload
.buffer_offset
,
500 intel
->upload
.buffer_len
,
501 intel
->upload
.buffer
);
502 intel
->upload
.buffer_len
= 0;
505 drm_intel_bo_unreference(intel
->upload
.bo
);
506 intel
->upload
.bo
= NULL
;
509 static void wrap_buffers(struct intel_context
*intel
, GLuint size
)
511 intel_upload_finish(intel
);
513 if (size
< INTEL_UPLOAD_SIZE
)
514 size
= INTEL_UPLOAD_SIZE
;
516 intel
->upload
.bo
= drm_intel_bo_alloc(intel
->bufmgr
, "upload", size
, 0);
517 intel
->upload
.offset
= 0;
520 void intel_upload_data(struct intel_context
*intel
,
521 const void *ptr
, GLuint size
, GLuint align
,
522 drm_intel_bo
**return_bo
,
523 GLuint
*return_offset
)
527 base
= (intel
->upload
.offset
+ align
- 1) / align
* align
;
528 if (intel
->upload
.bo
== NULL
|| base
+ size
> intel
->upload
.bo
->size
) {
529 wrap_buffers(intel
, size
);
533 drm_intel_bo_reference(intel
->upload
.bo
);
534 *return_bo
= intel
->upload
.bo
;
535 *return_offset
= base
;
537 delta
= base
- intel
->upload
.offset
;
538 if (intel
->upload
.buffer_len
&&
539 intel
->upload
.buffer_len
+ delta
+ size
> sizeof(intel
->upload
.buffer
))
541 drm_intel_bo_subdata(intel
->upload
.bo
,
542 intel
->upload
.buffer_offset
,
543 intel
->upload
.buffer_len
,
544 intel
->upload
.buffer
);
545 intel
->upload
.buffer_len
= 0;
548 if (size
< sizeof(intel
->upload
.buffer
))
550 if (intel
->upload
.buffer_len
== 0)
551 intel
->upload
.buffer_offset
= base
;
553 intel
->upload
.buffer_len
+= delta
;
555 memcpy(intel
->upload
.buffer
+ intel
->upload
.buffer_len
, ptr
, size
);
556 intel
->upload
.buffer_len
+= size
;
560 drm_intel_bo_subdata(intel
->upload
.bo
, base
, size
, ptr
);
563 intel
->upload
.offset
= base
+ size
;
566 void *intel_upload_map(struct intel_context
*intel
, GLuint size
, GLuint align
)
571 base
= (intel
->upload
.offset
+ align
- 1) / align
* align
;
572 if (intel
->upload
.bo
== NULL
|| base
+ size
> intel
->upload
.bo
->size
) {
573 wrap_buffers(intel
, size
);
577 delta
= base
- intel
->upload
.offset
;
578 if (intel
->upload
.buffer_len
&&
579 intel
->upload
.buffer_len
+ delta
+ size
> sizeof(intel
->upload
.buffer
))
581 drm_intel_bo_subdata(intel
->upload
.bo
,
582 intel
->upload
.buffer_offset
,
583 intel
->upload
.buffer_len
,
584 intel
->upload
.buffer
);
585 intel
->upload
.buffer_len
= 0;
588 if (size
<= sizeof(intel
->upload
.buffer
)) {
589 if (intel
->upload
.buffer_len
== 0)
590 intel
->upload
.buffer_offset
= base
;
592 intel
->upload
.buffer_len
+= delta
;
594 ptr
= intel
->upload
.buffer
+ intel
->upload
.buffer_len
;
595 intel
->upload
.buffer_len
+= size
;
602 void intel_upload_unmap(struct intel_context
*intel
,
603 const void *ptr
, GLuint size
, GLuint align
,
604 drm_intel_bo
**return_bo
,
605 GLuint
*return_offset
)
609 base
= (intel
->upload
.offset
+ align
- 1) / align
* align
;
610 if (size
> sizeof(intel
->upload
.buffer
)) {
611 drm_intel_bo_subdata(intel
->upload
.bo
, base
, size
, ptr
);
615 drm_intel_bo_reference(intel
->upload
.bo
);
616 *return_bo
= intel
->upload
.bo
;
617 *return_offset
= base
;
619 intel
->upload
.offset
= base
+ size
;
623 intel_bufferobj_source(struct intel_context
*intel
,
624 struct intel_buffer_object
*intel_obj
,
625 GLuint align
, GLuint
*offset
)
627 if (intel_obj
->buffer
== NULL
) {
628 intel_upload_data(intel
,
629 intel_obj
->sys_buffer
, intel_obj
->Base
.Size
, align
,
630 &intel_obj
->buffer
, &intel_obj
->offset
);
631 intel_obj
->source
= 1;
634 *offset
= intel_obj
->offset
;
635 return intel_obj
->buffer
;
639 intel_bufferobj_copy_subdata(struct gl_context
*ctx
,
640 struct gl_buffer_object
*src
,
641 struct gl_buffer_object
*dst
,
642 GLintptr read_offset
, GLintptr write_offset
,
645 struct intel_context
*intel
= intel_context(ctx
);
646 struct intel_buffer_object
*intel_src
= intel_buffer_object(src
);
647 struct intel_buffer_object
*intel_dst
= intel_buffer_object(dst
);
648 drm_intel_bo
*src_bo
, *dst_bo
;
654 /* If we're in system memory, just map and memcpy. */
655 if (intel_src
->sys_buffer
|| intel_dst
->sys_buffer
) {
656 /* The same buffer may be used, but note that regions copied may
660 char *ptr
= intel_bufferobj_map_range(ctx
, 0, dst
->Size
,
664 memmove(ptr
+ write_offset
, ptr
+ read_offset
, size
);
665 intel_bufferobj_unmap(ctx
, dst
);
670 src_ptr
= intel_bufferobj_map_range(ctx
, 0, src
->Size
,
671 GL_MAP_READ_BIT
, src
);
672 dst_ptr
= intel_bufferobj_map_range(ctx
, 0, dst
->Size
,
673 GL_MAP_WRITE_BIT
, dst
);
675 memcpy(dst_ptr
+ write_offset
, src_ptr
+ read_offset
, size
);
677 intel_bufferobj_unmap(ctx
, src
);
678 intel_bufferobj_unmap(ctx
, dst
);
683 /* Otherwise, we have real BOs, so blit them. */
685 dst_bo
= intel_bufferobj_buffer(intel
, intel_dst
, INTEL_WRITE_PART
);
686 src_bo
= intel_bufferobj_source(intel
, intel_src
, 64, &src_offset
);
688 intel_emit_linear_blit(intel
,
689 dst_bo
, write_offset
,
690 src_bo
, read_offset
+ src_offset
, size
);
692 /* Since we've emitted some blits to buffers that will (likely) be used
693 * in rendering operations in other cache domains in this batch, emit a
694 * flush. Once again, we wish for a domain tracker in libdrm to cover
695 * usage inside of a batchbuffer.
697 intel_batchbuffer_emit_mi_flush(intel
);
700 #if FEATURE_APPLE_object_purgeable
702 intel_buffer_purgeable(drm_intel_bo
*buffer
)
707 retained
= drm_intel_bo_madvise (buffer
, I915_MADV_DONTNEED
);
709 return retained
? GL_VOLATILE_APPLE
: GL_RELEASED_APPLE
;
713 intel_buffer_object_purgeable(struct gl_context
* ctx
,
714 struct gl_buffer_object
*obj
,
717 struct intel_buffer_object
*intel_obj
= intel_buffer_object (obj
);
719 if (intel_obj
->buffer
!= NULL
)
720 return intel_buffer_purgeable(intel_obj
->buffer
);
722 if (option
== GL_RELEASED_APPLE
) {
723 if (intel_obj
->sys_buffer
!= NULL
) {
724 free(intel_obj
->sys_buffer
);
725 intel_obj
->sys_buffer
= NULL
;
728 return GL_RELEASED_APPLE
;
730 /* XXX Create the buffer and madvise(MADV_DONTNEED)? */
731 struct intel_context
*intel
= intel_context(ctx
);
732 drm_intel_bo
*bo
= intel_bufferobj_buffer(intel
, intel_obj
, INTEL_READ
);
734 return intel_buffer_purgeable(bo
);
739 intel_texture_object_purgeable(struct gl_context
* ctx
,
740 struct gl_texture_object
*obj
,
743 struct intel_texture_object
*intel
;
748 intel
= intel_texture_object(obj
);
749 if (intel
->mt
== NULL
|| intel
->mt
->region
== NULL
)
750 return GL_RELEASED_APPLE
;
752 return intel_buffer_purgeable(intel
->mt
->region
->bo
);
756 intel_render_object_purgeable(struct gl_context
* ctx
,
757 struct gl_renderbuffer
*obj
,
760 struct intel_renderbuffer
*intel
;
765 intel
= intel_renderbuffer(obj
);
766 if (intel
->mt
== NULL
)
767 return GL_RELEASED_APPLE
;
769 return intel_buffer_purgeable(intel
->mt
->region
->bo
);
773 intel_buffer_unpurgeable(drm_intel_bo
*buffer
)
779 retained
= drm_intel_bo_madvise (buffer
, I915_MADV_WILLNEED
);
781 return retained
? GL_RETAINED_APPLE
: GL_UNDEFINED_APPLE
;
785 intel_buffer_object_unpurgeable(struct gl_context
* ctx
,
786 struct gl_buffer_object
*obj
,
792 return intel_buffer_unpurgeable(intel_buffer_object (obj
)->buffer
);
796 intel_texture_object_unpurgeable(struct gl_context
* ctx
,
797 struct gl_texture_object
*obj
,
800 struct intel_texture_object
*intel
;
805 intel
= intel_texture_object(obj
);
806 if (intel
->mt
== NULL
|| intel
->mt
->region
== NULL
)
807 return GL_UNDEFINED_APPLE
;
809 return intel_buffer_unpurgeable(intel
->mt
->region
->bo
);
813 intel_render_object_unpurgeable(struct gl_context
* ctx
,
814 struct gl_renderbuffer
*obj
,
817 struct intel_renderbuffer
*intel
;
822 intel
= intel_renderbuffer(obj
);
823 if (intel
->mt
== NULL
)
824 return GL_UNDEFINED_APPLE
;
826 return intel_buffer_unpurgeable(intel
->mt
->region
->bo
);
831 intelInitBufferObjectFuncs(struct dd_function_table
*functions
)
833 functions
->NewBufferObject
= intel_bufferobj_alloc
;
834 functions
->DeleteBuffer
= intel_bufferobj_free
;
835 functions
->BufferData
= intel_bufferobj_data
;
836 functions
->BufferSubData
= intel_bufferobj_subdata
;
837 functions
->GetBufferSubData
= intel_bufferobj_get_subdata
;
838 functions
->MapBufferRange
= intel_bufferobj_map_range
;
839 functions
->FlushMappedBufferRange
= intel_bufferobj_flush_mapped_range
;
840 functions
->UnmapBuffer
= intel_bufferobj_unmap
;
841 functions
->CopyBufferSubData
= intel_bufferobj_copy_subdata
;
843 #if FEATURE_APPLE_object_purgeable
844 functions
->BufferObjectPurgeable
= intel_buffer_object_purgeable
;
845 functions
->TextureObjectPurgeable
= intel_texture_object_purgeable
;
846 functions
->RenderObjectPurgeable
= intel_render_object_purgeable
;
848 functions
->BufferObjectUnpurgeable
= intel_buffer_object_unpurgeable
;
849 functions
->TextureObjectUnpurgeable
= intel_texture_object_unpurgeable
;
850 functions
->RenderObjectUnpurgeable
= intel_render_object_unpurgeable
;