• 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 <EGL/eglext.h>
15 #include <math.h>
16 #include <stddef.h>
17 #include <stdint.h>
18 
19 #include "angle_gl.h"
20 #include "trace_interface.h"
21 #include "traces_export.h"
22 
23 #if defined(__cplusplus)
24 #    include <cstdio>
25 #    include <cstring>
26 #    include <limits>
27 #    include <unordered_map>
28 #    include <vector>
29 
30 // TODO(jmadill): Consolidate. http://anglebug.com/42266223
31 using BlockIndexesMap = std::unordered_map<GLuint, std::unordered_map<GLuint, GLuint>>;
32 extern BlockIndexesMap gUniformBlockIndexes;
33 using BufferHandleMap = std::unordered_map<GLuint, void *>;
34 extern BufferHandleMap gMappedBufferData;
35 using ClientBufferMap = std::unordered_map<uintptr_t, EGLClientBuffer>;
36 extern ClientBufferMap gClientBufferMap;
37 using EGLImageMap = std::unordered_map<uintptr_t, GLeglImageOES>;
38 extern EGLImageMap gEGLImageMap;
39 using SyncResourceMap = std::unordered_map<uintptr_t, GLsync>;
40 extern SyncResourceMap gSyncMap;
41 using SurfaceMap = std::unordered_map<uintptr_t, EGLSurface>;
42 extern SurfaceMap gSurfaceMap;
43 using ContextMap = std::unordered_map<uintptr_t, EGLContext>;
44 extern ContextMap gContextMap;
45 
46 extern std::string gBinaryDataDir;
47 extern angle::TraceInfo gTraceInfo;
48 extern std::string gTraceGzPath;
49 
50 using ValidateSerializedStateCallback = void (*)(const char *, const char *, uint32_t);
51 
52 extern "C" {
53 
54 // Functions implemented by traces.
55 // "not exported" tag is a hack to get around trace interpreter codegen -_-
56 /* not exported */ void SetupReplay();
57 /* not exported */ void ReplayFrame(uint32_t frameIndex);
58 /* not exported */ void ResetReplay();
59 /* not exported */ void FinishReplay();
60 /* not exported */ void SetupFirstFrame();
61 
62 ANGLE_REPLAY_EXPORT void SetValidateSerializedStateCallback(
63     ValidateSerializedStateCallback callback);
64 
65 // Only defined if serialization is enabled.
66 ANGLE_REPLAY_EXPORT const char *GetSerializedContextState(uint32_t frameIndex);
67 
68 ANGLE_REPLAY_EXPORT void SetupEntryPoints(angle::TraceCallbacks *traceCallbacks,
69                                           angle::TraceFunctions **traceFunctions);
70 #endif  // defined(__cplusplus)
71 
72 // Maps from <captured Program ID, captured location> to run-time location.
73 extern GLint **gUniformLocations;
74 extern GLuint gCurrentProgram;
75 
76 void UpdateUniformLocation(GLuint program, const char *name, GLint location, GLint count);
77 void DeleteUniformLocations(GLuint program);
78 void UpdateUniformBlockIndex(GLuint program, const char *name, GLuint index);
79 void UniformBlockBinding(GLuint program, GLuint uniformblockIndex, GLuint binding);
80 void UpdateCurrentProgram(GLuint program);
81 
82 // Global state
83 
84 extern uint8_t *gBinaryData;
85 extern uint8_t *gReadBuffer;
86 extern uint8_t *gClientArrays[];
87 extern GLuint *gResourceIDBuffer;
88 
89 extern GLuint *gBufferMap;
90 extern GLuint *gFenceNVMap;
91 extern GLuint *gFramebufferMap;
92 extern GLuint **gFramebufferMapPerContext;
93 extern GLuint *gMemoryObjectMap;
94 extern GLuint *gProgramPipelineMap;
95 extern GLuint *gQueryMap;
96 extern GLuint *gRenderbufferMap;
97 extern GLuint *gSamplerMap;
98 extern GLuint *gSemaphoreMap;
99 extern GLuint *gShaderProgramMap;
100 extern GLuint *gTextureMap;
101 extern GLuint *gTransformFeedbackMap;
102 extern GLuint *gVertexArrayMap;
103 
104 // TODO(jmadill): Consolidate. http://anglebug.com/42266223
105 extern GLeglImageOES *gEGLImageMap2;
106 extern EGLSurface *gSurfaceMap2;
107 extern EGLContext *gContextMap2;
108 extern GLsync *gSyncMap2;
109 extern EGLSync *gEGLSyncMap;
110 extern EGLDisplay gEGLDisplay;
111 extern angle::ReplayResourceMode gReplayResourceMode;
112 
113 void InitializeReplay4(const char *binaryDataFileName,
114                        size_t maxClientArraySize,
115                        size_t readBufferSize,
116                        size_t resourceIDBufferSize,
117                        GLuint contextId,
118                        uint32_t maxBuffer,
119                        uint32_t maxContext,
120                        uint32_t maxFenceNV,
121                        uint32_t maxFramebuffer,
122                        uint32_t maxImage,
123                        uint32_t maxMemoryObject,
124                        uint32_t maxProgramPipeline,
125                        uint32_t maxQuery,
126                        uint32_t maxRenderbuffer,
127                        uint32_t maxSampler,
128                        uint32_t maxSemaphore,
129                        uint32_t maxShaderProgram,
130                        uint32_t maxSurface,
131                        uint32_t maxSync,
132                        uint32_t maxTexture,
133                        uint32_t maxTransformFeedback,
134                        uint32_t maxVertexArray,
135                        uint32_t maxEGLSyncID);
136 
137 void InitializeReplay3(const char *binaryDataFileName,
138                        size_t maxClientArraySize,
139                        size_t readBufferSize,
140                        size_t resourceIDBufferSize,
141                        GLuint contextId,
142                        uint32_t maxBuffer,
143                        uint32_t maxContext,
144                        uint32_t maxFenceNV,
145                        uint32_t maxFramebuffer,
146                        uint32_t maxImage,
147                        uint32_t maxMemoryObject,
148                        uint32_t maxProgramPipeline,
149                        uint32_t maxQuery,
150                        uint32_t maxRenderbuffer,
151                        uint32_t maxSampler,
152                        uint32_t maxSemaphore,
153                        uint32_t maxShaderProgram,
154                        uint32_t maxSurface,
155                        uint32_t maxSync,
156                        uint32_t maxTexture,
157                        uint32_t maxTransformFeedback,
158                        uint32_t maxVertexArray);
159 
160 void InitializeReplay2(const char *binaryDataFileName,
161                        size_t maxClientArraySize,
162                        size_t readBufferSize,
163                        GLuint contextId,
164                        uint32_t maxBuffer,
165                        uint32_t maxContext,
166                        uint32_t maxFenceNV,
167                        uint32_t maxFramebuffer,
168                        uint32_t maxImage,
169                        uint32_t maxMemoryObject,
170                        uint32_t maxProgramPipeline,
171                        uint32_t maxQuery,
172                        uint32_t maxRenderbuffer,
173                        uint32_t maxSampler,
174                        uint32_t maxSemaphore,
175                        uint32_t maxShaderProgram,
176                        uint32_t maxSurface,
177                        uint32_t maxTexture,
178                        uint32_t maxTransformFeedback,
179                        uint32_t maxVertexArray);
180 
181 void InitializeReplay(const char *binaryDataFileName,
182                       size_t maxClientArraySize,
183                       size_t readBufferSize,
184                       uint32_t maxBuffer,
185                       uint32_t maxFenceNV,
186                       uint32_t maxFramebuffer,
187                       uint32_t maxMemoryObject,
188                       uint32_t maxProgramPipeline,
189                       uint32_t maxQuery,
190                       uint32_t maxRenderbuffer,
191                       uint32_t maxSampler,
192                       uint32_t maxSemaphore,
193                       uint32_t maxShaderProgram,
194                       uint32_t maxTexture,
195                       uint32_t maxTransformFeedback,
196                       uint32_t maxVertexArray);
197 
198 void UpdateClientArrayPointer(int arrayIndex, const void *data, uint64_t size);
199 void UpdateClientBufferData(GLuint bufferID, const void *source, GLsizei size);
200 void UpdateClientBufferDataWithOffset(GLuint bufferID,
201                                       const void *source,
202                                       GLsizei size,
203                                       GLsizei offset);
204 void UpdateResourceIDBuffer(int resourceIndex, GLuint id);
205 void UpdateBufferID(GLuint id, GLsizei readBufferOffset);
206 void UpdateFenceNVID(GLuint id, GLsizei readBufferOffset);
207 void UpdateFramebufferID(GLuint id, GLsizei readBufferOffset);
208 void UpdateFramebufferID2(GLuint contextId, GLuint id, GLsizei readBufferOffset);
209 void UpdateMemoryObjectID(GLuint id, GLsizei readBufferOffset);
210 void UpdateProgramPipelineID(GLuint id, GLsizei readBufferOffset);
211 void UpdateQueryID(GLuint id, GLsizei readBufferOffset);
212 void UpdateRenderbufferID(GLuint id, GLsizei readBufferOffset);
213 void UpdateSamplerID(GLuint id, GLsizei readBufferOffset);
214 void UpdateSemaphoreID(GLuint id, GLsizei readBufferOffset);
215 void UpdateShaderProgramID(GLuint id, GLsizei readBufferOffset);
216 void UpdateTextureID(GLuint id, GLsizei readBufferOffset);
217 void UpdateTransformFeedbackID(GLuint id, GLsizei readBufferOffset);
218 void UpdateVertexArrayID(GLuint id, GLsizei readBufferOffset);
219 
220 void SetCurrentContextID(GLuint id);
221 
222 void SetFramebufferID(GLuint id);
223 void SetFramebufferID2(GLuint contextID, GLuint id);
224 void SetBufferID(GLuint id);
225 void SetRenderbufferID(GLuint id);
226 void SetTextureID(GLuint id);
227 
228 // These functions allow the traces to change variable assignments into function calls,
229 // which makes it so the trace C interpreter doesn't need to implement operators at all.
230 void MapBufferRange(GLenum target,
231                     GLintptr offset,
232                     GLsizeiptr length,
233                     GLbitfield access,
234                     GLuint buffer);
235 void MapBufferRangeEXT(GLenum target,
236                        GLintptr offset,
237                        GLsizeiptr length,
238                        GLbitfield access,
239                        GLuint buffer);
240 void MapBufferOES(GLenum target, GLbitfield access, GLuint buffer);
241 void CreateShader(GLenum shaderType, GLuint shaderProgram);
242 void CreateProgram(GLuint shaderProgram);
243 void CreateShaderProgramv(GLenum type,
244                           GLsizei count,
245                           const GLchar *const *strings,
246                           GLuint shaderProgram);
247 void FenceSync(GLenum condition, GLbitfield flags, uintptr_t fenceSync);
248 void FenceSync2(GLenum condition, GLbitfield flags, uintptr_t fenceSync);
249 void CreateEGLImage(EGLDisplay dpy,
250                     EGLContext ctx,
251                     EGLenum target,
252                     uintptr_t buffer,
253                     const EGLAttrib *attrib_list,
254                     GLsizei width,
255                     GLsizei height,
256                     GLuint imageID);
257 void CreateEGLImageKHR(EGLDisplay dpy,
258                        EGLContext ctx,
259                        EGLenum target,
260                        uintptr_t buffer,
261                        const EGLint *attrib_list,
262                        GLsizei width,
263                        GLsizei height,
264                        GLuint imageID);
265 void DestroyEGLImage(EGLDisplay dpy, EGLImage image, GLuint imageID);
266 void DestroyEGLImageKHR(EGLDisplay dpy, EGLImageKHR image, GLuint imageID);
267 void CreateEGLSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list, GLuint syncID);
268 void CreateEGLSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list, GLuint syncID);
269 void CreatePbufferSurface(EGLDisplay dpy,
270                           EGLConfig config,
271                           const EGLint *attrib_list,
272                           GLuint surfaceID);
273 void CreateNativeClientBufferANDROID(const EGLint *attrib_list, uintptr_t clientBuffer);
274 void CreateContext(GLuint contextID);
275 
276 void ValidateSerializedState(const char *serializedState, const char *fileName, uint32_t line);
277 
278 #define VALIDATE_CHECKPOINT(STATE) ValidateSerializedState(STATE, __FILE__, __LINE__)
279 
280 #if defined(__cplusplus)
281 }       // extern "C"
282 #endif  // defined(__cplusplus)
283 
284 #endif  // ANGLE_TRACE_FIXTURE_H_
285