Hash :
7a85d114
Author :
Date :
2022-03-25T15:01:17
Use [[nodiscard]] on RAII classes
Scoped* classes provide an RAII way of adding cleanup/restore state/etc
in a robust way. Unfortunatley, it's very easy to mistakenly leave the
variable name, leading to the destructor being called immediately
instead of at the end of the scope:
{
ScopedX(parameters); // instead of ScopedX x(parameters);
// Code here is run after destructor
}
The [[nodiscard]] attribute, if specified on the ScopedX class would
lead to a warning (turned to error with -Werror). This change does
that for classes named *Scoped* in ANGLE.
Bug: chromium:1103817
Change-Id: I65c9922c9b4eba1f9c033e093fe8fe534648ab62
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3552092
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
//
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// vulkan_icd.h : Helper for creating vulkan instances & selecting physical device.
#ifndef COMMON_VULKAN_VULKAN_ICD_H_
#define COMMON_VULKAN_VULKAN_ICD_H_
#include <string>
#include "common/Optional.h"
#include "common/angleutils.h"
#include "common/vulkan/vk_headers.h"
namespace angle
{
namespace vk
{
enum class ICD
{
Default,
Mock,
SwiftShader,
};
struct SimpleDisplayWindow
{
uint16_t width;
uint16_t height;
};
class ANGLE_NO_DISCARD ScopedVkLoaderEnvironment : angle::NonCopyable
{
public:
ScopedVkLoaderEnvironment(bool enableValidationLayers, vk::ICD icd);
~ScopedVkLoaderEnvironment();
bool canEnableValidationLayers() const { return mEnableValidationLayers; }
vk::ICD getEnabledICD() const { return mICD; }
private:
bool setICDEnvironment(const char *icd);
bool setCustomExtensionsEnvironment();
bool mEnableValidationLayers;
vk::ICD mICD;
bool mChangedCWD;
Optional<std::string> mPreviousCWD;
bool mChangedICDEnv;
Optional<std::string> mPreviousICDEnv;
Optional<std::string> mPreviousCustomExtensionsEnv;
bool mChangedNoDeviceSelect;
Optional<std::string> mPreviousNoDeviceSelectEnv;
};
void ChoosePhysicalDevice(PFN_vkGetPhysicalDeviceProperties pGetPhysicalDeviceProperties,
const std::vector<VkPhysicalDevice> &physicalDevices,
vk::ICD preferredICD,
VkPhysicalDevice *physicalDeviceOut,
VkPhysicalDeviceProperties *physicalDevicePropertiesOut);
} // namespace vk
} // namespace angle
#endif // COMMON_VULKAN_VULKAN_ICD_H_