Commit 8a854d68 by Olli Etuaho Committed by Commit Bot

Replace GetDXGIFormatInfo with a GetDXGIFormatSizeInfo where possible

It's not always clear which format should be passed to GetDXGIFormatInfo, since a resource is associated with multiple formats. In some cases, one of the formats is typeless and one of them is typed, which would return different type information depending on which one is used. In some cases, one of the formats may even be a depth format while another is not. GetDXGIFormatSizeInfo will return correct data no matter which format associated with a certain resource is passed to it. Remaining uses of GetDXGIFormatInfo will need to be addressed separately, either making sure that they always use the format that makes sense in a given context, or plumbing in the required information in some other way. BUG=angleproject:1244 TEST=angle_end2end_tests Change-Id: If3cb03ab68d27743b1fdeb539234ec621dfa3c04 Reviewed-on: https://chromium-review.googlesource.com/328230Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 8322cb91
...@@ -1052,7 +1052,8 @@ gl::Error Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSu ...@@ -1052,7 +1052,8 @@ gl::Error Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSu
ASSERT(format == GetTextureFormat(dest)); ASSERT(format == GetTextureFormat(dest));
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(format); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(format);
unsigned int pixelSize = dxgiFormatInfo.pixelBytes; const d3d11::DXGIFormatSize &dxgiFormatSizeInfo = d3d11::GetDXGIFormatSizeInfo(format);
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)
......
...@@ -606,7 +606,7 @@ ID3D11ShaderResourceView *Buffer11::getSRV(DXGI_FORMAT srvFormat) ...@@ -606,7 +606,7 @@ ID3D11ShaderResourceView *Buffer11::getSRV(DXGI_FORMAT srvFormat)
ID3D11Device *device = mRenderer->getDevice(); ID3D11Device *device = mRenderer->getDevice();
ID3D11ShaderResourceView *bufferSRV = nullptr; ID3D11ShaderResourceView *bufferSRV = nullptr;
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(srvFormat); const d3d11::DXGIFormatSize &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(srvFormat);
D3D11_SHADER_RESOURCE_VIEW_DESC bufferSRVDesc; D3D11_SHADER_RESOURCE_VIEW_DESC bufferSRVDesc;
bufferSRVDesc.Buffer.ElementOffset = 0; bufferSRVDesc.Buffer.ElementOffset = 0;
......
...@@ -252,7 +252,7 @@ gl::Error Image11::loadData(const gl::Box &area, const gl::PixelUnpackState &unp ...@@ -252,7 +252,7 @@ gl::Error Image11::loadData(const gl::Box &area, const gl::PixelUnpackState &unp
GLsizei inputSkipBytes = formatInfo.computeSkipPixels( GLsizei inputSkipBytes = formatInfo.computeSkipPixels(
inputRowPitch, inputDepthPitch, unpack.skipImages, unpack.skipRows, unpack.skipPixels); inputRowPitch, inputDepthPitch, unpack.skipImages, unpack.skipRows, unpack.skipPixels);
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(mDXGIFormat); const d3d11::DXGIFormatSize &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(mDXGIFormat);
GLuint outputPixelSize = dxgiFormatInfo.pixelBytes; GLuint outputPixelSize = dxgiFormatInfo.pixelBytes;
const d3d11::TextureFormat &d3dFormatInfo = d3d11::GetTextureFormatInfo(mInternalFormat, mRenderer->getRenderer11DeviceCaps()); const d3d11::TextureFormat &d3dFormatInfo = d3d11::GetTextureFormatInfo(mInternalFormat, mRenderer->getRenderer11DeviceCaps());
...@@ -282,7 +282,7 @@ gl::Error Image11::loadCompressedData(const gl::Box &area, const void *input) ...@@ -282,7 +282,7 @@ gl::Error Image11::loadCompressedData(const gl::Box &area, const void *input)
GLsizei inputDepthPitch = GLsizei inputDepthPitch =
formatInfo.computeDepthPitch(GL_UNSIGNED_BYTE, area.width, area.height, 1, 0, 0); formatInfo.computeDepthPitch(GL_UNSIGNED_BYTE, area.width, area.height, 1, 0, 0);
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(mDXGIFormat); const d3d11::DXGIFormatSize &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(mDXGIFormat);
GLuint outputPixelSize = dxgiFormatInfo.pixelBytes; GLuint outputPixelSize = dxgiFormatInfo.pixelBytes;
GLuint outputBlockWidth = dxgiFormatInfo.blockWidth; GLuint outputBlockWidth = dxgiFormatInfo.blockWidth;
GLuint outputBlockHeight = dxgiFormatInfo.blockHeight; GLuint outputBlockHeight = dxgiFormatInfo.blockHeight;
...@@ -370,7 +370,7 @@ gl::Error Image11::copyFromFramebuffer(const gl::Offset &destOffset, ...@@ -370,7 +370,7 @@ gl::Error Image11::copyFromFramebuffer(const gl::Offset &destOffset,
} }
// determine the offset coordinate into the destination buffer // determine the offset coordinate into the destination buffer
const auto &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(mDXGIFormat); const auto &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(mDXGIFormat);
GLsizei rowOffset = dxgiFormatInfo.pixelBytes * destOffset.x; GLsizei rowOffset = dxgiFormatInfo.pixelBytes * destOffset.x;
uint8_t *dataOffset = static_cast<uint8_t *>(mappedImage.pData) + uint8_t *dataOffset = static_cast<uint8_t *>(mappedImage.pData) +
......
...@@ -462,6 +462,7 @@ gl::Error TextureStorage11::updateSubresourceLevel(ID3D11Resource *srcTexture, ...@@ -462,6 +462,7 @@ gl::Error TextureStorage11::updateSubresourceLevel(ID3D11Resource *srcTexture,
ASSERT(dstTexture); ASSERT(dstTexture);
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(mTextureFormat); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(mTextureFormat);
const d3d11::DXGIFormatSize &dxgiFormatSizeInfo = d3d11::GetDXGIFormatSizeInfo(mTextureFormat);
if (!fullCopy && (dxgiFormatInfo.depthBits > 0 || dxgiFormatInfo.stencilBits > 0)) if (!fullCopy && (dxgiFormatInfo.depthBits > 0 || dxgiFormatInfo.stencilBits > 0))
{ {
// CopySubresourceRegion cannot copy partial depth stencils, use the blitter instead // CopySubresourceRegion cannot copy partial depth stencils, use the blitter instead
...@@ -476,9 +477,9 @@ gl::Error TextureStorage11::updateSubresourceLevel(ID3D11Resource *srcTexture, ...@@ -476,9 +477,9 @@ gl::Error TextureStorage11::updateSubresourceLevel(ID3D11Resource *srcTexture,
srcBox.left = copyArea.x; srcBox.left = copyArea.x;
srcBox.top = copyArea.y; srcBox.top = copyArea.y;
srcBox.right = srcBox.right =
copyArea.x + roundUp(static_cast<UINT>(copyArea.width), dxgiFormatInfo.blockWidth); copyArea.x + roundUp(static_cast<UINT>(copyArea.width), dxgiFormatSizeInfo.blockWidth);
srcBox.bottom = srcBox.bottom = copyArea.y +
copyArea.y + roundUp(static_cast<UINT>(copyArea.height), dxgiFormatInfo.blockHeight); roundUp(static_cast<UINT>(copyArea.height), dxgiFormatSizeInfo.blockHeight);
srcBox.front = copyArea.z; srcBox.front = copyArea.z;
srcBox.back = copyArea.z + copyArea.depth; srcBox.back = copyArea.z + copyArea.depth;
...@@ -693,7 +694,8 @@ gl::Error TextureStorage11::setData(const gl::ImageIndex &index, ...@@ -693,7 +694,8 @@ gl::Error TextureStorage11::setData(const gl::ImageIndex &index,
const d3d11::TextureFormat &d3d11Format = d3d11::GetTextureFormatInfo( const d3d11::TextureFormat &d3d11Format = d3d11::GetTextureFormatInfo(
image->getInternalFormat(), mRenderer->getRenderer11DeviceCaps()); image->getInternalFormat(), mRenderer->getRenderer11DeviceCaps());
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(d3d11Format.texFormat); const d3d11::DXGIFormatSize &dxgiFormatInfo =
d3d11::GetDXGIFormatSizeInfo(d3d11Format.texFormat);
const size_t outputPixelSize = dxgiFormatInfo.pixelBytes; const size_t outputPixelSize = dxgiFormatInfo.pixelBytes;
......
...@@ -163,7 +163,8 @@ gl::Error VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GL ...@@ -163,7 +163,8 @@ gl::Error VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GL
gl::VertexFormatType formatType = gl::GetVertexFormatType(attrib); gl::VertexFormatType formatType = gl::GetVertexFormatType(attrib);
const D3D_FEATURE_LEVEL featureLevel = mRenderer->getRenderer11DeviceCaps().featureLevel; const D3D_FEATURE_LEVEL featureLevel = mRenderer->getRenderer11DeviceCaps().featureLevel;
const d3d11::VertexFormat &vertexFormatInfo = d3d11::GetVertexFormatInfo(formatType, featureLevel); const d3d11::VertexFormat &vertexFormatInfo = d3d11::GetVertexFormatInfo(formatType, featureLevel);
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(vertexFormatInfo.nativeFormat); const d3d11::DXGIFormatSize &dxgiFormatInfo =
d3d11::GetDXGIFormatSizeInfo(vertexFormatInfo.nativeFormat);
unsigned int elementSize = dxgiFormatInfo.pixelBytes; unsigned int elementSize = dxgiFormatInfo.pixelBytes;
if (elementSize <= std::numeric_limits<unsigned int>::max() / elementCount) if (elementSize <= std::numeric_limits<unsigned int>::max() / elementCount)
{ {
......
...@@ -31,10 +31,6 @@ struct DXGIFormat ...@@ -31,10 +31,6 @@ struct DXGIFormat
{ {
DXGIFormat(); DXGIFormat();
GLuint pixelBytes;
GLuint blockWidth;
GLuint blockHeight;
GLuint redBits; GLuint redBits;
GLuint greenBits; GLuint greenBits;
GLuint blueBits; GLuint blueBits;
...@@ -58,8 +54,23 @@ struct DXGIFormat ...@@ -58,8 +54,23 @@ struct DXGIFormat
ColorCopyFunction getFastCopyFunction(GLenum format, GLenum type) const; ColorCopyFunction getFastCopyFunction(GLenum format, GLenum type) const;
}; };
// This structure is problematic because a resource is associated with multiple DXGI formats.
// For example, a texture might be stored as DXGI_FORMAT_R16_TYPELESS but store integer components,
// which are accessed through an DXGI_FORMAT_R16_SINT view. It's easy to write code which queries
// information about the wrong format. Therefore, use of this should be avoided where possible.
const DXGIFormat &GetDXGIFormatInfo(DXGI_FORMAT format); const DXGIFormat &GetDXGIFormatInfo(DXGI_FORMAT format);
struct DXGIFormatSize
{
DXGIFormatSize(GLuint pixelBits, GLuint blockWidth, GLuint blockHeight);
GLuint pixelBytes;
GLuint blockWidth;
GLuint blockHeight;
};
const DXGIFormatSize &GetDXGIFormatSizeInfo(DXGI_FORMAT format);
struct VertexFormat struct VertexFormat
{ {
VertexFormat(); VertexFormat();
......
...@@ -1323,7 +1323,7 @@ ANGLED3D11DeviceType GetDeviceType(ID3D11Device *device) ...@@ -1323,7 +1323,7 @@ ANGLED3D11DeviceType GetDeviceType(ID3D11Device *device)
void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset) void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset)
{ {
const DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(format); const DXGIFormatSize &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(format);
int upsampleCount = 0; int upsampleCount = 0;
// Don't expand the size of full textures that are at least (blockWidth x blockHeight) already. // Don't expand the size of full textures that are at least (blockWidth x blockHeight) already.
...@@ -1352,7 +1352,8 @@ void GenerateInitialTextureData(GLint internalFormat, ...@@ -1352,7 +1352,8 @@ void GenerateInitialTextureData(GLint internalFormat,
const d3d11::TextureFormat &d3dFormatInfo = d3d11::GetTextureFormatInfo(internalFormat, renderer11DeviceCaps); const d3d11::TextureFormat &d3dFormatInfo = d3d11::GetTextureFormatInfo(internalFormat, renderer11DeviceCaps);
ASSERT(d3dFormatInfo.dataInitializerFunction != NULL); ASSERT(d3dFormatInfo.dataInitializerFunction != NULL);
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(d3dFormatInfo.texFormat); const d3d11::DXGIFormatSize &dxgiFormatInfo =
d3d11::GetDXGIFormatSizeInfo(d3dFormatInfo.texFormat);
outSubresourceData->resize(mipLevels); outSubresourceData->resize(mipLevels);
outData->resize(mipLevels); outData->resize(mipLevels);
......
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