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/7753 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 *gMemoryObjectMap; 92 extern GLuint *gProgramPipelineMap; 93 extern GLuint *gQueryMap; 94 extern GLuint *gRenderbufferMap; 95 extern GLuint *gSamplerMap; 96 extern GLuint *gSemaphoreMap; 97 extern GLuint *gShaderProgramMap; 98 extern GLuint *gTextureMap; 99 extern GLuint *gTransformFeedbackMap; 100 extern GLuint *gVertexArrayMap; 101 102 // TODO(jmadill): Consolidate. http://anglebug.com/7753 103 extern GLeglImageOES *gEGLImageMap2; 104 extern EGLSurface *gSurfaceMap2; 105 extern EGLContext *gContextMap2; 106 extern GLsync *gSyncMap2; 107 extern EGLSync *gEGLSyncMap; 108 extern EGLDisplay gEGLDisplay; 109 void InitializeReplay4(const char *binaryDataFileName, 110 size_t maxClientArraySize, 111 size_t readBufferSize, 112 size_t resourceIDBufferSize, 113 GLuint contextId, 114 uint32_t maxBuffer, 115 uint32_t maxContext, 116 uint32_t maxFenceNV, 117 uint32_t maxFramebuffer, 118 uint32_t maxImage, 119 uint32_t maxMemoryObject, 120 uint32_t maxProgramPipeline, 121 uint32_t maxQuery, 122 uint32_t maxRenderbuffer, 123 uint32_t maxSampler, 124 uint32_t maxSemaphore, 125 uint32_t maxShaderProgram, 126 uint32_t maxSurface, 127 uint32_t maxSync, 128 uint32_t maxTexture, 129 uint32_t maxTransformFeedback, 130 uint32_t maxVertexArray, 131 uint32_t maxEGLSyncID); 132 133 void InitializeReplay3(const char *binaryDataFileName, 134 size_t maxClientArraySize, 135 size_t readBufferSize, 136 size_t resourceIDBufferSize, 137 GLuint contextId, 138 uint32_t maxBuffer, 139 uint32_t maxContext, 140 uint32_t maxFenceNV, 141 uint32_t maxFramebuffer, 142 uint32_t maxImage, 143 uint32_t maxMemoryObject, 144 uint32_t maxProgramPipeline, 145 uint32_t maxQuery, 146 uint32_t maxRenderbuffer, 147 uint32_t maxSampler, 148 uint32_t maxSemaphore, 149 uint32_t maxShaderProgram, 150 uint32_t maxSurface, 151 uint32_t maxSync, 152 uint32_t maxTexture, 153 uint32_t maxTransformFeedback, 154 uint32_t maxVertexArray); 155 156 void InitializeReplay2(const char *binaryDataFileName, 157 size_t maxClientArraySize, 158 size_t readBufferSize, 159 GLuint contextId, 160 uint32_t maxBuffer, 161 uint32_t maxContext, 162 uint32_t maxFenceNV, 163 uint32_t maxFramebuffer, 164 uint32_t maxImage, 165 uint32_t maxMemoryObject, 166 uint32_t maxProgramPipeline, 167 uint32_t maxQuery, 168 uint32_t maxRenderbuffer, 169 uint32_t maxSampler, 170 uint32_t maxSemaphore, 171 uint32_t maxShaderProgram, 172 uint32_t maxSurface, 173 uint32_t maxTexture, 174 uint32_t maxTransformFeedback, 175 uint32_t maxVertexArray); 176 177 void InitializeReplay(const char *binaryDataFileName, 178 size_t maxClientArraySize, 179 size_t readBufferSize, 180 uint32_t maxBuffer, 181 uint32_t maxFenceNV, 182 uint32_t maxFramebuffer, 183 uint32_t maxMemoryObject, 184 uint32_t maxProgramPipeline, 185 uint32_t maxQuery, 186 uint32_t maxRenderbuffer, 187 uint32_t maxSampler, 188 uint32_t maxSemaphore, 189 uint32_t maxShaderProgram, 190 uint32_t maxTexture, 191 uint32_t maxTransformFeedback, 192 uint32_t maxVertexArray); 193 194 void UpdateClientArrayPointer(int arrayIndex, const void *data, uint64_t size); 195 void UpdateClientBufferData(GLuint bufferID, const void *source, GLsizei size); 196 void UpdateClientBufferDataWithOffset(GLuint bufferID, 197 const void *source, 198 GLsizei size, 199 GLsizei offset); 200 void UpdateResourceIDBuffer(int resourceIndex, GLuint id); 201 void UpdateBufferID(GLuint id, GLsizei readBufferOffset); 202 void UpdateFenceNVID(GLuint id, GLsizei readBufferOffset); 203 void UpdateFramebufferID(GLuint id, GLsizei readBufferOffset); 204 void UpdateMemoryObjectID(GLuint id, GLsizei readBufferOffset); 205 void UpdateProgramPipelineID(GLuint id, GLsizei readBufferOffset); 206 void UpdateQueryID(GLuint id, GLsizei readBufferOffset); 207 void UpdateRenderbufferID(GLuint id, GLsizei readBufferOffset); 208 void UpdateSamplerID(GLuint id, GLsizei readBufferOffset); 209 void UpdateSemaphoreID(GLuint id, GLsizei readBufferOffset); 210 void UpdateShaderProgramID(GLuint id, GLsizei readBufferOffset); 211 void UpdateTextureID(GLuint id, GLsizei readBufferOffset); 212 void UpdateTransformFeedbackID(GLuint id, GLsizei readBufferOffset); 213 void UpdateVertexArrayID(GLuint id, GLsizei readBufferOffset); 214 215 void SetCurrentContextID(GLuint id); 216 217 void SetFramebufferID(GLuint id); 218 void SetBufferID(GLuint id); 219 void SetRenderbufferID(GLuint id); 220 void SetTextureID(GLuint id); 221 222 // These functions allow the traces to change variable assignments into function calls, 223 // which makes it so the trace C interpreter doesn't need to implement operators at all. 224 void MapBufferRange(GLenum target, 225 GLintptr offset, 226 GLsizeiptr length, 227 GLbitfield access, 228 GLuint buffer); 229 void MapBufferRangeEXT(GLenum target, 230 GLintptr offset, 231 GLsizeiptr length, 232 GLbitfield access, 233 GLuint buffer); 234 void MapBufferOES(GLenum target, GLbitfield access, GLuint buffer); 235 void CreateShader(GLenum shaderType, GLuint shaderProgram); 236 void CreateProgram(GLuint shaderProgram); 237 void CreateShaderProgramv(GLenum type, 238 GLsizei count, 239 const GLchar *const *strings, 240 GLuint shaderProgram); 241 void FenceSync(GLenum condition, GLbitfield flags, uintptr_t fenceSync); 242 void FenceSync2(GLenum condition, GLbitfield flags, uintptr_t fenceSync); 243 void CreateEGLImage(EGLDisplay dpy, 244 EGLContext ctx, 245 EGLenum target, 246 uintptr_t buffer, 247 const EGLAttrib *attrib_list, 248 GLuint imageID); 249 void CreateEGLImageKHR(EGLDisplay dpy, 250 EGLContext ctx, 251 EGLenum target, 252 uintptr_t buffer, 253 const EGLint *attrib_list, 254 GLuint imageID); 255 void CreateEGLSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list, GLuint syncID); 256 void CreateEGLSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list, GLuint syncID); 257 void CreatePbufferSurface(EGLDisplay dpy, 258 EGLConfig config, 259 const EGLint *attrib_list, 260 GLuint surfaceID); 261 void CreateNativeClientBufferANDROID(const EGLint *attrib_list, uintptr_t clientBuffer); 262 void CreateContext(GLuint contextID); 263 264 void ValidateSerializedState(const char *serializedState, const char *fileName, uint32_t line); 265 #define VALIDATE_CHECKPOINT(STATE) ValidateSerializedState(STATE, __FILE__, __LINE__) 266 267 #if defined(__cplusplus) 268 } // extern "C" 269 #endif // defined(__cplusplus) 270 271 #endif // ANGLE_TRACE_FIXTURE_H_ 272