Image11 now generates multiple mip levels in its staging texture if a lod offset…

Image11 now generates multiple mip levels in its staging texture if a lod offset is required. TextureStorage11::updateSubresourceLevel now takes a subresource index on the source texture and copies to the correct subresource if mLodOffset is non-zero. TRAC #13332 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Geoff Lang git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1972 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent cabb17c5
...@@ -114,13 +114,13 @@ bool Image11::isDirty() const ...@@ -114,13 +114,13 @@ bool Image11::isDirty() const
bool Image11::updateSurface(TextureStorageInterface2D *storage, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height) bool Image11::updateSurface(TextureStorageInterface2D *storage, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height)
{ {
TextureStorage11_2D *storage11 = TextureStorage11_2D::makeTextureStorage11_2D(storage->getStorageInstance()); TextureStorage11_2D *storage11 = TextureStorage11_2D::makeTextureStorage11_2D(storage->getStorageInstance());
return storage11->updateSubresourceLevel(getStagingTexture(), level, 0, xoffset, yoffset, width, height); return storage11->updateSubresourceLevel(getStagingTexture(), getStagingSubresource(), level, 0, xoffset, yoffset, width, height);
} }
bool Image11::updateSurface(TextureStorageInterfaceCube *storage, int face, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height) bool Image11::updateSurface(TextureStorageInterfaceCube *storage, int face, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height)
{ {
TextureStorage11_Cube *storage11 = TextureStorage11_Cube::makeTextureStorage11_Cube(storage->getStorageInstance()); TextureStorage11_Cube *storage11 = TextureStorage11_Cube::makeTextureStorage11_Cube(storage->getStorageInstance());
return storage11->updateSubresourceLevel(getStagingTexture(), level, face, xoffset, yoffset, width, height); return storage11->updateSubresourceLevel(getStagingTexture(), getStagingSubresource(), level, face, xoffset, yoffset, width, height);
} }
bool Image11::redefine(Renderer *renderer, GLint internalformat, GLsizei width, GLsizei height, bool forceRelease) bool Image11::redefine(Renderer *renderer, GLint internalformat, GLsizei width, GLsizei height, bool forceRelease)
...@@ -362,6 +362,13 @@ ID3D11Texture2D *Image11::getStagingTexture() ...@@ -362,6 +362,13 @@ ID3D11Texture2D *Image11::getStagingTexture()
return mStagingTexture; return mStagingTexture;
} }
unsigned int Image11::getStagingSubresource()
{
createStagingTexture();
return mStagingSubresource;
}
void Image11::createStagingTexture() void Image11::createStagingTexture()
{ {
if (mStagingTexture) if (mStagingTexture)
...@@ -370,22 +377,24 @@ void Image11::createStagingTexture() ...@@ -370,22 +377,24 @@ void Image11::createStagingTexture()
} }
ID3D11Texture2D *newTexture = NULL; ID3D11Texture2D *newTexture = NULL;
int lodOffset = 1;
const DXGI_FORMAT dxgiFormat = getDXGIFormat(); const DXGI_FORMAT dxgiFormat = getDXGIFormat();
ASSERT(!d3d11::IsDepthStencilFormat(dxgiFormat)); // We should never get here for depth textures ASSERT(!d3d11::IsDepthStencilFormat(dxgiFormat)); // We should never get here for depth textures
if (mWidth != 0 && mHeight != 0) if (mWidth != 0 && mHeight != 0)
{ {
ID3D11Device *device = mRenderer->getDevice(); GLsizei width = mWidth;
GLsizei height = mHeight;
// Round up the width and height to the nearest multiple of dimension alignment // adjust size if needed for compressed textures
unsigned int dimensionAlignment = d3d11::GetTextureFormatDimensionAlignment(dxgiFormat); gl::MakeValidSize(false, d3d11::IsCompressed(dxgiFormat), &width, &height, &lodOffset);
unsigned int width = mWidth + dimensionAlignment - 1 - (mWidth - 1) % dimensionAlignment; ID3D11Device *device = mRenderer->getDevice();
unsigned int height = mHeight + dimensionAlignment - 1 - (mHeight - 1) % dimensionAlignment;
D3D11_TEXTURE2D_DESC desc; D3D11_TEXTURE2D_DESC desc;
desc.Width = width; desc.Width = width;
desc.Height = height; desc.Height = height;
desc.MipLevels = desc.ArraySize = 1; desc.MipLevels = lodOffset + 1;
desc.ArraySize = 1;
desc.Format = dxgiFormat; desc.Format = dxgiFormat;
desc.SampleDesc.Count = 1; desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0; desc.SampleDesc.Quality = 0;
...@@ -405,6 +414,7 @@ void Image11::createStagingTexture() ...@@ -405,6 +414,7 @@ void Image11::createStagingTexture()
} }
mStagingTexture = newTexture; mStagingTexture = newTexture;
mStagingSubresource = D3D11CalcSubresource(lodOffset, 0, lodOffset + 1);
mDirty = false; mDirty = false;
} }
...@@ -417,7 +427,7 @@ HRESULT Image11::map(D3D11_MAPPED_SUBRESOURCE *map) ...@@ -417,7 +427,7 @@ HRESULT Image11::map(D3D11_MAPPED_SUBRESOURCE *map)
if (mStagingTexture) if (mStagingTexture)
{ {
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
result = deviceContext->Map(mStagingTexture, 0, D3D11_MAP_WRITE, 0, map); result = deviceContext->Map(mStagingTexture, mStagingSubresource, D3D11_MAP_WRITE, 0, map);
// this can fail if the device is removed (from TDR) // this can fail if the device is removed (from TDR)
if (d3d11::isDeviceLostError(result)) if (d3d11::isDeviceLostError(result))
...@@ -438,7 +448,7 @@ void Image11::unmap() ...@@ -438,7 +448,7 @@ void Image11::unmap()
if (mStagingTexture) if (mStagingTexture)
{ {
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
deviceContext->Unmap(mStagingTexture, 0); deviceContext->Unmap(mStagingTexture, mStagingSubresource);
} }
} }
......
...@@ -61,12 +61,14 @@ class Image11 : public Image ...@@ -61,12 +61,14 @@ class Image11 : public Image
DISALLOW_COPY_AND_ASSIGN(Image11); DISALLOW_COPY_AND_ASSIGN(Image11);
ID3D11Texture2D *getStagingTexture(); ID3D11Texture2D *getStagingTexture();
unsigned int getStagingSubresource();
void createStagingTexture(); void createStagingTexture();
Renderer11 *mRenderer; Renderer11 *mRenderer;
DXGI_FORMAT mDXGIFormat; DXGI_FORMAT mDXGIFormat;
ID3D11Texture2D *mStagingTexture; ID3D11Texture2D *mStagingTexture;
unsigned int mStagingSubresource;
}; };
} }
......
...@@ -132,7 +132,9 @@ UINT TextureStorage11::getSubresourceIndex(int level, int faceIndex) ...@@ -132,7 +132,9 @@ UINT TextureStorage11::getSubresourceIndex(int level, int faceIndex)
return index; return index;
} }
bool TextureStorage11::updateSubresourceLevel(ID3D11Texture2D *srcTexture, int level, int face, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height) bool TextureStorage11::updateSubresourceLevel(ID3D11Texture2D *srcTexture, unsigned int sourceSubresource,
int level, int face, GLint xoffset, GLint yoffset,
GLsizei width, GLsizei height)
{ {
if (srcTexture) if (srcTexture)
{ {
...@@ -152,7 +154,8 @@ bool TextureStorage11::updateSubresourceLevel(ID3D11Texture2D *srcTexture, int l ...@@ -152,7 +154,8 @@ bool TextureStorage11::updateSubresourceLevel(ID3D11Texture2D *srcTexture, int l
ID3D11DeviceContext *context = mRenderer->getDeviceContext(); ID3D11DeviceContext *context = mRenderer->getDeviceContext();
ASSERT(getBaseTexture()); ASSERT(getBaseTexture());
context->CopySubresourceRegion(getBaseTexture(), getSubresourceIndex(level, face), xoffset, yoffset, 0, srcTexture, 0, &srcBox); context->CopySubresourceRegion(getBaseTexture(), getSubresourceIndex(level + mLodOffset, face),
xoffset, yoffset, 0, srcTexture, sourceSubresource, &srcBox);
return true; return true;
} }
......
...@@ -50,7 +50,8 @@ class TextureStorage11 : public TextureStorage ...@@ -50,7 +50,8 @@ class TextureStorage11 : public TextureStorage
virtual int levelCount(); virtual int levelCount();
UINT getSubresourceIndex(int level, int faceTarget); UINT getSubresourceIndex(int level, int faceTarget);
bool updateSubresourceLevel(ID3D11Texture2D *texture, int level, int faceTarget, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height); bool updateSubresourceLevel(ID3D11Texture2D *texture, unsigned int sourceSubresource, int level,
int faceTarget, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
protected: protected:
void generateMipmapLayer(RenderTarget11 *source, RenderTarget11 *dest); void generateMipmapLayer(RenderTarget11 *source, RenderTarget11 *dest);
......
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