12 #ifndef hifi_gpu_Context_h
13 #define hifi_gpu_Context_h
22 #include "PointerStorage.h"
31 using Size = Resource::Size;
32 typedef BackendPointer (*CreateBackend)();
68 void beginFrame(
const glm::mat4& renderView = glm::mat4(),
const glm::mat4& renderPose = glm::mat4());
91 static BatchPointer
acquireBatch(
const char* name =
nullptr);
121 void executeBatch(
const char* name, std::function<
void(Batch&)> lambda)
const;
208 void downloadFramebuffer(
const FramebufferPointer& srcFramebuffer,
const Vec4i& region, QImage& destImage);
220 void getStats(ContextStats& stats)
const;
350 ProgramsToSync(
const std::vector<gpu::ShaderPointer>& programs, std::function<
void()> callback,
size_t rate) :
351 programs(programs), callback(callback), rate(rate) {}
353 std::vector<gpu::ShaderPointer> programs;
354 std::function<void()> callback;
365 void pushProgramsToSync(
const std::vector<uint32_t>& programIDs, std::function<
void()> callback,
size_t rate = 0);
374 void pushProgramsToSync(
const std::vector<gpu::ShaderPointer>& programs, std::function<
void()> callback,
size_t rate = 0);
399 bool _frameActive{
false };
472 friend class Backend;
474 typedef std::shared_ptr<Context> ContextPointer;
483 void doInBatch(
const char* name,
const std::shared_ptr<gpu::Context>& context,
const std::function<
void(Batch& batch)>& f);
Definition: gpu/src/gpu/Context.h:29
static uint32_t getTextureResidentGPUCount()
Definition: gpu/src/gpu/Context.cpp:240
static void clearBatches()
Deletes all batches in the batch pool.
Definition: gpu/src/gpu/Context.cpp:332
static void init()
Creates graphics-API specific Backend object.
Definition: gpu/src/gpu/Context.h:42
static Size getTextureFramebufferGPUMemSize()
Definition: gpu/src/gpu/Context.cpp:259
void downloadFramebuffer(const FramebufferPointer &srcFramebuffer, const Vec4i ®ion, QImage &destImage)
Writes a region of a given framebuffer to a QImage.
Definition: gpu/src/gpu/Context.cpp:191
FramePointer endFrame()
Finalizes the currently recorded frame.
Definition: gpu/src/gpu/Context.cpp:93
std::shared_ptr< Backend > _backend
Definition: gpu/src/gpu/Context.h:394
static void releaseBatch(Batch *batch)
Clears the batch and adds it batch to the pool.
Definition: gpu/src/gpu/Context.cpp:357
Context(const Context &context)=delete
static Size getTextureResourceIdealGPUMemSize()
Definition: gpu/src/gpu/Context.cpp:291
bool isStereo()
Definition: gpu/src/gpu/Context.cpp:163
const BackendPointer & getBackend() const
Definition: gpu/src/gpu/Context.h:155
void enableStereo(bool enable=true)
Enables stereo for the context.
Definition: gpu/src/gpu/Context.cpp:159
static Size getTextureResidentGPUMemSize()
Definition: gpu/src/gpu/Context.cpp:256
void resetStats() const
Resets render statistics such as draw call count.
Definition: gpu/src/gpu/Context.cpp:195
static Size getTextureGPUMemSize()
Definition: gpu/src/gpu/Context.cpp:253
static BatchPointer acquireBatch(const char *name=nullptr)
Acquires batch from a batch pool and sets its name.
Definition: gpu/src/gpu/Context.cpp:339
void executeBatch(Batch &batch) const
Definition: gpu/src/gpu/Context.cpp:111
void recycle() const
Definition: gpu/src/gpu/Context.cpp:121
StereoState _stereo
Definition: gpu/src/gpu/Context.h:415
static Size getTextureResourcePopulatedGPUMemSize()
Definition: gpu/src/gpu/Context.cpp:277
std::mutex _programsToSyncMutex
Definition: gpu/src/gpu/Context.h:420
gpu::Shaders _syncedPrograms
Definition: gpu/src/gpu/Context.h:430
void executeFrame(const FramePointer &frame) const
Definition: gpu/src/gpu/Context.cpp:131
static Size getBufferGPUMemSize()
Definition: gpu/src/gpu/Context.cpp:233
void pushProgramsToSync(const std::vector< uint32_t > &programIDs, std::function< void()> callback, size_t rate=0)
Schedule shaders for loading.
Definition: gpu/src/gpu/Context.cpp:295
static std::once_flag _initialized
Definition: gpu/src/gpu/Context.h:450
void shutdown()
Definition: gpu/src/gpu/Context.cpp:62
void getStereoViews(mat4 *eyeViews) const
Writes current stereo view matrices to a given mat4 array.
Definition: gpu/src/gpu/Context.cpp:185
static std::mutex _batchPoolMutex
Definition: gpu/src/gpu/Context.h:464
void getStereoProjections(mat4 *eyeProjections) const
Writes current stereo projection matrices to a given mat4 array.
Definition: gpu/src/gpu/Context.cpp:179
void setStereoViews(const mat4 eyeViews[2])
Sets view matrices for each eye.
Definition: gpu/src/gpu/Context.cpp:173
void beginFrame(const glm::mat4 &renderView=glm::mat4(), const glm::mat4 &renderPose=glm::mat4())
Creates and sets up new Frame object to which batches of renderer commands will be written.
Definition: gpu/src/gpu/Context.cpp:73
FramePointer _currentFrame
Definition: gpu/src/gpu/Context.h:405
static uint32_t getBufferGPUCount()
Definition: gpu/src/gpu/Context.cpp:229
static uint32_t getTextureFramebufferGPUCount()
Definition: gpu/src/gpu/Context.cpp:243
double getFrameTimerGPUAverage() const
Definition: gpu/src/gpu/Context.cpp:207
static uint32_t getTextureExternalGPUCount()
Definition: gpu/src/gpu/Context.cpp:249
std::queue< ProgramsToSync > _programsToSyncQueue
Definition: gpu/src/gpu/Context.h:425
const std::string & getBackendVersion() const
Definition: gpu/src/gpu/Context.cpp:69
static Size getUsedGPUMemSize()
Definition: gpu/src/gpu/Context.cpp:225
static uint32_t getTexturePendingGPUTransferCount()
Definition: gpu/src/gpu/Context.cpp:269
static std::list< Batch * > _batchPool
Definition: gpu/src/gpu/Context.h:469
static Size getTexturePendingGPUTransferMemSize()
Definition: gpu/src/gpu/Context.cpp:273
size_t _nextProgramToSyncIndex
Definition: gpu/src/gpu/Context.h:435
static PipelinePointer createMipGenerationPipeline(const ShaderPointer &pixelShader)
Creates a custom pipeline for generating mipmaps.
Definition: gpu/src/gpu/Context.cpp:281
void consumeFrameUpdates(const FramePointer &frame) const
Definition: gpu/src/gpu/Context.cpp:126
void getFrameStats(ContextStats &stats) const
Retrieves most recent frame render statistics such as draw call count.
Definition: gpu/src/gpu/Context.cpp:203
RangeTimerPointer _frameRangeTimer
Definition: gpu/src/gpu/Context.h:410
static Size getFreeGPUMemSize()
Definition: gpu/src/gpu/Context.cpp:221
void setStereoProjections(const mat4 eyeProjections[2])
Sets projection matrices for each eye.
Definition: gpu/src/gpu/Context.cpp:167
static CreateBackend _createBackendCallback
Definition: gpu/src/gpu/Context.h:445
void getStats(ContextStats &stats) const
Retrieves current render statistics such as draw call count.
Definition: gpu/src/gpu/Context.cpp:199
static uint32_t getTextureResourceGPUCount()
Definition: gpu/src/gpu/Context.cpp:246
static uint32_t getTextureGPUCount()
Definition: gpu/src/gpu/Context.cpp:237
ContextStats _frameStats
Definition: gpu/src/gpu/Context.h:440
static Size getTextureResourceGPUMemSize()
Definition: gpu/src/gpu/Context.cpp:262
void processProgramsToSync()
Loads and compiles shaders.
Definition: gpu/src/gpu/Context.cpp:308
void appendFrameBatch(const BatchPointer &batch)
Appends a batch at the end of the current frame.
Definition: gpu/src/gpu/Context.cpp:85
static Size getTextureExternalGPUMemSize()
Definition: gpu/src/gpu/Context.cpp:265
double getFrameTimerBatchAverage() const
Definition: gpu/src/gpu/Context.cpp:214
Definition: gpu/src/gpu/Context.h:344
ProgramsToSync(const std::vector< gpu::ShaderPointer > &programs, std::function< void()> callback, size_t rate)
Definition: gpu/src/gpu/Context.h:350
Definition: gpu/src/gpu/Forward.h:105