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 @@ ...@@ -12,6 +12,7 @@
#ifndef LIBANGLE_RENDERER_FORMAT_H_ #ifndef LIBANGLE_RENDERER_FORMAT_H_
#define LIBANGLE_RENDERER_FORMAT_H_ #define LIBANGLE_RENDERER_FORMAT_H_
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/renderer_utils.h" #include "libANGLE/renderer/renderer_utils.h"
namespace angle namespace angle
...@@ -25,14 +26,7 @@ struct Format final : angle::NonCopyable ...@@ -25,14 +26,7 @@ struct Format final : angle::NonCopyable
GLenum glFormat, GLenum glFormat,
GLenum fboFormat, GLenum fboFormat,
rx::MipGenerationFunction mipGen, rx::MipGenerationFunction mipGen,
rx::ColorReadFunction colorRead) rx::ColorReadFunction colorRead);
: id(id),
glInternalFormat(glFormat),
fboImplementationInternalFormat(fboFormat),
mipGenerationFunction(mipGen),
colorReadFunction(colorRead)
{
}
static const Format &Get(ID id); static const Format &Get(ID id);
...@@ -49,6 +43,9 @@ struct Format final : angle::NonCopyable ...@@ -49,6 +43,9 @@ struct Format final : angle::NonCopyable
rx::MipGenerationFunction mipGenerationFunction; rx::MipGenerationFunction mipGenerationFunction;
rx::ColorReadFunction colorReadFunction; rx::ColorReadFunction colorReadFunction;
// A map from a gl::FormatType to a fast pixel copy function for this format.
rx::FastCopyFunctionMap fastCopyFunctions;
}; };
} // namespace angle } // namespace angle
......
...@@ -3786,12 +3786,10 @@ gl::Error Renderer11::packPixels(const TextureHelper11 &textureHelper, ...@@ -3786,12 +3786,10 @@ gl::Error Renderer11::packPixels(const TextureHelper11 &textureHelper,
uint8_t *source = static_cast<uint8_t *>(mapping.pData); uint8_t *source = static_cast<uint8_t *>(mapping.pData);
int inputPitch = static_cast<int>(mapping.RowPitch); int inputPitch = static_cast<int>(mapping.RowPitch);
const auto &angleFormatInfo = textureHelper.getFormatSet(); const auto &formatInfo = textureHelper.getFormatSet();
const auto &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(textureHelper.getFormat()); ASSERT(formatInfo.format.glInternalFormat != GL_NONE);
ASSERT(angleFormatInfo.format.glInternalFormat != GL_NONE);
PackPixels(params, angleFormatInfo.format, dxgiFormatInfo.fastCopyFunctions, inputPitch, source, PackPixels(params, formatInfo.format, inputPitch, source, pixelsOut);
pixelsOut);
mDeviceContext->Unmap(readResource, 0); mDeviceContext->Unmap(readResource, 0);
......
...@@ -24,43 +24,6 @@ namespace rx ...@@ -24,43 +24,6 @@ namespace rx
namespace d3d11 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 struct DXGIColorFormatInfo
{ {
size_t redBits; size_t redBits;
...@@ -220,7 +183,6 @@ DXGIFormat::DXGIFormat() ...@@ -220,7 +183,6 @@ DXGIFormat::DXGIFormat()
depthBits(0), depthBits(0),
stencilBits(0), stencilBits(0),
componentType(GL_NONE), componentType(GL_NONE),
fastCopyFunctions(),
nativeMipmapSupport(NULL) nativeMipmapSupport(NULL)
{ {
} }
...@@ -265,7 +227,6 @@ void AddDXGIFormat(DXGIFormatInfoMap *map, ...@@ -265,7 +227,6 @@ void AddDXGIFormat(DXGIFormatInfoMap *map,
} }
info.componentType = componentType; info.componentType = componentType;
info.fastCopyFunctions = GetFastCopyFunctionMap(dxgiFormat);
info.nativeMipmapSupport = nativeMipmapSupport; info.nativeMipmapSupport = nativeMipmapSupport;
map->insert(std::make_pair(dxgiFormat, info)); map->insert(std::make_pair(dxgiFormat, info));
......
...@@ -42,8 +42,6 @@ struct DXGIFormat ...@@ -42,8 +42,6 @@ struct DXGIFormat
GLenum componentType; GLenum componentType;
FastCopyFunctionMap fastCopyFunctions;
NativeMipmapGenerationSupportFunction nativeMipmapSupport; NativeMipmapGenerationSupportFunction nativeMipmapSupport;
}; };
......
...@@ -205,8 +205,7 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Rectangle &area, ...@@ -205,8 +205,7 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Rectangle &area,
packParams.outputPitch = static_cast<GLuint>(outputPitch); packParams.outputPitch = static_cast<GLuint>(outputPitch);
packParams.pack = pack; packParams.pack = pack;
PackPixels(packParams, *d3dFormatInfo.info, d3dFormatInfo.fastCopyFunctions, inputPitch, source, PackPixels(packParams, *d3dFormatInfo.info, inputPitch, source, pixels);
pixels);
systemSurface->UnlockRect(); systemSurface->UnlockRect();
SafeRelease(systemSurface); SafeRelease(systemSurface);
......
...@@ -27,43 +27,6 @@ namespace d3d9 ...@@ -27,43 +27,6 @@ namespace d3d9
const D3DFORMAT D3DFMT_INTZ = ((D3DFORMAT)(MAKEFOURCC('I', 'N', 'T', 'Z'))); const D3DFORMAT D3DFMT_INTZ = ((D3DFORMAT)(MAKEFOURCC('I', 'N', 'T', 'Z')));
const D3DFORMAT D3DFMT_NULL = ((D3DFORMAT)(MAKEFOURCC('N', 'U', 'L', 'L'))); 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 // A map to determine the pixel size and mip generation function of a given D3D format
typedef std::map<D3DFORMAT, D3DFormat> D3D9FormatInfoMap; typedef std::map<D3DFORMAT, D3DFormat> D3D9FormatInfoMap;
...@@ -78,8 +41,7 @@ D3DFormat::D3DFormat() ...@@ -78,8 +41,7 @@ D3DFormat::D3DFormat()
luminanceBits(0), luminanceBits(0),
depthBits(0), depthBits(0),
stencilBits(0), stencilBits(0),
info(nullptr), info(nullptr)
fastCopyFunctions()
{ {
} }
...@@ -108,8 +70,7 @@ static inline void InsertD3DFormatInfo(D3D9FormatInfoMap *map, ...@@ -108,8 +70,7 @@ static inline void InsertD3DFormatInfo(D3D9FormatInfoMap *map,
info.luminanceBits = lumBits; info.luminanceBits = lumBits;
info.depthBits = depthBits; info.depthBits = depthBits;
info.stencilBits = stencilBits; info.stencilBits = stencilBits;
info.info = &Format::Get(formatID); info.info = &Format::Get(formatID);
info.fastCopyFunctions = GetFastCopyFunctionMap(format);
map->insert(std::make_pair(format, info)); map->insert(std::make_pair(format, info));
} }
......
...@@ -45,8 +45,6 @@ struct D3DFormat ...@@ -45,8 +45,6 @@ struct D3DFormat
GLuint stencilBits; GLuint stencilBits;
const angle::Format *info; const angle::Format *info;
FastCopyFunctionMap fastCopyFunctions;
}; };
const D3DFormat &GetD3DFormatInfo(D3DFORMAT format); const D3DFormat &GetD3DFormatInfo(D3DFORMAT format);
......
...@@ -172,7 +172,6 @@ PackPixelsParams::PackPixelsParams(const gl::Rectangle &areaIn, ...@@ -172,7 +172,6 @@ PackPixelsParams::PackPixelsParams(const gl::Rectangle &areaIn,
void PackPixels(const PackPixelsParams &params, void PackPixels(const PackPixelsParams &params,
const angle::Format &sourceFormat, const angle::Format &sourceFormat,
const FastCopyFunctionMap &fastCopyFunctionsMap,
int inputPitchIn, int inputPitchIn,
const uint8_t *sourceIn, const uint8_t *sourceIn,
uint8_t *destWithoutOffset) uint8_t *destWithoutOffset)
...@@ -204,7 +203,8 @@ void PackPixels(const PackPixelsParams &params, ...@@ -204,7 +203,8 @@ void PackPixels(const PackPixelsParams &params,
ASSERT(sourceGLInfo.pixelBytes > 0); ASSERT(sourceGLInfo.pixelBytes > 0);
gl::FormatType formatType(params.format, params.type); 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); GLenum sizedDestInternalFormat = gl::GetSizedInternalFormat(formatType.format, formatType.type);
const auto &destFormatInfo = gl::GetInternalFormatInfo(sizedDestInternalFormat); const auto &destFormatInfo = gl::GetInternalFormatInfo(sizedDestInternalFormat);
......
...@@ -67,7 +67,6 @@ struct PackPixelsParams ...@@ -67,7 +67,6 @@ struct PackPixelsParams
void PackPixels(const PackPixelsParams &params, void PackPixels(const PackPixelsParams &params,
const angle::Format &sourceFormat, const angle::Format &sourceFormat,
const FastCopyFunctionMap &fastCopyFunctionsMap,
int inputPitch, int inputPitch,
const uint8_t *source, const uint8_t *source,
uint8_t *destination); uint8_t *destination);
......
...@@ -171,6 +171,7 @@ ...@@ -171,6 +171,7 @@
'libANGLE/renderer/FenceSyncImpl.h', 'libANGLE/renderer/FenceSyncImpl.h',
'libANGLE/renderer/Format_ID_autogen.inl', 'libANGLE/renderer/Format_ID_autogen.inl',
'libANGLE/renderer/Format_autogen.cpp', 'libANGLE/renderer/Format_autogen.cpp',
'libANGLE/renderer/Format.cpp',
'libANGLE/renderer/Format.h', 'libANGLE/renderer/Format.h',
'libANGLE/renderer/FramebufferAttachmentObjectImpl.h', 'libANGLE/renderer/FramebufferAttachmentObjectImpl.h',
'libANGLE/renderer/FramebufferImpl.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