i965g: add missing buffer functions
[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 };
49
50 /**
51 * Subclass of pipe_transfer
52 */
53 struct brw_transfer
54 {
55 struct pipe_transfer base;
56
57 unsigned offset;
58 };
59
60 struct brw_buffer
61 {
62 struct pipe_buffer base;
63
64 /* One of either bo or user_buffer will be non-null, depending on
65 * whether this is a hardware or user buffer.
66 */
67 struct brw_winsys_buffer *bo;
68 void *user_buffer;
69
70 /* Mapped pointer??
71 */
72 void *ptr;
73 };
74
75 #define BRW_TILING_NONE 0
76 #define BRW_TILING_Y 1
77 #define BRW_TILING_X 2
78
79 union brw_surface_id {
80 struct {
81 unsigned face:3;
82 unsigned zslice:13;
83 unsigned level:16;
84 } bits;
85 unsigned value;
86 };
87
88
89 struct brw_surface
90 {
91 struct pipe_surface base;
92 union brw_surface_id id;
93 struct brw_surface_state ss;
94 struct brw_winsys_buffer *bo;
95 struct brw_surface *next, *prev;
96 };
97
98
99
100 struct brw_texture
101 {
102 struct pipe_texture base;
103 struct brw_winsys_buffer *bo;
104 struct brw_surface_state ss;
105
106 unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS];
107 unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS];
108 unsigned level_offset[PIPE_MAX_TEXTURE_LEVELS];
109
110 boolean compressed;
111 unsigned brw_target;
112 unsigned pitch;
113 unsigned tiling;
114 unsigned cpp;
115 unsigned total_height;
116
117 struct brw_surface views[2];
118 };
119
120
121
122 /*
123 * Cast wrappers
124 */
125 static INLINE struct brw_screen *
126 brw_screen(struct pipe_screen *pscreen)
127 {
128 return (struct brw_screen *) pscreen;
129 }
130
131 static INLINE struct brw_transfer *
132 brw_transfer(struct pipe_transfer *transfer)
133 {
134 return (struct brw_transfer *)transfer;
135 }
136
137 static INLINE struct brw_surface *
138 brw_surface(struct pipe_surface *surface)
139 {
140 return (struct brw_surface *)surface;
141 }
142
143 static INLINE struct brw_buffer *
144 brw_buffer(struct pipe_buffer *buffer)
145 {
146 return (struct brw_buffer *)buffer;
147 }
148
149 static INLINE struct brw_texture *
150 brw_texture(struct pipe_texture *texture)
151 {
152 return (struct brw_texture *)texture;
153 }
154
155
156 /* Pipe buffer helpers
157 */
158 static INLINE boolean
159 brw_buffer_is_user_buffer( const struct pipe_buffer *buf )
160 {
161 return ((const struct brw_buffer *)buf)->user_buffer != NULL;
162 }
163
164 struct brw_winsys_buffer *
165 brw_surface_bo( struct pipe_surface *surface );
166
167 unsigned
168 brw_surface_pitch( const struct pipe_surface *surface );
169
170 /***********************************************************************
171 * Internal functions
172 */
173 GLboolean brw_texture_layout(struct brw_screen *brw_screen,
174 struct brw_texture *tex );
175
176 void brw_update_texture( struct brw_screen *brw_screen,
177 struct brw_texture *tex );
178
179
180 void brw_screen_tex_init( struct brw_screen *brw_screen );
181 void brw_screen_tex_surface_init( struct brw_screen *brw_screen );
182
183 void brw_screen_buffer_init(struct brw_screen *brw_screen);
184
185
186 #endif /* BRW_SCREEN_H */