Hash :
5118002e
Author :
Date :
2021-11-29T21:01:03
Capture/Replay: test and handle texture gen-on-bind Bug: angleproject:6425 Change-Id: Ieb4c0a7a6ffdbf0690c07c10e001835a0dcbb6e1 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3295620 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.com> Commit-Queue: Gert Wollny <gert.wollny@collabora.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// trace_fixture.cpp:
// Common code for the ANGLE trace replays.
//
#include "trace_fixture.h"
#include "angle_trace_gl.h"
#include <string>
namespace
{
void UpdateResourceMap(GLuint *resourceMap, GLuint id, GLsizei readBufferOffset)
{
GLuint returnedID;
memcpy(&returnedID, &gReadBuffer[readBufferOffset], sizeof(GLuint));
resourceMap[id] = returnedID;
}
DecompressCallback gDecompressCallback;
std::string gBinaryDataDir = ".";
void LoadBinaryData(const char *fileName)
{
// TODO(b/179188489): Fix cross-module deallocation.
if (gBinaryData != nullptr)
{
delete[] gBinaryData;
}
char pathBuffer[1000] = {};
sprintf(pathBuffer, "%s/%s", gBinaryDataDir.c_str(), fileName);
FILE *fp = fopen(pathBuffer, "rb");
if (fp == 0)
{
fprintf(stderr, "Error loading binary data file: %s\n", fileName);
return;
}
fseek(fp, 0, SEEK_END);
long size = ftell(fp);
fseek(fp, 0, SEEK_SET);
if (gDecompressCallback)
{
if (!strstr(fileName, ".gz"))
{
fprintf(stderr, "Filename does not end in .gz");
exit(1);
}
std::vector<uint8_t> compressedData(size);
(void)fread(compressedData.data(), 1, size, fp);
gBinaryData = gDecompressCallback(compressedData);
}
else
{
if (!strstr(fileName, ".angledata"))
{
fprintf(stderr, "Filename does not end in .angledata");
exit(1);
}
gBinaryData = new uint8_t[size];
(void)fread(gBinaryData, 1, size, fp);
}
fclose(fp);
}
ValidateSerializedStateCallback gValidateSerializedStateCallback;
std::unordered_map<GLuint, std::vector<GLint>> gInternalUniformLocationsMap;
} // namespace
GLint **gUniformLocations;
BlockIndexesMap gUniformBlockIndexes;
GLuint gCurrentProgram = 0;
void UpdateUniformLocation(GLuint program, const char *name, GLint location, GLint count)
{
std::vector<GLint> &programLocations = gInternalUniformLocationsMap[program];
if (static_cast<GLint>(programLocations.size()) < location + count)
{
programLocations.resize(location + count, 0);
}
for (GLint arrayIndex = 0; arrayIndex < count; ++arrayIndex)
{
GLuint mappedProgramID = gShaderProgramMap[program];
programLocations[location + arrayIndex] =
glGetUniformLocation(mappedProgramID, name) + arrayIndex;
}
gUniformLocations[program] = programLocations.data();
}
void DeleteUniformLocations(GLuint program)
{
// No-op. We leave uniform locations around so deleted current programs can still use them.
}
void UpdateUniformBlockIndex(GLuint program, const char *name, GLuint index)
{
gUniformBlockIndexes[program][index] = glGetUniformBlockIndex(program, name);
}
void UpdateCurrentProgram(GLuint program)
{
gCurrentProgram = program;
}
uint8_t *gBinaryData;
uint8_t *gReadBuffer;
uint8_t *gClientArrays[kMaxClientArrays];
SyncResourceMap gSyncMap;
ContextMap gContextMap;
GLuint *gBufferMap;
GLuint *gFenceNVMap;
GLuint *gFramebufferMap;
GLuint *gMemoryObjectMap;
GLuint *gProgramPipelineMap;
GLuint *gQueryMap;
GLuint *gRenderbufferMap;
GLuint *gSamplerMap;
GLuint *gSemaphoreMap;
GLuint *gShaderProgramMap;
GLuint *gTextureMap;
GLuint *gTransformFeedbackMap;
GLuint *gVertexArrayMap;
void SetBinaryDataDecompressCallback(DecompressCallback callback)
{
gDecompressCallback = callback;
}
void SetBinaryDataDir(const char *dataDir)
{
gBinaryDataDir = dataDir;
}
GLuint *AllocateZeroedUints(size_t count)
{
GLuint *mem = new GLuint[count + 1];
memset(mem, 0, sizeof(GLuint) * (count + 1));
return mem;
}
void InitializeReplay(const char *binaryDataFileName,
size_t maxClientArraySize,
size_t readBufferSize,
uint32_t maxBuffer,
uint32_t maxFenceNV,
uint32_t maxFramebuffer,
uint32_t maxMemoryObject,
uint32_t maxProgramPipeline,
uint32_t maxQuery,
uint32_t maxRenderbuffer,
uint32_t maxSampler,
uint32_t maxSemaphore,
uint32_t maxShaderProgram,
uint32_t maxTexture,
uint32_t maxTransformFeedback,
uint32_t maxVertexArray)
{
LoadBinaryData(binaryDataFileName);
for (uint8_t *&clientArray : gClientArrays)
{
clientArray = new uint8_t[maxClientArraySize];
}
gReadBuffer = new uint8_t[readBufferSize];
gBufferMap = AllocateZeroedUints(maxBuffer);
gFenceNVMap = AllocateZeroedUints(maxFenceNV);
gFramebufferMap = AllocateZeroedUints(maxFramebuffer);
gMemoryObjectMap = AllocateZeroedUints(maxMemoryObject);
gProgramPipelineMap = AllocateZeroedUints(maxProgramPipeline);
gQueryMap = AllocateZeroedUints(maxQuery);
gRenderbufferMap = AllocateZeroedUints(maxRenderbuffer);
gSamplerMap = AllocateZeroedUints(maxSampler);
gSemaphoreMap = AllocateZeroedUints(maxSemaphore);
gShaderProgramMap = AllocateZeroedUints(maxShaderProgram);
gTextureMap = AllocateZeroedUints(maxTexture);
gTransformFeedbackMap = AllocateZeroedUints(maxTransformFeedback);
gVertexArrayMap = AllocateZeroedUints(maxVertexArray);
gUniformLocations = new GLint *[maxShaderProgram + 1];
memset(gUniformLocations, 0, sizeof(GLint *) * (maxShaderProgram + 1));
}
void FinishReplay()
{
for (uint8_t *&clientArray : gClientArrays)
{
delete[] clientArray;
}
delete[] gReadBuffer;
delete[] gBufferMap;
delete[] gRenderbufferMap;
delete[] gTextureMap;
delete[] gFramebufferMap;
delete[] gShaderProgramMap;
delete[] gFenceNVMap;
delete[] gMemoryObjectMap;
delete[] gProgramPipelineMap;
delete[] gQueryMap;
delete[] gSamplerMap;
delete[] gSemaphoreMap;
delete[] gTransformFeedbackMap;
delete[] gVertexArrayMap;
}
void SetValidateSerializedStateCallback(ValidateSerializedStateCallback callback)
{
gValidateSerializedStateCallback = callback;
}
void UpdateClientArrayPointer(int arrayIndex, const void *data, uint64_t size)
{
memcpy(gClientArrays[arrayIndex], data, static_cast<size_t>(size));
}
BufferHandleMap gMappedBufferData;
void UpdateClientBufferData(GLuint bufferID, const void *source, GLsizei size)
{
memcpy(gMappedBufferData[gBufferMap[bufferID]], source, size);
}
void UpdateClientBufferDataWithOffset(GLuint bufferID,
const void *source,
GLsizei size,
GLsizei offset)
{
uintptr_t dest = reinterpret_cast<uintptr_t>(gMappedBufferData[gBufferMap[bufferID]]) + offset;
memcpy(reinterpret_cast<void *>(dest), source, size);
}
void UpdateBufferID(GLuint id, GLsizei readBufferOffset)
{
UpdateResourceMap(gBufferMap, id, readBufferOffset);
}
void UpdateFenceNVID(GLuint id, GLsizei readBufferOffset)
{
UpdateResourceMap(gFenceNVMap, id, readBufferOffset);
}
void UpdateFramebufferID(GLuint id, GLsizei readBufferOffset)
{
UpdateResourceMap(gFramebufferMap, id, readBufferOffset);
}
void UpdateMemoryObjectID(GLuint id, GLsizei readBufferOffset)
{
UpdateResourceMap(gMemoryObjectMap, id, readBufferOffset);
}
void UpdateProgramPipelineID(GLuint id, GLsizei readBufferOffset)
{
UpdateResourceMap(gProgramPipelineMap, id, readBufferOffset);
}
void UpdateQueryID(GLuint id, GLsizei readBufferOffset)
{
UpdateResourceMap(gQueryMap, id, readBufferOffset);
}
void UpdateRenderbufferID(GLuint id, GLsizei readBufferOffset)
{
UpdateResourceMap(gRenderbufferMap, id, readBufferOffset);
}
void UpdateSamplerID(GLuint id, GLsizei readBufferOffset)
{
UpdateResourceMap(gSamplerMap, id, readBufferOffset);
}
void UpdateSemaphoreID(GLuint id, GLsizei readBufferOffset)
{
UpdateResourceMap(gSemaphoreMap, id, readBufferOffset);
}
void UpdateShaderProgramID(GLuint id, GLsizei readBufferOffset)
{
UpdateResourceMap(gShaderProgramMap, id, readBufferOffset);
}
void UpdateTextureID(GLuint id, GLsizei readBufferOffset)
{
UpdateResourceMap(gTextureMap, id, readBufferOffset);
}
void UpdateTransformFeedbackID(GLuint id, GLsizei readBufferOffset)
{
UpdateResourceMap(gTransformFeedbackMap, id, readBufferOffset);
}
void UpdateVertexArrayID(GLuint id, GLsizei readBufferOffset)
{
UpdateResourceMap(gVertexArrayMap, id, readBufferOffset);
}
void SetResourceID(GLuint *map, GLuint id)
{
if (map[id] != 0)
{
fprintf(stderr, "%s: resource ID %d is already reserved\n", __func__, id);
exit(1);
}
map[id] = id;
}
void SetFramebufferID(GLuint id)
{
SetResourceID(gFramebufferMap, id);
}
void SetBufferID(GLuint id)
{
SetResourceID(gBufferMap, id);
}
void SetRenderbufferID(GLuint id)
{
SetResourceID(gRenderbufferMap, id);
}
void SetTextureID(GLuint id)
{
SetResourceID(gTextureMap, id);
}
void ValidateSerializedState(const char *serializedState, const char *fileName, uint32_t line)
{
if (gValidateSerializedStateCallback)
{
gValidateSerializedStateCallback(serializedState, fileName, line);
}
}