Rendu
A lightweight rendering engine for experimentations
|
Provide utility functions to communicate with the driver and GPU. More...
#include <GPU.hpp>
Classes | |
struct | Metrics |
Static Public Member Functions | |
static bool | setup (const std::string &appName) |
static bool | setupWindow (Window *window) |
static void | createGraphicsProgram (Program &program, const std::string &vertexContent, const std::string &fragmentContent, const std::string &tessControlContent, const std::string &tessEvalContent, const std::string &debugInfos) |
static void | createComputeProgram (Program &program, const std::string &computeContent, const std::string &debugInfos) |
static void | bindProgram (const Program &program) |
static void | beginRender (const Load &depthOp, const Load &stencilOp, const Texture *depthStencil, const Load &colorOp, const Texture *color0=nullptr, const Texture *color1=nullptr, const Texture *color2=nullptr, const Texture *color3=nullptr) |
static void | beginRender (const Load &colorOp, const Texture *color0, const Texture *color1=nullptr, const Texture *color2=nullptr, const Texture *color3=nullptr) |
static void | beginRender (const Load &depthOp, const Load &stencilOp, const Texture *depthStencil) |
static void | beginRender (uint layer, uint mip, const Load &depthOp, const Load &stencilOp, const Texture *depthStencil, const Load &colorOp, const Texture *color0=nullptr, const Texture *color1=nullptr, const Texture *color2=nullptr, const Texture *color3=nullptr) |
static void | beginRender (uint layer, uint mip, const Load &colorOp, const Texture *color0, const Texture *color1=nullptr, const Texture *color2=nullptr, const Texture *color3=nullptr) |
static void | beginRender (uint layer, uint mip, const Load &depthOp, const Load &stencilOp, const Texture *depthStencil) |
static void | beginRender (const Window &window, const Load &depthOp=Load::Operation::DONTCARE, const Load &stencilOp=Load::Operation::DONTCARE, const Load &colorOp=Load::Operation::DONTCARE) |
static void | endRender () |
static void | saveTexture (Texture &texture, const std::string &path, Image::Save options) |
static void | setupTexture (Texture &texture) |
static void | uploadTexture (const Texture &texture) |
static void | downloadTextureSync (Texture &texture) |
static void | downloadTextureSync (Texture &texture, int level) |
static GPUAsyncTask | downloadTextureAsync (const Texture &texture, const glm::uvec2 &offset, const glm::uvec2 &size, uint layerCount, std::function< void(const Texture &)> callback) |
static void | cancelAsyncOperation (const GPUAsyncTask &id) |
static void | generateMipMaps (const Texture &texture) |
static void | clearTexture (const Texture &texture, const glm::vec4 &color) |
static void | clearDepth (const Texture &texture, float depth) |
static void | setupBuffer (Buffer &buffer) |
static void | uploadBuffer (const Buffer &buffer, size_t size, uchar *data, size_t offset=0) |
static void | downloadBufferSync (const Buffer &buffer, size_t size, uchar *data, size_t offset=0) |
static void | flushBuffer (const Buffer &buffer, size_t size, size_t offset) |
static void | setupMesh (Mesh &mesh) |
static void | drawMesh (const Mesh &mesh) |
static void | drawTesselatedMesh (const Mesh &mesh, uint patchSize) |
static void | drawQuad () |
static void | dispatch (uint width, uint height, uint depth) |
static void | flush () |
static void | nextFrame () |
static void | deviceInfos (std::string &vendor, std::string &renderer, std::string &version, std::string &shaderVersion) |
static std::vector< std::string > | supportedExtensions () |
static void | setViewport (int x, int y, int w, int h) |
static void | setViewport (const Texture &tex) |
static void | setDepthState (bool test) |
static void | setDepthState (bool test, TestFunction function, bool write) |
static void | setStencilState (bool test, bool write) |
static void | setStencilState (bool test, TestFunction function, StencilOp fail, StencilOp pass, StencilOp depthFail, uchar value) |
static void | setBlendState (bool test) |
static void | setBlendState (bool test, BlendEquation equation, BlendFunction src, BlendFunction dst) |
static void | setCullState (bool cull) |
static void | setCullState (bool cull, Faces culledFaces) |
static void | setPolygonState (PolygonMode mode) |
static void | setColorState (bool writeRed, bool writeGreen, bool writeBlue, bool writeAlpha) |
static void | getState (GPUState &state) |
static const Metrics & | getMetrics () |
static void | blitDepth (const Texture &src, const Texture &dst) |
static void | blit (const Texture &src, const Texture &dst, Filter filter) |
static void | blit (const Texture &src, const Texture &dst, size_t lSrc, size_t lDst, Filter filter) |
static void | blit (const Texture &src, const Texture &dst, size_t lSrc, size_t lDst, size_t mipSrc, size_t mipDst, Filter filter) |
static GPUContext * | getInternal () |
static void | cleanup () |
Static Private Member Functions | |
static void | bindAttachments (uint layer, uint mip, const Load &colorOp, const Load &depthOp, const Load &stencilOp, const Texture *depthStencil, const Texture *color0, const Texture *color1, const Texture *color2, const Texture *color3) |
static void | bindGraphicsPipelineIfNeeded () |
static void | bindComputePipelineIfNeeded () |
static void | endRenderingIfNeeded () |
static void | beginFrameCommandBuffers () |
static void | submitFrameCommandBuffers () |
static void | clean (GPUTexture &tex) |
static void | clean (GPUMesh &mesh) |
static void | clean (GPUBuffer &buffer) |
static void | clean (Program &program) |
static void | processDestructionRequests () |
static void | processAsyncTasks (bool forceAll=false) |
Static Private Attributes | |
static GPUState | _state |
Current GPU state. | |
static GPUState | _lastState |
Previous draw call GPU state for caching. | |
static Metrics | _metrics |
Internal metrics (draw count, state changes,...). | |
static Metrics | _metricsPrevious |
Internal metrics for the last completed frame. | |
static Mesh | _quad |
Screen-covering triangle. | |
Friends | |
class | GPUTexture |
Access to deletion notifier for cached state update. | |
class | GPUBuffer |
Access to deletion notifier for cached state update. | |
class | GPUMesh |
Access to deletion notifier for cached state update. | |
class | Program |
Access to metrics. | |
class | Swapchain |
Access to command buffers. | |
class | PipelineCache |
Access to metrics. | |
Provide utility functions to communicate with the driver and GPU.
|
staticprivate |
Begin render and upload command buffers for this frame
|
static |
Begin rendering to a set of textures set as attachments.
colorOp | the operation to perform on the color attachments |
color0 | the first color attachment |
color1 | the second color attachment (optional) |
color2 | the third color attachment (optional) |
color3 | the fourth color attachment (optional) |
|
static |
Begin rendering to a set of textures set as attachments.
depthOp | the operation to perform on the depth attachment |
stencilOp | the operation to perform on the stencil attachment |
depthStencil | the depth/stencil attachment |
|
static |
Begin rendering to a set of textures set as attachments.
depthOp | the operation to perform on the depth attachment |
stencilOp | the operation to perform on the stencil attachment |
depthStencil | the depth/stencil attachment (optional) |
colorOp | the operation to perform on the color attachments |
color0 | the first color attachment (optional) |
color1 | the second color attachment (optional) |
color2 | the third color attachment (optional) |
color3 | the fourth color attachment (optional) |
|
static |
Begin rendering to the swapchain backbuffer (convenience helper).
window | the window attached to the swapchain to render to |
depthOp | the operation to perform on the depth attachment |
stencilOp | the operation to perform on the stencil attachment |
colorOp | the operation to perform on the color attachments |
|
static |
Begin rendering to a set of textures set as attachments.
layer | the texture layer to bind |
mip | the mip level to bind |
colorOp | the operation to perform on the color attachments |
color0 | the first color attachment |
color1 | the second color attachment (optional) |
color2 | the third color attachment (optional) |
color3 | the fourth color attachment (optional) |
|
static |
Begin rendering to a set of textures set as attachments.
layer | the texture layer to bind |
mip | the mip level to bind |
depthOp | the operation to perform on the depth attachment |
stencilOp | the operation to perform on the stencil attachment |
depthStencil | the depth/stencil attachment |
|
static |
Begin rendering to a set of textures set as attachments.
layer | the texture layer to bind |
mip | the mip level to bind |
depthOp | the operation to perform on the depth attachment |
stencilOp | the operation to perform on the stencil attachment |
depthStencil | the depth/stencil attachment (optional) |
colorOp | the operation to perform on the color attachments |
color0 | the first color attachment (optional) |
color1 | the second color attachment (optional) |
color2 | the third color attachment (optional) |
color3 | the fourth color attachment (optional) |
|
staticprivate |
Bind textures as a draw destination.
layer | the texture layer to bind |
mip | the mip level to bind |
colorOp | the operation to perform on the color attachments |
depthOp | the operation to perform on the depth attachment |
stencilOp | the operation to perform on the stencil attachment |
depthStencil | the depth/stencil attachment (optional) |
color0 | the first color attachment (optional) |
color1 | the second color attachment (optional) |
color2 | the third color attachment (optional) |
color3 | the fourth color attachment (optional) |
|
staticprivate |
If the GPU compute state has changed, retrieve and bind the pipeline corresponding to the new state.
|
staticprivate |
If the GPU graphics state has changed, retrieve and bind the pipeline corresponding to the new state.
|
static |
Bind a program to use for rendering
program | the program to use |
Blit the content of a texture into another one, resizing the content accordingly.
src | the source texture |
dst | the destination texture |
filter | the filtering to use for resizing |
|
static |
Blit the content of a texture into another one, resizing the content accordingly.
src | the source texture |
dst | the destination texture |
lSrc | the src layer to copy |
lDst | the dst layer to copy to |
filter | the filtering to use for resizing |
|
static |
Blit the content of a texture into another one, resizing the content accordingly.
src | the source texture |
dst | the destination texture |
lSrc | the src layer to copy |
lDst | the dst layer to copy to |
mipSrc | the src mip level to copy |
mipDst | the dst mip level to copy to |
filter | the filtering to use for resizing |
Blit the content of a depth texture into another one.
src | the source texture |
dst | the destination texture |
|
static |
Cancel an asynchronous download operation.
id | the ID of the task to cancel |
|
staticprivate |
Clean a buffer GPU object.
buffer | the object to delete |
|
staticprivate |
Clean a mesh GPU object.
mesh | the object to delete |
|
staticprivate |
Clean a texture GPU object.
tex | the object to delete |
|
staticprivate |
Clean a shader program object.
program | the object to delete |
|
static |
Clean all created GPU structures.
|
static |
Clear a depth texture with a given depth.
texture | the texture to clear/ |
depth | the depth to use |
|
static |
Clear a texture content with a given color.
texture | the texture to clear |
color | the color to use |
|
static |
Create and link a compute program using the shader code contained in the given strings.
program | the program to compile |
computeContent | the compute shader string |
debugInfos | the name of the program, or any custom debug infos that will be logged. |
|
static |
Create and link a graphics program using the shader code contained in the given strings.
program | the program to compile |
vertexContent | the vertex shader string |
fragmentContent | the fragment shader string |
tessControlContent | the optional tessellation control shader string |
tessEvalContent | the optional tessellation evaluation shader string |
debugInfos | the name of the program, or any custom debug infos that will be logged. |
|
static |
|
static |
Run a compute program by spawning computation threads.
width | the number of threads to spawn on the X axis |
height | the number of threads to spawn on the Y axis |
depth | the number of threads to spawn on the Z axis |
|
static |
Download data from a buffer on the GPU. It's possible to download a subrange of the buffer data store.
buffer | the buffer to download from |
size | the amount of data to download, in bytes |
data | pointer to the storage destination |
offset | optional offset in the buffer store |
|
static |
Copy a texture GPU data at this point of the frame command buffer, and download the copied data once the frame is complete.
texture | the texture to download |
offset | (x,y) offset of the region in the texture to download, from the top-left corner |
size | dimensions of the region to download |
layerCount | number of layers to download from |
callback | function that will be called once the data has been download and stored in the images of the Texture parameter |
|
static |
Download a texture images current data from the GPU.
texture | the texture to download |
|
static |
Download a texture images current data from the GPU.
texture | the texture to download |
level | the specific mip level to download |
|
static |
Draw indexed geometry.
mesh | the mesh to draw |
|
static |
Helper used to draw a fullscreen quad for texture processing.
Instead of story two-triangles geometry, it uses a single triangle covering the whole screen. For instance:
2: (-1,3),(0,2) * | \ | \ | \ | \ | \ *-----------* 1: (3,-1), (2,0) 0: (-1,-1), (0,0)
|
static |
Draw tessellated geometry.
mesh | the mesh to tessellate and render |
patchSize | number of vertices to use in a patch |
|
static |
End a rendering pass, detach the current attached textures.
|
staticprivate |
End the current render pass if one is started.
|
static |
Flush current GPU commands and wait for all processing to be done.
|
static |
Ensure that a buffer region is visible from the CPU and up-to-date.
buffer | the buffer to flush |
size | size of the region to flush |
offset | start of the region in the buffer |
|
static |
Generate a texture mipmaps on the GPU.
texture | the texture to use |
|
static |
|
static |
|
static |
|
static |
Prepare GPU for next frame.
|
staticprivate |
Process async download tasks for frames that are complete.
forceAll | process all pending requests, including for the current frame. |
|
staticprivate |
Process destruction requests for which we are sure that the resources are not used anymore.
|
static |
Save a given texture content to the disk.
texture | the texture to save |
path | the output image path |
options | output options (flip,...) |
|
static |
Enable or disable blending.
test | should blending be enabled |
|
static |
Configure blending.
test | should blending be enabled |
equation | the blending equation |
src | the blending value to use for the source |
dst | the blending value to use for the destination |
|
static |
Set the color write mask.
writeRed | allow writes to the red channel |
writeGreen | allow writes to the green channel |
writeBlue | allow writes to the blue channel |
writeAlpha | allow writes to the alpha channel |
|
static |
Enable or disable backface culling.
cull | should backfaces be culled |
|
static |
Configure backface culling.
cull | should backfaces be culled |
culledFaces | the set of faces to cull |
|
static |
Enable or disable the depth test.
test | should depth test be performed |
|
static |
Configure depth testing.
test | should depth test be performed |
function | the test function |
write | should the depth be written to the depth buffer |
|
static |
Set the polygon rasterization mode.
mode | the mode (filled, lines, points) |
|
static |
Enable or disable the stencil test.
test | should stencil test be performed |
write | should the stencil be written to the stencil buffer |
|
static |
Configure stencil testing.
test | should stencil test be performed |
function | the test function |
fail | operation to perform if the stencil test fails |
pass | operation to perform if the stencil and depth tests succeed, or if the stencil test is disabled |
depthFail | operation to perform if the stencil test succeeds but not the depth test |
value | reference value used for comparison |
|
static |
Setup the GPU device in its initial state.
appName | the name of the current executable |
|
static |
|
static |
|
static |
|
static |
Setup a window swapchain, creating backbuffers and resources.
window | the window to create a swapchain for |
|
static |
Set the current viewport based on a texture dimensions.
tex | the texture to use the dimensions |
|
static |
Set the current viewport.
x | horizontal coordinate |
y | vertical coordinate |
w | width |
h | height |
|
staticprivate |
End and submit upload and render command buffers for this frame, guaranteeing sequential execution.
|
static |
|
static |
Upload data to a buffer on the GPU. It's possible to upload a subrange of the buffer data store.
buffer | the buffer to upload to |
size | the amount of data to upload, in bytes |
data | pointer to the data to upload |
offset | optional offset in the buffer store |
|
static |
Upload a texture images data to the GPU.
texture | the texture to upload |