Commit 20f69ce5 by Jamie Madill Committed by Commit Bot

Introduce angle::Format enum.

This general enum can encapsulate different formats between GL/Vulkan/D3D9/D3D11/etc so we can use them in common routines like PackPixels. It also can help us get rid of the ANGLEX enums which we use to represent internal formats not present in GL. It is currently used for Textures/Renderbuffers/Surfaces, but can also be extended in the future to cover things like vertex formats. It mirrors something like a DXGI_FORMAT in D3D11 or VkFormat. BUG=angleproject:1455 Change-Id: I467d7b36d8fc92bb45239d56b9243d06f4e29378 Reviewed-on: https://chromium-review.googlesource.com/365413Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 383b791a
//
// 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.
//
// Format:
// A universal description of typed GPU storage. Across multiple
// renderer back-ends, there are common formats and some distinct
// permutations, this enum encapsulates them all. Formats apply to
// textures, but could also apply to any typed data.
#ifndef LIBANGLE_RENDERER_FORMAT_H_
#define LIBANGLE_RENDERER_FORMAT_H_
namespace angle
{
// TODO(jmadill): It would be nice if we could auto-generate this.
enum class Format
{
NONE,
A8_UNORM,
B4G4R4A4_UNORM,
B5G5R5A1_UNORM,
B5G6R5_UNORM,
B8G8R8A8_UNORM,
BC1_UNORM,
BC2_UNORM,
BC3_UNORM,
D16_UNORM,
D24_UNORM_S8_UINT,
D32_FLOAT,
D32_FLOAT_S8X24_UINT,
R10G10B10A2_UINT,
R10G10B10A2_UNORM,
R11G11B10_FLOAT,
R16G16B16A16_FLOAT,
R16G16B16A16_SINT,
R16G16B16A16_SNORM,
R16G16B16A16_UINT,
R16G16B16A16_UNORM,
R16G16_FLOAT,
R16G16_SINT,
R16G16_SNORM,
R16G16_UINT,
R16G16_UNORM,
R16_FLOAT,
R16_SINT,
R16_SNORM,
R16_UINT,
R16_UNORM,
R32G32B32A32_FLOAT,
R32G32B32A32_SINT,
R32G32B32A32_UINT,
R32G32_FLOAT,
R32G32_SINT,
R32G32_UINT,
R32_FLOAT,
R32_SINT,
R32_UINT,
R8G8B8A8_SINT,
R8G8B8A8_SNORM,
R8G8B8A8_UINT,
R8G8B8A8_UNORM,
R8G8B8A8_UNORM_SRGB,
R8G8_SINT,
R8G8_SNORM,
R8G8_UINT,
R8G8_UNORM,
R8_SINT,
R8_SNORM,
R8_UINT,
R8_UNORM,
R9G9B9E5_SHAREDEXP,
};
} // namespace angle
#endif // LIBANGLE_RENDERER_FORMAT_H_
......@@ -1984,7 +1984,7 @@ gl::Error Blit11::initResolveDepthStencil(const gl::Extents &extents)
releaseResolveDepthStencilResources();
}
auto resolvedFormat = d3d11::ANGLE_FORMAT_R32G32_FLOAT;
auto resolvedFormat = angle::Format::R32G32_FLOAT;
const auto &formatSet =
d3d11::GetANGLEFormatSet(resolvedFormat, mRenderer->getRenderer11DeviceCaps());
......
......@@ -261,7 +261,7 @@ TextureRenderTarget11::TextureRenderTarget11(ID3D11RenderTargetView *rtv,
{
mSubresourceIndex = GetRTVSubresourceIndex(mTexture, mRenderTarget);
}
ASSERT(mFormatSet.format != d3d11::ANGLE_FORMAT_NONE || mWidth == 0 || mHeight == 0);
ASSERT(mFormatSet.format != angle::Format::NONE || mWidth == 0 || mHeight == 0);
}
TextureRenderTarget11::TextureRenderTarget11(ID3D11DepthStencilView *dsv,
......@@ -305,7 +305,7 @@ TextureRenderTarget11::TextureRenderTarget11(ID3D11DepthStencilView *dsv,
{
mSubresourceIndex = GetDSVSubresourceIndex(mTexture, mDepthStencil);
}
ASSERT(mFormatSet.format != d3d11::ANGLE_FORMAT_NONE || mWidth == 0 || mHeight == 0);
ASSERT(mFormatSet.format != angle::Format::NONE || mWidth == 0 || mHeight == 0);
}
TextureRenderTarget11::~TextureRenderTarget11()
......
......@@ -3280,8 +3280,8 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
{
*outRT = new TextureRenderTarget11(
static_cast<ID3D11RenderTargetView *>(nullptr), nullptr, nullptr, nullptr, format,
d3d11::GetANGLEFormatSet(d3d11::ANGLE_FORMAT_NONE, mRenderer11DeviceCaps), width,
height, 1, supportedSamples);
d3d11::GetANGLEFormatSet(angle::Format::NONE, mRenderer11DeviceCaps), width, height, 1,
supportedSamples);
}
return gl::Error(GL_NO_ERROR);
......
......@@ -14,30 +14,6 @@ import pprint
import re
import sys
template_texture_format_table_autogen_h = """// GENERATED FILE - DO NOT EDIT.
// Generated by gen_texture_format_table.py using data from texture_format_data.json
//
// 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.
//
namespace rx
{{
namespace d3d11
{{
enum ANGLEFormat
{{
{angle_format_enum}
}};
}} // namespace d3d11
}} // namespace rx
"""
template_texture_format_table_autogen_cpp = """// GENERATED FILE - DO NOT EDIT.
// Generated by gen_texture_format_table.py using data from texture_format_data.json
//
......@@ -67,7 +43,7 @@ namespace rx
namespace d3d11
{{
const ANGLEFormatSet &GetANGLEFormatSet(ANGLEFormat angleFormat,
const ANGLEFormatSet &GetANGLEFormatSet(angle::Format angleFormat,
const Renderer11DeviceCaps &deviceCaps)
{{
// clang-format off
......@@ -97,7 +73,7 @@ const TextureFormat &GetTextureFormatInfo(GLenum internalFormat,
}}
// clang-format on
static const TextureFormat defaultInfo(GL_NONE, ANGLE_FORMAT_NONE, nullptr, deviceCaps);
static const TextureFormat defaultInfo(GL_NONE, angle::Format::NONE, nullptr, deviceCaps);
return defaultInfo;
}} // GetTextureFormatInfo
......@@ -182,8 +158,8 @@ def get_internal_format_initializer(internal_format, angle_format):
return internal_format_initializer
def get_swizzle_format_id(angle_format_id, angle_format):
if angle_format_id == 'ANGLE_FORMAT_NONE':
return 'ANGLE_FORMAT_NONE'
if angle_format_id == 'angle::Format::NONE':
return 'angle::Format::NONE'
elif 'swizzleFormat' in angle_format:
# For some special formats like compressed formats that don't have a clearly defined number
# of bits per channel, swizzle format needs to be specified manually.
......@@ -207,9 +183,9 @@ def get_swizzle_format_id(angle_format_id, angle_format):
# defined component type.
if angle_format['channels'].find('d') >= 0:
if b == 24 or b == 32:
return 'ANGLE_FORMAT_R32G32B32A32_FLOAT'
return 'angle::Format::R32G32B32A32_FLOAT'
if b == 16:
return 'ANGLE_FORMAT_R16G16B16A16_UNORM'
return 'angle::Format::R16G16B16A16_UNORM'
if b == 24:
raise ValueError('unexpected 24-bit format when determining swizzleformat for format: ' + angle_format_id)
......@@ -219,15 +195,15 @@ def get_swizzle_format_id(angle_format_id, angle_format):
component_type = angle_format['componentType']
if component_type == 'uint':
return 'ANGLE_FORMAT_R{}G{}B{}A{}_UINT'.format(b, b, b, b)
return 'angle::Format::R{}G{}B{}A{}_UINT'.format(b, b, b, b)
elif component_type == 'int':
return 'ANGLE_FORMAT_R{}G{}B{}A{}_SINT'.format(b, b, b, b)
return 'angle::Format::R{}G{}B{}A{}_SINT'.format(b, b, b, b)
elif component_type == 'unorm':
return 'ANGLE_FORMAT_R{}G{}B{}A{}_UNORM'.format(b, b, b, b)
return 'angle::Format::R{}G{}B{}A{}_UNORM'.format(b, b, b, b)
elif component_type == 'snorm':
return 'ANGLE_FORMAT_R{}G{}B{}A{}_SNORM'.format(b, b, b, b)
return 'angle::Format::R{}G{}B{}A{}_SNORM'.format(b, b, b, b)
elif component_type == 'float':
return 'ANGLE_FORMAT_R{}G{}B{}A{}_FLOAT'.format(b, b, b, b)
return 'angle::Format::R{}G{}B{}A{}_FLOAT'.format(b, b, b, b)
else:
raise ValueError('could not determine swizzleformat based on componentType for format: ' + angle_format_id)
......@@ -386,7 +362,7 @@ def json_to_table_data(format_name, prefix, json):
for k, v in json.iteritems():
parsed[k] = v
if (format_name != "ANGLE_FORMAT_NONE") and (parsed["glInternalFormat"] == "GL_NONE"):
if (format_name != "angle::Format::NONE") and (parsed["glInternalFormat"] == "GL_NONE"):
print("Missing 'glInternalFormat' from " + format_name)
sys.exit(1)
......@@ -439,16 +415,6 @@ def parse_json_into_switch_angle_format_string(json_data):
return table_data
def parse_json_into_angle_format_enum_string(json_data):
enum_data = ''
index = 0
for angle_format_item in sorted(json_data.iteritems()):
if index > 0:
enum_data += ',\n'
enum_data += ' ' + angle_format_item[0]
index += 1
return enum_data
def reject_duplicate_keys(pairs):
found_keys = {}
for key, value in pairs:
......@@ -476,9 +442,3 @@ with open('texture_format_map.json') as texture_format_map_file:
with open('texture_format_table_autogen.cpp', 'wt') as out_file:
out_file.write(output_cpp)
out_file.close()
enum_data = parse_json_into_angle_format_enum_string(json_data)
output_h = template_texture_format_table_autogen_h.format(angle_format_enum=enum_data)
with open('texture_format_table_autogen.h', 'wt') as out_file:
out_file.write(output_h)
out_file.close()
......@@ -16,7 +16,7 @@ namespace d3d11
{
ANGLEFormatSet::ANGLEFormatSet()
: format(ANGLE_FORMAT_NONE),
: format(angle::Format::NONE),
glInternalFormat(GL_NONE),
fboImplementationInternalFormat(GL_NONE),
texFormat(DXGI_FORMAT_UNKNOWN),
......@@ -24,13 +24,13 @@ ANGLEFormatSet::ANGLEFormatSet()
rtvFormat(DXGI_FORMAT_UNKNOWN),
dsvFormat(DXGI_FORMAT_UNKNOWN),
blitSRVFormat(DXGI_FORMAT_UNKNOWN),
swizzleFormat(ANGLE_FORMAT_NONE),
swizzleFormat(angle::Format::NONE),
mipGenerationFunction(nullptr),
colorReadFunction(nullptr)
{
}
ANGLEFormatSet::ANGLEFormatSet(ANGLEFormat format,
ANGLEFormatSet::ANGLEFormatSet(angle::Format format,
GLenum glInternalFormat,
GLenum fboImplementationInternalFormat,
DXGI_FORMAT texFormat,
......@@ -38,7 +38,7 @@ ANGLEFormatSet::ANGLEFormatSet(ANGLEFormat format,
DXGI_FORMAT rtvFormat,
DXGI_FORMAT dsvFormat,
DXGI_FORMAT blitSRVFormat,
ANGLEFormat swizzleFormat,
angle::Format swizzleFormat,
MipGenerationFunction mipGenerationFunction,
ColorReadFunction colorReadFunction)
: format(format),
......@@ -60,7 +60,7 @@ ANGLEFormatSet::ANGLEFormatSet(ANGLEFormat format,
// This function allows querying for the DXGI texture formats to use for textures, SRVs, RTVs and
// DSVs given a GL internal format.
TextureFormat::TextureFormat(GLenum internalFormat,
const ANGLEFormat angleFormat,
const angle::Format angleFormat,
InitializeTextureDataFunction internalFormatInitializer,
const Renderer11DeviceCaps &deviceCaps)
: internalFormat(internalFormat),
......@@ -69,7 +69,7 @@ TextureFormat::TextureFormat(GLenum internalFormat,
dataInitializerFunction(internalFormatInitializer),
loadFunctions(GetLoadFunctionsMap(internalFormat, formatSet.texFormat))
{
ASSERT(!loadFunctions.empty() || angleFormat == ANGLE_FORMAT_NONE);
ASSERT(!loadFunctions.empty() || angleFormat == angle::Format::NONE);
}
} // namespace d3d11
......
......@@ -14,9 +14,9 @@
#include "common/angleutils.h"
#include "common/platform.h"
#include "libANGLE/renderer/Format.h"
#include "libANGLE/renderer/renderer_utils.h"
#include "libANGLE/renderer/d3d/formatutilsD3D.h"
#include "libANGLE/renderer/d3d/d3d11/texture_format_table_autogen.h"
namespace rx
{
......@@ -41,7 +41,7 @@ struct LoadImageFunctionInfo
struct ANGLEFormatSet final : angle::NonCopyable
{
ANGLEFormatSet();
ANGLEFormatSet(ANGLEFormat format,
ANGLEFormatSet(angle::Format format,
GLenum glInternalFormat,
GLenum fboImplementationInternalFormat,
DXGI_FORMAT texFormat,
......@@ -49,11 +49,11 @@ struct ANGLEFormatSet final : angle::NonCopyable
DXGI_FORMAT rtvFormat,
DXGI_FORMAT dsvFormat,
DXGI_FORMAT blitSRVFormat,
ANGLEFormat swizzleFormat,
angle::Format swizzleFormat,
MipGenerationFunction mipGenerationFunction,
ColorReadFunction colorReadFunction);
ANGLEFormat format;
angle::Format format;
// The closest matching GL internal format for the DXGI formats this format uses. Note that this
// may be a different internal format than the one this ANGLE format is used for.
......@@ -71,7 +71,7 @@ struct ANGLEFormatSet final : angle::NonCopyable
DXGI_FORMAT blitSRVFormat;
ANGLEFormat swizzleFormat;
angle::Format swizzleFormat;
MipGenerationFunction mipGenerationFunction;
ColorReadFunction colorReadFunction;
......@@ -80,7 +80,7 @@ struct ANGLEFormatSet final : angle::NonCopyable
struct TextureFormat : public angle::NonCopyable
{
TextureFormat(GLenum internalFormat,
const ANGLEFormat angleFormat,
const angle::Format angleFormat,
InitializeTextureDataFunction internalFormatInitializer,
const Renderer11DeviceCaps &deviceCaps);
......@@ -94,7 +94,7 @@ struct TextureFormat : public angle::NonCopyable
LoadFunctionMap loadFunctions;
};
const ANGLEFormatSet &GetANGLEFormatSet(ANGLEFormat angleFormat,
const ANGLEFormatSet &GetANGLEFormatSet(angle::Format angleFormat,
const Renderer11DeviceCaps &deviceCaps);
const TextureFormat &GetTextureFormatInfo(GLenum internalformat,
......
This source diff could not be displayed because it is too large. You can view the blob instead.
// GENERATED FILE - DO NOT EDIT.
// Generated by gen_texture_format_table.py using data from texture_format_data.json
//
// 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.
//
namespace rx
{
namespace d3d11
{
enum ANGLEFormat
{
ANGLE_FORMAT_A8_UNORM,
ANGLE_FORMAT_B4G4R4A4_UNORM,
ANGLE_FORMAT_B5G5R5A1_UNORM,
ANGLE_FORMAT_B5G6R5_UNORM,
ANGLE_FORMAT_B8G8R8A8_UNORM,
ANGLE_FORMAT_BC1_UNORM,
ANGLE_FORMAT_BC2_UNORM,
ANGLE_FORMAT_BC3_UNORM,
ANGLE_FORMAT_D16_UNORM,
ANGLE_FORMAT_D24_UNORM_S8_UINT,
ANGLE_FORMAT_D32_FLOAT,
ANGLE_FORMAT_D32_FLOAT_S8X24_UINT,
ANGLE_FORMAT_NONE,
ANGLE_FORMAT_R10G10B10A2_UINT,
ANGLE_FORMAT_R10G10B10A2_UNORM,
ANGLE_FORMAT_R11G11B10_FLOAT,
ANGLE_FORMAT_R16G16B16A16_FLOAT,
ANGLE_FORMAT_R16G16B16A16_SINT,
ANGLE_FORMAT_R16G16B16A16_SNORM,
ANGLE_FORMAT_R16G16B16A16_UINT,
ANGLE_FORMAT_R16G16B16A16_UNORM,
ANGLE_FORMAT_R16G16_FLOAT,
ANGLE_FORMAT_R16G16_SINT,
ANGLE_FORMAT_R16G16_SNORM,
ANGLE_FORMAT_R16G16_UINT,
ANGLE_FORMAT_R16G16_UNORM,
ANGLE_FORMAT_R16_FLOAT,
ANGLE_FORMAT_R16_SINT,
ANGLE_FORMAT_R16_SNORM,
ANGLE_FORMAT_R16_UINT,
ANGLE_FORMAT_R16_UNORM,
ANGLE_FORMAT_R32G32B32A32_FLOAT,
ANGLE_FORMAT_R32G32B32A32_SINT,
ANGLE_FORMAT_R32G32B32A32_UINT,
ANGLE_FORMAT_R32G32_FLOAT,
ANGLE_FORMAT_R32G32_SINT,
ANGLE_FORMAT_R32G32_UINT,
ANGLE_FORMAT_R32_FLOAT,
ANGLE_FORMAT_R32_SINT,
ANGLE_FORMAT_R32_UINT,
ANGLE_FORMAT_R8G8B8A8_SINT,
ANGLE_FORMAT_R8G8B8A8_SNORM,
ANGLE_FORMAT_R8G8B8A8_UINT,
ANGLE_FORMAT_R8G8B8A8_UNORM,
ANGLE_FORMAT_R8G8B8A8_UNORM_SRGB,
ANGLE_FORMAT_R8G8_SINT,
ANGLE_FORMAT_R8G8_SNORM,
ANGLE_FORMAT_R8G8_UINT,
ANGLE_FORMAT_R8G8_UNORM,
ANGLE_FORMAT_R8_SINT,
ANGLE_FORMAT_R8_SNORM,
ANGLE_FORMAT_R8_UINT,
ANGLE_FORMAT_R8_UNORM,
ANGLE_FORMAT_R9G9B9E5_SHAREDEXP
};
} // namespace d3d11
} // namespace rx
......@@ -169,6 +169,7 @@
'libANGLE/renderer/EGLImplFactory.h',
'libANGLE/renderer/FenceNVImpl.h',
'libANGLE/renderer/FenceSyncImpl.h',
'libANGLE/renderer/Format.h',
'libANGLE/renderer/FramebufferAttachmentObjectImpl.h',
'libANGLE/renderer/FramebufferImpl.h',
'libANGLE/renderer/GLImplFactory.h',
......@@ -421,7 +422,6 @@
'libANGLE/renderer/d3d/d3d11/Trim11.cpp',
'libANGLE/renderer/d3d/d3d11/Trim11.h',
'libANGLE/renderer/d3d/d3d11/texture_format_table_autogen.cpp',
'libANGLE/renderer/d3d/d3d11/texture_format_table_autogen.h',
'libANGLE/renderer/d3d/d3d11/texture_format_table_utils.h',
'libANGLE/renderer/d3d/d3d11/texture_format_table.cpp',
'libANGLE/renderer/d3d/d3d11/texture_format_table.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