Home | History | Annotate | Download | only in src
      1 /**************************************************************************
      2  *
      3  * Copyright 2010 Luca Barbieri
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining
      6  * a copy of this software and associated documentation files (the
      7  * "Software"), to deal in the Software without restriction, including
      8  * without limitation the rights to use, copy, modify, merge, publish,
      9  * distribute, sublicense, and/or sell copies of the Software, and to
     10  * permit persons to whom the Software is furnished to do so, subject to
     11  * the following conditions:
     12  *
     13  * The above copyright notice and this permission notice (including the
     14  * next paragraph) shall be included in all copies or substantial
     15  * portions of the Software.
     16  *
     17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     20  * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
     21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     24  *
     25  **************************************************************************/
     26 
     27 #include <d3d1xstutil.h>
     28 
     29 /* D3D has to keep binary compatibility, so these tables will always work
     30  * However, Gallium -> D3D conversion must use .[PIPE_xxx] = D3D11_xxx syntax */
     31 
     32 pipe_format dxgi_to_pipe_format[DXGI_FORMAT_COUNT] =
     33 {
     34 	PIPE_FORMAT_NONE,
     35 	PIPE_FORMAT_R32G32B32A32_UINT, /* TYPELESS */
     36 	PIPE_FORMAT_R32G32B32A32_FLOAT,
     37 	PIPE_FORMAT_R32G32B32A32_UINT,
     38 	PIPE_FORMAT_R32G32B32A32_SINT,
     39 	PIPE_FORMAT_R32G32B32_UINT, /* TYPELESS */
     40 	PIPE_FORMAT_R32G32B32_FLOAT,
     41 	PIPE_FORMAT_R32G32B32_UINT,
     42 	PIPE_FORMAT_R32G32B32_SINT,
     43 	PIPE_FORMAT_R16G16B16A16_UINT, /* TYPELESS */
     44 	PIPE_FORMAT_R16G16B16A16_FLOAT,
     45 	PIPE_FORMAT_R16G16B16A16_UNORM,
     46 	PIPE_FORMAT_R16G16B16A16_UINT,
     47 	PIPE_FORMAT_R16G16B16A16_SNORM,
     48 	PIPE_FORMAT_R16G16B16A16_SINT,
     49 	PIPE_FORMAT_R32G32_UINT, /* TYPELESS */
     50 	PIPE_FORMAT_R32G32_FLOAT,
     51 	PIPE_FORMAT_R32G32_UINT,
     52 	PIPE_FORMAT_R32G32_SINT,
     53 	PIPE_FORMAT_Z32_FLOAT_S8X24_UINT, /* PIPE_FORMAT_R32_G8X24_TYPELESS */
     54 	PIPE_FORMAT_Z32_FLOAT_S8X24_UINT,
     55 	PIPE_FORMAT_Z32_FLOAT_S8X24_UINT, /* PIPE_FORMAT_R32_X8X24_FLOAT */
     56 	PIPE_FORMAT_Z32_FLOAT_S8X24_UINT, /* PIPE_FORMAT_X32_G8X24_UINT */
     57 	PIPE_FORMAT_R10G10B10A2_UNORM, /* TYPELESS */
     58 	PIPE_FORMAT_R10G10B10A2_UNORM,
     59 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_R10G10B10A2_UINT */
     60 	PIPE_FORMAT_R11G11B10_FLOAT,
     61 	PIPE_FORMAT_R8G8B8A8_UINT, /* TYPELESS */
     62 	PIPE_FORMAT_R8G8B8A8_UNORM,
     63 	PIPE_FORMAT_R8G8B8A8_SRGB,
     64 	PIPE_FORMAT_R8G8B8A8_UINT,
     65 	PIPE_FORMAT_R8G8B8A8_SNORM,
     66 	PIPE_FORMAT_R8G8B8A8_SINT,
     67 	PIPE_FORMAT_R16G16_UINT, /* TYPELESS */
     68 	PIPE_FORMAT_R16G16_FLOAT,
     69 	PIPE_FORMAT_R16G16_UNORM,
     70 	PIPE_FORMAT_R16G16_UINT,
     71 	PIPE_FORMAT_R16G16_SNORM,
     72 	PIPE_FORMAT_R16G16_SINT,
     73 	PIPE_FORMAT_R32_UINT, /* TYPELESS */
     74 	PIPE_FORMAT_Z32_FLOAT,
     75 	PIPE_FORMAT_R32_FLOAT,
     76 	PIPE_FORMAT_R32_UINT,
     77 	PIPE_FORMAT_R32_SINT,
     78 	PIPE_FORMAT_Z24_UNORM_S8_UINT, /* PIPE_FORMAT_R24G8_TYPELESS */
     79 	PIPE_FORMAT_Z24_UNORM_S8_UINT,
     80 	PIPE_FORMAT_Z24X8_UNORM, /* PIPE_FORMAT_R24X8_UNORM */
     81 	PIPE_FORMAT_Z24_UNORM_S8_UINT, /* PIPE_FORMAT_X24G8_UINT */
     82 	PIPE_FORMAT_R8G8_UINT, /* TYPELESS */
     83 	PIPE_FORMAT_R8G8_UNORM,
     84 	PIPE_FORMAT_R8G8_UINT,
     85 	PIPE_FORMAT_R8G8_SNORM,
     86 	PIPE_FORMAT_R8G8_SINT,
     87 	PIPE_FORMAT_R16_UINT, /* TYPELESS */
     88 	PIPE_FORMAT_R16_FLOAT,
     89 	PIPE_FORMAT_Z16_UNORM,
     90 	PIPE_FORMAT_R16_UNORM,
     91 	PIPE_FORMAT_R16_UINT,
     92 	PIPE_FORMAT_R16_SNORM,
     93 	PIPE_FORMAT_R16_SINT,
     94 	PIPE_FORMAT_R8_UINT, /* TYPELESS */
     95 	PIPE_FORMAT_R8_UNORM,
     96 	PIPE_FORMAT_R8_UINT,
     97 	PIPE_FORMAT_R8_SNORM,
     98 	PIPE_FORMAT_R8_SINT,
     99 	PIPE_FORMAT_A8_UNORM,
    100 	PIPE_FORMAT_R1_UNORM,
    101 	PIPE_FORMAT_R9G9B9E5_FLOAT,
    102 	PIPE_FORMAT_R8G8_B8G8_UNORM,
    103 	PIPE_FORMAT_G8R8_G8B8_UNORM,
    104 	PIPE_FORMAT_DXT1_RGBA, /* TYPELESS */
    105 	PIPE_FORMAT_DXT1_RGBA,
    106 	PIPE_FORMAT_DXT1_SRGBA,
    107 	PIPE_FORMAT_DXT3_RGBA, /* TYPELESS */
    108 	PIPE_FORMAT_DXT3_RGBA,
    109 	PIPE_FORMAT_DXT3_SRGBA,
    110 	PIPE_FORMAT_DXT5_RGBA, /* TYPELESS */
    111 	PIPE_FORMAT_DXT5_RGBA,
    112 	PIPE_FORMAT_DXT5_SRGBA,
    113 	PIPE_FORMAT_RGTC1_UNORM, /* TYPELESS */
    114 	PIPE_FORMAT_RGTC1_UNORM,
    115 	PIPE_FORMAT_RGTC1_SNORM,
    116 	PIPE_FORMAT_RGTC2_UNORM, /* TYPELESS */
    117 	PIPE_FORMAT_RGTC2_UNORM,
    118 	PIPE_FORMAT_RGTC2_SNORM,
    119 	PIPE_FORMAT_B5G6R5_UNORM,
    120 	PIPE_FORMAT_B5G5R5A1_UNORM,
    121 	PIPE_FORMAT_B8G8R8A8_UNORM,
    122 	PIPE_FORMAT_B8G8R8X8_UNORM,
    123 	PIPE_FORMAT_R10SG10SB10SA2U_NORM,
    124 	PIPE_FORMAT_B8G8R8A8_UNORM, /* TYPELESS */
    125 	PIPE_FORMAT_B8G8R8A8_SRGB,
    126 	PIPE_FORMAT_B8G8R8X8_UNORM, /* TYPELESS */
    127 	PIPE_FORMAT_B8G8R8X8_SRGB,
    128 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_BC6H_TYPELESS */
    129 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_BC6H_UF16 */
    130 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_BC6H_SF16 */
    131 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_BC7_TYPELESS */
    132 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_BC7_UNORM */
    133 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_BC7_UNORM_SRGB */
    134 	PIPE_FORMAT_A8R8G8B8_UNORM, /* PIPE_FORMAT_AYUV */
    135 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_Y410 */
    136 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_Y416 */
    137 	PIPE_FORMAT_NV12,
    138 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_P010 */
    139 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_P016 */
    140 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_420_OPAQUE */
    141 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_YUV2 */
    142 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_Y210 */
    143 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_Y216 */
    144 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_NV11 */
    145 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_AI44 (palettized) */
    146 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_IA44 (palettized) */
    147 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_P8 (palettized) */
    148 	PIPE_FORMAT_NONE, /* PIPE_FORMAT_A8P8 (palettized) */
    149 	PIPE_FORMAT_B4G4R4A4_UNORM,
    150 };
    151 
    152 DXGI_FORMAT pipe_to_dxgi_format[PIPE_FORMAT_COUNT];
    153 static int pipe_to_dxgi_format_initialized;
    154 void init_pipe_to_dxgi_format()
    155 {
    156 	if(!pipe_to_dxgi_format_initialized)
    157 	{
    158 		for(unsigned i = 0; i < DXGI_FORMAT_COUNT; ++i)
    159 			pipe_to_dxgi_format[dxgi_to_pipe_format[i]] = (DXGI_FORMAT)i;
    160 		pipe_to_dxgi_format[PIPE_FORMAT_NONE] = DXGI_FORMAT_UNKNOWN;
    161 		pipe_to_dxgi_format[PIPE_FORMAT_Z32_FLOAT_S8X24_UINT] = DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
    162 		pipe_to_dxgi_format[PIPE_FORMAT_Z24_UNORM_S8_UINT] = DXGI_FORMAT_D24_UNORM_S8_UINT;
    163 		pipe_to_dxgi_format_initialized = 1;
    164 	}
    165 }
    166