[Impeller] Made other vulkan objects cleanup properly. (flutter/engine#42113)
fixes https://github.com/flutter/flutter/issues/127058 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -278,7 +278,10 @@ void ContextVK::Setup(Settings settings) {
|
||||
VALIDATION_LOG << "Could not create logical device.";
|
||||
return;
|
||||
}
|
||||
vk::UniqueDevice device = std::move(device_result.value);
|
||||
device_ = std::move(device_result.value);
|
||||
// This makes sure that the device is deleted at the proper time if there is
|
||||
// an error.
|
||||
fml::ScopedCleanupClosure device_resetter([this]() { device_.reset(); });
|
||||
|
||||
if (!caps->SetDevice(physical_device.value())) {
|
||||
VALIDATION_LOG << "Capabilities could not be updated.";
|
||||
@@ -292,7 +295,7 @@ void ContextVK::Setup(Settings settings) {
|
||||
weak_from_this(), //
|
||||
application_info.apiVersion, //
|
||||
physical_device.value(), //
|
||||
device.get(), //
|
||||
device_.get(), //
|
||||
instance.value.get(), //
|
||||
dispatcher.vkGetInstanceProcAddr, //
|
||||
dispatcher.vkGetDeviceProcAddr //
|
||||
@@ -307,8 +310,7 @@ void ContextVK::Setup(Settings settings) {
|
||||
/// Setup the pipeline library.
|
||||
///
|
||||
auto pipeline_library = std::shared_ptr<PipelineLibraryVK>(
|
||||
new PipelineLibraryVK(weak_from_this(), //
|
||||
device.get(), //
|
||||
new PipelineLibraryVK(shared_from_this(), //
|
||||
caps, //
|
||||
std::move(settings.cache_directory), //
|
||||
settings.worker_task_runner //
|
||||
@@ -320,10 +322,10 @@ void ContextVK::Setup(Settings settings) {
|
||||
}
|
||||
|
||||
auto sampler_library =
|
||||
std::shared_ptr<SamplerLibraryVK>(new SamplerLibraryVK(device.get()));
|
||||
std::shared_ptr<SamplerLibraryVK>(new SamplerLibraryVK(device_.get()));
|
||||
|
||||
auto shader_library = std::shared_ptr<ShaderLibraryVK>(
|
||||
new ShaderLibraryVK(device.get(), //
|
||||
new ShaderLibraryVK(weak_from_this(), //
|
||||
settings.shader_libraries_data) //
|
||||
);
|
||||
|
||||
@@ -336,7 +338,7 @@ void ContextVK::Setup(Settings settings) {
|
||||
/// Create the fence waiter.
|
||||
///
|
||||
auto fence_waiter =
|
||||
std::shared_ptr<FenceWaiterVK>(new FenceWaiterVK(device.get()));
|
||||
std::shared_ptr<FenceWaiterVK>(new FenceWaiterVK(device_.get()));
|
||||
if (!fence_waiter->IsValid()) {
|
||||
VALIDATION_LOG << "Could not create fence waiter.";
|
||||
return;
|
||||
@@ -345,7 +347,7 @@ void ContextVK::Setup(Settings settings) {
|
||||
//----------------------------------------------------------------------------
|
||||
/// Fetch the queues.
|
||||
///
|
||||
QueuesVK queues(device.get(), //
|
||||
QueuesVK queues(device_.get(), //
|
||||
graphics_queue.value(), //
|
||||
compute_queue.value(), //
|
||||
transfer_queue.value() //
|
||||
@@ -365,7 +367,7 @@ void ContextVK::Setup(Settings settings) {
|
||||
instance_ = std::move(instance.value);
|
||||
debug_report_ = std::move(debug_report);
|
||||
physical_device_ = physical_device.value();
|
||||
device_ = std::move(device);
|
||||
device_resetter.Release();
|
||||
allocator_ = std::move(allocator);
|
||||
shader_library_ = std::move(shader_library);
|
||||
sampler_library_ = std::move(sampler_library);
|
||||
|
||||
@@ -26,5 +26,62 @@ TEST(ContextVKTest, DeletesCommandPools) {
|
||||
ASSERT_FALSE(weak_context.lock());
|
||||
}
|
||||
|
||||
TEST(ContextVKTest, DeletePipelineAfterContext) {
|
||||
std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline;
|
||||
std::shared_ptr<std::vector<std::string>> functions;
|
||||
{
|
||||
std::shared_ptr<ContextVK> context = CreateMockVulkanContext();
|
||||
PipelineDescriptor pipeline_desc;
|
||||
pipeline_desc.SetVertexDescriptor(std::make_shared<VertexDescriptor>());
|
||||
PipelineFuture<PipelineDescriptor> pipeline_future =
|
||||
context->GetPipelineLibrary()->GetPipeline(pipeline_desc);
|
||||
pipeline = pipeline_future.Get();
|
||||
ASSERT_TRUE(pipeline);
|
||||
functions = GetMockVulkanFunctions(context->GetDevice());
|
||||
ASSERT_TRUE(std::find(functions->begin(), functions->end(),
|
||||
"vkCreateGraphicsPipelines") != functions->end());
|
||||
}
|
||||
ASSERT_TRUE(std::find(functions->begin(), functions->end(),
|
||||
"vkDestroyDevice") != functions->end());
|
||||
}
|
||||
|
||||
TEST(ContextVKTest, DeleteShaderFunctionAfterContext) {
|
||||
std::shared_ptr<const ShaderFunction> shader_function;
|
||||
std::shared_ptr<std::vector<std::string>> functions;
|
||||
{
|
||||
std::shared_ptr<ContextVK> context = CreateMockVulkanContext();
|
||||
PipelineDescriptor pipeline_desc;
|
||||
pipeline_desc.SetVertexDescriptor(std::make_shared<VertexDescriptor>());
|
||||
std::vector<uint8_t> data = {0x03, 0x02, 0x23, 0x07};
|
||||
context->GetShaderLibrary()->RegisterFunction(
|
||||
"foobar", ShaderStage::kFragment,
|
||||
std::make_shared<fml::DataMapping>(data), [](bool) {});
|
||||
shader_function = context->GetShaderLibrary()->GetFunction(
|
||||
"foobar_fragment_main", ShaderStage::kFragment);
|
||||
ASSERT_TRUE(shader_function);
|
||||
functions = GetMockVulkanFunctions(context->GetDevice());
|
||||
ASSERT_TRUE(std::find(functions->begin(), functions->end(),
|
||||
"vkCreateShaderModule") != functions->end());
|
||||
}
|
||||
ASSERT_TRUE(std::find(functions->begin(), functions->end(),
|
||||
"vkDestroyDevice") != functions->end());
|
||||
}
|
||||
|
||||
TEST(ContextVKTest, DeletePipelineLibraryAfterContext) {
|
||||
std::shared_ptr<PipelineLibrary> pipeline_library;
|
||||
std::shared_ptr<std::vector<std::string>> functions;
|
||||
{
|
||||
std::shared_ptr<ContextVK> context = CreateMockVulkanContext();
|
||||
PipelineDescriptor pipeline_desc;
|
||||
pipeline_desc.SetVertexDescriptor(std::make_shared<VertexDescriptor>());
|
||||
pipeline_library = context->GetPipelineLibrary();
|
||||
functions = GetMockVulkanFunctions(context->GetDevice());
|
||||
ASSERT_TRUE(std::find(functions->begin(), functions->end(),
|
||||
"vkCreatePipelineCache") != functions->end());
|
||||
}
|
||||
ASSERT_TRUE(std::find(functions->begin(), functions->end(),
|
||||
"vkDestroyDevice") != functions->end());
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
|
||||
@@ -53,13 +53,12 @@ static std::unique_ptr<fml::Mapping> OpenCacheFile(
|
||||
}
|
||||
|
||||
PipelineCacheVK::PipelineCacheVK(std::shared_ptr<const Capabilities> caps,
|
||||
std::weak_ptr<DeviceHolder> device_holder,
|
||||
const vk::Device& device,
|
||||
std::shared_ptr<DeviceHolder> device_holder,
|
||||
fml::UniqueFD cache_directory)
|
||||
: caps_(std::move(caps)),
|
||||
device_holder_(device_holder),
|
||||
cache_directory_(std::move(cache_directory)) {
|
||||
if (!caps_ || !device) {
|
||||
if (!caps_ || !device_holder->GetDevice()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,7 +80,8 @@ PipelineCacheVK::PipelineCacheVK(std::shared_ptr<const Capabilities> caps,
|
||||
cache_info.pInitialData = existing_cache_data->GetMapping();
|
||||
}
|
||||
|
||||
auto [result, existing_cache] = device.createPipelineCacheUnique(cache_info);
|
||||
auto [result, existing_cache] =
|
||||
device_holder->GetDevice().createPipelineCacheUnique(cache_info);
|
||||
|
||||
if (result == vk::Result::eSuccess) {
|
||||
cache_ = std::move(existing_cache);
|
||||
@@ -93,7 +93,8 @@ PipelineCacheVK::PipelineCacheVK(std::shared_ptr<const Capabilities> caps,
|
||||
<< vk::to_string(result) << ". Starting with a fresh cache.";
|
||||
cache_info.pInitialData = nullptr;
|
||||
cache_info.initialDataSize = 0u;
|
||||
auto [result2, new_cache] = device.createPipelineCacheUnique(cache_info);
|
||||
auto [result2, new_cache] =
|
||||
device_holder->GetDevice().createPipelineCacheUnique(cache_info);
|
||||
if (result2 == vk::Result::eSuccess) {
|
||||
cache_ = std::move(new_cache);
|
||||
} else {
|
||||
@@ -105,7 +106,14 @@ PipelineCacheVK::PipelineCacheVK(std::shared_ptr<const Capabilities> caps,
|
||||
is_valid_ = !!cache_;
|
||||
}
|
||||
|
||||
PipelineCacheVK::~PipelineCacheVK() = default;
|
||||
PipelineCacheVK::~PipelineCacheVK() {
|
||||
std::shared_ptr<DeviceHolder> device_holder = device_holder_.lock();
|
||||
if (device_holder) {
|
||||
cache_.reset();
|
||||
} else {
|
||||
cache_.release();
|
||||
}
|
||||
}
|
||||
|
||||
bool PipelineCacheVK::IsValid() const {
|
||||
return is_valid_;
|
||||
|
||||
@@ -20,8 +20,7 @@ class PipelineCacheVK {
|
||||
// at the time of executing `PipelineCacheVK` because of how `ContextVK` does
|
||||
// initialization.
|
||||
explicit PipelineCacheVK(std::shared_ptr<const Capabilities> caps,
|
||||
std::weak_ptr<DeviceHolder> device_holder,
|
||||
const vk::Device& device,
|
||||
std::shared_ptr<DeviceHolder> device_holder,
|
||||
fml::UniqueFD cache_directory);
|
||||
|
||||
~PipelineCacheVK();
|
||||
|
||||
@@ -19,15 +19,13 @@
|
||||
namespace impeller {
|
||||
|
||||
PipelineLibraryVK::PipelineLibraryVK(
|
||||
const std::weak_ptr<DeviceHolder>& device_holder,
|
||||
const vk::Device& device,
|
||||
const std::shared_ptr<DeviceHolder>& device_holder,
|
||||
std::shared_ptr<const Capabilities> caps,
|
||||
fml::UniqueFD cache_directory,
|
||||
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner)
|
||||
: device_holder_(device_holder),
|
||||
pso_cache_(std::make_shared<PipelineCacheVK>(std::move(caps),
|
||||
device_holder,
|
||||
device,
|
||||
std::move(cache_directory))),
|
||||
worker_task_runner_(std::move(worker_task_runner)) {
|
||||
if (!pso_cache_->IsValid() || !worker_task_runner_) {
|
||||
@@ -334,7 +332,8 @@ std::unique_ptr<PipelineVK> PipelineLibraryVK::CreatePipeline(
|
||||
ContextVK::SetDebugName(strong_device->GetDevice(), *pipeline,
|
||||
"Pipeline " + desc.GetLabel());
|
||||
|
||||
return std::make_unique<PipelineVK>(weak_from_this(), //
|
||||
return std::make_unique<PipelineVK>(device_holder_,
|
||||
weak_from_this(), //
|
||||
desc, //
|
||||
std::move(pipeline), //
|
||||
std::move(render_pass), //
|
||||
|
||||
@@ -43,8 +43,7 @@ class PipelineLibraryVK final
|
||||
bool is_valid_ = false;
|
||||
|
||||
PipelineLibraryVK(
|
||||
const std::weak_ptr<DeviceHolder>& device_holder,
|
||||
const vk::Device& device,
|
||||
const std::shared_ptr<DeviceHolder>& device_holder,
|
||||
std::shared_ptr<const Capabilities> caps,
|
||||
fml::UniqueFD cache_directory,
|
||||
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner);
|
||||
|
||||
@@ -6,13 +6,15 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
PipelineVK::PipelineVK(std::weak_ptr<PipelineLibrary> library,
|
||||
PipelineVK::PipelineVK(std::weak_ptr<DeviceHolder> device_holder,
|
||||
std::weak_ptr<PipelineLibrary> library,
|
||||
const PipelineDescriptor& desc,
|
||||
vk::UniquePipeline pipeline,
|
||||
vk::UniqueRenderPass render_pass,
|
||||
vk::UniquePipelineLayout layout,
|
||||
vk::UniqueDescriptorSetLayout descriptor_set_layout)
|
||||
: Pipeline(std::move(library), desc),
|
||||
device_holder_(device_holder),
|
||||
pipeline_(std::move(pipeline)),
|
||||
render_pass_(std::move(render_pass)),
|
||||
layout_(std::move(layout)),
|
||||
@@ -20,7 +22,20 @@ PipelineVK::PipelineVK(std::weak_ptr<PipelineLibrary> library,
|
||||
is_valid_ = pipeline_ && render_pass_ && layout_ && descriptor_set_layout_;
|
||||
}
|
||||
|
||||
PipelineVK::~PipelineVK() = default;
|
||||
PipelineVK::~PipelineVK() {
|
||||
std::shared_ptr<DeviceHolder> device_holder = device_holder_.lock();
|
||||
if (device_holder) {
|
||||
descriptor_set_layout_.reset();
|
||||
layout_.reset();
|
||||
render_pass_.reset();
|
||||
pipeline_.reset();
|
||||
} else {
|
||||
descriptor_set_layout_.release();
|
||||
layout_.release();
|
||||
render_pass_.release();
|
||||
pipeline_.release();
|
||||
}
|
||||
}
|
||||
|
||||
bool PipelineVK::IsValid() const {
|
||||
return is_valid_;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/base/backend_cast.h"
|
||||
#include "impeller/renderer/backend/vulkan/device_holder.h"
|
||||
#include "impeller/renderer/backend/vulkan/vk.h"
|
||||
#include "impeller/renderer/pipeline.h"
|
||||
|
||||
@@ -17,7 +18,8 @@ class PipelineVK final
|
||||
: public Pipeline<PipelineDescriptor>,
|
||||
public BackendCast<PipelineVK, Pipeline<PipelineDescriptor>> {
|
||||
public:
|
||||
PipelineVK(std::weak_ptr<PipelineLibrary> library,
|
||||
PipelineVK(std::weak_ptr<DeviceHolder> device_holder,
|
||||
std::weak_ptr<PipelineLibrary> library,
|
||||
const PipelineDescriptor& desc,
|
||||
vk::UniquePipeline pipeline,
|
||||
vk::UniqueRenderPass render_pass,
|
||||
@@ -38,10 +40,11 @@ class PipelineVK final
|
||||
private:
|
||||
friend class PipelineLibraryVK;
|
||||
|
||||
const vk::UniquePipeline pipeline_;
|
||||
const vk::UniqueRenderPass render_pass_;
|
||||
const vk::UniquePipelineLayout layout_;
|
||||
const vk::UniqueDescriptorSetLayout descriptor_set_layout_;
|
||||
std::weak_ptr<DeviceHolder> device_holder_;
|
||||
vk::UniquePipeline pipeline_;
|
||||
vk::UniqueRenderPass render_pass_;
|
||||
vk::UniquePipelineLayout layout_;
|
||||
vk::UniqueDescriptorSetLayout descriptor_set_layout_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
// |Pipeline|
|
||||
|
||||
@@ -6,14 +6,24 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
ShaderFunctionVK::ShaderFunctionVK(UniqueID parent_library_id,
|
||||
std::string name,
|
||||
ShaderStage stage,
|
||||
vk::UniqueShaderModule module)
|
||||
ShaderFunctionVK::ShaderFunctionVK(
|
||||
const std::weak_ptr<DeviceHolder>& device_holder,
|
||||
UniqueID parent_library_id,
|
||||
std::string name,
|
||||
ShaderStage stage,
|
||||
vk::UniqueShaderModule module)
|
||||
: ShaderFunction(parent_library_id, std::move(name), stage),
|
||||
module_(std::move(module)) {}
|
||||
module_(std::move(module)),
|
||||
device_holder_(device_holder) {}
|
||||
|
||||
ShaderFunctionVK::~ShaderFunctionVK() = default;
|
||||
ShaderFunctionVK::~ShaderFunctionVK() {
|
||||
std::shared_ptr<DeviceHolder> device_holder = device_holder_.lock();
|
||||
if (device_holder) {
|
||||
module_.reset();
|
||||
} else {
|
||||
module_.release();
|
||||
}
|
||||
}
|
||||
|
||||
const vk::ShaderModule& ShaderFunctionVK::GetModule() const {
|
||||
return module_.get();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/base/backend_cast.h"
|
||||
#include "impeller/renderer/backend/vulkan/device_holder.h"
|
||||
#include "impeller/renderer/backend/vulkan/shader_function_vk.h"
|
||||
#include "impeller/renderer/backend/vulkan/vk.h"
|
||||
#include "impeller/renderer/shader_function.h"
|
||||
@@ -25,8 +26,10 @@ class ShaderFunctionVK final
|
||||
friend class ShaderLibraryVK;
|
||||
|
||||
vk::UniqueShaderModule module_;
|
||||
std::weak_ptr<DeviceHolder> device_holder_;
|
||||
|
||||
ShaderFunctionVK(UniqueID parent_library_id,
|
||||
ShaderFunctionVK(const std::weak_ptr<DeviceHolder>& device_holder,
|
||||
UniqueID parent_library_id,
|
||||
std::string name,
|
||||
ShaderStage stage,
|
||||
vk::UniqueShaderModule module);
|
||||
|
||||
@@ -53,9 +53,9 @@ static std::string VKShaderNameToShaderKeyName(const std::string& name,
|
||||
}
|
||||
|
||||
ShaderLibraryVK::ShaderLibraryVK(
|
||||
const vk::Device& device,
|
||||
std::weak_ptr<DeviceHolder> device_holder,
|
||||
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data)
|
||||
: device_(device) {
|
||||
: device_holder_(device_holder) {
|
||||
TRACE_EVENT0("impeller", "CreateShaderLibrary");
|
||||
bool success = true;
|
||||
auto iterator = [&](auto type, //
|
||||
@@ -145,7 +145,13 @@ bool ShaderLibraryVK::RegisterFunction(
|
||||
reinterpret_cast<const uint32_t*>(code->GetMapping()));
|
||||
shader_module_info.setCodeSize(code->GetSize());
|
||||
|
||||
auto module = device_.createShaderModuleUnique(shader_module_info);
|
||||
auto device_holder = device_holder_.lock();
|
||||
if (!device_holder) {
|
||||
return false;
|
||||
}
|
||||
FML_DCHECK(device_holder->GetDevice());
|
||||
auto module =
|
||||
device_holder->GetDevice().createShaderModuleUnique(shader_module_info);
|
||||
|
||||
if (module.result != vk::Result::eSuccess) {
|
||||
VALIDATION_LOG << "Could not create shader module: "
|
||||
@@ -156,11 +162,13 @@ bool ShaderLibraryVK::RegisterFunction(
|
||||
const auto key_name = VKShaderNameToShaderKeyName(name, stage);
|
||||
|
||||
vk::UniqueShaderModule shader_module = std::move(module.value);
|
||||
ContextVK::SetDebugName(device_, *shader_module, "Shader " + name);
|
||||
ContextVK::SetDebugName(device_holder->GetDevice(), *shader_module,
|
||||
"Shader " + name);
|
||||
|
||||
WriterLock lock(functions_mutex_);
|
||||
functions_[ShaderKey{key_name, stage}] = std::shared_ptr<ShaderFunctionVK>(
|
||||
new ShaderFunctionVK(library_id_, //
|
||||
new ShaderFunctionVK(device_holder_,
|
||||
library_id_, //
|
||||
key_name, //
|
||||
stage, //
|
||||
std::move(shader_module) //
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/base/comparable.h"
|
||||
#include "impeller/base/thread.h"
|
||||
#include "impeller/renderer/backend/vulkan/device_holder.h"
|
||||
#include "impeller/renderer/backend/vulkan/vk.h"
|
||||
#include "impeller/renderer/shader_key.h"
|
||||
#include "impeller/renderer/shader_library.h"
|
||||
@@ -23,14 +24,14 @@ class ShaderLibraryVK final : public ShaderLibrary {
|
||||
|
||||
private:
|
||||
friend class ContextVK;
|
||||
const vk::Device device_;
|
||||
std::weak_ptr<DeviceHolder> device_holder_;
|
||||
const UniqueID library_id_;
|
||||
mutable RWMutex functions_mutex_;
|
||||
ShaderFunctionMap functions_ IPLR_GUARDED_BY(functions_mutex_);
|
||||
bool is_valid_ = false;
|
||||
|
||||
ShaderLibraryVK(
|
||||
const vk::Device& device,
|
||||
std::weak_ptr<DeviceHolder> device_holder,
|
||||
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data);
|
||||
|
||||
// |ShaderLibrary|
|
||||
|
||||
@@ -8,6 +8,12 @@ namespace impeller {
|
||||
namespace testing {
|
||||
|
||||
namespace {
|
||||
|
||||
struct MockDevice {
|
||||
MockDevice() : called_functions_(new std::vector<std::string>()) {}
|
||||
std::shared_ptr<std::vector<std::string>> called_functions_;
|
||||
};
|
||||
|
||||
void noop() {}
|
||||
|
||||
VkResult vkEnumerateInstanceExtensionProperties(
|
||||
@@ -97,7 +103,7 @@ VkResult vkCreateDevice(VkPhysicalDevice physicalDevice,
|
||||
const VkDeviceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkDevice* pDevice) {
|
||||
*pDevice = reinterpret_cast<VkDevice>(0xcafebabe);
|
||||
*pDevice = reinterpret_cast<VkDevice>(new MockDevice());
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -125,6 +131,8 @@ VkResult vkCreatePipelineCache(VkDevice device,
|
||||
const VkPipelineCacheCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkPipelineCache* pPipelineCache) {
|
||||
MockDevice* mock_device = reinterpret_cast<MockDevice*>(device);
|
||||
mock_device->called_functions_->push_back("vkCreatePipelineCache");
|
||||
*pPipelineCache = reinterpret_cast<VkPipelineCache>(0xb000dead);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
@@ -212,6 +220,81 @@ VkResult vkBindBufferMemory(VkDevice device,
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult vkCreateRenderPass(VkDevice device,
|
||||
const VkRenderPassCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkRenderPass* pRenderPass) {
|
||||
*pRenderPass = reinterpret_cast<VkRenderPass>(0x12341234);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult vkCreateDescriptorSetLayout(
|
||||
VkDevice device,
|
||||
const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkDescriptorSetLayout* pSetLayout) {
|
||||
*pSetLayout = reinterpret_cast<VkDescriptorSetLayout>(0x77777777);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult vkCreatePipelineLayout(VkDevice device,
|
||||
const VkPipelineLayoutCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkPipelineLayout* pPipelineLayout) {
|
||||
*pPipelineLayout = reinterpret_cast<VkPipelineLayout>(0x88888888);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult vkCreateGraphicsPipelines(
|
||||
VkDevice device,
|
||||
VkPipelineCache pipelineCache,
|
||||
uint32_t createInfoCount,
|
||||
const VkGraphicsPipelineCreateInfo* pCreateInfos,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkPipeline* pPipelines) {
|
||||
MockDevice* mock_device = reinterpret_cast<MockDevice*>(device);
|
||||
mock_device->called_functions_->push_back("vkCreateGraphicsPipelines");
|
||||
*pPipelines = reinterpret_cast<VkPipeline>(0x99999999);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
void vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) {
|
||||
MockDevice* mock_device = reinterpret_cast<MockDevice*>(device);
|
||||
mock_device->called_functions_->push_back("vkDestroyDevice");
|
||||
delete reinterpret_cast<MockDevice*>(device);
|
||||
}
|
||||
|
||||
void vkDestroyPipeline(VkDevice device,
|
||||
VkPipeline pipeline,
|
||||
const VkAllocationCallbacks* pAllocator) {
|
||||
MockDevice* mock_device = reinterpret_cast<MockDevice*>(device);
|
||||
mock_device->called_functions_->push_back("vkDestroyPipeline");
|
||||
}
|
||||
|
||||
VkResult vkCreateShaderModule(VkDevice device,
|
||||
const VkShaderModuleCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkShaderModule* pShaderModule) {
|
||||
MockDevice* mock_device = reinterpret_cast<MockDevice*>(device);
|
||||
mock_device->called_functions_->push_back("vkCreateShaderModule");
|
||||
*pShaderModule = reinterpret_cast<VkShaderModule>(0x11111111);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
void vkDestroyShaderModule(VkDevice device,
|
||||
VkShaderModule shaderModule,
|
||||
const VkAllocationCallbacks* pAllocator) {
|
||||
MockDevice* mock_device = reinterpret_cast<MockDevice*>(device);
|
||||
mock_device->called_functions_->push_back("vkDestroyShaderModule");
|
||||
}
|
||||
|
||||
void vkDestroyPipelineCache(VkDevice device,
|
||||
VkPipelineCache pipelineCache,
|
||||
const VkAllocationCallbacks* pAllocator) {
|
||||
MockDevice* mock_device = reinterpret_cast<MockDevice*>(device);
|
||||
mock_device->called_functions_->push_back("vkDestroyPipelineCache");
|
||||
}
|
||||
|
||||
PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance,
|
||||
const char* pName) {
|
||||
if (strcmp("vkEnumerateInstanceExtensionProperties", pName) == 0) {
|
||||
@@ -264,6 +347,24 @@ PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance,
|
||||
return (PFN_vkVoidFunction)vkGetBufferMemoryRequirements2KHR;
|
||||
} else if (strcmp("vkBindBufferMemory", pName) == 0) {
|
||||
return (PFN_vkVoidFunction)vkBindBufferMemory;
|
||||
} else if (strcmp("vkCreateRenderPass", pName) == 0) {
|
||||
return (PFN_vkVoidFunction)vkCreateRenderPass;
|
||||
} else if (strcmp("vkCreateDescriptorSetLayout", pName) == 0) {
|
||||
return (PFN_vkVoidFunction)vkCreateDescriptorSetLayout;
|
||||
} else if (strcmp("vkCreatePipelineLayout", pName) == 0) {
|
||||
return (PFN_vkVoidFunction)vkCreatePipelineLayout;
|
||||
} else if (strcmp("vkCreateGraphicsPipelines", pName) == 0) {
|
||||
return (PFN_vkVoidFunction)vkCreateGraphicsPipelines;
|
||||
} else if (strcmp("vkDestroyDevice", pName) == 0) {
|
||||
return (PFN_vkVoidFunction)vkDestroyDevice;
|
||||
} else if (strcmp("vkDestroyPipeline", pName) == 0) {
|
||||
return (PFN_vkVoidFunction)vkDestroyPipeline;
|
||||
} else if (strcmp("vkCreateShaderModule", pName) == 0) {
|
||||
return (PFN_vkVoidFunction)vkCreateShaderModule;
|
||||
} else if (strcmp("vkDestroyShaderModule", pName) == 0) {
|
||||
return (PFN_vkVoidFunction)vkDestroyShaderModule;
|
||||
} else if (strcmp("vkDestroyPipelineCache", pName) == 0) {
|
||||
return (PFN_vkVoidFunction)vkDestroyPipelineCache;
|
||||
}
|
||||
return noop;
|
||||
}
|
||||
@@ -279,5 +380,11 @@ std::shared_ptr<ContextVK> CreateMockVulkanContext(void) {
|
||||
return ContextVK::Create(std::move(settings));
|
||||
}
|
||||
|
||||
std::shared_ptr<std::vector<std::string>> GetMockVulkanFunctions(
|
||||
VkDevice device) {
|
||||
MockDevice* mock_device = reinterpret_cast<MockDevice*>(device);
|
||||
return mock_device->called_functions_;
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
|
||||
@@ -4,12 +4,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "impeller/renderer/backend/vulkan/context_vk.h"
|
||||
|
||||
namespace impeller {
|
||||
namespace testing {
|
||||
|
||||
std::shared_ptr<std::vector<std::string>> GetMockVulkanFunctions(
|
||||
VkDevice device);
|
||||
|
||||
std::shared_ptr<ContextVK> CreateMockVulkanContext(void);
|
||||
|
||||
}
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
|
||||
Reference in New Issue
Block a user