Skip to content

Commit

Permalink
[Impeller] fail CI if validations are enabled but not available. (flu…
Browse files Browse the repository at this point in the history
…tter#51378)

Fixes flutter/flutter#145041

Will test this by unsetting the VVL configuration
  • Loading branch information
jonahwilliams authored Apr 5, 2024
1 parent d048b9a commit 62df3bd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions impeller/playground/backend/vulkan/playground_impl_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ PlaygroundImplVK::PlaygroundImplVK(PlaygroundSwitches switches)
context_settings.shader_libraries_data = ShaderLibraryMappingsForPlayground();
context_settings.cache_directory = fml::paths::GetCachesDirectory();
context_settings.enable_validation = switches_.enable_vulkan_validation;
context_settings.fatal_missing_validations =
switches_.enable_vulkan_validation;
;

auto context_vk = ContextVK::Create(std::move(context_settings));
if (!context_vk || !context_vk->IsValid()) {
Expand Down
6 changes: 5 additions & 1 deletion impeller/renderer/backend/vulkan/capabilities_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace impeller {

static constexpr const char* kInstanceLayer = "ImpellerInstance";

CapabilitiesVK::CapabilitiesVK(bool enable_validations) {
CapabilitiesVK::CapabilitiesVK(bool enable_validations,
bool fatal_missing_validations) {
auto extensions = vk::enumerateInstanceExtensionProperties();
auto layers = vk::enumerateInstanceLayerProperties();

Expand Down Expand Up @@ -45,6 +46,9 @@ CapabilitiesVK::CapabilitiesVK(bool enable_validations) {
<< "Requested Impeller context creation with validations but the "
"validation layers could not be found. Expect no Vulkan validation "
"checks!";
if (fatal_missing_validations) {
FML_LOG(FATAL) << "Validation missing. Exiting.";
}
}
if (validations_enabled_) {
FML_LOG(INFO) << "Vulkan validations are enabled.";
Expand Down
3 changes: 2 additions & 1 deletion impeller/renderer/backend/vulkan/capabilities_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ enum class OptionalDeviceExtensionVK : uint32_t {
class CapabilitiesVK final : public Capabilities,
public BackendCast<CapabilitiesVK, Capabilities> {
public:
explicit CapabilitiesVK(bool enable_validations);
explicit CapabilitiesVK(bool enable_validations,
bool fatal_missing_validations = false);

~CapabilitiesVK();

Expand Down
4 changes: 2 additions & 2 deletions impeller/renderer/backend/vulkan/context_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ void ContextVK::Setup(Settings settings) {
enable_validation = true;
#endif

auto caps =
std::shared_ptr<CapabilitiesVK>(new CapabilitiesVK(enable_validation));
auto caps = std::shared_ptr<CapabilitiesVK>(new CapabilitiesVK(
enable_validation, settings.fatal_missing_validations));

if (!caps->IsValid()) {
VALIDATION_LOG << "Could not determine device capabilities.";
Expand Down
2 changes: 2 additions & 0 deletions impeller/renderer/backend/vulkan/context_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class ContextVK final : public Context,
fml::UniqueFD cache_directory;
bool enable_validation = false;
bool enable_gpu_tracing = false;
/// If validations are requested but cannot be enabled, log a fatal error.
bool fatal_missing_validations = false;

Settings() = default;

Expand Down
11 changes: 11 additions & 0 deletions impeller/renderer/backend/vulkan/context_vk_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ TEST(ContextVKTest, WarmUpFunctionCreatesRenderPass) {
"vkCreateRenderPass") != functions->end());
}

TEST(ContextVKTest, FatalMissingValidations) {
EXPECT_DEATH(const std::shared_ptr<ContextVK> context =
MockVulkanContextBuilder()
.SetSettingsCallback([](ContextVK::Settings& settings) {
settings.enable_validation = true;
settings.fatal_missing_validations = true;
})
.Build(),
"");
}

TEST(ContextVKTest, HasDefaultColorFormat) {
std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();

Expand Down

0 comments on commit 62df3bd

Please sign in to comment.