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