summaryrefslogtreecommitdiffstats
path: root/gfx/angle/src/libANGLE/renderer/d3d/d3d11/gen_dxgi_support_tables.py
blob: dba583f1e61e461e2bd3b08f6c6ca21f61605f4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/usr/bin/python
# Copyright 2015 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# gen_dxgi_support_tables.py:
#  Code generation for the DXGI support tables. Determines which formats
#  are natively support in D3D10+.
#
# MSDN links:
#  10_0: https://msdn.microsoft.com/en-us/library/windows/desktop/cc627090.aspx
#  10_1: https://msdn.microsoft.com/en-us/library/windows/desktop/cc627091.aspx
#  11_0: https://msdn.microsoft.com/en-us/library/windows/desktop/ff471325.aspx
#  11_1: https://msdn.microsoft.com/en-us/library/windows/desktop/hh404483.aspx

import sys
import json

macro_prefix = 'F_'

template = """// GENERATED FILE - DO NOT EDIT. See dxgi_support_data.json.
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// dxgi_support_table:
//   Queries for DXGI support of various texture formats. Depends on DXGI
//   version, D3D feature level, and is sometimes guaranteed or optional.
//

#include "libANGLE/renderer/d3d/d3d11/dxgi_support_table.h"

#include "common/debug.h"

namespace rx
{{

namespace d3d11
{{

#define {prefix}2D D3D11_FORMAT_SUPPORT_TEXTURE2D
#define {prefix}3D D3D11_FORMAT_SUPPORT_TEXTURE3D
#define {prefix}CUBE D3D11_FORMAT_SUPPORT_TEXTURECUBE
#define {prefix}SAMPLE D3D11_FORMAT_SUPPORT_SHADER_SAMPLE
#define {prefix}RT D3D11_FORMAT_SUPPORT_RENDER_TARGET
#define {prefix}MS D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
#define {prefix}DS D3D11_FORMAT_SUPPORT_DEPTH_STENCIL
#define {prefix}MIPGEN D3D11_FORMAT_SUPPORT_MIP_AUTOGEN

namespace
{{

const DXGISupport &GetDefaultSupport()
{{
    static UINT AllSupportFlags =
        D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURE3D |
        D3D11_FORMAT_SUPPORT_TEXTURECUBE | D3D11_FORMAT_SUPPORT_SHADER_SAMPLE |
        D3D11_FORMAT_SUPPORT_RENDER_TARGET | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET |
        D3D11_FORMAT_SUPPORT_DEPTH_STENCIL | D3D11_FORMAT_SUPPORT_MIP_AUTOGEN;
    static const DXGISupport defaultSupport(0, 0, AllSupportFlags);
    return defaultSupport;
}}

const DXGISupport &GetDXGISupport_9_3(DXGI_FORMAT dxgiFormat)
{{
    // clang-format off
    switch (dxgiFormat)
    {{
{table_data_9_3}
        default:
            UNREACHABLE();
            return GetDefaultSupport();
    }}
    // clang-format on
}}

const DXGISupport &GetDXGISupport_10_0(DXGI_FORMAT dxgiFormat)
{{
    // clang-format off
    switch (dxgiFormat)
    {{
{table_data_10_0}
        default:
            UNREACHABLE();
            return GetDefaultSupport();
    }}
    // clang-format on
}}

const DXGISupport &GetDXGISupport_10_1(DXGI_FORMAT dxgiFormat)
{{
    // clang-format off
    switch (dxgiFormat)
    {{
{table_data_10_1}
        default:
            UNREACHABLE();
            return GetDefaultSupport();
    }}
    // clang-format on
}}

const DXGISupport &GetDXGISupport_11_0(DXGI_FORMAT dxgiFormat)
{{
    // clang-format off
    switch (dxgiFormat)
    {{
{table_data_11_0}
        default:
            UNREACHABLE();
            return GetDefaultSupport();
    }}
    // clang-format on
}}

}}

#undef {prefix}2D
#undef {prefix}3D
#undef {prefix}CUBE
#undef {prefix}SAMPLE
#undef {prefix}RT
#undef {prefix}MS
#undef {prefix}DS
#undef {prefix}MIPGEN

const DXGISupport &GetDXGISupport(DXGI_FORMAT dxgiFormat, D3D_FEATURE_LEVEL featureLevel)
{{
    switch (featureLevel)
    {{
        case D3D_FEATURE_LEVEL_9_3:
            return GetDXGISupport_9_3(dxgiFormat);
        case D3D_FEATURE_LEVEL_10_0:
            return GetDXGISupport_10_0(dxgiFormat);
        case D3D_FEATURE_LEVEL_10_1:
            return GetDXGISupport_10_1(dxgiFormat);
        case D3D_FEATURE_LEVEL_11_0:
            return GetDXGISupport_11_0(dxgiFormat);
        default:
            return GetDefaultSupport();
    }}
}}

}} // namespace d3d11

}} // namespace rx
"""

table_init = ""

def do_format(format_data):
    table_data = {'9_3': '', '10_0': '', '10_1': '', '11_0': ''}

    json_flag_to_d3d = {
        'texture2D': macro_prefix + '2D',
        'texture3D': macro_prefix + '3D',
        'textureCube': macro_prefix + 'CUBE',
        'shaderSample': macro_prefix + 'SAMPLE',
        'renderTarget': macro_prefix + 'RT',
        'multisampleRT': macro_prefix + 'MS',
        'depthStencil': macro_prefix + 'DS',
        'mipAutoGen': macro_prefix + 'MIPGEN'
    }

    for format_name, format_support in sorted(format_data.iteritems()):

        always_supported = set()
        never_supported = set()
        optionally_supported = set()
        fl_9_3_supported = set()
        fl_9_3_check = set()
        fl_10_0_supported = set()
        fl_10_1_supported = set()
        fl_11_0_supported = set()
        fl_11_0_check = set()
        fl_10_0_check_10_1_supported = set()
        fl_10_0_check_11_0_supported = set()

        for json_flag, support in format_support.iteritems():

            d3d_flag = [json_flag_to_d3d[json_flag]]

            if support == 'check':
                optionally_supported.update(d3d_flag)
            elif support == 'always':
                always_supported.update(d3d_flag)
            elif support == 'never':
                never_supported.update(d3d_flag)
            elif support == '10_0':
                fl_10_0_supported.update(d3d_flag)
            elif support == '10_1':
                fl_10_1_supported.update(d3d_flag)
            elif support == '11_0':
                fl_11_0_supported.update(d3d_flag)
            elif support == '11_1':
                # TODO(jmadill): D3D 11.1 handling
                never_supported.update(d3d_flag)
            elif support == 'dxgi1_2':
                # TODO(jmadill): DXGI 1.2 handling.
                always_supported.update(d3d_flag)
            elif support == '10_0check10_1always':
                fl_10_0_check_10_1_supported.update(d3d_flag)
            elif support == '10_0check11_0always':
                fl_10_0_check_11_0_supported.update(d3d_flag)
            elif support == '11_0check':
                fl_11_0_check.update(d3d_flag)
            elif support == '9_3always_10_0check11_0always':
                fl_9_3_supported.update(d3d_flag)
                fl_10_0_check_11_0_supported.update(d3d_flag)
            elif support == '9_3check_10_0always':
                fl_9_3_check.update(d3d_flag)
                fl_10_0_supported.update(d3d_flag)
            else:
                print("Data specification error: " + support)
                sys.exit(1)

        for feature_level in ['9_3', '10_0', '10_1', '11_0']:
            always_for_fl = always_supported
            optional_for_fl = optionally_supported
            if feature_level == '9_3':
                always_for_fl = fl_9_3_supported.union(always_for_fl)
                optional_for_fl = fl_9_3_check.union(optional_for_fl)
            elif feature_level == '10_0':
                always_for_fl = fl_10_0_supported.union(always_for_fl)
                optional_for_fl = fl_10_0_check_10_1_supported.union(optional_for_fl)
                optional_for_fl = fl_10_0_check_11_0_supported.union(optional_for_fl)
            elif feature_level == '10_1':
                always_for_fl = fl_10_0_supported.union(always_for_fl)
                always_for_fl = fl_10_1_supported.union(always_for_fl)
                always_for_fl = fl_10_0_check_10_1_supported.union(always_for_fl)
                optional_for_fl = fl_10_0_check_11_0_supported.union(optional_for_fl)
            elif feature_level == '11_0':
                always_for_fl = fl_10_0_supported.union(always_for_fl)
                always_for_fl = fl_10_0_check_10_1_supported.union(always_for_fl)
                always_for_fl = fl_10_0_check_11_0_supported.union(always_for_fl)
                always_for_fl = fl_10_1_supported.union(always_for_fl)
                always_for_fl = fl_11_0_supported.union(always_for_fl)

            always = ' | '.join(sorted(always_for_fl))
            never = ' | '.join(sorted(never_supported))
            optional = ' | '.join(sorted(optional_for_fl))

            if not always: always = '0'
            if not never: never = '0'
            if not optional: optional = '0'

            table_data[feature_level] += '        case ' + format_name + ':\n'
            table_data[feature_level] += '        {\n'
            table_data[feature_level] += '            static const DXGISupport info(' + always + ', ' + never + ', ' + optional + ');\n'
            table_data[feature_level] += '            return info;\n'
            table_data[feature_level] += '        }\n'

    return table_data

def join_table_data(table_data_1, table_data_2):
    return {'9_3':  table_data_1['9_3']  + table_data_2['9_3'],
            '10_0': table_data_1['10_0'] + table_data_2['10_0'],
            '10_1': table_data_1['10_1'] + table_data_2['10_1'],
            '11_0': table_data_1['11_0'] + table_data_2['11_0']}

with open('dxgi_support_data.json') as dxgi_file:
    file_data = dxgi_file.read()
    dxgi_file.close()
    json_data = json.loads(file_data)

    table_data = {'9_3': '', '10_0': '', '10_1': '', '11_0': ''}

    for format_data in json_data:
        table_data = join_table_data(table_data, do_format(format_data))

    out_data = template.format(prefix=macro_prefix,
                               table_data_9_3=table_data['9_3'],
                               table_data_10_0=table_data['10_0'],
                               table_data_10_1=table_data['10_1'],
                               table_data_11_0=table_data['11_0'])

    with open('dxgi_support_table.cpp', 'wt') as out_file:
        out_file.write(out_data)
        out_file.close()