2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2010 Marek Olšák <maraeo@gmail.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
24 #include "util/u_format.h"
25 #include "util/u_memory.h"
27 #include "r300_context.h"
28 #include "r300_texture.h"
29 #include "r300_screen_buffer.h"
30 #include "r300_winsys.h"
32 /* Return the identifier behind whom the brave coders responsible for this
33 * amalgamation of code, sweat, and duct tape, routinely obscure their names.
35 * ...I should have just put "Corbin Simpson", but I'm not that cool.
37 * (Or egotistical. Yet.) */
38 static const char* r300_get_vendor(struct pipe_screen* pscreen)
40 return "X.Org R300 Project";
43 static const char* chip_families[] = {
71 static const char* r300_get_name(struct pipe_screen* pscreen)
73 struct r300_screen* r300screen = r300_screen(pscreen);
75 return chip_families[r300screen->caps.family];
78 static int r300_get_param(struct pipe_screen* pscreen, int param)
80 struct r300_screen* r300screen = r300_screen(pscreen);
83 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
84 case PIPE_CAP_MAX_COMBINED_SAMPLERS:
85 return r300screen->caps.num_tex_units;
86 case PIPE_CAP_NPOT_TEXTURES:
87 /* XXX enable now to get GL2.1 API,
88 * figure out later how to emulate this */
90 case PIPE_CAP_TWO_SIDED_STENCIL:
93 /* I'll be frank. This is a lie.
95 * We don't truly support GLSL on any of this driver's chipsets.
96 * To be fair, no chipset supports the full GLSL specification
97 * to the best of our knowledge, but some of the less esoteric
98 * features are still missing here.
100 * Rather than cripple ourselves intentionally, I'm going to set
101 * this flag, and as Gallium's interface continues to change, I
102 * hope that this single monolithic GLSL enable can slowly get
103 * split down into many different pieces and the state tracker
104 * will handle fallbacks transparently, like it should.
109 case PIPE_CAP_DUAL_SOURCE_BLEND:
111 case PIPE_CAP_ANISOTROPIC_FILTER:
113 case PIPE_CAP_POINT_SPRITE:
115 case PIPE_CAP_MAX_RENDER_TARGETS:
117 case PIPE_CAP_OCCLUSION_QUERY:
119 case PIPE_CAP_TEXTURE_SHADOW_MAP:
121 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
122 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
123 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
124 if (r300screen->caps.is_r500) {
131 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
133 case PIPE_CAP_TEXTURE_MIRROR_REPEAT:
135 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS:
137 case PIPE_CAP_TGSI_CONT_SUPPORTED:
139 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
142 if (r300screen->caps.is_r500) {
147 case PIPE_CAP_MAX_CONST_BUFFERS:
149 case PIPE_CAP_MAX_CONST_BUFFER_SIZE:
151 case PIPE_CAP_INDEP_BLEND_ENABLE:
153 case PIPE_CAP_INDEP_BLEND_FUNC:
155 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
156 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
158 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
159 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
162 fprintf(stderr, "r300: Implementation error: Bad param %d\n",
168 static float r300_get_paramf(struct pipe_screen* pscreen, int param)
170 struct r300_screen* r300screen = r300_screen(pscreen);
173 case PIPE_CAP_MAX_LINE_WIDTH:
174 case PIPE_CAP_MAX_LINE_WIDTH_AA:
175 case PIPE_CAP_MAX_POINT_WIDTH:
176 case PIPE_CAP_MAX_POINT_WIDTH_AA:
177 /* The maximum dimensions of the colorbuffer are our practical
178 * rendering limits. 2048 pixels should be enough for anybody. */
179 if (r300screen->caps.is_r500) {
181 } else if (r300screen->caps.is_r400) {
186 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
188 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
191 fprintf(stderr, "r300: Implementation error: Bad paramf %d\n",
197 static boolean r300_is_format_supported(struct pipe_screen* screen,
198 enum pipe_format format,
199 enum pipe_texture_target target,
204 boolean is_r500 = r300_screen(screen)->caps.is_r500;
205 boolean is_r400 = r300_screen(screen)->caps.is_r400;
206 boolean is_z24 = format == PIPE_FORMAT_X8Z24_UNORM ||
207 format == PIPE_FORMAT_S8_USCALED_Z24_UNORM;
208 boolean is_color2101010 = format == PIPE_FORMAT_R10G10B10A2_UNORM;
209 boolean is_ati1n = format == PIPE_FORMAT_RGTC1_UNORM ||
210 format == PIPE_FORMAT_RGTC1_SNORM;
211 boolean is_ati2n = format == PIPE_FORMAT_RGTC2_UNORM ||
212 format == PIPE_FORMAT_RGTC2_SNORM;
214 if (target >= PIPE_MAX_TEXTURE_TYPES) {
215 fprintf(stderr, "r300: Implementation error: Received bogus texture "
216 "target %d in %s\n", target, __FUNCTION__);
220 /* Check sampler format support. */
221 if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
222 /* Z24 cannot be sampled from on non-r5xx. */
223 (is_r500 || !is_z24) &&
224 /* ATI1N is r5xx-only. */
225 (is_r500 || !is_ati1n) &&
226 /* ATI2N is supported on r4xx-r5xx. */
227 (is_r400 || is_r500 || !is_ati2n) &&
228 r300_is_sampler_format_supported(format)) {
229 retval |= PIPE_BIND_SAMPLER_VIEW;
232 /* Check colorbuffer format support. */
233 if ((usage & (PIPE_BIND_RENDER_TARGET |
234 PIPE_BIND_DISPLAY_TARGET |
236 PIPE_BIND_SHARED)) &&
237 /* 2101010 cannot be rendered to on non-r5xx. */
238 (is_r500 || !is_color2101010) &&
239 r300_is_colorbuffer_format_supported(format)) {
241 (PIPE_BIND_RENDER_TARGET |
242 PIPE_BIND_DISPLAY_TARGET |
247 /* Check depth-stencil format support. */
248 if (usage & PIPE_BIND_DEPTH_STENCIL &&
249 r300_is_zs_format_supported(format)) {
250 retval |= PIPE_BIND_DEPTH_STENCIL;
253 return retval == usage;
256 static void r300_destroy_screen(struct pipe_screen* pscreen)
258 struct r300_screen* r300screen = r300_screen(pscreen);
259 struct r300_winsys_screen *rws = r300_winsys_screen(pscreen);
267 static void r300_fence_reference(struct pipe_screen *screen,
268 struct pipe_fence_handle **ptr,
269 struct pipe_fence_handle *fence)
273 static int r300_fence_signalled(struct pipe_screen *screen,
274 struct pipe_fence_handle *fence,
280 static int r300_fence_finish(struct pipe_screen *screen,
281 struct pipe_fence_handle *fence,
287 struct pipe_screen* r300_create_screen(struct r300_winsys_screen *rws)
289 struct r300_screen *r300screen = CALLOC_STRUCT(r300_screen);
296 r300screen->caps.pci_id = rws->get_value(rws, R300_VID_PCI_ID);
297 r300screen->caps.num_frag_pipes = rws->get_value(rws, R300_VID_GB_PIPES);
298 r300screen->caps.num_z_pipes = rws->get_value(rws, R300_VID_Z_PIPES);
300 r300_init_debug(r300screen);
301 r300_parse_chipset(&r300screen->caps);
303 r300screen->rws = rws;
304 r300screen->screen.winsys = (struct pipe_winsys*)rws;
305 r300screen->screen.destroy = r300_destroy_screen;
306 r300screen->screen.get_name = r300_get_name;
307 r300screen->screen.get_vendor = r300_get_vendor;
308 r300screen->screen.get_param = r300_get_param;
309 r300screen->screen.get_paramf = r300_get_paramf;
310 r300screen->screen.is_format_supported = r300_is_format_supported;
311 r300screen->screen.context_create = r300_create_context;
313 r300screen->screen.fence_reference = r300_fence_reference;
314 r300screen->screen.fence_signalled = r300_fence_signalled;
315 r300screen->screen.fence_finish = r300_fence_finish;
317 r300_init_screen_resource_functions(r300screen);
319 return &r300screen->screen;
322 struct r300_winsys_screen *
323 r300_winsys_screen(struct pipe_screen *screen)
325 return r300_screen(screen)->rws;