Commit 3b43647f by Mingyu Hu Committed by Commit Bot

EXT_multisampled_render_to_texture clean up and prep for 2DMultisampleArray.

1) Added new Multisampled Image Index. For the upcoming multisampled array case, we cannot automatically create the same MS image index during resolve. So the correct MS image index is created and saved during the initial creation of the MS Texture. It seems to be more streamlined as well, only creating the MS image index once, and not using hardcoded values to get the subresourceIndex. 2) reordering resolveTextureHelper to remove duplicated code. Bug: angleproject:3107 Change-Id: Ifd91136a64efb5e7bd296e09cd876a6e6eb8e77e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1919555 Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent cbabb453
...@@ -68,8 +68,9 @@ bool TextureStorage11::ImageKey::operator<(const ImageKey &rhs) const ...@@ -68,8 +68,9 @@ bool TextureStorage11::ImageKey::operator<(const ImageKey &rhs) const
} }
MultisampledRenderToTextureInfo::MultisampledRenderToTextureInfo(const GLsizei samples, MultisampledRenderToTextureInfo::MultisampledRenderToTextureInfo(const GLsizei samples,
const gl::ImageIndex index) const gl::ImageIndex &indexSS,
: samples(samples), index(index), msTextureNeedsResolve(false) const gl::ImageIndex &indexMS)
: samples(samples), indexSS(indexSS), indexMS(indexMS), msTextureNeedsResolve(false)
{} {}
MultisampledRenderToTextureInfo::~MultisampledRenderToTextureInfo() {} MultisampledRenderToTextureInfo::~MultisampledRenderToTextureInfo() {}
...@@ -870,27 +871,22 @@ angle::Result TextureStorage11::initDropStencilTexture(const gl::Context *contex ...@@ -870,27 +871,22 @@ angle::Result TextureStorage11::initDropStencilTexture(const gl::Context *contex
angle::Result TextureStorage11::resolveTextureHelper(const gl::Context *context, angle::Result TextureStorage11::resolveTextureHelper(const gl::Context *context,
const TextureHelper11 &texture) const TextureHelper11 &texture)
{ {
if (mMSTexInfo) UINT subresourceIndexSS;
{ ANGLE_TRY(getSubresourceIndex(context, mMSTexInfo->indexSS, &subresourceIndexSS));
gl::ImageIndex indexSS = gl::ImageIndex::Make2D(mMSTexInfo->index.getLevelIndex()); UINT subresourceIndexMS;
UINT subresourceIndexSS; ANGLE_TRY(getSubresourceIndex(context, mMSTexInfo->indexMS, &subresourceIndexMS));
ANGLE_TRY(getSubresourceIndex(context, indexSS, &subresourceIndexSS)); ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
// For MS texture level must = 0, layer is the entire level -> 0 const TextureHelper11 *resource = nullptr;
// and miplevels must = 1. D3D11CalcSubresource(level, layer, miplevels); ANGLE_TRY(mMSTexInfo->msTex->getResource(context, &resource));
UINT subresourceIndexMS = D3D11CalcSubresource(0, 0, 1); deviceContext->ResolveSubresource(texture.get(), subresourceIndexSS, resource->get(),
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); subresourceIndexMS, texture.getFormat());
const TextureHelper11 *resource = nullptr; mMSTexInfo->msTextureNeedsResolve = false;
ANGLE_TRY(mMSTexInfo->msTex->getResource(context, &resource));
deviceContext->ResolveSubresource(texture.get(), subresourceIndexSS, resource->get(),
subresourceIndexMS, texture.getFormat());
mMSTexInfo->msTextureNeedsResolve = false;
}
return angle::Result::Continue; return angle::Result::Continue;
} }
angle::Result TextureStorage11::releaseMultisampledTexStorageForLevel(size_t level) angle::Result TextureStorage11::releaseMultisampledTexStorageForLevel(size_t level)
{ {
if (mMSTexInfo && mMSTexInfo->index.getLevelIndex() == static_cast<int>(level)) if (mMSTexInfo && mMSTexInfo->indexSS.getLevelIndex() == static_cast<int>(level))
{ {
mMSTexInfo->msTex.reset(); mMSTexInfo->msTex.reset();
onStateChange(angle::SubjectMessage::ContentsChanged); onStateChange(angle::SubjectMessage::ContentsChanged);
...@@ -913,24 +909,12 @@ angle::Result TextureStorage11::getMultisampledRenderTarget(const gl::Context *c ...@@ -913,24 +909,12 @@ angle::Result TextureStorage11::getMultisampledRenderTarget(const gl::Context *c
RenderTargetD3D **outRT) RenderTargetD3D **outRT)
{ {
const int level = index.getLevelIndex(); const int level = index.getLevelIndex();
if (mMSTexInfo && level == mMSTexInfo->index.getLevelIndex() && if (!mMSTexInfo || level != mMSTexInfo->indexSS.getLevelIndex() ||
samples == mMSTexInfo->samples && mMSTexInfo->msTex) samples != mMSTexInfo->samples || !mMSTexInfo->msTex)
{
RenderTargetD3D *rt;
ANGLE_TRY(mMSTexInfo->msTex->getRenderTarget(context, index, samples, &rt));
// By returning the multisampled render target to the caller, the render target
// is expected to be changed so we need to resolve to a single sampled texture
// next time resolveTexture is called.
mMSTexInfo->msTextureNeedsResolve = true;
*outRT = rt;
return angle::Result::Continue;
}
else
{ {
// if mMSTexInfo already exists, then we want to resolve and release it // if mMSTexInfo already exists, then we want to resolve and release it
// since the mMSTexInfo must be for a different sample count or level // since the mMSTexInfo must be for a different sample count or level
ANGLE_TRY(resolveTexture(context)); ANGLE_TRY(resolveTexture(context));
ASSERT(!mMSTexInfo);
// Now we can create a new object for the correct sample and level // Now we can create a new object for the correct sample and level
GLsizei width = getLevelWidth(level); GLsizei width = getLevelWidth(level);
...@@ -942,8 +926,8 @@ angle::Result TextureStorage11::getMultisampledRenderTarget(const gl::Context *c ...@@ -942,8 +926,8 @@ angle::Result TextureStorage11::getMultisampledRenderTarget(const gl::Context *c
// make sure multisample object has the blitted information. // make sure multisample object has the blitted information.
gl::Rectangle area(0, 0, width, height); gl::Rectangle area(0, 0, width, height);
gl::ImageIndex indexSS = gl::ImageIndex::Make2D(level);
RenderTargetD3D *readRenderTarget = nullptr; RenderTargetD3D *readRenderTarget = nullptr;
// use incoming index here since the index will correspond to the single sampled texture
ANGLE_TRY(getRenderTarget(context, index, 0, &readRenderTarget)); ANGLE_TRY(getRenderTarget(context, index, 0, &readRenderTarget));
gl::ImageIndex indexMS = gl::ImageIndex::Make2DMultisample(); gl::ImageIndex indexMS = gl::ImageIndex::Make2DMultisample();
RenderTargetD3D *drawRenderTarget = nullptr; RenderTargetD3D *drawRenderTarget = nullptr;
...@@ -954,17 +938,17 @@ angle::Result TextureStorage11::getMultisampledRenderTarget(const gl::Context *c ...@@ -954,17 +938,17 @@ angle::Result TextureStorage11::getMultisampledRenderTarget(const gl::Context *c
ANGLE_TRY(mRenderer->blitRenderbufferRect(context, area, area, readRenderTarget, ANGLE_TRY(mRenderer->blitRenderbufferRect(context, area, area, readRenderTarget,
drawRenderTarget, GL_NEAREST, nullptr, true, drawRenderTarget, GL_NEAREST, nullptr, true,
false, false)); false, false));
mMSTexInfo = std::make_unique<MultisampledRenderToTextureInfo>(samples, indexSS); mMSTexInfo = std::make_unique<MultisampledRenderToTextureInfo>(samples, index, indexMS);
mMSTexInfo->msTex = std::move(texMS); mMSTexInfo->msTex = std::move(texMS);
RenderTargetD3D *rt;
ANGLE_TRY(mMSTexInfo->msTex->getRenderTarget(context, index, samples, &rt));
// By returning the multisampled render target to the caller, the render target
// is expected to be changed so we need to resolve to a single sampled texture
// next time resolveTexture is called.
mMSTexInfo->msTextureNeedsResolve = true;
*outRT = rt;
return angle::Result::Continue;
} }
RenderTargetD3D *rt;
ANGLE_TRY(mMSTexInfo->msTex->getRenderTarget(context, mMSTexInfo->indexMS, samples, &rt));
// By returning the multisampled render target to the caller, the render target
// is expected to be changed so we need to resolve to a single sampled texture
// next time resolveTexture is called.
mMSTexInfo->msTextureNeedsResolve = true;
*outRT = rt;
return angle::Result::Continue;
} }
TextureStorage11_2D::TextureStorage11_2D(Renderer11 *renderer, SwapChain11 *swapchain) TextureStorage11_2D::TextureStorage11_2D(Renderer11 *renderer, SwapChain11 *swapchain)
......
...@@ -41,11 +41,22 @@ using CubeFaceArray = std::array<T, gl::kCubeFaceCount>; ...@@ -41,11 +41,22 @@ using CubeFaceArray = std::array<T, gl::kCubeFaceCount>;
struct MultisampledRenderToTextureInfo struct MultisampledRenderToTextureInfo
{ {
MultisampledRenderToTextureInfo(const GLsizei samples, const gl::ImageIndex index); MultisampledRenderToTextureInfo(const GLsizei samples,
const gl::ImageIndex &indexSS,
const gl::ImageIndex &indexMS);
~MultisampledRenderToTextureInfo(); ~MultisampledRenderToTextureInfo();
// How many samples the multisampled texture contains
GLsizei samples; GLsizei samples;
gl::ImageIndex index; // This is the image index for the single sampled texture
// This will hold the relevant level information
gl::ImageIndex indexSS;
// This is the image index for the multisampled texture
// For multisampled indexes, there is no level Index since they should
// account for the entire level.
gl::ImageIndex indexMS;
// True when multisampled texture has been written to and needs to be
// resolved to the single sampled texture
bool msTextureNeedsResolve; bool msTextureNeedsResolve;
std::unique_ptr<TextureStorage11_2DMultisample> msTex; std::unique_ptr<TextureStorage11_2DMultisample> msTex;
}; };
......
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