Commit 4f57e5f9 by Jamie Madill Committed by Commit Bot

D3D11: Make several format tables constexpr.

This should guarantee the best memory access patterns. It introduces some indirections for some format queries, but most of these should be direct array lookups, or used infrequently. We can optimize this later if necessary. BUG=angleproject:1389 Change-Id: I5e2c8c530a07798494afd3ea36b6164d7564c02c Reviewed-on: https://chromium-review.googlesource.com/403314 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent 1d2c41d6
//
// 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 texture storage. Across multiple
// renderer back-ends, there are common formats and some distinct
// permutations, this enum encapsulates them all.
#include "libANGLE/renderer/Format.h"
#include "image_util/copyimage.h"
using namespace rx;
namespace angle
{
namespace
{
const FastCopyFunctionMap &GetFastCopyFunctionsMap(Format::ID formatID)
{
switch (formatID)
{
case Format::ID::B8G8R8A8_UNORM:
{
static FastCopyFunctionMap fastCopyMap;
if (fastCopyMap.empty())
{
fastCopyMap[gl::FormatType(GL_RGBA, GL_UNSIGNED_BYTE)] = CopyBGRA8ToRGBA8;
}
return fastCopyMap;
}
default:
{
static FastCopyFunctionMap emptyMap;
return emptyMap;
}
}
}
} // anonymous namespace
Format::Format(ID id,
GLenum glFormat,
GLenum fboFormat,
MipGenerationFunction mipGen,
ColorReadFunction colorRead,
GLenum componentType,
GLuint redBits,
GLuint greenBits,
GLuint blueBits,
GLuint alphaBits,
GLuint depthBits,
GLuint stencilBits)
: id(id),
glInternalFormat(glFormat),
fboImplementationInternalFormat(fboFormat),
mipGenerationFunction(mipGen),
colorReadFunction(colorRead),
fastCopyFunctions(GetFastCopyFunctionsMap(id)),
componentType(componentType),
redBits(redBits),
greenBits(greenBits),
blueBits(blueBits),
alphaBits(alphaBits),
depthBits(depthBits),
stencilBits(stencilBits)
{
}
} // namespace angle
......@@ -15,6 +15,10 @@
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/renderer_utils.h"
#include "image_util/copyimage.h"
#include "image_util/generatemip.h"
#include "image_util/loadimage.h"
namespace angle
{
......@@ -22,20 +26,21 @@ struct Format final : angle::NonCopyable
{
enum class ID;
Format(ID id,
GLenum glFormat,
GLenum fboFormat,
rx::MipGenerationFunction mipGen,
rx::ColorReadFunction colorRead,
GLenum componentType,
GLuint redBits,
GLuint greenBits,
GLuint blueBits,
GLuint alphaBits,
GLuint depthBits,
GLuint stencilBits);
static const Format &Get(ID id);
constexpr Format(ID id,
GLenum glFormat,
GLenum fboFormat,
rx::MipGenerationFunction mipGen,
const rx::FastCopyFunctionMap &fastCopyFunctions,
rx::ColorReadFunction colorRead,
GLenum componentType,
GLuint redBits,
GLuint greenBits,
GLuint blueBits,
GLuint alphaBits,
GLuint depthBits,
GLuint stencilBits);
constexpr static const Format &Get(ID id);
ID id;
......@@ -52,7 +57,7 @@ struct Format final : angle::NonCopyable
rx::ColorReadFunction colorReadFunction;
// A map from a gl::FormatType to a fast pixel copy function for this format.
rx::FastCopyFunctionMap fastCopyFunctions;
const rx::FastCopyFunctionMap &fastCopyFunctions;
GLenum componentType;
......@@ -64,8 +69,54 @@ struct Format final : angle::NonCopyable
GLuint stencilBits;
};
static constexpr rx::FastCopyFunctionMap::Entry BGRAEntry = {GL_RGBA, GL_UNSIGNED_BYTE,
CopyBGRA8ToRGBA8};
static constexpr rx::FastCopyFunctionMap BGRACopyFunctions = {&BGRAEntry, 1};
static constexpr rx::FastCopyFunctionMap NoCopyFunctions;
constexpr Format::Format(ID id,
GLenum glFormat,
GLenum fboFormat,
rx::MipGenerationFunction mipGen,
const rx::FastCopyFunctionMap &fastCopyFunctions,
rx::ColorReadFunction colorRead,
GLenum componentType,
GLuint redBits,
GLuint greenBits,
GLuint blueBits,
GLuint alphaBits,
GLuint depthBits,
GLuint stencilBits)
: id(id),
glInternalFormat(glFormat),
fboImplementationInternalFormat(fboFormat),
mipGenerationFunction(mipGen),
colorReadFunction(colorRead),
fastCopyFunctions(fastCopyFunctions),
componentType(componentType),
redBits(redBits),
greenBits(greenBits),
blueBits(blueBits),
alphaBits(alphaBits),
depthBits(depthBits),
stencilBits(stencilBits)
{
}
} // namespace angle
#include "libANGLE/renderer/Format_ID_autogen.inl"
#include "libANGLE/renderer/Format_table_autogen.inl"
namespace angle
{
// static
constexpr const Format &Format::Get(ID id)
{
return g_formatInfoTable[static_cast<size_t>(id)];
}
} // namespace angle
#endif // LIBANGLE_RENDERER_FORMAT_H_
......@@ -1470,7 +1470,7 @@ gl::Error Blit11::copyDepthStencilImpl(const TextureHelper11 &source,
if (stencilOnly)
{
const auto &srcFormat = source.getFormatSet().format;
const auto &srcFormat = source.getFormatSet().format();
// Stencil channel should be right after the depth channel. Some views to depth/stencil
// resources have red channel for depth, in which case the depth channel bit width is in
......
......@@ -332,7 +332,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
"Internal render target view pointer unexpectedly null.");
}
const auto &nativeFormat = renderTarget->getFormatSet().format;
const auto &nativeFormat = renderTarget->getFormatSet().format();
// Check if the actual format has a channel that the internal format does not and
// set them to the default values
......@@ -389,7 +389,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
RenderTarget11 *renderTarget = nullptr;
ANGLE_TRY(attachment->getRenderTarget(&renderTarget));
const auto &nativeFormat = renderTarget->getFormatSet().format;
const auto &nativeFormat = renderTarget->getFormatSet().format();
unsigned int stencilUnmasked =
(stencilAttachment != nullptr) ? (1 << nativeFormat.stencilBits) - 1 : 0;
......
......@@ -358,7 +358,7 @@ gl::Error Framebuffer11::blitImpl(const gl::Rectangle &sourceArea,
GLenum Framebuffer11::getRenderTargetImplementationFormat(RenderTargetD3D *renderTarget) const
{
RenderTarget11 *renderTarget11 = GetAs<RenderTarget11>(renderTarget);
return renderTarget11->getFormatSet().format.fboImplementationInternalFormat;
return renderTarget11->getFormatSet().format().fboImplementationInternalFormat;
}
void Framebuffer11::updateColorRenderTarget(size_t colorIndex)
......
......@@ -64,7 +64,7 @@ gl::Error Image11::generateMipmap(Image11 *dest,
uint8_t *destData = reinterpret_cast<uint8_t *>(destMapped.pData);
auto mipGenerationFunction =
d3d11::Format::Get(src->getInternalFormat(), rendererCaps).format.mipGenerationFunction;
d3d11::Format::Get(src->getInternalFormat(), rendererCaps).format().mipGenerationFunction;
mipGenerationFunction(src->getWidth(), src->getHeight(), src->getDepth(), sourceData,
srcMapped.RowPitch, srcMapped.DepthPitch, destData, destMapped.RowPitch,
destMapped.DepthPitch);
......@@ -251,7 +251,7 @@ gl::Error Image11::loadData(const gl::Box &area,
const d3d11::Format &d3dFormatInfo =
d3d11::Format::Get(mInternalFormat, mRenderer->getRenderer11DeviceCaps());
LoadImageFunction loadFunction = d3dFormatInfo.loadFunctions(type).loadFunction;
LoadImageFunction loadFunction = d3dFormatInfo.getLoadFunctions()(type).loadFunction;
D3D11_MAPPED_SUBRESOURCE mappedImage;
ANGLE_TRY(map(D3D11_MAP_WRITE, &mappedImage));
......@@ -286,7 +286,8 @@ gl::Error Image11::loadCompressedData(const gl::Box &area, const void *input)
const d3d11::Format &d3dFormatInfo =
d3d11::Format::Get(mInternalFormat, mRenderer->getRenderer11DeviceCaps());
LoadImageFunction loadFunction = d3dFormatInfo.loadFunctions(GL_UNSIGNED_BYTE).loadFunction;
LoadImageFunction loadFunction =
d3dFormatInfo.getLoadFunctions()(GL_UNSIGNED_BYTE).loadFunction;
D3D11_MAPPED_SUBRESOURCE mappedImage;
ANGLE_TRY(map(D3D11_MAP_WRITE, &mappedImage));
......@@ -364,7 +365,7 @@ gl::Error Image11::copyFromFramebuffer(const gl::Offset &destOffset,
const auto &destD3D11Format =
d3d11::Format::Get(mInternalFormat, mRenderer->getRenderer11DeviceCaps());
auto loadFunction = destD3D11Format.loadFunctions(destFormatInfo.type);
auto loadFunction = destD3D11Format.getLoadFunctions()(destFormatInfo.type);
gl::Error error = gl::NoError();
if (loadFunction.requiresConversion)
{
......
......@@ -258,7 +258,7 @@ TextureRenderTarget11::TextureRenderTarget11(ID3D11RenderTargetView *rtv,
{
mSubresourceIndex = GetRTVSubresourceIndex(mTexture, mRenderTarget);
}
ASSERT(mFormatSet.format.id != angle::Format::ID::NONE || mWidth == 0 || mHeight == 0);
ASSERT(mFormatSet.formatID != angle::Format::ID::NONE || mWidth == 0 || mHeight == 0);
}
TextureRenderTarget11::TextureRenderTarget11(ID3D11DepthStencilView *dsv,
......@@ -302,7 +302,7 @@ TextureRenderTarget11::TextureRenderTarget11(ID3D11DepthStencilView *dsv,
{
mSubresourceIndex = GetDSVSubresourceIndex(mTexture, mDepthStencil);
}
ASSERT(mFormatSet.format.id != angle::Format::ID::NONE || mWidth == 0 || mHeight == 0);
ASSERT(mFormatSet.formatID != angle::Format::ID::NONE || mWidth == 0 || mHeight == 0);
}
TextureRenderTarget11::~TextureRenderTarget11()
......
......@@ -3688,7 +3688,7 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const
}
// We don't support formats which we can't represent without conversion
if (d3d11FormatInfo.format.glInternalFormat != internalFormat)
if (d3d11FormatInfo.format().glInternalFormat != internalFormat)
{
return false;
}
......@@ -3968,9 +3968,9 @@ gl::Error Renderer11::packPixels(const TextureHelper11 &textureHelper,
int inputPitch = static_cast<int>(mapping.RowPitch);
const auto &formatInfo = textureHelper.getFormatSet();
ASSERT(formatInfo.format.glInternalFormat != GL_NONE);
ASSERT(formatInfo.format().glInternalFormat != GL_NONE);
PackPixels(params, formatInfo.format, inputPitch, source, pixelsOut);
PackPixels(params, formatInfo.format(), inputPitch, source, pixelsOut);
mDeviceContext->Unmap(readResource, 0);
......@@ -4128,7 +4128,7 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn,
const auto &destFormatInfo = gl::GetInternalFormatInfo(drawRenderTarget->getInternalFormat());
const auto &srcFormatInfo = gl::GetInternalFormatInfo(readRenderTarget->getInternalFormat());
const auto &formatSet = drawRenderTarget11->getFormatSet();
const auto &nativeFormat = formatSet.format;
const auto &nativeFormat = formatSet.format();
// Some blits require masking off emulated texture channels. eg: from RGBA8 to RGB8, we
// emulate RGB8 with RGBA8, so we need to mask off the alpha channel when we copy.
......@@ -4166,8 +4166,8 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn,
bool partialDSBlit =
(nativeFormat.depthBits > 0 && depthBlit) != (nativeFormat.stencilBits > 0 && stencilBlit);
if (readRenderTarget11->getFormatSet().format.id ==
drawRenderTarget11->getFormatSet().format.id &&
if (readRenderTarget11->getFormatSet().formatID ==
drawRenderTarget11->getFormatSet().formatID &&
!stretchRequired && !outOfBounds && !flipRequired && !partialDSBlit &&
!colorMaskingNeeded && (!(depthBlit || stencilBlit) || wholeBufferCopy))
{
......
......@@ -215,7 +215,7 @@ gl::Error TextureStorage11::getSRV(const gl::TextureState &textureState,
// 1. the drop stencil workaround is enabled.
bool workaround = mRenderer->getWorkarounds().emulateTinyStencilTextures;
// 2. this is a stencil texture.
bool hasStencil = (mFormatInfo.format.stencilBits > 0);
bool hasStencil = (mFormatInfo.format().stencilBits > 0);
// 3. the texture has a 1x1 or 2x2 mip.
bool hasSmallMips = (getLevelWidth(mMipLevels - 1) <= 2 || getLevelHeight(mMipLevels - 1) <= 2);
......@@ -247,9 +247,11 @@ gl::Error TextureStorage11::getCachedOrCreateSRV(const SRVKey &key,
if (key.swizzle)
{
ASSERT(!key.dropStencil || mFormatInfo.swizzle.format.stencilBits == 0);
const auto &swizzleFormat =
mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps());
ASSERT(!key.dropStencil || swizzleFormat.format().stencilBits == 0);
ANGLE_TRY(getSwizzleTexture(&texture));
format = mFormatInfo.swizzle.srvFormat;
format = swizzleFormat.srvFormat;
}
else if (key.dropStencil)
{
......@@ -643,7 +645,7 @@ gl::Error TextureStorage11::setData(const gl::ImageIndex &index,
MemoryBuffer *conversionBuffer = nullptr;
const uint8_t *data = nullptr;
LoadImageFunctionInfo loadFunctionInfo = d3d11Format.loadFunctions(type);
LoadImageFunctionInfo loadFunctionInfo = d3d11Format.getLoadFunctions()(type);
if (loadFunctionInfo.requiresConversion)
{
ANGLE_TRY(mRenderer->getScratchMemoryBuffer(neededSize, &conversionBuffer));
......@@ -1249,7 +1251,7 @@ gl::Error TextureStorage11_2D::getSwizzleTexture(ID3D11Resource **outTexture)
desc.Height = mTextureHeight;
desc.MipLevels = mMipLevels;
desc.ArraySize = 1;
desc.Format = mFormatInfo.swizzle.texFormat;
desc.Format = mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).texFormat;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
......@@ -1286,7 +1288,8 @@ gl::Error TextureStorage11_2D::getSwizzleRenderTarget(int mipLevel, ID3D11Render
ID3D11Device *device = mRenderer->getDevice();
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
rtvDesc.Format = mFormatInfo.swizzle.rtvFormat;
rtvDesc.Format =
mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).rtvFormat;
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
rtvDesc.Texture2D.MipSlice = mTopLevel + mipLevel;
......@@ -1608,7 +1611,7 @@ gl::Error TextureStorage11_EGLImage::getSwizzleTexture(ID3D11Resource **outTextu
desc.Height = mTextureHeight;
desc.MipLevels = mMipLevels;
desc.ArraySize = 1;
desc.Format = mFormatInfo.swizzle.texFormat;
desc.Format = mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).texFormat;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
......@@ -1646,7 +1649,8 @@ gl::Error TextureStorage11_EGLImage::getSwizzleRenderTarget(int mipLevel,
ID3D11Device *device = mRenderer->getDevice();
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
rtvDesc.Format = mFormatInfo.swizzle.rtvFormat;
rtvDesc.Format =
mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).rtvFormat;
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
rtvDesc.Texture2D.MipSlice = mTopLevel + mipLevel;
......@@ -2383,7 +2387,7 @@ gl::Error TextureStorage11_Cube::getSwizzleTexture(ID3D11Resource **outTexture)
desc.Height = mTextureHeight;
desc.MipLevels = mMipLevels;
desc.ArraySize = CUBE_FACE_COUNT;
desc.Format = mFormatInfo.swizzle.texFormat;
desc.Format = mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).texFormat;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
......@@ -2421,7 +2425,8 @@ gl::Error TextureStorage11_Cube::getSwizzleRenderTarget(int mipLevel,
ID3D11Device *device = mRenderer->getDevice();
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
rtvDesc.Format = mFormatInfo.swizzle.rtvFormat;
rtvDesc.Format =
mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).rtvFormat;
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
rtvDesc.Texture2DArray.MipSlice = mTopLevel + mipLevel;
rtvDesc.Texture2DArray.FirstArraySlice = 0;
......@@ -2849,7 +2854,7 @@ gl::Error TextureStorage11_3D::getSwizzleTexture(ID3D11Resource **outTexture)
desc.Height = mTextureHeight;
desc.Depth = mTextureDepth;
desc.MipLevels = mMipLevels;
desc.Format = mFormatInfo.swizzle.texFormat;
desc.Format = mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).texFormat;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
desc.CPUAccessFlags = 0;
......@@ -2884,7 +2889,8 @@ gl::Error TextureStorage11_3D::getSwizzleRenderTarget(int mipLevel, ID3D11Render
ID3D11Device *device = mRenderer->getDevice();
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
rtvDesc.Format = mFormatInfo.swizzle.rtvFormat;
rtvDesc.Format =
mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).rtvFormat;
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
rtvDesc.Texture3D.MipSlice = mTopLevel + mipLevel;
rtvDesc.Texture3D.FirstWSlice = 0;
......@@ -3284,7 +3290,7 @@ gl::Error TextureStorage11_2DArray::getSwizzleTexture(ID3D11Resource **outTextur
desc.Height = mTextureHeight;
desc.MipLevels = mMipLevels;
desc.ArraySize = mTextureDepth;
desc.Format = mFormatInfo.swizzle.texFormat;
desc.Format = mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).texFormat;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
......@@ -3322,7 +3328,8 @@ gl::Error TextureStorage11_2DArray::getSwizzleRenderTarget(int mipLevel,
ID3D11Device *device = mRenderer->getDevice();
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
rtvDesc.Format = mFormatInfo.swizzle.rtvFormat;
rtvDesc.Format =
mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).rtvFormat;
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
rtvDesc.Texture2DArray.MipSlice = mTopLevel + mipLevel;
rtvDesc.Texture2DArray.FirstArraySlice = 0;
......
......@@ -19,7 +19,7 @@ sys.path.append('../..')
import angle_format
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
// 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
......@@ -60,7 +60,7 @@ const Format &Format::Get(GLenum internalFormat, const Renderer11DeviceCaps &dev
// clang-format on
UNREACHABLE();
static const Format defaultInfo;
static constexpr Format defaultInfo;
return defaultInfo;
}}
......@@ -216,23 +216,7 @@ def get_blit_srv_format(angle_format):
format_entry_template = """{space}{{
{space} static const Format info({internalFormat},
{space} angle::Format::ID::{formatName},
{space} {texFormat},
{space} {srvFormat},
{space} {rtvFormat},
{space} {dsvFormat},
{space} {blitSRVFormat},
{space} {swizzleFormat},
{space} {initializer},
{space} deviceCaps);
{space} return info;
{space}}}
"""
split_format_entry_template = """{space} {condition}
{space} {{
{space} static const Format info({internalFormat},
{space} static constexpr Format info({internalFormat},
{space} angle::Format::ID::{formatName},
{space} {texFormat},
{space} {srvFormat},
......@@ -240,8 +224,22 @@ split_format_entry_template = """{space} {condition}
{space} {dsvFormat},
{space} {blitSRVFormat},
{space} {swizzleFormat},
{space} {initializer},
{space} deviceCaps);
{space} {initializer});
{space} return info;
{space}}}
"""
split_format_entry_template = """{space} {condition}
{space} {{
{space} static constexpr Format info({internalFormat},
{space} angle::Format::ID::{formatName},
{space} {texFormat},
{space} {srvFormat},
{space} {rtvFormat},
{space} {dsvFormat},
{space} {blitSRVFormat},
{space} {swizzleFormat},
{space} {initializer});
{space} return info;
{space} }}
"""
......@@ -344,16 +342,19 @@ def reject_duplicate_keys(pairs):
return found_keys
json_map = angle_format.load_with_override(os.path.abspath('texture_format_map.json'))
data_source_name = 'texture_format_data.json'
with open('texture_format_data.json') as texture_format_json_file:
with open(data_source_name) as texture_format_json_file:
texture_format_data = texture_format_json_file.read()
texture_format_json_file.close()
json_data = json.loads(texture_format_data, object_pairs_hook=angle_format.reject_duplicate_keys)
angle_format_cases = parse_json_into_switch_angle_format_string(json_map, json_data)
output_cpp = template_texture_format_table_autogen_cpp.format(
copyright_year=date.today().year,
angle_format_info_cases=angle_format_cases)
script_name = sys.argv[0],
copyright_year = date.today().year,
angle_format_info_cases = angle_format_cases,
data_source_name = data_source_name)
with open('texture_format_table_autogen.cpp', 'wt') as out_file:
out_file.write(output_cpp)
out_file.close()
......@@ -15,40 +15,19 @@ namespace rx
namespace d3d11
{
Format::Format()
: internalFormat(GL_NONE),
format(angle::Format::Get(angle::Format::ID::NONE)),
texFormat(DXGI_FORMAT_UNKNOWN),
srvFormat(DXGI_FORMAT_UNKNOWN),
rtvFormat(DXGI_FORMAT_UNKNOWN),
dsvFormat(DXGI_FORMAT_UNKNOWN),
blitSRVFormat(DXGI_FORMAT_UNKNOWN),
swizzle(*this),
dataInitializerFunction(nullptr)
const Format &Format::getSwizzleFormat(const Renderer11DeviceCaps &deviceCaps) const
{
return (swizzleFormat == internalFormat ? *this : Format::Get(swizzleFormat, deviceCaps));
}
Format::Format(GLenum internalFormat,
angle::Format::ID formatID,
DXGI_FORMAT texFormat,
DXGI_FORMAT srvFormat,
DXGI_FORMAT rtvFormat,
DXGI_FORMAT dsvFormat,
DXGI_FORMAT blitSRVFormat,
GLenum swizzleFormat,
InitializeTextureDataFunction internalFormatInitializer,
const Renderer11DeviceCaps &deviceCaps)
: internalFormat(internalFormat),
format(angle::Format::Get(formatID)),
texFormat(texFormat),
srvFormat(srvFormat),
rtvFormat(rtvFormat),
dsvFormat(dsvFormat),
blitSRVFormat(blitSRVFormat),
swizzle(swizzleFormat == internalFormat ? *this : Format::Get(swizzleFormat, deviceCaps)),
dataInitializerFunction(internalFormatInitializer),
loadFunctions(GetLoadFunctionsMap(internalFormat, formatID))
LoadFunctionMap Format::getLoadFunctions() const
{
return GetLoadFunctionsMap(internalFormat, formatID);
}
const angle::Format &Format::format() const
{
return angle::Format::Get(formatID);
}
} // namespace d3d11
......
......@@ -32,22 +32,25 @@ namespace d3d11
// DSVs given a GL internal format.
struct Format final : angle::NonCopyable
{
Format();
Format(GLenum internalFormat,
angle::Format::ID formatID,
DXGI_FORMAT texFormat,
DXGI_FORMAT srvFormat,
DXGI_FORMAT rtvFormat,
DXGI_FORMAT dsvFormat,
DXGI_FORMAT blitSRVFormat,
GLenum swizzleFormat,
InitializeTextureDataFunction internalFormatInitializer,
const Renderer11DeviceCaps &deviceCaps);
constexpr Format();
constexpr Format(GLenum internalFormat,
angle::Format::ID formatID,
DXGI_FORMAT texFormat,
DXGI_FORMAT srvFormat,
DXGI_FORMAT rtvFormat,
DXGI_FORMAT dsvFormat,
DXGI_FORMAT blitSRVFormat,
GLenum swizzleFormat,
InitializeTextureDataFunction internalFormatInitializer);
static const Format &Get(GLenum internalFormat, const Renderer11DeviceCaps &deviceCaps);
const Format &getSwizzleFormat(const Renderer11DeviceCaps &deviceCaps) const;
LoadFunctionMap getLoadFunctions() const;
const angle::Format &format() const;
GLenum internalFormat;
const angle::Format &format;
angle::Format::ID formatID;
DXGI_FORMAT texFormat;
DXGI_FORMAT srvFormat;
......@@ -56,13 +59,45 @@ struct Format final : angle::NonCopyable
DXGI_FORMAT blitSRVFormat;
const Format &swizzle;
GLenum swizzleFormat;
InitializeTextureDataFunction dataInitializerFunction;
LoadFunctionMap loadFunctions;
};
constexpr Format::Format()
: internalFormat(GL_NONE),
formatID(angle::Format::ID::NONE),
texFormat(DXGI_FORMAT_UNKNOWN),
srvFormat(DXGI_FORMAT_UNKNOWN),
rtvFormat(DXGI_FORMAT_UNKNOWN),
dsvFormat(DXGI_FORMAT_UNKNOWN),
blitSRVFormat(DXGI_FORMAT_UNKNOWN),
swizzleFormat(GL_NONE),
dataInitializerFunction(nullptr)
{
}
constexpr Format::Format(GLenum internalFormat,
angle::Format::ID formatID,
DXGI_FORMAT texFormat,
DXGI_FORMAT srvFormat,
DXGI_FORMAT rtvFormat,
DXGI_FORMAT dsvFormat,
DXGI_FORMAT blitSRVFormat,
GLenum swizzleFormat,
InitializeTextureDataFunction internalFormatInitializer)
: internalFormat(internalFormat),
formatID(formatID),
texFormat(texFormat),
srvFormat(srvFormat),
rtvFormat(rtvFormat),
dsvFormat(dsvFormat),
blitSRVFormat(blitSRVFormat),
swizzleFormat(swizzleFormat),
dataInitializerFunction(internalFormatInitializer)
{
}
} // namespace d3d11
} // namespace rx
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -16,7 +16,7 @@ import re
import sys
template_autogen_h = """// GENERATED FILE - DO NOT EDIT.
// Generated by gen_angle_format_table.py using data from angle_format_data.json
// 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
......@@ -35,8 +35,8 @@ enum class Format::ID
}} // namespace angle
"""
template_autogen_cpp = """// GENERATED FILE - DO NOT EDIT.
// Generated by gen_angle_format_table.py using data from angle_format_data.json
template_autogen_inl = """// 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
......@@ -45,31 +45,15 @@ template_autogen_cpp = """// GENERATED FILE - DO NOT EDIT.
// ANGLE Format table:
// Queries for typed format information from the ANGLE format enum.
#include "libANGLE/renderer/Format.h"
#include "image_util/copyimage.h"
#include "image_util/generatemip.h"
#include "image_util/loadimage.h"
namespace angle
{{
// static
const Format &Format::Get(ID id)
constexpr Format g_formatInfoTable[] =
{{
// clang-format off
switch (id)
{{
{angle_format_info_cases}
default:
UNREACHABLE();
break;
}}
// clang-format on
static const Format noneInfo(ID::NONE, GL_NONE, GL_NONE, nullptr, nullptr, GL_NONE, 0, 0, 0, 0, 0, 0);
return noneInfo;
}}
{{ Format::ID::NONE, GL_NONE, GL_NONE, nullptr, NoCopyFunctions, nullptr, GL_NONE, 0, 0, 0, 0, 0, 0 }},
{angle_format_info_cases} // clang-format on
}};
}} // namespace angle
"""
......@@ -123,16 +107,7 @@ def get_color_read_function(angle_format):
}
return 'ReadColor<' + channel_struct + ', '+ component_type_map[angle_format['componentType']] + '>'
format_entry_template = """{space}{{
{space} static const Format info(ID::{id},
{space} {glInternalFormat},
{space} {fboImplementationInternalFormat},
{space} {mipGenerationFunction},
{space} {colorReadFunction},
{space} {namedComponentType},
{space} {R}, {G}, {B}, {A}, {D}, {S});
{space} return info;
{space}}}
format_entry_template = """ {{ Format::ID::{id}, {glInternalFormat}, {fboImplementationInternalFormat}, {mipGenerationFunction}, {fastCopyFunctions}, {colorReadFunction}, {namedComponentType}, {R}, {G}, {B}, {A}, {D}, {S} }},
"""
def get_component_type(format_id):
......@@ -197,8 +172,8 @@ def json_to_table_data(format_id, json, angle_to_gl):
table_data = ""
parsed = {
"space": " ",
"id": format_id,
"fastCopyFunctions": "NoCopyFunctions",
}
for k, v in json.iteritems():
......@@ -231,14 +206,17 @@ def json_to_table_data(format_id, json, angle_to_gl):
parsed["namedComponentType"] = get_named_component_type(parsed["componentType"])
if format_id == "B8G8R8A8_UNORM":
parsed["fastCopyFunctions"] = "BGRACopyFunctions"
return format_entry_template.format(**parsed)
def parse_json_into_angle_format_switch_string(all_angle, json_data, angle_to_gl):
def parse_angle_format_table(all_angle, json_data, angle_to_gl):
table_data = ''
for format_id in sorted(all_angle):
format_info = json_data[format_id] if format_id in json_data else {}
table_data += ' case ID::' + format_id + ':\n'
table_data += json_to_table_data(format_id, format_info, angle_to_gl)
if format_id != "NONE":
format_info = json_data[format_id] if format_id in json_data else {}
table_data += json_to_table_data(format_id, format_info, angle_to_gl)
return table_data
......@@ -252,22 +230,27 @@ def gen_enum_string(all_angle):
gl_to_angle = angle_format.load_forward_table('angle_format_map.json')
angle_to_gl = angle_format.load_inverse_table('angle_format_map.json')
json_data = angle_format.load_json('angle_format_data.json')
data_source_name = 'angle_format_data.json'
json_data = angle_format.load_json(data_source_name)
all_angle = angle_to_gl.keys()
angle_format_cases = parse_json_into_angle_format_switch_string(
angle_format_cases = parse_angle_format_table(
all_angle, json_data, angle_to_gl)
output_cpp = template_autogen_cpp.format(
copyright_year=date.today().year,
angle_format_info_cases=angle_format_cases)
with open('Format_autogen.cpp', 'wt') as out_file:
output_cpp = template_autogen_inl.format(
script_name = sys.argv[0],
copyright_year = date.today().year,
angle_format_info_cases = angle_format_cases,
data_source_name = data_source_name)
with open('Format_table_autogen.inl', 'wt') as out_file:
out_file.write(output_cpp)
out_file.close()
enum_data = gen_enum_string(all_angle)
output_h = template_autogen_h.format(
copyright_year=date.today().year,
angle_format_enum=enum_data)
script_name = sys.argv[0],
copyright_year = date.today().year,
angle_format_enum = enum_data,
data_source_name = data_source_name)
with open('Format_ID_autogen.inl', 'wt') as out_file:
out_file.write(output_h)
out_file.close()
......@@ -268,8 +268,25 @@ ColorWriteFunction GetColorWriteFunction(const gl::FormatType &formatType)
ColorCopyFunction GetFastCopyFunction(const FastCopyFunctionMap &fastCopyFunctions,
const gl::FormatType &formatType)
{
auto iter = fastCopyFunctions.find(formatType);
return (iter != fastCopyFunctions.end()) ? iter->second : nullptr;
return fastCopyFunctions.get(formatType);
}
bool FastCopyFunctionMap::has(const gl::FormatType &formatType) const
{
return (get(formatType) != nullptr);
}
ColorCopyFunction FastCopyFunctionMap::get(const gl::FormatType &formatType) const
{
for (size_t index = 0; index < mSize; ++index)
{
if (mData[index].format == formatType.format && mData[index].type == formatType.type)
{
return mData[index].func;
}
}
return nullptr;
}
} // namespace rx
......@@ -44,7 +44,27 @@ typedef void (*ColorReadFunction)(const uint8_t *source, uint8_t *dest);
typedef void (*ColorWriteFunction)(const uint8_t *source, uint8_t *dest);
typedef void (*ColorCopyFunction)(const uint8_t *source, uint8_t *dest);
typedef std::map<gl::FormatType, ColorCopyFunction> FastCopyFunctionMap;
class FastCopyFunctionMap
{
public:
struct Entry
{
GLenum format;
GLenum type;
ColorCopyFunction func;
};
constexpr FastCopyFunctionMap() : FastCopyFunctionMap(nullptr, 0) {}
constexpr FastCopyFunctionMap(const Entry *data, size_t size) : mSize(size), mData(data) {}
bool has(const gl::FormatType &formatType) const;
ColorCopyFunction get(const gl::FormatType &formatType) const;
private:
size_t mSize;
const Entry *mData;
};
struct PackPixelsParams
{
......
......@@ -175,8 +175,7 @@
'libANGLE/renderer/FenceNVImpl.h',
'libANGLE/renderer/FenceSyncImpl.h',
'libANGLE/renderer/Format_ID_autogen.inl',
'libANGLE/renderer/Format_autogen.cpp',
'libANGLE/renderer/Format.cpp',
'libANGLE/renderer/Format_table_autogen.inl',
'libANGLE/renderer/Format.h',
'libANGLE/renderer/FramebufferAttachmentObjectImpl.h',
'libANGLE/renderer/FramebufferImpl.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