Commit 4b66f055 by Olli Etuaho Committed by Commit Bot

Make copyDepthStencil more robust to texture format table changes

This will make it easier to verify changes to integer texture DXGI formats. Currently the DXGI format info table contains some values that wouldn't make sense after the integer formats are changed, such as R32_TYPELESS being recorded as a depth format, and we need to make sure no code relies on this kind of information to make changing the table safe. Includes cleaning up unused depth/stencil offset fields from DXGIFormatInfo. BUG=angleproject:1244 TEST=dEQP-GLES3.functional.fbo.blit.*depth* Change-Id: I0149f28e4c6f961af99ac2f5a656f3fbfe13aee6 Reviewed-on: https://chromium-review.googlesource.com/328964Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 86821db3
...@@ -1070,20 +1070,25 @@ gl::Error Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSu ...@@ -1070,20 +1070,25 @@ gl::Error Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSu
DXGI_FORMAT format = GetTextureFormat(source); DXGI_FORMAT format = GetTextureFormat(source);
ASSERT(format == GetTextureFormat(dest)); ASSERT(format == GetTextureFormat(dest));
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(format);
const d3d11::DXGIFormatSize &dxgiFormatSizeInfo = d3d11::GetDXGIFormatSizeInfo(format); const d3d11::DXGIFormatSize &dxgiFormatSizeInfo = d3d11::GetDXGIFormatSizeInfo(format);
unsigned int pixelSize = dxgiFormatSizeInfo.pixelBytes; unsigned int pixelSize = dxgiFormatSizeInfo.pixelBytes;
unsigned int copyOffset = 0; unsigned int copyOffset = 0;
unsigned int copySize = pixelSize; unsigned int copySize = pixelSize;
if (stencilOnly) if (stencilOnly)
{ {
copyOffset = dxgiFormatInfo.depthBits / 8; const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(format);
copySize = dxgiFormatInfo.stencilBits / 8;
// Stencil channel should be right after the depth channel. Some views to depth/stencil
// It would be expensive to have non-byte sized stencil sizes since it would // resources have red channel for depth, in which case the depth channel bit width is in
// require reading from the destination, currently there aren't any though. // redBits.
ASSERT(dxgiFormatInfo.stencilBits % 8 == 0 && ASSERT((dxgiFormatInfo.redBits != 0) != (dxgiFormatInfo.depthBits != 0));
dxgiFormatInfo.depthBits % 8 == 0); GLuint depthBits = dxgiFormatInfo.redBits + dxgiFormatInfo.depthBits;
// Known formats have either 24 or 32 bits of depth.
ASSERT(depthBits == 24 || depthBits == 32);
copyOffset = depthBits / 8;
// Stencil is assumed to be 8-bit - currently this is true for all possible formats.
copySize = 1;
} }
D3D11_MAPPED_SUBRESOURCE sourceMapping; D3D11_MAPPED_SUBRESOURCE sourceMapping;
......
...@@ -226,22 +226,20 @@ static ColorFormatInfoMap BuildColorFormatInfoMap() ...@@ -226,22 +226,20 @@ static ColorFormatInfoMap BuildColorFormatInfoMap()
struct DXGIDepthStencilInfo struct DXGIDepthStencilInfo
{ {
unsigned int depthBits; unsigned int depthBits;
unsigned int depthOffset;
unsigned int stencilBits; unsigned int stencilBits;
unsigned int stencilOffset;
}; };
typedef std::map<DXGI_FORMAT, DXGIDepthStencilInfo> DepthStencilInfoMap; typedef std::map<DXGI_FORMAT, DXGIDepthStencilInfo> DepthStencilInfoMap;
typedef std::pair<DXGI_FORMAT, DXGIDepthStencilInfo> DepthStencilInfoPair; typedef std::pair<DXGI_FORMAT, DXGIDepthStencilInfo> DepthStencilInfoPair;
static inline void InsertDXGIDepthStencilInfo(DepthStencilInfoMap *map, DXGI_FORMAT format, unsigned int depthBits, static inline void InsertDXGIDepthStencilInfo(DepthStencilInfoMap *map,
unsigned int depthOffset, unsigned int stencilBits, unsigned int stencilOffset) DXGI_FORMAT format,
unsigned int depthBits,
unsigned int stencilBits)
{ {
DXGIDepthStencilInfo info; DXGIDepthStencilInfo info;
info.depthBits = depthBits; info.depthBits = depthBits;
info.depthOffset = depthOffset;
info.stencilBits = stencilBits; info.stencilBits = stencilBits;
info.stencilOffset = stencilOffset;
map->insert(std::make_pair(format, info)); map->insert(std::make_pair(format, info));
} }
...@@ -250,21 +248,23 @@ static DepthStencilInfoMap BuildDepthStencilInfoMap() ...@@ -250,21 +248,23 @@ static DepthStencilInfoMap BuildDepthStencilInfoMap()
{ {
DepthStencilInfoMap map; DepthStencilInfoMap map;
InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R16_TYPELESS, 16, 0, 0, 0); // clang-format off
InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R16_UNORM, 16, 0, 0, 0); InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R16_TYPELESS, 16, 0);
InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_D16_UNORM, 16, 0, 0, 0); InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R16_UNORM, 16, 0);
InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_D16_UNORM, 16, 0);
InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R24G8_TYPELESS, 24, 0, 8, 24); InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R24G8_TYPELESS, 24, 8);
InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, 24, 0, 8, 24); InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, 24, 8);
InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_D24_UNORM_S8_UINT, 24, 0, 8, 24); InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_D24_UNORM_S8_UINT, 24, 8);
InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R32_TYPELESS, 32, 0, 0, 0); InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R32_TYPELESS, 32, 0);
InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R32_FLOAT, 32, 0, 0, 0); InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R32_FLOAT, 32, 0);
InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_D32_FLOAT, 32, 0, 0, 0); InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_D32_FLOAT, 32, 0);
InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R32G8X24_TYPELESS, 32, 0, 8, 32); InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R32G8X24_TYPELESS, 32, 8);
InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, 32, 0, 8, 32); InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, 32, 8);
InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_D32_FLOAT_S8X24_UINT, 32, 0, 8, 32); InsertDXGIDepthStencilInfo(&map, DXGI_FORMAT_D32_FLOAT_S8X24_UINT, 32, 8);
// clang-format on
return map; return map;
} }
...@@ -278,9 +278,7 @@ DXGIFormat::DXGIFormat() ...@@ -278,9 +278,7 @@ DXGIFormat::DXGIFormat()
alphaBits(0), alphaBits(0),
sharedBits(0), sharedBits(0),
depthBits(0), depthBits(0),
depthOffset(0),
stencilBits(0), stencilBits(0),
stencilOffset(0),
internalFormat(GL_NONE), internalFormat(GL_NONE),
componentType(GL_NONE), componentType(GL_NONE),
colorReadFunction(NULL), colorReadFunction(NULL),
...@@ -332,9 +330,7 @@ void AddDXGIFormat(DXGIFormatInfoMap *map, ...@@ -332,9 +330,7 @@ void AddDXGIFormat(DXGIFormatInfoMap *map,
{ {
const DXGIDepthStencilInfo &dsInfo = dsInfoIter->second; const DXGIDepthStencilInfo &dsInfo = dsInfoIter->second;
info.depthBits = dsInfo.depthBits; info.depthBits = dsInfo.depthBits;
info.depthOffset = dsInfo.depthOffset;
info.stencilBits = dsInfo.stencilBits; info.stencilBits = dsInfo.stencilBits;
info.stencilOffset = dsInfo.stencilOffset;
} }
static const DXGIToESFormatMap dxgiToESMap = BuildDXGIToESFormatMap(); static const DXGIToESFormatMap dxgiToESMap = BuildDXGIToESFormatMap();
......
...@@ -38,9 +38,7 @@ struct DXGIFormat ...@@ -38,9 +38,7 @@ struct DXGIFormat
GLuint sharedBits; GLuint sharedBits;
GLuint depthBits; GLuint depthBits;
GLuint depthOffset;
GLuint stencilBits; GLuint stencilBits;
GLuint stencilOffset;
GLenum internalFormat; GLenum internalFormat;
GLenum componentType; GLenum componentType;
......
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