Commit 9cf9bcbe by Matt Woodrow Committed by Geoff Lang

Avoid a copy in TextureStorage11::setData

This code always allocates a new memory buffer for the texture memory, picks a load function to copy/convert the input data into it, and the uploads. In the case where the input format matches the upload format we should be able to skip the allocation and copy and be much happier. Change-Id: I8b8c106e0d397bef1c4bcfdb0df60669030776a3 Reviewed-on: https://chromium-review.googlesource.com/293742Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org> Tryjob-Request: Geoff Lang <geofflang@chromium.org>
parent 934cd2e5
...@@ -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
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());
LoadImageFunction loadFunction = d3dFormatInfo.loadFunctions.at(type); LoadImageFunction loadFunction = d3dFormatInfo.loadFunctions.at(type).loadFunction;
D3D11_MAPPED_SUBRESOURCE mappedImage; D3D11_MAPPED_SUBRESOURCE mappedImage;
gl::Error error = map(D3D11_MAP_WRITE, &mappedImage); gl::Error error = map(D3D11_MAP_WRITE, &mappedImage);
...@@ -286,7 +286,7 @@ gl::Error Image11::loadCompressedData(const gl::Box &area, const void *input) ...@@ -286,7 +286,7 @@ gl::Error Image11::loadCompressedData(const gl::Box &area, const void *input)
ASSERT(area.y % outputBlockHeight == 0); ASSERT(area.y % outputBlockHeight == 0);
const d3d11::TextureFormat &d3dFormatInfo = d3d11::GetTextureFormatInfo(mInternalFormat, mRenderer->getRenderer11DeviceCaps()); const d3d11::TextureFormat &d3dFormatInfo = d3d11::GetTextureFormatInfo(mInternalFormat, mRenderer->getRenderer11DeviceCaps());
LoadImageFunction loadFunction = d3dFormatInfo.loadFunctions.at(GL_UNSIGNED_BYTE); LoadImageFunction loadFunction = d3dFormatInfo.loadFunctions.at(GL_UNSIGNED_BYTE).loadFunction;
D3D11_MAPPED_SUBRESOURCE mappedImage; D3D11_MAPPED_SUBRESOURCE mappedImage;
gl::Error error = map(D3D11_MAP_WRITE, &mappedImage); gl::Error error = map(D3D11_MAP_WRITE, &mappedImage);
......
...@@ -657,18 +657,28 @@ gl::Error TextureStorage11::setData(const gl::ImageIndex &index, ImageD3D *image ...@@ -657,18 +657,28 @@ gl::Error TextureStorage11::setData(const gl::ImageIndex &index, ImageD3D *image
UINT bufferDepthPitch = bufferRowPitch * height; UINT bufferDepthPitch = bufferRowPitch * height;
size_t neededSize = bufferDepthPitch * depth; size_t neededSize = bufferDepthPitch * depth;
MemoryBuffer *conversionBuffer = NULL; MemoryBuffer *conversionBuffer = nullptr;
error = mRenderer->getScratchMemoryBuffer(neededSize, &conversionBuffer); const uint8_t *data = nullptr;
if (error.isError())
d3d11::LoadImageFunctionInfo loadFunctionInfo = d3d11Format.loadFunctions.at(type);
if (loadFunctionInfo.requiresConversion)
{ {
return error; error = mRenderer->getScratchMemoryBuffer(neededSize, &conversionBuffer);
} if (error.isError())
{
return error;
}
// TODO: fast path loadFunctionInfo.loadFunction(width, height, depth, pixelData, srcRowPitch, srcDepthPitch,
LoadImageFunction loadFunction = d3d11Format.loadFunctions.at(type); conversionBuffer->data(), bufferRowPitch, bufferDepthPitch);
loadFunction(width, height, depth, data = conversionBuffer->data();
pixelData, srcRowPitch, srcDepthPitch, }
conversionBuffer->data(), bufferRowPitch, bufferDepthPitch); else
{
data = pixelData;
bufferRowPitch = srcRowPitch;
bufferDepthPitch = srcDepthPitch;
}
ID3D11DeviceContext *immediateContext = mRenderer->getDeviceContext(); ID3D11DeviceContext *immediateContext = mRenderer->getDeviceContext();
...@@ -684,15 +694,13 @@ gl::Error TextureStorage11::setData(const gl::ImageIndex &index, ImageD3D *image ...@@ -684,15 +694,13 @@ gl::Error TextureStorage11::setData(const gl::ImageIndex &index, ImageD3D *image
destD3DBox.front = destBox->z; destD3DBox.front = destBox->z;
destD3DBox.back = destBox->z + destBox->depth; destD3DBox.back = destBox->z + destBox->depth;
immediateContext->UpdateSubresource(resource, destSubresource, immediateContext->UpdateSubresource(resource, destSubresource, &destD3DBox, data,
&destD3DBox, conversionBuffer->data(),
bufferRowPitch, bufferDepthPitch); bufferRowPitch, bufferDepthPitch);
} }
else else
{ {
immediateContext->UpdateSubresource(resource, destSubresource, immediateContext->UpdateSubresource(resource, destSubresource, NULL, data, bufferRowPitch,
NULL, conversionBuffer->data(), bufferDepthPitch);
bufferRowPitch, bufferDepthPitch);
} }
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
......
...@@ -60,6 +60,17 @@ struct DXGIFormat ...@@ -60,6 +60,17 @@ struct DXGIFormat
}; };
const DXGIFormat &GetDXGIFormatInfo(DXGI_FORMAT format); const DXGIFormat &GetDXGIFormatInfo(DXGI_FORMAT format);
struct LoadImageFunctionInfo
{
LoadImageFunctionInfo(LoadImageFunction loadFunction, bool requiresConversion)
: loadFunction(loadFunction), requiresConversion(requiresConversion)
{
}
LoadImageFunction loadFunction;
bool requiresConversion;
};
struct TextureFormat struct TextureFormat
{ {
TextureFormat(); TextureFormat();
...@@ -76,7 +87,7 @@ struct TextureFormat ...@@ -76,7 +87,7 @@ struct TextureFormat
InitializeTextureDataFunction dataInitializerFunction; InitializeTextureDataFunction dataInitializerFunction;
typedef std::map<GLenum, LoadImageFunction> LoadFunctionMap; typedef std::map<GLenum, LoadImageFunctionInfo> LoadFunctionMap;
LoadFunctionMap loadFunctions; LoadFunctionMap loadFunctions;
}; };
const TextureFormat &GetTextureFormatInfo(GLenum internalFormat, const Renderer11DeviceCaps &renderer11DeviceCaps); const TextureFormat &GetTextureFormatInfo(GLenum internalFormat, const Renderer11DeviceCaps &renderer11DeviceCaps);
......
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