access_out: rist: fix mem leak
[vlc.git] / modules / video_chroma / dxgi_fmt.c
blob2138cf6f4e22176343fd6081203ead64a7c2729c
1 /*****************************************************************************
2 * dxgi_fmt.c : DXGI GPU surface conversion module for vlc
3 *****************************************************************************
4 * Copyright © 2015 VLC authors, VideoLAN and VideoLabs
6 * Authors: Steve Lhomme <robux4@gmail.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <vlc_es.h>
29 #include "dxgi_fmt.h"
31 typedef struct
33 const char *name;
34 DXGI_FORMAT format;
35 vlc_fourcc_t vlc_format;
36 } dxgi_format_t;
38 static const dxgi_format_t dxgi_formats[] = {
39 { "NV12", DXGI_FORMAT_NV12, VLC_CODEC_NV12 },
40 { "I420_OPAQUE", DXGI_FORMAT_420_OPAQUE, 0 },
41 { "RGBA", DXGI_FORMAT_R8G8B8A8_UNORM, VLC_CODEC_RGBA },
42 { "RGBA_SRGB", DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, VLC_CODEC_RGBA },
43 { "BGRX", DXGI_FORMAT_B8G8R8X8_UNORM, VLC_CODEC_RGB32 },
44 { "BGRA", DXGI_FORMAT_B8G8R8A8_UNORM, VLC_CODEC_BGRA },
45 { "BGRA_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, VLC_CODEC_BGRA },
46 { "AYUV", DXGI_FORMAT_AYUV, VLC_CODEC_YUVA },
47 { "YUY2", DXGI_FORMAT_YUY2, VLC_CODEC_YUYV },
48 { "AI44", DXGI_FORMAT_AI44, 0 },
49 { "P8", DXGI_FORMAT_P8, 0 },
50 { "A8P8", DXGI_FORMAT_A8P8, 0 },
51 { "B5G6R5", DXGI_FORMAT_B5G6R5_UNORM, VLC_CODEC_RGB16 },
52 { "Y416", DXGI_FORMAT_Y416, 0 },
53 { "P010", DXGI_FORMAT_P010, VLC_CODEC_P010 },
54 { "P016", DXGI_FORMAT_P016, 0 },
55 { "Y210", DXGI_FORMAT_Y210, VLC_CODEC_YUYV }, /* AV_PIX_FMT_YUYV422 */
56 { "Y410", DXGI_FORMAT_Y410, 0 },
57 { "NV11", DXGI_FORMAT_NV11, 0 },
58 { "RGB10A2", DXGI_FORMAT_R10G10B10A2_UNORM, VLC_CODEC_RGBA10 },
59 { "RGB16", DXGI_FORMAT_R16G16B16A16_UNORM, VLC_CODEC_RGBA64 },
60 { "RGB16_FLOAT", DXGI_FORMAT_R16G16B16A16_FLOAT, 0 },
61 { "UNKNOWN", DXGI_FORMAT_UNKNOWN, 0 },
63 { NULL, 0, 0}
66 static const d3d_format_t d3d_formats[] = {
67 { "NV12", DXGI_FORMAT_NV12, VLC_CODEC_NV12, 8, 2, 2, { DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8G8_UNORM } },
68 { "VA_NV12", DXGI_FORMAT_NV12, VLC_CODEC_D3D11_OPAQUE, 8, 2, 2, { DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8G8_UNORM } },
69 { "P010", DXGI_FORMAT_P010, VLC_CODEC_P010, 10, 2, 2, { DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_R16G16_UNORM } },
70 { "VA_P010", DXGI_FORMAT_P010, VLC_CODEC_D3D11_OPAQUE_10B, 10, 2, 2, { DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_R16G16_UNORM } },
71 { "YUY2", DXGI_FORMAT_YUY2, VLC_CODEC_YUYV, 8, 2, 2, { DXGI_FORMAT_R8G8B8A8_UNORM } },
72 #ifdef BROKEN_PIXEL
73 { "Y416", DXGI_FORMAT_Y416, VLC_CODEC_I444_16L, 16, 1, 1, { DXGI_FORMAT_R16G16B16A16_UINT } },
74 #endif
75 #ifdef UNTESTED
76 { "Y210", DXGI_FORMAT_Y210, VLC_CODEC_I422_10L, 10, 2, 1, { DXGI_FORMAT_R16G16B16A16_UNORM } },
77 { "Y410", DXGI_FORMAT_Y410, VLC_CODEC_I444, 10, 1, 1, { DXGI_FORMAT_R10G10B10A2_UNORM } },
78 { "NV11", DXGI_FORMAT_NV11, VLC_CODEC_I411, 8, 4, 1, { DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8G8_UNORM} },
79 #endif
80 { "I420", DXGI_FORMAT_UNKNOWN, VLC_CODEC_I420, 8, 2, 2, { DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM } },
81 { "I420_10", DXGI_FORMAT_UNKNOWN, VLC_CODEC_I420_10L, 10, 2, 2, { DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_R16_UNORM } },
82 { "YUVA", DXGI_FORMAT_UNKNOWN, VLC_CODEC_YUVA, 8, 1, 1, { DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM } },
83 { "B8G8R8A8", DXGI_FORMAT_B8G8R8A8_UNORM, VLC_CODEC_BGRA, 8, 1, 1, { DXGI_FORMAT_B8G8R8A8_UNORM } },
84 { "VA_BGRA", DXGI_FORMAT_B8G8R8A8_UNORM, VLC_CODEC_D3D11_OPAQUE_BGRA, 8, 1, 1, { DXGI_FORMAT_B8G8R8A8_UNORM } },
85 { "R8G8B8A8", DXGI_FORMAT_R8G8B8A8_UNORM, VLC_CODEC_RGBA, 8, 1, 1, { DXGI_FORMAT_R8G8B8A8_UNORM } },
86 { "VA_RGBA", DXGI_FORMAT_R8G8B8A8_UNORM, VLC_CODEC_D3D11_OPAQUE_RGBA, 8, 1, 1, { DXGI_FORMAT_R8G8B8A8_UNORM } },
87 { "R8G8B8X8", DXGI_FORMAT_B8G8R8X8_UNORM, VLC_CODEC_RGB32, 8, 1, 1, { DXGI_FORMAT_B8G8R8X8_UNORM } },
88 { "RGBA64", DXGI_FORMAT_R16G16B16A16_UNORM, VLC_CODEC_RGBA64, 16, 1, 1, { DXGI_FORMAT_R16G16B16A16_UNORM } },
89 { "RGB10A2", DXGI_FORMAT_R10G10B10A2_UNORM, VLC_CODEC_RGBA10, 10, 1, 1, { DXGI_FORMAT_R10G10B10A2_UNORM } },
90 { "VA_RGB10", DXGI_FORMAT_R10G10B10A2_UNORM, VLC_CODEC_D3D11_OPAQUE_RGBA, 10, 1, 1, { DXGI_FORMAT_R10G10B10A2_UNORM } },
91 { "AYUV", DXGI_FORMAT_AYUV, VLC_CODEC_VUYA, 8, 1, 1, { DXGI_FORMAT_R8G8B8A8_UNORM } },
92 { "B5G6R5", DXGI_FORMAT_B5G6R5_UNORM, VLC_CODEC_RGB16, 5, 1, 1, { DXGI_FORMAT_B5G6R5_UNORM } },
93 { "I420_OPAQUE", DXGI_FORMAT_420_OPAQUE, VLC_CODEC_D3D11_OPAQUE, 8, 2, 2, { DXGI_FORMAT_UNKNOWN } },
95 { NULL, 0, 0, 0, 0, 0, {} }
98 const char *DxgiFormatToStr(DXGI_FORMAT format)
100 for (const dxgi_format_t *f = dxgi_formats; f->name != NULL; ++f)
102 if (f->format == format)
103 return f->name;
105 return NULL;
108 vlc_fourcc_t DxgiFormatFourcc(DXGI_FORMAT format)
110 for (const dxgi_format_t *f = dxgi_formats; f->name != NULL; ++f)
112 if (f->format == format)
113 return f->vlc_format;
115 return 0;
118 DXGI_FORMAT DxgiFourccFormat(vlc_fourcc_t fcc)
120 for (const dxgi_format_t *f = dxgi_formats; f->name != NULL; ++f)
122 if (f->vlc_format == fcc)
123 return f->format;
125 return DXGI_FORMAT_UNKNOWN;
128 const d3d_format_t *GetRenderFormatList(void)
130 return d3d_formats;
133 void DxgiFormatMask(DXGI_FORMAT format, video_format_t *fmt)
135 if (format == DXGI_FORMAT_B8G8R8X8_UNORM || format == DXGI_FORMAT_B8G8R8A8_UNORM)
137 fmt->i_rmask = 0x0000ff00;
138 fmt->i_gmask = 0x00ff0000;
139 fmt->i_bmask = 0xff000000;
143 const char *DxgiVendorStr(int gpu_vendor)
145 static const struct {
146 unsigned id;
147 const char name[32];
148 } vendors [] = {
149 { GPU_MANUFACTURER_AMD, "ATI" },
150 { GPU_MANUFACTURER_NVIDIA, "NVIDIA" },
151 { GPU_MANUFACTURER_VIA, "VIA" },
152 { GPU_MANUFACTURER_INTEL, "Intel" },
153 { GPU_MANUFACTURER_S3, "S3 Graphics" },
154 { GPU_MANUFACTURER_QUALCOMM, "Qualcomm" },
155 { 0, "Unknown" }
158 int i = 0;
159 for (i = 0; vendors[i].id != 0; i++) {
160 if (vendors[i].id == gpu_vendor)
161 break;
163 return vendors[i].name;
166 UINT DxgiResourceCount(const d3d_format_t *d3d_fmt)
168 for (UINT count=0; count<D3D11_MAX_SHADER_VIEW; count++)
170 if (d3d_fmt->resourceFormat[count] == DXGI_FORMAT_UNKNOWN)
171 return count;
173 return D3D11_MAX_SHADER_VIEW;