2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
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:
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
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. */
23 #include "r300_screen.h"
25 /* Return the identifier behind whom the brave coders responsible for this
26 * amalgamation of code, sweat, and duct tape, routinely obscure their names.
28 * ...I should have just put "Corbin Simpson", but I'm not that cool.
30 * (Or egotistical. Yet.) */
31 static const char* r300_get_vendor(struct pipe_screen
* pscreen
)
33 return "X.Org R300 Project";
36 static const char* chip_families
[] = {
63 static const char* r300_get_name(struct pipe_screen
* pscreen
)
65 struct r300_screen
* r300screen
= r300_screen(pscreen
);
67 return chip_families
[r300screen
->caps
->family
];
70 static int r300_get_param(struct pipe_screen
* pscreen
, int param
)
72 struct r300_screen
* r300screen
= r300_screen(pscreen
);
75 /* XXX cases marked "IN THEORY" are possible on the hardware,
76 * but haven't been implemented yet. */
77 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS
:
78 /* XXX I'm told this goes up to 16 */
80 case PIPE_CAP_NPOT_TEXTURES
:
83 case PIPE_CAP_TWO_SIDED_STENCIL
:
84 if (r300screen
->caps
->is_r500
) {
96 case PIPE_CAP_ANISOTROPIC_FILTER
:
99 case PIPE_CAP_POINT_SPRITE
:
102 case PIPE_CAP_MAX_RENDER_TARGETS
:
104 case PIPE_CAP_OCCLUSION_QUERY
:
107 case PIPE_CAP_TEXTURE_SHADOW_MAP
:
110 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS
:
111 if (r300screen
->caps
->is_r500
) {
112 /* 13 == 4096x4096 */
115 /* 12 == 2048x2048 */
118 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS
:
119 /* So, technically, the limit is the same as above, but some math
120 * shows why this is silly. Assuming RGBA, 4cpp, we can see that
121 * 4096*4096*4096 = 64.0 GiB exactly, so it's not exactly
122 * practical. However, if at some point a game really wants this,
123 * then we can remove this limit. */
124 if (r300screen
->caps
->is_r500
) {
125 /* 9 == 256x256x256 */
128 /* 8 == 128*128*128 */
131 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS
:
132 if (r300screen
->caps
->is_r500
) {
133 /* 13 == 4096x4096 */
136 /* 12 == 2048x2048 */
139 case PIPE_CAP_TEXTURE_MIRROR_CLAMP
:
141 case PIPE_CAP_TEXTURE_MIRROR_REPEAT
:
143 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS
:
147 debug_printf("r300: Implementation error: Bad param %d\n",
153 static float r300_get_paramf(struct pipe_screen
* pscreen
, int param
)
156 case PIPE_CAP_MAX_LINE_WIDTH
:
157 case PIPE_CAP_MAX_LINE_WIDTH_AA
:
158 /* XXX this is the biggest thing that will fit in that register.
159 * Perhaps the actual rendering limits are less? */
161 case PIPE_CAP_MAX_POINT_WIDTH
:
162 case PIPE_CAP_MAX_POINT_WIDTH_AA
:
163 /* XXX this is the biggest thing that will fit in that register.
164 * Perhaps the actual rendering limits are less? */
166 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY
:
168 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS
:
171 debug_printf("r300: Implementation error: Bad paramf %d\n",
177 /* XXX moar formats */
178 static boolean
check_tex_2d_format(enum pipe_format format
)
181 case PIPE_FORMAT_A8R8G8B8_UNORM
:
182 case PIPE_FORMAT_I8_UNORM
:
185 debug_printf("r300: Warning: Got unknown format: %s, in %s\n",
186 pf_name(format
), __FUNCTION__
);
193 /* XXX moar targets */
194 static boolean
r300_is_format_supported(struct pipe_screen
* pscreen
,
195 enum pipe_format format
,
196 enum pipe_texture_target target
,
201 case PIPE_TEXTURE_2D
:
202 return check_tex_2d_format(format
);
204 debug_printf("r300: Warning: Got unknown format target: %d\n",
212 static void* r300_surface_map(struct pipe_screen
* screen
,
213 struct pipe_surface
* surface
,
216 struct r300_texture
* tex
= (struct r300_texture
*)surface
->texture
;
217 char* map
= pipe_buffer_map(screen
, tex
->buffer
, flags
);
223 return map
+ surface
->offset
;
226 static void r300_surface_unmap(struct pipe_screen
* screen
,
227 struct pipe_surface
* surface
)
229 struct r300_texture
* tex
= (struct r300_texture
*)surface
->texture
;
230 pipe_buffer_unmap(screen
, tex
->buffer
);
233 static void r300_destroy_screen(struct pipe_screen
* pscreen
)
235 struct r300_screen
* r300screen
= r300_screen(pscreen
);
237 FREE(r300screen
->caps
);
241 struct pipe_screen
* r300_create_screen(struct pipe_winsys
* winsys
,
242 struct r300_winsys
* r300_winsys
)
244 struct r300_screen
* r300screen
= CALLOC_STRUCT(r300_screen
);
245 struct r300_capabilities
* caps
= CALLOC_STRUCT(r300_capabilities
);
247 if (!r300screen
|| !caps
)
250 caps
->pci_id
= r300_winsys
->pci_id
;
251 caps
->num_frag_pipes
= r300_winsys
->gb_pipes
;
253 r300_parse_chipset(caps
);
255 r300screen
->caps
= caps
;
256 r300screen
->screen
.winsys
= winsys
;
257 r300screen
->screen
.destroy
= r300_destroy_screen
;
258 r300screen
->screen
.get_name
= r300_get_name
;
259 r300screen
->screen
.get_vendor
= r300_get_vendor
;
260 r300screen
->screen
.get_param
= r300_get_param
;
261 r300screen
->screen
.get_paramf
= r300_get_paramf
;
262 r300screen
->screen
.is_format_supported
= r300_is_format_supported
;
263 r300screen
->screen
.surface_map
= r300_surface_map
;
264 r300screen
->screen
.surface_unmap
= r300_surface_unmap
;
266 r300_init_screen_texture_functions(&r300screen
->screen
);
267 u_simple_screen_init(&r300screen
->screen
);
269 return &r300screen
->screen
;