aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/winsys/xlib/xlib_brw_context.c
blob: 09599507f440cda1ca5c8db8b9c751e2198268d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**************************************************************************
 * 
 * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA
 * All Rights Reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 * 
 * 
 **************************************************************************/

/*
 * Authors:
 *   Keith Whitwell
 *   Brian Paul
 */


//#include "glxheader.h"
//#include "xmesaP.h"

#include "pipe/internal/p_winsys_screen.h"
#include "pipe/p_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "i965simple/brw_winsys.h"
#include "xlib_brw_aub.h"
#include "xlib_brw.h"




#define XBCWS_BATCHBUFFER_SIZE 1024


/* The backend to the brw driver (ie struct brw_winsys) is actually a
 * per-context entity.
 */
struct xlib_brw_context_winsys {
   struct brw_winsys brw_context_winsys;   /**< batch buffer funcs */
   struct aub_context *aub;
                         
   struct pipe_winsys *pipe_winsys;

   unsigned batch_data[XBCWS_BATCHBUFFER_SIZE];
   unsigned batch_nr;
   unsigned batch_size;
   unsigned batch_alloc;
};


/* Turn a brw_winsys into an xlib_brw_context_winsys:
 */
static inline struct xlib_brw_context_winsys *
xlib_brw_context_winsys( struct brw_winsys *sws )
{
   return (struct xlib_brw_context_winsys *)sws;
}


/* Simple batchbuffer interface:
 */

static unsigned *xbcws_batch_start( struct brw_winsys *sws,
					 unsigned dwords,
					 unsigned relocs )
{
   struct xlib_brw_context_winsys *xbcws = xlib_brw_context_winsys(sws);

   if (xbcws->batch_size < xbcws->batch_nr + dwords)
      return NULL;

   xbcws->batch_alloc = xbcws->batch_nr + dwords;
   return (void *)1;			/* not a valid pointer! */
}

static void xbcws_batch_dword( struct brw_winsys *sws,
				    unsigned dword )
{
   struct xlib_brw_context_winsys *xbcws = xlib_brw_context_winsys(sws);

   assert(xbcws->batch_nr < xbcws->batch_alloc);
   xbcws->batch_data[xbcws->batch_nr++] = dword;
}

static void xbcws_batch_reloc( struct brw_winsys *sws,
			     struct pipe_buffer *buf,
			     unsigned access_flags,
			     unsigned delta )
{
   struct xlib_brw_context_winsys *xbcws = xlib_brw_context_winsys(sws);

   assert(xbcws->batch_nr < xbcws->batch_alloc);
   xbcws->batch_data[xbcws->batch_nr++] = 
      ( xlib_brw_get_buffer_offset( NULL, buf, access_flags ) +
        delta );
}

static void xbcws_batch_end( struct brw_winsys *sws )
{
   struct xlib_brw_context_winsys *xbcws = xlib_brw_context_winsys(sws);

   assert(xbcws->batch_nr <= xbcws->batch_alloc);
   xbcws->batch_alloc = 0;
}

static void xbcws_batch_flush( struct brw_winsys *sws,
				    struct pipe_fence_handle **fence )
{
   struct xlib_brw_context_winsys *xbcws = xlib_brw_context_winsys(sws);
   assert(xbcws->batch_nr <= xbcws->batch_size);

   if (xbcws->batch_nr) {
      xlib_brw_commands_aub( xbcws->pipe_winsys,
                             xbcws->batch_data,
                             xbcws->batch_nr );
   }

   xbcws->batch_nr = 0;
}

  

/* Really a per-device function, just pass through:
 */
static unsigned xbcws_get_buffer_offset( struct brw_winsys *sws,
                                         struct pipe_buffer *buf,
                                         unsigned access_flags )
{
   struct xlib_brw_context_winsys *xbcws = xlib_brw_context_winsys(sws);

   return xlib_brw_get_buffer_offset( xbcws->pipe_winsys,
                                      buf,
                                      access_flags );
}


/* Really a per-device function, just pass through:
 */
static void xbcws_buffer_subdata_typed( struct brw_winsys *sws,
                                       struct pipe_buffer *buf,
                                       unsigned long offset, 
                                       unsigned long size, 
                                       const void *data,
                                       unsigned data_type )
{
   struct xlib_brw_context_winsys *xbcws = xlib_brw_context_winsys(sws);

   xlib_brw_buffer_subdata_typed( xbcws->pipe_winsys,
                                  buf,
                                  offset,
                                  size,
                                  data,
                                  data_type );
}


/**
 * Create i965 hardware rendering context, but plugged into a
 * dump-to-aubfile backend.
 */
struct pipe_context *
xlib_create_brw_context( struct pipe_screen *screen,
                         void *unused )
{
   struct xlib_brw_context_winsys *xbcws = CALLOC_STRUCT( xlib_brw_context_winsys );
   
   /* Fill in this struct with callbacks that i965simple will need to
    * communicate with the window system, buffer manager, etc. 
    */
   xbcws->brw_context_winsys.batch_start = xbcws_batch_start;
   xbcws->brw_context_winsys.batch_dword = xbcws_batch_dword;
   xbcws->brw_context_winsys.batch_reloc = xbcws_batch_reloc;
   xbcws->brw_context_winsys.batch_end = xbcws_batch_end;
   xbcws->brw_context_winsys.batch_flush = xbcws_batch_flush;
   xbcws->brw_context_winsys.buffer_subdata_typed = xbcws_buffer_subdata_typed;
   xbcws->brw_context_winsys.get_buffer_offset = xbcws_get_buffer_offset;

   xbcws->pipe_winsys = screen->winsys; /* redundant */

   xbcws->batch_size = XBCWS_BATCHBUFFER_SIZE;

   /* Create the i965simple context:
    */
#ifdef GALLIUM_CELL
   return NULL;
#else
   return brw_create( screen,
		      &xbcws->brw_context_winsys,
		      0 );
#endif
}