Merge commit 'origin/7.8'
[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_screen;
36
37 /* Creates a new r300 screen. */
38 struct pipe_screen* r300_create_screen(struct r300_winsys_screen *rws);
39
40 struct r300_winsys_buffer;
41
42 /* XXX: this is just a bandaid on larger problems in
43 * r300_screen_buffer.h which doesn't seem to be fully ported to
44 * gallium-resources.
45 */
46 #define R300_BIND_OQBO (1<<21)
47
48
49 enum r300_value_id {
50 R300_VID_PCI_ID,
51 R300_VID_GB_PIPES,
52 R300_VID_Z_PIPES,
53 R300_VID_SQUARE_TILING_SUPPORT,
54 R300_VID_TEX3D_MIP_BUG,
55 };
56
57 struct r300_winsys_screen {
58 void (*destroy)(struct r300_winsys_screen *ws);
59
60 /**
61 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
62 *
63 * Remember that gallium gets to choose the interface it needs, and the
64 * window systems must then implement that interface (rather than the
65 * other way around...).
66 *
67 * usage is a bitmask of R300_WINSYS_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
68 * usage argument is only an optimization hint, not a guarantee, therefore
69 * proper behavior must be observed in all circumstances.
70 *
71 * alignment indicates the client's alignment requirements, eg for
72 * SSE instructions.
73 */
74 struct r300_winsys_buffer *(*buffer_create)(struct r300_winsys_screen *ws,
75 unsigned alignment,
76 unsigned usage,
77 unsigned size);
78
79 /**
80 * Map the entire data store of a buffer object into the client's address.
81 * flags is bitmask of R300_WINSYS_BUFFER_USAGE_CPU_READ/WRITE flags.
82 */
83 void *(*buffer_map)( struct r300_winsys_screen *ws,
84 struct r300_winsys_buffer *buf,
85 unsigned usage);
86
87 void (*buffer_unmap)( struct r300_winsys_screen *ws,
88 struct r300_winsys_buffer *buf );
89
90 void (*buffer_destroy)( struct r300_winsys_buffer *buf );
91
92
93 void (*buffer_reference)(struct r300_winsys_screen *rws,
94 struct r300_winsys_buffer **pdst,
95 struct r300_winsys_buffer *src);
96
97 boolean (*buffer_references)(struct r300_winsys_buffer *a,
98 struct r300_winsys_buffer *b);
99
100 void (*buffer_flush_range)(struct r300_winsys_screen *rws,
101 struct r300_winsys_buffer *buf,
102 unsigned offset,
103 unsigned length);
104
105 /* Add a pipe_resource to the list of buffer objects to validate. */
106 boolean (*add_buffer)(struct r300_winsys_screen *winsys,
107 struct r300_winsys_buffer *buf,
108 uint32_t rd,
109 uint32_t wd);
110
111
112 /* Revalidate all currently setup pipe_buffers.
113 * Returns TRUE if a flush is required. */
114 boolean (*validate)(struct r300_winsys_screen* winsys);
115
116 /* Check to see if there's room for commands. */
117 boolean (*check_cs)(struct r300_winsys_screen* winsys, int size);
118
119 /* Start a command emit. */
120 void (*begin_cs)(struct r300_winsys_screen* winsys,
121 int size,
122 const char* file,
123 const char* function,
124 int line);
125
126 /* Write a dword to the command buffer. */
127 void (*write_cs_dword)(struct r300_winsys_screen* winsys, uint32_t dword);
128
129 /* Write a relocated dword to the command buffer. */
130 void (*write_cs_reloc)(struct r300_winsys_screen *winsys,
131 struct r300_winsys_buffer *buf,
132 uint32_t rd,
133 uint32_t wd,
134 uint32_t flags);
135
136 /* Finish a command emit. */
137 void (*end_cs)(struct r300_winsys_screen* winsys,
138 const char* file,
139 const char* function,
140 int line);
141
142 /* Flush the CS. */
143 void (*flush_cs)(struct r300_winsys_screen* winsys);
144
145 /* winsys flush - callback from winsys when flush required */
146 void (*set_flush_cb)(struct r300_winsys_screen *winsys,
147 void (*flush_cb)(void *), void *data);
148
149 void (*reset_bos)(struct r300_winsys_screen *winsys);
150
151 void (*buffer_get_tiling)(struct r300_winsys_screen *winsys,
152 struct r300_winsys_buffer *buffer,
153 enum r300_buffer_tiling *microtiled,
154 enum r300_buffer_tiling *macrotiled);
155
156 void (*buffer_set_tiling)(struct r300_winsys_screen *winsys,
157 struct r300_winsys_buffer *buffer,
158 uint32_t pitch,
159 enum r300_buffer_tiling microtiled,
160 enum r300_buffer_tiling macrotiled);
161
162 uint32_t (*get_value)(struct r300_winsys_screen *winsys,
163 enum r300_value_id vid);
164
165 struct r300_winsys_buffer *(*buffer_from_handle)(struct r300_winsys_screen *winsys,
166 struct pipe_screen *screen,
167 struct winsys_handle *whandle,
168 unsigned *stride);
169 boolean (*buffer_get_handle)(struct r300_winsys_screen *winsys,
170 struct r300_winsys_buffer *buffer,
171 unsigned stride,
172 struct winsys_handle *whandle);
173
174 boolean (*is_buffer_referenced)(struct r300_winsys_screen *winsys,
175 struct r300_winsys_buffer *buffer);
176
177
178 };
179
180 struct r300_winsys_screen *
181 r300_winsys_screen(struct pipe_screen *screen);
182
183 #endif /* R300_WINSYS_H */