• 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 extern GLint **gUniformLocations;
56 using BlockIndexesMap = std::unordered_map<GLuint, std::unordered_map<GLuint, GLuint>>;
57 extern BlockIndexesMap gUniformBlockIndexes;
58 extern GLuint gCurrentProgram;
59 void UpdateUniformLocation(GLuint program, const char *name, GLint location, GLint count);
60 void DeleteUniformLocations(GLuint program);
61 void UpdateUniformBlockIndex(GLuint program, const char *name, GLuint index);
62 void UpdateCurrentProgram(GLuint program);
63 
64 void InitializeReplay(const char *binaryDataFileName,
65                       size_t maxClientArraySize,
66                       size_t readBufferSize,
67                       uint32_t maxBuffer,
68                       uint32_t maxFenceNV,
69                       uint32_t maxFramebuffer,
70                       uint32_t maxMemoryObject,
71                       uint32_t maxProgramPipeline,
72                       uint32_t maxQuery,
73                       uint32_t maxRenderbuffer,
74                       uint32_t maxSampler,
75                       uint32_t maxSemaphore,
76                       uint32_t maxShaderProgram,
77                       uint32_t maxTexture,
78                       uint32_t maxTransformFeedback,
79                       uint32_t maxVertexArray);
80 
81 // Global state
82 
83 constexpr size_t kMaxClientArrays = 16;
84 
85 extern uint8_t *gBinaryData;
86 extern uint8_t *gReadBuffer;
87 extern uint8_t *gClientArrays[kMaxClientArrays];
88 
89 extern GLuint *gBufferMap;
90 extern GLuint *gFenceNVMap;
91 extern GLuint *gFramebufferMap;
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(http://www.anglebug.com/5878): avoid std::unordered_map, it's slow
104 using SyncResourceMap = std::unordered_map<uintptr_t, GLsync>;
105 extern SyncResourceMap gSyncMap;
106 using ContextMap = std::unordered_map<uint32_t, EGLContext>;
107 extern ContextMap gContextMap;
108 
109 void UpdateClientArrayPointer(int arrayIndex, const void *data, uint64_t size);
110 using BufferHandleMap = std::unordered_map<GLuint, void *>;
111 extern BufferHandleMap gMappedBufferData;
112 void UpdateClientBufferData(GLuint bufferID, const void *source, GLsizei size);
113 void UpdateClientBufferDataWithOffset(GLuint bufferID,
114                                       const void *source,
115                                       GLsizei size,
116                                       GLsizei offset);
117 void UpdateBufferID(GLuint id, GLsizei readBufferOffset);
118 void UpdateFenceNVID(GLuint id, GLsizei readBufferOffset);
119 void UpdateFramebufferID(GLuint id, GLsizei readBufferOffset);
120 void UpdateMemoryObjectID(GLuint id, GLsizei readBufferOffset);
121 void UpdateProgramPipelineID(GLuint id, GLsizei readBufferOffset);
122 void UpdateQueryID(GLuint id, GLsizei readBufferOffset);
123 void UpdateRenderbufferID(GLuint id, GLsizei readBufferOffset);
124 void UpdateSamplerID(GLuint id, GLsizei readBufferOffset);
125 void UpdateSemaphoreID(GLuint id, GLsizei readBufferOffset);
126 void UpdateShaderProgramID(GLuint id, GLsizei readBufferOffset);
127 void UpdateTextureID(GLuint id, GLsizei readBufferOffset);
128 void UpdateTransformFeedbackID(GLuint id, GLsizei readBufferOffset);
129 void UpdateVertexArrayID(GLuint id, GLsizei readBufferOffset);
130 void UpdateBufferID2(GLuint id, GLsizei readBufferOffset);
131 
132 void SetFramebufferID(GLuint id);
133 void SetBufferID(GLuint id);
134 void SetRenderbufferID(GLuint id);
135 void SetTextureID(GLuint id);
136 
137 void ValidateSerializedState(const char *serializedState, const char *fileName, uint32_t line);
138 #define VALIDATE_CHECKPOINT(STATE) ValidateSerializedState(STATE, __FILE__, __LINE__)
139 
140 #endif  // ANGLE_TRACE_FIXTURE_H_
141