1 /**************************************************************************
3 * Copyright 2006 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 **************************************************************************/
28 /* Provide additional functionality on top of bufmgr buffers:
29 * - 2d semantics and blit operations
30 * - refcounting of buffers for multiple images in a buffer.
31 * - refcounting of buffer mappings.
32 * - some logic for moving the buffers to the best memory pools for
35 * Most of this is to make it easier to implement the fixed-layout
36 * mipmap tree required by intel hardware in the face of GL's
37 * programming interface where each image can be specifed in random
38 * order and it isn't clear what layout the tree should have until the
42 #include "intel_context.h"
43 #include "intel_regions.h"
44 #include "intel_blit.h"
48 /* XXX: Thread safety?
50 GLubyte
*intel_region_map(struct intel_context
*intel
, struct intel_region
*region
)
52 DBG("%s\n", __FUNCTION__
);
53 if (!region
->map_refcount
++) {
54 region
->map
= bmMapBuffer(intel
, region
->buffer
, 0);
56 region
->map_refcount
--;
62 void intel_region_unmap(struct intel_context
*intel
,
63 struct intel_region
*region
)
65 DBG("%s\n", __FUNCTION__
);
66 if (!--region
->map_refcount
) {
67 bmUnmapBufferAUB(intel
, region
->buffer
, 0, 0);
72 struct intel_region
*intel_region_alloc( struct intel_context
*intel
,
77 struct intel_region
*region
= calloc(sizeof(*region
), 1);
79 DBG("%s %dx%dx%d == 0x%x bytes\n", __FUNCTION__
,
80 cpp
, pitch
, height
, cpp
*pitch
*height
);
83 region
->pitch
= pitch
;
84 region
->height
= height
; /* needed? */
87 bmGenBuffers(intel
, "tex", 1, ®ion
->buffer
, 6);
88 bmBufferData(intel
, region
->buffer
, pitch
* cpp
* height
, NULL
, 0);
93 void intel_region_reference( struct intel_region
**dst
,
94 struct intel_region
*src
)
101 void intel_region_release( struct intel_context
*intel
,
102 struct intel_region
**region
)
107 DBG("%s %d\n", __FUNCTION__
, (*region
)->refcount
-1);
109 if (--(*region
)->refcount
== 0) {
110 assert((*region
)->map_refcount
== 0);
111 bmDeleteBuffers(intel
, 1, &(*region
)->buffer
);
118 struct intel_region
*intel_region_create_static( struct intel_context
*intel
,
128 struct intel_region
*region
= calloc(sizeof(*region
), 1);
131 DBG("%s\n", __FUNCTION__
);
134 region
->pitch
= pitch
;
135 region
->height
= height
; /* needed? */
136 region
->refcount
= 1;
137 region
->tiled
= tiled
;
139 /* Recipe for creating a static buffer - create a static pool with
140 * the right offset and size, generate a buffer and use a special
141 * call to bind it to all of the memory in that pool.
143 pool
= bmInitPool(intel
, offset
, virtual, size
,
149 _mesa_printf("bmInitPool failed for static region\n");
153 region
->buffer
= bmGenBufferStatic(intel
, pool
);
161 void _mesa_copy_rect( GLubyte
*dst
,
179 dst
+= dst_y
* dst_pitch
;
180 src
+= src_y
* dst_pitch
;
183 if (width
== dst_pitch
&&
185 do_memcpy(dst
, src
, height
* width
);
187 for (i
= 0; i
< height
; i
++) {
188 do_memcpy(dst
, src
, width
);
196 /* Upload data to a rectangular sub-region. Lots of choices how to do this:
198 * - memcpy by span to current destination
199 * - upload data as new buffer and blit
201 * Currently always memcpy.
203 GLboolean
intel_region_data(struct intel_context
*intel
,
204 struct intel_region
*dst
,
206 GLuint dstx
, GLuint dsty
,
207 const void *src
, GLuint src_pitch
,
208 GLuint srcx
, GLuint srcy
,
209 GLuint width
, GLuint height
)
211 DBG("%s\n", __FUNCTION__
);
213 if (width
== dst
->pitch
&&
214 width
== src_pitch
&&
216 height
== dst
->height
&&
220 return (bmBufferDataAUB(intel
,
222 dst
->cpp
* width
* dst
->height
,
226 GLubyte
*map
= intel_region_map(intel
, dst
);
229 assert (dst_offset
+ dstx
+ width
+
230 (dsty
+ height
- 1) * dst
->pitch
* dst
->cpp
<=
231 dst
->pitch
* dst
->cpp
* dst
->height
);
233 _mesa_copy_rect(map
+ dst_offset
,
242 intel_region_unmap(intel
, dst
);
250 /* Copy rectangular sub-regions. Need better logic about when to
251 * push buffers into AGP - will currently do so whenever possible.
253 void intel_region_copy( struct intel_context
*intel
,
254 struct intel_region
*dst
,
256 GLuint dstx
, GLuint dsty
,
257 struct intel_region
*src
,
259 GLuint srcx
, GLuint srcy
,
260 GLuint width
, GLuint height
)
262 DBG("%s\n", __FUNCTION__
);
264 assert(src
->cpp
== dst
->cpp
);
266 intelEmitCopyBlit(intel
,
268 src
->pitch
, src
->buffer
, src_offset
, src
->tiled
,
269 dst
->pitch
, dst
->buffer
, dst_offset
, dst
->tiled
,
276 /* Fill a rectangular sub-region. Need better logic about when to
277 * push buffers into AGP - will currently do so whenever possible.
279 void intel_region_fill( struct intel_context
*intel
,
280 struct intel_region
*dst
,
282 GLuint dstx
, GLuint dsty
,
283 GLuint width
, GLuint height
,
286 DBG("%s\n", __FUNCTION__
);
288 intelEmitFillBlit(intel
,
290 dst
->pitch
, dst
->buffer
, dst_offset
, dst
->tiled
,