Vulkan: Implement StoreOp::Discard

It wasn't implemented because Discard wasn't implemented for a long
time.

Bug: dawn:1151
Change-Id: Ie26559dd65a2c97a32df418521ca93c1021dd837
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/65720
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Brandon Jones <bajones@chromium.org>
This commit is contained in:
Corentin Wallez 2021-10-04 11:02:17 +00:00 committed by Dawn LUCI CQ
parent bb417ace11
commit bf8c40b4f1
5 changed files with 45 additions and 16 deletions

View File

@ -209,17 +209,18 @@ namespace dawn_native { namespace vulkan {
const auto& attachmentInfo = renderPass->colorAttachments[i]; const auto& attachmentInfo = renderPass->colorAttachments[i];
bool hasResolveTarget = attachmentInfo.resolveTarget != nullptr; bool hasResolveTarget = attachmentInfo.resolveTarget != nullptr;
wgpu::LoadOp loadOp = attachmentInfo.loadOp;
query.SetColor(i, attachmentInfo.view->GetFormat().format, loadOp, query.SetColor(i, attachmentInfo.view->GetFormat().format,
hasResolveTarget); attachmentInfo.loadOp, attachmentInfo.storeOp, hasResolveTarget);
} }
if (renderPass->attachmentState->HasDepthStencilAttachment()) { if (renderPass->attachmentState->HasDepthStencilAttachment()) {
const auto& attachmentInfo = renderPass->depthStencilAttachment; const auto& attachmentInfo = renderPass->depthStencilAttachment;
query.SetDepthStencil(attachmentInfo.view->GetTexture()->GetFormat().format, query.SetDepthStencil(attachmentInfo.view->GetTexture()->GetFormat().format,
attachmentInfo.depthLoadOp, attachmentInfo.stencilLoadOp); attachmentInfo.depthLoadOp, attachmentInfo.depthStoreOp,
attachmentInfo.stencilLoadOp,
attachmentInfo.stencilStoreOp);
} }
query.SetSampleCount(renderPass->attachmentState->GetSampleCount()); query.SetSampleCount(renderPass->attachmentState->GetSampleCount());

View File

@ -32,6 +32,16 @@ namespace dawn_native { namespace vulkan {
} }
UNREACHABLE(); UNREACHABLE();
} }
VkAttachmentStoreOp VulkanAttachmentStoreOp(wgpu::StoreOp op) {
switch (op) {
case wgpu::StoreOp::Store:
return VK_ATTACHMENT_STORE_OP_STORE;
case wgpu::StoreOp::Discard:
return VK_ATTACHMENT_STORE_OP_DONT_CARE;
}
UNREACHABLE();
}
} // anonymous namespace } // anonymous namespace
// RenderPassCacheQuery // RenderPassCacheQuery
@ -39,20 +49,26 @@ namespace dawn_native { namespace vulkan {
void RenderPassCacheQuery::SetColor(ColorAttachmentIndex index, void RenderPassCacheQuery::SetColor(ColorAttachmentIndex index,
wgpu::TextureFormat format, wgpu::TextureFormat format,
wgpu::LoadOp loadOp, wgpu::LoadOp loadOp,
wgpu::StoreOp storeOp,
bool hasResolveTarget) { bool hasResolveTarget) {
colorMask.set(index); colorMask.set(index);
colorFormats[index] = format; colorFormats[index] = format;
colorLoadOp[index] = loadOp; colorLoadOp[index] = loadOp;
colorStoreOp[index] = storeOp;
resolveTargetMask[index] = hasResolveTarget; resolveTargetMask[index] = hasResolveTarget;
} }
void RenderPassCacheQuery::SetDepthStencil(wgpu::TextureFormat format, void RenderPassCacheQuery::SetDepthStencil(wgpu::TextureFormat format,
wgpu::LoadOp depthLoadOp, wgpu::LoadOp depthLoadOpIn,
wgpu::LoadOp stencilLoadOp) { wgpu::StoreOp depthStoreOpIn,
wgpu::LoadOp stencilLoadOpIn,
wgpu::StoreOp stencilStoreOpIn) {
hasDepthStencil = true; hasDepthStencil = true;
depthStencilFormat = format; depthStencilFormat = format;
this->depthLoadOp = depthLoadOp; depthLoadOp = depthLoadOpIn;
this->stencilLoadOp = stencilLoadOp; depthStoreOp = depthStoreOpIn;
stencilLoadOp = stencilLoadOpIn;
stencilStoreOp = stencilStoreOpIn;
} }
void RenderPassCacheQuery::SetSampleCount(uint32_t sampleCount) { void RenderPassCacheQuery::SetSampleCount(uint32_t sampleCount) {
@ -113,7 +129,7 @@ namespace dawn_native { namespace vulkan {
attachmentDesc.format = VulkanImageFormat(mDevice, query.colorFormats[i]); attachmentDesc.format = VulkanImageFormat(mDevice, query.colorFormats[i]);
attachmentDesc.samples = vkSampleCount; attachmentDesc.samples = vkSampleCount;
attachmentDesc.loadOp = VulkanAttachmentLoadOp(query.colorLoadOp[i]); attachmentDesc.loadOp = VulkanAttachmentLoadOp(query.colorLoadOp[i]);
attachmentDesc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; attachmentDesc.storeOp = VulkanAttachmentStoreOp(query.colorStoreOp[i]);
attachmentDesc.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; attachmentDesc.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachmentDesc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; attachmentDesc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
@ -134,9 +150,9 @@ namespace dawn_native { namespace vulkan {
attachmentDesc.format = VulkanImageFormat(mDevice, query.depthStencilFormat); attachmentDesc.format = VulkanImageFormat(mDevice, query.depthStencilFormat);
attachmentDesc.samples = vkSampleCount; attachmentDesc.samples = vkSampleCount;
attachmentDesc.loadOp = VulkanAttachmentLoadOp(query.depthLoadOp); attachmentDesc.loadOp = VulkanAttachmentLoadOp(query.depthLoadOp);
attachmentDesc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; attachmentDesc.storeOp = VulkanAttachmentStoreOp(query.depthStoreOp);
attachmentDesc.stencilLoadOp = VulkanAttachmentLoadOp(query.stencilLoadOp); attachmentDesc.stencilLoadOp = VulkanAttachmentLoadOp(query.stencilLoadOp);
attachmentDesc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; attachmentDesc.stencilStoreOp = VulkanAttachmentStoreOp(query.stencilStoreOp);
attachmentDesc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; attachmentDesc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
attachmentDesc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; attachmentDesc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;

View File

@ -41,21 +41,27 @@ namespace dawn_native { namespace vulkan {
void SetColor(ColorAttachmentIndex index, void SetColor(ColorAttachmentIndex index,
wgpu::TextureFormat format, wgpu::TextureFormat format,
wgpu::LoadOp loadOp, wgpu::LoadOp loadOp,
wgpu::StoreOp storeOp,
bool hasResolveTarget); bool hasResolveTarget);
void SetDepthStencil(wgpu::TextureFormat format, void SetDepthStencil(wgpu::TextureFormat format,
wgpu::LoadOp depthLoadOp, wgpu::LoadOp depthLoadOp,
wgpu::LoadOp stencilLoadOp); wgpu::StoreOp depthStoreOp,
wgpu::LoadOp stencilLoadOp,
wgpu::StoreOp stencilStoreOp);
void SetSampleCount(uint32_t sampleCount); void SetSampleCount(uint32_t sampleCount);
ityp::bitset<ColorAttachmentIndex, kMaxColorAttachments> colorMask; ityp::bitset<ColorAttachmentIndex, kMaxColorAttachments> colorMask;
ityp::bitset<ColorAttachmentIndex, kMaxColorAttachments> resolveTargetMask; ityp::bitset<ColorAttachmentIndex, kMaxColorAttachments> resolveTargetMask;
ityp::array<ColorAttachmentIndex, wgpu::TextureFormat, kMaxColorAttachments> colorFormats; ityp::array<ColorAttachmentIndex, wgpu::TextureFormat, kMaxColorAttachments> colorFormats;
ityp::array<ColorAttachmentIndex, wgpu::LoadOp, kMaxColorAttachments> colorLoadOp; ityp::array<ColorAttachmentIndex, wgpu::LoadOp, kMaxColorAttachments> colorLoadOp;
ityp::array<ColorAttachmentIndex, wgpu::StoreOp, kMaxColorAttachments> colorStoreOp;
bool hasDepthStencil = false; bool hasDepthStencil = false;
wgpu::TextureFormat depthStencilFormat; wgpu::TextureFormat depthStencilFormat;
wgpu::LoadOp depthLoadOp; wgpu::LoadOp depthLoadOp;
wgpu::StoreOp depthStoreOp;
wgpu::LoadOp stencilLoadOp; wgpu::LoadOp stencilLoadOp;
wgpu::StoreOp stencilStoreOp;
uint32_t sampleCount; uint32_t sampleCount;
}; };

View File

@ -496,19 +496,21 @@ namespace dawn_native { namespace vulkan {
dynamic.dynamicStateCount = sizeof(dynamicStates) / sizeof(dynamicStates[0]); dynamic.dynamicStateCount = sizeof(dynamicStates) / sizeof(dynamicStates[0]);
dynamic.pDynamicStates = dynamicStates; dynamic.pDynamicStates = dynamicStates;
// Get a VkRenderPass that matches the attachment formats for this pipeline, load ops don't // Get a VkRenderPass that matches the attachment formats for this pipeline, load/store ops
// matter so set them all to LoadOp::Load // don't matter so set them all to LoadOp::Load / StoreOp::Store
VkRenderPass renderPass = VK_NULL_HANDLE; VkRenderPass renderPass = VK_NULL_HANDLE;
{ {
RenderPassCacheQuery query; RenderPassCacheQuery query;
for (ColorAttachmentIndex i : IterateBitSet(GetColorAttachmentsMask())) { for (ColorAttachmentIndex i : IterateBitSet(GetColorAttachmentsMask())) {
query.SetColor(i, GetColorAttachmentFormat(i), wgpu::LoadOp::Load, false); query.SetColor(i, GetColorAttachmentFormat(i), wgpu::LoadOp::Load,
wgpu::StoreOp::Store, false);
} }
if (HasDepthStencilAttachment()) { if (HasDepthStencilAttachment()) {
query.SetDepthStencil(GetDepthStencilFormat(), wgpu::LoadOp::Load, query.SetDepthStencil(GetDepthStencilFormat(), wgpu::LoadOp::Load,
wgpu::LoadOp::Load); wgpu::StoreOp::Store, wgpu::LoadOp::Load,
wgpu::StoreOp::Store);
} }
query.SetSampleCount(GetSampleCount()); query.SetSampleCount(GetSampleCount());

View File

@ -592,6 +592,10 @@ TEST_P(TextureZeroInitTest, IndependentDepthStencilLoadAfterDiscard) {
// on some Intel drivers. // on some Intel drivers.
DAWN_SUPPRESS_TEST_IF(IsMetal() && IsIntel()); DAWN_SUPPRESS_TEST_IF(IsMetal() && IsIntel());
// TODO(crbug.com/dawn/1151): The test started failing on Wintel Vulkan when Discard was
// implemented for the Vulkan backend.
DAWN_SUPPRESS_TEST_IF(IsVulkan() && IsWindows() && IsIntel());
wgpu::TextureDescriptor depthStencilDescriptor = CreateTextureDescriptor( wgpu::TextureDescriptor depthStencilDescriptor = CreateTextureDescriptor(
1, 1, wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc, 1, 1, wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc,
kDepthStencilFormat); kDepthStencilFormat);