Commit 30712068 by Jamie Madill Committed by Commit Bot

Move fast copy functions into angle::Format.

These tables were duplicated in D3D11 and D3D9, and would have to be further duplicated into Vulkan. BUG=angleproject:1455 Change-Id: Ice1b81417d7b14f933b61861c4a9997c260ef72e Reviewed-on: https://chromium-review.googlesource.com/367690Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 41ee2024
//
// 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)
: id(id),
glInternalFormat(glFormat),
fboImplementationInternalFormat(fboFormat),
mipGenerationFunction(mipGen),
colorReadFunction(colorRead),
fastCopyFunctions(GetFastCopyFunctionsMap(id))
{
}
} // namespace angle
......@@ -12,6 +12,7 @@
#ifndef LIBANGLE_RENDERER_FORMAT_H_
#define LIBANGLE_RENDERER_FORMAT_H_
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/renderer_utils.h"
namespace angle
......@@ -25,14 +26,7 @@ struct Format final : angle::NonCopyable
GLenum glFormat,
GLenum fboFormat,
rx::MipGenerationFunction mipGen,
rx::ColorReadFunction colorRead)
: id(id),
glInternalFormat(glFormat),
fboImplementationInternalFormat(fboFormat),
mipGenerationFunction(mipGen),
colorReadFunction(colorRead)
{
}
rx::ColorReadFunction colorRead);
static const Format &Get(ID id);
......@@ -49,6 +43,9 @@ struct Format final : angle::NonCopyable
rx::MipGenerationFunction mipGenerationFunction;
rx::ColorReadFunction colorReadFunction;
// A map from a gl::FormatType to a fast pixel copy function for this format.
rx::FastCopyFunctionMap fastCopyFunctions;
};
} // namespace angle
......
......@@ -3786,12 +3786,10 @@ gl::Error Renderer11::packPixels(const TextureHelper11 &textureHelper,
uint8_t *source = static_cast<uint8_t *>(mapping.pData);
int inputPitch = static_cast<int>(mapping.RowPitch);
const auto &angleFormatInfo = textureHelper.getFormatSet();
const auto &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(textureHelper.getFormat());
ASSERT(angleFormatInfo.format.glInternalFormat != GL_NONE);
const auto &formatInfo = textureHelper.getFormatSet();
ASSERT(formatInfo.format.glInternalFormat != GL_NONE);
PackPixels(params, angleFormatInfo.format, dxgiFormatInfo.fastCopyFunctions, inputPitch, source,
pixelsOut);
PackPixels(params, formatInfo.format, inputPitch, source, pixelsOut);
mDeviceContext->Unmap(readResource, 0);
......
......@@ -24,43 +24,6 @@ namespace rx
namespace d3d11
{
struct D3D11FastCopyFormat
{
GLenum destFormat;
GLenum destType;
ColorCopyFunction copyFunction;
D3D11FastCopyFormat(GLenum destFormat, GLenum destType, ColorCopyFunction copyFunction)
: destFormat(destFormat), destType(destType), copyFunction(copyFunction)
{ }
bool operator<(const D3D11FastCopyFormat& other) const
{
return memcmp(this, &other, sizeof(D3D11FastCopyFormat)) < 0;
}
};
static const FastCopyFunctionMap &GetFastCopyFunctionMap(DXGI_FORMAT dxgiFormat)
{
switch (dxgiFormat)
{
case DXGI_FORMAT_B8G8R8A8_UNORM:
{
static FastCopyFunctionMap fastCopyMap;
if (fastCopyMap.empty())
{
fastCopyMap[gl::FormatType(GL_RGBA, GL_UNSIGNED_BYTE)] = angle::CopyBGRA8ToRGBA8;
}
return fastCopyMap;
}
default:
{
static FastCopyFunctionMap emptyMap;
return emptyMap;
}
}
}
struct DXGIColorFormatInfo
{
size_t redBits;
......@@ -220,7 +183,6 @@ DXGIFormat::DXGIFormat()
depthBits(0),
stencilBits(0),
componentType(GL_NONE),
fastCopyFunctions(),
nativeMipmapSupport(NULL)
{
}
......@@ -265,7 +227,6 @@ void AddDXGIFormat(DXGIFormatInfoMap *map,
}
info.componentType = componentType;
info.fastCopyFunctions = GetFastCopyFunctionMap(dxgiFormat);
info.nativeMipmapSupport = nativeMipmapSupport;
map->insert(std::make_pair(dxgiFormat, info));
......
......@@ -42,8 +42,6 @@ struct DXGIFormat
GLenum componentType;
FastCopyFunctionMap fastCopyFunctions;
NativeMipmapGenerationSupportFunction nativeMipmapSupport;
};
......
......@@ -205,8 +205,7 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Rectangle &area,
packParams.outputPitch = static_cast<GLuint>(outputPitch);
packParams.pack = pack;
PackPixels(packParams, *d3dFormatInfo.info, d3dFormatInfo.fastCopyFunctions, inputPitch, source,
pixels);
PackPixels(packParams, *d3dFormatInfo.info, inputPitch, source, pixels);
systemSurface->UnlockRect();
SafeRelease(systemSurface);
......
......@@ -27,43 +27,6 @@ namespace d3d9
const D3DFORMAT D3DFMT_INTZ = ((D3DFORMAT)(MAKEFOURCC('I', 'N', 'T', 'Z')));
const D3DFORMAT D3DFMT_NULL = ((D3DFORMAT)(MAKEFOURCC('N', 'U', 'L', 'L')));
struct D3D9FastCopyFormat
{
GLenum destFormat;
GLenum destType;
ColorCopyFunction copyFunction;
D3D9FastCopyFormat(GLenum destFormat, GLenum destType, ColorCopyFunction copyFunction)
: destFormat(destFormat), destType(destType), copyFunction(copyFunction)
{ }
bool operator<(const D3D9FastCopyFormat& other) const
{
return memcmp(this, &other, sizeof(D3D9FastCopyFormat)) < 0;
}
};
static const FastCopyFunctionMap &GetFastCopyFunctionMap(D3DFORMAT d3dFormat)
{
switch (d3dFormat)
{
case D3DFMT_A8R8G8B8:
{
static FastCopyFunctionMap fastCopyMap;
if (fastCopyMap.empty())
{
fastCopyMap[gl::FormatType(GL_RGBA, GL_UNSIGNED_BYTE)] = angle::CopyBGRA8ToRGBA8;
}
return fastCopyMap;
}
default:
{
static FastCopyFunctionMap emptyMap;
return emptyMap;
}
}
}
// A map to determine the pixel size and mip generation function of a given D3D format
typedef std::map<D3DFORMAT, D3DFormat> D3D9FormatInfoMap;
......@@ -78,8 +41,7 @@ D3DFormat::D3DFormat()
luminanceBits(0),
depthBits(0),
stencilBits(0),
info(nullptr),
fastCopyFunctions()
info(nullptr)
{
}
......@@ -108,8 +70,7 @@ static inline void InsertD3DFormatInfo(D3D9FormatInfoMap *map,
info.luminanceBits = lumBits;
info.depthBits = depthBits;
info.stencilBits = stencilBits;
info.info = &Format::Get(formatID);
info.fastCopyFunctions = GetFastCopyFunctionMap(format);
info.info = &Format::Get(formatID);
map->insert(std::make_pair(format, info));
}
......
......@@ -45,8 +45,6 @@ struct D3DFormat
GLuint stencilBits;
const angle::Format *info;
FastCopyFunctionMap fastCopyFunctions;
};
const D3DFormat &GetD3DFormatInfo(D3DFORMAT format);
......
......@@ -172,7 +172,6 @@ PackPixelsParams::PackPixelsParams(const gl::Rectangle &areaIn,
void PackPixels(const PackPixelsParams &params,
const angle::Format &sourceFormat,
const FastCopyFunctionMap &fastCopyFunctionsMap,
int inputPitchIn,
const uint8_t *sourceIn,
uint8_t *destWithoutOffset)
......@@ -204,7 +203,8 @@ void PackPixels(const PackPixelsParams &params,
ASSERT(sourceGLInfo.pixelBytes > 0);
gl::FormatType formatType(params.format, params.type);
ColorCopyFunction fastCopyFunc = GetFastCopyFunction(fastCopyFunctionsMap, formatType);
ColorCopyFunction fastCopyFunc =
GetFastCopyFunction(sourceFormat.fastCopyFunctions, formatType);
GLenum sizedDestInternalFormat = gl::GetSizedInternalFormat(formatType.format, formatType.type);
const auto &destFormatInfo = gl::GetInternalFormatInfo(sizedDestInternalFormat);
......
......@@ -67,7 +67,6 @@ struct PackPixelsParams
void PackPixels(const PackPixelsParams &params,
const angle::Format &sourceFormat,
const FastCopyFunctionMap &fastCopyFunctionsMap,
int inputPitch,
const uint8_t *source,
uint8_t *destination);
......
......@@ -171,6 +171,7 @@
'libANGLE/renderer/FenceSyncImpl.h',
'libANGLE/renderer/Format_ID_autogen.inl',
'libANGLE/renderer/Format_autogen.cpp',
'libANGLE/renderer/Format.cpp',
'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