Fixup readability/casting lint issues

This CL fixes a few readability/casting issues and enables the lint
check.

Bug: dawn:1339
Change-Id: Ib0d127c3e01fad9b5ac074d8ca09f3a1956ad4fc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87020
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair 2022-04-20 19:02:29 +00:00 committed by Dawn LUCI CQ
parent 3e0547df6c
commit 4c9b72b4fa
8 changed files with 22 additions and 23 deletions

View File

@ -1,4 +1,3 @@
filter=-build/namespaces
filter=-readability/casting
filter=-readability/todo
filter=-runtime/indentation_namespace

View File

@ -517,8 +517,8 @@ namespace dawn::native {
return true;
case BufferState::Mapped:
ASSERT(bool(mMapMode & wgpu::MapMode::Read) ^
bool(mMapMode & wgpu::MapMode::Write));
ASSERT(bool{mMapMode & wgpu::MapMode::Read} ^
bool{mMapMode & wgpu::MapMode::Write});
return !writable || (mMapMode & wgpu::MapMode::Write);
case BufferState::Unmapped:

View File

@ -32,7 +32,7 @@ wgpu::Buffer ubo;
float RandomFloat(float min, float max) {
// NOLINTNEXTLINE(runtime/threadsafe_fn)
float zeroOne = rand() / float(RAND_MAX);
float zeroOne = rand() / static_cast<float>(RAND_MAX);
return zeroOne * (max - min) + min;
}

View File

@ -625,11 +625,11 @@ TEST_P(TextureFormatTest, RGBA8UnormSrgb) {
std::vector<float> uncompressedData;
for (size_t i = 0; i < textureData.size(); i += 4) {
uncompressedData.push_back(SRGBToLinear(textureData[i + 0] / float(maxValue)));
uncompressedData.push_back(SRGBToLinear(textureData[i + 1] / float(maxValue)));
uncompressedData.push_back(SRGBToLinear(textureData[i + 2] / float(maxValue)));
uncompressedData.push_back(SRGBToLinear(textureData[i + 0] / static_cast<float>(maxValue)));
uncompressedData.push_back(SRGBToLinear(textureData[i + 1] / static_cast<float>(maxValue)));
uncompressedData.push_back(SRGBToLinear(textureData[i + 2] / static_cast<float>(maxValue)));
// Alpha is linear for sRGB formats
uncompressedData.push_back(textureData[i + 3] / float(maxValue));
uncompressedData.push_back(textureData[i + 3] / static_cast<float>(maxValue));
}
DoFloatFormatSamplingTest(
@ -652,11 +652,11 @@ TEST_P(TextureFormatTest, BGRA8UnormSrgb) {
std::vector<float> uncompressedData;
for (size_t i = 0; i < textureData.size(); i += 4) {
// Note that R and B are swapped
uncompressedData.push_back(SRGBToLinear(textureData[i + 2] / float(maxValue)));
uncompressedData.push_back(SRGBToLinear(textureData[i + 1] / float(maxValue)));
uncompressedData.push_back(SRGBToLinear(textureData[i + 0] / float(maxValue)));
uncompressedData.push_back(SRGBToLinear(textureData[i + 2] / static_cast<float>(maxValue)));
uncompressedData.push_back(SRGBToLinear(textureData[i + 1] / static_cast<float>(maxValue)));
uncompressedData.push_back(SRGBToLinear(textureData[i + 0] / static_cast<float>(maxValue)));
// Alpha is linear for sRGB formats
uncompressedData.push_back(textureData[i + 3] / float(maxValue));
uncompressedData.push_back(textureData[i + 3] / static_cast<float>(maxValue));
}
DoFloatFormatSamplingTest(
@ -755,7 +755,7 @@ TEST_P(TextureFormatTest, RGB9E5Ufloat) {
// exponent (15).
float smallestExponent = std::pow(2.0f, -24.0f);
float largestExponent = std::pow(2.0f, float(31 - 24));
float largestExponent = std::pow(2.0f, float{31 - 24});
auto MakeRGB9E5 = [](uint32_t r, uint32_t g, uint32_t b, uint32_t e) {
ASSERT((r & 0x1FF) == r);

View File

@ -485,8 +485,8 @@ void ShaderRobustnessPerf::Step() {
pass.SetPipeline(mPipeline);
pass.SetBindGroup(0, mBindGroup);
for (unsigned int i = 0; i < kNumIterations; ++i) {
pass.Dispatch(ceil(float(mDimBOuter) / float(kTileSize)),
ceil(float(mDimAOuter) / float(kTileSize)), 1);
pass.Dispatch(ceil(static_cast<float>(mDimBOuter) / float{kTileSize}),
ceil(static_cast<float>(mDimAOuter) / float{kTileSize}), 1);
}
pass.End();

View File

@ -144,8 +144,8 @@ namespace dawn::native {
TEST(CacheKeySerializerTests, FloatingTypes) {
// Using 0s to avoid dealing with implementation specific float details.
EXPECT_THAT(CacheKey().Record(float(0)), CacheKeyEq(CacheKey(sizeof(float), 0)));
EXPECT_THAT(CacheKey().Record(double(0)), CacheKeyEq(CacheKey(sizeof(double), 0)));
EXPECT_THAT(CacheKey().Record(float{0}), CacheKeyEq(CacheKey(sizeof(float), 0)));
EXPECT_THAT(CacheKey().Record(double{0}), CacheKeyEq(CacheKey(sizeof(double), 0)));
}
TEST(CacheKeySerializerTests, LiteralStrings) {

View File

@ -79,19 +79,19 @@ TEST_F(SetViewportTest, ViewportLargerThanFramebuffer) {
// Width is larger than the rendertarget's width
TestViewportCall(false, 0.0, 0.0, kWidth + 1.0, kHeight, 0.0, 1.0);
TestViewportCall(false, 0.0, 0.0, nextafter(float(kWidth), 1000.0f), kHeight, 0.0, 1.0);
TestViewportCall(false, 0.0, 0.0, nextafter(float{kWidth}, 1000.0f), kHeight, 0.0, 1.0);
// Height is larger than the rendertarget's height
TestViewportCall(false, 0.0, 0.0, kWidth, kHeight + 1.0, 0.0, 1.0);
TestViewportCall(false, 0.0, 0.0, kWidth, nextafter(float(kHeight), 1000.0f), 0.0, 1.0);
TestViewportCall(false, 0.0, 0.0, kWidth, nextafter(float{kHeight}, 1000.0f), 0.0, 1.0);
// x + width is larger than the rendertarget's width
TestViewportCall(false, 2.0, 0.0, kWidth - 1.0, kHeight, 0.0, 1.0);
TestViewportCall(false, 1.0, 0.0, nextafter(float(kWidth - 1.0), 1000.0f), kHeight, 0.0, 1.0);
TestViewportCall(false, 1.0, 0.0, nextafter(float{kWidth - 1.0}, 1000.0f), kHeight, 0.0, 1.0);
// Height is larger than the rendertarget's height
TestViewportCall(false, 0.0, 2.0, kWidth, kHeight - 1.0, 0.0, 1.0);
TestViewportCall(false, 0.0, 1.0, kWidth, nextafter(float(kHeight - 1.0), 1000.0f), 0.0, 1.0);
TestViewportCall(false, 0.0, 1.0, kWidth, nextafter(float{kHeight - 1.0}, 1000.0f), 0.0, 1.0);
}
// Test to check that negative x in viewport is disallowed

View File

@ -62,8 +62,8 @@ namespace {
continue;
}
float errorRate =
abs(static_cast<int64_t>(mExpected[i] - actual[i])) / float(mExpected[i]);
float errorRate = abs(static_cast<int64_t>(mExpected[i] - actual[i])) /
static_cast<float>(mExpected[i]);
if (errorRate > kErrorToleranceRatio) {
return testing::AssertionFailure()
<< "Expected data[" << i << "] to be " << mExpected[i] << ", actual "