1 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // MemoryObjectVk.h: Defines the class interface for MemoryObjectVk,
6 // implementing MemoryObjectImpl.
7 
8 #ifndef LIBANGLE_RENDERER_VULKAN_MEMORYOBJECTVK_H_
9 #define LIBANGLE_RENDERER_VULKAN_MEMORYOBJECTVK_H_
10 
11 #include "libANGLE/renderer/MemoryObjectImpl.h"
12 #include "libANGLE/renderer/vulkan/vk_helpers.h"
13 #include "libANGLE/renderer/vulkan/vk_wrapper.h"
14 
15 namespace rx
16 {
17 
18 class MemoryObjectVk : public MemoryObjectImpl
19 {
20   public:
21     MemoryObjectVk();
22     ~MemoryObjectVk() override;
23 
24     void onDestroy(const gl::Context *context) override;
25 
26     angle::Result setDedicatedMemory(const gl::Context *context, bool dedicatedMemory) override;
27 
28     angle::Result importFd(gl::Context *context,
29                            GLuint64 size,
30                            gl::HandleType handleType,
31                            GLint fd) override;
32 
33     angle::Result importZirconHandle(gl::Context *context,
34                                      GLuint64 size,
35                                      gl::HandleType handleType,
36                                      GLuint handle) override;
37 
38     angle::Result createImage(ContextVk *context,
39                               gl::TextureType type,
40                               size_t levels,
41                               GLenum internalFormat,
42                               const gl::Extents &size,
43                               GLuint64 offset,
44                               vk::ImageHelper *image,
45                               GLbitfield createFlags,
46                               GLbitfield usageFlags);
47 
48   private:
49     static constexpr int kInvalidFd = -1;
50     angle::Result importOpaqueFd(ContextVk *contextVk, GLuint64 size, GLint fd);
51     angle::Result importZirconVmo(ContextVk *contextVk, GLuint64 size, GLuint handle);
52 
53     // Imported memory object was a dedicated allocation.
54     bool mDedicatedMemory = false;
55 
56     GLuint64 mSize             = 0;
57     gl::HandleType mHandleType = gl::HandleType::InvalidEnum;
58     int mFd                    = kInvalidFd;
59 
60     zx_handle_t mZirconHandle = ZX_HANDLE_INVALID;
61 };
62 
63 }  // namespace rx
64 
65 #endif  // LIBANGLE_RENDERER_VULKAN_MEMORYOBJECTVK_H_
66