Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / drivers / softpipe / sp_screen.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "util/u_memory.h"
30 #include "util/u_simple_screen.h"
31 #include "pipe/internal/p_winsys_screen.h"
32 #include "pipe/p_defines.h"
33 #include "pipe/p_screen.h"
34
35 #include "sp_texture.h"
36 #include "sp_winsys.h"
37 #include "sp_screen.h"
38
39
40 static const char *
41 softpipe_get_vendor(struct pipe_screen *screen)
42 {
43 return "VMware, Inc.";
44 }
45
46
47 static const char *
48 softpipe_get_name(struct pipe_screen *screen)
49 {
50 return "softpipe";
51 }
52
53
54 static int
55 softpipe_get_param(struct pipe_screen *screen, int param)
56 {
57 switch (param) {
58 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
59 return PIPE_MAX_SAMPLERS;
60 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS:
61 return PIPE_MAX_VERTEX_SAMPLERS;
62 case PIPE_CAP_MAX_COMBINED_SAMPLERS:
63 return PIPE_MAX_SAMPLERS + PIPE_MAX_VERTEX_SAMPLERS;
64 case PIPE_CAP_NPOT_TEXTURES:
65 return 1;
66 case PIPE_CAP_TWO_SIDED_STENCIL:
67 return 1;
68 case PIPE_CAP_GLSL:
69 return 1;
70 case PIPE_CAP_ANISOTROPIC_FILTER:
71 return 0;
72 case PIPE_CAP_POINT_SPRITE:
73 return 1;
74 case PIPE_CAP_MAX_RENDER_TARGETS:
75 return PIPE_MAX_COLOR_BUFS;
76 case PIPE_CAP_OCCLUSION_QUERY:
77 return 1;
78 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
79 return 1;
80 case PIPE_CAP_TEXTURE_MIRROR_REPEAT:
81 return 1;
82 case PIPE_CAP_TEXTURE_SHADOW_MAP:
83 return 1;
84 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
85 return 13; /* max 4Kx4K */
86 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
87 return 9; /* max 256x256x256 */
88 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
89 return 13; /* max 4Kx4K */
90 case PIPE_CAP_TGSI_CONT_SUPPORTED:
91 return 1;
92 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
93 return 1;
94 default:
95 return 0;
96 }
97 }
98
99
100 static float
101 softpipe_get_paramf(struct pipe_screen *screen, int param)
102 {
103 switch (param) {
104 case PIPE_CAP_MAX_LINE_WIDTH:
105 /* fall-through */
106 case PIPE_CAP_MAX_LINE_WIDTH_AA:
107 return 255.0; /* arbitrary */
108 case PIPE_CAP_MAX_POINT_WIDTH:
109 /* fall-through */
110 case PIPE_CAP_MAX_POINT_WIDTH_AA:
111 return 255.0; /* arbitrary */
112 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
113 return 16.0; /* not actually signficant at this time */
114 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
115 return 16.0; /* arbitrary */
116 default:
117 return 0;
118 }
119 }
120
121
122 /**
123 * Query format support for creating a texture, drawing surface, etc.
124 * \param format the format to test
125 * \param type one of PIPE_TEXTURE, PIPE_SURFACE
126 */
127 static boolean
128 softpipe_is_format_supported( struct pipe_screen *screen,
129 enum pipe_format format,
130 enum pipe_texture_target target,
131 unsigned tex_usage,
132 unsigned geom_flags )
133 {
134 assert(target == PIPE_TEXTURE_1D ||
135 target == PIPE_TEXTURE_2D ||
136 target == PIPE_TEXTURE_3D ||
137 target == PIPE_TEXTURE_CUBE);
138
139 switch(format) {
140 case PIPE_FORMAT_L16_UNORM:
141 case PIPE_FORMAT_YCBCR_REV:
142 case PIPE_FORMAT_YCBCR:
143 case PIPE_FORMAT_DXT1_RGB:
144 case PIPE_FORMAT_DXT1_RGBA:
145 case PIPE_FORMAT_DXT3_RGBA:
146 case PIPE_FORMAT_DXT5_RGBA:
147 case PIPE_FORMAT_Z32_FLOAT:
148 case PIPE_FORMAT_R8G8_SNORM:
149 case PIPE_FORMAT_B6UG5SR5S_NORM:
150 case PIPE_FORMAT_X8UB8UG8SR8S_NORM:
151 case PIPE_FORMAT_A8B8G8R8_SNORM:
152 case PIPE_FORMAT_NONE:
153 return FALSE;
154 default:
155 return TRUE;
156 }
157 }
158
159
160 static void
161 softpipe_destroy_screen( struct pipe_screen *screen )
162 {
163 struct pipe_winsys *winsys = screen->winsys;
164
165 if(winsys->destroy)
166 winsys->destroy(winsys);
167
168 FREE(screen);
169 }
170
171
172
173 /**
174 * Create a new pipe_screen object
175 * Note: we're not presently subclassing pipe_screen (no softpipe_screen).
176 */
177 struct pipe_screen *
178 softpipe_create_screen(struct pipe_winsys *winsys)
179 {
180 struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen);
181
182 if (!screen)
183 return NULL;
184
185 screen->base.winsys = winsys;
186
187 screen->base.destroy = softpipe_destroy_screen;
188
189 screen->base.get_name = softpipe_get_name;
190 screen->base.get_vendor = softpipe_get_vendor;
191 screen->base.get_param = softpipe_get_param;
192 screen->base.get_paramf = softpipe_get_paramf;
193 screen->base.is_format_supported = softpipe_is_format_supported;
194
195 softpipe_init_screen_texture_funcs(&screen->base);
196 u_simple_screen_init(&screen->base);
197
198 return &screen->base;
199 }