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)
if (formatInfo.dataInitializerFunction != nullptr)
{
std::vector<D3D11_SUBRESOURCE_DATA> initialData;
std::vector<std::vector<BYTE>> textureData;
d3d11::GenerateInitialTextureData(
mInternalFormat, mRenderer->getRenderer11DeviceCaps(), width, height, mDepth,
lodOffset + 1, &initialData, &textureData);
gl::TexLevelArray<D3D11_SUBRESOURCE_DATA> initialData;
ANGLE_TRY(d3d11::GenerateInitialTextureData(
context, mInternalFormat, mRenderer->getRenderer11DeviceCaps(), width, height,
mDepth, lodOffset + 1, &initialData));
ANGLE_TRY(mRenderer->allocateTexture(desc, formatInfo, initialData.data(),
&mStagingTexture));
......@@ -599,11 +598,10 @@ gl::Error Image11::createStagingTexture(const gl::Context *context)
if (formatInfo.dataInitializerFunction != nullptr)
{
std::vector<D3D11_SUBRESOURCE_DATA> initialData;
std::vector<std::vector<BYTE>> textureData;
d3d11::GenerateInitialTextureData(
mInternalFormat, mRenderer->getRenderer11DeviceCaps(), width, height, 1,
lodOffset + 1, &initialData, &textureData);
gl::TexLevelArray<D3D11_SUBRESOURCE_DATA> initialData;
ANGLE_TRY(d3d11::GenerateInitialTextureData(
context, mInternalFormat, mRenderer->getRenderer11DeviceCaps(), width, height,
1, lodOffset + 1, &initialData));
ANGLE_TRY(mRenderer->allocateTexture(desc, formatInfo, initialData.data(),
&mStagingTexture));
......
......@@ -2030,14 +2030,14 @@ void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsi
}
}
void GenerateInitialTextureData(GLint internalFormat,
const Renderer11DeviceCaps &renderer11DeviceCaps,
GLuint width,
GLuint height,
GLuint depth,
GLuint mipLevels,
std::vector<D3D11_SUBRESOURCE_DATA> *outSubresourceData,
std::vector<std::vector<BYTE>> *outData)
gl::Error GenerateInitialTextureData(const gl::Context *context,
GLint internalFormat,
const Renderer11DeviceCaps &renderer11DeviceCaps,
GLuint width,
GLuint height,
GLuint depth,
GLuint mipLevels,
gl::TexLevelArray<D3D11_SUBRESOURCE_DATA> *outSubresourceData)
{
const d3d11::Format &d3dFormatInfo = d3d11::Format::Get(internalFormat, renderer11DeviceCaps);
ASSERT(d3dFormatInfo.dataInitializerFunction != nullptr);
......@@ -2045,25 +2045,30 @@ void GenerateInitialTextureData(GLint internalFormat,
const d3d11::DXGIFormatSize &dxgiFormatInfo =
d3d11::GetDXGIFormatSizeInfo(d3dFormatInfo.texFormat);
outSubresourceData->resize(mipLevels);
outData->resize(mipLevels);
unsigned int rowPitch = dxgiFormatInfo.pixelBytes * width;
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++)
{
unsigned int mipWidth = std::max(width >> 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);
d3dFormatInfo.dataInitializerFunction(mipWidth, mipHeight, mipDepth, outData->at(i).data(), rowWidth, imageSize);
unsigned int mipRowPitch = dxgiFormatInfo.pixelBytes * mipWidth;
unsigned int mipDepthPitch = mipRowPitch * mipHeight;
outSubresourceData->at(i).pSysMem = outData->at(i).data();
outSubresourceData->at(i).SysMemPitch = rowWidth;
outSubresourceData->at(i).SysMemSlicePitch = imageSize;
outSubresourceData->at(i).pSysMem = scratchBuffer->data();
outSubresourceData->at(i).SysMemPitch = mipRowPitch;
outSubresourceData->at(i).SysMemSlicePitch = mipDepthPitch;
}
return gl::NoError();
}
UINT GetPrimitiveRestartIndex()
......
......@@ -97,14 +97,14 @@ ANGLED3D11DeviceType GetDeviceType(ID3D11Device *device);
void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset);
void GenerateInitialTextureData(GLint internalFormat,
const Renderer11DeviceCaps &renderer11DeviceCaps,
GLuint width,
GLuint height,
GLuint depth,
GLuint mipLevels,
std::vector<D3D11_SUBRESOURCE_DATA> *outSubresourceData,
std::vector<std::vector<BYTE>> *outData);
gl::Error GenerateInitialTextureData(const gl::Context *context,
GLint internalFormat,
const Renderer11DeviceCaps &renderer11DeviceCaps,
GLuint width,
GLuint height,
GLuint depth,
GLuint mipLevels,
gl::TexLevelArray<D3D11_SUBRESOURCE_DATA> *outSubresourceData);
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