Commit 0450dfcc by Dian Xiang

Changed GetTextureFormatInfo to use static switch

BUG=angleproject:1160 The find of the map table in GetTextureFormatInfo is showing up as a hotspot in draw call perf benchmark. Switching the map into a static switch should make it more efficient. Other tables that only GetTextureFormatInfo uses is also converted into static switching instead of maps for performance. Other tables include swizzle_format_table and load_functions_table which are both only used by GetTextureFormatInfo to generate the TextureFormat for a given internalFormat and d3d device caps. The static switches for each table is generated using a python script named gen_*.py. The data for each table is stored in JSON files. This makes it more flexible for additions and deletions. Change-Id: I0f40fcc2a215c85661863ea225891071cb2f2c71 Reviewed-on: https://chromium-review.googlesource.com/301770Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tryjob-Request: Dian Xiang <dianx@google.com> Tested-by: 's avatarDian Xiang <dianx@google.com> Tryjob-Request: Jamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 7432321e
#!/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_load_functions_table.py:
# Code generation for the load function tables used for texture formats
#
import json
template = """// GENERATED FILE - DO NOT EDIT.
// Generated by gen_load_functions_table.py using data from load_functions_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.
//
// load_functions_table:
// Contains the GetLoadFunctionsMap for texture_format_util.h
//
#include "libANGLE/renderer/d3d/d3d11/load_functions_table.h"
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
#include "libANGLE/renderer/d3d/loadimage.h"
#include "libANGLE/renderer/d3d/loadimage_etc.h"
namespace rx
{{
namespace d3d11
{{
namespace
{{
// ES3 image loading functions vary based on:
// - the GL internal format (supplied to glTex*Image*D)
// - the GL data type given (supplied to glTex*Image*D)
// - the target DXGI_FORMAT that the image will be loaded into (which is chosen based on the D3D
// device's capabilities)
// This map type determines which loading function to use, based on these three parameters.
// Source formats and types are taken from Tables 3.2 and 3.3 of the ES 3 spec.
void UnimplementedLoadFunction(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{{
UNIMPLEMENTED();
}}
void UnreachableLoadFunction(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{{
UNREACHABLE();
}}
}} // namespace
// TODO we can replace these maps with more generated code
const std::map<GLenum, LoadImageFunction> &GetLoadFunctionsMap(GLenum {internal_format},
DXGI_FORMAT {dxgi_format})
{{
// clang-format off
switch ({internal_format})
{{
{data}
default:
{{
static std::map<GLenum, LoadImageFunction> emptyLoadFunctionsMap;
return emptyLoadFunctionsMap;
}}
}}
// clang-format on
}} // GetLoadFunctionsMap
}} // namespace d3d11
}} // namespace rx
"""
internal_format_param = 'internalFormat'
dxgi_format_param = 'dxgiFormat'
dxgi_format_unknown = "DXGI_FORMAT_UNKNOWN"
def get_function_maps_string(typestr, function):
return ' loadMap[' + typestr + '] = ' + function + ';\n'
def get_unknown_format_string(dxgi_to_type_map, dxgi_unknown_string):
if dxgi_unknown_string not in dxgi_to_type_map:
return ''
table_data = ''
for unknown_type_function in dxgi_to_type_map[dxgi_unknown_string]:
table_data += get_function_maps_string(unknown_type_function['type'], unknown_type_function['loadFunction'])
return table_data
# Making map from dxgi to type map for a particular internalFormat
def create_dxgi_to_type_map(dst, json_data, internal_format_str):
for type_item in sorted(json_data[internal_format_str].iteritems()):
for entry_in_type_item in type_item[1]:
dxgi_format_str = entry_in_type_item['dxgiFormat']
if dxgi_format_str not in dst:
dst[dxgi_format_str] = []
type_dxgi_load_function = entry_in_type_item.copy();
type_dxgi_load_function['type'] = type_item[0]
dst[dxgi_format_str].append(type_dxgi_load_function)
def get_load_function_map_snippet(insert_map_string):
load_function_map_snippet = ''
load_function_map_snippet += ' static const std::map<GLenum, LoadImageFunction> loadFunctionsMap = []() {\n'
load_function_map_snippet += ' std::map<GLenum, LoadImageFunction> loadMap;\n'
load_function_map_snippet += insert_map_string
load_function_map_snippet += ' return loadMap;\n'
load_function_map_snippet += ' }();\n\n'
load_function_map_snippet += ' return loadFunctionsMap;\n'
return load_function_map_snippet
def parse_json_into_switch_string(json_data):
table_data = ''
for internal_format_item in sorted(json_data.iteritems()):
internal_format_str = internal_format_item[0]
table_data += ' case ' + internal_format_str + ':\n'
table_data += ' {\n'
table_data += ' switch (' + dxgi_format_param + ')\n'
table_data += ' {\n'
dxgi_to_type_map = {};
create_dxgi_to_type_map(dxgi_to_type_map, json_data, internal_format_str)
dxgi_unknown_str = get_unknown_format_string(dxgi_to_type_map, dxgi_format_unknown);
for dxgi_format_item in sorted(dxgi_to_type_map.iteritems()):
dxgi_format_str = dxgi_format_item[0]
# Main case statements
table_data += ' case ' + dxgi_format_str + ':\n'
table_data += ' {\n'
insert_map_string = ''
types_already_in_loadmap = set()
for type_function in sorted(dxgi_format_item[1]):
# type_function['requiresConversion'] element is not in use at the moment but may be needed later
insert_map_string += get_function_maps_string(type_function['type'], type_function['loadFunction'])
types_already_in_loadmap.add(type_function['type'])
# DXGI_FORMAT_UNKNOWN add ons
if dxgi_format_unknown in dxgi_to_type_map:
for unknown_type_function in dxgi_to_type_map[dxgi_format_unknown]:
# Check that it's not already in the loadmap so it doesn't override the value
if unknown_type_function['type'] not in types_already_in_loadmap:
insert_map_string += get_function_maps_string(unknown_type_function['type'], unknown_type_function['loadFunction'])
table_data += get_load_function_map_snippet(insert_map_string)
table_data += ' }\n'
table_data += ' default:\n'
if dxgi_unknown_str:
table_data += ' {\n'
table_data += get_load_function_map_snippet(dxgi_unknown_str)
table_data += ' }\n'
else:
table_data += ' break;\n'
table_data += ' }\n'
table_data += ' }\n'
return table_data
with open('load_functions_data.json') as functions_json_file:
functions_data = functions_json_file.read();
functions_json_file.close()
json_data = json.loads(functions_data)
table_data = parse_json_into_switch_string(json_data)
output = template.format(internal_format = internal_format_param,
dxgi_format = dxgi_format_param,
data=table_data)
with open('load_functions_table_autogen.cpp', 'wt') as out_file:
out_file.write(output)
out_file.close()
#!/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_swizzle_format_table.py:
# Code generation for the swizzle format table used for texture formats
#
import json
import pprint
template = """// GENERATED FILE - DO NOT EDIT
// Generated by gen_swizzle_format_table.py using data from swizzle_format_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.
//
// swizzle_format_info:
// Provides information for swizzle format and a map from type->formatinfo
//
#include "libANGLE/renderer/d3d/d3d11/swizzle_format_info.h"
#include <GLES3/gl3.h>
namespace rx
{{
namespace d3d11
{{
SwizzleSizeType::SwizzleSizeType() : maxComponentSize(0), componentType(GL_NONE)
{{
}}
SwizzleSizeType::SwizzleSizeType(size_t maxComponentSize, GLenum componentType)
: maxComponentSize(maxComponentSize), componentType(componentType)
{{
}}
bool SwizzleSizeType::operator<(const SwizzleSizeType &other) const
{{
return (maxComponentSize != other.maxComponentSize)
? (maxComponentSize < other.maxComponentSize)
: (componentType < other.componentType);
}}
SwizzleFormatInfo::SwizzleFormatInfo()
: mTexFormat(DXGI_FORMAT_UNKNOWN),
mSRVFormat(DXGI_FORMAT_UNKNOWN),
mRTVFormat(DXGI_FORMAT_UNKNOWN)
{{
}}
SwizzleFormatInfo::SwizzleFormatInfo(DXGI_FORMAT texFormat,
DXGI_FORMAT srvFormat,
DXGI_FORMAT rtvFormat)
: mTexFormat(texFormat), mSRVFormat(srvFormat), mRTVFormat(rtvFormat)
{{
}}
const SwizzleFormatInfo &GetSwizzleFormatInfo(GLuint maxBits, GLenum componentType)
{{
// clang-format off
switch ({component_type_param})
{{
{data}
default:
{{
static const SwizzleFormatInfo defaultInfo(DXGI_FORMAT_UNKNOWN,
DXGI_FORMAT_UNKNOWN,
DXGI_FORMAT_UNKNOWN);
return defaultInfo;
}}
}}
// clang-format on
}} // GetSwizzleFormatInfo
}} // namespace d3d11
}} // namespace rx
"""
max_bits_param = 'maxBits'
component_type_param = 'componentType'
tex_format_key = 'texFormat'
srv_format_key = 'srvFormat'
rtv_format_key = 'rtvFormat'
def parse_json_into_switch_string(json_data):
table_data = ''
for component_type in sorted(json_data.iteritems()):
type_str = component_type[0]
table_data += ' case ' + type_str + ':\n'
table_data += ' {\n'
table_data += ' switch (' + max_bits_param + ')\n'
table_data += ' {\n'
for max_width_item in sorted(json_data[type_str].iteritems()):
max_width = max_width_item[0]
table_data += ' case ' + max_width + ':\n'
table_data += ' {\n'
table_data += ' static const SwizzleFormatInfo formatInfo(' + json_data[type_str][max_width][tex_format_key] + ',\n'
table_data += ' ' + json_data[type_str][max_width][srv_format_key] + ',\n'
table_data += ' ' + json_data[type_str][max_width][rtv_format_key] + ');\n'
table_data += ' return formatInfo;\n'
table_data += ' }\n'
table_data += ' default:\n'
table_data += ' break;\n'
table_data += ' }\n'
table_data += ' }\n'
return table_data
with open('swizzle_format_data.json') as functions_json_file:
functions_data = functions_json_file.read();
functions_json_file.close()
json_data = json.loads(functions_data)
table_data = parse_json_into_switch_string(json_data)
output = template.format(component_type_param=component_type_param,
data=table_data)
with open('swizzle_format_info_autogen.cpp', 'wt') as out_file:
out_file.write(output)
out_file.close()
//
// 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.
//
// internal_format_initializer_table:
// Contains table to go from internal format and dxgi format to initializer function
// for TextureFormat
//
#include "libANGLE/renderer/d3d/d3d11/internal_format_initializer_table.h"
#include "libANGLE/renderer/d3d/loadimage.h"
namespace rx
{
namespace d3d11
{
// TODO: This should be generated by a JSON file
InitializeTextureDataFunction GetInternalFormatInitializer(GLenum internalFormat,
DXGI_FORMAT dxgiFormat)
{
switch (internalFormat)
{
case GL_RGB8:
{
switch (dxgiFormat)
{
case DXGI_FORMAT_R8G8B8A8_UNORM:
{
return Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>;
}
default:
break;
}
}
case GL_RGB565:
{
switch (dxgiFormat)
{
case DXGI_FORMAT_R8G8B8A8_UNORM:
{
return Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>;
}
default:
break;
}
}
case GL_SRGB8:
{
switch (dxgiFormat)
{
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
{
return Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>;
}
default:
break;
}
}
case GL_RGB16F:
{
switch (dxgiFormat)
{
case DXGI_FORMAT_R16G16B16A16_FLOAT:
{
return Initialize4ComponentData<GLhalf, 0x0000, 0x0000, 0x0000, gl::Float16One>;
}
default:
break;
}
}
case GL_RGB32F:
{
switch (dxgiFormat)
{
case DXGI_FORMAT_R32G32B32A32_FLOAT:
{
return Initialize4ComponentData<GLfloat, 0x00000000, 0x00000000, 0x00000000,
gl::Float32One>;
}
default:
break;
}
}
case GL_RGB8UI:
{
switch (dxgiFormat)
{
case DXGI_FORMAT_R8G8B8A8_UINT:
{
return Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0x01>;
}
default:
break;
}
}
case GL_RGB8I:
{
switch (dxgiFormat)
{
case DXGI_FORMAT_R8G8B8A8_SINT:
{
return Initialize4ComponentData<GLbyte, 0x00, 0x00, 0x00, 0x01>;
}
default:
break;
}
}
case GL_RGB16UI:
{
switch (dxgiFormat)
{
case DXGI_FORMAT_R16G16B16A16_UINT:
{
return Initialize4ComponentData<GLushort, 0x0000, 0x0000, 0x0000, 0x0001>;
}
default:
break;
}
}
case GL_RGB16I:
{
switch (dxgiFormat)
{
case DXGI_FORMAT_R16G16B16A16_SINT:
{
return Initialize4ComponentData<GLshort, 0x0000, 0x0000, 0x0000, 0x0001>;
}
default:
break;
}
}
case GL_RGB32UI:
{
switch (dxgiFormat)
{
case DXGI_FORMAT_R32G32B32A32_UINT:
{
return Initialize4ComponentData<GLuint, 0x00000000, 0x00000000, 0x00000000,
0x00000001>;
}
default:
break;
}
}
case GL_RGB32I:
{
switch (dxgiFormat)
{
case DXGI_FORMAT_R32G32B32A32_SINT:
{
return Initialize4ComponentData<GLint, 0x00000000, 0x00000000, 0x00000000,
0x00000001>;
}
default:
break;
}
}
default:
{
return nullptr;
}
}
}
} // namespace d3d11
} // namespace rx
//
// 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.
//
// internal_format_initializer_table:
// Contains table to go from internal format and dxgi format to initializer function
// for TextureFormat
//
#ifndef LIBANGLE_RENDERER_D3D_D3D11_INTERNALFORMATINITIALIZERTABLE_H_
#define LIBANGLE_RENDERER_D3D_D3D11_INTERNALFORMATINITIALIZERTABLE_H_
#include "libANGLE/renderer/d3d/d3d11/renderer11.h"
#include <map>
namespace rx
{
namespace d3d11
{
InitializeTextureDataFunction GetInternalFormatInitializer(GLenum internalFormat,
DXGI_FORMAT dxgiFormat);
} // namespace d3d11
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_D3D11_INTERNALFORMATINITIALIZERTABLE_H_
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// texture_format_util: // load_functions_table:
// Contains helper functions for texture_format_table // Contains load functions table depending on internal format and dxgi format
// //
#ifndef LIBANGLE_RENDERER_D3D_D3D11_TEXTUREFORMATUTIL_H_ #ifndef LIBANGLE_RENDERER_D3D_D3D11_LOADFUNCTIONSTABLE_H_
#define LIBANGLE_RENDERER_D3D_D3D11_TEXTUREFORMATUTIL_H_ #define LIBANGLE_RENDERER_D3D_D3D11_LOADFUNCTIONSTABLE_H_
#include <map> #include <map>
...@@ -20,20 +20,11 @@ namespace rx ...@@ -20,20 +20,11 @@ namespace rx
namespace d3d11 namespace d3d11
{ {
typedef std::pair<DXGI_FORMAT, LoadImageFunction> DxgiFormatLoadFunctionPair; const std::map<GLenum, LoadImageFunction> &GetLoadFunctionsMap(GLenum internalFormat,
typedef std::pair<GLenum, DxgiFormatLoadFunctionPair> GLTypeDXGIFunctionPair; DXGI_FORMAT dxgiFormat);
typedef std::map<GLenum, std::vector<GLTypeDXGIFunctionPair>> D3D11LoadFunctionMap;
const D3D11LoadFunctionMap &BuildD3D11LoadFunctionMap();
typedef std::pair<GLint, DXGI_FORMAT> InitializeTextureFormatPair;
typedef std::map<InitializeTextureFormatPair, InitializeTextureDataFunction>
InternalFormatInitializerMap;
const InternalFormatInitializerMap &BuildInternalFormatInitializerMap();
} // namespace d3d11 } // namespace d3d11
} // namespace rx } // namespace rx
#endif // LIBANGLE_RENDERER_D3D_D3D11_TEXTUREFORMATUTIL_H_ #endif // LIBANGLE_RENDERER_D3D_D3D11_LOADFUNCTIONSTABLE_H_
{
"GL_UNSIGNED_NORMALIZED": {
"8": {
"texFormat": "DXGI_FORMAT_R8G8B8A8_UNORM",
"srvFormat": "DXGI_FORMAT_R8G8B8A8_UNORM",
"rtvFormat": "DXGI_FORMAT_R8G8B8A8_UNORM"
},
"16": {
"texFormat": "DXGI_FORMAT_R16G16B16A16_UNORM",
"srvFormat": "DXGI_FORMAT_R16G16B16A16_UNORM",
"rtvFormat": "DXGI_FORMAT_R16G16B16A16_UNORM"
},
"24": {
"texFormat": "DXGI_FORMAT_R32G32B32A32_FLOAT",
"srvFormat": "DXGI_FORMAT_R32G32B32A32_FLOAT",
"rtvFormat": "DXGI_FORMAT_R32G32B32A32_FLOAT"
},
"32": {
"texFormat": "DXGI_FORMAT_R32G32B32A32_FLOAT",
"srvFormat": "DXGI_FORMAT_R32G32B32A32_FLOAT",
"rtvFormat": "DXGI_FORMAT_R32G32B32A32_FLOAT"
}
},
"GL_SIGNED_NORMALIZED": {
"8": {
"texFormat": "DXGI_FORMAT_R8G8B8A8_SNORM",
"srvFormat": "DXGI_FORMAT_R8G8B8A8_SNORM",
"rtvFormat": "DXGI_FORMAT_R8G8B8A8_SNORM"
}
},
"GL_FLOAT": {
"16": {
"texFormat": "DXGI_FORMAT_R16G16B16A16_FLOAT",
"srvFormat": "DXGI_FORMAT_R16G16B16A16_FLOAT",
"rtvFormat": "DXGI_FORMAT_R16G16B16A16_FLOAT"
},
"32": {
"texFormat": "DXGI_FORMAT_R32G32B32A32_FLOAT",
"srvFormat": "DXGI_FORMAT_R32G32B32A32_FLOAT",
"rtvFormat": "DXGI_FORMAT_R32G32B32A32_FLOAT"
}
},
"GL_UNSIGNED_INT": {
"8": {
"texFormat": "DXGI_FORMAT_R8G8B8A8_UINT",
"srvFormat": "DXGI_FORMAT_R8G8B8A8_UINT",
"rtvFormat": "DXGI_FORMAT_R8G8B8A8_UINT"
},
"16": {
"texFormat": "DXGI_FORMAT_R16G16B16A16_UINT",
"srvFormat": "DXGI_FORMAT_R16G16B16A16_UINT",
"rtvFormat": "DXGI_FORMAT_R16G16B16A16_UINT"
},
"32": {
"texFormat": "DXGI_FORMAT_R32G32B32A32_UINT",
"srvFormat": "DXGI_FORMAT_R32G32B32A32_UINT",
"rtvFormat": "DXGI_FORMAT_R32G32B32A32_UINT"
}
},
"GL_INT": {
"8": {
"texFormat": "DXGI_FORMAT_R8G8B8A8_SINT",
"srvFormat": "DXGI_FORMAT_R8G8B8A8_SINT",
"rtvFormat": "DXGI_FORMAT_R8G8B8A8_SINT"
},
"16": {
"texFormat": "DXGI_FORMAT_R16G16B16A16_SINT",
"srvFormat": "DXGI_FORMAT_R16G16B16A16_SINT",
"rtvFormat": "DXGI_FORMAT_R16G16B16A16_SINT"
},
"32": {
"texFormat": "DXGI_FORMAT_R32G32B32A32_SINT",
"srvFormat": "DXGI_FORMAT_R32G32B32A32_SINT",
"rtvFormat": "DXGI_FORMAT_R32G32B32A32_SINT"
}
}
}
\ No newline at end of file
//
// 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.
//
// swizzle_format_info:
// Provides information for swizzle format and a map from type->formatinfo
//
#include "libANGLE/renderer/d3d/d3d11/swizzle_format_info.h"
#include <GLES3/gl3.h>
namespace rx
{
namespace d3d11
{
SwizzleSizeType::SwizzleSizeType() : maxComponentSize(0), componentType(GL_NONE)
{
}
SwizzleSizeType::SwizzleSizeType(size_t maxComponentSize, GLenum componentType)
: maxComponentSize(maxComponentSize), componentType(componentType)
{
}
bool SwizzleSizeType::operator<(const SwizzleSizeType &other) const
{
return (maxComponentSize != other.maxComponentSize)
? (maxComponentSize < other.maxComponentSize)
: (componentType < other.componentType);
}
SwizzleFormatInfo::SwizzleFormatInfo()
: mTexFormat(DXGI_FORMAT_UNKNOWN),
mSRVFormat(DXGI_FORMAT_UNKNOWN),
mRTVFormat(DXGI_FORMAT_UNKNOWN)
{
}
SwizzleFormatInfo::SwizzleFormatInfo(DXGI_FORMAT texFormat,
DXGI_FORMAT srvFormat,
DXGI_FORMAT rtvFormat)
: mTexFormat(texFormat), mSRVFormat(srvFormat), mRTVFormat(rtvFormat)
{
}
typedef std::pair<SwizzleSizeType, SwizzleFormatInfo> SwizzleInfoPair;
const SwizzleInfoMap &BuildSwizzleInfoMap()
{
static SwizzleInfoMap map;
map.insert(
SwizzleInfoPair(SwizzleSizeType(8, GL_UNSIGNED_NORMALIZED),
SwizzleFormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_FORMAT_R8G8B8A8_UNORM)));
map.insert(SwizzleInfoPair(
SwizzleSizeType(16, GL_UNSIGNED_NORMALIZED),
SwizzleFormatInfo(DXGI_FORMAT_R16G16B16A16_UNORM, DXGI_FORMAT_R16G16B16A16_UNORM,
DXGI_FORMAT_R16G16B16A16_UNORM)));
map.insert(SwizzleInfoPair(
SwizzleSizeType(24, GL_UNSIGNED_NORMALIZED),
SwizzleFormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT,
DXGI_FORMAT_R32G32B32A32_FLOAT)));
map.insert(SwizzleInfoPair(
SwizzleSizeType(32, GL_UNSIGNED_NORMALIZED),
SwizzleFormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT,
DXGI_FORMAT_R32G32B32A32_FLOAT)));
map.insert(
SwizzleInfoPair(SwizzleSizeType(8, GL_SIGNED_NORMALIZED),
SwizzleFormatInfo(DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SNORM,
DXGI_FORMAT_R8G8B8A8_SNORM)));
map.insert(SwizzleInfoPair(
SwizzleSizeType(16, GL_FLOAT),
SwizzleFormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT,
DXGI_FORMAT_R16G16B16A16_FLOAT)));
map.insert(SwizzleInfoPair(
SwizzleSizeType(32, GL_FLOAT),
SwizzleFormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT,
DXGI_FORMAT_R32G32B32A32_FLOAT)));
map.insert(
SwizzleInfoPair(SwizzleSizeType(8, GL_UNSIGNED_INT),
SwizzleFormatInfo(DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT,
DXGI_FORMAT_R8G8B8A8_UINT)));
map.insert(SwizzleInfoPair(
SwizzleSizeType(16, GL_UNSIGNED_INT),
SwizzleFormatInfo(DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT,
DXGI_FORMAT_R16G16B16A16_UINT)));
map.insert(SwizzleInfoPair(
SwizzleSizeType(32, GL_UNSIGNED_INT),
SwizzleFormatInfo(DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT,
DXGI_FORMAT_R32G32B32A32_UINT)));
map.insert(
SwizzleInfoPair(SwizzleSizeType(8, GL_INT),
SwizzleFormatInfo(DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT,
DXGI_FORMAT_R8G8B8A8_SINT)));
map.insert(SwizzleInfoPair(
SwizzleSizeType(16, GL_INT),
SwizzleFormatInfo(DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT,
DXGI_FORMAT_R16G16B16A16_SINT)));
map.insert(SwizzleInfoPair(
SwizzleSizeType(32, GL_INT),
SwizzleFormatInfo(DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT,
DXGI_FORMAT_R32G32B32A32_SINT)));
return map;
}
} // namespace d3d11
} // namespace rx
...@@ -42,9 +42,7 @@ struct SwizzleFormatInfo ...@@ -42,9 +42,7 @@ struct SwizzleFormatInfo
SwizzleFormatInfo(DXGI_FORMAT texFormat, DXGI_FORMAT srvFormat, DXGI_FORMAT rtvFormat); SwizzleFormatInfo(DXGI_FORMAT texFormat, DXGI_FORMAT srvFormat, DXGI_FORMAT rtvFormat);
}; };
typedef std::map<SwizzleSizeType, SwizzleFormatInfo> SwizzleInfoMap; const SwizzleFormatInfo &GetSwizzleFormatInfo(GLuint maxBits, GLenum componentType);
const SwizzleInfoMap &BuildSwizzleInfoMap();
} // namespace d3d11 } // namespace d3d11
......
// GENERATED FILE - DO NOT EDIT
// Generated by gen_swizzle_format_table.py using data from swizzle_format_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.
//
// swizzle_format_info:
// Provides information for swizzle format and a map from type->formatinfo
//
#include "libANGLE/renderer/d3d/d3d11/swizzle_format_info.h"
#include <GLES3/gl3.h>
namespace rx
{
namespace d3d11
{
SwizzleSizeType::SwizzleSizeType() : maxComponentSize(0), componentType(GL_NONE)
{
}
SwizzleSizeType::SwizzleSizeType(size_t maxComponentSize, GLenum componentType)
: maxComponentSize(maxComponentSize), componentType(componentType)
{
}
bool SwizzleSizeType::operator<(const SwizzleSizeType &other) const
{
return (maxComponentSize != other.maxComponentSize)
? (maxComponentSize < other.maxComponentSize)
: (componentType < other.componentType);
}
SwizzleFormatInfo::SwizzleFormatInfo()
: mTexFormat(DXGI_FORMAT_UNKNOWN),
mSRVFormat(DXGI_FORMAT_UNKNOWN),
mRTVFormat(DXGI_FORMAT_UNKNOWN)
{
}
SwizzleFormatInfo::SwizzleFormatInfo(DXGI_FORMAT texFormat,
DXGI_FORMAT srvFormat,
DXGI_FORMAT rtvFormat)
: mTexFormat(texFormat), mSRVFormat(srvFormat), mRTVFormat(rtvFormat)
{
}
const SwizzleFormatInfo &GetSwizzleFormatInfo(GLuint maxBits, GLenum componentType)
{
// clang-format off
switch (componentType)
{
case GL_FLOAT:
{
switch (maxBits)
{
case 16:
{
static const SwizzleFormatInfo formatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT,
DXGI_FORMAT_R16G16B16A16_FLOAT,
DXGI_FORMAT_R16G16B16A16_FLOAT);
return formatInfo;
}
case 32:
{
static const SwizzleFormatInfo formatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT,
DXGI_FORMAT_R32G32B32A32_FLOAT,
DXGI_FORMAT_R32G32B32A32_FLOAT);
return formatInfo;
}
default:
break;
}
}
case GL_INT:
{
switch (maxBits)
{
case 16:
{
static const SwizzleFormatInfo formatInfo(DXGI_FORMAT_R16G16B16A16_SINT,
DXGI_FORMAT_R16G16B16A16_SINT,
DXGI_FORMAT_R16G16B16A16_SINT);
return formatInfo;
}
case 32:
{
static const SwizzleFormatInfo formatInfo(DXGI_FORMAT_R32G32B32A32_SINT,
DXGI_FORMAT_R32G32B32A32_SINT,
DXGI_FORMAT_R32G32B32A32_SINT);
return formatInfo;
}
case 8:
{
static const SwizzleFormatInfo formatInfo(DXGI_FORMAT_R8G8B8A8_SINT,
DXGI_FORMAT_R8G8B8A8_SINT,
DXGI_FORMAT_R8G8B8A8_SINT);
return formatInfo;
}
default:
break;
}
}
case GL_SIGNED_NORMALIZED:
{
switch (maxBits)
{
case 8:
{
static const SwizzleFormatInfo formatInfo(DXGI_FORMAT_R8G8B8A8_SNORM,
DXGI_FORMAT_R8G8B8A8_SNORM,
DXGI_FORMAT_R8G8B8A8_SNORM);
return formatInfo;
}
default:
break;
}
}
case GL_UNSIGNED_INT:
{
switch (maxBits)
{
case 16:
{
static const SwizzleFormatInfo formatInfo(DXGI_FORMAT_R16G16B16A16_UINT,
DXGI_FORMAT_R16G16B16A16_UINT,
DXGI_FORMAT_R16G16B16A16_UINT);
return formatInfo;
}
case 32:
{
static const SwizzleFormatInfo formatInfo(DXGI_FORMAT_R32G32B32A32_UINT,
DXGI_FORMAT_R32G32B32A32_UINT,
DXGI_FORMAT_R32G32B32A32_UINT);
return formatInfo;
}
case 8:
{
static const SwizzleFormatInfo formatInfo(DXGI_FORMAT_R8G8B8A8_UINT,
DXGI_FORMAT_R8G8B8A8_UINT,
DXGI_FORMAT_R8G8B8A8_UINT);
return formatInfo;
}
default:
break;
}
}
case GL_UNSIGNED_NORMALIZED:
{
switch (maxBits)
{
case 16:
{
static const SwizzleFormatInfo formatInfo(DXGI_FORMAT_R16G16B16A16_UNORM,
DXGI_FORMAT_R16G16B16A16_UNORM,
DXGI_FORMAT_R16G16B16A16_UNORM);
return formatInfo;
}
case 24:
{
static const SwizzleFormatInfo formatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT,
DXGI_FORMAT_R32G32B32A32_FLOAT,
DXGI_FORMAT_R32G32B32A32_FLOAT);
return formatInfo;
}
case 32:
{
static const SwizzleFormatInfo formatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT,
DXGI_FORMAT_R32G32B32A32_FLOAT,
DXGI_FORMAT_R32G32B32A32_FLOAT);
return formatInfo;
}
case 8:
{
static const SwizzleFormatInfo formatInfo(DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_FORMAT_R8G8B8A8_UNORM);
return formatInfo;
}
default:
break;
}
}
default:
{
static const SwizzleFormatInfo defaultInfo(DXGI_FORMAT_UNKNOWN,
DXGI_FORMAT_UNKNOWN,
DXGI_FORMAT_UNKNOWN);
return defaultInfo;
}
}
// clang-format on
} // GetSwizzleFormatInfo
} // namespace d3d11
} // namespace rx
...@@ -300,6 +300,10 @@ ...@@ -300,6 +300,10 @@
'libANGLE/renderer/d3d/d3d11/IndexBuffer11.h', 'libANGLE/renderer/d3d/d3d11/IndexBuffer11.h',
'libANGLE/renderer/d3d/d3d11/InputLayoutCache.cpp', 'libANGLE/renderer/d3d/d3d11/InputLayoutCache.cpp',
'libANGLE/renderer/d3d/d3d11/InputLayoutCache.h', 'libANGLE/renderer/d3d/d3d11/InputLayoutCache.h',
'libANGLE/renderer/d3d/d3d11/internal_format_initializer_table.h',
'libANGLE/renderer/d3d/d3d11/internal_format_initializer_table.cpp',
'libANGLE/renderer/d3d/d3d11/load_functions_table.h',
'libANGLE/renderer/d3d/d3d11/load_functions_table_autogen.cpp',
'libANGLE/renderer/d3d/d3d11/NativeWindow.h', 'libANGLE/renderer/d3d/d3d11/NativeWindow.h',
'libANGLE/renderer/d3d/d3d11/PixelTransfer11.cpp', 'libANGLE/renderer/d3d/d3d11/PixelTransfer11.cpp',
'libANGLE/renderer/d3d/d3d11/PixelTransfer11.h', 'libANGLE/renderer/d3d/d3d11/PixelTransfer11.h',
...@@ -370,15 +374,13 @@ ...@@ -370,15 +374,13 @@
'libANGLE/renderer/d3d/d3d11/SwapChain11.cpp', 'libANGLE/renderer/d3d/d3d11/SwapChain11.cpp',
'libANGLE/renderer/d3d/d3d11/SwapChain11.h', 'libANGLE/renderer/d3d/d3d11/SwapChain11.h',
'libANGLE/renderer/d3d/d3d11/swizzle_format_info.h', 'libANGLE/renderer/d3d/d3d11/swizzle_format_info.h',
'libANGLE/renderer/d3d/d3d11/swizzle_format_info.cpp', 'libANGLE/renderer/d3d/d3d11/swizzle_format_info_autogen.cpp',
'libANGLE/renderer/d3d/d3d11/TextureStorage11.cpp', 'libANGLE/renderer/d3d/d3d11/TextureStorage11.cpp',
'libANGLE/renderer/d3d/d3d11/TextureStorage11.h', 'libANGLE/renderer/d3d/d3d11/TextureStorage11.h',
'libANGLE/renderer/d3d/d3d11/Trim11.cpp', 'libANGLE/renderer/d3d/d3d11/Trim11.cpp',
'libANGLE/renderer/d3d/d3d11/Trim11.h', 'libANGLE/renderer/d3d/d3d11/Trim11.h',
'libANGLE/renderer/d3d/d3d11/texture_format_table.cpp', 'libANGLE/renderer/d3d/d3d11/texture_format_table_autogen.cpp',
'libANGLE/renderer/d3d/d3d11/texture_format_table.h', 'libANGLE/renderer/d3d/d3d11/texture_format_table.h',
'libANGLE/renderer/d3d/d3d11/texture_format_util.cpp',
'libANGLE/renderer/d3d/d3d11/texture_format_util.h',
'libANGLE/renderer/d3d/d3d11/VertexArray11.h', 'libANGLE/renderer/d3d/d3d11/VertexArray11.h',
'libANGLE/renderer/d3d/d3d11/VertexBuffer11.cpp', 'libANGLE/renderer/d3d/d3d11/VertexBuffer11.cpp',
'libANGLE/renderer/d3d/d3d11/VertexBuffer11.h', 'libANGLE/renderer/d3d/d3d11/VertexBuffer11.h',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment