Hash :
6c7208f9
Author :
Date :
2019-10-31T14:33:27
Capture/Replay: Implement mid-execution replay. Mid-execution replay starts the replay from a specific start frame instead of frame 0. Integration tests will then run between the start and end frames. This lets us make much smaller reproduction cases from large benchmarks or applications. We implement mid-execution replay via a cpp "Setup" function. The replay test will run the setup function before the starting frame. Test execution proceeds normally after setup. Currently we do not implement mid-execution capture. We run capture on all frames. Including frames before the start frame. We do this to intercept compiled shaders and programs for easier caching. This could be changed in the future to also start capture mid-execution. Mid- execution capture might require using ProgramBinary calls to capture shader and program data. Many captures are unimplemented. Several comments indicate missing functionality. There's a lot we can add as we explore replaying more complex applications and higher GL versions. We will also need some kind of state reset functionality so we can run the replay in a loop. Bug: angleproject:3611 Change-Id: I51841fc1a64e3622c34e49c85ed8919a9a7c0b20 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1689329 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.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 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
//
// Copyright 2002 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.
//
// ResourceManager.h : Defines the ResourceManager classes, which handle allocation and lifetime of
// GL objects.
#ifndef LIBANGLE_RESOURCEMANAGER_H_
#define LIBANGLE_RESOURCEMANAGER_H_
#include "angle_gl.h"
#include "common/angleutils.h"
#include "libANGLE/Error.h"
#include "libANGLE/HandleAllocator.h"
#include "libANGLE/HandleRangeAllocator.h"
#include "libANGLE/ResourceMap.h"
namespace rx
{
class GLImplFactory;
}
namespace gl
{
class Buffer;
struct Caps;
class Context;
class Sync;
class Framebuffer;
struct Limitations;
class MemoryObject;
class Path;
class Program;
class ProgramPipeline;
class Renderbuffer;
class Sampler;
class Shader;
class Semaphore;
class Texture;
template <typename HandleAllocatorType>
class ResourceManagerBase : angle::NonCopyable
{
public:
ResourceManagerBase();
void addRef();
void release(const Context *context);
protected:
virtual void reset(const Context *context) = 0;
virtual ~ResourceManagerBase() {}
HandleAllocatorType mHandleAllocator;
private:
size_t mRefCount;
};
template <typename ResourceType, typename HandleAllocatorType, typename ImplT, typename IDType>
class TypedResourceManager : public ResourceManagerBase<HandleAllocatorType>
{
public:
TypedResourceManager() {}
void deleteObject(const Context *context, IDType handle);
ANGLE_INLINE bool isHandleGenerated(IDType handle) const
{
// Zero is always assumed to have been generated implicitly.
return GetIDValue(handle) == 0 || mObjectMap.contains(handle);
}
typename ResourceMap<ResourceType, IDType>::Iterator begin() const
{
return mObjectMap.begin();
}
typename ResourceMap<ResourceType, IDType>::Iterator end() const { return mObjectMap.end(); }
protected:
~TypedResourceManager() override;
// Inlined in the header for performance.
template <typename... ArgTypes>
ANGLE_INLINE ResourceType *checkObjectAllocation(rx::GLImplFactory *factory,
IDType handle,
ArgTypes... args)
{
ResourceType *value = mObjectMap.query(handle);
if (value)
{
return value;
}
if (GetIDValue(handle) == 0)
{
return nullptr;
}
return checkObjectAllocationImpl(factory, handle, args...);
}
void reset(const Context *context) override;
ResourceMap<ResourceType, IDType> mObjectMap;
private:
template <typename... ArgTypes>
ResourceType *checkObjectAllocationImpl(rx::GLImplFactory *factory,
IDType handle,
ArgTypes... args)
{
ResourceType *object = ImplT::AllocateNewObject(factory, handle, args...);
if (!mObjectMap.contains(handle))
{
this->mHandleAllocator.reserve(GetIDValue(handle));
}
mObjectMap.assign(handle, object);
return object;
}
};
class BufferManager : public TypedResourceManager<Buffer, HandleAllocator, BufferManager, BufferID>
{
public:
BufferID createBuffer();
Buffer *getBuffer(BufferID handle) const;
ANGLE_INLINE Buffer *checkBufferAllocation(rx::GLImplFactory *factory, BufferID handle)
{
return checkObjectAllocation(factory, handle);
}
// TODO(jmadill): Investigate design which doesn't expose these methods publicly.
static Buffer *AllocateNewObject(rx::GLImplFactory *factory, BufferID handle);
static void DeleteObject(const Context *context, Buffer *buffer);
protected:
~BufferManager() override {}
};
class ShaderProgramManager : public ResourceManagerBase<HandleAllocator>
{
public:
ShaderProgramManager();
ShaderProgramID createShader(rx::GLImplFactory *factory,
const Limitations &rendererLimitations,
ShaderType type);
void deleteShader(const Context *context, ShaderProgramID shader);
Shader *getShader(ShaderProgramID handle) const;
ShaderProgramID createProgram(rx::GLImplFactory *factory);
void deleteProgram(const Context *context, ShaderProgramID program);
ANGLE_INLINE Program *getProgram(ShaderProgramID handle) const
{
return mPrograms.query(handle);
}
// For capture only.
const ResourceMap<Shader, ShaderProgramID> &getShadersForCapture() const { return mShaders; }
const ResourceMap<Program, ShaderProgramID> &getProgramsForCapture() const { return mPrograms; }
protected:
~ShaderProgramManager() override;
private:
template <typename ObjectType, typename IDType>
void deleteObject(const Context *context,
ResourceMap<ObjectType, IDType> *objectMap,
IDType id);
void reset(const Context *context) override;
ResourceMap<Shader, ShaderProgramID> mShaders;
ResourceMap<Program, ShaderProgramID> mPrograms;
};
class TextureManager
: public TypedResourceManager<Texture, HandleAllocator, TextureManager, TextureID>
{
public:
TextureID createTexture();
ANGLE_INLINE Texture *getTexture(TextureID handle) const
{
ASSERT(mObjectMap.query({0}) == nullptr);
return mObjectMap.query(handle);
}
void signalAllTexturesDirty() const;
ANGLE_INLINE Texture *checkTextureAllocation(rx::GLImplFactory *factory,
TextureID handle,
TextureType type)
{
return checkObjectAllocation(factory, handle, type);
}
static Texture *AllocateNewObject(rx::GLImplFactory *factory,
TextureID handle,
TextureType type);
static void DeleteObject(const Context *context, Texture *texture);
void enableHandleAllocatorLogging();
protected:
~TextureManager() override {}
};
class RenderbufferManager : public TypedResourceManager<Renderbuffer,
HandleAllocator,
RenderbufferManager,
RenderbufferID>
{
public:
RenderbufferID createRenderbuffer();
Renderbuffer *getRenderbuffer(RenderbufferID handle) const;
Renderbuffer *checkRenderbufferAllocation(rx::GLImplFactory *factory, RenderbufferID handle)
{
return checkObjectAllocation(factory, handle);
}
static Renderbuffer *AllocateNewObject(rx::GLImplFactory *factory, RenderbufferID handle);
static void DeleteObject(const Context *context, Renderbuffer *renderbuffer);
protected:
~RenderbufferManager() override {}
};
class SamplerManager
: public TypedResourceManager<Sampler, HandleAllocator, SamplerManager, SamplerID>
{
public:
SamplerID createSampler();
Sampler *getSampler(SamplerID handle) const;
bool isSampler(SamplerID sampler) const;
Sampler *checkSamplerAllocation(rx::GLImplFactory *factory, SamplerID handle)
{
return checkObjectAllocation(factory, handle);
}
static Sampler *AllocateNewObject(rx::GLImplFactory *factory, SamplerID handle);
static void DeleteObject(const Context *context, Sampler *sampler);
protected:
~SamplerManager() override {}
};
class SyncManager : public TypedResourceManager<Sync, HandleAllocator, SyncManager, GLuint>
{
public:
GLuint createSync(rx::GLImplFactory *factory);
Sync *getSync(GLuint handle) const;
static void DeleteObject(const Context *context, Sync *sync);
protected:
~SyncManager() override {}
};
class PathManager : public ResourceManagerBase<HandleRangeAllocator>
{
public:
PathManager();
angle::Result createPaths(Context *context, GLsizei range, PathID *numCreated);
void deletePaths(PathID first, GLsizei range);
Path *getPath(PathID handle) const;
bool hasPath(PathID handle) const;
protected:
~PathManager() override;
void reset(const Context *context) override;
private:
ResourceMap<Path, PathID> mPaths;
};
class FramebufferManager
: public TypedResourceManager<Framebuffer, HandleAllocator, FramebufferManager, FramebufferID>
{
public:
FramebufferID createFramebuffer();
Framebuffer *getFramebuffer(FramebufferID handle) const;
void setDefaultFramebuffer(Framebuffer *framebuffer);
void invalidateFramebufferCompletenessCache() const;
Framebuffer *checkFramebufferAllocation(rx::GLImplFactory *factory,
const Caps &caps,
FramebufferID handle)
{
return checkObjectAllocation<const Caps &>(factory, handle, caps);
}
static Framebuffer *AllocateNewObject(rx::GLImplFactory *factory,
FramebufferID handle,
const Caps &caps);
static void DeleteObject(const Context *context, Framebuffer *framebuffer);
protected:
~FramebufferManager() override {}
};
class ProgramPipelineManager : public TypedResourceManager<ProgramPipeline,
HandleAllocator,
ProgramPipelineManager,
ProgramPipelineID>
{
public:
ProgramPipelineID createProgramPipeline();
ProgramPipeline *getProgramPipeline(ProgramPipelineID handle) const;
ProgramPipeline *checkProgramPipelineAllocation(rx::GLImplFactory *factory,
ProgramPipelineID handle)
{
return checkObjectAllocation(factory, handle);
}
static ProgramPipeline *AllocateNewObject(rx::GLImplFactory *factory, ProgramPipelineID handle);
static void DeleteObject(const Context *context, ProgramPipeline *pipeline);
protected:
~ProgramPipelineManager() override {}
};
class MemoryObjectManager : public ResourceManagerBase<HandleAllocator>
{
public:
MemoryObjectManager();
MemoryObjectID createMemoryObject(rx::GLImplFactory *factory);
void deleteMemoryObject(const Context *context, MemoryObjectID handle);
MemoryObject *getMemoryObject(MemoryObjectID handle) const;
protected:
~MemoryObjectManager() override;
private:
void reset(const Context *context) override;
ResourceMap<MemoryObject, MemoryObjectID> mMemoryObjects;
};
class SemaphoreManager : public ResourceManagerBase<HandleAllocator>
{
public:
SemaphoreManager();
SemaphoreID createSemaphore(rx::GLImplFactory *factory);
void deleteSemaphore(const Context *context, SemaphoreID handle);
Semaphore *getSemaphore(SemaphoreID handle) const;
protected:
~SemaphoreManager() override;
private:
void reset(const Context *context) override;
ResourceMap<Semaphore, SemaphoreID> mSemaphores;
};
} // namespace gl
#endif // LIBANGLE_RESOURCEMANAGER_H_