Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / drivers / i965 / brw_screen.h
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #ifndef BRW_SCREEN_H
29 #define BRW_SCREEN_H
30
31 #include "pipe/p_state.h"
32 #include "pipe/p_screen.h"
33
34 #include "brw_reg.h"
35 #include "brw_structs.h"
36
37 struct brw_winsys_screen;
38
39
40 /**
41 * Subclass of pipe_screen
42 */
43 struct brw_screen
44 {
45 struct pipe_screen base;
46 struct brw_chipset chipset;
47 struct brw_winsys_screen *sws;
48 boolean no_tiling;
49 };
50
51 /**
52 * Subclass of pipe_transfer
53 */
54 struct brw_transfer
55 {
56 struct pipe_transfer base;
57
58 unsigned offset;
59 };
60
61 struct brw_buffer
62 {
63 struct pipe_buffer base;
64
65 /* One of either bo or user_buffer will be non-null, depending on
66 * whether this is a hardware or user buffer.
67 */
68 struct brw_winsys_buffer *bo;
69 void *user_buffer;
70
71 /* Mapped pointer??
72 */
73 void *ptr;
74 };
75
76
77 union brw_surface_id {
78 struct {
79 unsigned face:3;
80 unsigned zslice:13;
81 unsigned level:16;
82 } bits;
83 unsigned value;
84 };
85
86
87 struct brw_surface
88 {
89 struct pipe_surface base;
90
91 union brw_surface_id id;
92 unsigned cpp;
93 unsigned pitch;
94 unsigned draw_offset;
95 unsigned tiling;
96
97 struct brw_surface_state ss;
98 struct brw_winsys_buffer *bo;
99 struct brw_surface *next, *prev;
100 };
101
102
103
104 struct brw_texture
105 {
106 struct pipe_texture base;
107 struct brw_winsys_buffer *bo;
108 struct brw_surface_state ss;
109
110 unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS];
111 unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS];
112 unsigned level_offset[PIPE_MAX_TEXTURE_LEVELS];
113
114 boolean compressed;
115 unsigned brw_target;
116 unsigned pitch;
117 unsigned tiling;
118 unsigned cpp;
119 unsigned total_height;
120
121 struct brw_surface views[2];
122 };
123
124
125
126 /*
127 * Cast wrappers
128 */
129 static INLINE struct brw_screen *
130 brw_screen(struct pipe_screen *pscreen)
131 {
132 return (struct brw_screen *) pscreen;
133 }
134
135 static INLINE struct brw_transfer *
136 brw_transfer(struct pipe_transfer *transfer)
137 {
138 return (struct brw_transfer *)transfer;
139 }
140
141 static INLINE struct brw_surface *
142 brw_surface(struct pipe_surface *surface)
143 {
144 return (struct brw_surface *)surface;
145 }
146
147 static INLINE struct brw_buffer *
148 brw_buffer(struct pipe_buffer *buffer)
149 {
150 return (struct brw_buffer *)buffer;
151 }
152
153 static INLINE struct brw_texture *
154 brw_texture(struct pipe_texture *texture)
155 {
156 return (struct brw_texture *)texture;
157 }
158
159
160 /* Pipe buffer helpers
161 */
162 static INLINE boolean
163 brw_buffer_is_user_buffer( const struct pipe_buffer *buf )
164 {
165 return ((const struct brw_buffer *)buf)->user_buffer != NULL;
166 }
167
168 unsigned
169 brw_surface_pitch( const struct pipe_surface *surface );
170
171 /***********************************************************************
172 * Internal functions
173 */
174 GLboolean brw_texture_layout(struct brw_screen *brw_screen,
175 struct brw_texture *tex );
176
177 void brw_update_texture( struct brw_screen *brw_screen,
178 struct brw_texture *tex );
179
180
181 void brw_screen_tex_init( struct brw_screen *brw_screen );
182 void brw_screen_tex_surface_init( struct brw_screen *brw_screen );
183
184 void brw_screen_buffer_init(struct brw_screen *brw_screen);
185
186
187 boolean brw_is_texture_referenced_by_bo( struct brw_screen *brw_screen,
188 struct pipe_texture *texture,
189 unsigned face,
190 unsigned level,
191 struct brw_winsys_buffer *bo );
192
193 boolean brw_is_buffer_referenced_by_bo( struct brw_screen *brw_screen,
194 struct pipe_buffer *buffer,
195 struct brw_winsys_buffer *bo );
196
197
198
199 #endif /* BRW_SCREEN_H */