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 "pipe/p_inlines.h"
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_screen.h"
30 #include "r300_texture.h"
32 #include "radeon_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
, int param
)
82 struct r300_screen
* r300screen
= r300_screen(pscreen
);
85 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS
:
86 case PIPE_CAP_MAX_COMBINED_SAMPLERS
:
87 /* XXX I'm told this goes up to 16 */
89 case PIPE_CAP_NPOT_TEXTURES
:
90 /* XXX enable now to get GL2.1 API,
91 * figure out later how to emulate this */
93 case PIPE_CAP_TWO_SIDED_STENCIL
:
94 if (r300screen
->caps
->is_r500
) {
100 /* I'll be frank. This is a lie.
102 * We don't truly support GLSL on any of this driver's chipsets.
103 * To be fair, no chipset supports the full GLSL specification
104 * to the best of our knowledge, but some of the less esoteric
105 * features are still missing here.
107 * Rather than cripple ourselves intentionally, I'm going to set
108 * this flag, and as Gallium's interface continues to change, I
109 * hope that this single monolithic GLSL enable can slowly get
110 * split down into many different pieces and the state tracker
111 * will handle fallbacks transparently, like it should.
116 case PIPE_CAP_ANISOTROPIC_FILTER
:
118 case PIPE_CAP_POINT_SPRITE
:
120 case PIPE_CAP_MAX_RENDER_TARGETS
:
122 case PIPE_CAP_OCCLUSION_QUERY
:
124 case PIPE_CAP_TEXTURE_SHADOW_MAP
:
126 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS
:
127 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS
:
128 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS
:
129 if (r300screen
->caps
->is_r500
) {
136 case PIPE_CAP_TEXTURE_MIRROR_CLAMP
:
138 case PIPE_CAP_TEXTURE_MIRROR_REPEAT
:
140 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS
:
142 case PIPE_CAP_TGSI_CONT_SUPPORTED
:
144 case PIPE_CAP_BLEND_EQUATION_SEPARATE
:
147 if (r300screen
->caps
->is_r500
) {
153 debug_printf("r300: Implementation error: Bad param %d\n",
159 static float r300_get_paramf(struct pipe_screen
* pscreen
, int param
)
161 struct r300_screen
* r300screen
= r300_screen(pscreen
);
164 case PIPE_CAP_MAX_LINE_WIDTH
:
165 case PIPE_CAP_MAX_LINE_WIDTH_AA
:
166 case PIPE_CAP_MAX_POINT_WIDTH
:
167 case PIPE_CAP_MAX_POINT_WIDTH_AA
:
168 /* The maximum dimensions of the colorbuffer are our practical
169 * rendering limits. 2048 pixels should be enough for anybody. */
170 if (r300screen
->caps
->is_r500
) {
175 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY
:
177 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS
:
180 debug_printf("r300: Implementation error: Bad paramf %d\n",
186 static boolean
r300_is_format_supported(struct pipe_screen
* screen
,
187 enum pipe_format format
,
188 enum pipe_texture_target target
,
193 boolean is_r500
= r300_screen(screen
)->caps
->is_r500
;
195 if (target
>= PIPE_MAX_TEXTURE_TYPES
) {
196 debug_printf("r300: Implementation error: Received bogus texture "
197 "target %d in %s\n", target
, __FUNCTION__
);
202 /* Supported formats. */
204 case PIPE_FORMAT_A4R4G4B4_UNORM
:
205 case PIPE_FORMAT_R5G6B5_UNORM
:
206 case PIPE_FORMAT_A1R5G5B5_UNORM
:
208 (PIPE_TEXTURE_USAGE_RENDER_TARGET
|
209 PIPE_TEXTURE_USAGE_DISPLAY_TARGET
|
210 PIPE_TEXTURE_USAGE_PRIMARY
);
214 case PIPE_FORMAT_A8R8G8B8_SRGB
:
215 case PIPE_FORMAT_R8G8B8A8_SRGB
:
216 case PIPE_FORMAT_DXT1_RGB
:
217 case PIPE_FORMAT_DXT1_RGBA
:
218 case PIPE_FORMAT_DXT3_RGBA
:
219 case PIPE_FORMAT_DXT5_RGBA
:
220 case PIPE_FORMAT_YCBCR
:
221 case PIPE_FORMAT_L8_UNORM
:
222 case PIPE_FORMAT_A8L8_UNORM
:
223 retval
= usage
& PIPE_TEXTURE_USAGE_SAMPLER
;
226 /* Colorbuffer or texture */
227 case PIPE_FORMAT_A8R8G8B8_UNORM
:
228 case PIPE_FORMAT_X8R8G8B8_UNORM
:
229 case PIPE_FORMAT_R8G8B8A8_UNORM
:
230 case PIPE_FORMAT_R8G8B8X8_UNORM
:
231 case PIPE_FORMAT_I8_UNORM
:
233 (PIPE_TEXTURE_USAGE_RENDER_TARGET
|
234 PIPE_TEXTURE_USAGE_DISPLAY_TARGET
|
235 PIPE_TEXTURE_USAGE_PRIMARY
|
236 PIPE_TEXTURE_USAGE_SAMPLER
);
239 /* Z buffer or texture */
240 case PIPE_FORMAT_Z16_UNORM
:
242 (PIPE_TEXTURE_USAGE_DEPTH_STENCIL
|
243 PIPE_TEXTURE_USAGE_SAMPLER
);
246 /* 24bit Z buffer can only be used as a texture on R500. */
247 case PIPE_FORMAT_Z24X8_UNORM
:
248 /* Z buffer with stencil or texture */
249 case PIPE_FORMAT_Z24S8_UNORM
:
251 (PIPE_TEXTURE_USAGE_DEPTH_STENCIL
|
252 (is_r500
? PIPE_TEXTURE_USAGE_SAMPLER
: 0));
255 /* Definitely unsupported formats. */
256 /* Non-usable Z buffer/stencil formats. */
257 case PIPE_FORMAT_Z32_UNORM
:
258 case PIPE_FORMAT_S8Z24_UNORM
:
259 case PIPE_FORMAT_X8Z24_UNORM
:
260 SCREEN_DBG(r300_screen(screen
), DBG_TEX
,
261 "r300: Note: Got unsupported format: %s in %s\n",
262 pf_name(format
), __FUNCTION__
);
265 /* XXX Add all remaining gallium-supported formats,
266 * see util/u_format.csv. */
269 /* Unknown format... */
270 debug_printf("r300: Warning: Got unknown format: %s in %s\n",
271 pf_name(format
), __FUNCTION__
);
275 /* If usage was a mask that contained multiple bits, and not all of them
276 * are supported, this will catch that and return FALSE.
277 * e.g. usage = 2 | 4; retval = 4; (retval >= usage) == FALSE
279 * This also returns FALSE for any unknown formats.
281 return (retval
>= usage
);
284 static struct pipe_transfer
*
285 r300_get_tex_transfer(struct pipe_screen
*screen
,
286 struct pipe_texture
*texture
,
287 unsigned face
, unsigned level
, unsigned zslice
,
288 enum pipe_transfer_usage usage
, unsigned x
, unsigned y
,
289 unsigned w
, unsigned h
)
291 struct r300_texture
*tex
= (struct r300_texture
*)texture
;
292 struct r300_transfer
*trans
;
293 struct r300_screen
*rscreen
= r300_screen(screen
);
296 offset
= r300_texture_get_offset(tex
, level
, zslice
, face
); /* in bytes */
298 trans
= CALLOC_STRUCT(r300_transfer
);
300 pipe_texture_reference(&trans
->transfer
.texture
, texture
);
301 trans
->transfer
.x
= x
;
302 trans
->transfer
.y
= y
;
303 trans
->transfer
.width
= w
;
304 trans
->transfer
.height
= h
;
305 trans
->transfer
.stride
= r300_texture_get_stride(rscreen
, tex
, level
);
306 trans
->transfer
.usage
= usage
;
307 trans
->transfer
.zslice
= zslice
;
308 trans
->transfer
.face
= face
;
310 trans
->offset
= offset
;
312 return &trans
->transfer
;
316 r300_tex_transfer_destroy(struct pipe_transfer
*trans
)
318 pipe_texture_reference(&trans
->texture
, NULL
);
322 static void* r300_transfer_map(struct pipe_screen
* screen
,
323 struct pipe_transfer
* transfer
)
325 struct r300_texture
* tex
= (struct r300_texture
*)transfer
->texture
;
327 enum pipe_format format
= tex
->tex
.format
;
329 map
= pipe_buffer_map(screen
, tex
->buffer
,
330 pipe_transfer_buffer_flags(transfer
));
336 return map
+ r300_transfer(transfer
)->offset
+
337 transfer
->y
/ util_format_get_blockheight(format
) * transfer
->stride
+
338 transfer
->x
/ util_format_get_blockwidth(format
) * util_format_get_blocksize(format
);
341 static void r300_transfer_unmap(struct pipe_screen
* screen
,
342 struct pipe_transfer
* transfer
)
344 struct r300_texture
* tex
= (struct r300_texture
*)transfer
->texture
;
345 pipe_buffer_unmap(screen
, tex
->buffer
);
348 static void r300_destroy_screen(struct pipe_screen
* pscreen
)
350 struct r300_screen
* r300screen
= r300_screen(pscreen
);
352 FREE(r300screen
->caps
);
356 struct pipe_screen
* r300_create_screen(struct radeon_winsys
* radeon_winsys
)
358 struct r300_screen
* r300screen
= CALLOC_STRUCT(r300_screen
);
359 struct r300_capabilities
* caps
= CALLOC_STRUCT(r300_capabilities
);
361 if (!r300screen
|| !caps
)
364 caps
->pci_id
= radeon_winsys
->pci_id
;
365 caps
->num_frag_pipes
= radeon_winsys
->gb_pipes
;
366 caps
->num_z_pipes
= radeon_winsys
->z_pipes
;
368 r300_init_debug(r300screen
);
369 r300_parse_chipset(caps
);
371 r300screen
->caps
= caps
;
372 r300screen
->screen
.winsys
= (struct pipe_winsys
*)radeon_winsys
;
373 r300screen
->screen
.destroy
= r300_destroy_screen
;
374 r300screen
->screen
.get_name
= r300_get_name
;
375 r300screen
->screen
.get_vendor
= r300_get_vendor
;
376 r300screen
->screen
.get_param
= r300_get_param
;
377 r300screen
->screen
.get_paramf
= r300_get_paramf
;
378 r300screen
->screen
.is_format_supported
= r300_is_format_supported
;
379 r300screen
->screen
.get_tex_transfer
= r300_get_tex_transfer
;
380 r300screen
->screen
.tex_transfer_destroy
= r300_tex_transfer_destroy
;
381 r300screen
->screen
.transfer_map
= r300_transfer_map
;
382 r300screen
->screen
.transfer_unmap
= r300_transfer_unmap
;
384 r300_init_screen_texture_functions(&r300screen
->screen
);
385 u_simple_screen_init(&r300screen
->screen
);
387 return &r300screen
->screen
;