Commit f7ccaf73 by Jamie Madill Committed by Commit Bot

D3D11: Move texture format code out of the python script.

It's better to maintain the code outside of a generator script. It gives easier formatting and updating. BUG=angleproject:1455 Change-Id: I2b4383f1ed01545004de10024d03879201e2bf41 Reviewed-on: https://chromium-review.googlesource.com/365410Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent f5207dea
...@@ -56,8 +56,8 @@ template_texture_format_table_autogen_cpp = """// GENERATED FILE - DO NOT EDIT. ...@@ -56,8 +56,8 @@ template_texture_format_table_autogen_cpp = """// GENERATED FILE - DO NOT EDIT.
#include "image_util/loadimage.h" #include "image_util/loadimage.h"
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" #include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
#include "libANGLE/renderer/d3d/d3d11/load_functions_table.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" #include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "libANGLE/renderer/d3d/d3d11/texture_format_table_utils.h"
using namespace angle; using namespace angle;
...@@ -67,140 +67,6 @@ namespace rx ...@@ -67,140 +67,6 @@ namespace rx
namespace d3d11 namespace d3d11
{{ {{
namespace
{{
typedef bool (*FormatSupportFunction)(const Renderer11DeviceCaps &);
bool OnlyFL10Plus(const Renderer11DeviceCaps &deviceCaps)
{{
return (deviceCaps.featureLevel >= D3D_FEATURE_LEVEL_10_0);
}}
bool OnlyFL9_3(const Renderer11DeviceCaps &deviceCaps)
{{
return (deviceCaps.featureLevel == D3D_FEATURE_LEVEL_9_3);
}}
template <DXGI_FORMAT format, bool requireSupport>
bool SupportsFormat(const Renderer11DeviceCaps &deviceCaps)
{{
// Must support texture, SRV and RTV support
UINT mustSupport = D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURECUBE |
D3D11_FORMAT_SUPPORT_SHADER_SAMPLE | D3D11_FORMAT_SUPPORT_MIP |
D3D11_FORMAT_SUPPORT_RENDER_TARGET;
if (d3d11_gl::GetMaximumClientVersion(deviceCaps.featureLevel) > 2)
{{
mustSupport |= D3D11_FORMAT_SUPPORT_TEXTURE3D;
}}
bool fullSupport = false;
if (format == DXGI_FORMAT_B5G6R5_UNORM)
{{
// All hardware that supports DXGI_FORMAT_B5G6R5_UNORM should support autogen mipmaps, but
// check anyway.
mustSupport |= D3D11_FORMAT_SUPPORT_MIP_AUTOGEN;
fullSupport = ((deviceCaps.B5G6R5support & mustSupport) == mustSupport);
}}
else if (format == DXGI_FORMAT_B4G4R4A4_UNORM)
{{
fullSupport = ((deviceCaps.B4G4R4A4support & mustSupport) == mustSupport);
}}
else if (format == DXGI_FORMAT_B5G5R5A1_UNORM)
{{
fullSupport = ((deviceCaps.B5G5R5A1support & mustSupport) == mustSupport);
}}
else
{{
UNREACHABLE();
return false;
}}
// This 'SupportsFormat' function is used by individual entries in the D3D11 Format Map below,
// which maps GL formats to DXGI formats.
if (requireSupport)
{{
// This means that ANGLE would like to use the entry in the map if the inputted DXGI format
// *IS* supported.
// e.g. the entry might map GL_RGB5_A1 to DXGI_FORMAT_B5G5R5A1, which should only be used if
// DXGI_FORMAT_B5G5R5A1 is supported.
// In this case, we should only return 'true' if the format *IS* supported.
return fullSupport;
}}
else
{{
// This means that ANGLE would like to use the entry in the map if the inputted DXGI format
// *ISN'T* supported.
// This might be a fallback entry. e.g. for ANGLE to use DXGI_FORMAT_R8G8B8A8_UNORM if
// DXGI_FORMAT_B5G5R5A1 isn't supported.
// In this case, we should only return 'true' if the format *ISN'T* supported.
return !fullSupport;
}}
}}
// End Format Support Functions
}} // namespace
ANGLEFormatSet::ANGLEFormatSet()
: format(ANGLE_FORMAT_NONE),
glInternalFormat(GL_NONE),
fboImplementationInternalFormat(GL_NONE),
texFormat(DXGI_FORMAT_UNKNOWN),
srvFormat(DXGI_FORMAT_UNKNOWN),
rtvFormat(DXGI_FORMAT_UNKNOWN),
dsvFormat(DXGI_FORMAT_UNKNOWN),
blitSRVFormat(DXGI_FORMAT_UNKNOWN),
swizzleFormat(ANGLE_FORMAT_NONE),
mipGenerationFunction(nullptr),
colorReadFunction(nullptr)
{{
}}
// For sized GL internal formats, there are several possible corresponding D3D11 formats depending
// on device capabilities.
// This function allows querying for the DXGI texture formats to use for textures, SRVs, RTVs and
// DSVs given a GL internal format.
TextureFormat::TextureFormat(GLenum internalFormat,
const ANGLEFormat angleFormat,
InitializeTextureDataFunction internalFormatInitializer,
const Renderer11DeviceCaps &deviceCaps)
: dataInitializerFunction(internalFormatInitializer)
{{
formatSet = &GetANGLEFormatSet(angleFormat, deviceCaps);
swizzleFormatSet = &GetANGLEFormatSet(formatSet->swizzleFormat, deviceCaps);
// Gather all the load functions for this internal format
loadFunctions = GetLoadFunctionsMap(internalFormat, formatSet->texFormat);
ASSERT(loadFunctions.size() != 0 || angleFormat == ANGLE_FORMAT_NONE);
}}
ANGLEFormatSet::ANGLEFormatSet(ANGLEFormat format,
GLenum glInternalFormat,
GLenum fboImplementationInternalFormat,
DXGI_FORMAT texFormat,
DXGI_FORMAT srvFormat,
DXGI_FORMAT rtvFormat,
DXGI_FORMAT dsvFormat,
DXGI_FORMAT blitSRVFormat,
ANGLEFormat swizzleFormat,
MipGenerationFunction mipGenerationFunction,
ColorReadFunction colorReadFunction)
: format(format),
glInternalFormat(glInternalFormat),
fboImplementationInternalFormat(fboImplementationInternalFormat),
texFormat(texFormat),
srvFormat(srvFormat),
rtvFormat(rtvFormat),
dsvFormat(dsvFormat),
blitSRVFormat(blitSRVFormat),
swizzleFormat(swizzleFormat),
mipGenerationFunction(mipGenerationFunction),
colorReadFunction(colorReadFunction)
{{
}}
const ANGLEFormatSet &GetANGLEFormatSet(ANGLEFormat angleFormat, const ANGLEFormatSet &GetANGLEFormatSet(ANGLEFormat angleFormat,
const Renderer11DeviceCaps &deviceCaps) const Renderer11DeviceCaps &deviceCaps)
{{ {{
......
//
// 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.
//
// Helper routines for the D3D11 texture format table.
#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h"
#include "libANGLE/renderer/d3d/d3d11/load_functions_table.h"
namespace rx
{
namespace d3d11
{
ANGLEFormatSet::ANGLEFormatSet()
: format(ANGLE_FORMAT_NONE),
glInternalFormat(GL_NONE),
fboImplementationInternalFormat(GL_NONE),
texFormat(DXGI_FORMAT_UNKNOWN),
srvFormat(DXGI_FORMAT_UNKNOWN),
rtvFormat(DXGI_FORMAT_UNKNOWN),
dsvFormat(DXGI_FORMAT_UNKNOWN),
blitSRVFormat(DXGI_FORMAT_UNKNOWN),
swizzleFormat(ANGLE_FORMAT_NONE),
mipGenerationFunction(nullptr),
colorReadFunction(nullptr)
{
}
ANGLEFormatSet::ANGLEFormatSet(ANGLEFormat format,
GLenum glInternalFormat,
GLenum fboImplementationInternalFormat,
DXGI_FORMAT texFormat,
DXGI_FORMAT srvFormat,
DXGI_FORMAT rtvFormat,
DXGI_FORMAT dsvFormat,
DXGI_FORMAT blitSRVFormat,
ANGLEFormat swizzleFormat,
MipGenerationFunction mipGenerationFunction,
ColorReadFunction colorReadFunction)
: format(format),
glInternalFormat(glInternalFormat),
fboImplementationInternalFormat(fboImplementationInternalFormat),
texFormat(texFormat),
srvFormat(srvFormat),
rtvFormat(rtvFormat),
dsvFormat(dsvFormat),
blitSRVFormat(blitSRVFormat),
swizzleFormat(swizzleFormat),
mipGenerationFunction(mipGenerationFunction),
colorReadFunction(colorReadFunction)
{
}
// For sized GL internal formats, there are several possible corresponding D3D11 formats depending
// on device capabilities.
// This function allows querying for the DXGI texture formats to use for textures, SRVs, RTVs and
// DSVs given a GL internal format.
TextureFormat::TextureFormat(GLenum internalFormat,
const ANGLEFormat angleFormat,
InitializeTextureDataFunction internalFormatInitializer,
const Renderer11DeviceCaps &deviceCaps)
: dataInitializerFunction(internalFormatInitializer)
{
formatSet = &GetANGLEFormatSet(angleFormat, deviceCaps);
swizzleFormatSet = &GetANGLEFormatSet(formatSet->swizzleFormat, deviceCaps);
// Gather all the load functions for this internal format
loadFunctions = GetLoadFunctionsMap(internalFormat, formatSet->texFormat);
ASSERT(loadFunctions.size() != 0 || angleFormat == ANGLE_FORMAT_NONE);
}
} // namespace d3d11
} // namespace rx
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
#include "image_util/loadimage.h" #include "image_util/loadimage.h"
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" #include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
#include "libANGLE/renderer/d3d/d3d11/load_functions_table.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" #include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "libANGLE/renderer/d3d/d3d11/texture_format_table_utils.h"
using namespace angle; using namespace angle;
...@@ -27,140 +27,6 @@ namespace rx ...@@ -27,140 +27,6 @@ namespace rx
namespace d3d11 namespace d3d11
{ {
namespace
{
typedef bool (*FormatSupportFunction)(const Renderer11DeviceCaps &);
bool OnlyFL10Plus(const Renderer11DeviceCaps &deviceCaps)
{
return (deviceCaps.featureLevel >= D3D_FEATURE_LEVEL_10_0);
}
bool OnlyFL9_3(const Renderer11DeviceCaps &deviceCaps)
{
return (deviceCaps.featureLevel == D3D_FEATURE_LEVEL_9_3);
}
template <DXGI_FORMAT format, bool requireSupport>
bool SupportsFormat(const Renderer11DeviceCaps &deviceCaps)
{
// Must support texture, SRV and RTV support
UINT mustSupport = D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURECUBE |
D3D11_FORMAT_SUPPORT_SHADER_SAMPLE | D3D11_FORMAT_SUPPORT_MIP |
D3D11_FORMAT_SUPPORT_RENDER_TARGET;
if (d3d11_gl::GetMaximumClientVersion(deviceCaps.featureLevel) > 2)
{
mustSupport |= D3D11_FORMAT_SUPPORT_TEXTURE3D;
}
bool fullSupport = false;
if (format == DXGI_FORMAT_B5G6R5_UNORM)
{
// All hardware that supports DXGI_FORMAT_B5G6R5_UNORM should support autogen mipmaps, but
// check anyway.
mustSupport |= D3D11_FORMAT_SUPPORT_MIP_AUTOGEN;
fullSupport = ((deviceCaps.B5G6R5support & mustSupport) == mustSupport);
}
else if (format == DXGI_FORMAT_B4G4R4A4_UNORM)
{
fullSupport = ((deviceCaps.B4G4R4A4support & mustSupport) == mustSupport);
}
else if (format == DXGI_FORMAT_B5G5R5A1_UNORM)
{
fullSupport = ((deviceCaps.B5G5R5A1support & mustSupport) == mustSupport);
}
else
{
UNREACHABLE();
return false;
}
// This 'SupportsFormat' function is used by individual entries in the D3D11 Format Map below,
// which maps GL formats to DXGI formats.
if (requireSupport)
{
// This means that ANGLE would like to use the entry in the map if the inputted DXGI format
// *IS* supported.
// e.g. the entry might map GL_RGB5_A1 to DXGI_FORMAT_B5G5R5A1, which should only be used if
// DXGI_FORMAT_B5G5R5A1 is supported.
// In this case, we should only return 'true' if the format *IS* supported.
return fullSupport;
}
else
{
// This means that ANGLE would like to use the entry in the map if the inputted DXGI format
// *ISN'T* supported.
// This might be a fallback entry. e.g. for ANGLE to use DXGI_FORMAT_R8G8B8A8_UNORM if
// DXGI_FORMAT_B5G5R5A1 isn't supported.
// In this case, we should only return 'true' if the format *ISN'T* supported.
return !fullSupport;
}
}
// End Format Support Functions
} // namespace
ANGLEFormatSet::ANGLEFormatSet()
: format(ANGLE_FORMAT_NONE),
glInternalFormat(GL_NONE),
fboImplementationInternalFormat(GL_NONE),
texFormat(DXGI_FORMAT_UNKNOWN),
srvFormat(DXGI_FORMAT_UNKNOWN),
rtvFormat(DXGI_FORMAT_UNKNOWN),
dsvFormat(DXGI_FORMAT_UNKNOWN),
blitSRVFormat(DXGI_FORMAT_UNKNOWN),
swizzleFormat(ANGLE_FORMAT_NONE),
mipGenerationFunction(nullptr),
colorReadFunction(nullptr)
{
}
// For sized GL internal formats, there are several possible corresponding D3D11 formats depending
// on device capabilities.
// This function allows querying for the DXGI texture formats to use for textures, SRVs, RTVs and
// DSVs given a GL internal format.
TextureFormat::TextureFormat(GLenum internalFormat,
const ANGLEFormat angleFormat,
InitializeTextureDataFunction internalFormatInitializer,
const Renderer11DeviceCaps &deviceCaps)
: dataInitializerFunction(internalFormatInitializer)
{
formatSet = &GetANGLEFormatSet(angleFormat, deviceCaps);
swizzleFormatSet = &GetANGLEFormatSet(formatSet->swizzleFormat, deviceCaps);
// Gather all the load functions for this internal format
loadFunctions = GetLoadFunctionsMap(internalFormat, formatSet->texFormat);
ASSERT(loadFunctions.size() != 0 || angleFormat == ANGLE_FORMAT_NONE);
}
ANGLEFormatSet::ANGLEFormatSet(ANGLEFormat format,
GLenum glInternalFormat,
GLenum fboImplementationInternalFormat,
DXGI_FORMAT texFormat,
DXGI_FORMAT srvFormat,
DXGI_FORMAT rtvFormat,
DXGI_FORMAT dsvFormat,
DXGI_FORMAT blitSRVFormat,
ANGLEFormat swizzleFormat,
MipGenerationFunction mipGenerationFunction,
ColorReadFunction colorReadFunction)
: format(format),
glInternalFormat(glInternalFormat),
fboImplementationInternalFormat(fboImplementationInternalFormat),
texFormat(texFormat),
srvFormat(srvFormat),
rtvFormat(rtvFormat),
dsvFormat(dsvFormat),
blitSRVFormat(blitSRVFormat),
swizzleFormat(swizzleFormat),
mipGenerationFunction(mipGenerationFunction),
colorReadFunction(colorReadFunction)
{
}
const ANGLEFormatSet &GetANGLEFormatSet(ANGLEFormat angleFormat, const ANGLEFormatSet &GetANGLEFormatSet(ANGLEFormat angleFormat,
const Renderer11DeviceCaps &deviceCaps) const Renderer11DeviceCaps &deviceCaps)
{ {
......
//
// 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.
//
// Helper routines for the D3D11 texture format table.
#ifndef LIBANGLE_RENDERER_D3D_D3D11_TEXTURE_FORMAT_TABLE_UTILS_H_
#define LIBANGLE_RENDERER_D3D_D3D11_TEXTURE_FORMAT_TABLE_UTILS_H_
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
namespace rx
{
namespace d3d11
{
using FormatSupportFunction = bool (*)(const Renderer11DeviceCaps &);
inline bool OnlyFL10Plus(const Renderer11DeviceCaps &deviceCaps)
{
return (deviceCaps.featureLevel >= D3D_FEATURE_LEVEL_10_0);
}
inline bool OnlyFL9_3(const Renderer11DeviceCaps &deviceCaps)
{
return (deviceCaps.featureLevel == D3D_FEATURE_LEVEL_9_3);
}
template <DXGI_FORMAT format, bool requireSupport>
bool SupportsFormat(const Renderer11DeviceCaps &deviceCaps)
{
// Must support texture, SRV and RTV support
UINT mustSupport = D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURECUBE |
D3D11_FORMAT_SUPPORT_SHADER_SAMPLE | D3D11_FORMAT_SUPPORT_MIP |
D3D11_FORMAT_SUPPORT_RENDER_TARGET;
if (d3d11_gl::GetMaximumClientVersion(deviceCaps.featureLevel) > 2)
{
mustSupport |= D3D11_FORMAT_SUPPORT_TEXTURE3D;
}
bool fullSupport = false;
if (format == DXGI_FORMAT_B5G6R5_UNORM)
{
// All hardware that supports DXGI_FORMAT_B5G6R5_UNORM should support autogen mipmaps, but
// check anyway.
mustSupport |= D3D11_FORMAT_SUPPORT_MIP_AUTOGEN;
fullSupport = ((deviceCaps.B5G6R5support & mustSupport) == mustSupport);
}
else if (format == DXGI_FORMAT_B4G4R4A4_UNORM)
{
fullSupport = ((deviceCaps.B4G4R4A4support & mustSupport) == mustSupport);
}
else if (format == DXGI_FORMAT_B5G5R5A1_UNORM)
{
fullSupport = ((deviceCaps.B5G5R5A1support & mustSupport) == mustSupport);
}
else
{
UNREACHABLE();
return false;
}
// This 'SupportsFormat' function is used by individual entries in the D3D11 Format Map below,
// which maps GL formats to DXGI formats.
if (requireSupport)
{
// This means that ANGLE would like to use the entry in the map if the inputted DXGI format
// *IS* supported.
// e.g. the entry might map GL_RGB5_A1 to DXGI_FORMAT_B5G5R5A1, which should only be used if
// DXGI_FORMAT_B5G5R5A1 is supported.
// In this case, we should only return 'true' if the format *IS* supported.
return fullSupport;
}
else
{
// This means that ANGLE would like to use the entry in the map if the inputted DXGI format
// *ISN'T* supported.
// This might be a fallback entry. e.g. for ANGLE to use DXGI_FORMAT_R8G8B8A8_UNORM if
// DXGI_FORMAT_B5G5R5A1 isn't supported.
// In this case, we should only return 'true' if the format *ISN'T* supported.
return !fullSupport;
}
}
} // namespace d3d11
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_D3D11_TEXTURE_FORMAT_TABLE_UTILS_H_
...@@ -422,6 +422,8 @@ ...@@ -422,6 +422,8 @@
'libANGLE/renderer/d3d/d3d11/Trim11.h', 'libANGLE/renderer/d3d/d3d11/Trim11.h',
'libANGLE/renderer/d3d/d3d11/texture_format_table_autogen.cpp', 'libANGLE/renderer/d3d/d3d11/texture_format_table_autogen.cpp',
'libANGLE/renderer/d3d/d3d11/texture_format_table_autogen.h', 'libANGLE/renderer/d3d/d3d11/texture_format_table_autogen.h',
'libANGLE/renderer/d3d/d3d11/texture_format_table_utils.h',
'libANGLE/renderer/d3d/d3d11/texture_format_table.cpp',
'libANGLE/renderer/d3d/d3d11/texture_format_table.h', 'libANGLE/renderer/d3d/d3d11/texture_format_table.h',
'libANGLE/renderer/d3d/d3d11/VertexArray11.cpp', 'libANGLE/renderer/d3d/d3d11/VertexArray11.cpp',
'libANGLE/renderer/d3d/d3d11/VertexArray11.h', 'libANGLE/renderer/d3d/d3d11/VertexArray11.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