Commit 1a4523f3 by Olli Etuaho Committed by Commit Bot

Avoid copying of texture format info structures

Use const pointers to the statically allocated structures instead of copying them in TextureStorage11. This avoids the cost of copying and saves a little bit of memory. BUG=angleproject:1244 TEST=angle_end2end_tests Change-Id: Ib59fddd68ba9bc53e491d55683416c0661f26e0e Reviewed-on: https://chromium-review.googlesource.com/333930Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 90a96efc
......@@ -68,7 +68,7 @@ gl::Error Image11::generateMipmap(Image11 *dest,
uint8_t *destData = reinterpret_cast<uint8_t*>(destMapped.pData);
auto mipGenerationFunction = d3d11::GetTextureFormatInfo(src->getInternalFormat(), rendererCaps)
.formatSet.mipGenerationFunction;
.formatSet->mipGenerationFunction;
mipGenerationFunction(src->getWidth(), src->getHeight(), src->getDepth(), sourceData,
srcMapped.RowPitch, srcMapped.DepthPitch, destData, destMapped.RowPitch,
destMapped.DepthPitch);
......@@ -222,8 +222,8 @@ bool Image11::redefine(GLenum target, GLenum internalformat, const gl::Extents &
// compute the d3d format that will be used
const d3d11::TextureFormat &formatInfo =
d3d11::GetTextureFormatInfo(internalformat, mRenderer->getRenderer11DeviceCaps());
mDXGIFormat = formatInfo.formatSet.texFormat;
mRenderable = (formatInfo.formatSet.rtvFormat != DXGI_FORMAT_UNKNOWN);
mDXGIFormat = formatInfo.formatSet->texFormat;
mRenderable = (formatInfo.formatSet->rtvFormat != DXGI_FORMAT_UNKNOWN);
releaseStagingTexture();
mDirty = (formatInfo.dataInitializerFunction != NULL);
......@@ -344,7 +344,7 @@ gl::Error Image11::copyFromFramebuffer(const gl::Offset &destOffset,
const auto &d3d11Format = d3d11::GetTextureFormatInfo(srcAttachment->getInternalFormat(),
mRenderer->getRenderer11DeviceCaps());
if (d3d11Format.formatSet.texFormat == mDXGIFormat)
if (d3d11Format.formatSet->texFormat == mDXGIFormat)
{
RenderTargetD3D *renderTarget = nullptr;
gl::Error error = srcAttachment->getRenderTarget(&renderTarget);
......
......@@ -205,7 +205,7 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpac
GLenum sourceFormat = gl::GetSizedInternalFormat(unsizedFormat, sourcePixelsType);
const d3d11::TextureFormat &sourceFormatInfo = d3d11::GetTextureFormatInfo(sourceFormat, mRenderer->getRenderer11DeviceCaps());
DXGI_FORMAT srvFormat = sourceFormatInfo.formatSet.srvFormat;
DXGI_FORMAT srvFormat = sourceFormatInfo.formatSet->srvFormat;
ASSERT(srvFormat != DXGI_FORMAT_UNKNOWN);
Buffer11 *bufferStorage11 = GetAs<Buffer11>(sourceBuffer.getImplementation());
ID3D11ShaderResourceView *bufferSRV = bufferStorage11->getSRV(srvFormat);
......
......@@ -381,7 +381,7 @@ SurfaceRenderTarget11::SurfaceRenderTarget11(SwapChain11 *swapChain,
mANGLEFormat = d3d11::GetTextureFormatInfo(getInternalFormatInternal(),
mRenderer->getRenderer11DeviceCaps())
.formatSet.format;
.formatSet->format;
}
SurfaceRenderTarget11::~SurfaceRenderTarget11()
......
......@@ -3036,7 +3036,7 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
desc.Height = height;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = formatInfo.formatSet.texFormat;
desc.Format = formatInfo.formatSet->texFormat;
desc.SampleDesc.Count = (supportedSamples == 0) ? 1 : supportedSamples;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
......@@ -3047,14 +3047,14 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
// we'll flag it to allow binding that way. Shader resource views are a little
// more complicated.
bool bindRTV = false, bindDSV = false, bindSRV = false;
bindRTV = (formatInfo.formatSet.rtvFormat != DXGI_FORMAT_UNKNOWN);
bindDSV = (formatInfo.formatSet.dsvFormat != DXGI_FORMAT_UNKNOWN);
if (formatInfo.formatSet.srvFormat != DXGI_FORMAT_UNKNOWN)
bindRTV = (formatInfo.formatSet->rtvFormat != DXGI_FORMAT_UNKNOWN);
bindDSV = (formatInfo.formatSet->dsvFormat != DXGI_FORMAT_UNKNOWN);
if (formatInfo.formatSet->srvFormat != DXGI_FORMAT_UNKNOWN)
{
// Multisample targets flagged for binding as depth stencil cannot also be
// flagged for binding as SRV, so make certain not to add the SRV flag for
// these targets.
bindSRV = !(formatInfo.formatSet.dsvFormat != DXGI_FORMAT_UNKNOWN &&
bindSRV = !(formatInfo.formatSet->dsvFormat != DXGI_FORMAT_UNKNOWN &&
desc.SampleDesc.Count > 1);
}
......@@ -3078,7 +3078,7 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
if (bindSRV)
{
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = formatInfo.formatSet.srvFormat;
srvDesc.Format = formatInfo.formatSet->srvFormat;
srvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS;
srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = 1;
......@@ -3091,10 +3091,10 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create render target shader resource view, result: 0x%X.", result);
}
if (formatInfo.formatSet.blitSRVFormat != formatInfo.formatSet.srvFormat)
if (formatInfo.formatSet->blitSRVFormat != formatInfo.formatSet->srvFormat)
{
D3D11_SHADER_RESOURCE_VIEW_DESC blitSRVDesc;
blitSRVDesc.Format = formatInfo.formatSet.blitSRVFormat;
blitSRVDesc.Format = formatInfo.formatSet->blitSRVFormat;
blitSRVDesc.ViewDimension = (supportedSamples == 0)
? D3D11_SRV_DIMENSION_TEXTURE2D
: D3D11_SRV_DIMENSION_TEXTURE2DMS;
......@@ -3123,7 +3123,7 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
if (bindDSV)
{
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
dsvDesc.Format = formatInfo.formatSet.dsvFormat;
dsvDesc.Format = formatInfo.formatSet->dsvFormat;
dsvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_DSV_DIMENSION_TEXTURE2D : D3D11_DSV_DIMENSION_TEXTURE2DMS;
dsvDesc.Texture2D.MipSlice = 0;
dsvDesc.Flags = 0;
......@@ -3140,7 +3140,7 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
}
*outRT =
new TextureRenderTarget11(dsv, texture, srv, format, formatInfo.formatSet.format,
new TextureRenderTarget11(dsv, texture, srv, format, formatInfo.formatSet->format,
width, height, 1, supportedSamples);
SafeRelease(dsv);
......@@ -3148,7 +3148,7 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
else if (bindRTV)
{
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
rtvDesc.Format = formatInfo.formatSet.rtvFormat;
rtvDesc.Format = formatInfo.formatSet->rtvFormat;
rtvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_RTV_DIMENSION_TEXTURE2D : D3D11_RTV_DIMENSION_TEXTURE2DMS;
rtvDesc.Texture2D.MipSlice = 0;
......@@ -3170,7 +3170,7 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
}
*outRT = new TextureRenderTarget11(rtv, texture, srv, blitSRV, format,
formatInfo.formatSet.format, width, height, 1,
formatInfo.formatSet->format, width, height, 1,
supportedSamples);
SafeRelease(rtv);
......@@ -3473,7 +3473,7 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const
}
// We cannot support direct copies to non-color-renderable formats
if (d3d11FormatInfo.formatSet.rtvFormat == DXGI_FORMAT_UNKNOWN)
if (d3d11FormatInfo.formatSet->rtvFormat == DXGI_FORMAT_UNKNOWN)
{
return false;
}
......@@ -3485,7 +3485,7 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const
}
// We don't support formats which we can't represent without conversion
if (d3d11FormatInfo.formatSet.glInternalFormat != internalFormat)
if (d3d11FormatInfo.formatSet->glInternalFormat != internalFormat)
{
return false;
}
......
......@@ -208,7 +208,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe
if (offscreenTextureDesc.Width != (UINT)backbufferWidth ||
offscreenTextureDesc.Height != (UINT)backbufferHeight ||
offscreenTextureDesc.Format != backbufferFormatInfo.formatSet.texFormat ||
offscreenTextureDesc.Format != backbufferFormatInfo.formatSet->texFormat ||
offscreenTextureDesc.MipLevels != 1 || offscreenTextureDesc.ArraySize != 1)
{
ERR("Invalid texture parameters in the shared offscreen texture pbuffer");
......@@ -223,7 +223,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe
D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0};
offscreenTextureDesc.Width = backbufferWidth;
offscreenTextureDesc.Height = backbufferHeight;
offscreenTextureDesc.Format = backbufferFormatInfo.formatSet.texFormat;
offscreenTextureDesc.Format = backbufferFormatInfo.formatSet->texFormat;
offscreenTextureDesc.MipLevels = 1;
offscreenTextureDesc.ArraySize = 1;
offscreenTextureDesc.SampleDesc.Count = 1;
......@@ -281,7 +281,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe
mKeyedMutex = d3d11::DynamicCastComObject<IDXGIKeyedMutex>(mOffscreenTexture);
D3D11_RENDER_TARGET_VIEW_DESC offscreenRTVDesc;
offscreenRTVDesc.Format = backbufferFormatInfo.formatSet.rtvFormat;
offscreenRTVDesc.Format = backbufferFormatInfo.formatSet->rtvFormat;
offscreenRTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
offscreenRTVDesc.Texture2D.MipSlice = 0;
......@@ -290,7 +290,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe
d3d11::SetDebugName(mOffscreenRTView, "Offscreen back buffer render target");
D3D11_SHADER_RESOURCE_VIEW_DESC offscreenSRVDesc;
offscreenSRVDesc.Format = backbufferFormatInfo.formatSet.srvFormat;
offscreenSRVDesc.Format = backbufferFormatInfo.formatSet->srvFormat;
offscreenSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
offscreenSRVDesc.Texture2D.MostDetailedMip = 0;
offscreenSRVDesc.Texture2D.MipLevels = static_cast<UINT>(-1);
......@@ -337,7 +337,7 @@ EGLint SwapChain11::resetOffscreenDepthBuffer(int backbufferWidth, int backbuffe
D3D11_TEXTURE2D_DESC depthStencilTextureDesc;
depthStencilTextureDesc.Width = backbufferWidth;
depthStencilTextureDesc.Height = backbufferHeight;
depthStencilTextureDesc.Format = depthBufferFormatInfo.formatSet.texFormat;
depthStencilTextureDesc.Format = depthBufferFormatInfo.formatSet->texFormat;
depthStencilTextureDesc.MipLevels = 1;
depthStencilTextureDesc.ArraySize = 1;
depthStencilTextureDesc.SampleDesc.Count = 1;
......@@ -345,7 +345,7 @@ EGLint SwapChain11::resetOffscreenDepthBuffer(int backbufferWidth, int backbuffe
depthStencilTextureDesc.Usage = D3D11_USAGE_DEFAULT;
depthStencilTextureDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
if (depthBufferFormatInfo.formatSet.srvFormat != DXGI_FORMAT_UNKNOWN)
if (depthBufferFormatInfo.formatSet->srvFormat != DXGI_FORMAT_UNKNOWN)
{
depthStencilTextureDesc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
}
......@@ -373,7 +373,7 @@ EGLint SwapChain11::resetOffscreenDepthBuffer(int backbufferWidth, int backbuffe
d3d11::SetDebugName(mDepthStencilTexture, "Offscreen depth stencil texture");
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilDesc;
depthStencilDesc.Format = depthBufferFormatInfo.formatSet.dsvFormat;
depthStencilDesc.Format = depthBufferFormatInfo.formatSet->dsvFormat;
depthStencilDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
depthStencilDesc.Flags = 0;
depthStencilDesc.Texture2D.MipSlice = 0;
......@@ -382,10 +382,10 @@ EGLint SwapChain11::resetOffscreenDepthBuffer(int backbufferWidth, int backbuffe
ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mDepthStencilDSView, "Offscreen depth stencil view");
if (depthBufferFormatInfo.formatSet.srvFormat != DXGI_FORMAT_UNKNOWN)
if (depthBufferFormatInfo.formatSet->srvFormat != DXGI_FORMAT_UNKNOWN)
{
D3D11_SHADER_RESOURCE_VIEW_DESC depthStencilSRVDesc;
depthStencilSRVDesc.Format = depthBufferFormatInfo.formatSet.srvFormat;
depthStencilSRVDesc.Format = depthBufferFormatInfo.formatSet->srvFormat;
depthStencilSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
depthStencilSRVDesc.Texture2D.MostDetailedMip = 0;
depthStencilSRVDesc.Texture2D.MipLevels = static_cast<UINT>(-1);
......
......@@ -107,8 +107,8 @@ class TextureStorage11 : public TextureStorage
unsigned int mMipLevels;
GLenum mInternalFormat;
d3d11::ANGLEFormatSet mTextureFormatSet;
d3d11::ANGLEFormatSet mSwizzleFormatSet;
const d3d11::ANGLEFormatSet *mTextureFormatSet;
const d3d11::ANGLEFormatSet *mSwizzleFormatSet;
unsigned int mTextureWidth;
unsigned int mTextureHeight;
unsigned int mTextureDepth;
......
......@@ -160,11 +160,11 @@ TextureFormat::TextureFormat(GLenum internalFormat,
InitializeTextureDataFunction internalFormatInitializer)
: dataInitializerFunction(internalFormatInitializer)
{{
formatSet = GetANGLEFormatSet(angleFormat);
swizzleFormatSet = GetANGLEFormatSet(formatSet.swizzleFormat);
formatSet = &GetANGLEFormatSet(angleFormat);
swizzleFormatSet = &GetANGLEFormatSet(formatSet->swizzleFormat);
// Gather all the load functions for this internal format
loadFunctions = GetLoadFunctionsMap(internalFormat, formatSet.texFormat);
loadFunctions = GetLoadFunctionsMap(internalFormat, formatSet->texFormat);
ASSERT(loadFunctions.size() != 0 || internalFormat == GL_NONE);
}}
......
......@@ -358,21 +358,21 @@ static gl::TextureCaps GenerateTextureFormatCaps(GLint maxClientVersion, GLenum
}
}
textureCaps.texturable = support.query(formatInfo.formatSet.texFormat, texSupportMask);
textureCaps.texturable = support.query(formatInfo.formatSet->texFormat, texSupportMask);
textureCaps.filterable =
support.query(formatInfo.formatSet.srvFormat, D3D11_FORMAT_SUPPORT_SHADER_SAMPLE);
support.query(formatInfo.formatSet->srvFormat, D3D11_FORMAT_SUPPORT_SHADER_SAMPLE);
textureCaps.renderable =
(support.query(formatInfo.formatSet.rtvFormat, D3D11_FORMAT_SUPPORT_RENDER_TARGET)) ||
(support.query(formatInfo.formatSet.dsvFormat, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL));
(support.query(formatInfo.formatSet->rtvFormat, D3D11_FORMAT_SUPPORT_RENDER_TARGET)) ||
(support.query(formatInfo.formatSet->dsvFormat, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL));
DXGI_FORMAT renderFormat = DXGI_FORMAT_UNKNOWN;
if (formatInfo.formatSet.dsvFormat != DXGI_FORMAT_UNKNOWN)
if (formatInfo.formatSet->dsvFormat != DXGI_FORMAT_UNKNOWN)
{
renderFormat = formatInfo.formatSet.dsvFormat;
renderFormat = formatInfo.formatSet->dsvFormat;
}
else if (formatInfo.formatSet.rtvFormat != DXGI_FORMAT_UNKNOWN)
else if (formatInfo.formatSet->rtvFormat != DXGI_FORMAT_UNKNOWN)
{
renderFormat = formatInfo.formatSet.rtvFormat;
renderFormat = formatInfo.formatSet->rtvFormat;
}
if (renderFormat != DXGI_FORMAT_UNKNOWN &&
support.query(renderFormat, D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET))
......@@ -1366,7 +1366,7 @@ void GenerateInitialTextureData(GLint internalFormat,
ASSERT(d3dFormatInfo.dataInitializerFunction != NULL);
const d3d11::DXGIFormatSize &dxgiFormatInfo =
d3d11::GetDXGIFormatSizeInfo(d3dFormatInfo.formatSet.texFormat);
d3d11::GetDXGIFormatSizeInfo(d3dFormatInfo.formatSet->texFormat);
outSubresourceData->resize(mipLevels);
outData->resize(mipLevels);
......
......@@ -78,8 +78,8 @@ struct TextureFormat : public angle::NonCopyable
const ANGLEFormat angleFormat,
InitializeTextureDataFunction internalFormatInitializer);
ANGLEFormatSet formatSet;
ANGLEFormatSet swizzleFormatSet;
const ANGLEFormatSet *formatSet;
const ANGLEFormatSet *swizzleFormatSet;
InitializeTextureDataFunction dataInitializerFunction;
typedef std::map<GLenum, LoadImageFunctionInfo> LoadFunctionMap;
......
......@@ -122,11 +122,11 @@ TextureFormat::TextureFormat(GLenum internalFormat,
InitializeTextureDataFunction internalFormatInitializer)
: dataInitializerFunction(internalFormatInitializer)
{
formatSet = GetANGLEFormatSet(angleFormat);
swizzleFormatSet = GetANGLEFormatSet(formatSet.swizzleFormat);
formatSet = &GetANGLEFormatSet(angleFormat);
swizzleFormatSet = &GetANGLEFormatSet(formatSet->swizzleFormat);
// Gather all the load functions for this internal format
loadFunctions = GetLoadFunctionsMap(internalFormat, formatSet.texFormat);
loadFunctions = GetLoadFunctionsMap(internalFormat, formatSet->texFormat);
ASSERT(loadFunctions.size() != 0 || internalFormat == GL_NONE);
}
......
......@@ -65,14 +65,14 @@ TEST_P(D3D11FormatTablesTest, TestFormatSupport)
UINT texSupport;
bool texSuccess =
SUCCEEDED(device->CheckFormatSupport(formatInfo.formatSet.texFormat, &texSupport));
SUCCEEDED(device->CheckFormatSupport(formatInfo.formatSet->texFormat, &texSupport));
bool textureable = texSuccess && ((texSupport & texSupportMask) == texSupportMask);
EXPECT_EQ(textureable, textureInfo.texturable);
// Bits for filtering
UINT filterSupport;
bool filterSuccess =
SUCCEEDED(device->CheckFormatSupport(formatInfo.formatSet.srvFormat, &filterSupport));
SUCCEEDED(device->CheckFormatSupport(formatInfo.formatSet->srvFormat, &filterSupport));
bool filterable = filterSuccess && ((filterSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE) != 0);
EXPECT_EQ(filterable, textureInfo.filterable);
......@@ -82,25 +82,25 @@ TEST_P(D3D11FormatTablesTest, TestFormatSupport)
DXGI_FORMAT renderFormat = DXGI_FORMAT_UNKNOWN;
if (internalFormatInfo.depthBits > 0 || internalFormatInfo.stencilBits > 0)
{
renderFormat = formatInfo.formatSet.dsvFormat;
renderFormat = formatInfo.formatSet->dsvFormat;
bool depthSuccess = SUCCEEDED(
device->CheckFormatSupport(formatInfo.formatSet.dsvFormat, &renderSupport));
device->CheckFormatSupport(formatInfo.formatSet->dsvFormat, &renderSupport));
renderable =
depthSuccess && ((renderSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL) != 0);
if (renderable)
{
EXPECT_NE(DXGI_FORMAT_UNKNOWN, formatInfo.formatSet.dsvFormat);
EXPECT_NE(DXGI_FORMAT_UNKNOWN, formatInfo.formatSet->dsvFormat);
}
}
else
{
renderFormat = formatInfo.formatSet.rtvFormat;
renderFormat = formatInfo.formatSet->rtvFormat;
bool rtSuccess = SUCCEEDED(
device->CheckFormatSupport(formatInfo.formatSet.rtvFormat, &renderSupport));
device->CheckFormatSupport(formatInfo.formatSet->rtvFormat, &renderSupport));
renderable = rtSuccess && ((renderSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET) != 0);
if (renderable)
{
EXPECT_NE(DXGI_FORMAT_UNKNOWN, formatInfo.formatSet.rtvFormat);
EXPECT_NE(DXGI_FORMAT_UNKNOWN, formatInfo.formatSet->rtvFormat);
}
}
EXPECT_EQ(renderable, textureInfo.renderable);
......
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