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 "glxheader.h" */
37 /* #include "xmesaP.h" */
39 #include "util/u_simple_screen.h"
40 #include "util/u_inlines.h"
41 #include "util/u_math.h"
42 #include "util/u_memory.h"
43 #include "i965simple/brw_winsys.h"
44 #include "xlib_brw_aub.h"
50 #define XBCWS_BATCHBUFFER_SIZE 1024
53 /* The backend to the brw driver (ie struct brw_winsys) is actually a
56 struct xlib_brw_context_winsys
{
57 struct brw_winsys brw_context_winsys
; /**< batch buffer funcs */
58 struct aub_context
*aub
;
60 struct pipe_winsys
*pipe_winsys
;
62 unsigned batch_data
[XBCWS_BATCHBUFFER_SIZE
];
69 /* Turn a brw_winsys into an xlib_brw_context_winsys:
71 static inline struct xlib_brw_context_winsys
*
72 xlib_brw_context_winsys( struct brw_winsys
*sws
)
74 return (struct xlib_brw_context_winsys
*)sws
;
78 /* Simple batchbuffer interface:
81 static unsigned *xbcws_batch_start( struct brw_winsys
*sws
,
85 struct xlib_brw_context_winsys
*xbcws
= xlib_brw_context_winsys(sws
);
87 if (xbcws
->batch_size
< xbcws
->batch_nr
+ dwords
)
90 xbcws
->batch_alloc
= xbcws
->batch_nr
+ dwords
;
91 return (void *)1; /* not a valid pointer! */
94 static void xbcws_batch_dword( struct brw_winsys
*sws
,
97 struct xlib_brw_context_winsys
*xbcws
= xlib_brw_context_winsys(sws
);
99 assert(xbcws
->batch_nr
< xbcws
->batch_alloc
);
100 xbcws
->batch_data
[xbcws
->batch_nr
++] = dword
;
103 static void xbcws_batch_reloc( struct brw_winsys
*sws
,
104 struct pipe_buffer
*buf
,
105 unsigned access_flags
,
108 struct xlib_brw_context_winsys
*xbcws
= xlib_brw_context_winsys(sws
);
110 assert(xbcws
->batch_nr
< xbcws
->batch_alloc
);
111 xbcws
->batch_data
[xbcws
->batch_nr
++] =
112 ( xlib_brw_get_buffer_offset( NULL
, buf
, access_flags
) +
116 static void xbcws_batch_end( struct brw_winsys
*sws
)
118 struct xlib_brw_context_winsys
*xbcws
= xlib_brw_context_winsys(sws
);
120 assert(xbcws
->batch_nr
<= xbcws
->batch_alloc
);
121 xbcws
->batch_alloc
= 0;
124 static void xbcws_batch_flush( struct brw_winsys
*sws
,
125 struct pipe_fence_handle
**fence
)
127 struct xlib_brw_context_winsys
*xbcws
= xlib_brw_context_winsys(sws
);
128 assert(xbcws
->batch_nr
<= xbcws
->batch_size
);
130 if (xbcws
->batch_nr
) {
131 xlib_brw_commands_aub( xbcws
->pipe_winsys
,
141 /* Really a per-device function, just pass through:
143 static unsigned xbcws_get_buffer_offset( struct brw_winsys
*sws
,
144 struct pipe_buffer
*buf
,
145 unsigned access_flags
)
147 struct xlib_brw_context_winsys
*xbcws
= xlib_brw_context_winsys(sws
);
149 return xlib_brw_get_buffer_offset( xbcws
->pipe_winsys
,
155 /* Really a per-device function, just pass through:
157 static void xbcws_buffer_subdata_typed( struct brw_winsys
*sws
,
158 struct pipe_buffer
*buf
,
159 unsigned long offset
,
164 struct xlib_brw_context_winsys
*xbcws
= xlib_brw_context_winsys(sws
);
166 xlib_brw_buffer_subdata_typed( xbcws
->pipe_winsys
,
176 * Create i965 hardware rendering context, but plugged into a
177 * dump-to-aubfile backend.
179 struct pipe_context
*
180 xlib_create_brw_context( struct pipe_screen
*screen
,
183 struct xlib_brw_context_winsys
*xbcws
= CALLOC_STRUCT( xlib_brw_context_winsys
);
185 /* Fill in this struct with callbacks that i965simple will need to
186 * communicate with the window system, buffer manager, etc.
188 xbcws
->brw_context_winsys
.batch_start
= xbcws_batch_start
;
189 xbcws
->brw_context_winsys
.batch_dword
= xbcws_batch_dword
;
190 xbcws
->brw_context_winsys
.batch_reloc
= xbcws_batch_reloc
;
191 xbcws
->brw_context_winsys
.batch_end
= xbcws_batch_end
;
192 xbcws
->brw_context_winsys
.batch_flush
= xbcws_batch_flush
;
193 xbcws
->brw_context_winsys
.buffer_subdata_typed
= xbcws_buffer_subdata_typed
;
194 xbcws
->brw_context_winsys
.get_buffer_offset
= xbcws_get_buffer_offset
;
196 xbcws
->pipe_winsys
= screen
->winsys
; /* redundant */
198 xbcws
->batch_size
= XBCWS_BATCHBUFFER_SIZE
;
200 /* Create the i965simple context:
205 return brw_create( screen
,
206 &xbcws
->brw_context_winsys
,