i965/vec4: Make with_writemask() non-static.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_object_purgeable.c
1 /*
2 * Copyright © 2010 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 /**
25 * @file brw_object_purgeable.c
26 *
27 * The driver implementation of the GL_APPLE_object_purgeable extension.
28 */
29
30 #include "main/imports.h"
31 #include "main/mtypes.h"
32 #include "main/macros.h"
33 #include "main/bufferobj.h"
34
35 #include "brw_context.h"
36 #include "intel_buffer_objects.h"
37 #include "intel_fbo.h"
38 #include "intel_mipmap_tree.h"
39
40 static GLenum
41 intel_buffer_purgeable(drm_intel_bo *buffer)
42 {
43 int retained = 0;
44
45 if (buffer != NULL)
46 retained = drm_intel_bo_madvise(buffer, I915_MADV_DONTNEED);
47
48 return retained ? GL_VOLATILE_APPLE : GL_RELEASED_APPLE;
49 }
50
51 static GLenum
52 intel_buffer_object_purgeable(struct gl_context * ctx,
53 struct gl_buffer_object *obj,
54 GLenum option)
55 {
56 struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
57
58 if (intel_obj->buffer != NULL)
59 return intel_buffer_purgeable(intel_obj->buffer);
60
61 if (option == GL_RELEASED_APPLE) {
62 return GL_RELEASED_APPLE;
63 } else {
64 /* XXX Create the buffer and madvise(MADV_DONTNEED)? */
65 struct brw_context *brw = brw_context(ctx);
66 drm_intel_bo *bo = intel_bufferobj_buffer(brw, intel_obj, INTEL_READ);
67
68 return intel_buffer_purgeable(bo);
69 }
70 }
71
72 static GLenum
73 intel_texture_object_purgeable(struct gl_context * ctx,
74 struct gl_texture_object *obj,
75 GLenum option)
76 {
77 struct intel_texture_object *intel;
78
79 (void) ctx;
80 (void) option;
81
82 intel = intel_texture_object(obj);
83 if (intel->mt == NULL || intel->mt->region == NULL)
84 return GL_RELEASED_APPLE;
85
86 return intel_buffer_purgeable(intel->mt->region->bo);
87 }
88
89 static GLenum
90 intel_render_object_purgeable(struct gl_context * ctx,
91 struct gl_renderbuffer *obj,
92 GLenum option)
93 {
94 struct intel_renderbuffer *intel;
95
96 (void) ctx;
97 (void) option;
98
99 intel = intel_renderbuffer(obj);
100 if (intel->mt == NULL)
101 return GL_RELEASED_APPLE;
102
103 return intel_buffer_purgeable(intel->mt->region->bo);
104 }
105
106 static GLenum
107 intel_buffer_unpurgeable(drm_intel_bo *buffer)
108 {
109 int retained;
110
111 retained = 0;
112 if (buffer != NULL)
113 retained = drm_intel_bo_madvise(buffer, I915_MADV_WILLNEED);
114
115 return retained ? GL_RETAINED_APPLE : GL_UNDEFINED_APPLE;
116 }
117
118 static GLenum
119 intel_buffer_object_unpurgeable(struct gl_context * ctx,
120 struct gl_buffer_object *obj,
121 GLenum option)
122 {
123 (void) ctx;
124 (void) option;
125
126 return intel_buffer_unpurgeable(intel_buffer_object(obj)->buffer);
127 }
128
129 static GLenum
130 intel_texture_object_unpurgeable(struct gl_context * ctx,
131 struct gl_texture_object *obj,
132 GLenum option)
133 {
134 struct intel_texture_object *intel;
135
136 (void) ctx;
137 (void) option;
138
139 intel = intel_texture_object(obj);
140 if (intel->mt == NULL || intel->mt->region == NULL)
141 return GL_UNDEFINED_APPLE;
142
143 return intel_buffer_unpurgeable(intel->mt->region->bo);
144 }
145
146 static GLenum
147 intel_render_object_unpurgeable(struct gl_context * ctx,
148 struct gl_renderbuffer *obj,
149 GLenum option)
150 {
151 struct intel_renderbuffer *intel;
152
153 (void) ctx;
154 (void) option;
155
156 intel = intel_renderbuffer(obj);
157 if (intel->mt == NULL)
158 return GL_UNDEFINED_APPLE;
159
160 return intel_buffer_unpurgeable(intel->mt->region->bo);
161 }
162
163 void
164 brw_init_object_purgeable_functions(struct dd_function_table *functions)
165 {
166 functions->BufferObjectPurgeable = intel_buffer_object_purgeable;
167 functions->TextureObjectPurgeable = intel_texture_object_purgeable;
168 functions->RenderObjectPurgeable = intel_render_object_purgeable;
169
170 functions->BufferObjectUnpurgeable = intel_buffer_object_unpurgeable;
171 functions->TextureObjectUnpurgeable = intel_texture_object_unpurgeable;
172 functions->RenderObjectUnpurgeable = intel_render_object_unpurgeable;
173 }