Only check the color channels available in the current color format
This patch optimizes the function `NeedsBigIntClear()` to only check
the color channels that are available in the current color format.
Bug: dawn:537
Test: dawn_end2end_tests
Change-Id: I51b8ed818a247976d07fa281b6f441e59976e8fb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/200895
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
diff --git a/src/dawn/native/ApplyClearColorValueWithDrawHelper.cpp b/src/dawn/native/ApplyClearColorValueWithDrawHelper.cpp
index 905f505..0ff2f3f 100644
--- a/src/dawn/native/ApplyClearColorValueWithDrawHelper.cpp
+++ b/src/dawn/native/ApplyClearColorValueWithDrawHelper.cpp
@@ -255,40 +255,36 @@
return false;
}
- // TODO(dawn:537): only check the color channels that are available in the current color format.
Color clearValue = GetClearColorValue(colorAttachmentInfo);
- switch (format.GetAspectInfo(Aspect::Color).baseType) {
- case TextureComponentType::Uint: {
- constexpr double kMaxUintRepresentableInFloat = 1 << std::numeric_limits<float>::digits;
- if (clearValue.r <= kMaxUintRepresentableInFloat &&
- clearValue.g <= kMaxUintRepresentableInFloat &&
- clearValue.b <= kMaxUintRepresentableInFloat &&
- clearValue.a <= kMaxUintRepresentableInFloat) {
- return false;
+ std::array<double, 4> clearValueInArray = {
+ {clearValue.r, clearValue.g, clearValue.b, clearValue.a}};
+ for (uint8_t i = 0; i < format.componentCount; ++i) {
+ double value = clearValueInArray[i];
+ switch (format.GetAspectInfo(Aspect::Color).baseType) {
+ case TextureComponentType::Uint: {
+ constexpr double kMaxUintRepresentableInFloat =
+ 1 << std::numeric_limits<float>::digits;
+ if (value > kMaxUintRepresentableInFloat) {
+ return true;
+ }
+ break;
}
- break;
- }
- case TextureComponentType::Sint: {
- constexpr double kMaxSintRepresentableInFloat = 1 << std::numeric_limits<float>::digits;
- constexpr double kMinSintRepresentableInFloat = -kMaxSintRepresentableInFloat;
- if (clearValue.r <= kMaxSintRepresentableInFloat &&
- clearValue.r >= kMinSintRepresentableInFloat &&
- clearValue.g <= kMaxSintRepresentableInFloat &&
- clearValue.g >= kMinSintRepresentableInFloat &&
- clearValue.b <= kMaxSintRepresentableInFloat &&
- clearValue.b >= kMinSintRepresentableInFloat &&
- clearValue.a <= kMaxSintRepresentableInFloat &&
- clearValue.a >= kMinSintRepresentableInFloat) {
- return false;
+ case TextureComponentType::Sint: {
+ constexpr double kMaxSintRepresentableInFloat =
+ 1 << std::numeric_limits<float>::digits;
+ constexpr double kMinSintRepresentableInFloat = -kMaxSintRepresentableInFloat;
+ if (value > kMaxSintRepresentableInFloat || value < kMinSintRepresentableInFloat) {
+ return true;
+ }
+ break;
}
- break;
+ case TextureComponentType::Float:
+ DAWN_UNREACHABLE();
+ return false;
}
- case TextureComponentType::Float:
- DAWN_UNREACHABLE();
- return false;
}
- return true;
+ return false;
}
bool GetKeyOfApplyClearColorValueWithDrawPipelines(