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 current shader program
392  /// Store the current shader
393  void pushShader();
394  /// Store the current shader and set the new shader to 'sh'
396  /// Restore the previous shader saved by pushShader()
397  void popShader();
398  /// Set the current shader to 'sh'
400  /// Get the current shader.
402  /// Get the current graphics shader. If the current shader is compute, return
403  /// null.
405  /// Get the current compute shader. If the current shader is graphics, return
406  /// null.
408 
409  /// Save the current render framebuffer
410  void pushDrawFramebuffer();
411  /// Save the current render framebuffer and make a new framebuffer active
413  /// Restore the previously pushed framebuffer from pushDrawFramebuffer().
414  void popDrawFramebuffer();
415  /// Make a new framebuffer active
417  /// Get the current framebuffer (may be null)
419 
420  /// Return the currently active occlusion query
421  const RV_OcclusionQuery* getQuery() const { return myCurOccludeQuery; }
422  /// Make occlusion query 'q' the active query (only 1 can be active at once)
424  { myCurOccludeQuery = q; }
425 
426  /// get the number of parallel command buffers within our pool
427  int getNumCommandBuffers() const;
428 
429  // TODO:
430  // void bindVertexState();
431 
432  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
433  // Actions
434 
435  /// End the current command buffer and start a new one. Wait until it is
436  /// executed if 'wait_for_finish' is true.
437  void flush(bool wait_for_finish);
438 
439  /// Run the current compute shader with explicit workgroup sizes. Returns
440  /// false if there is no compute shader bound.
441  bool runCompute(int wg_x, int wg_y, int wg_z);
442  /// Run the current compute shader with workgroup sizes stored in the given
443  /// buffer. Returns false if there is no compute shader bound.
445 
446  /// Draw the geometry 'geo' with the given connectivity group
447  void draw(
448  RV_Geometry* geo,
449  int connect_index,
450  const RV_OverrideList* override_list = nullptr);
451  /// Draw the geometry 'geo' with instancing with the given connectivity group
452  /// abd given instance group
453  void drawInstanced(
454  RV_Geometry* geo,
455  int connect_index,
456  int instance_group,
457  const RV_OverrideList* override_list = nullptr);
458 
459  /// Draw a range of connectivity groups
460  void drawRange(
461  RV_Geometry* geo,
462  int connect_index,
463  int connect_num,
464  const RV_OverrideList* override_list = nullptr);
465 
466  /// Draw using instancing a range of connectivity groups
467  void drawInstancedRange(
468  RV_Geometry* geo,
469  int connect_index,
470  int connect_num,
471  int inst_group,
472  const RV_OverrideList* override_list= nullptr);
473 
474  /// Render a deferred draw task
475  void draw(UT_UniquePtr<DrawTask> task);
476 
477  /// Render deferred draw using lambda
478  void draw(const UT_Function<bool(RV_Render*)> &task);
479 
480  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
481  // Thread-local Renders
482 
483  /// Get desired number of threads to use for parallel rendering
484  int getNumRenderThreads() const;
485 
486  /// Shold not be called manually. call GR_Utils::renderParallelFor() instead
487  /// Associate a unique RV_Render with the current thread and return it
488  /// `depth` output gives a call depth, used to pair get and return calls
489  /// for error checking
490  /// `idx` output gives the index of the render used. May not always be the
491  /// same when called on the same thread at different points. Used to match
492  /// render with other thread-specific resources (e.g. GR_Uniform objects)
493  RV_Render* getThreadedRender(int &out_depth, int &out_idx);
494 
495  /// Get the index of the current threaded render
496  /// Returns 0 for the main render, and >1 for thread specific renders
497  int getRenderIndex() const;
498 
499  /// Shold not be called manually. call GR_Utils::renderParallelFor() instead
500  /// Called by the task when done using the thread local render
501  /// (currently does nothing but could have per-task cleanup added)
502  void returnThreadedRender(int depth);
503 
504  /// Get the RV_Render used on the main thread. Will be This, if not
505  /// a thread-locall render
507 
508  /// Shold not be called manually. call GR_Utils::renderParallelFor() instead
509  /// Called on the main thread before using `getThreadedRender` on parallel threads
510  void enableThreadedRender();
511 
512  /// Shold not be called manually. call GR_Utils::renderParallelFor() instead
513  /// Called on the main thread after using `getThreadedRender()` on parallel threads.
514  /// Disassociates all per-thread RV_Renders from the thread they were used on
515  void endThreadedRender();
516 
518  /// Add callback to be executed on the main thread when
519  /// threaded render tasks have finished
520  void addPostThreadingCallback(const Callback &callback)
521  {
523  myPostThreadingCallbacks.append(callback);
524  }
525 
526  /// check whether this RV_Render is doing a threaded task
527  bool isMainRender() const;
528  /// check whether this RV_Render is doing a threaded task
529  bool isThreadedRender() const;
530  /// check whether this RV_Render is doing a threaded task
531  bool isThreading() const;
532 
533  /// Shold not be called manually. call GR_Utils::parallelGpuTask2() instead
534  /// Gets a task Arena with a concurrency limit equal to the
535  /// parallel rendering limit
537 
538  void dumpBoundState();
539 
540  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
541  // Sync
542 #define WIP_VULKAN_DEFER_BARRIERS
543 #ifdef WIP_VULKAN_DEFER_BARRIERS
544 
545  /// Add debug barrier that waits for all previous events
546  void addDebugBarrier();
547 
548  /// Add a barrier for buffer synchronization
549  void addBufferBarrier(
550  RV_BarrierScope scope,
551  const VkBufferMemoryBarrier& barrier,
552  RV_VKBuffer* buf);
553  /// Add a barrier for image synchronization
554  void addImageBarrier(
555  RV_BarrierScope scope,
556  const VkImageMemoryBarrier& barrier,
557  RV_VKImage* img);
558 
559  /// Remove all currently added barriers
560  void clearBarriers();
561  /// Execute all commands with barriers
562  void executeAllBarriers();
563  /// Execute all commands on some queues (graphics, compute, transfer).
565 
566  // called when setting up render for a frame
567  void initBarriers();
568 
570  {
572  VkMemoryBarrier myGenBarrier =
573  {
575  nullptr,
578  };
579  };
580 
581  // List of barriers waiting to be added to the commandbuffer
582  // -- any barrier MUST be added before a command in its DST stage is run
583  // inserted by DST RV_STAGE_GROUP
585 
586  // List of barriers that have been added, and were added later than ALL
587  // cmds included from their src stage -- inserted by SRC RV_STAGE_GROUP
589 
590  // List of IDs for each batch of barriers that was submitted
591  UT_FixedArray<exint, RV_STAGE_NUM> myBarrierGroupID = {};
592 
593  // counters for debugging
594  int myFrameExecBarrierCount = 0;
595  int myFrameMemBarrierCount = 0;
596 #endif
597 
598  // Ray tracing
599  exint myLastASCount = 0;
600 
601  void beginAccelStructBuild();
602  void addAccelStruct(RV_VKAccelerationStructure* accel_struct);
603  void endAccelStructBuild();
604 
607 
608  RV_StagingBufferPool* getStagingPool();
609 
610  // Random Helper functions
611 
612  // Copy src to dest with possibly differing vector sizes, padding with 0 if
613  // needed, or discarding extra data.
614  bool copyBuffer(RV_VKBuffer *src, int src_vsize,
615  RV_VKBuffer *dest, int dest_vsize,
616  int length, int src_start = 0,
617  int dst_start = 0);
618 
619 #ifdef VULKAN_PRESENTATION
620  // Swapchain
621  void present(RV_VKSwapchain* sc);
622 
623  // Semaphores
624  void waitOnSemaphore(VkSemaphore sem, VkPipelineStageFlags stage);
625  void signalSemaphore(VkSemaphore sem, VkPipelineStageFlags stage);
626 #endif
627 
628 private:
629  void privInitCB();
630  void privSubmitCB(bool wait_for_finish);
631 
632  // Vulkan Instance used to create this render
633  RV_Instance* myInst;
634 
636  RV_VKCommandBuffer* myCurrentCB = nullptr;
637 
638  // Pipeline state -- i.e. state that is part of dynamic state
639  // compiled into graphics pipeline
640  UT_Array<RV_VKPipelineStateInfo> myPipeStateStack;
641  RV_VKPipelineStateInfo& pipeState();
642  const RV_VKPipelineStateInfo& pipeState() const;
643 
644  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
645  // Binding State
646  static const int theMaxSets = 8;
647  static constexpr int theSetSize = 16*theMaxSets;
649  UT_SmallArray<exint,theSetSize> myBoundSetId;
650  RV_VKPushConstantInfo myBoundPushConstRanges;
651  UT_SmallArray<bool, theSetSize> myDirtySetFlags;
652 
653  UT_Array<RV_ShaderProgramBase*> myShaderStack;
654  UT_Array<RV_Framebuffer*> myFramebufferStack;
655 
656  RV_OcclusionQuery* myCurOccludeQuery = nullptr;
657 
658  RV_PushConstants myPushConstants;
659 
660  exint myFrameDepth = 0;
661  bool myIsRendering = false;
662  bool myIsReverseDepth = false;
663 
664  // snapshot of the render at a specific point in time
665 public:
666  struct RenderState
667  {
669  : myPipeState( r->myPipeStateStack.last() )
670  , myBoundSets{ r->myBoundSets }
671  , myBoundShader( r->getShader() )
672  , myBoundFramebuffer( r->getDrawFramebuffer() )
673  , myIsReverseDepth( r->isReverseDepth() )
674  , myIsDeferring( r->myIsDeferring )
675  {}
676 
681 
684  };
685 
686 private:
687  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
688  // Multi-Threading
689  int myRenderThreads;
690  RV_Render* myMainRender = nullptr;
691  UT_UniquePtr<rv_ThreadedRenders> myThreadedRenders;
692  friend rv_ThreadedRenders;
693  UT_Array<Callback> myPostThreadingCallbacks;
694 
695  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
696  // Ray Tracing
699  RV_VKAccelerationStructurePtr myTopLevelAccelStruct;
700  UT_Array<RV_AccelStructShaderInfo> myAccelStructShaderInfos;
701 
702  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
703  // Staging Buffers
704  UT_UniquePtr<RV_StagingBufferPool> myStagingBuffers;
705 
706  UT_UniquePtr<RV_ShaderVariableSet> myBufferCopySet;
707 };
708 
709 /// RAII wrapper for RV_Render beginFrame/EndFrame calls
711 {
712 public:
714  {
715  myFrameDepth = myR.beginFrame();
716  }
718  {
719  myR.endFrame(myFrameDepth);
720  }
721 private:
722  RV_Render& myR;
723  int myFrameDepth;
724 };
725 
726 /// Destroy VK resource after command buffer is executed,
727 /// when it will no longer be in-use by the GPU
728 template<class T>
730 {
731 
732  if (v)
733  {
734  if (r->isMainRender())
736  RVmakeDestroyPtrTask(std::move(v)));
737  else
739  RVmakeDestroyPtrTask(std::move(v)));
740  }
741 }
742 
743 
744 // Template Specializations
745 template<> RV_API
747 template<> RV_API
749 template<> RV_API
751 template<> RV_API
753 template<> RV_API
755 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
RenderState(RV_Render *r)
Definition: RV_Render.h:668
void drawInstanced(RV_Geometry *geo, int connect_index, int instance_group, const RV_OverrideList *override_list=nullptr)
RV_Framebuffer * myBoundFramebuffer
Definition: RV_Render.h:680
RAII wrapper for RV_Render beginFrame/EndFrame calls.
Definition: RV_Render.h:710
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:520
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:679
void executeAllBarriers()
Execute all commands with barriers.
RV_RenderAutoFrame(RV_Render &r)
Definition: RV_Render.h:713
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:423
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.
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:517
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:421
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:729
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:584
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:588
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:677
void endThreadedRender()
void clearDraws()
UT_SmallArray< RV_ShaderVariableSet *, theSetSize > myBoundSets
Definition: RV_Render.h:678
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