HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RV_Render Class Reference

#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_Instanceinstance ()
 The instance associated with this render. More...
 
VkDevice device ()
 The raw vulkan device. More...
 
RV_VKCommandBuffergetCurrentCB ()
 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_VKPipelineStateInfogetPipelineState ()
 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_PushConstantsgetPushConstants ()
 
const RV_PushConstantspushConstants () const
 
RV_ShaderVariableSetgetSet (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_ShaderProgramBasegetShader ()
 Get the current shader. More...
 
RV_ShaderComputegetComputeShader ()
 
RV_ShaderProgramgetGraphicsShader ()
 
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_FramebuffergetDrawFramebuffer ()
 Get the current framebuffer (may be null) More...
 
const RV_OcclusionQuerygetQuery () 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_RendergetThreadedRender ()
 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< DrawStatemyRecordedDraws
 
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
 

Detailed Description

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.

Constructor & Destructor Documentation

RV_Render::RV_Render ( RV_Instance inst)
RV_Render::~RV_Render ( )
RV_Render::RV_Render ( const RV_Render )
delete
RV_Render::RV_Render ( RV_Render &&  )
delete

Member Function Documentation

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.

void RV_Render::copyRenderState ( RV_Render other)

Copy render state from another RV_Render.

VkDevice RV_Render::device ( )
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.

void RV_Render::endFrame ( int  frame_depth)

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.

RV_VKPipelineStateInfo* RV_Render::getPipelineState ( )
inline

Return the current pipeline State.

Definition at line 129 of file RV_Render.h.

RV_PushConstants& RV_Render::getPushConstants ( )
inline

Definition at line 333 of file RV_Render.h.

const RV_OcclusionQuery* RV_Render::getQuery ( ) const
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 ( )
RV_Instance* RV_Render::instance ( )
inline

The instance associated with this render.

Definition at line 80 of file RV_Render.h.

bool RV_Render::isDeferringDraws ( ) const
inline

Definition at line 315 of file RV_Render.h.

bool RV_Render::isDepthBiasEnabled ( ) const

Whether there is a depth bias set.

bool RV_Render::isInFrame ( )
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.

bool RV_Render::isReverseDepth ( ) const
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 ( )
const RV_PushConstants& RV_Render::pushConstants ( ) const
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.

bool RV_Render::runCompute ( int  wg_x,
int  wg_y,
int  wg_z 
)

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.

void RV_Render::setDepthBias ( bool  enable,
float  zconst,
float  zslope,
float  clamp = 0.f 
)

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.

void RV_Render::setLineWidth ( float  width)

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).

void RV_Render::setQuery ( RV_OcclusionQuery q)
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::setSampleMask ( uint32  mask)

Set the sample mask for multisample rendering.

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 ( int  set_num)

Remove a bound variable set by index.

void RV_Render::unbindSet ( const RV_ShaderVariableSet set)

Remove a bound variable set by object.

Member Data Documentation

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.

UT_Array<DrawState> RV_Render::myRecordedDraws

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.


The documentation for this class was generated from the following file: