• 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 
39 extern "C" {
40 ANGLE_REPLAY_EXPORT void SetBinaryDataDecompressCallback(DecompressCallback callback);
41 ANGLE_REPLAY_EXPORT void SetBinaryDataDir(const char *dataDir);
42 ANGLE_REPLAY_EXPORT void SetupReplay();
43 ANGLE_REPLAY_EXPORT void ReplayFrame(uint32_t frameIndex);
44 ANGLE_REPLAY_EXPORT void ResetReplay();
45 ANGLE_REPLAY_EXPORT void FinishReplay();
46 
47 // Only defined if serialization is enabled.
48 ANGLE_REPLAY_EXPORT const char *GetSerializedContextState(uint32_t frameIndex);
49 }  // extern "C"
50 
51 // Maps from <captured Program ID, captured location> to run-time location.
52 using LocationsMap = std::unordered_map<GLuint, std::unordered_map<GLint, GLint>>;
53 extern LocationsMap gUniformLocations;
54 using BlockIndexesMap = std::unordered_map<GLuint, std::unordered_map<GLuint, GLuint>>;
55 extern BlockIndexesMap gUniformBlockIndexes;
56 extern GLuint gCurrentProgram;
57 void UpdateUniformLocation(GLuint program, const char *name, GLint location);
58 void DeleteUniformLocations(GLuint program);
59 void UpdateUniformBlockIndex(GLuint program, const char *name, GLuint index);
60 void UpdateCurrentProgram(GLuint program);
61 
62 // Maps from captured Resource ID to run-time Resource ID.
63 class ResourceMap
64 {
65   public:
ResourceMap()66     ResourceMap() {}
67     GLuint &operator[](GLuint index)
68     {
69         if (mIDs.size() <= static_cast<size_t>(index))
70             mIDs.resize(index + 1, 0);
71         return mIDs[index];
72     }
73 
74   private:
75     std::vector<GLuint> mIDs;
76 };
77 
78 void InitializeReplay(const char *binaryDataFileName,
79                       size_t maxClientArraySize,
80                       size_t readBufferSize);
81 
82 // Global state
83 
84 constexpr size_t kMaxClientArrays = 16;
85 
86 extern uint8_t *gBinaryData;
87 extern uint8_t *gReadBuffer;
88 extern uint8_t *gClientArrays[kMaxClientArrays];
89 extern ResourceMap gBufferMap;
90 extern ResourceMap gFenceNVMap;
91 extern ResourceMap gFramebufferMap;
92 extern ResourceMap gMemoryObjectMap;
93 extern ResourceMap gProgramPipelineMap;
94 extern ResourceMap gQueryMap;
95 extern ResourceMap gRenderbufferMap;
96 extern ResourceMap gSamplerMap;
97 extern ResourceMap gSemaphoreMap;
98 extern ResourceMap gShaderProgramMap;
99 extern ResourceMap gTextureMap;
100 extern ResourceMap gTransformFeedbackMap;
101 extern ResourceMap gVertexArrayMap;
102 using SyncResourceMap = std::unordered_map<uintptr_t, GLsync>;
103 extern SyncResourceMap gSyncMap;
104 
105 void UpdateClientArrayPointer(int arrayIndex, const void *data, uint64_t size);
106 using BufferHandleMap = std::unordered_map<GLuint, void *>;
107 extern BufferHandleMap gMappedBufferData;
108 void UpdateClientBufferData(GLuint bufferID, const void *source, GLsizei size);
109 void UpdateBufferID(GLuint id, GLsizei readBufferOffset);
110 void UpdateFenceNVID(GLuint id, GLsizei readBufferOffset);
111 void UpdateFramebufferID(GLuint id, GLsizei readBufferOffset);
112 void UpdateMemoryObjectID(GLuint id, GLsizei readBufferOffset);
113 void UpdateProgramPipelineID(GLuint id, GLsizei readBufferOffset);
114 void UpdateQueryID(GLuint id, GLsizei readBufferOffset);
115 void UpdateRenderbufferID(GLuint id, GLsizei readBufferOffset);
116 void UpdateSamplerID(GLuint id, GLsizei readBufferOffset);
117 void UpdateSemaphoreID(GLuint id, GLsizei readBufferOffset);
118 void UpdateShaderProgramID(GLuint id, GLsizei readBufferOffset);
119 void UpdateTextureID(GLuint id, GLsizei readBufferOffset);
120 void UpdateTransformFeedbackID(GLuint id, GLsizei readBufferOffset);
121 void UpdateVertexArrayID(GLuint id, GLsizei readBufferOffset);
122 
123 #endif  // ANGLE_TRACE_FIXTURE_H_
124