1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 #include "util/u_memory.h"
30 #include "util/u_format.h"
31 #include "util/u_format_s3tc.h"
32 #include "pipe/p_defines.h"
33 #include "pipe/p_screen.h"
34 #include "draw/draw_context.h"
36 #include "state_tracker/sw_winsys.h"
37 #include "tgsi/tgsi_exec.h"
39 #include "sp_texture.h"
40 #include "sp_screen.h"
41 #include "sp_context.h"
43 #include "sp_public.h"
47 softpipe_get_vendor(struct pipe_screen
*screen
)
49 return "VMware, Inc.";
54 softpipe_get_name(struct pipe_screen
*screen
)
61 softpipe_get_param(struct pipe_screen
*screen
, enum pipe_cap param
)
64 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS
:
65 return PIPE_MAX_SAMPLERS
;
66 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS
:
68 /* Softpipe doesn't yet know how to tell draw/llvm about textures */
71 return PIPE_MAX_VERTEX_SAMPLERS
;
73 case PIPE_CAP_MAX_COMBINED_SAMPLERS
:
74 return PIPE_MAX_SAMPLERS
+ PIPE_MAX_VERTEX_SAMPLERS
;
75 case PIPE_CAP_NPOT_TEXTURES
:
77 case PIPE_CAP_TWO_SIDED_STENCIL
:
83 case PIPE_CAP_ANISOTROPIC_FILTER
:
85 case PIPE_CAP_POINT_SPRITE
:
87 case PIPE_CAP_MAX_RENDER_TARGETS
:
88 return PIPE_MAX_COLOR_BUFS
;
89 case PIPE_CAP_OCCLUSION_QUERY
:
91 case PIPE_CAP_TIMER_QUERY
:
93 case PIPE_CAP_TEXTURE_MIRROR_CLAMP
:
95 case PIPE_CAP_TEXTURE_MIRROR_REPEAT
:
97 case PIPE_CAP_TEXTURE_SHADOW_MAP
:
99 case PIPE_CAP_TEXTURE_SWIZZLE
:
101 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS
:
102 return SP_MAX_TEXTURE_2D_LEVELS
;
103 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS
:
104 return SP_MAX_TEXTURE_3D_LEVELS
;
105 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS
:
106 return SP_MAX_TEXTURE_2D_LEVELS
;
107 case PIPE_CAP_BLEND_EQUATION_SEPARATE
:
109 case PIPE_CAP_INDEP_BLEND_ENABLE
:
111 case PIPE_CAP_INDEP_BLEND_FUNC
:
113 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT
:
114 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT
:
115 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER
:
116 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER
:
118 case PIPE_CAP_STREAM_OUTPUT
:
120 case PIPE_CAP_PRIMITIVE_RESTART
:
122 case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE
:
124 case PIPE_CAP_SHADER_STENCIL_EXPORT
:
126 case PIPE_CAP_TGSI_INSTANCEID
:
127 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR
:
129 case PIPE_CAP_ARRAY_TEXTURES
:
137 softpipe_get_shader_param(struct pipe_screen
*screen
, unsigned shader
, enum pipe_shader_cap param
)
141 case PIPE_SHADER_FRAGMENT
:
142 return tgsi_exec_get_shader_param(param
);
143 case PIPE_SHADER_VERTEX
:
144 case PIPE_SHADER_GEOMETRY
:
145 return draw_get_shader_param(shader
, param
);
152 softpipe_get_paramf(struct pipe_screen
*screen
, enum pipe_cap param
)
155 case PIPE_CAP_MAX_LINE_WIDTH
:
157 case PIPE_CAP_MAX_LINE_WIDTH_AA
:
158 return 255.0; /* arbitrary */
159 case PIPE_CAP_MAX_POINT_WIDTH
:
161 case PIPE_CAP_MAX_POINT_WIDTH_AA
:
162 return 255.0; /* arbitrary */
163 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY
:
165 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS
:
166 return 16.0; /* arbitrary */
174 * Query format support for creating a texture, drawing surface, etc.
175 * \param format the format to test
176 * \param type one of PIPE_TEXTURE, PIPE_SURFACE
179 softpipe_is_format_supported( struct pipe_screen
*screen
,
180 enum pipe_format format
,
181 enum pipe_texture_target target
,
182 unsigned sample_count
,
185 struct sw_winsys
*winsys
= softpipe_screen(screen
)->winsys
;
186 const struct util_format_description
*format_desc
;
188 assert(target
== PIPE_BUFFER
||
189 target
== PIPE_TEXTURE_1D
||
190 target
== PIPE_TEXTURE_1D_ARRAY
||
191 target
== PIPE_TEXTURE_2D
||
192 target
== PIPE_TEXTURE_2D_ARRAY
||
193 target
== PIPE_TEXTURE_RECT
||
194 target
== PIPE_TEXTURE_3D
||
195 target
== PIPE_TEXTURE_CUBE
);
197 format_desc
= util_format_description(format
);
201 if (sample_count
> 1)
204 if (bind
& (PIPE_BIND_DISPLAY_TARGET
|
207 if(!winsys
->is_displaytarget_format_supported(winsys
, bind
, format
))
211 if (bind
& PIPE_BIND_RENDER_TARGET
) {
212 if (format_desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
)
216 * Although possible, it is unnatural to render into compressed or YUV
217 * surfaces. So disable these here to avoid going into weird paths
218 * inside the state trackers.
220 if (format_desc
->block
.width
!= 1 ||
221 format_desc
->block
.height
!= 1)
225 if (bind
& PIPE_BIND_DEPTH_STENCIL
) {
226 if (format_desc
->colorspace
!= UTIL_FORMAT_COLORSPACE_ZS
)
230 * TODO: Unfortunately we cannot render into anything more than 32 bits
231 * because we encode depth and stencil clear values into a 32bit word.
233 if (format_desc
->block
.bits
> 32)
237 * TODO: eliminate this restriction
239 if (format
== PIPE_FORMAT_Z32_FLOAT
)
244 * All other operations (sampling, transfer, etc).
247 if (format_desc
->layout
== UTIL_FORMAT_LAYOUT_S3TC
) {
248 return util_format_s3tc_enabled
;
252 * Everything else should be supported by u_format.
259 softpipe_destroy_screen( struct pipe_screen
*screen
)
261 struct softpipe_screen
*sp_screen
= softpipe_screen(screen
);
262 struct sw_winsys
*winsys
= sp_screen
->winsys
;
265 winsys
->destroy(winsys
);
271 /* This is often overriden by the co-state tracker.
274 softpipe_flush_frontbuffer(struct pipe_screen
*_screen
,
275 struct pipe_resource
*resource
,
276 unsigned level
, unsigned layer
,
277 void *context_private
)
279 struct softpipe_screen
*screen
= softpipe_screen(_screen
);
280 struct sw_winsys
*winsys
= screen
->winsys
;
281 struct softpipe_resource
*texture
= softpipe_resource(resource
);
285 winsys
->displaytarget_display(winsys
, texture
->dt
, context_private
);
289 * Create a new pipe_screen object
290 * Note: we're not presently subclassing pipe_screen (no softpipe_screen).
293 softpipe_create_screen(struct sw_winsys
*winsys
)
295 struct softpipe_screen
*screen
= CALLOC_STRUCT(softpipe_screen
);
300 screen
->winsys
= winsys
;
302 screen
->base
.winsys
= NULL
;
303 screen
->base
.destroy
= softpipe_destroy_screen
;
305 screen
->base
.get_name
= softpipe_get_name
;
306 screen
->base
.get_vendor
= softpipe_get_vendor
;
307 screen
->base
.get_param
= softpipe_get_param
;
308 screen
->base
.get_shader_param
= softpipe_get_shader_param
;
309 screen
->base
.get_paramf
= softpipe_get_paramf
;
310 screen
->base
.is_format_supported
= softpipe_is_format_supported
;
311 screen
->base
.context_create
= softpipe_create_context
;
312 screen
->base
.flush_frontbuffer
= softpipe_flush_frontbuffer
;
314 util_format_s3tc_init();
316 softpipe_init_screen_texture_funcs(&screen
->base
);
317 softpipe_init_screen_fence_funcs(&screen
->base
);
319 return &screen
->base
;