1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
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 VMWARE 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/mtypes.h"
31 #include "main/macros.h"
32 #include "main/bufferobj.h"
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"
43 intel_bufferobj_unmap(struct gl_context
* ctx
, struct gl_buffer_object
*obj
,
44 gl_map_buffer_index index
);
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
)
73 struct intel_buffer_object
*obj
= CALLOC_STRUCT(intel_buffer_object
);
75 _mesa_initialize_buffer_object(ctx
, &obj
->Base
, name
);
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)
97 _mesa_buffer_unmap_all_mappings(ctx
, obj
);
99 _mesa_align_free(intel_obj
->sys_buffer
);
101 drm_intel_bo_unreference(intel_obj
->buffer
);
102 _mesa_delete_buffer_object(ctx
, obj
);
108 * Allocate space for and store data in a buffer object. Any data that was
109 * previously stored in the buffer object is lost. If data is NULL,
110 * memory will be allocated, but no copy will occur.
111 * Called via ctx->Driver.BufferData().
112 * \return true for success, false if out of memory
115 intel_bufferobj_data(struct gl_context
* ctx
,
120 GLbitfield storageFlags
,
121 struct gl_buffer_object
*obj
)
123 struct intel_context
*intel
= intel_context(ctx
);
124 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
126 intel_obj
->Base
.Size
= size
;
127 intel_obj
->Base
.Usage
= usage
;
128 intel_obj
->Base
.StorageFlags
= storageFlags
;
130 assert(!obj
->Mappings
[MAP_USER
].Pointer
); /* Mesa should have unmapped it */
131 assert(!obj
->Mappings
[MAP_INTERNAL
].Pointer
);
133 if (intel_obj
->buffer
!= NULL
)
134 release_buffer(intel_obj
);
136 _mesa_align_free(intel_obj
->sys_buffer
);
137 intel_obj
->sys_buffer
= NULL
;
140 /* Stick VBOs in system memory, as we're always doing swtnl with their
143 if (target
== GL_ARRAY_BUFFER
|| target
== GL_ELEMENT_ARRAY_BUFFER
) {
144 intel_obj
->sys_buffer
=
145 _mesa_align_malloc(size
, ctx
->Const
.MinMapBufferAlignment
);
146 if (intel_obj
->sys_buffer
!= NULL
) {
148 memcpy(intel_obj
->sys_buffer
, data
, size
);
153 intel_bufferobj_alloc_buffer(intel
, intel_obj
);
154 if (!intel_obj
->buffer
)
158 drm_intel_bo_subdata(intel_obj
->buffer
, 0, size
, data
);
166 * Replace data in a subrange of buffer object. If the data range
167 * specified by size + offset extends beyond the end of the buffer or
168 * if data is NULL, no copy is performed.
169 * Called via glBufferSubDataARB().
172 intel_bufferobj_subdata(struct gl_context
* ctx
,
175 const GLvoid
* data
, struct gl_buffer_object
*obj
)
177 struct intel_context
*intel
= intel_context(ctx
);
178 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
186 /* If we have a single copy in system memory, update that */
187 if (intel_obj
->sys_buffer
) {
188 if (intel_obj
->source
)
189 release_buffer(intel_obj
);
191 if (intel_obj
->buffer
== NULL
) {
192 memcpy((char *)intel_obj
->sys_buffer
+ offset
, data
, size
);
196 _mesa_align_free(intel_obj
->sys_buffer
);
197 intel_obj
->sys_buffer
= NULL
;
200 /* Otherwise we need to update the copy in video memory. */
202 drm_intel_bo_busy(intel_obj
->buffer
) ||
203 drm_intel_bo_references(intel
->batch
.bo
, intel_obj
->buffer
);
206 if (size
== intel_obj
->Base
.Size
) {
207 /* Replace the current busy bo with fresh data. */
208 drm_intel_bo_unreference(intel_obj
->buffer
);
209 intel_bufferobj_alloc_buffer(intel
, intel_obj
);
210 drm_intel_bo_subdata(intel_obj
->buffer
, 0, size
, data
);
212 perf_debug("Using a blit copy to avoid stalling on %ldb "
213 "glBufferSubData() to a busy buffer object.\n",
215 drm_intel_bo
*temp_bo
=
216 drm_intel_bo_alloc(intel
->bufmgr
, "subdata temp", size
, 64);
218 drm_intel_bo_subdata(temp_bo
, 0, size
, data
);
220 intel_emit_linear_blit(intel
,
221 intel_obj
->buffer
, offset
,
225 drm_intel_bo_unreference(temp_bo
);
228 drm_intel_bo_subdata(intel_obj
->buffer
, offset
, size
, data
);
234 * Called via glGetBufferSubDataARB().
237 intel_bufferobj_get_subdata(struct gl_context
* ctx
,
240 GLvoid
* data
, struct gl_buffer_object
*obj
)
242 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
243 struct intel_context
*intel
= intel_context(ctx
);
246 if (intel_obj
->sys_buffer
)
247 memcpy(data
, (char *)intel_obj
->sys_buffer
+ offset
, size
);
249 if (drm_intel_bo_references(intel
->batch
.bo
, intel_obj
->buffer
)) {
250 intel_batchbuffer_flush(intel
);
252 drm_intel_bo_get_subdata(intel_obj
->buffer
, offset
, size
, data
);
259 * Called via glMapBufferRange and glMapBuffer
261 * The goal of this extension is to allow apps to accumulate their rendering
262 * at the same time as they accumulate their buffer object. Without it,
263 * you'd end up blocking on execution of rendering every time you mapped
264 * the buffer to put new data in.
266 * We support it in 3 ways: If unsynchronized, then don't bother
267 * flushing the batchbuffer before mapping the buffer, which can save blocking
268 * in many cases. If we would still block, and they allow the whole buffer
269 * to be invalidated, then just allocate a new buffer to replace the old one.
270 * If not, and we'd block, and they allow the subrange of the buffer to be
271 * invalidated, then we can make a new little BO, let them write into that,
272 * and blit it into the real BO at unmap time.
275 intel_bufferobj_map_range(struct gl_context
* ctx
,
276 GLintptr offset
, GLsizeiptr length
,
277 GLbitfield access
, struct gl_buffer_object
*obj
,
278 gl_map_buffer_index index
)
280 struct intel_context
*intel
= intel_context(ctx
);
281 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
285 /* _mesa_MapBufferRange (GL entrypoint) sets these, but the vbo module also
286 * internally uses our functions directly.
288 obj
->Mappings
[index
].Offset
= offset
;
289 obj
->Mappings
[index
].Length
= length
;
290 obj
->Mappings
[index
].AccessFlags
= access
;
292 if (intel_obj
->sys_buffer
) {
293 const bool read_only
=
294 (access
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) == GL_MAP_READ_BIT
;
296 if (!read_only
&& intel_obj
->source
)
297 release_buffer(intel_obj
);
299 if (!intel_obj
->buffer
|| intel_obj
->source
) {
300 obj
->Mappings
[index
].Pointer
= intel_obj
->sys_buffer
+ offset
;
301 return obj
->Mappings
[index
].Pointer
;
304 _mesa_align_free(intel_obj
->sys_buffer
);
305 intel_obj
->sys_buffer
= NULL
;
308 if (intel_obj
->buffer
== NULL
) {
309 obj
->Mappings
[index
].Pointer
= NULL
;
313 /* If the access is synchronized (like a normal buffer mapping), then get
314 * things flushed out so the later mapping syncs appropriately through GEM.
315 * If the user doesn't care about existing buffer contents and mapping would
316 * cause us to block, then throw out the old buffer.
318 * If they set INVALIDATE_BUFFER, we can pitch the current contents to
319 * achieve the required synchronization.
321 if (!(access
& GL_MAP_UNSYNCHRONIZED_BIT
)) {
322 if (drm_intel_bo_references(intel
->batch
.bo
, intel_obj
->buffer
)) {
323 if (access
& GL_MAP_INVALIDATE_BUFFER_BIT
) {
324 drm_intel_bo_unreference(intel_obj
->buffer
);
325 intel_bufferobj_alloc_buffer(intel
, intel_obj
);
327 perf_debug("Stalling on the GPU for mapping a busy buffer "
331 } else if (drm_intel_bo_busy(intel_obj
->buffer
) &&
332 (access
& GL_MAP_INVALIDATE_BUFFER_BIT
)) {
333 drm_intel_bo_unreference(intel_obj
->buffer
);
334 intel_bufferobj_alloc_buffer(intel
, intel_obj
);
338 /* If the user is mapping a range of an active buffer object but
339 * doesn't require the current contents of that range, make a new
340 * BO, and we'll copy what they put in there out at unmap or
343 if ((access
& GL_MAP_INVALIDATE_RANGE_BIT
) &&
344 drm_intel_bo_busy(intel_obj
->buffer
)) {
345 /* Ensure that the base alignment of the allocation meets the alignment
346 * guarantees the driver has advertised to the application.
348 const unsigned alignment
= ctx
->Const
.MinMapBufferAlignment
;
349 const unsigned extra
= (uintptr_t) offset
% alignment
;
351 if (access
& GL_MAP_FLUSH_EXPLICIT_BIT
) {
352 intel_obj
->range_map_buffer
[index
] =
353 _mesa_align_malloc(length
+ extra
, alignment
);
354 obj
->Mappings
[index
].Pointer
=
355 intel_obj
->range_map_buffer
[index
] + extra
;
357 intel_obj
->range_map_bo
[index
] = drm_intel_bo_alloc(intel
->bufmgr
,
361 if (!(access
& GL_MAP_READ_BIT
)) {
362 drm_intel_gem_bo_map_gtt(intel_obj
->range_map_bo
[index
]);
364 drm_intel_bo_map(intel_obj
->range_map_bo
[index
],
365 (access
& GL_MAP_WRITE_BIT
) != 0);
367 obj
->Mappings
[index
].Pointer
=
368 intel_obj
->range_map_bo
[index
]->virtual + extra
;
370 return obj
->Mappings
[index
].Pointer
;
373 if (access
& GL_MAP_UNSYNCHRONIZED_BIT
)
374 drm_intel_gem_bo_map_unsynchronized(intel_obj
->buffer
);
375 else if (!(access
& GL_MAP_READ_BIT
)) {
376 drm_intel_gem_bo_map_gtt(intel_obj
->buffer
);
378 drm_intel_bo_map(intel_obj
->buffer
, (access
& GL_MAP_WRITE_BIT
) != 0);
381 obj
->Mappings
[index
].Pointer
= intel_obj
->buffer
->virtual + offset
;
382 return obj
->Mappings
[index
].Pointer
;
385 /* Ideally we'd use a BO to avoid taking up cache space for the temporary
386 * data, but FlushMappedBufferRange may be followed by further writes to
387 * the pointer, so we would have to re-map after emitting our blit, which
388 * would defeat the point.
391 intel_bufferobj_flush_mapped_range(struct gl_context
*ctx
,
392 GLintptr offset
, GLsizeiptr length
,
393 struct gl_buffer_object
*obj
,
394 gl_map_buffer_index index
)
396 struct intel_context
*intel
= intel_context(ctx
);
397 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
398 drm_intel_bo
*temp_bo
;
400 /* Unless we're in the range map using a temporary system buffer,
401 * there's no work to do.
403 if (intel_obj
->range_map_buffer
[index
] == NULL
)
409 temp_bo
= drm_intel_bo_alloc(intel
->bufmgr
, "range map flush", length
, 64);
411 /* Use obj->Pointer instead of intel_obj->range_map_buffer because the
412 * former points to the actual mapping while the latter may be offset to
413 * meet alignment guarantees.
415 drm_intel_bo_subdata(temp_bo
, 0, length
, obj
->Mappings
[index
].Pointer
);
417 intel_emit_linear_blit(intel
,
419 obj
->Mappings
[index
].Offset
+ offset
,
423 drm_intel_bo_unreference(temp_bo
);
428 * Called via glUnmapBuffer().
431 intel_bufferobj_unmap(struct gl_context
* ctx
, struct gl_buffer_object
*obj
,
432 gl_map_buffer_index index
)
434 struct intel_context
*intel
= intel_context(ctx
);
435 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
438 assert(obj
->Mappings
[index
].Pointer
);
439 if (intel_obj
->sys_buffer
!= NULL
) {
440 /* always keep the mapping around. */
441 } else if (intel_obj
->range_map_buffer
[index
] != NULL
) {
442 /* Since we've emitted some blits to buffers that will (likely) be used
443 * in rendering operations in other cache domains in this batch, emit a
444 * flush. Once again, we wish for a domain tracker in libdrm to cover
445 * usage inside of a batchbuffer.
447 intel_batchbuffer_emit_mi_flush(intel
);
448 _mesa_align_free(intel_obj
->range_map_buffer
[index
]);
449 intel_obj
->range_map_buffer
[index
] = NULL
;
450 } else if (intel_obj
->range_map_bo
[index
] != NULL
) {
451 const unsigned extra
= obj
->Mappings
[index
].Pointer
-
452 intel_obj
->range_map_bo
[index
]->virtual;
454 drm_intel_bo_unmap(intel_obj
->range_map_bo
[index
]);
456 intel_emit_linear_blit(intel
,
457 intel_obj
->buffer
, obj
->Mappings
[index
].Offset
,
458 intel_obj
->range_map_bo
[index
], extra
,
459 obj
->Mappings
[index
].Length
);
461 /* Since we've emitted some blits to buffers that will (likely) be used
462 * in rendering operations in other cache domains in this batch, emit a
463 * flush. Once again, we wish for a domain tracker in libdrm to cover
464 * usage inside of a batchbuffer.
466 intel_batchbuffer_emit_mi_flush(intel
);
468 drm_intel_bo_unreference(intel_obj
->range_map_bo
[index
]);
469 intel_obj
->range_map_bo
[index
] = NULL
;
470 } else if (intel_obj
->buffer
!= NULL
) {
471 drm_intel_bo_unmap(intel_obj
->buffer
);
473 obj
->Mappings
[index
].Pointer
= NULL
;
474 obj
->Mappings
[index
].Offset
= 0;
475 obj
->Mappings
[index
].Length
= 0;
481 intel_bufferobj_buffer(struct intel_context
*intel
,
482 struct intel_buffer_object
*intel_obj
)
484 if (intel_obj
->source
)
485 release_buffer(intel_obj
);
487 if (intel_obj
->buffer
== NULL
) {
488 intel_bufferobj_alloc_buffer(intel
, intel_obj
);
489 drm_intel_bo_subdata(intel_obj
->buffer
,
490 0, intel_obj
->Base
.Size
,
491 intel_obj
->sys_buffer
);
493 _mesa_align_free(intel_obj
->sys_buffer
);
494 intel_obj
->sys_buffer
= NULL
;
495 intel_obj
->offset
= 0;
498 return intel_obj
->buffer
;
501 #define INTEL_UPLOAD_SIZE (64*1024)
504 intel_upload_finish(struct intel_context
*intel
)
506 if (!intel
->upload
.bo
)
509 if (intel
->upload
.buffer_len
) {
510 drm_intel_bo_subdata(intel
->upload
.bo
,
511 intel
->upload
.buffer_offset
,
512 intel
->upload
.buffer_len
,
513 intel
->upload
.buffer
);
514 intel
->upload
.buffer_len
= 0;
517 drm_intel_bo_unreference(intel
->upload
.bo
);
518 intel
->upload
.bo
= NULL
;
521 static void wrap_buffers(struct intel_context
*intel
, GLuint size
)
523 intel_upload_finish(intel
);
525 if (size
< INTEL_UPLOAD_SIZE
)
526 size
= INTEL_UPLOAD_SIZE
;
528 intel
->upload
.bo
= drm_intel_bo_alloc(intel
->bufmgr
, "upload", size
, 0);
529 intel
->upload
.offset
= 0;
532 void intel_upload_data(struct intel_context
*intel
,
533 const void *ptr
, GLuint size
, GLuint align
,
534 drm_intel_bo
**return_bo
,
535 GLuint
*return_offset
)
539 base
= (intel
->upload
.offset
+ align
- 1) / align
* align
;
540 if (intel
->upload
.bo
== NULL
|| base
+ size
> intel
->upload
.bo
->size
) {
541 wrap_buffers(intel
, size
);
545 drm_intel_bo_reference(intel
->upload
.bo
);
546 *return_bo
= intel
->upload
.bo
;
547 *return_offset
= base
;
549 delta
= base
- intel
->upload
.offset
;
550 if (intel
->upload
.buffer_len
&&
551 intel
->upload
.buffer_len
+ delta
+ size
> sizeof(intel
->upload
.buffer
))
553 drm_intel_bo_subdata(intel
->upload
.bo
,
554 intel
->upload
.buffer_offset
,
555 intel
->upload
.buffer_len
,
556 intel
->upload
.buffer
);
557 intel
->upload
.buffer_len
= 0;
560 if (size
< sizeof(intel
->upload
.buffer
))
562 if (intel
->upload
.buffer_len
== 0)
563 intel
->upload
.buffer_offset
= base
;
565 intel
->upload
.buffer_len
+= delta
;
567 memcpy(intel
->upload
.buffer
+ intel
->upload
.buffer_len
, ptr
, size
);
568 intel
->upload
.buffer_len
+= size
;
572 drm_intel_bo_subdata(intel
->upload
.bo
, base
, size
, ptr
);
575 intel
->upload
.offset
= base
+ size
;
579 intel_bufferobj_source(struct intel_context
*intel
,
580 struct intel_buffer_object
*intel_obj
,
581 GLuint align
, GLuint
*offset
)
583 if (intel_obj
->buffer
== NULL
) {
584 intel_upload_data(intel
,
585 intel_obj
->sys_buffer
, intel_obj
->Base
.Size
, align
,
586 &intel_obj
->buffer
, &intel_obj
->offset
);
587 intel_obj
->source
= 1;
590 *offset
= intel_obj
->offset
;
591 return intel_obj
->buffer
;
595 intel_bufferobj_copy_subdata(struct gl_context
*ctx
,
596 struct gl_buffer_object
*src
,
597 struct gl_buffer_object
*dst
,
598 GLintptr read_offset
, GLintptr write_offset
,
601 struct intel_context
*intel
= intel_context(ctx
);
602 struct intel_buffer_object
*intel_src
= intel_buffer_object(src
);
603 struct intel_buffer_object
*intel_dst
= intel_buffer_object(dst
);
604 drm_intel_bo
*src_bo
, *dst_bo
;
610 /* If we're in system memory, just map and memcpy. */
611 if (intel_src
->sys_buffer
|| intel_dst
->sys_buffer
) {
612 /* The same buffer may be used, but note that regions copied may
616 char *ptr
= intel_bufferobj_map_range(ctx
, 0, dst
->Size
,
620 memmove(ptr
+ write_offset
, ptr
+ read_offset
, size
);
621 intel_bufferobj_unmap(ctx
, dst
, MAP_INTERNAL
);
626 src_ptr
= intel_bufferobj_map_range(ctx
, 0, src
->Size
,
627 GL_MAP_READ_BIT
, src
,
629 dst_ptr
= intel_bufferobj_map_range(ctx
, 0, dst
->Size
,
630 GL_MAP_WRITE_BIT
, dst
,
633 memcpy(dst_ptr
+ write_offset
, src_ptr
+ read_offset
, size
);
635 intel_bufferobj_unmap(ctx
, src
, MAP_INTERNAL
);
636 intel_bufferobj_unmap(ctx
, dst
, MAP_INTERNAL
);
641 /* Otherwise, we have real BOs, so blit them. */
643 dst_bo
= intel_bufferobj_buffer(intel
, intel_dst
);
644 src_bo
= intel_bufferobj_source(intel
, intel_src
, 64, &src_offset
);
646 intel_emit_linear_blit(intel
,
647 dst_bo
, write_offset
,
648 src_bo
, read_offset
+ src_offset
, size
);
650 /* Since we've emitted some blits to buffers that will (likely) be used
651 * in rendering operations in other cache domains in this batch, emit a
652 * flush. Once again, we wish for a domain tracker in libdrm to cover
653 * usage inside of a batchbuffer.
655 intel_batchbuffer_emit_mi_flush(intel
);
659 intel_buffer_purgeable(drm_intel_bo
*buffer
)
664 retained
= drm_intel_bo_madvise (buffer
, I915_MADV_DONTNEED
);
666 return retained
? GL_VOLATILE_APPLE
: GL_RELEASED_APPLE
;
670 intel_buffer_object_purgeable(struct gl_context
* ctx
,
671 struct gl_buffer_object
*obj
,
674 struct intel_buffer_object
*intel_obj
= intel_buffer_object (obj
);
676 if (intel_obj
->buffer
!= NULL
)
677 return intel_buffer_purgeable(intel_obj
->buffer
);
679 if (option
== GL_RELEASED_APPLE
) {
680 _mesa_align_free(intel_obj
->sys_buffer
);
681 intel_obj
->sys_buffer
= NULL
;
683 return GL_RELEASED_APPLE
;
685 /* XXX Create the buffer and madvise(MADV_DONTNEED)? */
686 struct intel_context
*intel
= intel_context(ctx
);
687 drm_intel_bo
*bo
= intel_bufferobj_buffer(intel
, intel_obj
);
689 return intel_buffer_purgeable(bo
);
694 intel_texture_object_purgeable(struct gl_context
* ctx
,
695 struct gl_texture_object
*obj
,
698 struct intel_texture_object
*intel
;
703 intel
= intel_texture_object(obj
);
704 if (intel
->mt
== NULL
|| intel
->mt
->region
== NULL
)
705 return GL_RELEASED_APPLE
;
707 return intel_buffer_purgeable(intel
->mt
->region
->bo
);
711 intel_render_object_purgeable(struct gl_context
* ctx
,
712 struct gl_renderbuffer
*obj
,
715 struct intel_renderbuffer
*intel
;
720 intel
= intel_renderbuffer(obj
);
721 if (intel
->mt
== NULL
)
722 return GL_RELEASED_APPLE
;
724 return intel_buffer_purgeable(intel
->mt
->region
->bo
);
728 intel_buffer_unpurgeable(drm_intel_bo
*buffer
)
734 retained
= drm_intel_bo_madvise (buffer
, I915_MADV_WILLNEED
);
736 return retained
? GL_RETAINED_APPLE
: GL_UNDEFINED_APPLE
;
740 intel_buffer_object_unpurgeable(struct gl_context
* ctx
,
741 struct gl_buffer_object
*obj
,
747 return intel_buffer_unpurgeable(intel_buffer_object (obj
)->buffer
);
751 intel_texture_object_unpurgeable(struct gl_context
* ctx
,
752 struct gl_texture_object
*obj
,
755 struct intel_texture_object
*intel
;
760 intel
= intel_texture_object(obj
);
761 if (intel
->mt
== NULL
|| intel
->mt
->region
== NULL
)
762 return GL_UNDEFINED_APPLE
;
764 return intel_buffer_unpurgeable(intel
->mt
->region
->bo
);
768 intel_render_object_unpurgeable(struct gl_context
* ctx
,
769 struct gl_renderbuffer
*obj
,
772 struct intel_renderbuffer
*intel
;
777 intel
= intel_renderbuffer(obj
);
778 if (intel
->mt
== NULL
)
779 return GL_UNDEFINED_APPLE
;
781 return intel_buffer_unpurgeable(intel
->mt
->region
->bo
);
785 intelInitBufferObjectFuncs(struct dd_function_table
*functions
)
787 functions
->NewBufferObject
= intel_bufferobj_alloc
;
788 functions
->DeleteBuffer
= intel_bufferobj_free
;
789 functions
->BufferData
= intel_bufferobj_data
;
790 functions
->BufferSubData
= intel_bufferobj_subdata
;
791 functions
->GetBufferSubData
= intel_bufferobj_get_subdata
;
792 functions
->MapBufferRange
= intel_bufferobj_map_range
;
793 functions
->FlushMappedBufferRange
= intel_bufferobj_flush_mapped_range
;
794 functions
->UnmapBuffer
= intel_bufferobj_unmap
;
795 functions
->CopyBufferSubData
= intel_bufferobj_copy_subdata
;
797 functions
->BufferObjectPurgeable
= intel_buffer_object_purgeable
;
798 functions
->TextureObjectPurgeable
= intel_texture_object_purgeable
;
799 functions
->RenderObjectPurgeable
= intel_render_object_purgeable
;
801 functions
->BufferObjectUnpurgeable
= intel_buffer_object_unpurgeable
;
802 functions
->TextureObjectUnpurgeable
= intel_texture_object_unpurgeable
;
803 functions
->RenderObjectUnpurgeable
= intel_render_object_unpurgeable
;