5#include "flutter/fml/synchronization/waitable_event.h"
6#include "flutter/testing/testing.h"
16TEST(ContextVKTest, CommonHardwareConcurrencyConfigurations) {
29TEST(ContextVKTest, DeletesCommandPools) {
30 std::weak_ptr<ContextVK> weak_context;
31 std::weak_ptr<CommandPoolVK> weak_pool;
34 auto const pool = context->GetCommandPoolRecycler()->Get();
36 weak_context = context;
37 ASSERT_TRUE(weak_pool.lock());
38 ASSERT_TRUE(weak_context.lock());
40 ASSERT_FALSE(weak_pool.lock());
41 ASSERT_FALSE(weak_context.lock());
44TEST(ContextVKTest, DeletesCommandPoolsOnAllThreads) {
45 std::weak_ptr<ContextVK> weak_context;
46 std::weak_ptr<CommandPoolVK> weak_pool_main;
49 weak_pool_main = context->GetCommandPoolRecycler()->Get();
50 weak_context = context;
51 ASSERT_TRUE(weak_pool_main.lock());
52 ASSERT_TRUE(weak_context.lock());
56 std::weak_ptr<CommandPoolVK> weak_pool_thread;
57 std::thread thread([&]() {
58 weak_pool_thread = context->GetCommandPoolRecycler()->
Get();
66 ASSERT_FALSE(weak_pool_main.lock());
67 ASSERT_FALSE(weak_context.lock());
72 ASSERT_FALSE(weak_pool_thread.lock());
75TEST(ContextVKTest, DeletePipelineAfterContext) {
76 std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline;
77 std::shared_ptr<std::vector<std::string>> functions;
83 context->GetPipelineLibrary()->GetPipeline(pipeline_desc);
84 pipeline = pipeline_future.
Get();
85 ASSERT_TRUE(pipeline);
87 ASSERT_TRUE(
std::find(functions->begin(), functions->end(),
88 "vkCreateGraphicsPipelines") != functions->end());
90 ASSERT_TRUE(
std::find(functions->begin(), functions->end(),
91 "vkDestroyDevice") != functions->end());
94TEST(ContextVKTest, DeleteShaderFunctionAfterContext) {
95 std::shared_ptr<const ShaderFunction> shader_function;
96 std::shared_ptr<std::vector<std::string>> functions;
101 std::vector<uint8_t>
data = {0x03, 0x02, 0x23, 0x07};
102 context->GetShaderLibrary()->RegisterFunction(
104 std::make_shared<fml::DataMapping>(
data), [](
bool) {});
105 shader_function = context->GetShaderLibrary()->GetFunction(
107 ASSERT_TRUE(shader_function);
109 ASSERT_TRUE(
std::find(functions->begin(), functions->end(),
110 "vkCreateShaderModule") != functions->end());
112 ASSERT_TRUE(
std::find(functions->begin(), functions->end(),
113 "vkDestroyDevice") != functions->end());
116TEST(ContextVKTest, DeletePipelineLibraryAfterContext) {
117 std::shared_ptr<PipelineLibrary> pipeline_library;
118 std::shared_ptr<std::vector<std::string>> functions;
123 pipeline_library = context->GetPipelineLibrary();
125 ASSERT_TRUE(
std::find(functions->begin(), functions->end(),
126 "vkCreatePipelineCache") != functions->end());
128 ASSERT_TRUE(
std::find(functions->begin(), functions->end(),
129 "vkDestroyDevice") != functions->end());
132TEST(ContextVKTest, CanCreateContextInAbsenceOfValidationLayers) {
140 ASSERT_NE(context,
nullptr);
142 reinterpret_cast<const CapabilitiesVK*
>(context->GetCapabilities().get());
146TEST(ContextVKTest, CanCreateContextWithValidationLayers) {
151 .SetInstanceExtensions(
152 {
"VK_KHR_surface",
"VK_MVK_macos_surface",
"VK_EXT_debug_utils"})
153 .SetInstanceLayers({
"VK_LAYER_KHRONOS_validation"})
155 ASSERT_NE(context,
nullptr);
157 reinterpret_cast<const CapabilitiesVK*
>(context->GetCapabilities().get());
164TEST(CapabilitiesVKTest, ContextInitializesWithNoStencilFormat) {
165 const std::shared_ptr<ContextVK> context =
173 vk::FormatFeatureFlagBits::eColorAttachment);
177 vk::FormatFeatureFlagBits::eDepthStencilAttachment);
182 ASSERT_NE(context,
nullptr);
184 reinterpret_cast<const CapabilitiesVK*
>(context->GetCapabilities().get());
196 ContextFailsInitializationForNoCombinedDepthStencilFormat) {
198 const std::shared_ptr<ContextVK> context =
206 vk::FormatFeatureFlagBits::eColorAttachment);
211 ASSERT_EQ(context,
nullptr);
214TEST(ContextVKTest, WarmUpFunctionCreatesRenderPass) {
218 context->InitializeCommonlyUsedShadersIfNeeded();
221 ASSERT_TRUE(
std::find(functions->begin(), functions->end(),
222 "vkCreateRenderPass") != functions->end());
225TEST(ContextVKTest, FatalMissingValidations) {
226 EXPECT_DEATH(
const std::shared_ptr<ContextVK> context =
230 settings.fatal_missing_validations =
true;
236TEST(ContextVKTest, HasDefaultColorFormat) {
240 reinterpret_cast<const CapabilitiesVK*
>(context->GetCapabilities().get());
int find(T *array, int N, T item)
The Vulkan layers and extensions wrangler.
bool AreValidationsEnabled() const
PixelFormat GetDefaultStencilFormat() const override
Returns a supported PixelFormat for textures that store stencil information. May include a depth chan...
PixelFormat GetDefaultDepthStencilFormat() const override
Returns a supported PixelFormat for textures that store both a stencil and depth component....
PixelFormat GetDefaultColorFormat() const override
Returns a supported PixelFormat for textures that store 4-channel colors (red/green/blue/alpha).
static size_t ChooseThreadCountForWorkers(size_t hardware_concurrency)
PipelineDescriptor & SetVertexDescriptor(std::shared_ptr< VertexDescriptor > vertex_descriptor)
std::shared_ptr< ContextVK > Build()
Create a Vulkan context with Vulkan functions mocked. The caller is given a chance to tinker on the s...
MockVulkanContextBuilder & SetPhysicalDeviceFormatPropertiesCallback(std::function< void(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties *pFormatProperties)> format_properties_callback)
MockVulkanContextBuilder & SetSettingsCallback(const std::function< void(ContextVK::Settings &)> &settings_callback)
uint32_t uint32_t * format
const GrXPFactory * Get(SkBlendMode mode)
def Build(configs, env, options)
std::shared_ptr< std::vector< std::string > > GetMockVulkanFunctions(VkDevice device)
TEST(AiksCanvasTest, EmptyCullRect)
const std::shared_ptr< Pipeline< T > > Get() const
std::shared_ptr< const fml::Mapping > data
VkFlags VkFormatFeatureFlags
@ VK_FORMAT_R8G8B8A8_UNORM
@ VK_FORMAT_D32_SFLOAT_S8_UINT