#include <Context.h>
Classes | |
| struct | ProgramsToSync |
Public Member Functions | |
| void | shutdown () |
| const std::string & | getBackendVersion () const |
| 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. More... | |
| void | appendFrameBatch (const BatchPointer &batch) |
| Appends a batch at the end of the current frame. More... | |
| FramePointer | endFrame () |
| Finalizes the currently recorded frame. More... | |
| void | recycle () const |
| void | executeBatch (Batch &batch) const |
| void | executeBatch (const char *name, std::function< void(Batch &)> lambda) const |
| void | executeFrame (const FramePointer &frame) const |
| void | consumeFrameUpdates (const FramePointer &frame) const |
| const BackendPointer & | getBackend () const |
| void | enableStereo (bool enable=true) |
| Enables stereo for the context. More... | |
| bool | isStereo () |
| void | setStereoProjections (const mat4 eyeProjections[2]) |
| Sets projection matrices for each eye. More... | |
| void | setStereoViews (const mat4 eyeViews[2]) |
| Sets view matrices for each eye. More... | |
| void | getStereoProjections (mat4 *eyeProjections) const |
Writes current stereo projection matrices to a given mat4 array. More... | |
| void | getStereoViews (mat4 *eyeViews) const |
Writes current stereo view matrices to a given mat4 array. More... | |
| void | downloadFramebuffer (const FramebufferPointer &srcFramebuffer, const Vec4i ®ion, QImage &destImage) |
| Writes a region of a given framebuffer to a QImage. More... | |
| void | resetStats () const |
| Resets render statistics such as draw call count. | |
| void | getStats (ContextStats &stats) const |
| Retrieves current render statistics such as draw call count. More... | |
| void | getFrameStats (ContextStats &stats) const |
| Retrieves most recent frame render statistics such as draw call count. More... | |
| double | getFrameTimerGPUAverage () const |
| double | getFrameTimerBatchAverage () const |
| void | pushProgramsToSync (const std::vector< uint32_t > &programIDs, std::function< void()> callback, size_t rate=0) |
| Schedule shaders for loading. More... | |
| void | pushProgramsToSync (const std::vector< gpu::ShaderPointer > &programs, std::function< void()> callback, size_t rate=0) |
| Schedule shaders for loading. More... | |
| void | processProgramsToSync () |
| Loads and compiles shaders. More... | |
Static Public Member Functions | |
| template<class T > | |
| static void | init () |
| Creates graphics-API specific Backend object. More... | |
| static BatchPointer | acquireBatch (const char *name=nullptr) |
| Acquires batch from a batch pool and sets its name. More... | |
| static void | releaseBatch (Batch *batch) |
| Clears the batch and adds it batch to the pool. More... | |
| static PipelinePointer | createMipGenerationPipeline (const ShaderPointer &pixelShader) |
| Creates a custom pipeline for generating mipmaps. More... | |
| static Size | getFreeGPUMemSize () |
| static Size | getUsedGPUMemSize () |
| static uint32_t | getBufferGPUCount () |
| static Size | getBufferGPUMemSize () |
| static uint32_t | getTextureGPUCount () |
| static uint32_t | getTextureResidentGPUCount () |
| static uint32_t | getTextureFramebufferGPUCount () |
| static uint32_t | getTextureResourceGPUCount () |
| static uint32_t | getTextureExternalGPUCount () |
| static Size | getTextureGPUMemSize () |
| static Size | getTextureResidentGPUMemSize () |
| static Size | getTextureFramebufferGPUMemSize () |
| static Size | getTextureResourceGPUMemSize () |
| static Size | getTextureExternalGPUMemSize () |
| static uint32_t | getTexturePendingGPUTransferCount () |
| static Size | getTexturePendingGPUTransferMemSize () |
| static Size | getTextureResourcePopulatedGPUMemSize () |
| static Size | getTextureResourceIdealGPUMemSize () |
Protected Member Functions | |
| Context (const Context &context)=delete | |
Static Protected Member Functions | |
| static void | clearBatches () |
| Deletes all batches in the batch pool. More... | |
Protected Attributes | |
| std::shared_ptr< Backend > | _backend |
| FramePointer | _currentFrame |
| RangeTimerPointer | _frameRangeTimer |
| StereoState | _stereo |
| std::mutex | _programsToSyncMutex |
| std::queue< ProgramsToSync > | _programsToSyncQueue |
| gpu::Shaders | _syncedPrograms |
| size_t | _nextProgramToSyncIndex { 0 } |
| ContextStats | _frameStats |
Static Protected Attributes | |
| static CreateBackend | _createBackendCallback = nullptr |
| static std::once_flag | _initialized |
| static std::mutex | _batchPoolMutex |
| static std::list< Batch * > | _batchPool |
DOCTODO
|
protecteddelete |
Copy constructor, not used.
| context | Not used. |
|
static |
Acquires batch from a batch pool and sets its name.
If there are no free batches, it creates new one.
| name | Name to set fot the batch. |
| void Context::appendFrameBatch | ( | const BatchPointer & | batch | ) |
Appends a batch at the end of the current frame.
| batch | Batch to append. |
| void Context::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.
| renderView | The view matrix used for rendering the frame, only applicable for HMDs. |
| renderPose | HMD head pose. |
|
staticprotected |
Deletes all batches in the batch pool.
Called from the Context destructor. TODO: Should probably move this functionality to Batch. (this comment was here since High Fidelity days, I'm not sure if it still makes sense)
| void Context::consumeFrameUpdates | ( | const FramePointer & | frame | ) | const |
Consuming a frame applies any updates queued from the recording thread and applies them to the shadow copy used by the rendering thread.
EVERY frame generated MUST be consumed, regardless of whether the frame is actually executed, or the buffer shadow copies can become unsynced from the recording thread copies.
Consuming a frame is idempotent, as the frame encapsulates the updates and clears them out as it applies them, so calling it more than once on a given frame will have no effect after the first time
This is automatically called by executeFrame, so you only need to call it if you have frames you aren't going to otherwise execute, for instance when a display plugin is being disabled, or in the null display plugin where no rendering actually occurs MUST only be called on the Present thread, which does rendering.
| frame | Frame for which updates are to be consumed. |
|
static |
Creates a custom pipeline for generating mipmaps.
Used for SSAO.
| pixelShader | Pixel shader to use for mipmap generation. |
| void Context::downloadFramebuffer | ( | const FramebufferPointer & | srcFramebuffer, |
| const Vec4i & | region, | ||
| QImage & | destImage | ||
| ) |
Writes a region of a given framebuffer to a QImage.
Downloading the Framebuffer is a synchronous action that is not efficient. It s here for convenience to easily capture a snapshot
| srcFramebuffer | Framebuffer from which to capture the contents. |
| region | Area to capture. First two coordinates are position of the corner in pixels, and second two are width and height. |
| destImage | QImage object. Needs to be a correct size and format. |
| void Context::enableStereo | ( | bool | enable = true | ) |
Enables stereo for the context.
Called in render_performFrame, where frame rendering commands are recorded.
| enable | True if stereo rendering should be enabled. |
| FramePointer Context::endFrame | ( | ) |
Finalizes the currently recorded frame.
After calling this function batches cannot be added to the frame anymore.
| void Context::executeBatch | ( | Batch & | batch | ) | const |
Execute a batch immediately, rather than as part of a frame. MUST only be called on the Present thread, which does rendering.
| batch |
| void Context::executeBatch | ( | const char * | name, |
| std::function< void(Batch &)> | lambda | ||
| ) | const |
Execute a batch immediately, rather than as part of a frame. MUST only be called on the Present thread, which does rendering.
| name | Name of the batch. |
| lambda | Function that adds commands to batch that will be executed. |
| void Context::executeFrame | ( | const FramePointer & | frame | ) | const |
Executes a frame, applying any updates contained in the frame batches to the rendering thread shadow copies. Either executeFrame or consumeFrameUpdates MUST be called on every frame generated, IN THE ORDER they were generated.
| frame | Frame to be executed. |
|
inline |
| const std::string & Context::getBackendVersion | ( | ) | const |
|
static |
|
static |
| void Context::getFrameStats | ( | ContextStats & | stats | ) | const |
Retrieves most recent frame render statistics such as draw call count.
Same as above but updated at every end of a frame
| stats | Object to which current statistics will be written. |
| double Context::getFrameTimerBatchAverage | ( | ) | const |
| double Context::getFrameTimerGPUAverage | ( | ) | const |
|
static |
| void Context::getStats | ( | ContextStats & | stats | ) | const |
Retrieves current render statistics such as draw call count.
| stats | Object to which current statistics will be written. |
| void Context::getStereoProjections | ( | mat4 * | eyeProjections | ) | const |
Writes current stereo projection matrices to a given mat4 array.
| eyeProjections | Pointer to the array of matrices. Array needs to have 2 matrices. |
| void Context::getStereoViews | ( | mat4 * | eyeViews | ) | const |
Writes current stereo view matrices to a given mat4 array.
| eyeViews | Pointer to the array of matrices. Array needs to have 2 matrices. |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
TODO: Currently not used.
|
static |
|
static |
TextureUsageType::STRICT_RESOURCE.
|
static |
TextureUsageType::STRICT_RESOURCE.
|
static |
|
static |
|
static |
|
static |
|
static |
|
inlinestatic |
Creates graphics-API specific Backend object.
This one call must happen before any context is created or used (Shader::MakeProgram) in order to set up the Backend and any singleton data needed.
| T | Type of the backend to create, specific to given graphics API. |
| bool Context::isStereo | ( | ) |
true if stereo rendering was enabled with enableStereo. | void Context::processProgramsToSync | ( | ) |
Loads and compiles shaders.
Called once per frame.
| void Context::pushProgramsToSync | ( | const std::vector< gpu::ShaderPointer > & | programs, |
| std::function< void()> | callback, | ||
| size_t | rate = 0 |
||
| ) |
Schedule shaders for loading.
| programs | Pointers to shaders to be loaded and compiled. |
| callback | Function to call when work is done. |
| rate | Limits how many shaders can be processed in a single frame. |
| void Context::pushProgramsToSync | ( | const std::vector< uint32_t > & | programIDs, |
| std::function< void()> | callback, | ||
| size_t | rate = 0 |
||
| ) |
Schedule shaders for loading.
| programIDs | IDs representing shaders to be synchronized. Can be found in ShaderEnums.h file, which is generated at build time. |
| callback | Function to call when work is done. |
| rate | Limits how many shaders can be processed in a single frame. |
| void Context::recycle | ( | ) | const |
Handle any pending operations to clean up (recycle / deallocate) resources no longer in use. MUST only be called on the Present thread, which does rendering.
|
static |
Clears the batch and adds it batch to the pool.
| batch | Batch to be released. |
| void Context::setStereoProjections | ( | const mat4 | eyeProjections[2] | ) |
Sets projection matrices for each eye.
Used in render_performFrame before recording the frame rendering commands,
| eyeProjections |
| void Context::setStereoViews | ( | const mat4 | eyeViews[2] | ) |
Sets view matrices for each eye.
DOCTODO: What coordinate system does this use? Used in render_performFrame before recording the frame rendering commands,
| eyeViews |
| void Context::shutdown | ( | ) |
@bried Shuts down and deletes graphics backend.
|
protected |
Instance of Backend class specific to currently selected graphics APT, for example Vulkan or OpenGL.
|
staticprotected |
Pool of batches that can be acquired by renderer and reused for recording.
|
staticprotected |
Mutex for accessing batch pool.
|
staticprotected |
API-specific call that creates rendering backend.
|
protected |
Frame currently being recorded. A new Frame object is placed here by beginFrame and the variable is reset by endFrame.
|
protected |
Time it takes for the frame to execute.
|
mutableprotected |
Sampled at the end of every frame, the stats of all the counters.
|
staticprotected |
Ensures that initialization inside Context::init() is called only once.
|
protected |
Next shader that will be loaded/compiled.
|
protected |
Mutex protecting _programsToSyncQueue, must be locked every time it's accessed.
|
protected |
Queue for loading and compiling shaders. It helps avoid stutter later during the game.
|
protected |
Stereo state is configured before frame recording starts.
|
protected |
Shaders that were already loaded/compiled.