Commit 032e3702 by Jamie Madill Committed by Commit Bot

D3D9: Make GetD3DFormatInfo constexpr.

This removes another static global map initializer. BUG=angleproject:1389 BUG=angleproject:1459 Change-Id: I302f349ea4e95d079077866a07b0d57758c40892 Reviewed-on: https://chromium-review.googlesource.com/405488 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 9cec39f6
...@@ -205,7 +205,7 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Rectangle &area, ...@@ -205,7 +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, inputPitch, source, pixels); PackPixels(packParams, d3dFormatInfo.info(), inputPitch, source, pixels);
systemSurface->UnlockRect(); systemSurface->UnlockRect();
SafeRelease(systemSurface); SafeRelease(systemSurface);
...@@ -404,7 +404,7 @@ GLenum Framebuffer9::getRenderTargetImplementationFormat(RenderTargetD3D *render ...@@ -404,7 +404,7 @@ GLenum Framebuffer9::getRenderTargetImplementationFormat(RenderTargetD3D *render
{ {
RenderTarget9 *renderTarget9 = GetAs<RenderTarget9>(renderTarget); RenderTarget9 *renderTarget9 = GetAs<RenderTarget9>(renderTarget);
const d3d9::D3DFormat &d3dFormatInfo = d3d9::GetD3DFormatInfo(renderTarget9->getD3DFormat()); const d3d9::D3DFormat &d3dFormatInfo = d3d9::GetD3DFormatInfo(renderTarget9->getD3DFormat());
return d3dFormatInfo.info->glInternalFormat; return d3dFormatInfo.info().glInternalFormat;
} }
} // namespace rx } // namespace rx
...@@ -61,7 +61,7 @@ gl::Error Image9::generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 ...@@ -61,7 +61,7 @@ gl::Error Image9::generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9
ASSERT(sourceDesc.Height == 1 || sourceDesc.Height / 2 == destDesc.Height); ASSERT(sourceDesc.Height == 1 || sourceDesc.Height / 2 == destDesc.Height);
const d3d9::D3DFormat &d3dFormatInfo = d3d9::GetD3DFormatInfo(sourceDesc.Format); const d3d9::D3DFormat &d3dFormatInfo = d3d9::GetD3DFormatInfo(sourceDesc.Format);
ASSERT(d3dFormatInfo.info->mipGenerationFunction != NULL); ASSERT(d3dFormatInfo.info().mipGenerationFunction != NULL);
D3DLOCKED_RECT sourceLocked = {0}; D3DLOCKED_RECT sourceLocked = {0};
result = sourceSurface->LockRect(&sourceLocked, NULL, D3DLOCK_READONLY); result = sourceSurface->LockRect(&sourceLocked, NULL, D3DLOCK_READONLY);
...@@ -85,8 +85,9 @@ gl::Error Image9::generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 ...@@ -85,8 +85,9 @@ gl::Error Image9::generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9
ASSERT(sourceData && destData); ASSERT(sourceData && destData);
d3dFormatInfo.info->mipGenerationFunction(sourceDesc.Width, sourceDesc.Height, 1, sourceData, d3dFormatInfo.info().mipGenerationFunction(sourceDesc.Width, sourceDesc.Height, 1, sourceData,
sourceLocked.Pitch, 0, destData, destLocked.Pitch, 0); sourceLocked.Pitch, 0, destData, destLocked.Pitch,
0);
destSurface->UnlockRect(); destSurface->UnlockRect();
sourceSurface->UnlockRect(); sourceSurface->UnlockRect();
......
...@@ -732,8 +732,8 @@ egl::Error Renderer9::getD3DTextureInfo(IUnknown *d3dTexture, ...@@ -732,8 +732,8 @@ egl::Error Renderer9::getD3DTextureInfo(IUnknown *d3dTexture,
if (fboFormat) if (fboFormat)
{ {
const auto &d3dFormatInfo = d3d9::GetD3DFormatInfo(desc.Format); const auto &d3dFormatInfo = d3d9::GetD3DFormatInfo(desc.Format);
ASSERT(d3dFormatInfo.info != nullptr); ASSERT(d3dFormatInfo.info().id != angle::Format::ID::NONE);
*fboFormat = d3dFormatInfo.info->fboImplementationInternalFormat; *fboFormat = d3dFormatInfo.info().fboImplementationInternalFormat;
} }
return egl::Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
......
...@@ -24,13 +24,13 @@ namespace rx ...@@ -24,13 +24,13 @@ namespace rx
namespace d3d9 namespace d3d9
{ {
const D3DFORMAT D3DFMT_INTZ = ((D3DFORMAT)(MAKEFOURCC('I', 'N', 'T', 'Z'))); constexpr D3DFORMAT D3DFMT_INTZ = ((D3DFORMAT)(MAKEFOURCC('I', 'N', 'T', 'Z')));
const D3DFORMAT D3DFMT_NULL = ((D3DFORMAT)(MAKEFOURCC('N', 'U', 'L', 'L'))); constexpr D3DFORMAT D3DFMT_NULL = ((D3DFORMAT)(MAKEFOURCC('N', 'U', 'L', 'L')));
// 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;
D3DFormat::D3DFormat() constexpr D3DFormat::D3DFormat()
: pixelBytes(0), : pixelBytes(0),
blockWidth(0), blockWidth(0),
blockHeight(0), blockHeight(0),
...@@ -41,97 +41,188 @@ D3DFormat::D3DFormat() ...@@ -41,97 +41,188 @@ D3DFormat::D3DFormat()
luminanceBits(0), luminanceBits(0),
depthBits(0), depthBits(0),
stencilBits(0), stencilBits(0),
info(nullptr) formatID(angle::Format::ID::NONE)
{ {
} }
static inline void InsertD3DFormatInfo(D3D9FormatInfoMap *map, constexpr D3DFormat::D3DFormat(GLuint bits,
D3DFORMAT format, GLuint blockWidth,
GLuint bits, GLuint blockHeight,
GLuint blockWidth, GLuint redBits,
GLuint blockHeight, GLuint greenBits,
GLuint redBits, GLuint blueBits,
GLuint greenBits, GLuint alphaBits,
GLuint blueBits, GLuint lumBits,
GLuint alphaBits, GLuint depthBits,
GLuint lumBits, GLuint stencilBits,
GLuint depthBits, Format::ID formatID)
GLuint stencilBits, : pixelBytes(bits / 8),
Format::ID formatID) blockWidth(blockWidth),
blockHeight(blockHeight),
redBits(redBits),
greenBits(greenBits),
blueBits(blueBits),
alphaBits(alphaBits),
luminanceBits(lumBits),
depthBits(depthBits),
stencilBits(stencilBits),
formatID(formatID)
{ {
D3DFormat info;
info.pixelBytes = bits / 8;
info.blockWidth = blockWidth;
info.blockHeight = blockHeight;
info.redBits = redBits;
info.greenBits = greenBits;
info.blueBits = blueBits;
info.alphaBits = alphaBits;
info.luminanceBits = lumBits;
info.depthBits = depthBits;
info.stencilBits = stencilBits;
info.info = &Format::Get(formatID);
map->insert(std::make_pair(format, info));
}
static D3D9FormatInfoMap BuildD3D9FormatInfoMap()
{
using namespace angle; // For image reading and mipmap generation functions
D3D9FormatInfoMap map;
// clang-format off
// | D3DFORMAT | S |W |H | R | G | B | A | L | D | S | ANGLE format |
InsertD3DFormatInfo(&map, D3DFMT_NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Format::ID::NONE );
InsertD3DFormatInfo(&map, D3DFMT_UNKNOWN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Format::ID::NONE );
InsertD3DFormatInfo(&map, D3DFMT_L8, 8, 1, 1, 0, 0, 0, 0, 8, 0, 0, Format::ID::L8_UNORM );
InsertD3DFormatInfo(&map, D3DFMT_A8, 8, 1, 1, 0, 0, 0, 8, 0, 0, 0, Format::ID::A8_UNORM );
InsertD3DFormatInfo(&map, D3DFMT_A8L8, 16, 1, 1, 0, 0, 0, 8, 8, 0, 0, Format::ID::L8A8_UNORM );
InsertD3DFormatInfo(&map, D3DFMT_A4R4G4B4, 16, 1, 1, 4, 4, 4, 4, 0, 0, 0, Format::ID::B4G4R4A4_UNORM );
InsertD3DFormatInfo(&map, D3DFMT_A1R5G5B5, 16, 1, 1, 5, 5, 5, 1, 0, 0, 0, Format::ID::B5G5R5A1_UNORM );
InsertD3DFormatInfo(&map, D3DFMT_R5G6B5, 16, 1, 1, 5, 6, 5, 0, 0, 0, 0, Format::ID::R5G6B5_UNORM );
InsertD3DFormatInfo(&map, D3DFMT_X8R8G8B8, 32, 1, 1, 8, 8, 8, 0, 0, 0, 0, Format::ID::B8G8R8X8_UNORM );
InsertD3DFormatInfo(&map, D3DFMT_A8R8G8B8, 32, 1, 1, 8, 8, 8, 8, 0, 0, 0, Format::ID::B8G8R8A8_UNORM );
InsertD3DFormatInfo(&map, D3DFMT_R16F, 16, 1, 1, 16, 0, 0, 0, 0, 0, 0, Format::ID::R16_FLOAT );
InsertD3DFormatInfo(&map, D3DFMT_G16R16F, 32, 1, 1, 16, 16, 0, 0, 0, 0, 0, Format::ID::R16G16_FLOAT );
InsertD3DFormatInfo(&map, D3DFMT_A16B16G16R16F, 64, 1, 1, 16, 16, 16, 16, 0, 0, 0, Format::ID::R16G16B16A16_FLOAT );
InsertD3DFormatInfo(&map, D3DFMT_R32F, 32, 1, 1, 32, 0, 0, 0, 0, 0, 0, Format::ID::R32_FLOAT );
InsertD3DFormatInfo(&map, D3DFMT_G32R32F, 64, 1, 1, 32, 32, 0, 0, 0, 0, 0, Format::ID::R32G32_FLOAT );
InsertD3DFormatInfo(&map, D3DFMT_A32B32G32R32F, 128, 1, 1, 32, 32, 32, 32, 0, 0, 0, Format::ID::R32G32B32A32_FLOAT );
InsertD3DFormatInfo(&map, D3DFMT_D16, 16, 1, 1, 0, 0, 0, 0, 0, 16, 0, Format::ID::D16_UNORM );
InsertD3DFormatInfo(&map, D3DFMT_D24S8, 32, 1, 1, 0, 0, 0, 0, 0, 24, 8, Format::ID::D24_UNORM_S8_UINT );
InsertD3DFormatInfo(&map, D3DFMT_D24X8, 32, 1, 1, 0, 0, 0, 0, 0, 24, 0, Format::ID::D16_UNORM );
InsertD3DFormatInfo(&map, D3DFMT_D32, 32, 1, 1, 0, 0, 0, 0, 0, 32, 0, Format::ID::D32_UNORM );
InsertD3DFormatInfo(&map, D3DFMT_INTZ, 32, 1, 1, 0, 0, 0, 0, 0, 24, 8, Format::ID::D24_UNORM_S8_UINT );
InsertD3DFormatInfo(&map, D3DFMT_DXT1, 64, 4, 4, 0, 0, 0, 0, 0, 0, 0, Format::ID::BC1_RGBA_UNORM_BLOCK);
InsertD3DFormatInfo(&map, D3DFMT_DXT3, 128, 4, 4, 0, 0, 0, 0, 0, 0, 0, Format::ID::BC2_RGBA_UNORM_BLOCK);
InsertD3DFormatInfo(&map, D3DFMT_DXT5, 128, 4, 4, 0, 0, 0, 0, 0, 0, 0, Format::ID::BC3_RGBA_UNORM_BLOCK);
// clang-format on
return map;
} }
const D3DFormat &GetD3DFormatInfo(D3DFORMAT format) const D3DFormat &GetD3DFormatInfo(D3DFORMAT format)
{ {
static const D3D9FormatInfoMap infoMap = BuildD3D9FormatInfoMap(); if (format == D3DFMT_NULL)
D3D9FormatInfoMap::const_iterator iter = infoMap.find(format);
if (iter != infoMap.end())
{ {
return iter->second; static constexpr D3DFormat info(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Format::ID::NONE);
return info;
} }
else
if (format == D3DFMT_INTZ)
{ {
static const D3DFormat defaultInfo; static constexpr D3DFormat info(32, 1, 1, 0, 0, 0, 0, 0, 24, 8,
return defaultInfo; Format::ID::D24_UNORM_S8_UINT);
return info;
} }
}
switch (format)
{
case D3DFMT_UNKNOWN:
{
static constexpr D3DFormat info(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Format::ID::NONE);
return info;
}
case D3DFMT_L8:
{
static constexpr D3DFormat info(8, 1, 1, 0, 0, 0, 0, 8, 0, 0, Format::ID::L8_UNORM);
return info;
}
case D3DFMT_A8:
{
static constexpr D3DFormat info(8, 1, 1, 0, 0, 0, 8, 0, 0, 0, Format::ID::A8_UNORM);
return info;
}
case D3DFMT_A8L8:
{
static constexpr D3DFormat info(16, 1, 1, 0, 0, 0, 8, 8, 0, 0, Format::ID::L8A8_UNORM);
return info;
}
case D3DFMT_A4R4G4B4:
{
static constexpr D3DFormat info(16, 1, 1, 4, 4, 4, 4, 0, 0, 0,
Format::ID::B4G4R4A4_UNORM);
return info;
}
case D3DFMT_A1R5G5B5:
{
static constexpr D3DFormat info(16, 1, 1, 5, 5, 5, 1, 0, 0, 0,
Format::ID::B5G5R5A1_UNORM);
return info;
}
case D3DFMT_R5G6B5:
{
static constexpr D3DFormat info(16, 1, 1, 5, 6, 5, 0, 0, 0, 0,
Format::ID::R5G6B5_UNORM);
return info;
}
case D3DFMT_X8R8G8B8:
{
static constexpr D3DFormat info(32, 1, 1, 8, 8, 8, 0, 0, 0, 0,
Format::ID::B8G8R8X8_UNORM);
return info;
}
case D3DFMT_A8R8G8B8:
{
static constexpr D3DFormat info(32, 1, 1, 8, 8, 8, 8, 0, 0, 0,
Format::ID::B8G8R8A8_UNORM);
return info;
}
case D3DFMT_R16F:
{
static constexpr D3DFormat info(16, 1, 1, 16, 0, 0, 0, 0, 0, 0, Format::ID::R16_FLOAT);
return info;
}
case D3DFMT_G16R16F:
{
static constexpr D3DFormat info(32, 1, 1, 16, 16, 0, 0, 0, 0, 0,
Format::ID::R16G16_FLOAT);
return info;
}
case D3DFMT_A16B16G16R16F:
{
static constexpr D3DFormat info(64, 1, 1, 16, 16, 16, 16, 0, 0, 0,
Format::ID::R16G16B16A16_FLOAT);
return info;
}
case D3DFMT_R32F:
{
static constexpr D3DFormat info(32, 1, 1, 32, 0, 0, 0, 0, 0, 0, Format::ID::R32_FLOAT);
return info;
}
case D3DFMT_G32R32F:
{
static constexpr D3DFormat info(64, 1, 1, 32, 32, 0, 0, 0, 0, 0,
Format::ID::R32G32_FLOAT);
return info;
}
case D3DFMT_A32B32G32R32F:
{
static constexpr D3DFormat info(128, 1, 1, 32, 32, 32, 32, 0, 0, 0,
Format::ID::R32G32B32A32_FLOAT);
return info;
}
case D3DFMT_D16:
{
static constexpr D3DFormat info(16, 1, 1, 0, 0, 0, 0, 0, 16, 0, Format::ID::D16_UNORM);
return info;
}
case D3DFMT_D24S8:
{
static constexpr D3DFormat info(32, 1, 1, 0, 0, 0, 0, 0, 24, 8,
Format::ID::D24_UNORM_S8_UINT);
return info;
}
case D3DFMT_D24X8:
{
static constexpr D3DFormat info(32, 1, 1, 0, 0, 0, 0, 0, 24, 0, Format::ID::D16_UNORM);
return info;
}
case D3DFMT_D32:
{
static constexpr D3DFormat info(32, 1, 1, 0, 0, 0, 0, 0, 32, 0, Format::ID::D32_UNORM);
return info;
}
case D3DFMT_DXT1:
{
static constexpr D3DFormat info(64, 4, 4, 0, 0, 0, 0, 0, 0, 0,
Format::ID::BC1_RGBA_UNORM_BLOCK);
return info;
}
case D3DFMT_DXT3:
{
static constexpr D3DFormat info(128, 4, 4, 0, 0, 0, 0, 0, 0, 0,
Format::ID::BC2_RGBA_UNORM_BLOCK);
return info;
}
case D3DFMT_DXT5:
{
static constexpr D3DFormat info(128, 4, 4, 0, 0, 0, 0, 0, 0, 0,
Format::ID::BC3_RGBA_UNORM_BLOCK);
return info;
}
default:
{
static constexpr D3DFormat defaultInfo;
return defaultInfo;
}
}
}
typedef std::pair<GLint, InitializeTextureDataFunction> InternalFormatInitialzerPair; typedef std::pair<GLint, InitializeTextureDataFunction> InternalFormatInitialzerPair;
typedef std::map<GLint, InitializeTextureDataFunction> InternalFormatInitialzerMap; typedef std::map<GLint, InitializeTextureDataFunction> InternalFormatInitialzerMap;
......
...@@ -29,7 +29,20 @@ namespace d3d9 ...@@ -29,7 +29,20 @@ namespace d3d9
struct D3DFormat struct D3DFormat
{ {
D3DFormat(); constexpr D3DFormat();
constexpr D3DFormat(GLuint pixelBytes,
GLuint blockWidth,
GLuint blockHeight,
GLuint redBits,
GLuint greenBits,
GLuint blueBits,
GLuint alphaBits,
GLuint luminanceBits,
GLuint depthBits,
GLuint stencilBits,
angle::Format::ID formatID);
const angle::Format &info() const { return angle::Format::Get(formatID); }
GLuint pixelBytes; GLuint pixelBytes;
GLuint blockWidth; GLuint blockWidth;
...@@ -44,7 +57,7 @@ struct D3DFormat ...@@ -44,7 +57,7 @@ struct D3DFormat
GLuint depthBits; GLuint depthBits;
GLuint stencilBits; GLuint stencilBits;
const angle::Format *info; angle::Format::ID formatID;
}; };
const D3DFormat &GetD3DFormatInfo(D3DFORMAT format); const D3DFormat &GetD3DFormatInfo(D3DFORMAT format);
......
...@@ -307,7 +307,7 @@ GLsizei GetSamplesCount(D3DMULTISAMPLE_TYPE type) ...@@ -307,7 +307,7 @@ GLsizei GetSamplesCount(D3DMULTISAMPLE_TYPE type)
bool IsFormatChannelEquivalent(D3DFORMAT d3dformat, GLenum format) bool IsFormatChannelEquivalent(D3DFORMAT d3dformat, GLenum format)
{ {
GLenum internalFormat = d3d9::GetD3DFormatInfo(d3dformat).info->glInternalFormat; GLenum internalFormat = d3d9::GetD3DFormatInfo(d3dformat).info().glInternalFormat;
GLenum convertedFormat = gl::GetInternalFormatInfo(internalFormat).format; GLenum convertedFormat = gl::GetInternalFormatInfo(internalFormat).format;
return convertedFormat == format; return convertedFormat == format;
} }
......
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