blob: a0c5e3a3cc333d1e675757738748eb953202b831 [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef LIB_ESCHER_TEST_FAKE_GPU_ALLOCATOR_H_
#define LIB_ESCHER_TEST_FAKE_GPU_ALLOCATOR_H_
#include <vulkan/vulkan.hpp>
#include "lib/escher/vk/gpu_allocator.h"
namespace escher {
namespace test {
// This fake gpu allocator does not have a dependency on a functional
// vk::Device. It will make objects with mapped memory, but without working
// Vulkan objects. This should be sufficient for tests that push bits in buffers
// or manage object lifetimes, but will not work for tests that actually want to
// execute Vulkan commands.
//
// All three factory methods can be called with a null ResourceManager.
//
// AllocateImage is currently unimplemented.
class FakeGpuAllocator : public GpuAllocator {
public:
FakeGpuAllocator();
~FakeGpuAllocator();
// |GpuAllocator|
GpuMemPtr AllocateMemory(vk::MemoryRequirements reqs,
vk::MemoryPropertyFlags flags) override;
// |GpuAllocator|
BufferPtr AllocateBuffer(ResourceManager* manager, vk::DeviceSize size,
vk::BufferUsageFlags usage_flags,
vk::MemoryPropertyFlags memory_property_flags,
GpuMemPtr* out_ptr) override;
// |GpuAllocator|
ImagePtr AllocateImage(ResourceManager* manager,
const escher::ImageInfo& info,
GpuMemPtr* out_ptr) override;
// |GpuAllocator|
uint32_t GetTotalBytesAllocated() const override;
// These functions are public because this is a test class, and unit tests may
// wish to indirectly mock GetTotalBytesAllocated() behavior.
void OnAllocation(uint64_t size);
void OnDeallocation(uint64_t size);
private:
uint64_t bytes_allocated_ = 0;
};
} // namespace test
} // namespace escher
#endif // LIB_ESCHER_TEST_FAKE_GPU_ALLOCATOR_H_