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:
86 case PIPE_CAP_TWO_SIDED_STENCIL:
88 /* if (r300screen->is_r500) {
94 case PIPE_CAP_ANISOTROPIC_FILTER:
97 case PIPE_CAP_POINT_SPRITE:
100 case PIPE_CAP_OCCLUSION_QUERY:
103 case PIPE_CAP_TEXTURE_SHADOW_MAP:
109 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
110 if (r300screen->caps->is_r500) {
111 /* 13 == 4096x4096 */
114 /* 12 == 2048x2048 */
117 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
118 /* So, technically, the limit is the same as above, but some math
119 * shows why this is silly. Assuming RGBA, 4cpp, we can see that
120 * 4096*4096*4096 = 64.0 GiB exactly, so it's not exactly
121 * practical. However, if at some point a game really wants this,
122 * then we can remove this limit. */
123 if (r300screen->caps->is_r500) {
124 /* 9 == 256x256x256 */
127 /* 8 == 128*128*128 */
130 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
131 if (r300screen->caps->is_r500) {
132 /* 13 == 4096x4096 */
135 /* 12 == 2048x2048 */
138 case PIPE_CAP_MAX_RENDER_TARGETS:
139 /* XXX 4 eventually */
142 debug_printf("r300: Implementation error: Bad param %d", param);
147 static float r300_get_paramf(struct pipe_screen* pscreen, int param)
150 case PIPE_CAP_MAX_LINE_WIDTH:
151 case PIPE_CAP_MAX_LINE_WIDTH_AA:
152 /* XXX this is the biggest thing that will fit in that register.
153 * Perhaps the actual rendering limits are less? */
155 case PIPE_CAP_MAX_POINT_WIDTH:
156 case PIPE_CAP_MAX_POINT_WIDTH_AA:
157 /* XXX this is the biggest thing that will fit in that register.
158 * Perhaps the actual rendering limits are less? */
160 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
162 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
165 debug_printf("r300: Implementation error: Bad paramf %d", param);
170 /* XXX moar formats */
171 static boolean check_tex_2d_format(enum pipe_format format)
174 case PIPE_FORMAT_A8R8G8B8_UNORM:
175 case PIPE_FORMAT_I8_UNORM:
178 debug_printf("r300: Warning: Got unknown format: %d, in %s",
179 format, __FUNCTION__);
186 /* XXX moar targets */
187 static boolean r300_is_format_supported(struct pipe_screen* pscreen,
188 enum pipe_format format,
189 enum pipe_texture_target target,
194 case PIPE_TEXTURE_2D:
195 return check_tex_2d_format(format);
197 debug_printf("r300: Warning: Got unknown format target: %d",
205 static void* r300_surface_map(struct pipe_screen* screen,
206 struct pipe_surface* surface,
209 char* map = pipe_buffer_map(screen, surface->buffer, flags);
215 return map + surface->offset;
218 static void r300_surface_unmap(struct pipe_screen* screen,
219 struct pipe_surface* surface)
221 pipe_buffer_unmap(screen, surface->buffer);
224 static void r300_destroy_screen(struct pipe_screen* pscreen)
226 struct r300_screen* r300screen = r300_screen(pscreen);
228 FREE(r300screen->caps);
232 struct pipe_screen* r300_create_screen(struct pipe_winsys* winsys,
233 struct r300_winsys* r300_winsys)
235 struct r300_screen* r300screen = CALLOC_STRUCT(r300_screen);
236 struct r300_capabilities* caps = CALLOC_STRUCT(r300_capabilities);
238 if (!r300screen || !caps)
241 caps->pci_id = r300_winsys->pci_id;
242 caps->num_frag_pipes = r300_winsys->gb_pipes;
244 r300_parse_chipset(caps);
246 r300screen->caps = caps;
247 r300screen->screen.winsys = winsys;
248 r300screen->screen.destroy = r300_destroy_screen;
249 r300screen->screen.get_name = r300_get_name;
250 r300screen->screen.get_vendor = r300_get_vendor;
251 r300screen->screen.get_param = r300_get_param;
252 r300screen->screen.get_paramf = r300_get_paramf;
253 r300screen->screen.is_format_supported = r300_is_format_supported;
254 r300screen->screen.surface_map = r300_surface_map;
255 r300screen->screen.surface_unmap = r300_surface_unmap;
257 r300_init_screen_texture_functions(&r300screen->screen);
259 return &r300screen->screen;