Fix more compilation warnings.

Bug: chromium:1064305
Change-Id: I3aac24f8179d2c9e5206dd4542ea2506f26755e9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/19301
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Zhenyao Mo <zmo@google.com>
This commit is contained in:
Zhenyao Mo 2020-04-11 03:22:33 +00:00 committed by Commit Bot service account
parent 8619cbe237
commit 5b7292c8f8
21 changed files with 85 additions and 71 deletions

View File

@ -414,12 +414,12 @@ namespace dawn_wire {
// Macro to simplify error handling, similar to DAWN_TRY but for DeserializeResult. // Macro to simplify error handling, similar to DAWN_TRY but for DeserializeResult.
#define DESERIALIZE_TRY(EXPR) \ #define DESERIALIZE_TRY(EXPR) \
{ \ do { \
DeserializeResult exprResult = EXPR; \ DeserializeResult exprResult = EXPR; \
if (exprResult != DeserializeResult::Success) { \ if (exprResult != DeserializeResult::Success) { \
return exprResult; \ return exprResult; \
} \ } \
} } while (0)
ObjectHandle::ObjectHandle() = default; ObjectHandle::ObjectHandle() = default;
ObjectHandle::ObjectHandle(ObjectId id, ObjectSerial serial) : id(id), serial(serial) {} ObjectHandle::ObjectHandle(ObjectId id, ObjectSerial serial) : id(id), serial(serial) {}

View File

@ -95,6 +95,12 @@ config("dawn_internal") {
"-Wshadow-field", "-Wshadow-field",
"-Wmissing-field-initializers", "-Wmissing-field-initializers",
"-Wcstring-format-directive", "-Wcstring-format-directive",
"-Wtautological-unsigned-zero-compare",
"-Wreturn-std-move-in-c++11",
# Turn on the following flag after removing the empty statement in
# third_party/glm/glm/simd/common.h:106
# "-Wextra-semi-stmt",
] ]
} }
} }
@ -143,13 +149,9 @@ if (is_win || is_linux || is_mac || is_fuchsia || is_android) {
] ]
public_configs = [ ":dawn_internal" ] public_configs = [ ":dawn_internal" ]
deps = [ deps = [ "${dawn_root}/src/dawn:dawn_headers" ]
"${dawn_root}/src/dawn:dawn_headers",
]
if (dawn_enable_vulkan) { if (dawn_enable_vulkan) {
public_deps = [ public_deps = [ "${dawn_root}/third_party/khronos:vulkan_headers" ]
"${dawn_root}/third_party/khronos:vulkan_headers",
]
} }
if (is_android) { if (is_android) {
libs = [ "log" ] libs = [ "log" ]

View File

@ -42,7 +42,7 @@ namespace dawn_native {
ResourceMemoryAllocation invalidAllocation = ResourceMemoryAllocation{}; ResourceMemoryAllocation invalidAllocation = ResourceMemoryAllocation{};
if (allocationSize == 0) { if (allocationSize == 0) {
return invalidAllocation; return std::move(invalidAllocation);
} }
// Round allocation size to nearest power-of-two. // Round allocation size to nearest power-of-two.
@ -50,13 +50,13 @@ namespace dawn_native {
// Allocation cannot exceed the memory size. // Allocation cannot exceed the memory size.
if (allocationSize > mMemoryBlockSize) { if (allocationSize > mMemoryBlockSize) {
return invalidAllocation; return std::move(invalidAllocation);
} }
// Attempt to sub-allocate a block of the requested size. // Attempt to sub-allocate a block of the requested size.
const uint64_t blockOffset = mBuddyBlockAllocator.Allocate(allocationSize, alignment); const uint64_t blockOffset = mBuddyBlockAllocator.Allocate(allocationSize, alignment);
if (blockOffset == BuddyAllocator::kInvalidOffset) { if (blockOffset == BuddyAllocator::kInvalidOffset) {
return invalidAllocation; return std::move(invalidAllocation);
} }
const uint64_t memoryIndex = GetMemoryIndex(blockOffset); const uint64_t memoryIndex = GetMemoryIndex(blockOffset);

View File

@ -700,7 +700,7 @@ namespace dawn_native {
SpirvCrossBaseTypeToFormatType(shaderFragmentOutputBaseType); SpirvCrossBaseTypeToFormatType(shaderFragmentOutputBaseType);
if (formatType == Format::Type::Other) { if (formatType == Format::Type::Other) {
return DAWN_VALIDATION_ERROR("Unexpected Fragment output type"); return DAWN_VALIDATION_ERROR("Unexpected Fragment output type");
}; }
mFragmentOutputFormatBaseTypes[location] = formatType; mFragmentOutputFormatBaseTypes[location] = formatType;
} }
} }

View File

@ -65,7 +65,7 @@ namespace dawn_native { namespace d3d12 {
} }
ASSERT(factory != nullptr); ASSERT(factory != nullptr);
return factory; return std::move(factory);
} }
} // anonymous namespace } // anonymous namespace

View File

@ -395,7 +395,7 @@ namespace dawn_native { namespace d3d12 {
DAWN_TRY(CheckHRESULT(d3d11Texture.As(&dxgiKeyedMutex), DAWN_TRY(CheckHRESULT(d3d11Texture.As(&dxgiKeyedMutex),
"D3D12 QueryInterface ID3D11Texture2D to IDXGIKeyedMutex")); "D3D12 QueryInterface ID3D11Texture2D to IDXGIKeyedMutex"));
return dxgiKeyedMutex; return std::move(dxgiKeyedMutex);
} }
void Device::ReleaseKeyedMutexForTexture(ComPtr<IDXGIKeyedMutex> dxgiKeyedMutex) { void Device::ReleaseKeyedMutexForTexture(ComPtr<IDXGIKeyedMutex> dxgiKeyedMutex) {

View File

@ -39,10 +39,10 @@ namespace dawn_native { namespace d3d12 {
class StagingDescriptorAllocator; class StagingDescriptorAllocator;
#define ASSERT_SUCCESS(hr) \ #define ASSERT_SUCCESS(hr) \
{ \ do { \
HRESULT succeeded = hr; \ HRESULT succeeded = hr; \
ASSERT(SUCCEEDED(succeeded)); \ ASSERT(SUCCEEDED(succeeded)); \
} } while (0)
// Definition of backend types // Definition of backend types
class Device : public DeviceBase { class Device : public DeviceBase {

View File

@ -57,7 +57,7 @@ namespace dawn_native { namespace d3d12 {
// Calling CreateHeap implicitly calls MakeResident on the new heap. We must track this to // Calling CreateHeap implicitly calls MakeResident on the new heap. We must track this to
// avoid calling MakeResident a second time. // avoid calling MakeResident a second time.
mDevice->GetResidencyManager()->TrackResidentAllocation(ToBackend(heapBase.get())); mDevice->GetResidencyManager()->TrackResidentAllocation(ToBackend(heapBase.get()));
return heapBase; return std::move(heapBase);
} }
void HeapAllocator::DeallocateResourceHeap(std::unique_ptr<ResourceHeapBase> heap) { void HeapAllocator::DeallocateResourceHeap(std::unique_ptr<ResourceHeapBase> heap) {

View File

@ -162,7 +162,7 @@ namespace dawn_native { namespace d3d12 {
DAWN_TRY_ASSIGN(subAllocation, DAWN_TRY_ASSIGN(subAllocation,
CreatePlacedResource(heapType, resourceDescriptor, initialUsage)); CreatePlacedResource(heapType, resourceDescriptor, initialUsage));
if (subAllocation.GetInfo().mMethod != AllocationMethod::kInvalid) { if (subAllocation.GetInfo().mMethod != AllocationMethod::kInvalid) {
return subAllocation; return std::move(subAllocation);
} }
// If sub-allocation fails, fall-back to direct allocation (committed resource). // If sub-allocation fails, fall-back to direct allocation (committed resource).
@ -170,7 +170,7 @@ namespace dawn_native { namespace d3d12 {
DAWN_TRY_ASSIGN(directAllocation, DAWN_TRY_ASSIGN(directAllocation,
CreateCommittedResource(heapType, resourceDescriptor, initialUsage)); CreateCommittedResource(heapType, resourceDescriptor, initialUsage));
return directAllocation; return std::move(directAllocation);
} }
void ResourceAllocatorManager::Tick(Serial completedSerial) { void ResourceAllocatorManager::Tick(Serial completedSerial) {

View File

@ -122,7 +122,7 @@ namespace dawn_native { namespace d3d12 {
std::string result_string; std::string result_string;
DAWN_TRY(CheckSpvcSuccess(result.GetStringOutput(&result_string), DAWN_TRY(CheckSpvcSuccess(result.GetStringOutput(&result_string),
"Unable to get HLSL shader text")); "Unable to get HLSL shader text"));
return result_string; return std::move(result_string);
} else { } else {
return compiler->compile(); return compiler->compile();
} }

View File

@ -183,7 +183,7 @@ namespace dawn_native { namespace metal {
if (!instance->ConsumedError(GetDevicePCIInfo(device, &ids))) { if (!instance->ConsumedError(GetDevicePCIInfo(device, &ids))) {
mPCIInfo.vendorId = ids.vendorId; mPCIInfo.vendorId = ids.vendorId;
mPCIInfo.deviceId = ids.deviceId; mPCIInfo.deviceId = ids.deviceId;
}; }
#if defined(DAWN_PLATFORM_IOS) #if defined(DAWN_PLATFORM_IOS)
mAdapterType = wgpu::AdapterType::IntegratedGPU; mAdapterType = wgpu::AdapterType::IntegratedGPU;

View File

@ -120,7 +120,7 @@ namespace dawn_native { namespace vulkan {
DAWN_TRY_ASSIGN(subAllocation, DAWN_TRY_ASSIGN(subAllocation,
mAllocatorsPerType[memoryType]->AllocateMemory(requirements)); mAllocatorsPerType[memoryType]->AllocateMemory(requirements));
if (subAllocation.GetInfo().mMethod != AllocationMethod::kInvalid) { if (subAllocation.GetInfo().mMethod != AllocationMethod::kInvalid) {
return subAllocation; return std::move(subAllocation);
} }
} }

View File

@ -20,10 +20,12 @@
namespace dawn_native { namespace vulkan { namespace dawn_native { namespace vulkan {
#define GET_GLOBAL_PROC(name) \ #define GET_GLOBAL_PROC(name) \
do { \
name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(nullptr, "vk" #name)); \ name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(nullptr, "vk" #name)); \
if (name == nullptr) { \ if (name == nullptr) { \
return DAWN_INTERNAL_ERROR(std::string("Couldn't get proc vk") + #name); \ return DAWN_INTERNAL_ERROR(std::string("Couldn't get proc vk") + #name); \
} } \
} while (0)
MaybeError VulkanFunctions::LoadGlobalProcs(const DynamicLib& vulkanLib) { MaybeError VulkanFunctions::LoadGlobalProcs(const DynamicLib& vulkanLib) {
if (!vulkanLib.GetProc(&GetInstanceProcAddr, "vkGetInstanceProcAddr")) { if (!vulkanLib.GetProc(&GetInstanceProcAddr, "vkGetInstanceProcAddr")) {
@ -42,10 +44,12 @@ namespace dawn_native { namespace vulkan {
} }
#define GET_INSTANCE_PROC_BASE(name, procName) \ #define GET_INSTANCE_PROC_BASE(name, procName) \
do { \
name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(instance, "vk" #procName)); \ name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(instance, "vk" #procName)); \
if (name == nullptr) { \ if (name == nullptr) { \
return DAWN_INTERNAL_ERROR(std::string("Couldn't get proc vk") + #procName); \ return DAWN_INTERNAL_ERROR(std::string("Couldn't get proc vk") + #procName); \
} } \
} while (0)
#define GET_INSTANCE_PROC(name) GET_INSTANCE_PROC_BASE(name, name) #define GET_INSTANCE_PROC(name) GET_INSTANCE_PROC_BASE(name, name)
#define GET_INSTANCE_PROC_VENDOR(name, vendor) GET_INSTANCE_PROC_BASE(name, name##vendor) #define GET_INSTANCE_PROC_VENDOR(name, vendor) GET_INSTANCE_PROC_BASE(name, name##vendor)
@ -145,10 +149,12 @@ namespace dawn_native { namespace vulkan {
} }
#define GET_DEVICE_PROC(name) \ #define GET_DEVICE_PROC(name) \
do { \
name = reinterpret_cast<decltype(name)>(GetDeviceProcAddr(device, "vk" #name)); \ name = reinterpret_cast<decltype(name)>(GetDeviceProcAddr(device, "vk" #name)); \
if (name == nullptr) { \ if (name == nullptr) { \
return DAWN_INTERNAL_ERROR(std::string("Couldn't get proc vk") + #name); \ return DAWN_INTERNAL_ERROR(std::string("Couldn't get proc vk") + #name); \
} } \
} while (0)
MaybeError VulkanFunctions::LoadDeviceProcs(VkDevice device, MaybeError VulkanFunctions::LoadDeviceProcs(VkDevice device,
const VulkanDeviceInfo& deviceInfo) { const VulkanDeviceInfo& deviceInfo) {

View File

@ -196,7 +196,7 @@ namespace dawn_native { namespace vulkan {
// TODO(cwallez@chromium:org): Each layer can expose additional extensions, query them? // TODO(cwallez@chromium:org): Each layer can expose additional extensions, query them?
return info; return std::move(info);
} }
ResultOrError<std::vector<VkPhysicalDevice>> GetPhysicalDevices(const Backend& backend) { ResultOrError<std::vector<VkPhysicalDevice>> GetPhysicalDevices(const Backend& backend) {
@ -215,7 +215,7 @@ namespace dawn_native { namespace vulkan {
vkFunctions.EnumeratePhysicalDevices(instance, &count, physicalDevices.data()), vkFunctions.EnumeratePhysicalDevices(instance, &count, physicalDevices.data()),
"vkEnumeratePhysicalDevices")); "vkEnumeratePhysicalDevices"));
return physicalDevices; return std::move(physicalDevices);
} }
ResultOrError<VulkanDeviceInfo> GatherDeviceInfo(const Adapter& adapter) { ResultOrError<VulkanDeviceInfo> GatherDeviceInfo(const Adapter& adapter) {
@ -321,7 +321,7 @@ namespace dawn_native { namespace vulkan {
// TODO(cwallez@chromium.org): gather info about formats // TODO(cwallez@chromium.org): gather info about formats
return info; return std::move(info);
} }
ResultOrError<VulkanSurfaceInfo> GatherSurfaceInfo(const Adapter& adapter, ResultOrError<VulkanSurfaceInfo> GatherSurfaceInfo(const Adapter& adapter,
@ -382,7 +382,7 @@ namespace dawn_native { namespace vulkan {
"vkGetPhysicalDeviceSurfacePresentModesKHR")); "vkGetPhysicalDeviceSurfacePresentModesKHR"));
} }
return info; return std::move(info);
} }
}} // namespace dawn_native::vulkan }} // namespace dawn_native::vulkan

View File

@ -689,13 +689,15 @@
#define INTERNAL_TRACE_EVENT_ADD_SCOPED(platform, category, name, ...) \ #define INTERNAL_TRACE_EVENT_ADD_SCOPED(platform, category, name, ...) \
INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, ::dawn_platform::TraceCategory::category) \ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, ::dawn_platform::TraceCategory::category) \
dawn_platform::TraceEvent::TraceEndOnScopeClose INTERNALTRACEEVENTUID(profileScope); \ dawn_platform::TraceEvent::TraceEndOnScopeClose INTERNALTRACEEVENTUID(profileScope); \
do { \
if (*INTERNALTRACEEVENTUID(catstatic)) { \ if (*INTERNALTRACEEVENTUID(catstatic)) { \
dawn_platform::TraceEvent::addTraceEvent( \ dawn_platform::TraceEvent::addTraceEvent( \
platform, TRACE_EVENT_PHASE_BEGIN, INTERNALTRACEEVENTUID(catstatic), name, \ platform, TRACE_EVENT_PHASE_BEGIN, INTERNALTRACEEVENTUID(catstatic), name, \
dawn_platform::TraceEvent::noEventId, TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ dawn_platform::TraceEvent::noEventId, TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \
INTERNALTRACEEVENTUID(profileScope) \ INTERNALTRACEEVENTUID(profileScope) \
.initialize(platform, INTERNALTRACEEVENTUID(catstatic), name); \ .initialize(platform, INTERNALTRACEEVENTUID(catstatic), name); \
} } \
} while (0)
// Implementation detail: internal macro to create static category and add // Implementation detail: internal macro to create static category and add
// event if the category is enabled. // event if the category is enabled.

View File

@ -63,7 +63,7 @@
StartExpectDeviceError(); \ StartExpectDeviceError(); \
statement; \ statement; \
FlushWire(); \ FlushWire(); \
ASSERT_TRUE(EndExpectDeviceError()); ASSERT_TRUE(EndExpectDeviceError())
struct RGBA8 { struct RGBA8 {
constexpr RGBA8() : RGBA8(0, 0, 0, 0) { constexpr RGBA8() : RGBA8(0, 0, 0, 0) {
@ -315,11 +315,13 @@ class DawnTestBase {
// Skip a test when the given condition is satisfied. // Skip a test when the given condition is satisfied.
#define DAWN_SKIP_TEST_IF(condition) \ #define DAWN_SKIP_TEST_IF(condition) \
do { \
if (condition) { \ if (condition) { \
dawn::InfoLog() << "Test skipped: " #condition "."; \ dawn::InfoLog() << "Test skipped: " #condition "."; \
GTEST_SKIP(); \ GTEST_SKIP(); \
return; \ return; \
} } \
} while (0)
template <typename Params = DawnTestParam> template <typename Params = DawnTestParam>
class DawnTestWithParams : public DawnTestBase, public ::testing::TestWithParam<Params> { class DawnTestWithParams : public DawnTestBase, public ::testing::TestWithParam<Params> {

View File

@ -19,6 +19,7 @@
#include "utils/WGPUHelpers.h" #include "utils/WGPUHelpers.h"
#define EXPECT_LAZY_CLEAR(N, statement) \ #define EXPECT_LAZY_CLEAR(N, statement) \
do { \
if (UsesWire()) { \ if (UsesWire()) { \
statement; \ statement; \
} else { \ } else { \
@ -26,7 +27,8 @@
statement; \ statement; \
size_t lazyClearsAfter = dawn_native::GetLazyClearCountForTesting(device.Get()); \ size_t lazyClearsAfter = dawn_native::GetLazyClearCountForTesting(device.Get()); \
EXPECT_EQ(N, lazyClearsAfter - lazyClearsBefore); \ EXPECT_EQ(N, lazyClearsAfter - lazyClearsBefore); \
} } \
} while (0)
class TextureZeroInitTest : public DawnTest { class TextureZeroInitTest : public DawnTest {
protected: protected:

View File

@ -22,7 +22,7 @@
#define ASSERT_DEVICE_ERROR(statement) \ #define ASSERT_DEVICE_ERROR(statement) \
StartExpectDeviceError(); \ StartExpectDeviceError(); \
statement; \ statement; \
ASSERT_TRUE(EndExpectDeviceError()); ASSERT_TRUE(EndExpectDeviceError())
class ValidationTest : public testing::Test { class ValidationTest : public testing::Test {
public: public:

View File

@ -194,7 +194,7 @@ TEST_P(D3D12ResidencyTests, OvercommitLargeResources) {
TEST_P(D3D12ResidencyTests, AsyncMappedBufferRead) { TEST_P(D3D12ResidencyTests, AsyncMappedBufferRead) {
// Dawn currently only manages LOCAL_MEMORY. Mappable buffers exist in NON_LOCAL_MEMORY on // Dawn currently only manages LOCAL_MEMORY. Mappable buffers exist in NON_LOCAL_MEMORY on
// discrete devices. // discrete devices.
DAWN_SKIP_TEST_IF(!IsUMA()) DAWN_SKIP_TEST_IF(!IsUMA());
// Create a mappable buffer. // Create a mappable buffer.
wgpu::Buffer buffer = CreateBuffer(4, wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst); wgpu::Buffer buffer = CreateBuffer(4, wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst);
@ -239,7 +239,7 @@ TEST_P(D3D12ResidencyTests, AsyncMappedBufferRead) {
TEST_P(D3D12ResidencyTests, AsyncMappedBufferWrite) { TEST_P(D3D12ResidencyTests, AsyncMappedBufferWrite) {
// Dawn currently only manages LOCAL_MEMORY. Mappable buffers exist in NON_LOCAL_MEMORY on // Dawn currently only manages LOCAL_MEMORY. Mappable buffers exist in NON_LOCAL_MEMORY on
// discrete devices. // discrete devices.
DAWN_SKIP_TEST_IF(!IsUMA()) DAWN_SKIP_TEST_IF(!IsUMA());
// Create a mappable buffer. // Create a mappable buffer.
wgpu::Buffer buffer = CreateBuffer(4, wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc); wgpu::Buffer buffer = CreateBuffer(4, wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc);

View File

@ -61,7 +61,7 @@ namespace utils {
std::make_unique<wgpu::SurfaceDescriptorFromWindowsHWND>(); std::make_unique<wgpu::SurfaceDescriptorFromWindowsHWND>();
desc->hwnd = glfwGetWin32Window(window); desc->hwnd = glfwGetWin32Window(window);
desc->hinstance = GetModuleHandle(nullptr); desc->hinstance = GetModuleHandle(nullptr);
return desc; return std::move(desc);
} }
#elif defined(DAWN_USE_X11) #elif defined(DAWN_USE_X11)
std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptorForTesting( std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptorForTesting(
@ -70,7 +70,7 @@ namespace utils {
std::make_unique<wgpu::SurfaceDescriptorFromXlib>(); std::make_unique<wgpu::SurfaceDescriptorFromXlib>();
desc->display = glfwGetX11Display(); desc->display = glfwGetX11Display();
desc->window = glfwGetX11Window(window); desc->window = glfwGetX11Window(window);
return desc; return std::move(desc);
} }
#elif defined(DAWN_ENABLE_BACKEND_METAL) #elif defined(DAWN_ENABLE_BACKEND_METAL)
// SetupWindowAndGetSurfaceDescriptorForTesting defined in GLFWUtils_metal.mm // SetupWindowAndGetSurfaceDescriptorForTesting defined in GLFWUtils_metal.mm

View File

@ -45,7 +45,7 @@ namespace utils {
std::unique_ptr<wgpu::SurfaceDescriptorFromMetalLayer> desc = std::unique_ptr<wgpu::SurfaceDescriptorFromMetalLayer> desc =
std::make_unique<wgpu::SurfaceDescriptorFromMetalLayer>(); std::make_unique<wgpu::SurfaceDescriptorFromMetalLayer>();
desc->layer = [view layer]; desc->layer = [view layer];
return desc; return std::move(desc);
} }
return nullptr; return nullptr;