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