Commit 5733801a by Jamie Madill Committed by Commit Bot

D3D11: Refactor depth/stencil blit code.

Blit11 refactorings enable re-using some code for multisample resolve blits. Also some Renderer11 refactorings to use TextureHelper11 make the code more flexible for the multisample resolve, to come later. BUG=angleproject:1246 Change-Id: Id0c168cef75b0f487cb3995a906f6473989edcd5 Reviewed-on: https://chromium-review.googlesource.com/354420Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 82a468af
...@@ -42,18 +42,38 @@ class Blit11 : angle::NonCopyable ...@@ -42,18 +42,38 @@ class Blit11 : angle::NonCopyable
GLenum filter, GLenum filter,
bool maskOffAlpha); bool maskOffAlpha);
gl::Error copyStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize, gl::Error copyStencil(const TextureHelper11 &source,
ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize, unsigned int sourceSubresource,
const gl::Box &sourceArea,
const gl::Extents &sourceSize,
const TextureHelper11 &dest,
unsigned int destSubresource,
const gl::Box &destArea,
const gl::Extents &destSize,
const gl::Rectangle *scissor); const gl::Rectangle *scissor);
gl::Error copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sourceArea, const gl::Extents &sourceSize, gl::Error copyDepth(ID3D11ShaderResourceView *source,
ID3D11DepthStencilView *dest, const gl::Box &destArea, const gl::Extents &destSize, const gl::Box &sourceArea,
const gl::Extents &sourceSize,
ID3D11DepthStencilView *dest,
const gl::Box &destArea,
const gl::Extents &destSize,
const gl::Rectangle *scissor); const gl::Rectangle *scissor);
gl::Error copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize, gl::Error copyDepthStencil(const TextureHelper11 &source,
ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize, unsigned int sourceSubresource,
const gl::Box &sourceArea,
const gl::Extents &sourceSize,
const TextureHelper11 &dest,
unsigned int destSubresource,
const gl::Box &destArea,
const gl::Extents &destSize,
const gl::Rectangle *scissor); const gl::Rectangle *scissor);
gl::ErrorOrResult<TextureHelper11> resolveDepthStencil(RenderTarget11 *dsRenderTarget,
bool resolveDepth,
bool resolveStencil);
private: private:
enum BlitShaderType enum BlitShaderType
{ {
...@@ -109,9 +129,13 @@ class Blit11 : angle::NonCopyable ...@@ -109,9 +129,13 @@ class Blit11 : angle::NonCopyable
SWIZZLESHADER_ARRAY_INT, SWIZZLESHADER_ARRAY_INT,
}; };
typedef void (*WriteVertexFunction)(const gl::Box &sourceArea, const gl::Extents &sourceSize, typedef void (*WriteVertexFunction)(const gl::Box &sourceArea,
const gl::Box &destArea, const gl::Extents &destSize, const gl::Extents &sourceSize,
void *outVertices, unsigned int *outStride, unsigned int *outVertexCount, const gl::Box &destArea,
const gl::Extents &destSize,
void *outVertices,
unsigned int *outStride,
unsigned int *outVertexCount,
D3D11_PRIMITIVE_TOPOLOGY *outTopology); D3D11_PRIMITIVE_TOPOLOGY *outTopology);
enum ShaderDimension enum ShaderDimension
...@@ -139,19 +163,67 @@ class Blit11 : angle::NonCopyable ...@@ -139,19 +163,67 @@ class Blit11 : angle::NonCopyable
ShaderSupport getShaderSupport(const Shader &shader); ShaderSupport getShaderSupport(const Shader &shader);
static BlitShaderType GetBlitShaderType(GLenum destinationFormat, bool isSigned, ShaderDimension dimension); static BlitShaderType GetBlitShaderType(GLenum destinationFormat,
bool isSigned,
ShaderDimension dimension);
static SwizzleShaderType GetSwizzleShaderType(GLenum type, D3D11_SRV_DIMENSION dimensionality); static SwizzleShaderType GetSwizzleShaderType(GLenum type, D3D11_SRV_DIMENSION dimensionality);
gl::Error copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize, typedef void BlitConvertFunction(const gl::Box &sourceArea,
ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize, const gl::Box &destArea,
const gl::Rectangle *scissor, bool stencilOnly); const gl::Rectangle &clipRect,
const gl::Extents &sourceSize,
void addBlitShaderToMap(BlitShaderType blitShaderType, ShaderDimension dimension, ID3D11PixelShader *ps); unsigned int sourceRowPitch,
unsigned int destRowPitch,
gl::Error getBlitShader(GLenum destFormat, bool isSigned, ShaderDimension dimension, const Shader **shaderOut); ptrdiff_t readOffset,
gl::Error getSwizzleShader(GLenum type, D3D11_SRV_DIMENSION viewDimension, const Shader **shaderOut); ptrdiff_t writeOffset,
size_t copySize,
void addSwizzleShaderToMap(SwizzleShaderType swizzleShaderType, ShaderDimension dimension, ID3D11PixelShader *ps); size_t srcPixelStride,
size_t destPixelStride,
const uint8_t *sourceData,
uint8_t *destData);
gl::Error copyDepthStencilImpl(const TextureHelper11 &source,
unsigned int sourceSubresource,
const gl::Box &sourceArea,
const gl::Extents &sourceSize,
const TextureHelper11 &dest,
unsigned int destSubresource,
const gl::Box &destArea,
const gl::Extents &destSize,
const gl::Rectangle *scissor,
bool stencilOnly);
gl::Error copyAndConvert(const TextureHelper11 &source,
unsigned int sourceSubresource,
const gl::Box &sourceArea,
const gl::Extents &sourceSize,
const TextureHelper11 &dest,
unsigned int destSubresource,
const gl::Box &destArea,
const gl::Extents &destSize,
const gl::Rectangle *scissor,
size_t readOffset,
size_t writeOffset,
size_t copySize,
size_t srcPixelStride,
size_t destPixelStride,
BlitConvertFunction *convertFunction);
void addBlitShaderToMap(BlitShaderType blitShaderType,
ShaderDimension dimension,
ID3D11PixelShader *ps);
gl::Error getBlitShader(GLenum destFormat,
bool isSigned,
ShaderDimension dimension,
const Shader **shaderOut);
gl::Error getSwizzleShader(GLenum type,
D3D11_SRV_DIMENSION viewDimension,
const Shader **shaderOut);
void addSwizzleShaderToMap(SwizzleShaderType swizzleShaderType,
ShaderDimension dimension,
ID3D11PixelShader *ps);
void clearShaderMap(); void clearShaderMap();
...@@ -181,6 +253,6 @@ class Blit11 : angle::NonCopyable ...@@ -181,6 +253,6 @@ class Blit11 : angle::NonCopyable
ID3D11Buffer *mSwizzleCB; ID3D11Buffer *mSwizzleCB;
}; };
} } // namespace rx
#endif // LIBANGLE_RENDERER_D3D_D3D11_BLIT11_H_ #endif // LIBANGLE_RENDERER_D3D_D3D11_BLIT11_H_
...@@ -1332,10 +1332,10 @@ gl::Error Buffer11::PackStorage::packPixels(const gl::FramebufferAttachment &rea ...@@ -1332,10 +1332,10 @@ gl::Error Buffer11::PackStorage::packPixels(const gl::FramebufferAttachment &rea
if (!mStagingTexture.getResource() || mStagingTexture.getFormat() != srcTexture.getFormat() || if (!mStagingTexture.getResource() || mStagingTexture.getFormat() != srcTexture.getFormat() ||
mStagingTexture.getExtents() != srcTextureSize) mStagingTexture.getExtents() != srcTextureSize)
{ {
ANGLE_TRY_RESULT(CreateStagingTexture(srcTexture.getTextureType(), srcTexture.getFormat(), ANGLE_TRY_RESULT(
srcTexture.getANGLEFormat(), srcTextureSize, CreateStagingTexture(srcTexture.getTextureType(), srcTexture.getANGLEFormat(),
mRenderer->getDevice()), srcTextureSize, StagingAccess::READ, mRenderer->getDevice()),
mStagingTexture); mStagingTexture);
} }
// ReadPixels from multisampled FBOs isn't supported in current GL // ReadPixels from multisampled FBOs isn't supported in current GL
......
...@@ -382,7 +382,9 @@ class Renderer11 : public RendererD3D ...@@ -382,7 +382,9 @@ class Renderer11 : public RendererD3D
gl::Error generateSwizzles(const gl::ContextState &data, gl::SamplerType type); gl::Error generateSwizzles(const gl::ContextState &data, gl::SamplerType type);
gl::Error generateSwizzles(const gl::ContextState &data); gl::Error generateSwizzles(const gl::ContextState &data);
ID3D11Texture2D *resolveMultisampledTexture(ID3D11Texture2D *source, unsigned int subresource); gl::ErrorOrResult<TextureHelper11> resolveMultisampledTexture(RenderTarget11 *renderTarget,
bool depth,
bool stencil);
void populateRenderer11DeviceCaps(); void populateRenderer11DeviceCaps();
......
...@@ -408,22 +408,16 @@ gl::Error TextureStorage11::updateSubresourceLevel(ID3D11Resource *srcTexture, ...@@ -408,22 +408,16 @@ gl::Error TextureStorage11::updateSubresourceLevel(ID3D11Resource *srcTexture,
copyArea.depth == texSize.depth; copyArea.depth == texSize.depth;
ID3D11Resource *dstTexture = nullptr; ID3D11Resource *dstTexture = nullptr;
gl::Error error(GL_NO_ERROR);
// If the zero-LOD workaround is active and we want to update a level greater than zero, then we // If the zero-LOD workaround is active and we want to update a level greater than zero, then we
// should update the mipmapped texture, even if mapmaps are currently disabled. // should update the mipmapped texture, even if mapmaps are currently disabled.
if (index.mipIndex > 0 && mRenderer->getWorkarounds().zeroMaxLodWorkaround) if (index.mipIndex > 0 && mRenderer->getWorkarounds().zeroMaxLodWorkaround)
{ {
error = getMippedResource(&dstTexture); ANGLE_TRY(getMippedResource(&dstTexture));
} }
else else
{ {
error = getResource(&dstTexture); ANGLE_TRY(getResource(&dstTexture));
}
if (error.isError())
{
return error;
} }
unsigned int dstSubresource = getSubresourceIndex(index); unsigned int dstSubresource = getSubresourceIndex(index);
...@@ -436,29 +430,27 @@ gl::Error TextureStorage11::updateSubresourceLevel(ID3D11Resource *srcTexture, ...@@ -436,29 +430,27 @@ gl::Error TextureStorage11::updateSubresourceLevel(ID3D11Resource *srcTexture,
{ {
// CopySubresourceRegion cannot copy partial depth stencils, use the blitter instead // CopySubresourceRegion cannot copy partial depth stencils, use the blitter instead
Blit11 *blitter = mRenderer->getBlitter(); Blit11 *blitter = mRenderer->getBlitter();
TextureHelper11 source = TextureHelper11::MakeAndReference(srcTexture, getANGLEFormat());
return blitter->copyDepthStencil(srcTexture, sourceSubresource, copyArea, texSize, TextureHelper11 dest = TextureHelper11::MakeAndReference(dstTexture, getANGLEFormat());
dstTexture, dstSubresource, copyArea, texSize, nullptr); return blitter->copyDepthStencil(source, sourceSubresource, copyArea, texSize, dest,
} dstSubresource, copyArea, texSize, nullptr);
else
{
D3D11_BOX srcBox;
srcBox.left = copyArea.x;
srcBox.top = copyArea.y;
srcBox.right =
copyArea.x + roundUp(static_cast<UINT>(copyArea.width), dxgiFormatSizeInfo.blockWidth);
srcBox.bottom = copyArea.y +
roundUp(static_cast<UINT>(copyArea.height), dxgiFormatSizeInfo.blockHeight);
srcBox.front = copyArea.z;
srcBox.back = copyArea.z + copyArea.depth;
ID3D11DeviceContext *context = mRenderer->getDeviceContext();
context->CopySubresourceRegion(dstTexture, dstSubresource, copyArea.x, copyArea.y,
copyArea.z, srcTexture, sourceSubresource,
fullCopy ? nullptr : &srcBox);
return gl::Error(GL_NO_ERROR);
} }
D3D11_BOX srcBox;
srcBox.left = copyArea.x;
srcBox.top = copyArea.y;
srcBox.right =
copyArea.x + roundUp(static_cast<UINT>(copyArea.width), dxgiFormatSizeInfo.blockWidth);
srcBox.bottom =
copyArea.y + roundUp(static_cast<UINT>(copyArea.height), dxgiFormatSizeInfo.blockHeight);
srcBox.front = copyArea.z;
srcBox.back = copyArea.z + copyArea.depth;
ID3D11DeviceContext *context = mRenderer->getDeviceContext();
context->CopySubresourceRegion(dstTexture, dstSubresource, copyArea.x, copyArea.y, copyArea.z,
srcTexture, sourceSubresource, fullCopy ? nullptr : &srcBox);
return gl::NoError();
} }
gl::Error TextureStorage11::copySubresourceLevel(ID3D11Resource *dstTexture, gl::Error TextureStorage11::copySubresourceLevel(ID3D11Resource *dstTexture,
......
...@@ -1658,11 +1658,13 @@ void TextureHelper11::reset() ...@@ -1658,11 +1658,13 @@ void TextureHelper11::reset()
} }
gl::ErrorOrResult<TextureHelper11> CreateStagingTexture(GLenum textureType, gl::ErrorOrResult<TextureHelper11> CreateStagingTexture(GLenum textureType,
DXGI_FORMAT dxgiFormat,
d3d11::ANGLEFormat angleFormat, d3d11::ANGLEFormat angleFormat,
const gl::Extents &size, const gl::Extents &size,
StagingAccess readAndWriteAccess,
ID3D11Device *device) ID3D11Device *device)
{ {
const auto &formatSet = d3d11::GetANGLEFormatSet(angleFormat);
if (textureType == GL_TEXTURE_2D) if (textureType == GL_TEXTURE_2D)
{ {
D3D11_TEXTURE2D_DESC stagingDesc; D3D11_TEXTURE2D_DESC stagingDesc;
...@@ -1670,7 +1672,7 @@ gl::ErrorOrResult<TextureHelper11> CreateStagingTexture(GLenum textureType, ...@@ -1670,7 +1672,7 @@ gl::ErrorOrResult<TextureHelper11> CreateStagingTexture(GLenum textureType,
stagingDesc.Height = size.height; stagingDesc.Height = size.height;
stagingDesc.MipLevels = 1; stagingDesc.MipLevels = 1;
stagingDesc.ArraySize = 1; stagingDesc.ArraySize = 1;
stagingDesc.Format = dxgiFormat; stagingDesc.Format = formatSet.texFormat;
stagingDesc.SampleDesc.Count = 1; stagingDesc.SampleDesc.Count = 1;
stagingDesc.SampleDesc.Quality = 0; stagingDesc.SampleDesc.Quality = 0;
stagingDesc.Usage = D3D11_USAGE_STAGING; stagingDesc.Usage = D3D11_USAGE_STAGING;
...@@ -1678,6 +1680,11 @@ gl::ErrorOrResult<TextureHelper11> CreateStagingTexture(GLenum textureType, ...@@ -1678,6 +1680,11 @@ gl::ErrorOrResult<TextureHelper11> CreateStagingTexture(GLenum textureType,
stagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; stagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
stagingDesc.MiscFlags = 0; stagingDesc.MiscFlags = 0;
if (readAndWriteAccess == StagingAccess::READ_WRITE)
{
stagingDesc.CPUAccessFlags |= D3D11_CPU_ACCESS_WRITE;
}
ID3D11Texture2D *stagingTex = nullptr; ID3D11Texture2D *stagingTex = nullptr;
HRESULT result = device->CreateTexture2D(&stagingDesc, nullptr, &stagingTex); HRESULT result = device->CreateTexture2D(&stagingDesc, nullptr, &stagingTex);
if (FAILED(result)) if (FAILED(result))
...@@ -1695,7 +1702,7 @@ gl::ErrorOrResult<TextureHelper11> CreateStagingTexture(GLenum textureType, ...@@ -1695,7 +1702,7 @@ gl::ErrorOrResult<TextureHelper11> CreateStagingTexture(GLenum textureType,
stagingDesc.Height = size.height; stagingDesc.Height = size.height;
stagingDesc.Depth = 1; stagingDesc.Depth = 1;
stagingDesc.MipLevels = 1; stagingDesc.MipLevels = 1;
stagingDesc.Format = dxgiFormat; stagingDesc.Format = formatSet.texFormat;
stagingDesc.Usage = D3D11_USAGE_STAGING; stagingDesc.Usage = D3D11_USAGE_STAGING;
stagingDesc.BindFlags = 0; stagingDesc.BindFlags = 0;
stagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; stagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
......
...@@ -396,10 +396,16 @@ class TextureHelper11 : angle::NonCopyable ...@@ -396,10 +396,16 @@ class TextureHelper11 : angle::NonCopyable
ID3D11Texture3D *mTexture3D; ID3D11Texture3D *mTexture3D;
}; };
enum class StagingAccess
{
READ,
READ_WRITE,
};
gl::ErrorOrResult<TextureHelper11> CreateStagingTexture(GLenum textureType, gl::ErrorOrResult<TextureHelper11> CreateStagingTexture(GLenum textureType,
DXGI_FORMAT dxgiFormat,
d3d11::ANGLEFormat angleFormat, d3d11::ANGLEFormat angleFormat,
const gl::Extents &size, const gl::Extents &size,
StagingAccess readAndWriteAccess,
ID3D11Device *device); ID3D11Device *device);
bool UsePresentPathFast(const Renderer11 *renderer, const gl::FramebufferAttachment *colorbuffer); bool UsePresentPathFast(const Renderer11 *renderer, const gl::FramebufferAttachment *colorbuffer);
......
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