Commit bb22f3d9 by Jamie Madill Committed by Commit Bot

D3D11: Reduce allocations in GenerateInitialTextureData.

We can re-use the same info for each level of the texture. Also use fixed sized arrays for the subresource data structure. Bug: chromium:867089 Change-Id: Ie43886f708d1141fb80d30a78cabdd37dfbf6f94 Reviewed-on: https://chromium-review.googlesource.com/1149082Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 6e909ef2
...@@ -561,11 +561,10 @@ gl::Error Image11::createStagingTexture(const gl::Context *context) ...@@ -561,11 +561,10 @@ gl::Error Image11::createStagingTexture(const gl::Context *context)
if (formatInfo.dataInitializerFunction != nullptr) if (formatInfo.dataInitializerFunction != nullptr)
{ {
std::vector<D3D11_SUBRESOURCE_DATA> initialData; gl::TexLevelArray<D3D11_SUBRESOURCE_DATA> initialData;
std::vector<std::vector<BYTE>> textureData; ANGLE_TRY(d3d11::GenerateInitialTextureData(
d3d11::GenerateInitialTextureData( context, mInternalFormat, mRenderer->getRenderer11DeviceCaps(), width, height,
mInternalFormat, mRenderer->getRenderer11DeviceCaps(), width, height, mDepth, mDepth, lodOffset + 1, &initialData));
lodOffset + 1, &initialData, &textureData);
ANGLE_TRY(mRenderer->allocateTexture(desc, formatInfo, initialData.data(), ANGLE_TRY(mRenderer->allocateTexture(desc, formatInfo, initialData.data(),
&mStagingTexture)); &mStagingTexture));
...@@ -599,11 +598,10 @@ gl::Error Image11::createStagingTexture(const gl::Context *context) ...@@ -599,11 +598,10 @@ gl::Error Image11::createStagingTexture(const gl::Context *context)
if (formatInfo.dataInitializerFunction != nullptr) if (formatInfo.dataInitializerFunction != nullptr)
{ {
std::vector<D3D11_SUBRESOURCE_DATA> initialData; gl::TexLevelArray<D3D11_SUBRESOURCE_DATA> initialData;
std::vector<std::vector<BYTE>> textureData; ANGLE_TRY(d3d11::GenerateInitialTextureData(
d3d11::GenerateInitialTextureData( context, mInternalFormat, mRenderer->getRenderer11DeviceCaps(), width, height,
mInternalFormat, mRenderer->getRenderer11DeviceCaps(), width, height, 1, 1, lodOffset + 1, &initialData));
lodOffset + 1, &initialData, &textureData);
ANGLE_TRY(mRenderer->allocateTexture(desc, formatInfo, initialData.data(), ANGLE_TRY(mRenderer->allocateTexture(desc, formatInfo, initialData.data(),
&mStagingTexture)); &mStagingTexture));
......
...@@ -2030,14 +2030,14 @@ void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsi ...@@ -2030,14 +2030,14 @@ void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsi
} }
} }
void GenerateInitialTextureData(GLint internalFormat, gl::Error GenerateInitialTextureData(const gl::Context *context,
const Renderer11DeviceCaps &renderer11DeviceCaps, GLint internalFormat,
GLuint width, const Renderer11DeviceCaps &renderer11DeviceCaps,
GLuint height, GLuint width,
GLuint depth, GLuint height,
GLuint mipLevels, GLuint depth,
std::vector<D3D11_SUBRESOURCE_DATA> *outSubresourceData, GLuint mipLevels,
std::vector<std::vector<BYTE>> *outData) gl::TexLevelArray<D3D11_SUBRESOURCE_DATA> *outSubresourceData)
{ {
const d3d11::Format &d3dFormatInfo = d3d11::Format::Get(internalFormat, renderer11DeviceCaps); const d3d11::Format &d3dFormatInfo = d3d11::Format::Get(internalFormat, renderer11DeviceCaps);
ASSERT(d3dFormatInfo.dataInitializerFunction != nullptr); ASSERT(d3dFormatInfo.dataInitializerFunction != nullptr);
...@@ -2045,25 +2045,30 @@ void GenerateInitialTextureData(GLint internalFormat, ...@@ -2045,25 +2045,30 @@ void GenerateInitialTextureData(GLint internalFormat,
const d3d11::DXGIFormatSize &dxgiFormatInfo = const d3d11::DXGIFormatSize &dxgiFormatInfo =
d3d11::GetDXGIFormatSizeInfo(d3dFormatInfo.texFormat); d3d11::GetDXGIFormatSizeInfo(d3dFormatInfo.texFormat);
outSubresourceData->resize(mipLevels); unsigned int rowPitch = dxgiFormatInfo.pixelBytes * width;
outData->resize(mipLevels); unsigned int depthPitch = rowPitch * height;
unsigned int maxImageSize = depthPitch * depth;
angle::MemoryBuffer *scratchBuffer = nullptr;
ANGLE_TRY_ALLOCATION(context->getScratchBuffer(maxImageSize, &scratchBuffer));
d3dFormatInfo.dataInitializerFunction(width, height, depth, scratchBuffer->data(), rowPitch,
depthPitch);
for (unsigned int i = 0; i < mipLevels; i++) for (unsigned int i = 0; i < mipLevels; i++)
{ {
unsigned int mipWidth = std::max(width >> i, 1U); unsigned int mipWidth = std::max(width >> i, 1U);
unsigned int mipHeight = std::max(height >> i, 1U); unsigned int mipHeight = std::max(height >> i, 1U);
unsigned int mipDepth = std::max(depth >> i, 1U);
unsigned int rowWidth = dxgiFormatInfo.pixelBytes * mipWidth;
unsigned int imageSize = rowWidth * height;
outData->at(i).resize(rowWidth * mipHeight * mipDepth); unsigned int mipRowPitch = dxgiFormatInfo.pixelBytes * mipWidth;
d3dFormatInfo.dataInitializerFunction(mipWidth, mipHeight, mipDepth, outData->at(i).data(), rowWidth, imageSize); unsigned int mipDepthPitch = mipRowPitch * mipHeight;
outSubresourceData->at(i).pSysMem = outData->at(i).data(); outSubresourceData->at(i).pSysMem = scratchBuffer->data();
outSubresourceData->at(i).SysMemPitch = rowWidth; outSubresourceData->at(i).SysMemPitch = mipRowPitch;
outSubresourceData->at(i).SysMemSlicePitch = imageSize; outSubresourceData->at(i).SysMemSlicePitch = mipDepthPitch;
} }
return gl::NoError();
} }
UINT GetPrimitiveRestartIndex() UINT GetPrimitiveRestartIndex()
......
...@@ -97,14 +97,14 @@ ANGLED3D11DeviceType GetDeviceType(ID3D11Device *device); ...@@ -97,14 +97,14 @@ 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);
void GenerateInitialTextureData(GLint internalFormat, gl::Error GenerateInitialTextureData(const gl::Context *context,
const Renderer11DeviceCaps &renderer11DeviceCaps, GLint internalFormat,
GLuint width, const Renderer11DeviceCaps &renderer11DeviceCaps,
GLuint height, GLuint width,
GLuint depth, GLuint height,
GLuint mipLevels, GLuint depth,
std::vector<D3D11_SUBRESOURCE_DATA> *outSubresourceData, GLuint mipLevels,
std::vector<std::vector<BYTE>> *outData); gl::TexLevelArray<D3D11_SUBRESOURCE_DATA> *outSubresourceData);
UINT GetPrimitiveRestartIndex(); UINT GetPrimitiveRestartIndex();
......
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