Fix clearing sint/uint color attachments on Vulkan and OpenGL

This patch fixes a bug on the clear of color attachments with signed or
unsigned integer formats on Vulkan and OpenGL by using the correct APIs
to set the clear color for signed/unsigned integer formats.

BUG=dawn:497
Change-Id: If1bc9858875e6384e71c15bb6770fbbb10045037
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/26041
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao
2020-08-01 04:18:17 +00:00
committed by Commit Bot service account
parent fada501190
commit 8c9858e9b8
5 changed files with 142 additions and 9 deletions

View File

@@ -913,13 +913,23 @@ namespace dawn_native { namespace opengl {
auto* attachmentInfo = &renderPass->colorAttachments[i];
// Load op - color
// TODO(cwallez@chromium.org): Choose the clear function depending on the
// componentType: things work for now because the clear color is always a float, but
// when that's fixed will lose precision on integer formats when converting to
// float.
if (attachmentInfo->loadOp == wgpu::LoadOp::Clear) {
gl.ColorMaski(i, true, true, true, true);
gl.ClearBufferfv(GL_COLOR, i, &attachmentInfo->clearColor.r);
const Format& attachmentFormat = attachmentInfo->view->GetFormat();
if (attachmentFormat.HasComponentType(Format::Type::Float)) {
gl.ClearBufferfv(GL_COLOR, i, &attachmentInfo->clearColor.r);
} else if (attachmentFormat.HasComponentType(Format::Type::Uint)) {
const std::array<uint32_t, 4> appliedClearColor =
ConvertToUnsignedIntegerColor(attachmentInfo->clearColor);
gl.ClearBufferuiv(GL_COLOR, i, appliedClearColor.data());
} else if (attachmentFormat.HasComponentType(Format::Type::Sint)) {
const std::array<int32_t, 4> appliedClearColor =
ConvertToSignedIntegerColor(attachmentInfo->clearColor);
gl.ClearBufferiv(GL_COLOR, i, appliedClearColor.data());
} else {
UNREACHABLE();
}
}
if (attachmentInfo->storeOp == wgpu::StoreOp::Clear) {