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_format_s3tc.h"
26 #include "util/u_memory.h"
28 #include "r300_context.h"
29 #include "r300_texture.h"
30 #include "r300_screen_buffer.h"
31 #include "r300_state_inlines.h"
32 #include "r300_winsys.h"
34 /* Return the identifier behind whom the brave coders responsible for this
35 * amalgamation of code, sweat, and duct tape, routinely obscure their names.
37 * ...I should have just put "Corbin Simpson", but I'm not that cool.
39 * (Or egotistical. Yet.) */
40 static const char* r300_get_vendor(struct pipe_screen
* pscreen
)
42 return "X.Org R300 Project";
45 static const char* chip_families
[] = {
73 static const char* r300_get_name(struct pipe_screen
* pscreen
)
75 struct r300_screen
* r300screen
= r300_screen(pscreen
);
77 return chip_families
[r300screen
->caps
.family
];
80 static int r300_get_param(struct pipe_screen
* pscreen
, enum pipe_cap param
)
82 struct r300_screen
* r300screen
= r300_screen(pscreen
);
83 boolean is_r400
= r300screen
->caps
.is_r400
;
84 boolean is_r500
= r300screen
->caps
.is_r500
;
86 /* XXX extended shader capabilities of r400 unimplemented */
90 /* Supported features (boolean caps). */
91 case PIPE_CAP_NPOT_TEXTURES
:
92 case PIPE_CAP_TWO_SIDED_STENCIL
:
94 /* I'll be frank. This is a lie.
96 * We don't truly support GLSL on any of this driver's chipsets.
97 * To be fair, no chipset supports the full GLSL specification
98 * to the best of our knowledge, but some of the less esoteric
99 * features are still missing here.
101 * Rather than cripple ourselves intentionally, I'm going to set
102 * this flag, and as Gallium's interface continues to change, I
103 * hope that this single monolithic GLSL enable can slowly get
104 * split down into many different pieces and the state tracker
105 * will handle fallbacks transparently, like it should.
109 case PIPE_CAP_ANISOTROPIC_FILTER
:
110 case PIPE_CAP_POINT_SPRITE
:
111 case PIPE_CAP_OCCLUSION_QUERY
:
112 case PIPE_CAP_TEXTURE_SHADOW_MAP
:
113 case PIPE_CAP_TEXTURE_MIRROR_CLAMP
:
114 case PIPE_CAP_TEXTURE_MIRROR_REPEAT
:
115 case PIPE_CAP_BLEND_EQUATION_SEPARATE
:
116 case PIPE_CAP_TEXTURE_SWIZZLE
:
119 /* Unsupported features (boolean caps). */
120 case PIPE_CAP_TIMER_QUERY
:
121 case PIPE_CAP_DUAL_SOURCE_BLEND
:
122 case PIPE_CAP_TGSI_CONT_SUPPORTED
:
123 case PIPE_CAP_INDEP_BLEND_ENABLE
:
124 case PIPE_CAP_INDEP_BLEND_FUNC
:
128 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS
:
129 case PIPE_CAP_MAX_COMBINED_SAMPLERS
:
130 return r300screen
->caps
.num_tex_units
;
131 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS
:
133 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS
:
134 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS
:
135 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS
:
136 /* 13 == 4096, 12 == 2048 */
137 return is_r500
? 13 : 12;
139 /* Render targets. */
140 case PIPE_CAP_MAX_RENDER_TARGETS
:
143 /* General shader limits and features. */
145 return is_r500
? 1 : 0;
146 case PIPE_CAP_MAX_CONST_BUFFERS
:
148 case PIPE_CAP_MAX_CONST_BUFFER_SIZE
:
151 case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE
:
154 /* Fragment coordinate conventions. */
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 /* Fragment shader limits. */
163 case PIPE_CAP_MAX_FS_INSTRUCTIONS
:
164 return is_r500
|| is_r400
? 512 : 96;
165 case PIPE_CAP_MAX_FS_ALU_INSTRUCTIONS
:
166 return is_r500
|| is_r400
? 512 : 64;
167 case PIPE_CAP_MAX_FS_TEX_INSTRUCTIONS
:
168 return is_r500
|| is_r400
? 512 : 32;
169 case PIPE_CAP_MAX_FS_TEX_INDIRECTIONS
:
170 return is_r500
? 511 : 4;
171 case PIPE_CAP_MAX_FS_CONTROL_FLOW_DEPTH
:
172 return is_r500
? 64 : 0; /* Actually unlimited on r500. */
173 case PIPE_CAP_MAX_FS_INPUTS
:
174 /* 2 colors + 8 texcoords are always supported
175 * (minus fog and wpos).
177 * R500 has the ability to turn 3rd and 4th color into
178 * additional texcoords but there is no two-sided color
179 * selection then. However the facing bit can be used instead. */
181 case PIPE_CAP_MAX_FS_CONSTS
:
182 return is_r500
? 256 : 32;
183 case PIPE_CAP_MAX_FS_TEMPS
:
184 return is_r500
? 128 : is_r400
? 64 : 32;
185 case PIPE_CAP_MAX_FS_ADDRS
:
187 case PIPE_CAP_MAX_FS_PREDS
:
188 return is_r500
? 1 : 0;
190 /* Vertex shader limits. */
191 case PIPE_CAP_MAX_VS_INSTRUCTIONS
:
192 case PIPE_CAP_MAX_VS_ALU_INSTRUCTIONS
:
193 return is_r500
? 1024 : 256;
194 case PIPE_CAP_MAX_VS_TEX_INSTRUCTIONS
:
195 case PIPE_CAP_MAX_VS_TEX_INDIRECTIONS
:
197 case PIPE_CAP_MAX_VS_CONTROL_FLOW_DEPTH
:
198 return is_r500
? 4 : 0; /* For loops; not sure about conditionals. */
199 case PIPE_CAP_MAX_VS_INPUTS
:
201 case PIPE_CAP_MAX_VS_CONSTS
:
203 case PIPE_CAP_MAX_VS_TEMPS
:
205 case PIPE_CAP_MAX_VS_ADDRS
:
206 return 1; /* XXX guessed */
207 case PIPE_CAP_MAX_VS_PREDS
:
208 return is_r500
? 4 : 0; /* XXX guessed. */
211 fprintf(stderr
, "r300: Implementation error: Bad param %d\n",
217 static float r300_get_paramf(struct pipe_screen
* pscreen
, enum pipe_cap param
)
219 struct r300_screen
* r300screen
= r300_screen(pscreen
);
222 case PIPE_CAP_MAX_LINE_WIDTH
:
223 case PIPE_CAP_MAX_LINE_WIDTH_AA
:
224 case PIPE_CAP_MAX_POINT_WIDTH
:
225 case PIPE_CAP_MAX_POINT_WIDTH_AA
:
226 /* The maximum dimensions of the colorbuffer are our practical
227 * rendering limits. 2048 pixels should be enough for anybody. */
228 if (r300screen
->caps
.is_r500
) {
230 } else if (r300screen
->caps
.is_r400
) {
235 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY
:
237 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS
:
240 fprintf(stderr
, "r300: Implementation error: Bad paramf %d\n",
246 static boolean
r300_is_format_supported(struct pipe_screen
* screen
,
247 enum pipe_format format
,
248 enum pipe_texture_target target
,
249 unsigned sample_count
,
254 boolean is_r500
= r300_screen(screen
)->caps
.is_r500
;
255 boolean is_r400
= r300_screen(screen
)->caps
.is_r400
;
256 boolean is_rv350
= r300_screen(screen
)->caps
.is_rv350
;
257 boolean is_z24
= format
== PIPE_FORMAT_X8Z24_UNORM
||
258 format
== PIPE_FORMAT_S8_USCALED_Z24_UNORM
;
259 boolean is_color2101010
= format
== PIPE_FORMAT_R10G10B10A2_UNORM
||
260 format
== PIPE_FORMAT_R10G10B10X2_SNORM
||
261 format
== PIPE_FORMAT_B10G10R10A2_UNORM
||
262 format
== PIPE_FORMAT_R10SG10SB10SA2U_NORM
;
263 boolean is_ati1n
= format
== PIPE_FORMAT_RGTC1_UNORM
||
264 format
== PIPE_FORMAT_RGTC1_SNORM
;
265 boolean is_ati2n
= format
== PIPE_FORMAT_RGTC2_UNORM
||
266 format
== PIPE_FORMAT_RGTC2_SNORM
;
267 boolean is_half_float
= format
== PIPE_FORMAT_R16_FLOAT
||
268 format
== PIPE_FORMAT_R16G16_FLOAT
||
269 format
== PIPE_FORMAT_R16G16B16_FLOAT
||
270 format
== PIPE_FORMAT_R16G16B16A16_FLOAT
;
272 if (target
>= PIPE_MAX_TEXTURE_TYPES
) {
273 fprintf(stderr
, "r300: Implementation error: Received bogus texture "
274 "target %d in %s\n", target
, __FUNCTION__
);
278 switch (sample_count
) {
286 if (usage
!= PIPE_BIND_RENDER_TARGET
||
287 !util_format_is_rgba8_variant(
288 util_format_description(format
))) {
296 /* Check sampler format support. */
297 if ((usage
& PIPE_BIND_SAMPLER_VIEW
) &&
298 /* Z24 cannot be sampled from on non-r5xx. */
299 (is_r500
|| !is_z24
) &&
300 /* ATI1N is r5xx-only. */
301 (is_r500
|| !is_ati1n
) &&
302 /* ATI2N is supported on r4xx-r5xx. */
303 (is_r400
|| is_r500
|| !is_ati2n
) &&
304 r300_is_sampler_format_supported(format
)) {
305 retval
|= PIPE_BIND_SAMPLER_VIEW
;
308 /* Check colorbuffer format support. */
309 if ((usage
& (PIPE_BIND_RENDER_TARGET
|
310 PIPE_BIND_DISPLAY_TARGET
|
312 PIPE_BIND_SHARED
)) &&
313 /* 2101010 cannot be rendered to on non-r5xx. */
314 (is_r500
|| !is_color2101010
) &&
315 r300_is_colorbuffer_format_supported(format
)) {
317 (PIPE_BIND_RENDER_TARGET
|
318 PIPE_BIND_DISPLAY_TARGET
|
323 /* Check depth-stencil format support. */
324 if (usage
& PIPE_BIND_DEPTH_STENCIL
&&
325 r300_is_zs_format_supported(format
)) {
326 retval
|= PIPE_BIND_DEPTH_STENCIL
;
329 /* Check vertex buffer format support. */
330 if (usage
& PIPE_BIND_VERTEX_BUFFER
&&
331 /* Half float is supported on >= RV350. */
332 (is_rv350
|| !is_half_float
) &&
333 r300_translate_vertex_data_type(format
) != R300_INVALID_FORMAT
) {
334 retval
|= PIPE_BIND_VERTEX_BUFFER
;
337 /* Transfers are always supported. */
338 if (usage
& PIPE_BIND_TRANSFER_READ
)
339 retval
|= PIPE_BIND_TRANSFER_READ
;
340 if (usage
& PIPE_BIND_TRANSFER_WRITE
)
341 retval
|= PIPE_BIND_TRANSFER_WRITE
;
343 return retval
== usage
;
346 static void r300_destroy_screen(struct pipe_screen
* pscreen
)
348 struct r300_screen
* r300screen
= r300_screen(pscreen
);
349 struct r300_winsys_screen
*rws
= r300_winsys_screen(pscreen
);
357 static void r300_fence_reference(struct pipe_screen
*screen
,
358 struct pipe_fence_handle
**ptr
,
359 struct pipe_fence_handle
*fence
)
361 struct r300_fence
**oldf
= (struct r300_fence
**)ptr
;
362 struct r300_fence
*newf
= (struct r300_fence
*)fence
;
364 if (pipe_reference(&(*oldf
)->reference
, &newf
->reference
))
370 static int r300_fence_signalled(struct pipe_screen
*screen
,
371 struct pipe_fence_handle
*fence
,
374 struct r300_fence
*rfence
= (struct r300_fence
*)fence
;
376 return rfence
->signalled
? 0 : 1; /* 0 == success */
379 static int r300_fence_finish(struct pipe_screen
*screen
,
380 struct pipe_fence_handle
*fence
,
383 struct r300_fence
*rfence
= (struct r300_fence
*)fence
;
385 r300_finish(rfence
->ctx
);
386 rfence
->signalled
= TRUE
;
387 return 0; /* 0 == success */
390 struct pipe_screen
* r300_create_screen(struct r300_winsys_screen
*rws
)
392 struct r300_screen
*r300screen
= CALLOC_STRUCT(r300_screen
);
399 r300screen
->caps
.pci_id
= rws
->get_value(rws
, R300_VID_PCI_ID
);
400 r300screen
->caps
.num_frag_pipes
= rws
->get_value(rws
, R300_VID_GB_PIPES
);
401 r300screen
->caps
.num_z_pipes
= rws
->get_value(rws
, R300_VID_Z_PIPES
);
403 r300_init_debug(r300screen
);
404 r300_parse_chipset(&r300screen
->caps
);
406 r300screen
->rws
= rws
;
407 r300screen
->screen
.winsys
= (struct pipe_winsys
*)rws
;
408 r300screen
->screen
.destroy
= r300_destroy_screen
;
409 r300screen
->screen
.get_name
= r300_get_name
;
410 r300screen
->screen
.get_vendor
= r300_get_vendor
;
411 r300screen
->screen
.get_param
= r300_get_param
;
412 r300screen
->screen
.get_paramf
= r300_get_paramf
;
413 r300screen
->screen
.is_format_supported
= r300_is_format_supported
;
414 r300screen
->screen
.context_create
= r300_create_context
;
416 r300screen
->screen
.fence_reference
= r300_fence_reference
;
417 r300screen
->screen
.fence_signalled
= r300_fence_signalled
;
418 r300screen
->screen
.fence_finish
= r300_fence_finish
;
420 r300_init_screen_resource_functions(r300screen
);
422 util_format_s3tc_init();
424 return &r300screen
->screen
;
427 struct r300_winsys_screen
*
428 r300_winsys_screen(struct pipe_screen
*screen
)
430 return r300_screen(screen
)->rws
;