• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2019 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #pragma once
15 
16 #include "base/Stream.h"
17 #include "base/EntityManager.h"
18 
19 #include "VulkanHandleMapping.h"
20 #include "VulkanHandles.h"
21 
22 #include "common/goldfish_vk_marshaling.h"
23 
24 // A class that captures all important data structures for
25 // reconstructing a Vulkan system state via trimmed API record and replay.
26 class VkReconstruction {
27 public:
28     VkReconstruction();
29 
30     void save(android::base::Stream* stream);
31     void load(android::base::Stream* stream);
32 
33     struct ApiInfo {
34         // Fast
35         uint32_t opCode;
36         std::vector<uint8_t> trace;
37         size_t traceBytes = 0;
38         // Book-keeping for which handles were created by this API
39         std::vector<uint64_t> createdHandles;
40     };
41 
42     using ApiTrace =
43         android::base::EntityManager<32, 16, 16, ApiInfo>;
44     using ApiHandle = ApiTrace::EntityHandle;
45 
46     struct HandleReconstruction {
47         std::vector<ApiHandle> apiRefs;
48         std::vector<uint64_t> childHandles;
49     };
50 
51     using HandleReconstructions =
52         android::base::UnpackedComponentManager<32, 16, 16, HandleReconstruction>;
53 
54     struct HandleModification {
55         std::vector<ApiHandle> apiRefs;
56         uint32_t order = 0;
57     };
58 
59     using HandleModifications =
60         android::base::UnpackedComponentManager<32, 16, 16, HandleModification>;
61 
62     ApiHandle createApiInfo();
63     void destroyApiInfo(ApiHandle h);
64 
65     ApiInfo* getApiInfo(ApiHandle h);
66 
67     void setApiTrace(ApiInfo* apiInfo, uint32_t opcode, const uint8_t* traceBegin, size_t traceBytes);
68 
69     void dump();
70 
71     void addHandles(const uint64_t* toAdd, uint32_t count);
72     void removeHandles(const uint64_t* toRemove, uint32_t count);
73 
74     void forEachHandleAddApi(const uint64_t* toProcess, uint32_t count, uint64_t apiHandle);
75     void forEachHandleDeleteApi(const uint64_t* toProcess, uint32_t count);
76 
77     void addHandleDependency(const uint64_t* handles, uint32_t count, uint64_t parentHandle);
78 
79     void setCreatedHandlesForApi(uint64_t apiHandle, const uint64_t* created, uint32_t count);
80 
81     void forEachHandleAddModifyApi(const uint64_t* toProcess, uint32_t count, uint64_t apiHandle);
82 
83     void setModifiedHandlesForApi(uint64_t apiHandle, const uint64_t* modified, uint32_t count);
84 private:
85 
86     std::vector<uint64_t> getOrderedUniqueModifyApis() const;
87 
88     ApiTrace mApiTrace;
89 
90     HandleReconstructions mHandleReconstructions;
91     HandleModifications mHandleModifications;
92 
93     std::vector<uint8_t> mLoadedTrace;
94 };
95