diff options
author | José Fonseca <[email protected]> | 2011-04-27 12:02:08 +0100 |
---|---|---|
committer | Brian Paul <[email protected]> | 2011-09-23 07:58:47 -0600 |
commit | 974b6413f4540d73c21c092cc0a62abb6d546e21 (patch) | |
tree | 6495d855498199c6fbdd61591bc6ec8b02d550e3 /src | |
parent | ffeed5da6e568836867f09f1acb7ce660d091d4a (diff) |
svga: Cleanup format capability checking.
Accurately describe what operations are supported when a format caps
entry is not advertised by the host, and which formats are never
supported, instead of making ad-hoc and often incorrect assumptions.
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/drivers/svga/Makefile.sources | 1 | ||||
-rw-r--r-- | src/gallium/drivers/svga/svga_format.c | 562 | ||||
-rw-r--r-- | src/gallium/drivers/svga/svga_format.h | 49 | ||||
-rw-r--r-- | src/gallium/drivers/svga/svga_resource_texture.c | 84 | ||||
-rw-r--r-- | src/gallium/drivers/svga/svga_resource_texture.h | 10 | ||||
-rw-r--r-- | src/gallium/drivers/svga/svga_sampler_view.c | 1 | ||||
-rw-r--r-- | src/gallium/drivers/svga/svga_screen.c | 164 | ||||
-rw-r--r-- | src/gallium/drivers/svga/svga_surface.c | 4 |
8 files changed, 683 insertions, 192 deletions
diff --git a/src/gallium/drivers/svga/Makefile.sources b/src/gallium/drivers/svga/Makefile.sources index a4c4a441f8d..5e714fcb5f5 100644 --- a/src/gallium/drivers/svga/Makefile.sources +++ b/src/gallium/drivers/svga/Makefile.sources @@ -7,6 +7,7 @@ C_SOURCES := \ svga_draw.c \ svga_draw_arrays.c \ svga_draw_elements.c \ + svga_format.c \ svga_pipe_blend.c \ svga_pipe_blit.c \ svga_pipe_clear.c \ diff --git a/src/gallium/drivers/svga/svga_format.c b/src/gallium/drivers/svga/svga_format.c new file mode 100644 index 00000000000..1b3f716a333 --- /dev/null +++ b/src/gallium/drivers/svga/svga_format.c @@ -0,0 +1,562 @@ +/********************************************************** + * Copyright 2011 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#include "pipe/p_format.h" +#include "util/u_debug.h" +#include "util/u_memory.h" + +#include "svga_winsys.h" +#include "svga_screen.h" +#include "svga_format.h" + + +/* + * Translate from gallium format to SVGA3D format. + */ +SVGA3dSurfaceFormat +svga_translate_format(struct svga_screen *ss, + enum pipe_format format, + unsigned bind) +{ + switch(format) { + + case PIPE_FORMAT_B8G8R8A8_UNORM: + return SVGA3D_A8R8G8B8; + case PIPE_FORMAT_B8G8R8X8_UNORM: + return SVGA3D_X8R8G8B8; + + /* Required for GL2.1: + */ + case PIPE_FORMAT_B8G8R8A8_SRGB: + return SVGA3D_A8R8G8B8; + + case PIPE_FORMAT_B5G6R5_UNORM: + return SVGA3D_R5G6B5; + case PIPE_FORMAT_B5G5R5A1_UNORM: + return SVGA3D_A1R5G5B5; + case PIPE_FORMAT_B4G4R4A4_UNORM: + return SVGA3D_A4R4G4B4; + + case PIPE_FORMAT_Z16_UNORM: + return bind & PIPE_BIND_SAMPLER_VIEW ? ss->depth.z16 : SVGA3D_Z_D16; + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + return bind & PIPE_BIND_SAMPLER_VIEW ? ss->depth.s8z24 : SVGA3D_Z_D24S8; + case PIPE_FORMAT_X8Z24_UNORM: + return bind & PIPE_BIND_SAMPLER_VIEW ? ss->depth.x8z24 : SVGA3D_Z_D24X8; + + case PIPE_FORMAT_A8_UNORM: + return SVGA3D_ALPHA8; + case PIPE_FORMAT_L8_UNORM: + return SVGA3D_LUMINANCE8; + + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + return SVGA3D_DXT1; + case PIPE_FORMAT_DXT3_RGBA: + return SVGA3D_DXT3; + case PIPE_FORMAT_DXT5_RGBA: + return SVGA3D_DXT5; + + case PIPE_FORMAT_Z32_UNORM: + /* SVGA3D_Z_D32 is not yet unsupported */ + /* fall-through */ + default: + return SVGA3D_FORMAT_INVALID; + } +} + + +/* + * Format capability description entry. + */ +struct format_cap { + SVGA3dSurfaceFormat format; + + /* + * Capability index corresponding to the format. + */ + SVGA3dDevCapIndex index; + + /* + * Mask of supported SVGA3dFormatOp operations, to be inferred when the + * capability is not explicitly present. + */ + uint32 defaultOperations; +}; + + +/* + * Format capability description table. + * + * Ordererd by increasing SVGA3dSurfaceFormat value, but with gaps. + */ +static const struct format_cap format_cap_table[] = { + { + SVGA3D_X8R8G8B8, + SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_DISPLAYMODE | + SVGA3DFORMAT_OP_3DACCELERATION | + SVGA3DFORMAT_OP_CONVERT_TO_ARGB | + SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_SRGBWRITE | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + { + SVGA3D_A8R8G8B8, + SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_CONVERT_TO_ARGB | + SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_SRGBWRITE | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + { + SVGA3D_R5G6B5, + SVGA3D_DEVCAP_SURFACEFMT_R5G6B5, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_DISPLAYMODE | + SVGA3DFORMAT_OP_3DACCELERATION | + SVGA3DFORMAT_OP_CONVERT_TO_ARGB | + SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_SRGBWRITE | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + { + SVGA3D_X1R5G5B5, + SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_CONVERT_TO_ARGB | + SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_SRGBWRITE | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + { + SVGA3D_A1R5G5B5, + SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_CONVERT_TO_ARGB | + SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_SRGBWRITE | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + { + SVGA3D_A4R4G4B4, + SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_SRGBWRITE | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + /* + * SVGA3D_Z_D32 is not yet supported, and has no corresponding + * SVGA3D_DEVCAP_xxx. + */ + { + SVGA3D_Z_D16, + SVGA3D_DEVCAP_SURFACEFMT_Z_D16, + SVGA3DFORMAT_OP_ZSTENCIL | + SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH + }, + { + SVGA3D_Z_D24S8, + SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8, + SVGA3DFORMAT_OP_ZSTENCIL | + SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH + }, + { + SVGA3D_Z_D15S1, + SVGA3D_DEVCAP_MAX, + SVGA3DFORMAT_OP_ZSTENCIL | + SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH + }, + { + SVGA3D_LUMINANCE8, + SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + { + SVGA3D_LUMINANCE8_ALPHA8, + SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8_ALPHA8, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + /* + * SVGA3D_LUMINANCE4_ALPHA4 is not supported, and has no corresponding + * SVGA3D_DEVCAP_xxx. + */ + { + SVGA3D_LUMINANCE16, + SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE16, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + { + SVGA3D_DXT1, + SVGA3D_DEVCAP_SURFACEFMT_DXT1, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + { + SVGA3D_DXT2, + SVGA3D_DEVCAP_SURFACEFMT_DXT2, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + { + SVGA3D_DXT3, + SVGA3D_DEVCAP_SURFACEFMT_DXT3, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + { + SVGA3D_DXT4, + SVGA3D_DEVCAP_SURFACEFMT_DXT4, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + { + SVGA3D_DXT5, + SVGA3D_DEVCAP_SURFACEFMT_DXT5, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + { + SVGA3D_BUMPU8V8, + SVGA3D_DEVCAP_SURFACEFMT_BUMPU8V8, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_BUMPMAP | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + /* + * SVGA3D_BUMPL6V5U5 is unsupported; it has no corresponding + * SVGA3D_DEVCAP_xxx. + */ + { + SVGA3D_BUMPX8L8V8U8, + SVGA3D_DEVCAP_SURFACEFMT_BUMPX8L8V8U8, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_BUMPMAP | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + /* + * SVGA3D_BUMPL8V8U8 is unsupported; it has no corresponding + * SVGA3D_DEVCAP_xxx. SVGA3D_BUMPX8L8V8U8 should be used instead. + */ + { + SVGA3D_ARGB_S10E5, + SVGA3D_DEVCAP_SURFACEFMT_ARGB_S10E5, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_SRGBWRITE | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + { + SVGA3D_ARGB_S23E8, + SVGA3D_DEVCAP_SURFACEFMT_ARGB_S23E8, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_SRGBWRITE | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + { + SVGA3D_A2R10G10B10, + SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_CONVERT_TO_ARGB | + SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_SRGBWRITE | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + /* + * SVGA3D_V8U8 is unsupported; it has no corresponding + * SVGA3D_DEVCAP_xxx. SVGA3D_BUMPU8V8 should be used instead. + */ + { + SVGA3D_Q8W8V8U8, + SVGA3D_DEVCAP_SURFACEFMT_Q8W8V8U8, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_BUMPMAP | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + { + SVGA3D_CxV8U8, + SVGA3D_DEVCAP_SURFACEFMT_CxV8U8, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_BUMPMAP | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + /* + * SVGA3D_X8L8V8U8 is unsupported; it has no corresponding + * SVGA3D_DEVCAP_xxx. SVGA3D_BUMPX8L8V8U8 should be used instead. + */ + { + SVGA3D_A2W10V10U10, + SVGA3D_DEVCAP_SURFACEFMT_A2W10V10U10, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_BUMPMAP | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + { + SVGA3D_ALPHA8, + SVGA3D_DEVCAP_SURFACEFMT_ALPHA8, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + { + SVGA3D_R_S10E5, + SVGA3D_DEVCAP_SURFACEFMT_R_S10E5, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_SRGBWRITE | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + { + SVGA3D_R_S23E8, + SVGA3D_DEVCAP_SURFACEFMT_R_S23E8, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_SRGBWRITE | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + { + SVGA3D_RG_S10E5, + SVGA3D_DEVCAP_SURFACEFMT_RG_S10E5, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_SRGBWRITE | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + { + SVGA3D_RG_S23E8, + SVGA3D_DEVCAP_SURFACEFMT_RG_S23E8, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SRGBREAD | + SVGA3DFORMAT_OP_SRGBWRITE | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + /* + * SVGA3D_BUFFER is a placeholder format for index/vertex buffers. + */ + { + SVGA3D_Z_D24X8, + SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8, + SVGA3DFORMAT_OP_ZSTENCIL | + SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH + }, + { + SVGA3D_V16U16, + SVGA3D_DEVCAP_SURFACEFMT_V16U16, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_BUMPMAP | + SVGA3DFORMAT_OP_OFFSCREENPLAIN + }, + { + SVGA3D_G16R16, + SVGA3D_DEVCAP_SURFACEFMT_G16R16, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + { + SVGA3D_A16B16G16R16, + SVGA3D_DEVCAP_SURFACEFMT_A16B16G16R16, + SVGA3DFORMAT_OP_TEXTURE | + SVGA3DFORMAT_OP_CUBETEXTURE | + SVGA3DFORMAT_OP_VOLUMETEXTURE | + SVGA3DFORMAT_OP_OFFSCREENPLAIN | + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET + }, + { + SVGA3D_UYVY, + SVGA3D_DEVCAP_SURFACEFMT_UYVY, + 0 + }, + { + SVGA3D_YUY2, + SVGA3D_DEVCAP_SURFACEFMT_YUY2, + 0 + }, + { + SVGA3D_NV12, + SVGA3D_DEVCAP_SURFACEFMT_NV12, + 0 + }, + { + SVGA3D_AYUV, + SVGA3D_DEVCAP_SURFACEFMT_AYUV, + 0 + }, + { + SVGA3D_BC4_UNORM, + SVGA3D_DEVCAP_SURFACEFMT_BC4_UNORM, + 0 + }, + { + SVGA3D_BC5_UNORM, + SVGA3D_DEVCAP_SURFACEFMT_BC5_UNORM, + 0 + }, + { + SVGA3D_Z_DF16, + SVGA3D_DEVCAP_SURFACEFMT_Z_DF16, + 0 + }, + { + SVGA3D_Z_DF24, + SVGA3D_DEVCAP_SURFACEFMT_Z_DF24, + 0 + }, + { + SVGA3D_Z_D24S8_INT, + SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8_INT, + 0 + }, +}; + + +/* + * Get format capabilities from the host. It takes in consideration + * deprecated/unsupported formats, and formats which are implicitely assumed to + * be supported when the host does not provide an explicit capability entry. + */ +void +svga_get_format_cap(struct svga_screen *ss, + SVGA3dSurfaceFormat format, + SVGA3dSurfaceFormatCaps *caps) +{ + const struct format_cap *entry; + + for (entry = format_cap_table; entry < format_cap_table + Elements(format_cap_table); ++entry) { + if (entry->format == format) { + struct svga_winsys_screen *sws = ss->sws; + SVGA3dDevCapResult result; + + if (sws->get_cap(sws, entry->index, &result)) { + /* Explicitly advertised format */ + caps->value = result.u; + } else { + /* Implicitly advertised format -- use default caps */ + caps->value = entry->defaultOperations; + } + + return; + } + } + + /* Unsupported format */ + caps->value = 0; +} diff --git a/src/gallium/drivers/svga/svga_format.h b/src/gallium/drivers/svga/svga_format.h new file mode 100644 index 00000000000..9ea9e05631d --- /dev/null +++ b/src/gallium/drivers/svga/svga_format.h @@ -0,0 +1,49 @@ +/********************************************************** + * Copyright 2011 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +#ifndef SVGA_FORMAT_H_ +#define SVGA_FORMAT_H_ + + +#include "svga_types.h" +#include "svga_reg.h" +#include "svga3d_reg.h" + + +struct svga_screen; + + +enum SVGA3dSurfaceFormat +svga_translate_format(struct svga_screen *ss, + enum pipe_format format, + unsigned bind); + +void +svga_get_format_cap(struct svga_screen *ss, + SVGA3dSurfaceFormat format, + SVGA3dSurfaceFormatCaps *caps); + + +#endif /* SVGA_FORMAT_H_ */ diff --git a/src/gallium/drivers/svga/svga_resource_texture.c b/src/gallium/drivers/svga/svga_resource_texture.c index 8297f830a61..c8cb4f9b3b8 100644 --- a/src/gallium/drivers/svga/svga_resource_texture.c +++ b/src/gallium/drivers/svga/svga_resource_texture.c @@ -33,6 +33,7 @@ #include "util/u_math.h" #include "util/u_memory.h" +#include "svga_format.h" #include "svga_screen.h" #include "svga_context.h" #include "svga_resource_texture.h" @@ -48,89 +49,6 @@ #define SVGA3D_SURFACE_HINT_SCANOUT (1 << 9) -/* - * Helper function and arrays - */ - -SVGA3dSurfaceFormat -svga_translate_format(struct svga_screen *ss, - enum pipe_format format, - unsigned bind) -{ - switch(format) { - - case PIPE_FORMAT_B8G8R8A8_UNORM: - return SVGA3D_A8R8G8B8; - case PIPE_FORMAT_B8G8R8X8_UNORM: - return SVGA3D_X8R8G8B8; - - /* Required for GL2.1: - */ - case PIPE_FORMAT_B8G8R8A8_SRGB: - return SVGA3D_A8R8G8B8; - - case PIPE_FORMAT_B5G6R5_UNORM: - return SVGA3D_R5G6B5; - case PIPE_FORMAT_B5G5R5A1_UNORM: - return SVGA3D_A1R5G5B5; - case PIPE_FORMAT_B4G4R4A4_UNORM: - return SVGA3D_A4R4G4B4; - - - /* XXX: Doesn't seem to work properly. - case PIPE_FORMAT_Z32_UNORM: - return SVGA3D_Z_D32; - */ - case PIPE_FORMAT_Z16_UNORM: - return bind & PIPE_BIND_SAMPLER_VIEW ? ss->depth.z16 : SVGA3D_Z_D16; - case PIPE_FORMAT_S8_USCALED_Z24_UNORM: - return bind & PIPE_BIND_SAMPLER_VIEW ? ss->depth.s8z24 : SVGA3D_Z_D24S8; - case PIPE_FORMAT_X8Z24_UNORM: - return bind & PIPE_BIND_SAMPLER_VIEW ? ss->depth.x8z24 : SVGA3D_Z_D24X8; - - case PIPE_FORMAT_A8_UNORM: - return SVGA3D_ALPHA8; - case PIPE_FORMAT_L8_UNORM: - return SVGA3D_LUMINANCE8; - - case PIPE_FORMAT_DXT1_RGB: - case PIPE_FORMAT_DXT1_RGBA: - return SVGA3D_DXT1; - case PIPE_FORMAT_DXT3_RGBA: - return SVGA3D_DXT3; - case PIPE_FORMAT_DXT5_RGBA: - return SVGA3D_DXT5; - - default: - return SVGA3D_FORMAT_INVALID; - } -} - - -SVGA3dSurfaceFormat -svga_translate_format_render(struct svga_screen *ss, - enum pipe_format format, - unsigned bind) -{ - switch(format) { - case PIPE_FORMAT_B8G8R8A8_UNORM: - case PIPE_FORMAT_B8G8R8X8_UNORM: - case PIPE_FORMAT_B5G5R5A1_UNORM: - case PIPE_FORMAT_B4G4R4A4_UNORM: - case PIPE_FORMAT_B5G6R5_UNORM: - case PIPE_FORMAT_S8_USCALED_Z24_UNORM: - case PIPE_FORMAT_X8Z24_UNORM: - case PIPE_FORMAT_Z32_UNORM: - case PIPE_FORMAT_Z16_UNORM: - case PIPE_FORMAT_L8_UNORM: - return svga_translate_format(ss, format, bind); - - default: - return SVGA3D_FORMAT_INVALID; - } -} - - static INLINE void svga_transfer_dma_band(struct svga_context *svga, struct svga_transfer *st, diff --git a/src/gallium/drivers/svga/svga_resource_texture.h b/src/gallium/drivers/svga/svga_resource_texture.h index eb85c698c98..57ed0f5a93d 100644 --- a/src/gallium/drivers/svga/svga_resource_texture.h +++ b/src/gallium/drivers/svga/svga_resource_texture.h @@ -126,15 +126,5 @@ svga_texture_from_handle(struct pipe_screen * screen, -enum SVGA3dSurfaceFormat -svga_translate_format(struct svga_screen *ss, - enum pipe_format format, - unsigned bind); - -enum SVGA3dSurfaceFormat -svga_translate_format_render(struct svga_screen *ss, - enum pipe_format format, - unsigned bind); - #endif /* SVGA_TEXTURE_H */ diff --git a/src/gallium/drivers/svga/svga_sampler_view.c b/src/gallium/drivers/svga/svga_sampler_view.c index 56acffee6d0..b756b07b4f6 100644 --- a/src/gallium/drivers/svga/svga_sampler_view.c +++ b/src/gallium/drivers/svga/svga_sampler_view.c @@ -34,6 +34,7 @@ #include "util/u_memory.h" #include "util/u_string.h" +#include "svga_format.h" #include "svga_screen.h" #include "svga_context.h" #include "svga_resource_texture.h" diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c index 98479f0d84e..3a1ac9e1d93 100644 --- a/src/gallium/drivers/svga/svga_screen.c +++ b/src/gallium/drivers/svga/svga_screen.c @@ -31,6 +31,7 @@ #include "svga_winsys.h" #include "svga_public.h" #include "svga_context.h" +#include "svga_format.h" #include "svga_screen.h" #include "svga_resource_texture.h" #include "svga_resource.h" @@ -309,41 +310,6 @@ static int svga_get_shader_param(struct pipe_screen *screen, unsigned shader, en return 0; } -static INLINE SVGA3dDevCapIndex -svga_translate_format_cap(enum pipe_format format) -{ - switch(format) { - - case PIPE_FORMAT_B8G8R8A8_UNORM: - return SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8; - case PIPE_FORMAT_B8G8R8X8_UNORM: - return SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8; - - case PIPE_FORMAT_B5G6R5_UNORM: - return SVGA3D_DEVCAP_SURFACEFMT_R5G6B5; - case PIPE_FORMAT_B5G5R5A1_UNORM: - return SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5; - case PIPE_FORMAT_B4G4R4A4_UNORM: - return SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4; - - case PIPE_FORMAT_A8_UNORM: - return SVGA3D_DEVCAP_SURFACEFMT_ALPHA8; - case PIPE_FORMAT_L8_UNORM: - return SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8; - - case PIPE_FORMAT_DXT1_RGB: - case PIPE_FORMAT_DXT1_RGBA: - return SVGA3D_DEVCAP_SURFACEFMT_DXT1; - case PIPE_FORMAT_DXT3_RGBA: - return SVGA3D_DEVCAP_SURFACEFMT_DXT3; - case PIPE_FORMAT_DXT5_RGBA: - return SVGA3D_DEVCAP_SURFACEFMT_DXT5; - - default: - return SVGA3D_DEVCAP_MAX; - } -} - static boolean svga_is_format_supported( struct pipe_screen *screen, @@ -353,18 +319,32 @@ svga_is_format_supported( struct pipe_screen *screen, unsigned tex_usage) { struct svga_screen *ss = svga_screen(screen); - struct svga_winsys_screen *sws = ss->sws; - SVGA3dDevCapIndex index; - SVGA3dDevCapResult result; + SVGA3dSurfaceFormat svga_format; + SVGA3dSurfaceFormatCaps caps; + SVGA3dSurfaceFormatCaps mask; assert(tex_usage); - if (sample_count > 1) + if (sample_count > 1) { return FALSE; + } - /* Override host capabilities */ - if (tex_usage & PIPE_BIND_RENDER_TARGET) { - switch(format) { + svga_format = svga_translate_format(ss, format, tex_usage); + if (svga_format == SVGA3D_FORMAT_INVALID) { + return FALSE; + } + + /* + * Override host capabilities, so that we end up with the same + * visuals for all virtual hardware implementations. + */ + + if (tex_usage & PIPE_BIND_DISPLAY_TARGET) { + switch (svga_format) { + case SVGA3D_A8R8G8B8: + case SVGA3D_X8R8G8B8: + case SVGA3D_R5G6B5: + break; /* Often unsupported/problematic. This means we end up with the same * visuals for all virtual hardware implementations. @@ -374,39 +354,28 @@ svga_is_format_supported( struct pipe_screen *screen, return FALSE; default: - break; + return FALSE; } } - /* Try to query the host */ - index = svga_translate_format_cap(format); - if( index < SVGA3D_DEVCAP_MAX && - sws->get_cap(sws, index, &result) ) - { - SVGA3dSurfaceFormatCaps mask; - - mask.value = 0; - if (tex_usage & PIPE_BIND_RENDER_TARGET) - mask.offscreenRenderTarget = 1; - if (tex_usage & PIPE_BIND_DEPTH_STENCIL) - mask.zStencil = 1; - if (tex_usage & PIPE_BIND_SAMPLER_VIEW) - mask.texture = 1; - - if ((result.u & mask.value) == mask.value) - return TRUE; - else - return FALSE; + /* + * Query the host capabilities. + */ + + svga_get_format_cap(ss, svga_format, &caps); + + mask.value = 0; + if (tex_usage & PIPE_BIND_RENDER_TARGET) { + mask.offscreenRenderTarget = 1; + } + if (tex_usage & PIPE_BIND_DEPTH_STENCIL) { + mask.zStencil = 1; + } + if (tex_usage & PIPE_BIND_SAMPLER_VIEW) { + mask.texture = 1; } - /* Use our translate functions directly rather than relying on a - * duplicated list of supported formats which is prone to getting - * out of sync: - */ - if(tex_usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL)) - return svga_translate_format_render(ss, format, tex_usage) != SVGA3D_FORMAT_INVALID; - else - return svga_translate_format(ss, format, tex_usage) != SVGA3D_FORMAT_INVALID; + return (caps.value & mask.value) == mask.value; } @@ -529,39 +498,40 @@ svga_screen_create(struct svga_winsys_screen *sws) */ { + boolean has_df16, has_df24, has_d24s8_int; + SVGA3dSurfaceFormatCaps caps; SVGA3dSurfaceFormatCaps mask; mask.value = 0; mask.zStencil = 1; mask.texture = 1; - svgascreen->depth.z16 = - sws->get_cap(sws, SVGA3D_DEVCAP_SURFACEFMT_Z_D16, &result) && - (result.u & mask.value) == mask.value ? - SVGA3D_Z_D16 : SVGA3D_FORMAT_INVALID; - svgascreen->depth.z16 = - sws->get_cap(sws, SVGA3D_DEVCAP_SURFACEFMT_Z_DF16, &result) && - (result.u & mask.value) == mask.value ? - SVGA3D_Z_DF16 : svgascreen->depth.z16; - - svgascreen->depth.x8z24 = - sws->get_cap(sws, SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8, &result) && - (result.u & mask.value) == mask.value ? - SVGA3D_Z_D24X8 : SVGA3D_FORMAT_INVALID; - svgascreen->depth.x8z24 = - sws->get_cap(sws, SVGA3D_DEVCAP_SURFACEFMT_Z_DF24, &result) && - (result.u & mask.value) == mask.value ? - SVGA3D_Z_DF24 : svgascreen->depth.x8z24; - - svgascreen->depth.s8z24 = - sws->get_cap(sws, SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8, &result) && - (result.u & mask.value) == mask.value ? - SVGA3D_Z_D24S8 : SVGA3D_FORMAT_INVALID; - svgascreen->depth.s8z24 = - sws->get_cap(sws, SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8_INT, &result) && - (result.u & mask.value) == mask.value ? - SVGA3D_Z_D24S8_INT : svgascreen->depth.s8z24; - } + svgascreen->depth.z16 = SVGA3D_Z_D16; + svgascreen->depth.x8z24 = SVGA3D_Z_D24X8; + svgascreen->depth.s8z24 = SVGA3D_Z_D24S8; + + svga_get_format_cap(svgascreen, SVGA3D_Z_DF16, &caps); + has_df16 = (caps.value & mask.value) == mask.value; + + svga_get_format_cap(svgascreen, SVGA3D_Z_DF24, &caps); + has_df24 = (caps.value & mask.value) == mask.value; + + svga_get_format_cap(svgascreen, SVGA3D_Z_D24S8_INT, &caps); + has_d24s8_int = (caps.value & mask.value) == mask.value; + /* XXX: We might want some other logic here. + * Like if we only have d24s8_int we should + * emulate the other formats with that. + */ + if (has_df16) { + svgascreen->depth.z16 = SVGA3D_Z_DF16; + } + if (has_df24) { + svgascreen->depth.x8z24 = SVGA3D_Z_DF24; + } + if (has_d24s8_int) { + svgascreen->depth.s8z24 = SVGA3D_Z_D24S8_INT; + } + } #if 1 /* Shader model 2.0 is unsupported at the moment. */ diff --git a/src/gallium/drivers/svga/svga_surface.c b/src/gallium/drivers/svga/svga_surface.c index 00973263112..c9f1370b39e 100644 --- a/src/gallium/drivers/svga/svga_surface.c +++ b/src/gallium/drivers/svga/svga_surface.c @@ -33,6 +33,7 @@ #include "util/u_math.h" #include "util/u_memory.h" +#include "svga_format.h" #include "svga_screen.h" #include "svga_context.h" #include "svga_resource_texture.h" @@ -225,7 +226,6 @@ svga_create_surface(struct pipe_context *pipe, if (!render) { flags = SVGA3D_SURFACE_HINT_TEXTURE; - format = svga_translate_format(ss, surf_tmpl->format, surf_tmpl->usage); } else { if (surf_tmpl->usage & PIPE_BIND_RENDER_TARGET) { flags = SVGA3D_SURFACE_HINT_RENDERTARGET; @@ -233,9 +233,9 @@ svga_create_surface(struct pipe_context *pipe, if (surf_tmpl->usage & PIPE_BIND_DEPTH_STENCIL) { flags = SVGA3D_SURFACE_HINT_DEPTHSTENCIL; } - format = svga_translate_format_render(ss, surf_tmpl->format, surf_tmpl->usage); } + format = svga_translate_format(ss, surf_tmpl->format, surf_tmpl->usage); assert(format != SVGA3D_FORMAT_INVALID); if (svga_screen(screen)->debug.force_surface_view) |