HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RV_VKFramebuffer.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: RV_VKFramebuffer.h ( RV Library, C++)
7  *
8  * COMMENTS:
9  * Class for representing list of attachments as a framebuffer in Vulkan
10  */
11 #ifndef RV_VKFramebuffer_h
12 #define RV_VKFramebuffer_h
13 
14 #include "RV_API.h"
15 
16 #include <UT/UT_Array.h>
17 #include <UT/UT_Rect.h>
18 #include <UT/UT_SmallArray.h>
19 #include <UT/UT_NonCopyable.h>
20 #include <UT/UT_UniquePtr.h>
21 
22 #include <VE/VE_VK.h>
23 #include "RV_Instance.h"
24 #include "RV_Type.h"
25 #include "RV_TypePtrs.h"
26 #include "RV_VKEnum.h"
27 
28 class RV_Instance;
29 class RV_Render;
30 class RV_Framebuffer;
31 class RV_VKCommandBuffer;
32 class RV_VKFramebuffer;
33 class RV_VKImage;
34 class RV_VKImageView;
35 class RV_VKRenderPass;
36 
37 class rv_VKAttachment;
39 
40 // info about the format of a renderpass i.e. the
41 // info required to know if two render passes are
42 // compatible:
43 // - attachment formats and samples
44 // - creation flags
45 // - subpass descriptions
46 // - (layouts do not matter)
48 {
49  bool myIsDynamicRendering = false;
51  bool myIsDepthReadOnly = false;
52 
53  // NOTE: using same sample count for all attachments
59 
60  // TODO: multiview rendering
61  // uint32 myViewMask = 0;
62  // NOTE: not bothering with subpasses at the moment
63  // int mySubPassCount = 1;
64 
65  bool operator==(const RV_RenderPassFormatInfo& other) const
66  {
69  && mySamples == other.mySamples
71  && myColorFormats == other.myColorFormats
74  }
75 
76  bool operator!=(const RV_RenderPassFormatInfo& other) const
77  {
78  return !(*this == other);
79  }
80 };
81 
83 {
84 public:
85  static UT_UniquePtr<RV_Framebuffer> create(
86  RV_Instance* inst,
87  int w,
88  int h,
89  int samples = 1,
90  const UT_StringRef &name = UT_StringRef());
91 
93  int w,
94  int h,
95  int samples = 1,
96  const UT_StringRef& name = UT_StringRef());
97  virtual ~RV_Framebuffer();
98 
99  virtual bool beginRendering(
100  RV_Instance *inst,
101  RV_VKCommandBuffer *cb,
102  RV_ImageOp img_op = RV_IMAGE_LOAD,
104 
105  virtual void endRendering(
106  RV_Instance *inst,
107  RV_VKCommandBuffer *cb) = 0;
108 
109  virtual bool fillPipelineInfo(RV_RenderPassFormatInfo& info) = 0;
110 
111  exint getMemoryUsage() const;
112 
113  UT_DimRect getRenderRegion() const;
114 
115  int getMaxLayers() const;
116 
117  // Update Framebuffer format state
118  void setSize(int w, int h)
119  {
120  UT_ASSERT(w > 0 && h > 0);
121  myWidth = w; myHeight = h;
122  }
123  int getWidth() { return myWidth;}
124  int getHeight() { return myHeight;}
125 
126  void setSampleCount(int samples);
127  int getSampleCount() { return mySamples; }
128 
129  void setClearColor(UT_Vector4F c) { myClearColor = c; }
130  UT_Vector4F getClearColor() const { return myClearColor; }
131 
132  void setClearInt(UT_Vector4i i) { myClearInt = i; }
133  UT_Vector4i getClearInt() const { return myClearInt; }
134 
135  void setClearDepth(fpreal32 d) { myClearDepth = d; }
136  fpreal32 getClearDepth() const { return myClearDepth; }
137 
138  void getColorImages(UT_Array<const RV_VKImage*> &out_list);
139  int getNumColorImages() const;
140  RV_VKImage* getColorImage(int i=0);
141  RV_VKImage* getDepthImage();
142 
143  void setMultiview(bool enable) { myIsMultiview = enable; }
144  bool getMultiview() const { return myIsMultiview;}
145 
146  void setReadOnlyDepth(bool enable) { myIsReadOnlyDepth = enable; }
147  bool getReadOnlyDepth() const { return myIsReadOnlyDepth; }
148 
149  void drawToBuffer(int color_buf_num);
150  void drawToBuffers(int num, const int *bufferlist);
151  void drawToNoBuffers();
152  void drawToAllBuffers();
153 
154  static const int ALL_LAYERS = -1;
155 
156  // Update Target info
157  bool attachImage(RV_Render* r,
158  RV_VKImage* img,
159  RV_AttachmentType buffer_type,
160  int buffer_target = 0,
161  int level = 0,
162  int layer = 0);
163 
164  RV_VKImagePtr createImage(RV_Render* r,
165  RV_GPUType type, int vec_size,
166  RV_AttachmentType attach_type,
167  int buffer_target = 0);
168 
169  void detachColorImage(RV_Render *r, int buffer_target = 0);
170  void detachDepthImage(RV_Render *r);
171 
172  const UT_StringHolder &name() const { return myName; }
173 
174  void writeToFiles(RV_Render *r,
175  const UT_StringHolder &base_name,
176  const UT_StringHolder &ext,
177  bool depth_too = false);
178 
179 protected:
180 
181  bool fillPipelineAttachments(RV_RenderPassFormatInfo& out_info);
183  { return myColorAttachments; }
185  { return myDepthAttachment; }
186 
187  void getColorDrawTargets(UT_Array<rv_VKAttachment*> &out_list);
188 
189  virtual void attachmentsChanged();
190 
191  // typed to match VK structs
192  uint32_t myWidth = 0;
193  uint32_t myHeight = 0;
194 
195  uint32_t mySamples = 1;
196 
197  UT_Vector4F myClearColor = UT_Vector4F(0.f, 0.f, 0.f, 0.f);
198  UT_Vector4i myClearInt = UT_Vector4i(0, 0, 0, 0);
199  fpreal32 myClearDepth = 1.f;
200 
201  int myDrawMask = 0;
202  bool myIsMultiview = false;
203  bool myIsReadOnlyDepth = false;
204 
208  bool myHasDrawTargets = true;
210 };
211 
213 {
214 public:
216  int w,
217  int h,
218  int samples = 1,
219  const UT_StringRef& name = UT_StringRef());
220  ~RV_DynamicFramebuffer() override;
221 
223 
224  bool fillPipelineInfo(RV_RenderPassFormatInfo& info) override;
225 
226  // Act on framebuffer
227  bool beginRendering(
228  RV_Instance *inst,
229  RV_VKCommandBuffer *cb,
230  RV_ImageOp img_op = RV_IMAGE_LOAD,
232 
233  void endRendering(
234  RV_Instance *inst,
235  RV_VKCommandBuffer *cb) override;
236 };
237 
239 {
240 public:
242  int w,
243  int h,
244  int samples = 1,
245  const UT_StringRef& name = UT_StringRef());
246  ~RV_RenderPassFramebuffer() override;
247 
248  bool fillPipelineInfo(RV_RenderPassFormatInfo& info) override;
249 
250  bool beginRendering(
251  RV_Instance *inst,
252  RV_VKCommandBuffer *cb,
253  RV_ImageOp img_op = RV_IMAGE_LOAD,
255 
256  void endRendering(
257  RV_Instance *inst,
258  RV_VKCommandBuffer *cb) override;
259 private:
260  void attachmentsChanged() override;
261 
262  bool myIsDirty = false;
263 
264  RV_ImageOp myLastLoadOp = RV_IMAGE_LOAD;
265  RV_RenderPassFormatInfo myLastFormat;
266  bool myLastMultiview = false;
267 
268  UT_UniquePtr<RV_VKRenderPass> myRenderPass;
269  UT_UniquePtr<RV_VKFramebuffer> myFramebuffer;
270 };
271 
273 {
274 public:
275  VkFramebuffer getVkFramebuffer() const { return myVkFramebuffer; }
276 
277  RV_VKFramebuffer(RV_Instance* inst, VkFramebuffer vk_handle)
278  : myInst(inst), myVkFramebuffer(vk_handle)
279  {}
280 
282  : myInst(other.myInst), myVkFramebuffer(other.myVkFramebuffer)
283  {
284  other.myInst = nullptr;
285  other.myVkFramebuffer = 0;
286  }
287 
288  // Disable move operator (since it would leave `rhs`) in null state
289  RV_VKFramebuffer& operator=(RV_VKFramebuffer&& rhs) noexcept = delete;
290 
291  void destroy()
292  {
293  UT_ASSERT(myInst || !myVkFramebuffer);
294  if (myInst && myInst->getDevice())
295  {
297  myInst->getDevice(), myVkFramebuffer, nullptr);
298  }
299  }
300 
301  virtual ~RV_VKFramebuffer() { destroy(); }
302 private:
303  RV_Instance* myInst = nullptr;
304  VkFramebuffer myVkFramebuffer = 0;
305 };
306 
308 {
309 public:
310  VkRenderPass getVkRenderPass() const { return myVkRenderPass; }
311 
313  RV_Instance* inst,
314  const RV_RenderPassFormatInfo& pass_info,
315  RV_ImageOp load_op);
316 
317  RV_VKRenderPass(RV_Instance* inst, VkRenderPass vk_handle)
318  : myInst(inst), myVkRenderPass(vk_handle)
319  {}
320 
322  : myInst(other.myInst), myVkRenderPass(other.myVkRenderPass)
323  {
324  other.myInst = nullptr;
325  other.myVkRenderPass = 0;
326  }
327 
328  // Disable move operator (since it would leave `rhs`) in null state
329  RV_VKRenderPass& operator=(RV_VKRenderPass&& rhs) noexcept = delete;
330 
331  void destroy()
332  {
333  UT_ASSERT(myInst || !myVkRenderPass);
334  if (myInst && myInst->getDevice())
335  {
337  myInst->getDevice(), myVkRenderPass, nullptr);
338  }
339  }
340 
341  virtual ~RV_VKRenderPass() { destroy(); }
342 private:
343  RV_Instance* myInst = nullptr;
344  VkRenderPass myVkRenderPass = 0;
345 };
346 
347 #endif
void setSize(int w, int h)
void setClearColor(UT_Vector4F c)
bool operator==(const RV_RenderPassFormatInfo &other) const
int int32
Definition: SYS_Types.h:39
bool operator!=(const RV_RenderPassFormatInfo &other) const
RV_VKFramebuffer(RV_VKFramebuffer &&other)
RV_ImageOp
Definition: RV_Type.h:401
int64 exint
Definition: SYS_Types.h:125
GLint level
Definition: glcorearb.h:108
virtual ~RV_VKFramebuffer()
UT_UniquePtr< RV_VKImage > RV_VKImagePtr
Definition: RV_TypePtrs.h:59
VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks *pAllocator)
float fpreal32
Definition: SYS_Types.h:200
bool getMultiview() const
const UT_Array< rv_VKAttachmentPtr > & colorAttachments() const
UT_StringHolder myName
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
rv_VKAttachmentPtr myDepthAttachment
RV_AttachmentType
Definition: RV_Type.h:393
UT_Vector4T< int32 > UT_Vector4i
GLfloat f
Definition: glcorearb.h:1926
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
std::array< T, N > UT_FixedArray
Definition: UT_FixedArray.h:19
VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks *pAllocator)
UT_Array< rv_VKAttachmentPtr > myColorAttachments
UT_Vector4i getClearInt() const
void setClearInt(UT_Vector4i i)
#define RV_API
Definition: RV_API.h:10
UT_SmallArray< int8 > myDrawTargets
virtual ~RV_VKRenderPass()
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual bool fillPipelineInfo(RV_RenderPassFormatInfo &info)=0
VkRenderPass getVkRenderPass() const
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:48
RV_VKRenderPass(RV_Instance *inst, VkRenderPass vk_handle)
GLint void * img
Definition: glcorearb.h:556
GLsizei samples
Definition: glcorearb.h:1298
void setReadOnlyDepth(bool enable)
const rv_VKAttachmentPtr & depthAttachment() const
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
bool getReadOnlyDepth() const
void setClearDepth(fpreal32 d)
RV_VKFramebuffer(RV_Instance *inst, VkFramebuffer vk_handle)
UT_Vector4T< fpreal32 > UT_Vector4F
virtual void attachmentsChanged()
RV_GPUType
Definition: RV_Type.h:40
void setMultiview(bool enable)
VkFormat
Definition: vulkan_core.h:1386
unsigned int uint32
Definition: SYS_Types.h:40
VkDevice getDevice()
Get the raw vulkan device assocated with this instance.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:165
static UT_UniquePtr< RV_VKRenderPass > create(RV_Instance *inst, const RV_RenderPassFormatInfo &pass_info, RV_ImageOp load_op)
RV_VKFramebuffer & operator=(RV_VKFramebuffer &&rhs) noexcept=delete
virtual bool beginRendering(RV_Instance *inst, RV_VKCommandBuffer *cb, RV_ImageOp img_op=RV_IMAGE_LOAD, RV_RenderPassType type=RV_PASS_WHOLE)=0
GLboolean r
Definition: glcorearb.h:1222
RV_RenderPassType
Definition: RV_Type.h:410
RV_VKRenderPass(RV_VKRenderPass &&other)
UT_Vector4F getClearColor() const
fpreal32 getClearDepth() const
UT_FixedArray< VkFormat, 8 > myColorFormats
const UT_StringHolder & name() const
RV_VKRenderPass & operator=(RV_VKRenderPass &&rhs) noexcept=delete
VkFramebuffer getVkFramebuffer() const
virtual void endRendering(RV_Instance *inst, RV_VKCommandBuffer *cb)=0
RAII wrapper class for VkImageView.
Definition: RV_VKImage.h:314
UT_UniquePtr< rv_VKAttachment > rv_VKAttachmentPtr