2 * Copyright © 2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * @file brw_object_purgeable.c
27 * The driver implementation of the GL_APPLE_object_purgeable extension.
30 #include "main/mtypes.h"
31 #include "main/macros.h"
32 #include "main/bufferobj.h"
34 #include "brw_context.h"
35 #include "intel_buffer_objects.h"
36 #include "intel_fbo.h"
37 #include "intel_mipmap_tree.h"
40 intel_buffer_purgeable(struct brw_bo
*buffer
)
45 retained
= brw_bo_madvise(buffer
, I915_MADV_DONTNEED
);
47 return retained
? GL_VOLATILE_APPLE
: GL_RELEASED_APPLE
;
51 intel_buffer_object_purgeable(struct gl_context
* ctx
,
52 struct gl_buffer_object
*obj
,
55 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
57 if (intel_obj
->buffer
!= NULL
)
58 return intel_buffer_purgeable(intel_obj
->buffer
);
60 if (option
== GL_RELEASED_APPLE
) {
61 return GL_RELEASED_APPLE
;
63 /* XXX Create the buffer and madvise(MADV_DONTNEED)? */
64 return intel_buffer_purgeable(intel_obj
->buffer
);
69 intel_texture_object_purgeable(struct gl_context
* ctx
,
70 struct gl_texture_object
*obj
,
73 struct intel_texture_object
*intel
;
78 intel
= intel_texture_object(obj
);
79 if (intel
->mt
== NULL
|| intel
->mt
->bo
== NULL
)
80 return GL_RELEASED_APPLE
;
82 return intel_buffer_purgeable(intel
->mt
->bo
);
86 intel_render_object_purgeable(struct gl_context
* ctx
,
87 struct gl_renderbuffer
*obj
,
90 struct intel_renderbuffer
*intel
;
95 intel
= intel_renderbuffer(obj
);
96 if (intel
->mt
== NULL
)
97 return GL_RELEASED_APPLE
;
99 return intel_buffer_purgeable(intel
->mt
->bo
);
103 intel_bo_unpurgeable(struct brw_bo
*buffer
)
109 retained
= brw_bo_madvise(buffer
, I915_MADV_WILLNEED
);
115 intel_buffer_object_unpurgeable(struct gl_context
* ctx
,
116 struct gl_buffer_object
*obj
,
119 struct intel_buffer_object
*intel
= intel_buffer_object(obj
);
124 return GL_UNDEFINED_APPLE
;
126 if (option
== GL_UNDEFINED_APPLE
|| !intel_bo_unpurgeable(intel
->buffer
)) {
127 brw_bo_unreference(intel
->buffer
);
128 intel
->buffer
= NULL
;
129 return GL_UNDEFINED_APPLE
;
132 return GL_RETAINED_APPLE
;
136 intel_texture_object_unpurgeable(struct gl_context
* ctx
,
137 struct gl_texture_object
*obj
,
140 struct intel_texture_object
*intel
;
144 intel
= intel_texture_object(obj
);
145 if (intel
->mt
== NULL
|| intel
->mt
->bo
== NULL
)
146 return GL_UNDEFINED_APPLE
;
148 if (option
== GL_UNDEFINED_APPLE
|| !intel_bo_unpurgeable(intel
->mt
->bo
)) {
149 intel_miptree_release(&intel
->mt
);
150 return GL_UNDEFINED_APPLE
;
153 return GL_RETAINED_APPLE
;
157 intel_render_object_unpurgeable(struct gl_context
* ctx
,
158 struct gl_renderbuffer
*obj
,
161 struct intel_renderbuffer
*intel
;
165 intel
= intel_renderbuffer(obj
);
166 if (intel
->mt
== NULL
)
167 return GL_UNDEFINED_APPLE
;
169 if (option
== GL_UNDEFINED_APPLE
|| !intel_bo_unpurgeable(intel
->mt
->bo
)) {
170 intel_miptree_release(&intel
->mt
);
171 return GL_UNDEFINED_APPLE
;
174 return GL_RETAINED_APPLE
;
178 brw_init_object_purgeable_functions(struct dd_function_table
*functions
)
180 functions
->BufferObjectPurgeable
= intel_buffer_object_purgeable
;
181 functions
->TextureObjectPurgeable
= intel_texture_object_purgeable
;
182 functions
->RenderObjectPurgeable
= intel_render_object_purgeable
;
184 functions
->BufferObjectUnpurgeable
= intel_buffer_object_unpurgeable
;
185 functions
->TextureObjectUnpurgeable
= intel_texture_object_unpurgeable
;
186 functions
->RenderObjectUnpurgeable
= intel_render_object_unpurgeable
;