• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2021 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // trace_fixture.h:
7 //   Common code for the ANGLE trace replays.
8 //
9 
10 #ifndef ANGLE_TRACE_FIXTURE_H_
11 #define ANGLE_TRACE_FIXTURE_H_
12 
13 #include <EGL/egl.h>
14 #include "angle_gl.h"
15 
16 #include <cstdint>
17 #include <cstdio>
18 #include <cstring>
19 #include <limits>
20 #include <unordered_map>
21 #include <vector>
22 
23 #if !defined(ANGLE_REPLAY_EXPORT)
24 #    if defined(_WIN32)
25 #        if defined(ANGLE_REPLAY_IMPLEMENTATION)
26 #            define ANGLE_REPLAY_EXPORT __declspec(dllexport)
27 #        else
28 #            define ANGLE_REPLAY_EXPORT __declspec(dllimport)
29 #        endif
30 #    elif defined(__GNUC__)
31 #        define ANGLE_REPLAY_EXPORT __attribute__((visibility("default")))
32 #    else
33 #        define ANGLE_REPLAY_EXPORT
34 #    endif
35 #endif  // !defined(ANGLE_REPLAY_EXPORT)
36 
37 using DecompressCallback              = uint8_t *(*)(const std::vector<uint8_t> &);
38 using ValidateSerializedStateCallback = void (*)(const char *, const char *, uint32_t);
39 
40 extern "C" {
41 ANGLE_REPLAY_EXPORT void SetBinaryDataDecompressCallback(DecompressCallback callback);
42 ANGLE_REPLAY_EXPORT void SetBinaryDataDir(const char *dataDir);
43 ANGLE_REPLAY_EXPORT void SetupReplay();
44 ANGLE_REPLAY_EXPORT void ReplayFrame(uint32_t frameIndex);
45 ANGLE_REPLAY_EXPORT void ResetReplay();
46 ANGLE_REPLAY_EXPORT void FinishReplay();
47 ANGLE_REPLAY_EXPORT void SetValidateSerializedStateCallback(
48     ValidateSerializedStateCallback callback);
49 
50 // Only defined if serialization is enabled.
51 ANGLE_REPLAY_EXPORT const char *GetSerializedContextState(uint32_t frameIndex);
52 }  // extern "C"
53 
54 // Maps from <captured Program ID, captured location> to run-time location.
55 using LocationsMap = std::unordered_map<GLuint, std::unordered_map<GLint, GLint>>;
56 extern LocationsMap gUniformLocations;
57 extern GLint **gUniformLocations2;
58 using BlockIndexesMap = std::unordered_map<GLuint, std::unordered_map<GLuint, GLuint>>;
59 extern BlockIndexesMap gUniformBlockIndexes;
60 extern GLuint gCurrentProgram;
61 void UpdateUniformLocation(GLuint program, const char *name, GLint location);
62 void UpdateUniformLocation(GLuint program, const char *name, GLint location, GLint count);
63 void UpdateUniformLocation2(GLuint program, const char *name, GLint location, GLint count);
64 void DeleteUniformLocations(GLuint program);
65 void DeleteUniformLocations2(GLuint program);
66 void UpdateUniformBlockIndex(GLuint program, const char *name, GLuint index);
67 void UpdateCurrentProgram(GLuint program);
68 
69 // Maps from captured Resource ID to run-time Resource ID.
70 class ResourceMap
71 {
72   public:
ResourceMap()73     ResourceMap() {}
74     GLuint &operator[](GLuint index)
75     {
76         if (mIDs.size() <= static_cast<size_t>(index))
77             mIDs.resize(index + 1, 0);
78         return mIDs[index];
79     }
80 
81   private:
82     std::vector<GLuint> mIDs;
83 };
84 
85 void InitializeReplay(const char *binaryDataFileName,
86                       size_t maxClientArraySize,
87                       size_t readBufferSize);
88 
89 void InitializeReplay2(const char *binaryDataFileName,
90                        size_t maxClientArraySize,
91                        size_t readBufferSize,
92                        uint32_t maxBuffer,
93                        uint32_t maxFenceNV,
94                        uint32_t maxFramebuffer,
95                        uint32_t maxMemoryObject,
96                        uint32_t maxProgramPipeline,
97                        uint32_t maxQuery,
98                        uint32_t maxRenderbuffer,
99                        uint32_t maxSampler,
100                        uint32_t maxSemaphore,
101                        uint32_t maxShaderProgram,
102                        uint32_t maxTexture,
103                        uint32_t maxTransformFeedback,
104                        uint32_t maxVertexArray);
105 
106 // Global state
107 
108 constexpr size_t kMaxClientArrays = 16;
109 
110 extern uint8_t *gBinaryData;
111 extern uint8_t *gReadBuffer;
112 extern uint8_t *gClientArrays[kMaxClientArrays];
113 extern ResourceMap gBufferMap;
114 extern ResourceMap gFenceNVMap;
115 extern ResourceMap gFramebufferMap;
116 extern ResourceMap gMemoryObjectMap;
117 extern ResourceMap gProgramPipelineMap;
118 extern ResourceMap gQueryMap;
119 extern ResourceMap gRenderbufferMap;
120 extern ResourceMap gSamplerMap;
121 extern ResourceMap gSemaphoreMap;
122 extern ResourceMap gShaderProgramMap;
123 extern ResourceMap gTextureMap;
124 extern ResourceMap gTransformFeedbackMap;
125 extern ResourceMap gVertexArrayMap;
126 
127 extern GLuint *gBufferMap2;
128 extern GLuint *gFenceNVMap2;
129 extern GLuint *gFramebufferMap2;
130 extern GLuint *gMemoryObjectMap2;
131 extern GLuint *gProgramPipelineMap2;
132 extern GLuint *gQueryMap2;
133 extern GLuint *gRenderbufferMap2;
134 extern GLuint *gSamplerMap2;
135 extern GLuint *gSemaphoreMap2;
136 extern GLuint *gShaderProgramMap2;
137 extern GLuint *gTextureMap2;
138 extern GLuint *gTransformFeedbackMap2;
139 extern GLuint *gVertexArrayMap2;
140 
141 // TODO(http://www.anglebug.com/5878): avoid std::unordered_map, it's slow
142 using SyncResourceMap = std::unordered_map<uintptr_t, GLsync>;
143 extern SyncResourceMap gSyncMap;
144 using ContextMap = std::unordered_map<uint32_t, EGLContext>;
145 extern ContextMap gContextMap;
146 
147 void UpdateClientArrayPointer(int arrayIndex, const void *data, uint64_t size);
148 using BufferHandleMap = std::unordered_map<GLuint, void *>;
149 extern BufferHandleMap gMappedBufferData;
150 void UpdateClientBufferData(GLuint bufferID, const void *source, GLsizei size);
151 void UpdateClientBufferData2(GLuint bufferID, const void *source, GLsizei size);
152 void UpdateClientBufferData2WithOffset(GLuint bufferID,
153                                        const void *source,
154                                        GLsizei size,
155                                        GLsizei offset);
156 void UpdateBufferID(GLuint id, GLsizei readBufferOffset);
157 void UpdateFenceNVID(GLuint id, GLsizei readBufferOffset);
158 void UpdateFramebufferID(GLuint id, GLsizei readBufferOffset);
159 void UpdateMemoryObjectID(GLuint id, GLsizei readBufferOffset);
160 void UpdateProgramPipelineID(GLuint id, GLsizei readBufferOffset);
161 void UpdateQueryID(GLuint id, GLsizei readBufferOffset);
162 void UpdateRenderbufferID(GLuint id, GLsizei readBufferOffset);
163 void UpdateSamplerID(GLuint id, GLsizei readBufferOffset);
164 void UpdateSemaphoreID(GLuint id, GLsizei readBufferOffset);
165 void UpdateShaderProgramID(GLuint id, GLsizei readBufferOffset);
166 void UpdateTextureID(GLuint id, GLsizei readBufferOffset);
167 void UpdateTransformFeedbackID(GLuint id, GLsizei readBufferOffset);
168 void UpdateVertexArrayID(GLuint id, GLsizei readBufferOffset);
169 void UpdateBufferID2(GLuint id, GLsizei readBufferOffset);
170 void UpdateFenceNVID2(GLuint id, GLsizei readBufferOffset);
171 void UpdateFramebufferID2(GLuint id, GLsizei readBufferOffset);
172 void UpdateMemoryObjectID2(GLuint id, GLsizei readBufferOffset);
173 void UpdateProgramPipelineID2(GLuint id, GLsizei readBufferOffset);
174 void UpdateQueryID2(GLuint id, GLsizei readBufferOffset);
175 void UpdateRenderbufferID2(GLuint id, GLsizei readBufferOffset);
176 void UpdateSamplerID2(GLuint id, GLsizei readBufferOffset);
177 void UpdateSemaphoreID2(GLuint id, GLsizei readBufferOffset);
178 void UpdateShaderProgramID2(GLuint id, GLsizei readBufferOffset);
179 void UpdateTextureID2(GLuint id, GLsizei readBufferOffset);
180 void UpdateTransformFeedbackID2(GLuint id, GLsizei readBufferOffset);
181 void UpdateVertexArrayID2(GLuint id, GLsizei readBufferOffset);
182 
183 void SetFramebufferID(GLuint id);
184 
185 void ValidateSerializedState(const char *serializedState, const char *fileName, uint32_t line);
186 #define VALIDATE_CHECKPOINT(STATE) ValidateSerializedState(STATE, __FILE__, __LINE__)
187 
188 #endif  // ANGLE_TRACE_FIXTURE_H_
189