Commit a5ac1e16 by Jamie Madill Committed by Commit Bot

D3D9: Use angle::Format when possible.

This will unify the way we call into PackPixels and also cleans u the code. It required adding a few D3D9-specific formats to the table. BUG=angleproject:1455 Change-Id: Ic8282f40f52cabdb2925e2bb305c26582284082d Reviewed-on: https://chromium-review.googlesource.com/365825 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent a5b1561e
......@@ -18,6 +18,7 @@ enum class Format::ID
B5G5R5A1_UNORM,
B5G6R5_UNORM,
B8G8R8A8_UNORM,
B8G8R8X8_UNORM,
BC1_UNORM,
BC2_UNORM,
BC3_UNORM,
......@@ -25,6 +26,9 @@ enum class Format::ID
D24_UNORM_S8_UINT,
D32_FLOAT,
D32_FLOAT_S8X24_UINT,
D32_UNORM,
L8A8_LUMA,
L8_LUMA,
R10G10B10A2_UINT,
R10G10B10A2_UNORM,
R11G11B10_FLOAT,
......@@ -52,6 +56,7 @@ enum class Format::ID
R32_FLOAT,
R32_SINT,
R32_UINT,
R5G6B5_UNORM,
R8G8B8A8_SINT,
R8G8B8A8_SNORM,
R8G8B8A8_UINT,
......
......@@ -68,6 +68,15 @@ const Format &Format::Get(ID id)
ReadColor<B8G8R8A8, GLfloat>);
return info;
}
case ID::B8G8R8X8_UNORM:
{
static const Format info(ID::B8G8R8X8_UNORM,
GL_BGRA8_EXT,
GL_BGRA8_EXT,
GenerateMip<B8G8R8X8>,
ReadColor<B8G8R8X8, GLfloat>);
return info;
}
case ID::BC1_UNORM:
{
static const Format info(ID::BC1_UNORM,
......@@ -131,6 +140,33 @@ const Format &Format::Get(ID id)
nullptr);
return info;
}
case ID::D32_UNORM:
{
static const Format info(ID::D32_UNORM,
GL_DEPTH_COMPONENT32_OES,
GL_DEPTH_COMPONENT32_OES,
nullptr,
nullptr);
return info;
}
case ID::L8A8_LUMA:
{
static const Format info(ID::L8A8_LUMA,
GL_LUMINANCE8_ALPHA8_EXT,
GL_LUMINANCE8_ALPHA8_EXT,
GenerateMip<L8A8>,
ReadColor<L8A8, GLfloat>);
return info;
}
case ID::L8_LUMA:
{
static const Format info(ID::L8_LUMA,
GL_LUMINANCE8_EXT,
GL_LUMINANCE8_EXT,
GenerateMip<L8>,
ReadColor<L8, GLfloat>);
return info;
}
case ID::NONE:
{
static const Format info(ID::NONE,
......@@ -383,6 +419,15 @@ const Format &Format::Get(ID id)
ReadColor<R32, GLuint>);
return info;
}
case ID::R5G6B5_UNORM:
{
static const Format info(ID::R5G6B5_UNORM,
GL_RGB565,
GL_RGB565,
GenerateMip<R5G6B5>,
ReadColor<R5G6B5, GLfloat>);
return info;
}
case ID::R8G8B8A8_SINT:
{
static const Format info(ID::R8G8B8A8_SINT,
......
......@@ -77,6 +77,25 @@
"bits": { "depth": 32 },
"glInternalFormat": "GL_DEPTH_COMPONENT32F"
},
"D32_UNORM": {
"channels": "d",
"componentType": "unorm",
"bits": { "depth": 32 },
"glInternalFormat": "GL_DEPTH_COMPONENT32_OES"
},
"L8_LUMA": {
"channels": "l",
"componentType": "unorm",
"bits": { "luma": 8 },
"glInternalFormat": "GL_LUMINANCE8_EXT"
},
"L8A8_LUMA": {
"channels": "la",
"componentType": "unorm",
"bits": { "luma": 8, "alpha": 8 },
"glInternalFormat": "GL_LUMINANCE8_ALPHA8_EXT",
"channelStruct": "L8A8"
},
"R11G11B10_FLOAT": {
"channels": "rgb",
"componentType": "float",
......@@ -255,6 +274,12 @@
"fboImplementationInternalFormat": "GL_RGB5_A1",
"channelStruct": "A1R5G5B5"
},
"R5G6B5_UNORM": {
"channels": "rgb",
"componentType": "unorm",
"bits": { "red": 5, "green": 6, "blue": 5 },
"glInternalFormat": "GL_RGB565"
},
"R8G8B8A8_SINT": {
"channels": "rgba",
"componentType": "int",
......@@ -273,6 +298,13 @@
"bits": { "red": 8, "green": 8, "blue": 8, "alpha": 8 },
"glInternalFormat": "GL_RGBA8_SNORM"
},
"B8G8R8X8_UNORM": {
"channels": "bgr",
"componentType": "unorm",
"bits": { "red": 8, "green": 8, "blue": 8 },
"glInternalFormat": "GL_BGRA8_EXT",
"channelStruct": "B8G8R8X8"
},
"R9G9B9E5_SHAREDEXP": {
"channels": "rgb",
"componentType": "float",
......
......@@ -192,9 +192,10 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Rectangle &area,
int inputPitch = lock.Pitch;
const d3d9::D3DFormat &d3dFormatInfo = d3d9::GetD3DFormatInfo(desc.Format);
const gl::InternalFormat &sourceFormatInfo = gl::GetInternalFormatInfo(d3dFormatInfo.internalFormat);
const gl::InternalFormat &sourceFormatInfo =
gl::GetInternalFormatInfo(d3dFormatInfo.info->glInternalFormat);
gl::FormatType formatType(format, type);
ColorReadFunction colorReadFunction = d3dFormatInfo.colorReadFunction;
ColorReadFunction colorReadFunction = d3dFormatInfo.info->colorReadFunction;
// TODO(jmadill): Maybe we can avoid a copy of pack parameters here?
PackPixelsParams packParams;
......@@ -407,7 +408,7 @@ GLenum Framebuffer9::getRenderTargetImplementationFormat(RenderTargetD3D *render
{
RenderTarget9 *renderTarget9 = GetAs<RenderTarget9>(renderTarget);
const d3d9::D3DFormat &d3dFormatInfo = d3d9::GetD3DFormatInfo(renderTarget9->getD3DFormat());
return d3dFormatInfo.internalFormat;
return d3dFormatInfo.info->glInternalFormat;
}
} // namespace rx
......@@ -61,7 +61,7 @@ gl::Error Image9::generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9
ASSERT(sourceDesc.Height == 1 || sourceDesc.Height / 2 == destDesc.Height);
const d3d9::D3DFormat &d3dFormatInfo = d3d9::GetD3DFormatInfo(sourceDesc.Format);
ASSERT(d3dFormatInfo.mipGenerationFunction != NULL);
ASSERT(d3dFormatInfo.info->mipGenerationFunction != NULL);
D3DLOCKED_RECT sourceLocked = {0};
result = sourceSurface->LockRect(&sourceLocked, NULL, D3DLOCK_READONLY);
......@@ -85,8 +85,8 @@ gl::Error Image9::generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9
ASSERT(sourceData && destData);
d3dFormatInfo.mipGenerationFunction(sourceDesc.Width, sourceDesc.Height, 1, sourceData, sourceLocked.Pitch, 0,
destData, destLocked.Pitch, 0);
d3dFormatInfo.info->mipGenerationFunction(sourceDesc.Width, sourceDesc.Height, 1, sourceData,
sourceLocked.Pitch, 0, destData, destLocked.Pitch, 0);
destSurface->UnlockRect();
sourceSurface->UnlockRect();
......
......@@ -16,6 +16,8 @@
#include "libANGLE/renderer/d3d/d3d9/Renderer9.h"
#include "libANGLE/renderer/d3d/d3d9/vertexconversion.h"
using namespace angle;
namespace rx
{
......@@ -76,18 +78,24 @@ D3DFormat::D3DFormat()
luminanceBits(0),
depthBits(0),
stencilBits(0),
internalFormat(GL_NONE),
mipGenerationFunction(NULL),
colorReadFunction(NULL),
info(nullptr),
fastCopyFunctions()
{
}
static inline void InsertD3DFormatInfo(D3D9FormatInfoMap *map, D3DFORMAT format, GLuint bits, GLuint blockWidth,
GLuint blockHeight, GLuint redBits, GLuint greenBits, GLuint blueBits,
GLuint alphaBits, GLuint lumBits, GLuint depthBits, GLuint stencilBits,
GLenum internalFormat, MipGenerationFunction mipFunc,
ColorReadFunction colorReadFunc)
static inline void InsertD3DFormatInfo(D3D9FormatInfoMap *map,
D3DFORMAT format,
GLuint bits,
GLuint blockWidth,
GLuint blockHeight,
GLuint redBits,
GLuint greenBits,
GLuint blueBits,
GLuint alphaBits,
GLuint lumBits,
GLuint depthBits,
GLuint stencilBits,
Format::ID formatID)
{
D3DFormat info;
info.pixelBytes = bits / 8;
......@@ -100,9 +108,7 @@ static inline void InsertD3DFormatInfo(D3D9FormatInfoMap *map, D3DFORMAT format,
info.luminanceBits = lumBits;
info.depthBits = depthBits;
info.stencilBits = stencilBits;
info.internalFormat = internalFormat;
info.mipGenerationFunction = mipFunc;
info.colorReadFunction = colorReadFunc;
info.info = &Format::Get(formatID);
info.fastCopyFunctions = GetFastCopyFunctionMap(format);
map->insert(std::make_pair(format, info));
......@@ -114,35 +120,37 @@ static D3D9FormatInfoMap BuildD3D9FormatInfoMap()
D3D9FormatInfoMap map;
// | D3DFORMAT | S |W |H | R | G | B | A | L | D | S | Internal format | Mip generation function | Color read function |
InsertD3DFormatInfo(&map, D3DFMT_NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, GL_NONE, NULL, NULL );
InsertD3DFormatInfo(&map, D3DFMT_UNKNOWN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, GL_NONE, NULL, NULL );
InsertD3DFormatInfo(&map, D3DFMT_L8, 8, 1, 1, 0, 0, 0, 0, 8, 0, 0, GL_LUMINANCE8_EXT, GenerateMip<L8>, ReadColor<L8, GLfloat> );
InsertD3DFormatInfo(&map, D3DFMT_A8, 8, 1, 1, 0, 0, 0, 8, 0, 0, 0, GL_ALPHA8_EXT, GenerateMip<A8>, ReadColor<A8, GLfloat> );
InsertD3DFormatInfo(&map, D3DFMT_A8L8, 16, 1, 1, 0, 0, 0, 8, 8, 0, 0, GL_LUMINANCE8_ALPHA8_EXT, GenerateMip<A8L8>, ReadColor<A8L8, GLfloat> );
InsertD3DFormatInfo(&map, D3DFMT_A4R4G4B4, 16, 1, 1, 4, 4, 4, 4, 0, 0, 0, GL_BGRA4_ANGLEX, GenerateMip<A4R4G4B4>, ReadColor<A4R4G4B4, GLfloat> );
InsertD3DFormatInfo(&map, D3DFMT_A1R5G5B5, 16, 1, 1, 5, 5, 5, 1, 0, 0, 0, GL_BGR5_A1_ANGLEX, GenerateMip<A1R5G5B5>, ReadColor<A1R5G5B5, GLfloat> );
InsertD3DFormatInfo(&map, D3DFMT_R5G6B5, 16, 1, 1, 5, 6, 5, 0, 0, 0, 0, GL_RGB565, GenerateMip<R5G6B5>, ReadColor<R5G6B5, GLfloat> );
InsertD3DFormatInfo(&map, D3DFMT_X8R8G8B8, 32, 1, 1, 8, 8, 8, 0, 0, 0, 0, GL_BGRA8_EXT, GenerateMip<B8G8R8X8>, ReadColor<B8G8R8X8, GLfloat> );
InsertD3DFormatInfo(&map, D3DFMT_A8R8G8B8, 32, 1, 1, 8, 8, 8, 8, 0, 0, 0, GL_BGRA8_EXT, GenerateMip<B8G8R8A8>, ReadColor<B8G8R8A8, GLfloat> );
InsertD3DFormatInfo(&map, D3DFMT_R16F, 16, 1, 1, 16, 0, 0, 0, 0, 0, 0, GL_R16F_EXT, GenerateMip<R16F>, ReadColor<R16F, GLfloat> );
InsertD3DFormatInfo(&map, D3DFMT_G16R16F, 32, 1, 1, 16, 16, 0, 0, 0, 0, 0, GL_RG16F_EXT, GenerateMip<R16G16F>, ReadColor<R16G16F, GLfloat> );
InsertD3DFormatInfo(&map, D3DFMT_A16B16G16R16F, 64, 1, 1, 16, 16, 16, 16, 0, 0, 0, GL_RGBA16F_EXT, GenerateMip<R16G16B16A16F>, ReadColor<R16G16B16A16F, GLfloat>);
InsertD3DFormatInfo(&map, D3DFMT_R32F, 32, 1, 1, 32, 0, 0, 0, 0, 0, 0, GL_R32F_EXT, GenerateMip<R32F>, ReadColor<R32F, GLfloat> );
InsertD3DFormatInfo(&map, D3DFMT_G32R32F, 64, 1, 1, 32, 32, 0, 0, 0, 0, 0, GL_RG32F_EXT, GenerateMip<R32G32F>, ReadColor<R32G32F, GLfloat> );
InsertD3DFormatInfo(&map, D3DFMT_A32B32G32R32F, 128, 1, 1, 32, 32, 32, 32, 0, 0, 0, GL_RGBA32F_EXT, GenerateMip<R32G32B32A32F>, ReadColor<R32G32B32A32F, GLfloat>);
InsertD3DFormatInfo(&map, D3DFMT_D16, 16, 1, 1, 0, 0, 0, 0, 0, 16, 0, GL_DEPTH_COMPONENT16, NULL, NULL );
InsertD3DFormatInfo(&map, D3DFMT_D24S8, 32, 1, 1, 0, 0, 0, 0, 0, 24, 8, GL_DEPTH24_STENCIL8_OES, NULL, NULL );
InsertD3DFormatInfo(&map, D3DFMT_D24X8, 32, 1, 1, 0, 0, 0, 0, 0, 24, 0, GL_DEPTH_COMPONENT16, NULL, NULL );
InsertD3DFormatInfo(&map, D3DFMT_D32, 32, 1, 1, 0, 0, 0, 0, 0, 32, 0, GL_DEPTH_COMPONENT32_OES, NULL, NULL );
InsertD3DFormatInfo(&map, D3DFMT_INTZ, 32, 1, 1, 0, 0, 0, 0, 0, 24, 8, GL_DEPTH24_STENCIL8_OES, NULL, NULL );
InsertD3DFormatInfo(&map, D3DFMT_DXT1, 64, 4, 4, 0, 0, 0, 0, 0, 0, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, NULL, NULL );
InsertD3DFormatInfo(&map, D3DFMT_DXT3, 128, 4, 4, 0, 0, 0, 0, 0, 0, 0, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, NULL, NULL );
InsertD3DFormatInfo(&map, D3DFMT_DXT5, 128, 4, 4, 0, 0, 0, 0, 0, 0, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, NULL, NULL );
// 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_LUMA );
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_LUMA );
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_UNORM );
InsertD3DFormatInfo(&map, D3DFMT_DXT3, 128, 4, 4, 0, 0, 0, 0, 0, 0, 0, Format::ID::BC2_UNORM );
InsertD3DFormatInfo(&map, D3DFMT_DXT5, 128, 4, 4, 0, 0, 0, 0, 0, 0, 0, Format::ID::BC3_UNORM );
// clang-format on
return map;
}
......
......@@ -15,6 +15,7 @@
#include "common/platform.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/Format.h"
#include "libANGLE/renderer/renderer_utils.h"
#include "libANGLE/renderer/d3d/formatutilsD3D.h"
......@@ -43,10 +44,7 @@ struct D3DFormat
GLuint depthBits;
GLuint stencilBits;
GLenum internalFormat;
MipGenerationFunction mipGenerationFunction;
ColorReadFunction colorReadFunction;
const angle::Format *info;
FastCopyFunctionMap fastCopyFunctions;
};
......
......@@ -306,7 +306,7 @@ GLsizei GetSamplesCount(D3DMULTISAMPLE_TYPE type)
bool IsFormatChannelEquivalent(D3DFORMAT d3dformat, GLenum format)
{
GLenum internalFormat = d3d9::GetD3DFormatInfo(d3dformat).internalFormat;
GLenum internalFormat = d3d9::GetD3DFormatInfo(d3dformat).info->glInternalFormat;
GLenum convertedFormat = gl::GetInternalFormatInfo(internalFormat).format;
return convertedFormat == format;
}
......
......@@ -93,6 +93,8 @@ def get_channel_struct(angle_format):
struct_name += 'B{}'.format(bits['blue'])
if channel == 'a':
struct_name += 'A{}'.format(bits['alpha'])
if channel == 'l':
struct_name += 'L{}'.format(bits['luma'])
if angle_format['componentType'] == 'float':
struct_name += 'F'
if angle_format['componentType'] == 'int' or angle_format['componentType'] == 'snorm':
......
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