HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RV_Render.h
Go to the documentation of this file.
1 
2 /*
3  * PROPRIETARY INFORMATION. This software is proprietary to
4  * Side Effects Software Inc., and is not to be reproduced,
5  * transmitted, or disclosed in any way without written permission.
6  *
7  * NAME: RV_Render.h ( RV Library, C++)
8  *
9  * COMMENTS:
10  * Class to do render work with RV library
11  * Represents the set of resources and render state
12  * for a single frame/thread
13  */
14 
15 #ifndef RV_Render_h
16 #define RV_Render_h
17 
18 #include "RV_API.h"
19 
20 #include <UT/UT_FixedArray.h>
21 #include <UT/UT_Function.h>
22 #include <UT/UT_Map.h>
23 #include <UT/UT_Rect.h>
24 #include <UT/UT_Set.h>
25 #include <UT/UT_SharedPtr.h>
26 #include <UT/UT_TaskArena.h>
27 #include <UT/UT_Thread.h>
29 #include <UT/UT_UniquePtr.h>
30 #include <RE/RE_Types.h>
31 #include <SYS/SYS_Compiler.h>
32 
33 #include <functional>
34 #include <utility>
35 
36 #include <VE/VE_VK.h>
37 #include "RV_Instance.h"
38 #include "RV_ShaderBlock.h"
39 #include "RV_Type.h"
40 #include "RV_VKCommandBuffer.h"
41 #include "RV_VKPipeline.h"
43 #include "RV_VKPipelineLayout.h"
44 
45 
46 class RV_Instance;
47 class RV_Geometry;
49 class RV_ShaderProgram;
50 class RV_ShaderCompute;
52 class RV_OcclusionQuery;
53 
54 class RV_VKBuffer;
55 class RV_VKCommandBufferAllocator;
56 class RV_VKCommandBuffer;
57 class RV_VKDescriptorSet;
58 class RV_Framebuffer;
59 class RV_VKImage;
61 
62 class RV_StagingBufferPool;
63 
64 #ifdef VULKAN_PRESENTATION
65 class RV_VKSwapchain;
66 #endif
67 
68 class rv_ThreadedRenders;
69 
72 
73 typedef std::pair<VkPipelineStageFlags,VkPipelineStageFlags> RV_BarrierScope;
74 
76 
77 /// Per-thread object for rendering Vulkan objects, which maintains the state
78 /// and a cache of various Vulkan entities
80 {
81 public:
82  struct RenderState;
83 
84  RV_Render(RV_Instance* inst);
85  ~RV_Render();
86 
87  RV_Render(const RV_Render&) = delete;
88  RV_Render(RV_Render&&) = delete;
89 
90  /// The instance associated with this render
91  RV_Instance* instance() { return myInst; }
92  /// The raw vulkan device
93  VkDevice device() { return myInst->getDevice(); }
94 
95  // Current Command buffer
96  // - separate Compute + Transfer + Main CB?
97  // - functions to start command buffer
98  // - functions to flush command buffer
99  // - function to get command buffer
100  /// The currently recording command buffer
101  RV_VKCommandBuffer* getCurrentCB();
102 
103  /// Start rendering a single frame, returns the current nesting level
104  /// See `RV_RenderAutoFrame` for RAII wrapper
105  int beginFrame();
106  /// End rendering a single frame, takes the nesting level returned from begin
107  /// for error checking
108  void endFrame(int frame_depth);
109  /// Returns true if currently rendering a frame
110  bool isInFrame() { return myFrameDepth > 0; }
111 
112  /// Begin rendering to the current framebuffer. 'img_op' can be LOAD (keep
113  /// contents), CLEAR (discard and set to a constant) or DONT_CARE.
114  bool beginRendering(RV_ImageOp img_op = RV_IMAGE_LOAD);
115  /// End rendering.
116  void endRendering();
117  /// Query if Vulkan is rendering. Cannot upload buffers or textures while
118  /// rendering.
119  bool isRendering();
120 
121  static void init(RV_Instance *inst);
122  static void cleanup();
123 
124  // --------------------------------
125  // Render State
126  // helper class to hold the required render state
127  // Includes (TODO):
128  // - current command buffer
129  // - pipeline state (all elements provided in pipeline creation
130  // - current bound pipeline
131  // - current descriptor sets
132  // - current framebuffer + render pass
133  // - current vertex state (i.e. which vert buffers bound)
134  // - current clear color / clear depth
135 
136  /// Reset the cached render state in this object to Vulkan defaults.
137  void resetRenderState();
138 
139  /// Copy render state from another RV_Render
140  void copyRenderState(RV_Render* other);
141 
142  /// Copy saved render state from another RV_Render
143  void copyRenderState(const RenderState* state);
144 
145  // get a struct that is a copy of the current render state
146  RenderState getRenderState();
147 
148  /// Return the current pipeline State
149  RV_VKPipelineStateInfo* getPipelineState() { return &pipeState(); }
150 
151  // shader state
152 
153  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154  // Pipeline State
155 
156  // state management
157 
158  /// Reset the pipeline state to Vulkan defaults.
159  void resetPipeState();
160  /// Send the current pipeline state to the GPU.
161  void commitPipeState();
162  /// Save the existing state so that the state can be modified, then restored
163  /// to its previous state with popPipeState()
164  void pushPipeState();
165  /// Restore the pipeline state from a previous pushPipeState().
166  void popPipeState();
167 
168  // Poly Raster + Sample State
169  /// Set the sample mask for multisample rendering
170  void setSampleMask(uint32 mask);
171  /// Set the color channel mask
172  void setColorMask(bool red, bool green, bool blue, bool alpha);
173  /// Set the primitive culling mode, for backface or frontface culling
174  void setCullMode(bool enable, bool back_face = true, bool is_ccw = true);
175  bool getCullEnabled() const;
176  bool getCullIsBackFace() const;
177  bool getCullIsCCWWinding() const;
178 
179  /// Set the primitive winding order for front face determination
180  void setCCWWinding(bool is_ccw = true);
181  /// Set the width of line primitives (may not be supported on all platforms)
182  void setLineWidth(float width);
183  /// Set the polygon draw mode - FILL (normal), LINES (outline),
184  /// POINTS (vertices).
185  void setPolygonMode(RV_PolygonMode mode);
186  // set whether to use a single sample location for multisample rendering
187  // requires VK_EXT_SAMPLE_LOCATION extension
188  void setSingleSampleLocation(bool value);
189 
190  // Depth State
191 
192  /// Set the depth state for zbuffer operations.
193  void setDepthState(
194  bool enable,
196  bool writing = true,
197  float near = 0.0,
198  float far = 1.0,
199  bool clamp = false);
200 
201  bool isDepthTestEnabled() const { return pipeState().myDepthTest; }
202 
203  /// Query the current depth function
204  RE_ZFunction getDepthFunction() const;
205 
206  /// Set the polygon depth bias to reduce z-fighting for overlapping objects
207  void setDepthBias(bool enable, float zconst, float zslope, float clamp = 0.f);
208 
209  /// Whether there is a depth bias set
210  bool isDepthBiasEnabled() const;
211 
212  // If true, depth is reversed (near at 1.0, far at 0.0). Any calls to set
213  // depth state will reverse the z function.
214 
215  /// Convenience method to map near to 1.0 and far to 0.0 so that the depth
216  /// state will be converted to the correct comparisons (LESS -> GREATER)
217  void setReverseDepth(bool reverse);
218  /// Query if reverse depth mapping is enabled.
219  bool isReverseDepth() const { return myIsReverseDepth; }
220 
221  /// return the current near and far plane in NDC space,
222  /// based on if reverse Depth is enabled
223  int getNDCNearPlane() const { return isReverseDepth() ? 1.0 : 0.0; }
224  int getNDCFarPlane() const { return isReverseDepth() ? 0.0 : 1.0; }
225 
226  // Stencil State
227 
228  /// Enable stencil buffer rendering. Framebuffer must have a stencil buffer.
229  void setStencilEnable(bool enable);
230 
231  // Check whether stencil test is currently enabled
232  bool getStencilEnable() const;
233 
234  /// Define the stencil test
235  void setStencilTest(
237  uint8 ref,
238  uint8 compare_mask,
239  bool set_back = true);
240  /// Define the stencil operation based on the stencil test result. If
241  /// 'set_back' is true, also set the same values for backfacing polygons.
242  void setStencilOp(
243  RE_SOperation stencil_fail,
244  RE_SOperation depth_fail,
245  RE_SOperation pass,
246  uint8 write_mask,
247  bool set_back = true);
248  /// Define the stencil test for backfacing polygons
249  void setStencilBackTest(
251  uint8 ref,
252  uint8 compare_mask);
253  /// Define the stencil operation for backfacing polygons
254  void setStencilBackOp(
255  RE_SOperation stencil_fail,
256  RE_SOperation depth_fail,
257  RE_SOperation pass,
258  uint8 write_mask);
259 
260  // TODO: logic state set
261 
262  /// Define the viewport for rendering
263  void setViewport2DI(bool enable, const UT_DimRect &rect);
264  UT_DimRect getViewport2DI() const;
265 
266  /// Define the scissor (clip) area
267  void setScissor2DI(bool enable, const UT_DimRect &rect);
268 
269  /// Enable logic operations instead of color, plus the operation (AND,OR,etc)
270  void setLogicOp(bool enable, RV_LogicOp = RV_LOGIC_NO_OP);
271 
272  // Blend State
273  /// Enable framebuffer blending
274  void setBlendEnable(bool blend);
275 
276  /// Get whether framebuffer blending is enabled
277  bool getBlendEnable() const;
278 
279  // functions to set color/alpha separately
280 
281  /// Set the blending weights for color and alpha
282  void setBlendFunction(RE_BlendSourceFactor source_factor,
283  RE_BlendDestFactor dest_factor);
284  /// Set the blending weights for color only
285  void setColorBlendFunction(RE_BlendSourceFactor source_factor,
286  RE_BlendDestFactor dest_factor);
287  /// Set the blending weights for alpha only
288  void setAlphaBlendFunction(RE_BlendSourceFactor source_factor,
289  RE_BlendDestFactor dest_factor);
290  /// Set the blending operator (add, subtract, multiply, etc)
291  void setBlendEquation(RE_BlendEquation eq);
292  /// Set the blending operator (add, subtract, multiply, etc) for Alpha Only
293  void setAlphaBlendEquation(RE_BlendEquation eq);
294 
295  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
296  // Command Buffer Binding State
297 
299  {
300  DrawTask() = default;
301  virtual ~DrawTask() {};
302 
303  virtual bool runDraw(RV_Render* r) = 0;
304  };
305 
306 
307  struct DrawState
308  {
309  // Bound sets
311 
312  // Bound pipeline
315 
316  // TODO: convert to use UT_Function object
318  };
319 
321  {
323  int connect,
324  const RV_OverrideList* override_list,
325  int inst = -1)
326  : myGeo(geo)
327  , myConnectGroup(connect)
328  , myConnectRange(1)
329  , myInstanceGroup(inst)
330  , myOverrides(override_list ? *override_list : RV_OverrideList())
331  {
332  }
333 
335  int connect,
336  int connect_num,
337  const RV_OverrideList* override_list,
338  int inst = -1)
339  : myGeo(geo)
340  , myConnectGroup(connect)
341  , myConnectRange(connect_num)
342  , myInstanceGroup(inst)
343  , myOverrides(override_list ? *override_list : RV_OverrideList())
344  {
345  }
346 
347  ~DefaultDrawTask() override {}
348 
349  bool runDraw(RV_Render* r) override;
350 
351  // Bound Vertex state + Input State
352  // plus draw params needed for geo to get vert + idx buffers
358  };
359 // WIP: allow recording bind state for deferring draws
360 #define WIP_VULKAN_DEFER_DRAW
361 #ifdef WIP_VULKAN_DEFER_DRAW
363  bool myIsDeferring = false;
364 
365  bool isDeferringDraws() const { return myIsDeferring; }
366  void clearDraws();
367  void queueDraw(
368  RV_Geometry* geo,
369  int connect,
370  int connect_num,
371  const RV_OverrideList* override_list,
372  int inst = -1);
374  void runDraws();
375 #endif
376 
377  // call vkCmdBind functions for all bound state
378  bool refreshBindings();
379 
380  // should be called before a draw
381  bool prepareForDraw();
382 
384  {
385 #ifdef WIP_VULKAN_DEFER_DRAW
386  UT_ASSERT_MSG(!myIsDeferring, "RV_Render::getPushConstants "
387  "Called while in deferred mode, bound values will likely "
388  "be lost");
389 #endif
390  return myPushConstants;
391  }
392 
393  const RV_PushConstants &pushConstants() const { return myPushConstants; }
394 
395  /// Return the bound variable set at index 'set_num'
396  RV_ShaderVariableSet* getSet(int set_num);
397  /// Remove a bound variable set by index
398  void unbindSet(int set_num);
399  /// Remove a bound variable set by object
400  void unbindSet(const RV_ShaderVariableSet* set);
401  /// Bind a variable set to the specific shader program
403  const RV_ShaderProgramBase* shr);
404  /// Bind a variable set to the specific shader program, failing
405  /// if the set has uncommitted writes
407  const RV_ShaderProgramBase* shr);
408  /// Bind a variable set to the current shader program
410  /// Store the current shader
411  void pushShader();
412  /// Store the current shader and set the new shader to 'sh'
414  /// Restore the previous shader saved by pushShader()
415  void popShader();
416  /// Set the current shader to 'sh'
418  /// Get the current shader.
420  /// Get the current compute shader. If the current shader is graphics, return
421  /// null.
423  /// Get the current graphics shader. If the current shader is compute, return
424  /// null.
426 
427  /// Save the current render framebuffer
428  void pushDrawFramebuffer();
429  /// Save the current render framebuffer and make a new framebuffer active
431  /// Restore the previously pushed framebuffer from pushDrawFramebuffer().
432  void popDrawFramebuffer();
433  /// Make a new framebuffer active
435  /// Get the current framebuffer (may be null)
437 
438  /// Return the currently active occlusion query
439  const RV_OcclusionQuery* getQuery() const { return myCurOccludeQuery; }
440  /// Make occlusion query 'q' the active query (only 1 can be active at once)
442  { myCurOccludeQuery = q; }
443 
444  /// get the number of parallel command buffers within our pool
445  int getNumCommandBuffers() const;
446 
447  // TODO:
448  // void bindVertexState();
449 
450  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
451  // Actions
452 
453  /// End the current command buffer and start a new one. Wait until it is
454  /// executed if 'wait_for_finish' is true.
455  void flush(bool wait_for_finish);
456 
457  /// Run the current compute shader with explicit workgroup sizes. Returns
458  /// false if there is no compute shader bound.
459  bool runCompute(int wg_x, int wg_y, int wg_z);
460  /// Run the current compute shader with workgroup sizes stored in the given
461  /// buffer. Returns false if there is no compute shader bound.
463 
464  /// Draw the geometry 'geo' with the given connectivity group
465  void draw(
466  RV_Geometry* geo,
467  int connect_index,
468  const RV_OverrideList* override_list = nullptr);
469  /// Draw the geometry 'geo' with instancing with the given connectivity group
470  /// abd given instance group
471  void drawInstanced(
472  RV_Geometry* geo,
473  int connect_index,
474  int instance_group,
475  const RV_OverrideList* override_list = nullptr);
476 
477  /// Draw a range of connectivity groups
478  void drawRange(
479  RV_Geometry* geo,
480  int connect_index,
481  int connect_num,
482  const RV_OverrideList* override_list = nullptr);
483 
484  /// Draw using instancing a range of connectivity groups
485  void drawInstancedRange(
486  RV_Geometry* geo,
487  int connect_index,
488  int connect_num,
489  int inst_group,
490  const RV_OverrideList* override_list= nullptr);
491 
492  /// Render a deferred draw task
493  void draw(UT_UniquePtr<DrawTask> task);
494 
495  /// Render deferred draw using lambda
496  void draw(const UT_Function<bool(RV_Render*)> &task);
497 
498  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
499  // Thread-local Renders
500 
501  /// Get desired number of threads to use for parallel rendering
502  int getNumRenderThreads() const;
503 
504  /// Shold not be called manually. call GR_Utils::renderParallelFor() instead
505  /// Associate a unique RV_Render with the current thread and return it
506  /// `depth` output gives a call depth, used to pair get and return calls
507  /// for error checking
508  /// `idx` output gives the index of the render used. May not always be the
509  /// same when called on the same thread at different points. Used to match
510  /// render with other thread-specific resources (e.g. GR_Uniform objects)
511  RV_Render* getThreadedRender(int &out_depth, int &out_idx);
512 
513  /// Get the index of the current threaded render
514  /// Returns 0 for the main render, and >1 for thread specific renders
515  int getRenderIndex() const;
516 
517  /// Shold not be called manually. call GR_Utils::renderParallelFor() instead
518  /// Called by the task when done using the thread local render
519  /// (currently does nothing but could have per-task cleanup added)
520  void returnThreadedRender(int depth);
521 
522  /// Get the RV_Render used on the main thread. Will be This, if not
523  /// a thread-locall render
525 
526  /// Shold not be called manually. call GR_Utils::renderParallelFor() instead
527  /// Called on the main thread before using `getThreadedRender` on parallel threads
528  void enableThreadedRender();
529 
530  /// Shold not be called manually. call GR_Utils::renderParallelFor() instead
531  /// Called on the main thread after using `getThreadedRender()` on parallel threads.
532  /// Disassociates all per-thread RV_Renders from the thread they were used on
533  void endThreadedRender();
534 
536  /// Add callback to be executed on the main thread when
537  /// threaded render tasks have finished
538  void addPostThreadingCallback(const Callback &callback)
539  {
541  myPostThreadingCallbacks.append(callback);
542  }
543 
544  /// check whether this RV_Render is doing a threaded task
545  bool isMainRender() const;
546  /// check whether this RV_Render is doing a threaded task
547  bool isThreadedRender() const;
548  /// check whether this RV_Render is doing a threaded task
549  bool isThreading() const;
550 
551  /// Shold not be called manually. call GR_Utils::parallelGpuTask2() instead
552  /// Gets a task Arena with a concurrency limit equal to the
553  /// parallel rendering limit
555 
556  void dumpBoundState();
557 
558  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
559  // Sync
560 #define WIP_VULKAN_DEFER_BARRIERS
561 #ifdef WIP_VULKAN_DEFER_BARRIERS
562 
563  /// Add debug barrier that waits for all previous events
564  void addDebugBarrier();
565 
566  /// Add a barrier for buffer synchronization
567  void addBufferBarrier(
568  RV_BarrierScope scope,
569  const VkBufferMemoryBarrier& barrier,
570  RV_VKBuffer* buf);
571  /// Add a barrier for image synchronization
572  void addImageBarrier(
573  RV_BarrierScope scope,
574  const VkImageMemoryBarrier& barrier,
575  RV_VKImage* img);
576 
577  /// Remove all currently added barriers
578  void clearBarriers();
579  /// Execute all commands with barriers
580  void executeAllBarriers();
581  /// Execute all commands on some queues (graphics, compute, transfer).
583 
584  // called when setting up render for a frame
585  void initBarriers();
586 
588  {
590  VkMemoryBarrier myGenBarrier =
591  {
593  nullptr,
596  };
597  };
598 
599  // List of barriers waiting to be added to the commandbuffer
600  // -- any barrier MUST be added before a command in its DST stage is run
601  // inserted by DST RV_STAGE_GROUP
603 
604  // List of barriers that have been added, and were added later than ALL
605  // cmds included from their src stage -- inserted by SRC RV_STAGE_GROUP
607 
608  // List of IDs for each batch of barriers that was submitted
609  UT_FixedArray<exint, RV_STAGE_NUM> myBarrierGroupID = {};
610 
611  // counters for debugging
612  int myFrameExecBarrierCount = 0;
613  int myFrameMemBarrierCount = 0;
614 #endif
615 
616  // Ray tracing
617  exint myLastASCount = 0;
618 
619  void beginAccelStructBuild();
620  void addAccelStruct(RV_VKAccelerationStructure* accel_struct);
621  void endAccelStructBuild();
622 
625 
626  RV_StagingBufferPool* getStagingPool();
627 
628  // Helper functions
629 
630  // Copy src to dest with possibly differing vector sizes, padding with 0 if
631  // needed, or discarding extra data.
632  bool copyBuffer(RV_VKBuffer *src, int src_vsize,
633  RV_VKBuffer *dest, int dest_vsize,
634  int length, int src_start = 0,
635  int dst_start = 0);
636 
637 #ifdef VULKAN_PRESENTATION
638  // Swapchain
639  void present(RV_VKSwapchain* sc);
640 
641  // Semaphores
642  void waitOnSemaphore(VkSemaphore sem, VkPipelineStageFlags stage);
643  void signalSemaphore(VkSemaphore sem, VkPipelineStageFlags stage);
644 #endif
645 
646 private:
647  void privInitCB();
648  void privSubmitCB(bool wait_for_finish);
649 
650  // Vulkan Instance used to create this render
651  RV_Instance* myInst;
652 
654  RV_VKCommandBuffer* myCurrentCB = nullptr;
655 
656  // Pipeline state -- i.e. state that is part of dynamic state
657  // compiled into graphics pipeline
658  UT_Array<RV_VKPipelineStateInfo> myPipeStateStack;
659  RV_VKPipelineStateInfo& pipeState();
660  const RV_VKPipelineStateInfo& pipeState() const;
661 
662  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
663  // Binding State
664  static const int theMaxSets = 8;
665  static constexpr int theSetSize = 16*theMaxSets;
667  UT_SmallArray<exint,theSetSize> myBoundSetId;
669  RV_VKPushConstantInfo myBoundPushConstRanges;
670  UT_SmallArray<bool, theSetSize> myDirtySetFlags;
671 
672  UT_Array<RV_ShaderProgramBase*> myShaderStack;
673  UT_Array<RV_Framebuffer*> myFramebufferStack;
674 
675  RV_OcclusionQuery* myCurOccludeQuery = nullptr;
676 
677  RV_PushConstants myPushConstants;
678 
679  exint myFrameDepth = 0;
680  bool myIsRendering = false;
681  bool myIsReverseDepth = false;
682 
683  // snapshot of the render at a specific point in time
684 public:
685  struct RenderState
686  {
688  : myPipeState( r->myPipeStateStack.last() )
689  , myBoundSets{ r->myBoundSets }
690  , myBoundShader( r->getShader() )
691  , myBoundFramebuffer( r->getDrawFramebuffer() )
692  , myIsReverseDepth( r->isReverseDepth() )
693  , myIsDeferring( r->myIsDeferring )
694  {}
695 
700 
703  };
704 
705 private:
706  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
707  // Multi-Threading
708  int myRenderThreads;
709  RV_Render* myMainRender = nullptr;
710  UT_UniquePtr<rv_ThreadedRenders> myThreadedRenders;
711  friend rv_ThreadedRenders;
712  UT_Array<Callback> myPostThreadingCallbacks;
713 
714  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
715  // Ray Tracing
718  RV_VKAccelerationStructurePtr myTopLevelAccelStruct;
719  UT_Array<RV_AccelStructShaderInfo> myAccelStructShaderInfos;
720 
721  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
722  // Staging Buffers
723  UT_UniquePtr<RV_StagingBufferPool> myStagingBuffers;
724 
725  UT_UniquePtr<RV_ShaderVariableSet> myBufferCopySet;
726 };
727 
728 /// RAII wrapper for RV_Render beginFrame/EndFrame calls
730 {
731 public:
732  RV_RenderAutoFrame(RV_Render* r) : myR(r), myFrameDepth(-1)
733  {
734  if (myR)
735  myFrameDepth = myR->beginFrame();
736  }
738  {
739  if (myR)
740  myR->endFrame(myFrameDepth);
741  }
742 private:
743  RV_Render* myR;
744  int myFrameDepth;
745 };
746 
747 /// Destroy VK resource after command buffer is executed,
748 /// when it will no longer be in-use by the GPU
749 template<class T>
751 {
752 
753  if (v)
754  {
755  if (r->isMainRender())
757  RVmakeDestroyPtrTask(std::move(v)));
758  else
760  RVmakeDestroyPtrTask(std::move(v)));
761  }
762 }
763 
764 // Template Specializations
765 template<> RV_API
767 template<> RV_API
769 template<> RV_API
771 template<> RV_API
773 template<> RV_API
775 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
RenderState(RV_Render *r)
Definition: RV_Render.h:687
void drawInstanced(RV_Geometry *geo, int connect_index, int instance_group, const RV_OverrideList *override_list=nullptr)
RV_Framebuffer * myBoundFramebuffer
Definition: RV_Render.h:699
RAII wrapper for RV_Render beginFrame/EndFrame calls.
Definition: RV_Render.h:729
RV_VKPipelineStateInfo * getPipelineState()
Return the current pipeline State.
Definition: RV_Render.h:149
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
bool runCompute(int wg_x, int wg_y, int wg_z)
bool isDeferringDraws() const
Definition: RV_Render.h:365
RV_PushConstants & getPushConstants()
Definition: RV_Render.h:383
VkDevice device()
The raw vulkan device.
Definition: RV_Render.h:93
int getRenderIndex() const
void addBufferBarrier(RV_BarrierScope scope, const VkBufferMemoryBarrier &barrier, RV_VKBuffer *buf)
Add a barrier for buffer synchronization.
void addPostThreadingCallback(const Callback &callback)
Definition: RV_Render.h:538
RV_ImageOp
Definition: RV_Type.h:401
RV_ShaderProgram * getGraphicsShader()
void pushShader()
Store the current shader.
UT_UniquePtr< DrawTask > myTask
Definition: RV_Render.h:317
GLbitfield stages
Definition: glcorearb.h:1931
GLenum clamp
Definition: glcorearb.h:1234
const UT_Array< RV_AccelStructShaderInfo > & getAccelStructShaderInfos()
RV_ShaderProgramBase * myBoundShader
Definition: RV_Render.h:698
void executeAllBarriers()
Execute all commands with barriers.
const GLdouble * v
Definition: glcorearb.h:837
void pushDrawFramebuffer()
Save the current render framebuffer.
RV_ShaderVariableSet * getSet(int set_num)
Return the bound variable set at index 'set_num'.
void dumpBoundState()
GLsizei const GLfloat * value
Definition: glcorearb.h:824
void setQuery(RV_OcclusionQuery *q)
Make occlusion query 'q' the active query (only 1 can be active at once)
Definition: RV_Render.h:441
void draw(RV_Geometry *geo, int connect_index, const RV_OverrideList *override_list=nullptr)
Draw the geometry 'geo' with the given connectivity group.
int64 exint
Definition: SYS_Types.h:125
RV_StageGroup
Definition: RV_Type.h:442
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
Definition: RV_Geometry.h:165
bool isDepthTestEnabled() const
Definition: RV_Render.h:201
void executeBarriers(RV_StageGroup stages)
Execute all commands on some queues (graphics, compute, transfer).
RV_ShaderProgramBase * getShader()
Get the current shader.
PUGI__FN void reverse(I begin, I end)
Definition: pugixml.cpp:7458
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
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.
RV_VKAccelerationStructure * getTopLevelAccelStruct() const
std::pair< VkPipelineStageFlags, VkPipelineStageFlags > RV_BarrierScope
Definition: RV_Render.h:71
RV_VKCommandBuffer::Callback RVmakeDestroyPtrTask(UT_UniquePtr< T > obj)
void flush(bool wait_for_finish)
VkFlags VkPipelineStageFlags
Definition: vulkan_core.h:2401
UT_TaskArena & getTaskArena()
bool refreshBindings()
GLdouble GLdouble GLdouble q
Definition: glad.h:2445
GLdouble far
Definition: glcorearb.h:143
void unbindSet(int set_num)
Remove a bound variable set by index.
RV_Render * getThreadedRender(int &out_depth, int &out_idx)
void addAccelStruct(RV_VKAccelerationStructure *accel_struct)
DefaultDrawTask(RV_Geometry *geo, int connect, const RV_OverrideList *override_list, int inst=-1)
Definition: RV_Render.h:322
int getNumCommandBuffers() const
get the number of parallel command buffers within our pool
void clearBarriers()
Remove all currently added barriers.
RV_RenderAutoFrame(RV_Render *r)
Definition: RV_Render.h:732
bool bindSetWithoutUpdate(RV_ShaderVariableSet *set, const RV_ShaderProgramBase *shr)
int getNumRenderThreads() const
Get desired number of threads to use for parallel rendering.
RV_VKCommandBuffer * getCurrentCB()
The currently recording command buffer.
void enableThreadedRender()
int getNDCNearPlane() const
Definition: RV_Render.h:223
void addDebugBarrier()
Add debug barrier that waits for all previous events.
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
void returnThreadedRender(int depth)
#define UT_ASSERT_MSG(ZZ,...)
Definition: UT_Assert.h:168
unsigned char uint8
Definition: SYS_Types.h:36
vint4 blend(const vint4 &a, const vint4 &b, const vbool4 &mask)
Definition: simd.h:4949
virtual ~DrawTask()
Definition: RV_Render.h:301
bool isThreadedRender() const
check whether this RV_Render is doing a threaded task
bool prepareForDraw()
GLfloat f
Definition: glcorearb.h:1926
bool isInFrame()
Returns true if currently rendering a frame.
Definition: RV_Render.h:110
Compute shader object.
GLintptr offset
Definition: glcorearb.h:665
std::array< T, N > UT_FixedArray
Definition: UT_FixedArray.h:19
UT_Array< DrawState > myRecordedDraws
Definition: RV_Render.h:362
int getNDCFarPlane() const
Definition: RV_Render.h:224
RV_Render * getMainRender()
UT_UniquePtr< RV_VKAccelerationStructure > RV_VKAccelerationStructurePtr
Definition: RV_TypePtrs.h:84
GLint ref
Definition: glcorearb.h:124
DefaultDrawTask(RV_Geometry *geo, int connect, int connect_num, const RV_OverrideList *override_list, int inst=-1)
Definition: RV_Render.h:334
UT_Function< void(RV_Instance *)> Callback
Definition: RV_Render.h:535
void setShader(RV_ShaderProgramBase *sh)
Set the current shader to 'sh'.
UT_Array< RV_ShaderVariableSet * > mySets
Definition: RV_Render.h:310
const RV_OcclusionQuery * getQuery() const
Return the currently active occlusion query.
Definition: RV_Render.h:439
Occlusion query object.
Definition: RV_Query.h:31
constexpr auto set(type rhs) -> int
Definition: core.h:610
bool isMainRender() const
check whether this RV_Render is doing a threaded task
RV_VKPipelineStateInfo myPipelineState
Definition: RV_Render.h:314
GLfloat green
Definition: glcorearb.h:112
RV_PolygonMode
Definition: RV_Type.h:426
GLint GLuint mask
Definition: glcorearb.h:124
#define RV_API
Definition: RV_API.h:10
RV_StageGroup RVgetStageGroup(VkPipelineStageFlags stage_bits)
RE_BlendEquation
Definition: RE_Types.h:539
#define SYS_NO_DISCARD_RESULT
Definition: SYS_Compiler.h:86
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:112
bool copyBuffer(RV_VKBuffer *src, int src_vsize, RV_VKBuffer *dest, int dest_vsize, int length, int src_start=0, int dst_start=0)
RE_ZFunction
Definition: RE_Types.h:478
std::function< T > UT_Function
Definition: UT_Function.h:37
bool isReverseDepth() const
Query if reverse depth mapping is enabled.
Definition: RV_Render.h:219
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:48
bool runComputeIndirect(RV_VKBuffer *buf, exint offset=0)
GLint void * img
Definition: glcorearb.h:556
void initBarriers()
void bindDrawFramebuffer(RV_Framebuffer *fb)
Make a new framebuffer active.
FS_API bool cleanup(UT_StringArray &removed, UT_StringArray &error_files, exint &memory_freed, bool dry_run, const char *override_path=nullptr)
void popDrawFramebuffer()
Restore the previously pushed framebuffer from pushDrawFramebuffer().
void RVdestroyVKPtr(RV_Render *r, UT_UniquePtr< T > v)
Definition: RV_Render.h:750
void addCompletionCallback(const Callback &callback)
GLenum mode
Definition: glcorearb.h:99
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:476
RV_Instance * instance()
The instance associated with this render.
Definition: RV_Render.h:91
__hostdev__ uint64_t last(uint32_t i) const
Definition: NanoVDB.h:5976
void popShader()
Restore the previous shader saved by pushShader()
bool isThreading() const
check whether this RV_Render is doing a threaded task
GLenum func
Definition: glcorearb.h:783
RV_StagingBufferPool * getStagingPool()
RV_Framebuffer * getDrawFramebuffer()
Get the current framebuffer (may be null)
UT_FixedArray< rv_MemoryBarriers, RV_STAGE_NUM > myWaitingBarriers
Definition: RV_Render.h:602
RV_LogicOp
Definition: RV_Type.h:433
RE_SOperation
Definition: RE_Types.h:502
UT_FixedArray< RV_BarrierScope, RV_STAGE_NUM > myActiveBarriers
Definition: RV_Render.h:606
RE_BlendSourceFactor
Definition: RE_Types.h:514
RV_ShaderProgram * myShader
Definition: RV_Render.h:313
unsigned int uint32
Definition: SYS_Types.h:40
GLint GLsizei width
Definition: glcorearb.h:103
void runDraws()
void queueDraw(RV_Geometry *geo, int connect, int connect_num, const RV_OverrideList *override_list, int inst=-1)
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:165
void addImageBarrier(RV_BarrierScope scope, const VkImageMemoryBarrier &barrier, RV_VKImage *img)
Add a barrier for image synchronization.
GLboolean r
Definition: glcorearb.h:1222
GLfloat GLfloat blue
Definition: glcorearb.h:112
const RV_PushConstants & pushConstants() const
Definition: RV_Render.h:393
A vulkan buffer object.
Definition: RV_VKBuffer.h:75
void drawRange(RV_Geometry *geo, int connect_index, int connect_num, const RV_OverrideList *override_list=nullptr)
Draw a range of connectivity groups.
virtual bool runDraw(RV_Render *r)=0
bool myIsDeferring
Definition: RV_Render.h:363
RV_OverrideList myOverrides
Definition: RV_Render.h:357
void beginAccelStructBuild()
void endAccelStructBuild()
RV_ShaderCompute * getComputeShader()
RE_SFunction
Definition: RE_Types.h:490
png_structrp int png_fixed_point red
Definition: png.h:1083
state
Definition: core.h:2289
RV_VKPipelineStateInfo myPipeState
Definition: RV_Render.h:696
void endThreadedRender()
void clearDraws()
UT_SmallArray< RV_ShaderVariableSet *, theSetSize > myBoundSets
Definition: RV_Render.h:697
bool bindSet(RV_ShaderVariableSet *set, const RV_ShaderProgramBase *shr)
Bind a variable set to the specific shader program.
RE_BlendDestFactor
Definition: RE_Types.h:527
GLenum src
Definition: glcorearb.h:1793