r300g: various other cleanups
[mesa.git] / src / gallium / drivers / r300 / r300_winsys.h
1 /*
2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #ifndef R300_WINSYS_H
24 #define R300_WINSYS_H
25
26 /* The public interface header for the r300 pipe driver.
27 * Any winsys hosting this pipe needs to implement r300_winsys and then
28 * call r300_create_screen to start things. */
29
30 #include "pipe/p_defines.h"
31 #include "pipe/p_state.h"
32
33 #include "r300_defines.h"
34
35 struct r300_winsys_buffer;
36
37 enum r300_value_id {
38 R300_VID_PCI_ID,
39 R300_VID_GB_PIPES,
40 R300_VID_Z_PIPES,
41 R300_VID_SQUARE_TILING_SUPPORT,
42 R300_VID_TEX3D_MIP_BUG,
43 };
44
45 struct r300_winsys_screen {
46 void (*destroy)(struct r300_winsys_screen *ws);
47
48 /**
49 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
50 *
51 * Remember that gallium gets to choose the interface it needs, and the
52 * window systems must then implement that interface (rather than the
53 * other way around...).
54 *
55 * usage is a bitmask of R300_WINSYS_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
56 * usage argument is only an optimization hint, not a guarantee, therefore
57 * proper behavior must be observed in all circumstances.
58 *
59 * alignment indicates the client's alignment requirements, eg for
60 * SSE instructions.
61 */
62 struct r300_winsys_buffer *(*buffer_create)(struct r300_winsys_screen *ws,
63 unsigned alignment,
64 unsigned usage,
65 unsigned size);
66
67 /**
68 * Map the entire data store of a buffer object into the client's address.
69 * flags is bitmask of R300_WINSYS_BUFFER_USAGE_CPU_READ/WRITE flags.
70 */
71 void *(*buffer_map)( struct r300_winsys_screen *ws,
72 struct r300_winsys_buffer *buf,
73 unsigned usage);
74
75 void (*buffer_unmap)( struct r300_winsys_screen *ws,
76 struct r300_winsys_buffer *buf );
77
78 void (*buffer_destroy)( struct r300_winsys_buffer *buf );
79
80
81 void (*buffer_reference)(struct r300_winsys_screen *rws,
82 struct r300_winsys_buffer **pdst,
83 struct r300_winsys_buffer *src);
84
85 boolean (*buffer_references)(struct r300_winsys_buffer *a,
86 struct r300_winsys_buffer *b);
87
88 void (*buffer_flush_range)(struct r300_winsys_screen *rws,
89 struct r300_winsys_buffer *buf,
90 unsigned offset,
91 unsigned length);
92
93 /* Add a pipe_resource to the list of buffer objects to validate. */
94 boolean (*add_buffer)(struct r300_winsys_screen *winsys,
95 struct r300_winsys_buffer *buf,
96 uint32_t rd,
97 uint32_t wd);
98
99
100 /* Revalidate all currently setup pipe_buffers.
101 * Returns TRUE if a flush is required. */
102 boolean (*validate)(struct r300_winsys_screen* winsys);
103
104 /* Check to see if there's room for commands. */
105 boolean (*check_cs)(struct r300_winsys_screen* winsys, int size);
106
107 /* Start a command emit. */
108 void (*begin_cs)(struct r300_winsys_screen* winsys,
109 int size,
110 const char* file,
111 const char* function,
112 int line);
113
114 /* Write a dword to the command buffer. */
115 void (*write_cs_dword)(struct r300_winsys_screen* winsys, uint32_t dword);
116
117 /* Write a relocated dword to the command buffer. */
118 void (*write_cs_reloc)(struct r300_winsys_screen *winsys,
119 struct r300_winsys_buffer *buf,
120 uint32_t rd,
121 uint32_t wd,
122 uint32_t flags);
123
124 /* Finish a command emit. */
125 void (*end_cs)(struct r300_winsys_screen* winsys,
126 const char* file,
127 const char* function,
128 int line);
129
130 /* Flush the CS. */
131 void (*flush_cs)(struct r300_winsys_screen* winsys);
132
133 /* winsys flush - callback from winsys when flush required */
134 void (*set_flush_cb)(struct r300_winsys_screen *winsys,
135 void (*flush_cb)(void *), void *data);
136
137 void (*reset_bos)(struct r300_winsys_screen *winsys);
138
139 void (*buffer_get_tiling)(struct r300_winsys_screen *winsys,
140 struct r300_winsys_buffer *buffer,
141 enum r300_buffer_tiling *microtiled,
142 enum r300_buffer_tiling *macrotiled);
143
144 void (*buffer_set_tiling)(struct r300_winsys_screen *winsys,
145 struct r300_winsys_buffer *buffer,
146 uint32_t pitch,
147 enum r300_buffer_tiling microtiled,
148 enum r300_buffer_tiling macrotiled);
149
150 uint32_t (*get_value)(struct r300_winsys_screen *winsys,
151 enum r300_value_id vid);
152
153 struct r300_winsys_buffer *(*buffer_from_handle)(struct r300_winsys_screen *winsys,
154 struct pipe_screen *screen,
155 struct winsys_handle *whandle,
156 unsigned *stride);
157 boolean (*buffer_get_handle)(struct r300_winsys_screen *winsys,
158 struct r300_winsys_buffer *buffer,
159 unsigned stride,
160 struct winsys_handle *whandle);
161
162 boolean (*is_buffer_referenced)(struct r300_winsys_screen *winsys,
163 struct r300_winsys_buffer *buffer);
164
165
166 };
167
168 struct r300_winsys_screen *
169 r300_winsys_screen(struct pipe_screen *screen);
170
171 /* Creates a new r300 screen. */
172 struct pipe_screen* r300_create_screen(struct r300_winsys_screen *rws);
173
174 #endif /* R300_WINSYS_H */