Commit e0548ad2 by Jamie Madill

D3D11: Split off DXGI component type query.

This query is currently a part of a std::map. Split it off to its own switch using auto-generation based on the format string. Also introduce a DXGI-to-angle format map. This map is not totally complete because some more esoteric formats don't have corresponding ANGLE formats yet. We should add these other formats (EG NV12) if we need them. BUG=angleproject:1389 BUG=angleproject:1459 Change-Id: I49e045bdc04a52166299c9e22a4c4d3f24069dbc Reviewed-on: https://chromium-review.googlesource.com/392209Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 65c79dbc
...@@ -48,6 +48,7 @@ Format::Format(ID id, ...@@ -48,6 +48,7 @@ Format::Format(ID id,
GLenum fboFormat, GLenum fboFormat,
MipGenerationFunction mipGen, MipGenerationFunction mipGen,
ColorReadFunction colorRead, ColorReadFunction colorRead,
GLenum componentType,
GLuint redBits, GLuint redBits,
GLuint greenBits, GLuint greenBits,
GLuint blueBits, GLuint blueBits,
...@@ -60,6 +61,7 @@ Format::Format(ID id, ...@@ -60,6 +61,7 @@ Format::Format(ID id,
mipGenerationFunction(mipGen), mipGenerationFunction(mipGen),
colorReadFunction(colorRead), colorReadFunction(colorRead),
fastCopyFunctions(GetFastCopyFunctionsMap(id)), fastCopyFunctions(GetFastCopyFunctionsMap(id)),
componentType(componentType),
redBits(redBits), redBits(redBits),
greenBits(greenBits), greenBits(greenBits),
blueBits(blueBits), blueBits(blueBits),
......
...@@ -27,6 +27,7 @@ struct Format final : angle::NonCopyable ...@@ -27,6 +27,7 @@ struct Format final : angle::NonCopyable
GLenum fboFormat, GLenum fboFormat,
rx::MipGenerationFunction mipGen, rx::MipGenerationFunction mipGen,
rx::ColorReadFunction colorRead, rx::ColorReadFunction colorRead,
GLenum componentType,
GLuint redBits, GLuint redBits,
GLuint greenBits, GLuint greenBits,
GLuint blueBits, GLuint blueBits,
...@@ -53,6 +54,8 @@ struct Format final : angle::NonCopyable ...@@ -53,6 +54,8 @@ struct Format final : angle::NonCopyable
// A map from a gl::FormatType to a fast pixel copy function for this format. // A map from a gl::FormatType to a fast pixel copy function for this format.
rx::FastCopyFunctionMap fastCopyFunctions; rx::FastCopyFunctionMap fastCopyFunctions;
GLenum componentType;
GLuint redBits; GLuint redBits;
GLuint greenBits; GLuint greenBits;
GLuint blueBits; GLuint blueBits;
......
...@@ -1022,8 +1022,7 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source, ...@@ -1022,8 +1022,7 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source,
D3D11_SHADER_RESOURCE_VIEW_DESC sourceSRVDesc; D3D11_SHADER_RESOURCE_VIEW_DESC sourceSRVDesc;
source->GetDesc(&sourceSRVDesc); source->GetDesc(&sourceSRVDesc);
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(sourceSRVDesc.Format); GLenum componentType = d3d11::GetComponentType(sourceSRVDesc.Format);
GLenum componentType = dxgiFormatInfo.componentType;
if (componentType == GL_NONE) if (componentType == GL_NONE)
{ {
// We're swizzling the depth component of a depth-stencil texture. // We're swizzling the depth component of a depth-stencil texture.
...@@ -1183,8 +1182,7 @@ gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source, ...@@ -1183,8 +1182,7 @@ gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source,
D3D11_SHADER_RESOURCE_VIEW_DESC sourceSRVDesc; D3D11_SHADER_RESOURCE_VIEW_DESC sourceSRVDesc;
source->GetDesc(&sourceSRVDesc); source->GetDesc(&sourceSRVDesc);
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(sourceSRVDesc.Format); GLenum componentType = d3d11::GetComponentType(sourceSRVDesc.Format);
GLenum componentType = dxgiFormatInfo.componentType;
ASSERT(componentType != GL_NONE); ASSERT(componentType != GL_NONE);
ASSERT(componentType != GL_SIGNED_NORMALIZED); ASSERT(componentType != GL_SIGNED_NORMALIZED);
......
...@@ -4174,7 +4174,9 @@ VertexConversionType Renderer11::getVertexConversionType(gl::VertexFormatType ve ...@@ -4174,7 +4174,9 @@ VertexConversionType Renderer11::getVertexConversionType(gl::VertexFormatType ve
GLenum Renderer11::getVertexComponentType(gl::VertexFormatType vertexFormatType) const GLenum Renderer11::getVertexComponentType(gl::VertexFormatType vertexFormatType) const
{ {
return d3d11::GetDXGIFormatInfo(d3d11::GetVertexFormatInfo(vertexFormatType, mRenderer11DeviceCaps.featureLevel).nativeFormat).componentType; const auto &format =
d3d11::GetVertexFormatInfo(vertexFormatType, mRenderer11DeviceCaps.featureLevel);
return d3d11::GetComponentType(format.nativeFormat);
} }
gl::ErrorOrResult<unsigned int> Renderer11::getVertexSpaceRequired( gl::ErrorOrResult<unsigned int> Renderer11::getVertexSpaceRequired(
......
...@@ -2403,8 +2403,8 @@ gl::Error TextureStorage11_Cube::createSRV(int baseLevel, ...@@ -2403,8 +2403,8 @@ gl::Error TextureStorage11_Cube::createSRV(int baseLevel,
// Unnormalized integer cube maps are not supported by DX11; we emulate them as an array of six // Unnormalized integer cube maps are not supported by DX11; we emulate them as an array of six
// 2D textures // 2D textures
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(format); const GLenum componentType = d3d11::GetComponentType(format);
if (dxgiFormatInfo.componentType == GL_INT || dxgiFormatInfo.componentType == GL_UNSIGNED_INT) if (componentType == GL_INT || componentType == GL_UNSIGNED_INT)
{ {
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
srvDesc.Texture2DArray.MostDetailedMip = mTopLevel + baseLevel; srvDesc.Texture2DArray.MostDetailedMip = mTopLevel + baseLevel;
......
{
"UNKNOWN": "NONE",
"R32G32B32A32_TYPELESS": "",
"R32G32B32A32_FLOAT": "",
"R32G32B32A32_UINT": "",
"R32G32B32A32_SINT": "",
"R32G32B32_TYPELESS": "",
"R32G32B32_FLOAT": "",
"R32G32B32_UINT": "",
"R32G32B32_SINT": "",
"R16G16B16A16_TYPELESS": "",
"R16G16B16A16_FLOAT": "",
"R16G16B16A16_UNORM": "",
"R16G16B16A16_UINT": "",
"R16G16B16A16_SNORM": "",
"R16G16B16A16_SINT": "",
"R32G32_TYPELESS": "",
"R32G32_FLOAT": "",
"R32G32_UINT": "",
"R32G32_SINT": "",
"R32G8X24_TYPELESS": "",
"D32_FLOAT_S8X24_UINT": "",
"R32_FLOAT_X8X24_TYPELESS": "",
"X32_TYPELESS_G8X24_UINT": "",
"R10G10B10A2_TYPELESS": "",
"R10G10B10A2_UNORM": "",
"R10G10B10A2_UINT": "",
"R11G11B10_FLOAT": "",
"R8G8B8A8_TYPELESS": "",
"R8G8B8A8_UNORM": "",
"R8G8B8A8_UNORM_SRGB": "",
"R8G8B8A8_UINT": "",
"R8G8B8A8_SNORM": "",
"R8G8B8A8_SINT": "",
"R16G16_TYPELESS": "",
"R16G16_FLOAT": "",
"R16G16_UNORM": "",
"R16G16_UINT": "",
"R16G16_SNORM": "",
"R16G16_SINT": "",
"R32_TYPELESS": "",
"D32_FLOAT": "",
"R32_FLOAT": "",
"R32_UINT": "",
"R32_SINT": "",
"R24G8_TYPELESS": "",
"D24_UNORM_S8_UINT": "",
"R24_UNORM_X8_TYPELESS": "",
"X24_TYPELESS_G8_UINT": "",
"R8G8_TYPELESS": "",
"R8G8_UNORM": "",
"R8G8_UINT": "",
"R8G8_SNORM": "",
"R8G8_SINT": "",
"R16_TYPELESS": "",
"R16_FLOAT": "",
"D16_UNORM": "",
"R16_UNORM": "",
"R16_UINT": "",
"R16_SNORM": "",
"R16_SINT": "",
"R8_TYPELESS": "",
"R8_UNORM": "",
"R8_UINT": "",
"R8_SNORM": "",
"R8_SINT": "",
"A8_UNORM": "",
"R1_UNORM": "",
"R9G9B9E5_SHAREDEXP": "",
"R8G8_B8G8_UNORM": "",
"G8R8_G8B8_UNORM": "",
"BC1_TYPELESS": "",
"BC1_UNORM": "BC1_RGBA_UNORM_BLOCK",
"BC1_UNORM_SRGB": "",
"BC2_TYPELESS": "",
"BC2_UNORM": "BC2_RGBA_UNORM_BLOCK",
"BC2_UNORM_SRGB": "",
"BC3_TYPELESS": "",
"BC3_UNORM": "BC3_RGBA_UNORM_BLOCK",
"BC3_UNORM_SRGB": "",
"BC4_TYPELESS": "",
"BC4_UNORM": "",
"BC4_SNORM": "",
"BC5_TYPELESS": "",
"BC5_UNORM": "",
"BC5_SNORM": "",
"B5G6R5_UNORM": "",
"B5G5R5A1_UNORM": "",
"B8G8R8A8_UNORM": "",
"B8G8R8X8_UNORM": "",
"R10G10B10_XR_BIAS_A2_UNORM": "",
"B8G8R8A8_TYPELESS": "",
"B8G8R8A8_UNORM_SRGB": "",
"B8G8R8X8_TYPELESS": "",
"B8G8R8X8_UNORM_SRGB": "",
"BC6H_TYPELESS": "",
"BC6H_UF16": "",
"BC6H_SF16": "",
"BC7_TYPELESS": "",
"BC7_UNORM": "",
"BC7_UNORM_SRGB": "",
"AYUV": "",
"Y410": "",
"Y416": "",
"NV12": "",
"P010": "",
"P016": "",
"420_OPAQUE": "",
"YUY2": "",
"Y210": "",
"Y216": "",
"NV11": "",
"AI44": "",
"IA44": "",
"P8": "",
"A8P8": "",
"B4G4R4A4_UNORM": ""
}
...@@ -31,8 +31,6 @@ struct DXGIFormat ...@@ -31,8 +31,6 @@ struct DXGIFormat
{ {
DXGIFormat(); DXGIFormat();
GLenum componentType;
NativeMipmapGenerationSupportFunction nativeMipmapSupport; NativeMipmapGenerationSupportFunction nativeMipmapSupport;
}; };
...@@ -66,6 +64,9 @@ struct VertexFormat ...@@ -66,6 +64,9 @@ struct VertexFormat
const VertexFormat &GetVertexFormatInfo(gl::VertexFormatType vertexFormatType, const VertexFormat &GetVertexFormatInfo(gl::VertexFormatType vertexFormatType,
D3D_FEATURE_LEVEL featureLevel); D3D_FEATURE_LEVEL featureLevel);
// Auto-generated in dxgi_format_map_autogen.cpp.
GLenum GetComponentType(DXGI_FORMAT dxgiFormat);
} // namespace d3d11 } // namespace d3d11
} // namespace rx } // namespace rx
......
#!/usr/bin/python
# Copyright 2016 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_format_table.py:
# Code generation for DXGI format map.
from datetime import date
import sys
sys.path.append('../..')
import angle_format
template_cpp = """// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {data_source_name}.
//
// Copyright {copyright_year} 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 format info:
// Determining metadata about a DXGI format.
#include "libANGLE/renderer/Format.h"
using namespace angle;
namespace rx
{{
namespace d3d11
{{
GLenum GetComponentType(DXGI_FORMAT dxgiFormat)
{{
switch (dxgiFormat)
{{
{component_type_cases} default:
break;
}}
UNREACHABLE();
return GL_NONE;
}}
}} // namespace d3d11
namespace d3d11_angle
{{
const Format &GetFormat(DXGI_FORMAT dxgiFormat)
{{
switch (dxgiFormat)
{{
{format_cases} default:
break;
}}
UNREACHABLE();
return Format::Get(Format::ID::NONE);
}}
}} // namespace d3d11_angle
}} // namespace rx
"""
template_format_case = """ case DXGI_FORMAT_{dxgi_format}:
return {result};
"""
template_undefined_case = """ case DXGI_FORMAT_{dxgi_format}:
break;
"""
def format_case(dxgi_format, result):
return template_format_case.format(
dxgi_format = dxgi_format,
result = result)
def undefined_case(dxgi_format):
return template_undefined_case.format(dxgi_format = dxgi_format)
component_cases = ""
format_cases = ""
input_data = 'dxgi_format_data.json'
dxgi_map = angle_format.load_json(input_data)
types = {
'SNORM': 'GL_SIGNED_NORMALIZED',
'UNORM': 'GL_UNSIGNED_NORMALIZED',
'SINT': 'GL_INT',
'UINT': 'GL_UNSIGNED_INT',
'FLOAT': 'GL_FLOAT',
'SHAREDEXP': 'GL_FLOAT'
}
angle_to_gl = angle_format.load_inverse_table('../../angle_format_map.json')
all_angle = angle_to_gl.keys()
for dxgi_format, angle_format in sorted(dxgi_map.iteritems()):
found = [ctype in dxgi_format for ctype in types.keys()]
count = reduce((lambda a, b: int(a) + int(b)), found)
component_type = 'GL_NONE'
if count == 1:
gltype = next(gltype for ctype, gltype in types.iteritems() if ctype in dxgi_format)
component_cases += format_case(dxgi_format, gltype)
else:
component_cases += undefined_case(dxgi_format)
if angle_format == "":
angle_format = dxgi_format
if angle_format in all_angle:
angle_format = "Format::Get(Format::ID::" + angle_format + ")"
format_cases += format_case(dxgi_format, angle_format)
else:
format_cases += undefined_case(dxgi_format)
with open('dxgi_format_map_autogen.cpp', 'wt') as out_file:
output_cpp = template_cpp.format(
script_name = sys.argv[0],
data_source_name = input_data,
copyright_year = date.today().year,
component_type_cases = component_cases,
format_cases = format_cases)
out_file.write(output_cpp)
out_file.close()
...@@ -67,7 +67,7 @@ const Format &Format::Get(ID id) ...@@ -67,7 +67,7 @@ const Format &Format::Get(ID id)
}} }}
// clang-format on // clang-format on
static const Format noneInfo(ID::NONE, GL_NONE, GL_NONE, nullptr, nullptr, 0, 0, 0, 0, 0, 0); static const Format noneInfo(ID::NONE, GL_NONE, GL_NONE, nullptr, nullptr, GL_NONE, 0, 0, 0, 0, 0, 0);
return noneInfo; return noneInfo;
}} }}
...@@ -129,6 +129,7 @@ format_entry_template = """{space}{{ ...@@ -129,6 +129,7 @@ format_entry_template = """{space}{{
{space} {fboImplementationInternalFormat}, {space} {fboImplementationInternalFormat},
{space} {mipGenerationFunction}, {space} {mipGenerationFunction},
{space} {colorReadFunction}, {space} {colorReadFunction},
{space} {namedComponentType},
{space} {R}, {G}, {B}, {A}, {D}, {S}); {space} {R}, {G}, {B}, {A}, {D}, {S});
{space} return info; {space} return info;
{space}}} {space}}}
...@@ -175,6 +176,22 @@ def get_bits(format_id): ...@@ -175,6 +176,22 @@ def get_bits(format_id):
bits[token[0]] = int(token[1:]) bits[token[0]] = int(token[1:])
return bits return bits
def get_named_component_type(component_type):
if component_type == "snorm":
return "GL_SIGNED_NORMALIZED"
elif component_type == "unorm":
return "GL_UNSIGNED_NORMALIZED"
elif component_type == "float":
return "GL_FLOAT"
elif component_type == "uint":
return "GL_UNSIGNED_INT"
elif component_type == "int":
return "GL_INT"
elif component_type == "none":
return "GL_NONE"
else:
raise ValueError("Unknown component type for " + component_type)
def json_to_table_data(format_id, json, angle_to_gl): def json_to_table_data(format_id, json, angle_to_gl):
table_data = "" table_data = ""
...@@ -212,6 +229,8 @@ def json_to_table_data(format_id, json, angle_to_gl): ...@@ -212,6 +229,8 @@ def json_to_table_data(format_id, json, angle_to_gl):
else: else:
parsed[channel] = "0" parsed[channel] = "0"
parsed["namedComponentType"] = get_named_component_type(parsed["componentType"])
return format_entry_template.format(**parsed) return format_entry_template.format(**parsed)
def parse_json_into_angle_format_switch_string(all_angle, json_data, angle_to_gl): def parse_json_into_angle_format_switch_string(all_angle, json_data, angle_to_gl):
......
...@@ -330,6 +330,7 @@ ...@@ -330,6 +330,7 @@
'libANGLE/renderer/d3d/d3d11/copyvertex.inl', 'libANGLE/renderer/d3d/d3d11/copyvertex.inl',
'libANGLE/renderer/d3d/d3d11/DebugAnnotator11.cpp', 'libANGLE/renderer/d3d/d3d11/DebugAnnotator11.cpp',
'libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h', 'libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h',
'libANGLE/renderer/d3d/d3d11/dxgi_format_map_autogen.cpp',
'libANGLE/renderer/d3d/d3d11/dxgi_support_table.cpp', 'libANGLE/renderer/d3d/d3d11/dxgi_support_table.cpp',
'libANGLE/renderer/d3d/d3d11/dxgi_support_table.h', 'libANGLE/renderer/d3d/d3d11/dxgi_support_table.h',
'libANGLE/renderer/d3d/d3d11/Fence11.cpp', 'libANGLE/renderer/d3d/d3d11/Fence11.cpp',
......
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