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  // set whether to use a single sample location for multisample rendering
182  // requires VK_EXT_SAMPLE_LOCATION extension
183  void setSingleSampleLocation(bool value);
184 
185  // Depth State
186 
187  /// Set the depth state for zbuffer operations.
188  void setDepthState(
189  bool enable,
191  bool writing = true,
192  float near = 0.0,
193  float far = 1.0,
194  bool clamp = false);
195 
196  /// Query the current depth function
197  RE_ZFunction getDepthFunction() const;
198 
199  /// Set the polygon depth bias to reduce z-fighting for overlapping objects
200  void setDepthBias(bool enable, float zconst, float zslope, float clamp = 0.f);
201 
202  /// Whether there is a depth bias set
203  bool isDepthBiasEnabled() const;
204 
205  // If true, depth is reversed (near at 1.0, far at 0.0). Any calls to set
206  // depth state will reverse the z function.
207 
208  /// Convenience method to map near to 1.0 and far to 0.0 so that the depth
209  /// state will be converted to the correct comparisons (LESS -> GREATER)
210  void setReverseDepth(bool reverse);
211  /// Query if reverse depth mapping is enabled.
212  bool isReverseDepth() const { return myIsReverseDepth; }
213 
214  /// return the current near and far plane in NDC space,
215  /// based on if reverse Depth is enabled
216  int getNDCNearPlane() const { return isReverseDepth() ? 1.0 : 0.0; }
217  int getNDCFarPlane() const { return isReverseDepth() ? 0.0 : 1.0; }
218 
219  // Stencil State
220 
221  /// Enable stencil buffer rendering. Framebuffer must have a stencil buffer.
222  void setStencilEnable(bool enable);
223 
224  // Check whether stencil test is currently enabled
225  bool getStencilEnable() const;
226 
227  /// Define the stencil test
228  void setStencilTest(
230  uint8 ref,
231  uint8 compare_mask,
232  bool set_back = true);
233  /// Define the stencil operation based on the stencil test result. If
234  /// 'set_back' is true, also set the same values for backfacing polygons.
235  void setStencilOp(
236  RE_SOperation stencil_fail,
237  RE_SOperation depth_fail,
238  RE_SOperation pass,
239  uint8 write_mask,
240  bool set_back = true);
241  /// Define the stencil test for backfacing polygons
242  void setStencilBackTest(
244  uint8 ref,
245  uint8 compare_mask);
246  /// Define the stencil operation for backfacing polygons
247  void setStencilBackOp(
248  RE_SOperation stencil_fail,
249  RE_SOperation depth_fail,
250  RE_SOperation pass,
251  uint8 write_mask);
252 
253  // TODO: logic state set
254 
255  /// Define the viewport for rendering
256  void setViewport2DI(bool enable, const UT_DimRect &rect);
257 
258  /// Define the scissor (clip) area
259  void setScissor2DI(bool enable, const UT_DimRect &rect);
260 
261  /// Enable logic operations instead of color, plus the operation (AND,OR,etc)
262  void setLogicOp(bool enable, RV_LogicOp = RV_LOGIC_NO_OP);
263 
264  // Blend State
265  /// Enable framebuffer blending
266  void setBlendEnable(bool blend);
267 
268  // functions to set color/alpha separately
269 
270  /// Set the blending weights for color and alpha
271  void setBlendFunction(RE_BlendSourceFactor source_factor,
272  RE_BlendDestFactor dest_factor);
273  /// Set the blending weights for color only
274  void setColorBlendFunction(RE_BlendSourceFactor source_factor,
275  RE_BlendDestFactor dest_factor);
276  /// Set the blending weights for alpha only
277  void setAlphaBlendFunction(RE_BlendSourceFactor source_factor,
278  RE_BlendDestFactor dest_factor);
279  /// Set the blending operator (add, subtract, multiply, etc)
280  void setBlendEquation(RE_BlendEquation eq);
281  /// Set the blending operator (add, subtract, multiply, etc) for Alpha Only
282  void setAlphaBlendEquation(RE_BlendEquation eq);
283 
284  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285  // Command Buffer Binding State
286 
288  {
289  DrawTask() = default;
290  virtual ~DrawTask() {};
291 
292  virtual bool runDraw(RV_Render* r) = 0;
293  };
294 
295 
296  struct DrawState
297  {
298  // Bound sets
300 
301  // Bound pipeline
304 
305  // TODO: convert to use UT_Function object
307  };
308 
310  {
312  int connect,
313  const RV_OverrideList* override_list,
314  int inst = -1)
315  : myGeo(geo)
316  , myConnectGroup(connect)
317  , myConnectRange(1)
318  , myInstanceGroup(inst)
319  , myOverrides(override_list ? *override_list : RV_OverrideList())
320  {
321  }
322 
324  int connect,
325  int connect_num,
326  const RV_OverrideList* override_list,
327  int inst = -1)
328  : myGeo(geo)
329  , myConnectGroup(connect)
330  , myConnectRange(connect_num)
331  , myInstanceGroup(inst)
332  , myOverrides(override_list ? *override_list : RV_OverrideList())
333  {
334  }
335 
336  ~DefaultDrawTask() override {}
337 
338  bool runDraw(RV_Render* r) override;
339 
340  // Bound Vertex state + Input State
341  // plus draw params needed for geo to get vert + idx buffers
347  };
348 // WIP: allow recording bind state for deferring draws
349 #define WIP_VULKAN_DEFER_DRAW
350 #ifdef WIP_VULKAN_DEFER_DRAW
352  bool myIsDeferring = false;
353 
354  bool isDeferringDraws() const { return myIsDeferring; }
355  void clearDraws();
356  void queueDraw(
357  RV_Geometry* geo,
358  int connect,
359  int connect_num,
360  const RV_OverrideList* override_list,
361  int inst = -1);
363  void runDraws();
364 #endif
365 
366  // call vkCmdBind functions for all bound state
367  bool refreshBindings();
368 
369  // should be called before a draw
370  bool prepareForDraw();
371 
373  {
374 #ifdef WIP_VULKAN_DEFER_DRAW
375  UT_ASSERT_MSG(!myIsDeferring, "RV_Render::getPushConstants "
376  "Called while in deferred mode, bound values will likely "
377  "be lost");
378 #endif
379  return myPushConstants;
380  }
381 
382  const RV_PushConstants &pushConstants() const { return myPushConstants; }
383 
384  /// Return the bound variable set at index 'set_num'
385  RV_ShaderVariableSet* getSet(int set_num);
386  /// Remove a bound variable set by index
387  void unbindSet(int set_num);
388  /// Remove a bound variable set by object
389  void unbindSet(const RV_ShaderVariableSet* set);
390  /// Bind a variable set to the specific shader program
392  const RV_ShaderProgramBase* shr);
393  /// Bind a variable set to the specific shader program, failing
394  /// if the set has uncommitted writes
396  const RV_ShaderProgramBase* shr);
397  /// Bind a variable set to the current shader program
399  /// Store the current shader
400  void pushShader();
401  /// Store the current shader and set the new shader to 'sh'
403  /// Restore the previous shader saved by pushShader()
404  void popShader();
405  /// Set the current shader to 'sh'
407  /// Get the current shader.
409  /// Get the current graphics shader. If the current shader is compute, return
410  /// null.
412  /// Get the current compute shader. If the current shader is graphics, return
413  /// null.
415 
416  /// Save the current render framebuffer
417  void pushDrawFramebuffer();
418  /// Save the current render framebuffer and make a new framebuffer active
420  /// Restore the previously pushed framebuffer from pushDrawFramebuffer().
421  void popDrawFramebuffer();
422  /// Make a new framebuffer active
424  /// Get the current framebuffer (may be null)
426 
427  /// Return the currently active occlusion query
428  const RV_OcclusionQuery* getQuery() const { return myCurOccludeQuery; }
429  /// Make occlusion query 'q' the active query (only 1 can be active at once)
431  { myCurOccludeQuery = q; }
432 
433  /// get the number of parallel command buffers within our pool
434  int getNumCommandBuffers() const;
435 
436  // TODO:
437  // void bindVertexState();
438 
439  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
440  // Actions
441 
442  /// End the current command buffer and start a new one. Wait until it is
443  /// executed if 'wait_for_finish' is true.
444  void flush(bool wait_for_finish);
445 
446  /// Run the current compute shader with explicit workgroup sizes. Returns
447  /// false if there is no compute shader bound.
448  bool runCompute(int wg_x, int wg_y, int wg_z);
449  /// Run the current compute shader with workgroup sizes stored in the given
450  /// buffer. Returns false if there is no compute shader bound.
452 
453  /// Draw the geometry 'geo' with the given connectivity group
454  void draw(
455  RV_Geometry* geo,
456  int connect_index,
457  const RV_OverrideList* override_list = nullptr);
458  /// Draw the geometry 'geo' with instancing with the given connectivity group
459  /// abd given instance group
460  void drawInstanced(
461  RV_Geometry* geo,
462  int connect_index,
463  int instance_group,
464  const RV_OverrideList* override_list = nullptr);
465 
466  /// Draw a range of connectivity groups
467  void drawRange(
468  RV_Geometry* geo,
469  int connect_index,
470  int connect_num,
471  const RV_OverrideList* override_list = nullptr);
472 
473  /// Draw using instancing a range of connectivity groups
474  void drawInstancedRange(
475  RV_Geometry* geo,
476  int connect_index,
477  int connect_num,
478  int inst_group,
479  const RV_OverrideList* override_list= nullptr);
480 
481  /// Render a deferred draw task
482  void draw(UT_UniquePtr<DrawTask> task);
483 
484  /// Render deferred draw using lambda
485  void draw(const UT_Function<bool(RV_Render*)> &task);
486 
487  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
488  // Thread-local Renders
489 
490  /// Get desired number of threads to use for parallel rendering
491  int getNumRenderThreads() const;
492 
493  /// Shold not be called manually. call GR_Utils::renderParallelFor() instead
494  /// Associate a unique RV_Render with the current thread and return it
495  /// `depth` output gives a call depth, used to pair get and return calls
496  /// for error checking
497  /// `idx` output gives the index of the render used. May not always be the
498  /// same when called on the same thread at different points. Used to match
499  /// render with other thread-specific resources (e.g. GR_Uniform objects)
500  RV_Render* getThreadedRender(int &out_depth, int &out_idx);
501 
502  /// Get the index of the current threaded render
503  /// Returns 0 for the main render, and >1 for thread specific renders
504  int getRenderIndex() const;
505 
506  /// Shold not be called manually. call GR_Utils::renderParallelFor() instead
507  /// Called by the task when done using the thread local render
508  /// (currently does nothing but could have per-task cleanup added)
509  void returnThreadedRender(int depth);
510 
511  /// Get the RV_Render used on the main thread. Will be This, if not
512  /// a thread-locall render
514 
515  /// Shold not be called manually. call GR_Utils::renderParallelFor() instead
516  /// Called on the main thread before using `getThreadedRender` on parallel threads
517  void enableThreadedRender();
518 
519  /// Shold not be called manually. call GR_Utils::renderParallelFor() instead
520  /// Called on the main thread after using `getThreadedRender()` on parallel threads.
521  /// Disassociates all per-thread RV_Renders from the thread they were used on
522  void endThreadedRender();
523 
525  /// Add callback to be executed on the main thread when
526  /// threaded render tasks have finished
527  void addPostThreadingCallback(const Callback &callback)
528  {
530  myPostThreadingCallbacks.append(callback);
531  }
532 
533  /// check whether this RV_Render is doing a threaded task
534  bool isMainRender() const;
535  /// check whether this RV_Render is doing a threaded task
536  bool isThreadedRender() const;
537  /// check whether this RV_Render is doing a threaded task
538  bool isThreading() const;
539 
540  /// Shold not be called manually. call GR_Utils::parallelGpuTask2() instead
541  /// Gets a task Arena with a concurrency limit equal to the
542  /// parallel rendering limit
544 
545  void dumpBoundState();
546 
547  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
548  // Sync
549 #define WIP_VULKAN_DEFER_BARRIERS
550 #ifdef WIP_VULKAN_DEFER_BARRIERS
551 
552  /// Add debug barrier that waits for all previous events
553  void addDebugBarrier();
554 
555  /// Add a barrier for buffer synchronization
556  void addBufferBarrier(
557  RV_BarrierScope scope,
558  const VkBufferMemoryBarrier& barrier,
559  RV_VKBuffer* buf);
560  /// Add a barrier for image synchronization
561  void addImageBarrier(
562  RV_BarrierScope scope,
563  const VkImageMemoryBarrier& barrier,
564  RV_VKImage* img);
565 
566  /// Remove all currently added barriers
567  void clearBarriers();
568  /// Execute all commands with barriers
569  void executeAllBarriers();
570  /// Execute all commands on some queues (graphics, compute, transfer).
572 
573  // called when setting up render for a frame
574  void initBarriers();
575 
577  {
579  VkMemoryBarrier myGenBarrier =
580  {
582  nullptr,
585  };
586  };
587 
588  // List of barriers waiting to be added to the commandbuffer
589  // -- any barrier MUST be added before a command in its DST stage is run
590  // inserted by DST RV_STAGE_GROUP
592 
593  // List of barriers that have been added, and were added later than ALL
594  // cmds included from their src stage -- inserted by SRC RV_STAGE_GROUP
596 
597  // List of IDs for each batch of barriers that was submitted
598  UT_FixedArray<exint, RV_STAGE_NUM> myBarrierGroupID = {};
599 
600  // counters for debugging
601  int myFrameExecBarrierCount = 0;
602  int myFrameMemBarrierCount = 0;
603 #endif
604 
605  // Ray tracing
606  exint myLastASCount = 0;
607 
608  void beginAccelStructBuild();
609  void addAccelStruct(RV_VKAccelerationStructure* accel_struct);
610  void endAccelStructBuild();
611 
614 
615  RV_StagingBufferPool* getStagingPool();
616 
617  // Random Helper functions
618 
619  // Copy src to dest with possibly differing vector sizes, padding with 0 if
620  // needed, or discarding extra data.
621  bool copyBuffer(RV_VKBuffer *src, int src_vsize,
622  RV_VKBuffer *dest, int dest_vsize,
623  int length, int src_start = 0,
624  int dst_start = 0);
625 
626 #ifdef VULKAN_PRESENTATION
627  // Swapchain
628  void present(RV_VKSwapchain* sc);
629 
630  // Semaphores
631  void waitOnSemaphore(VkSemaphore sem, VkPipelineStageFlags stage);
632  void signalSemaphore(VkSemaphore sem, VkPipelineStageFlags stage);
633 #endif
634 
635 private:
636  void privInitCB();
637  void privSubmitCB(bool wait_for_finish);
638 
639  // Vulkan Instance used to create this render
640  RV_Instance* myInst;
641 
643  RV_VKCommandBuffer* myCurrentCB = nullptr;
644 
645  // Pipeline state -- i.e. state that is part of dynamic state
646  // compiled into graphics pipeline
647  UT_Array<RV_VKPipelineStateInfo> myPipeStateStack;
648  RV_VKPipelineStateInfo& pipeState();
649  const RV_VKPipelineStateInfo& pipeState() const;
650 
651  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
652  // Binding State
653  static const int theMaxSets = 8;
654  static constexpr int theSetSize = 16*theMaxSets;
656  UT_SmallArray<exint,theSetSize> myBoundSetId;
657  RV_VKPushConstantInfo myBoundPushConstRanges;
658  UT_SmallArray<bool, theSetSize> myDirtySetFlags;
659 
660  UT_Array<RV_ShaderProgramBase*> myShaderStack;
661  UT_Array<RV_Framebuffer*> myFramebufferStack;
662 
663  RV_OcclusionQuery* myCurOccludeQuery = nullptr;
664 
665  RV_PushConstants myPushConstants;
666 
667  exint myFrameDepth = 0;
668  bool myIsRendering = false;
669  bool myIsReverseDepth = false;
670 
671  // snapshot of the render at a specific point in time
672 public:
673  struct RenderState
674  {
676  : myPipeState( r->myPipeStateStack.last() )
677  , myBoundSets{ r->myBoundSets }
678  , myBoundShader( r->getShader() )
679  , myBoundFramebuffer( r->getDrawFramebuffer() )
680  , myIsReverseDepth( r->isReverseDepth() )
681  , myIsDeferring( r->myIsDeferring )
682  {}
683 
688 
691  };
692 
693 private:
694  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
695  // Multi-Threading
696  int myRenderThreads;
697  RV_Render* myMainRender = nullptr;
698  UT_UniquePtr<rv_ThreadedRenders> myThreadedRenders;
699  friend rv_ThreadedRenders;
700  UT_Array<Callback> myPostThreadingCallbacks;
701 
702  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
703  // Ray Tracing
706  RV_VKAccelerationStructurePtr myTopLevelAccelStruct;
707  UT_Array<RV_AccelStructShaderInfo> myAccelStructShaderInfos;
708 
709  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
710  // Staging Buffers
711  UT_UniquePtr<RV_StagingBufferPool> myStagingBuffers;
712 
713  UT_UniquePtr<RV_ShaderVariableSet> myBufferCopySet;
714 };
715 
716 /// RAII wrapper for RV_Render beginFrame/EndFrame calls
718 {
719 public:
721  {
722  myFrameDepth = myR.beginFrame();
723  }
725  {
726  myR.endFrame(myFrameDepth);
727  }
728 private:
729  RV_Render& myR;
730  int myFrameDepth;
731 };
732 
733 /// Destroy VK resource after command buffer is executed,
734 /// when it will no longer be in-use by the GPU
735 template<class T>
737 {
738 
739  if (v)
740  {
741  if (r->isMainRender())
743  RVmakeDestroyPtrTask(std::move(v)));
744  else
746  RVmakeDestroyPtrTask(std::move(v)));
747  }
748 }
749 
750 // Template Specializations
751 template<> RV_API
753 template<> RV_API
755 template<> RV_API
757 template<> RV_API
759 template<> RV_API
761 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
RenderState(RV_Render *r)
Definition: RV_Render.h:675
void drawInstanced(RV_Geometry *geo, int connect_index, int instance_group, const RV_OverrideList *override_list=nullptr)
RV_Framebuffer * myBoundFramebuffer
Definition: RV_Render.h:687
RAII wrapper for RV_Render beginFrame/EndFrame calls.
Definition: RV_Render.h:717
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:354
RV_PushConstants & getPushConstants()
Definition: RV_Render.h:372
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:527
RV_ImageOp
Definition: RV_Type.h:469
RV_ShaderProgram * getGraphicsShader()
void pushShader()
Store the current shader.
UT_UniquePtr< DrawTask > myTask
Definition: RV_Render.h:306
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:686
void executeAllBarriers()
Execute all commands with barriers.
RV_RenderAutoFrame(RV_Render &r)
Definition: RV_Render.h:720
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:430
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:311
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:216
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:290
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:351
int getNDCFarPlane() const
Definition: RV_Render.h:217
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:323
UT_Function< void(RV_Instance *)> Callback
Definition: RV_Render.h:524
void setShader(RV_ShaderProgramBase *sh)
Set the current shader to 'sh'.
UT_Array< RV_ShaderVariableSet * > mySets
Definition: RV_Render.h:299
const RV_OcclusionQuery * getQuery() const
Return the currently active occlusion query.
Definition: RV_Render.h:428
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:303
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:212
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:736
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:591
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:595
RE_BlendSourceFactor
Definition: RE_Types.h:514
RV_ShaderProgram * myShader
Definition: RV_Render.h:302
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:382
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:352
RV_OverrideList myOverrides
Definition: RV_Render.h:346
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:684
void endThreadedRender()
void clearDraws()
UT_SmallArray< RV_ShaderVariableSet *, theSetSize > myBoundSets
Definition: RV_Render.h:685
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