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"
26 #include "util/u_simple_screen.h"
28 #include "r300_context.h"
29 #include "r300_texture.h"
31 #include "radeon_winsys.h"
33 /* Return the identifier behind whom the brave coders responsible for this
34 * amalgamation of code, sweat, and duct tape, routinely obscure their names.
36 * ...I should have just put "Corbin Simpson", but I'm not that cool.
38 * (Or egotistical. Yet.) */
39 static const char* r300_get_vendor(struct pipe_screen
* pscreen
)
41 return "X.Org R300 Project";
44 static const char* chip_families
[] = {
72 static const char* r300_get_name(struct pipe_screen
* pscreen
)
74 struct r300_screen
* r300screen
= r300_screen(pscreen
);
76 return chip_families
[r300screen
->caps
->family
];
79 static int r300_get_param(struct pipe_screen
* pscreen
, int param
)
81 struct r300_screen
* r300screen
= r300_screen(pscreen
);
84 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS
:
85 case PIPE_CAP_MAX_COMBINED_SAMPLERS
:
86 /* XXX I'm told this goes up to 16 */
88 case PIPE_CAP_NPOT_TEXTURES
:
89 /* XXX enable now to get GL2.1 API,
90 * figure out later how to emulate this */
92 case PIPE_CAP_TWO_SIDED_STENCIL
:
93 if (r300screen
->caps
->is_r500
) {
99 /* I'll be frank. This is a lie.
101 * We don't truly support GLSL on any of this driver's chipsets.
102 * To be fair, no chipset supports the full GLSL specification
103 * to the best of our knowledge, but some of the less esoteric
104 * features are still missing here.
106 * Rather than cripple ourselves intentionally, I'm going to set
107 * this flag, and as Gallium's interface continues to change, I
108 * hope that this single monolithic GLSL enable can slowly get
109 * split down into many different pieces and the state tracker
110 * will handle fallbacks transparently, like it should.
115 case PIPE_CAP_DUAL_SOURCE_BLEND
:
117 case PIPE_CAP_ANISOTROPIC_FILTER
:
119 case PIPE_CAP_POINT_SPRITE
:
121 case PIPE_CAP_MAX_RENDER_TARGETS
:
123 case PIPE_CAP_OCCLUSION_QUERY
:
125 case PIPE_CAP_TEXTURE_SHADOW_MAP
:
127 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS
:
128 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS
:
129 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS
:
130 if (r300screen
->caps
->is_r500
) {
137 case PIPE_CAP_TEXTURE_MIRROR_CLAMP
:
139 case PIPE_CAP_TEXTURE_MIRROR_REPEAT
:
141 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS
:
143 case PIPE_CAP_TGSI_CONT_SUPPORTED
:
145 case PIPE_CAP_BLEND_EQUATION_SEPARATE
:
148 if (r300screen
->caps
->is_r500
) {
153 case PIPE_CAP_MAX_CONST_BUFFERS
:
155 case PIPE_CAP_MAX_CONST_BUFFER_SIZE
:
157 case PIPE_CAP_INDEP_BLEND_ENABLE
:
159 case PIPE_CAP_INDEP_BLEND_FUNC
:
161 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT
:
162 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER
:
164 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT
:
165 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER
:
168 debug_printf("r300: Implementation error: Bad param %d\n",
174 static float r300_get_paramf(struct pipe_screen
* pscreen
, int param
)
176 struct r300_screen
* r300screen
= r300_screen(pscreen
);
179 case PIPE_CAP_MAX_LINE_WIDTH
:
180 case PIPE_CAP_MAX_LINE_WIDTH_AA
:
181 case PIPE_CAP_MAX_POINT_WIDTH
:
182 case PIPE_CAP_MAX_POINT_WIDTH_AA
:
183 /* The maximum dimensions of the colorbuffer are our practical
184 * rendering limits. 2048 pixels should be enough for anybody. */
185 if (r300screen
->caps
->is_r500
) {
187 } else if (r300screen
->caps
->is_r400
) {
192 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY
:
194 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS
:
197 debug_printf("r300: Implementation error: Bad paramf %d\n",
203 static boolean
r300_is_format_supported(struct pipe_screen
* screen
,
204 enum pipe_format format
,
205 enum pipe_texture_target target
,
210 boolean is_r500
= r300_screen(screen
)->caps
->is_r500
;
211 boolean is_z24
= format
== PIPE_FORMAT_X8Z24_UNORM
||
212 format
== PIPE_FORMAT_S8Z24_UNORM
;
213 boolean is_color2101010
= format
== PIPE_FORMAT_R10G10B10A2_UNORM
;
215 if (target
>= PIPE_MAX_TEXTURE_TYPES
) {
216 debug_printf("r300: Implementation error: Received bogus texture "
217 "target %d in %s\n", target
, __FUNCTION__
);
221 /* Check sampler format support. */
222 if ((usage
& PIPE_TEXTURE_USAGE_SAMPLER
) &&
223 /* Z24 cannot be sampled from on non-r5xx. */
224 (is_r500
|| !is_z24
) &&
225 r300_is_sampler_format_supported(format
)) {
226 retval
|= PIPE_TEXTURE_USAGE_SAMPLER
;
229 /* Check colorbuffer format support. */
230 if ((usage
& (PIPE_TEXTURE_USAGE_RENDER_TARGET
|
231 PIPE_TEXTURE_USAGE_DISPLAY_TARGET
|
232 PIPE_TEXTURE_USAGE_SCANOUT
|
233 PIPE_TEXTURE_USAGE_SHARED
)) &&
234 /* 2101010 cannot be rendered to on non-r5xx. */
235 (is_r500
|| !is_color2101010
) &&
236 r300_is_colorbuffer_format_supported(format
)) {
238 (PIPE_TEXTURE_USAGE_RENDER_TARGET
|
239 PIPE_TEXTURE_USAGE_DISPLAY_TARGET
|
240 PIPE_TEXTURE_USAGE_SCANOUT
|
241 PIPE_TEXTURE_USAGE_SHARED
);
244 /* Check depth-stencil format support. */
245 if (usage
& PIPE_TEXTURE_USAGE_DEPTH_STENCIL
&&
246 r300_is_zs_format_supported(format
)) {
247 retval
|= PIPE_TEXTURE_USAGE_DEPTH_STENCIL
;
250 return retval
== usage
;
253 static void r300_destroy_screen(struct pipe_screen
* pscreen
)
255 struct r300_screen
* r300screen
= r300_screen(pscreen
);
257 FREE(r300screen
->caps
);
261 struct pipe_screen
* r300_create_screen(struct radeon_winsys
* radeon_winsys
)
263 struct r300_screen
* r300screen
= CALLOC_STRUCT(r300_screen
);
264 struct r300_capabilities
* caps
= CALLOC_STRUCT(r300_capabilities
);
266 if (!r300screen
|| !caps
) {
272 caps
->pci_id
= radeon_winsys
->pci_id
;
273 caps
->num_frag_pipes
= radeon_winsys
->gb_pipes
;
274 caps
->num_z_pipes
= radeon_winsys
->z_pipes
;
276 r300_init_debug(r300screen
);
277 r300_parse_chipset(caps
);
279 r300screen
->caps
= caps
;
280 r300screen
->radeon_winsys
= radeon_winsys
;
281 r300screen
->screen
.winsys
= (struct pipe_winsys
*)radeon_winsys
;
282 r300screen
->screen
.destroy
= r300_destroy_screen
;
283 r300screen
->screen
.get_name
= r300_get_name
;
284 r300screen
->screen
.get_vendor
= r300_get_vendor
;
285 r300screen
->screen
.get_param
= r300_get_param
;
286 r300screen
->screen
.get_paramf
= r300_get_paramf
;
287 r300screen
->screen
.is_format_supported
= r300_is_format_supported
;
288 r300screen
->screen
.context_create
= r300_create_context
;
290 r300_init_screen_texture_functions(&r300screen
->screen
);
291 u_simple_screen_init(&r300screen
->screen
);
293 return &r300screen
->screen
;