1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA
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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
27 **************************************************************************/
36 #include "util/u_memory.h"
37 #include "util/u_math.h"
38 #include "pipe/p_context.h"
40 #include "xm_winsys.h"
42 #include "i965/brw_winsys.h"
43 #include "i965/brw_screen.h"
44 #include "i965/brw_reg.h"
46 #define MAX_VRAM (128*1024*1024)
48 struct xlib_brw_buffer
50 struct brw_winsys_buffer base
;
54 unsigned cheesy_refcount
;
60 * Subclass of brw_winsys_screen for Xlib winsys
62 struct xlib_brw_winsys
64 struct brw_winsys_screen base
;
68 static struct xlib_brw_winsys
*
69 xlib_brw_winsys( struct brw_winsys_screen
*screen
)
71 return (struct xlib_brw_winsys
*)screen
;
75 static struct xlib_brw_buffer
*
76 xlib_brw_buffer( struct brw_winsys_buffer
*buffer
)
78 return (struct xlib_brw_buffer
*)buffer
;
83 const char *names
[BRW_BUFFER_TYPE_MAX
] = {
97 const char *usages
[BRW_USAGE_MAX
] = {
109 static struct brw_winsys_buffer
*
110 xlib_brw_bo_alloc( struct brw_winsys_screen
*sws
,
111 enum brw_buffer_type type
,
115 struct xlib_brw_winsys
*xbw
= xlib_brw_winsys(sws
);
116 struct xlib_brw_buffer
*buf
;
118 debug_printf("%s type %d sz %d align %d\n",
119 __FUNCTION__
, type
, size
, alignment
);
121 buf
= CALLOC_STRUCT(xlib_brw_buffer
);
125 buf
->offset
= align(xbw
->offset
, alignment
);
127 buf
->virtual = MALLOC(size
);
128 buf
->base
.offset
= &buf
->offset
; /* hmm, cheesy */
129 buf
->base
.size
= size
;
131 xbw
->offset
= align(xbw
->offset
, alignment
) + size
;
132 if (xbw
->offset
> MAX_VRAM
)
144 xlib_brw_bo_reference( struct brw_winsys_buffer
*buffer
)
146 struct xlib_brw_buffer
*buf
= xlib_brw_buffer(buffer
);
148 buf
->cheesy_refcount
++;
152 xlib_brw_bo_unreference( struct brw_winsys_buffer
*buffer
)
154 struct xlib_brw_buffer
*buf
= xlib_brw_buffer(buffer
);
156 if (--buf
->cheesy_refcount
== 0) {
162 xlib_brw_bo_emit_reloc( struct brw_winsys_buffer
*buffer
,
163 enum brw_buffer_usage usage
,
166 struct brw_winsys_buffer
*buffer2
)
168 struct xlib_brw_buffer
*buf
= xlib_brw_buffer(buffer
);
169 struct xlib_brw_buffer
*buf2
= xlib_brw_buffer(buffer2
);
171 debug_printf("%s buf %p offset %x val %x + %x buf2 %p/%s/%s\n",
172 __FUNCTION__
, (void *)buffer
, offset
,
174 (void *)buffer2
, names
[buf2
->type
], usages
[usage
]);
176 *(uint32_t *)(buf
->virtual + offset
) = buf2
->offset
+ delta
;
182 xlib_brw_bo_exec( struct brw_winsys_buffer
*buffer
,
183 unsigned bytes_used
)
185 debug_printf("execute buffer %p, bytes %d\n", (void *)buffer
, bytes_used
);
191 xlib_brw_bo_subdata(struct brw_winsys_buffer
*buffer
,
196 struct xlib_brw_buffer
*buf
= xlib_brw_buffer(buffer
);
198 debug_printf("%s buf %p off %d sz %d data %p\n",
200 (void *)buffer
, offset
, size
, data
);
202 memcpy(buf
->virtual + offset
, data
, size
);
208 xlib_brw_bo_is_busy(struct brw_winsys_buffer
*buffer
)
210 debug_printf("%s %p\n", __FUNCTION__
, (void *)buffer
);
215 xlib_brw_bo_references(struct brw_winsys_buffer
*a
,
216 struct brw_winsys_buffer
*b
)
218 debug_printf("%s %p %p\n", __FUNCTION__
, (void *)a
, (void *)b
);
223 xlib_brw_check_aperture_space( struct brw_winsys_screen
*iws
,
224 struct brw_winsys_buffer
**buffers
,
227 unsigned tot_size
= 0;
230 for (i
= 0; i
< count
; i
++)
231 tot_size
+= buffers
[i
]->size
;
233 debug_printf("%s %d bufs, tot_size: %d kb\n",
235 (tot_size
+ 1023) / 1024);
241 xlib_brw_bo_map(struct brw_winsys_buffer
*buffer
,
244 struct xlib_brw_buffer
*buf
= xlib_brw_buffer(buffer
);
246 debug_printf("%s %p %s\n", __FUNCTION__
, (void *)buffer
,
247 write
? "read/write" : "read");
254 xlib_brw_bo_unmap(struct brw_winsys_buffer
*buffer
)
256 struct xlib_brw_buffer
*buf
= xlib_brw_buffer(buffer
);
258 debug_printf("%s %p\n", __FUNCTION__
, (void *)buffer
);
261 assert(buf
->map_count
>= 0);
266 xlib_brw_winsys_destroy( struct brw_winsys_screen
*screen
)
268 /* XXX: free all buffers */
272 static struct brw_winsys_screen
*
273 xlib_create_brw_winsys_screen( void )
275 struct xlib_brw_winsys
*ws
;
277 ws
= CALLOC_STRUCT(xlib_brw_winsys
);
281 ws
->base
.destroy
= xlib_brw_winsys_destroy
;
282 ws
->base
.bo_alloc
= xlib_brw_bo_alloc
;
283 ws
->base
.bo_reference
= xlib_brw_bo_reference
;
284 ws
->base
.bo_unreference
= xlib_brw_bo_unreference
;
285 ws
->base
.bo_emit_reloc
= xlib_brw_bo_emit_reloc
;
286 ws
->base
.bo_exec
= xlib_brw_bo_exec
;
287 ws
->base
.bo_subdata
= xlib_brw_bo_subdata
;
288 ws
->base
.bo_is_busy
= xlib_brw_bo_is_busy
;
289 ws
->base
.bo_references
= xlib_brw_bo_references
;
290 ws
->base
.check_aperture_space
= xlib_brw_check_aperture_space
;
291 ws
->base
.bo_map
= xlib_brw_bo_map
;
292 ws
->base
.bo_unmap
= xlib_brw_bo_unmap
;
298 /***********************************************************************
299 * Implementation of Xlib co-state-tracker's winsys interface
302 static struct pipe_screen
*
303 xlib_create_i965_screen( void )
305 struct brw_winsys_screen
*winsys
;
306 struct pipe_screen
*screen
;
308 winsys
= xlib_create_brw_winsys_screen();
312 screen
= brw_create_screen(winsys
,
321 winsys
->destroy( winsys
);
327 static struct pipe_context
*
328 xlib_create_i965_context( struct pipe_screen
*screen
,
329 void *context_private
)
331 struct pipe_context
*pipe
;
333 pipe
= brw_create_context(screen
);
337 pipe
->priv
= context_private
;
341 /* Free stuff here */
347 xlib_i965_display_surface(struct xmesa_buffer
*xm_buffer
,
348 struct pipe_surface
*surf
)
350 /* struct brw_texture *texture = brw_texture(surf->texture); */
352 debug_printf("%s tex %p, sz %dx%d\n", __FUNCTION__
,
353 (void *)surf
->texture
,
354 surf
->texture
->width
[0],
355 surf
->texture
->height
[0]);
359 struct xm_driver xlib_i965_driver
=
361 .create_pipe_screen
= xlib_create_i965_screen
,
362 .create_pipe_context
= xlib_create_i965_context
,
363 .display_surface
= xlib_i965_display_surface
367 /* Register this driver at library load:
369 static void _init( void ) __attribute__((constructor
));
370 static void _init( void )
372 xmesa_set_driver( &xlib_i965_driver
);
377 /***********************************************************************
379 * Butt-ugly hack to convince the linker not to throw away public GL
380 * symbols (they are all referenced from getprocaddress, I guess).
382 extern void (*linker_foo(const unsigned char *procName
))();
383 extern void (*glXGetProcAddress(const unsigned char *procName
))();
385 extern void (*linker_foo(const unsigned char *procName
))()
387 return glXGetProcAddress(procName
);