OpenGL: Simplify lazy clear of render pass attachments

Bug: dawn:145
Change-Id: Ia175ebc5a74f7cc15584b9132e00f9089d5dc5b6
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/14983
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Austin Eng 2020-01-16 01:30:30 +00:00 committed by Commit Bot service account
parent 3d97384e16
commit 9652add688
3 changed files with 18 additions and 46 deletions

View File

@ -408,12 +408,13 @@ namespace dawn_native { namespace opengl {
auto TransitionForPass = [](const PassResourceUsage& usages) { auto TransitionForPass = [](const PassResourceUsage& usages) {
for (size_t i = 0; i < usages.textures.size(); i++) { for (size_t i = 0; i < usages.textures.size(); i++) {
Texture* texture = ToBackend(usages.textures[i]); Texture* texture = ToBackend(usages.textures[i]);
// We count the lazy clears for non output attachment textures in order to match the // Clear textures that are not output attachments. Output attachments will be
// backdoor lazy clear counts in Vulkan and D3D12. // cleared in BeginRenderPass by setting the loadop to clear when the
bool isLazyClear = // texture subresource has not been initialized before the render pass.
!(usages.textureUsages[i] & wgpu::TextureUsage::OutputAttachment); if (!(usages.textureUsages[i] & wgpu::TextureUsage::OutputAttachment)) {
texture->EnsureSubresourceContentInitialized( texture->EnsureSubresourceContentInitialized(0, texture->GetNumMipLevels(), 0,
0, texture->GetNumMipLevels(), 0, texture->GetArrayLayers(), isLazyClear); texture->GetArrayLayers());
}
} }
}; };
@ -434,6 +435,8 @@ namespace dawn_native { namespace opengl {
case Command::BeginRenderPass: { case Command::BeginRenderPass: {
auto* cmd = mCommands.NextCommand<BeginRenderPassCmd>(); auto* cmd = mCommands.NextCommand<BeginRenderPassCmd>();
TransitionForPass(passResourceUsages[nextPassNumber]); TransitionForPass(passResourceUsages[nextPassNumber]);
LazyClearRenderPassAttachments(cmd);
ExecuteRenderPass(cmd); ExecuteRenderPass(cmd);
nextPassNumber++; nextPassNumber++;
@ -779,7 +782,6 @@ namespace dawn_native { namespace opengl {
for (uint32_t i : for (uint32_t i :
IterateBitSet(renderPass->attachmentState->GetColorAttachmentsMask())) { IterateBitSet(renderPass->attachmentState->GetColorAttachmentsMask())) {
auto* attachmentInfo = &renderPass->colorAttachments[i]; auto* attachmentInfo = &renderPass->colorAttachments[i];
TextureView* view = ToBackend(attachmentInfo->view.Get());
// Load op - color // Load op - color
// TODO(cwallez@chromium.org): Choose the clear function depending on the // TODO(cwallez@chromium.org): Choose the clear function depending on the
@ -791,30 +793,14 @@ namespace dawn_native { namespace opengl {
gl.ClearBufferfv(GL_COLOR, i, &attachmentInfo->clearColor.r); gl.ClearBufferfv(GL_COLOR, i, &attachmentInfo->clearColor.r);
} }
switch (attachmentInfo->storeOp) { if (attachmentInfo->storeOp == wgpu::StoreOp::Clear) {
case wgpu::StoreOp::Store: { // TODO(natlee@microsoft.com): call glDiscard to do optimization
view->GetTexture()->SetIsSubresourceContentInitialized(
true, view->GetBaseMipLevel(), view->GetLevelCount(),
view->GetBaseArrayLayer(), view->GetLayerCount());
} break;
case wgpu::StoreOp::Clear: {
// TODO(natlee@microsoft.com): call glDiscard to do optimization
view->GetTexture()->SetIsSubresourceContentInitialized(
false, view->GetBaseMipLevel(), view->GetLevelCount(),
view->GetBaseArrayLayer(), view->GetLayerCount());
} break;
default:
UNREACHABLE();
break;
} }
} }
if (renderPass->attachmentState->HasDepthStencilAttachment()) { if (renderPass->attachmentState->HasDepthStencilAttachment()) {
auto* attachmentInfo = &renderPass->depthStencilAttachment; auto* attachmentInfo = &renderPass->depthStencilAttachment;
const Format& attachmentFormat = attachmentInfo->view->GetTexture()->GetFormat(); const Format& attachmentFormat = attachmentInfo->view->GetTexture()->GetFormat();
TextureView* view = ToBackend(attachmentInfo->view.Get());
// Load op - depth/stencil // Load op - depth/stencil
bool doDepthClear = attachmentFormat.HasDepth() && bool doDepthClear = attachmentFormat.HasDepth() &&
@ -838,18 +824,6 @@ namespace dawn_native { namespace opengl {
const GLint clearStencil = attachmentInfo->clearStencil; const GLint clearStencil = attachmentInfo->clearStencil;
gl.ClearBufferiv(GL_STENCIL, 0, &clearStencil); gl.ClearBufferiv(GL_STENCIL, 0, &clearStencil);
} }
if (attachmentInfo->depthStoreOp == wgpu::StoreOp::Store &&
attachmentInfo->stencilStoreOp == wgpu::StoreOp::Store) {
view->GetTexture()->SetIsSubresourceContentInitialized(
true, view->GetBaseMipLevel(), view->GetLevelCount(),
view->GetBaseArrayLayer(), view->GetLayerCount());
} else if (attachmentInfo->depthStoreOp == wgpu::StoreOp::Clear &&
attachmentInfo->stencilStoreOp == wgpu::StoreOp::Clear) {
view->GetTexture()->SetIsSubresourceContentInitialized(
false, view->GetBaseMipLevel(), view->GetLevelCount(),
view->GetBaseArrayLayer(), view->GetLayerCount());
}
} }
} }

View File

@ -299,14 +299,18 @@ namespace dawn_native { namespace opengl {
gl.BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); gl.BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
} }
} }
if (clearValue == TextureBase::ClearValue::Zero) {
SetIsSubresourceContentInitialized(true, baseMipLevel, levelCount, baseArrayLayer,
layerCount);
device->IncrementLazyClearCountForTesting();
}
return {}; return {};
} }
void Texture::EnsureSubresourceContentInitialized(uint32_t baseMipLevel, void Texture::EnsureSubresourceContentInitialized(uint32_t baseMipLevel,
uint32_t levelCount, uint32_t levelCount,
uint32_t baseArrayLayer, uint32_t baseArrayLayer,
uint32_t layerCount, uint32_t layerCount) {
bool isLazyClear) {
if (!GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) { if (!GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return; return;
} }
@ -314,11 +318,6 @@ namespace dawn_native { namespace opengl {
layerCount)) { layerCount)) {
GetDevice()->ConsumedError(ClearTexture(baseMipLevel, levelCount, baseArrayLayer, GetDevice()->ConsumedError(ClearTexture(baseMipLevel, levelCount, baseArrayLayer,
layerCount, TextureBase::ClearValue::Zero)); layerCount, TextureBase::ClearValue::Zero));
if (isLazyClear) {
GetDevice()->IncrementLazyClearCountForTesting();
}
SetIsSubresourceContentInitialized(true, baseMipLevel, levelCount, baseArrayLayer,
layerCount);
} }
} }

View File

@ -40,8 +40,7 @@ namespace dawn_native { namespace opengl {
void EnsureSubresourceContentInitialized(uint32_t baseMipLevel, void EnsureSubresourceContentInitialized(uint32_t baseMipLevel,
uint32_t levelCount, uint32_t levelCount,
uint32_t baseArrayLayer, uint32_t baseArrayLayer,
uint32_t layerCount, uint32_t layerCount);
bool isLazyClear = true);
private: private:
void DestroyImpl() override; void DestroyImpl() override;