Merge branch '7.8'
[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 #define BRW_MAX_TEXTURE_2D_LEVELS 11 /* max 1024x1024 */
104 #define BRW_MAX_TEXTURE_3D_LEVELS 8 /* max 128x128x128 */
105
106
107 struct brw_texture
108 {
109 struct pipe_texture base;
110 struct brw_winsys_buffer *bo;
111 struct brw_surface_state ss;
112
113 unsigned *image_offset[BRW_MAX_TEXTURE_2D_LEVELS];
114 unsigned nr_images[BRW_MAX_TEXTURE_2D_LEVELS];
115 unsigned level_offset[BRW_MAX_TEXTURE_2D_LEVELS];
116
117 boolean compressed;
118 unsigned brw_target;
119 unsigned pitch;
120 unsigned tiling;
121 unsigned cpp;
122 unsigned total_height;
123
124 struct brw_surface views[2];
125 };
126
127
128
129 /*
130 * Cast wrappers
131 */
132 static INLINE struct brw_screen *
133 brw_screen(struct pipe_screen *pscreen)
134 {
135 return (struct brw_screen *) pscreen;
136 }
137
138 static INLINE struct brw_transfer *
139 brw_transfer(struct pipe_transfer *transfer)
140 {
141 return (struct brw_transfer *)transfer;
142 }
143
144 static INLINE struct brw_surface *
145 brw_surface(struct pipe_surface *surface)
146 {
147 return (struct brw_surface *)surface;
148 }
149
150 static INLINE struct brw_buffer *
151 brw_buffer(struct pipe_buffer *buffer)
152 {
153 return (struct brw_buffer *)buffer;
154 }
155
156 static INLINE struct brw_texture *
157 brw_texture(struct pipe_texture *texture)
158 {
159 return (struct brw_texture *)texture;
160 }
161
162
163 /* Pipe buffer helpers
164 */
165 static INLINE boolean
166 brw_buffer_is_user_buffer( const struct pipe_buffer *buf )
167 {
168 return ((const struct brw_buffer *)buf)->user_buffer != NULL;
169 }
170
171 unsigned
172 brw_surface_pitch( const struct pipe_surface *surface );
173
174 /***********************************************************************
175 * Internal functions
176 */
177 GLboolean brw_texture_layout(struct brw_screen *brw_screen,
178 struct brw_texture *tex );
179
180 void brw_update_texture( struct brw_screen *brw_screen,
181 struct brw_texture *tex );
182
183
184 /* brw_screen_texture.h
185 */
186 struct brw_context;
187 void brw_tex_init( struct brw_context *brw );
188 void brw_screen_tex_init( struct brw_screen *brw_screen );
189 void brw_screen_tex_surface_init( struct brw_screen *brw_screen );
190
191 void brw_screen_buffer_init(struct brw_screen *brw_screen);
192
193
194 boolean brw_is_texture_referenced_by_bo( struct brw_screen *brw_screen,
195 struct pipe_texture *texture,
196 unsigned face,
197 unsigned level,
198 struct brw_winsys_buffer *bo );
199
200 boolean brw_is_buffer_referenced_by_bo( struct brw_screen *brw_screen,
201 struct pipe_buffer *buffer,
202 struct brw_winsys_buffer *bo );
203
204
205
206 #endif /* BRW_SCREEN_H */