HDK
|
#include <RV_Render.h>
Classes | |
struct | DefaultDrawTask |
struct | DrawState |
struct | DrawTask |
struct | rv_MemoryBarriers |
Public Member Functions | |
RV_Render (RV_Instance *inst) | |
~RV_Render () | |
RV_Render (const RV_Render &)=delete | |
RV_Render (RV_Render &&)=delete | |
RV_Instance * | instance () |
The instance associated with this render. More... | |
VkDevice | device () |
The raw vulkan device. More... | |
RV_VKCommandBuffer * | getCurrentCB () |
The currently recording command buffer. More... | |
int | beginFrame () |
void | endFrame (int frame_depth) |
bool | isInFrame () |
Returns true if currently rendering a frame. More... | |
bool | beginRendering (RV_ImageOp img_op=RV_IMAGE_LOAD) |
void | endRendering () |
End rendering. More... | |
bool | isRendering () |
void | resetRenderState () |
Reset the cached render state in this object to Vulkan defaults. More... | |
void | copyRenderState (RV_Render *other) |
Copy render state from another RV_Render. More... | |
RV_VKPipelineStateInfo * | getPipelineState () |
Return the current pipeline State. More... | |
void | resetPipeState () |
Reset the pipeline state to Vulkan defaults. More... | |
void | commitPipeState () |
Send the current pipeline state to the GPU. More... | |
void | pushPipeState () |
void | popPipeState () |
Restore the pipeline state from a previous pushPipeState(). More... | |
void | setSampleMask (uint32 mask) |
Set the sample mask for multisample rendering. More... | |
void | setColorMask (bool red, bool green, bool blue, bool alpha) |
Set the color channel mask. More... | |
void | setCullMode (bool enable, bool back_face=true, bool is_ccw=true) |
Set the primitive culling mode, for backface or frontface culling. More... | |
void | setLineWidth (float width) |
Set the width of line primitives (may not be supported on all platforms) More... | |
void | setPolygonMode (RV_PolygonMode mode) |
void | setDepthState (bool enable, RE_ZFunction func=RE_ZLESS, bool writing=true, float near=0.0, float far=1.0, bool clamp=false) |
Set the depth state for zbuffer operations. More... | |
void | setDepthBias (bool enable, float zconst, float zslope, float clamp=0.f) |
Set the polygon depth bias to reduce z-fighting for overlapping objects. More... | |
bool | isDepthBiasEnabled () const |
Whether there is a depth bias set. More... | |
void | setReverseDepth (bool reverse) |
bool | isReverseDepth () const |
Query if reverse depth mapping is enabled. More... | |
void | setStencilEnable (bool enable) |
Enable stencil buffer rendering. Framebuffer must have a stencil buffer. More... | |
void | setStencilTest (RE_SFunction func, uint8 ref, uint8 compare_mask, bool set_back=true) |
Define the stencil test. More... | |
void | setStencilOp (RE_SOperation stencil_fail, RE_SOperation depth_fail, RE_SOperation pass, uint8 write_mask, bool set_back=true) |
void | setStencilBackTest (RE_SFunction func, uint8 ref, uint8 compare_mask) |
Define the stencil test for backfacing polygons. More... | |
void | setStencilBackOp (RE_SOperation stencil_fail, RE_SOperation depth_fail, RE_SOperation pass, uint8 write_mask) |
Define the stencil operation for backfacing polygons. More... | |
void | setViewport2DI (bool enable, const UT_DimRect &rect) |
Define the viewport for rendering. More... | |
void | setScissor2DI (bool enable, const UT_DimRect &rect) |
Define the scissor (clip) area. More... | |
void | setLogicOp (bool enable, RV_LogicOp=RV_LOGIC_NO_OP) |
Enable logic operations instead of color, plus the operation (AND,OR,etc) More... | |
void | setBlendEnable (bool blend) |
Enable framebuffer blending. More... | |
void | setBlendFunction (RE_BlendSourceFactor source_factor, RE_BlendDestFactor dest_factor) |
Set the blending weights for color and alpha. More... | |
void | setColorBlendFunction (RE_BlendSourceFactor source_factor, RE_BlendDestFactor dest_factor) |
Set the blending weights for color only. More... | |
void | setAlphaBlendFunction (RE_BlendSourceFactor source_factor, RE_BlendDestFactor dest_factor) |
Set the blending weights for alpha only. More... | |
void | setBlendEquation (RE_BlendEquation eq) |
Set the blending operator (add, subtract, multiply, etc) More... | |
bool | isDeferringDraws () const |
void | clearDraws () |
void | queueDraw (RV_Geometry *geo, int connect, int connect_num, const RV_OverrideList *override_list, int inst=-1) |
void | queueDraw (UT_UniquePtr< DrawTask > task) |
void | runDraws () |
void | refreshBindings () |
bool | prepareForDraw () |
RV_PushConstants & | getPushConstants () |
const RV_PushConstants & | pushConstants () const |
RV_ShaderVariableSet * | getSet (int set_num) |
Return the bound variable set at index 'set_num'. More... | |
void | unbindSet (int set_num) |
Remove a bound variable set by index. More... | |
void | unbindSet (const RV_ShaderVariableSet *set) |
Remove a bound variable set by object. More... | |
bool | bindSet (RV_ShaderVariableSet *set, const RV_ShaderProgramBase *shr) |
Bind a variable set to the specific shader program. More... | |
bool | bindSet (const UT_UniquePtr< RV_ShaderVariableSet > &set) |
Bind a variable set to the current shader program. More... | |
void | pushShader () |
Store the current shader. More... | |
void | pushShader (RV_ShaderProgramBase *sh) |
Store the current shader and set the new shader to 'sh'. More... | |
void | popShader () |
Restore the previous shader saved by pushShader() More... | |
void | setShader (RV_ShaderProgramBase *sh) |
Set the current shader to 'sh'. More... | |
RV_ShaderProgramBase * | getShader () |
Get the current shader. More... | |
RV_ShaderCompute * | getComputeShader () |
RV_ShaderProgram * | getGraphicsShader () |
void | pushDrawFramebuffer () |
Save the current render framebuffer. More... | |
void | pushDrawFramebuffer (RV_Framebuffer *fb) |
Save the current render framebuffer and make a new framebuffer active. More... | |
void | popDrawFramebuffer () |
Restore the previously pushed framebuffer from pushDrawFramebuffer(). More... | |
void | bindDrawFramebuffer (RV_Framebuffer *fb) |
Make a new framebuffer active. More... | |
RV_Framebuffer * | getDrawFramebuffer () |
Get the current framebuffer (may be null) More... | |
const RV_OcclusionQuery * | getQuery () const |
Return the currently active occlusion query. More... | |
void | setQuery (RV_OcclusionQuery *q) |
Make occlusion query 'q' the active query (only 1 can be active at once) More... | |
int | getNumCommandBuffers () const |
get the number of parallel command buffers within our pool More... | |
void | flush (bool wait_for_finish) |
bool | runCompute (int wg_x, int wg_y, int wg_z) |
bool | runComputeIndirect (RV_VKBuffer *buf, exint offset=0) |
void | draw (RV_Geometry *geo, int connect_index, const RV_OverrideList *override_list=nullptr) |
Draw the geometry 'geo' with the given connectivity group. More... | |
void | drawInstanced (RV_Geometry *geo, int connect_index, int instance_group, const RV_OverrideList *override_list=nullptr) |
void | drawRange (RV_Geometry *geo, int connect_index, int connect_num, const RV_OverrideList *override_list=nullptr) |
Draw a range of connectivity groups. More... | |
void | drawInstancedRange (RV_Geometry *geo, int connect_index, int connect_num, int inst_group, const RV_OverrideList *override_list=nullptr) |
Draw using instancing a range of connectivity groups. More... | |
void | draw (UT_UniquePtr< DrawTask > task) |
Render a deferred draw task. More... | |
void | draw (const UT_Function< bool(RV_Render *)> &task) |
Render deferred draw using lambda. More... | |
int | getNumRenderThreads () const |
Get desired number of threads to use for parallel rendering. More... | |
void | enableThreadedRender () |
Call before using getThreadedRender and rendering from a new thread. More... | |
RV_Render * | getThreadedRender () |
Associate a unique RV_Render with the current thread and return it. More... | |
void | endThreadedRender () |
void | dumpBoundState () |
void | addBufferBarrier (RV_BarrierScope scope, const VkBufferMemoryBarrier &barrier, RV_VKBuffer *buf) |
Add a barrier for buffer synchronization. More... | |
void | addImageBarrier (RV_BarrierScope scope, const VkImageMemoryBarrier &barrier, RV_VKImage *img) |
Add a barrier for image synchronization. More... | |
void | clearBarriers () |
Remove all currently added barriers. More... | |
void | executeAllBarriers () |
Execute all commands with barriers. More... | |
void | executeBarriers (RV_StageGroup stages) |
Execute all commands on some queues (graphics, compute, transfer). More... | |
void | initBarriers () |
Public Attributes | |
UT_Array< DrawState > | myRecordedDraws |
bool | myIsDeferring = false |
UT_FixedArray < rv_MemoryBarriers, RV_STAGE_NUM > | myWaitingBarriers |
UT_FixedArray< RV_BarrierScope, RV_STAGE_NUM > | myActiveBarriers |
UT_FixedArray< exint, RV_STAGE_NUM > | myBarrierGroupID = {} |
int | myFrameExecBarrierCount = 0 |
int | myFrameMemBarrierCount = 0 |
Per-thread object for rendering Vulkan objects, which maintains the state and a cache of various Vulkan entities
Definition at line 70 of file RV_Render.h.
RV_Render::RV_Render | ( | RV_Instance * | inst | ) |
RV_Render::~RV_Render | ( | ) |
|
delete |
|
delete |
void RV_Render::addBufferBarrier | ( | RV_BarrierScope | scope, |
const VkBufferMemoryBarrier & | barrier, | ||
RV_VKBuffer * | buf | ||
) |
Add a barrier for buffer synchronization.
void RV_Render::addImageBarrier | ( | RV_BarrierScope | scope, |
const VkImageMemoryBarrier & | barrier, | ||
RV_VKImage * | img | ||
) |
Add a barrier for image synchronization.
int RV_Render::beginFrame | ( | ) |
Start rendering a single frame, returns the current nesting level See RV_RenderAutoFrame
for RAII wrapper
bool RV_Render::beginRendering | ( | RV_ImageOp | img_op = RV_IMAGE_LOAD | ) |
Begin rendering to the current framebuffer. 'img_op' can be LOAD (keep contents), CLEAR (discard and set to a constant) or DONT_CARE.
void RV_Render::bindDrawFramebuffer | ( | RV_Framebuffer * | fb | ) |
Make a new framebuffer active.
bool RV_Render::bindSet | ( | RV_ShaderVariableSet * | set, |
const RV_ShaderProgramBase * | shr | ||
) |
Bind a variable set to the specific shader program.
bool RV_Render::bindSet | ( | const UT_UniquePtr< RV_ShaderVariableSet > & | set | ) |
Bind a variable set to the current shader program.
void RV_Render::clearBarriers | ( | ) |
Remove all currently added barriers.
void RV_Render::clearDraws | ( | ) |
void RV_Render::commitPipeState | ( | ) |
Send the current pipeline state to the GPU.
|
inline |
The raw vulkan device.
Definition at line 82 of file RV_Render.h.
void RV_Render::draw | ( | RV_Geometry * | geo, |
int | connect_index, | ||
const RV_OverrideList * | override_list = nullptr |
||
) |
Draw the geometry 'geo' with the given connectivity group.
void RV_Render::draw | ( | UT_UniquePtr< DrawTask > | task | ) |
Render a deferred draw task.
void RV_Render::draw | ( | const UT_Function< bool(RV_Render *)> & | task | ) |
Render deferred draw using lambda.
void RV_Render::drawInstanced | ( | RV_Geometry * | geo, |
int | connect_index, | ||
int | instance_group, | ||
const RV_OverrideList * | override_list = nullptr |
||
) |
Draw the geometry 'geo' with instancing with the given connectivity group abd given instance group
void RV_Render::drawInstancedRange | ( | RV_Geometry * | geo, |
int | connect_index, | ||
int | connect_num, | ||
int | inst_group, | ||
const RV_OverrideList * | override_list = nullptr |
||
) |
Draw using instancing a range of connectivity groups.
void RV_Render::drawRange | ( | RV_Geometry * | geo, |
int | connect_index, | ||
int | connect_num, | ||
const RV_OverrideList * | override_list = nullptr |
||
) |
Draw a range of connectivity groups.
void RV_Render::dumpBoundState | ( | ) |
void RV_Render::enableThreadedRender | ( | ) |
Call before using getThreadedRender
and rendering from a new thread.
End rendering a single frame, takes the nesting level returned from begin for error checking
void RV_Render::endRendering | ( | ) |
End rendering.
void RV_Render::endThreadedRender | ( | ) |
Finish rendering with multiple threads, and disassociates all per-thread RV_Renders from the thread they were used on
void RV_Render::executeAllBarriers | ( | ) |
Execute all commands with barriers.
void RV_Render::executeBarriers | ( | RV_StageGroup | stages | ) |
Execute all commands on some queues (graphics, compute, transfer).
void RV_Render::flush | ( | bool | wait_for_finish | ) |
End the current command buffer and start a new one. Wait until it is executed if 'wait_for_finish' is true.
RV_ShaderCompute* RV_Render::getComputeShader | ( | ) |
Get the current graphics shader. If the current shader is compute, return null.
RV_VKCommandBuffer* RV_Render::getCurrentCB | ( | ) |
The currently recording command buffer.
RV_Framebuffer* RV_Render::getDrawFramebuffer | ( | ) |
Get the current framebuffer (may be null)
RV_ShaderProgram* RV_Render::getGraphicsShader | ( | ) |
Get the current compute shader. If the current shader is graphics, return null.
int RV_Render::getNumCommandBuffers | ( | ) | const |
get the number of parallel command buffers within our pool
int RV_Render::getNumRenderThreads | ( | ) | const |
Get desired number of threads to use for parallel rendering.
|
inline |
Return the current pipeline State.
Definition at line 129 of file RV_Render.h.
|
inline |
Definition at line 333 of file RV_Render.h.
|
inline |
Return the currently active occlusion query.
Definition at line 385 of file RV_Render.h.
RV_ShaderVariableSet* RV_Render::getSet | ( | int | set_num | ) |
Return the bound variable set at index 'set_num'.
RV_ShaderProgramBase* RV_Render::getShader | ( | ) |
Get the current shader.
RV_Render* RV_Render::getThreadedRender | ( | ) |
Associate a unique RV_Render with the current thread and return it.
void RV_Render::initBarriers | ( | ) |
|
inline |
The instance associated with this render.
Definition at line 80 of file RV_Render.h.
|
inline |
Definition at line 315 of file RV_Render.h.
bool RV_Render::isDepthBiasEnabled | ( | ) | const |
Whether there is a depth bias set.
|
inline |
Returns true if currently rendering a frame.
Definition at line 99 of file RV_Render.h.
bool RV_Render::isRendering | ( | ) |
Query if Vulkan is rendering. Cannot upload buffers or textures while rendering.
|
inline |
Query if reverse depth mapping is enabled.
Definition at line 184 of file RV_Render.h.
void RV_Render::popDrawFramebuffer | ( | ) |
Restore the previously pushed framebuffer from pushDrawFramebuffer().
void RV_Render::popPipeState | ( | ) |
Restore the pipeline state from a previous pushPipeState().
void RV_Render::popShader | ( | ) |
Restore the previous shader saved by pushShader()
bool RV_Render::prepareForDraw | ( | ) |
|
inline |
Definition at line 343 of file RV_Render.h.
void RV_Render::pushDrawFramebuffer | ( | ) |
Save the current render framebuffer.
void RV_Render::pushDrawFramebuffer | ( | RV_Framebuffer * | fb | ) |
Save the current render framebuffer and make a new framebuffer active.
void RV_Render::pushPipeState | ( | ) |
Save the existing state so that the state can be modified, then restored to its previous state with popPipeState()
void RV_Render::pushShader | ( | ) |
Store the current shader.
void RV_Render::pushShader | ( | RV_ShaderProgramBase * | sh | ) |
Store the current shader and set the new shader to 'sh'.
void RV_Render::queueDraw | ( | RV_Geometry * | geo, |
int | connect, | ||
int | connect_num, | ||
const RV_OverrideList * | override_list, | ||
int | inst = -1 |
||
) |
void RV_Render::queueDraw | ( | UT_UniquePtr< DrawTask > | task | ) |
void RV_Render::refreshBindings | ( | ) |
void RV_Render::resetPipeState | ( | ) |
Reset the pipeline state to Vulkan defaults.
void RV_Render::resetRenderState | ( | ) |
Reset the cached render state in this object to Vulkan defaults.
Run the current compute shader with explicit workgroup sizes. Returns false if there is no compute shader bound.
bool RV_Render::runComputeIndirect | ( | RV_VKBuffer * | buf, |
exint | offset = 0 |
||
) |
Run the current compute shader with workgroup sizes stored in the given buffer. Returns false if there is no compute shader bound.
void RV_Render::runDraws | ( | ) |
void RV_Render::setAlphaBlendFunction | ( | RE_BlendSourceFactor | source_factor, |
RE_BlendDestFactor | dest_factor | ||
) |
Set the blending weights for alpha only.
void RV_Render::setBlendEnable | ( | bool | blend | ) |
Enable framebuffer blending.
void RV_Render::setBlendEquation | ( | RE_BlendEquation | eq | ) |
Set the blending operator (add, subtract, multiply, etc)
void RV_Render::setBlendFunction | ( | RE_BlendSourceFactor | source_factor, |
RE_BlendDestFactor | dest_factor | ||
) |
Set the blending weights for color and alpha.
void RV_Render::setColorBlendFunction | ( | RE_BlendSourceFactor | source_factor, |
RE_BlendDestFactor | dest_factor | ||
) |
Set the blending weights for color only.
void RV_Render::setColorMask | ( | bool | red, |
bool | green, | ||
bool | blue, | ||
bool | alpha | ||
) |
Set the color channel mask.
void RV_Render::setCullMode | ( | bool | enable, |
bool | back_face = true , |
||
bool | is_ccw = true |
||
) |
Set the primitive culling mode, for backface or frontface culling.
Set the polygon depth bias to reduce z-fighting for overlapping objects.
void RV_Render::setDepthState | ( | bool | enable, |
RE_ZFunction | func = RE_ZLESS , |
||
bool | writing = true , |
||
float | near = 0.0 , |
||
float | far = 1.0 , |
||
bool | clamp = false |
||
) |
Set the depth state for zbuffer operations.
Set the width of line primitives (may not be supported on all platforms)
void RV_Render::setLogicOp | ( | bool | enable, |
RV_LogicOp | = RV_LOGIC_NO_OP |
||
) |
Enable logic operations instead of color, plus the operation (AND,OR,etc)
void RV_Render::setPolygonMode | ( | RV_PolygonMode | mode | ) |
Set the polygon draw mode - FILL (normal), LINES (outline), POINTS (vertices).
|
inline |
Make occlusion query 'q' the active query (only 1 can be active at once)
Definition at line 387 of file RV_Render.h.
void RV_Render::setReverseDepth | ( | bool | reverse | ) |
Convenience method to map near to 1.0 and far to 0.0 so that the depth state will be converted to the correct comparisons (LESS -> GREATER)
void RV_Render::setScissor2DI | ( | bool | enable, |
const UT_DimRect & | rect | ||
) |
Define the scissor (clip) area.
void RV_Render::setShader | ( | RV_ShaderProgramBase * | sh | ) |
Set the current shader to 'sh'.
void RV_Render::setStencilBackOp | ( | RE_SOperation | stencil_fail, |
RE_SOperation | depth_fail, | ||
RE_SOperation | pass, | ||
uint8 | write_mask | ||
) |
Define the stencil operation for backfacing polygons.
void RV_Render::setStencilBackTest | ( | RE_SFunction | func, |
uint8 | ref, | ||
uint8 | compare_mask | ||
) |
Define the stencil test for backfacing polygons.
void RV_Render::setStencilEnable | ( | bool | enable | ) |
Enable stencil buffer rendering. Framebuffer must have a stencil buffer.
void RV_Render::setStencilOp | ( | RE_SOperation | stencil_fail, |
RE_SOperation | depth_fail, | ||
RE_SOperation | pass, | ||
uint8 | write_mask, | ||
bool | set_back = true |
||
) |
Define the stencil operation based on the stencil test result. If 'set_back' is true, also set the same values for backfacing polygons.
void RV_Render::setStencilTest | ( | RE_SFunction | func, |
uint8 | ref, | ||
uint8 | compare_mask, | ||
bool | set_back = true |
||
) |
Define the stencil test.
void RV_Render::setViewport2DI | ( | bool | enable, |
const UT_DimRect & | rect | ||
) |
Define the viewport for rendering.
void RV_Render::unbindSet | ( | const RV_ShaderVariableSet * | set | ) |
Remove a bound variable set by object.
UT_FixedArray<RV_BarrierScope, RV_STAGE_NUM> RV_Render::myActiveBarriers |
Definition at line 505 of file RV_Render.h.
UT_FixedArray<exint, RV_STAGE_NUM> RV_Render::myBarrierGroupID = {} |
Definition at line 508 of file RV_Render.h.
int RV_Render::myFrameExecBarrierCount = 0 |
Definition at line 511 of file RV_Render.h.
int RV_Render::myFrameMemBarrierCount = 0 |
Definition at line 512 of file RV_Render.h.
bool RV_Render::myIsDeferring = false |
Definition at line 313 of file RV_Render.h.
Definition at line 312 of file RV_Render.h.
UT_FixedArray<rv_MemoryBarriers, RV_STAGE_NUM> RV_Render::myWaitingBarriers |
Definition at line 501 of file RV_Render.h.