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_NonCopyable.h>
19 #include <UT/UT_UniquePtr.h>
20 
21 #include <VE/VE_VK.h>
22 #include "RV_Instance.h"
23 #include "RV_Type.h"
24 #include "RV_TypePtrs.h"
25 #include "RV_VKEnum.h"
26 
27 class RV_Instance;
28 class RV_Render;
29 class RV_Framebuffer;
30 class RV_VKCommandBuffer;
31 class RV_VKFramebuffer;
32 class RV_VKImage;
33 class RV_VKImageView;
34 class RV_VKRenderPass;
35 
36 class rv_VKAttachment;
38 
39 // info about the format of a renderpass i.e. the
40 // info required to know if two render passes are
41 // compatible:
42 // - attachment formats and samples
43 // - creation flags
44 // - subpass descriptions
45 // - (layouts do not matter)
47 {
48  bool myIsDynamicRendering = false;
50  bool myIsDepthReadOnly = false;
51 
52  // NOTE: using same sample count for all attachments
58 
59  // TODO: multiview rendering
60  // uint32 myViewMask = 0;
61  // NOTE: not bothering with subpasses at the moment
62  // int mySubPassCount = 1;
63 
64  bool operator==(const RV_RenderPassFormatInfo& other) const
65  {
68  && mySamples == other.mySamples
70  && myColorFormats == other.myColorFormats
73  }
74 
75  bool operator!=(const RV_RenderPassFormatInfo& other) const
76  {
77  return !(*this == other);
78  }
79 };
80 
82 {
83 public:
84  static UT_UniquePtr<RV_Framebuffer> create(
85  RV_Instance* inst,
86  int w,
87  int h,
88  int samples = 1,
89  const UT_StringRef &name = UT_StringRef());
90 
92  int w,
93  int h,
94  int samples = 1,
95  const UT_StringRef& name = UT_StringRef());
96  virtual ~RV_Framebuffer();
97 
98  virtual bool beginRendering(
99  RV_Instance *inst,
100  RV_VKCommandBuffer *cb,
101  RV_ImageOp img_op = RV_IMAGE_LOAD,
103 
104  virtual void endRendering(
105  RV_Instance *inst,
106  RV_VKCommandBuffer *cb) = 0;
107 
108  virtual bool fillPipelineInfo(RV_RenderPassFormatInfo& info) = 0;
109 
110  UT_DimRect getRenderRegion() const;
111 
112  int getMaxLayers() const;
113 
114  // Update Framebuffer format state
115  void setSize(int w, int h)
116  {
117  UT_ASSERT(w > 0 && h > 0);
118  myWidth = w; myHeight = h;
119  }
120  int getWidth() { return myWidth;}
121  int getHeight() { return myHeight;}
122 
123  void setSampleCount(int samples);
124  int getSampleCount() { return mySamples; }
125 
126  void setClearColor(UT_Vector4F c) { myClearColor = c; }
127  UT_Vector4F getClearColor() const { return myClearColor; }
128 
129  void setClearInt(UT_Vector4i i) { myClearInt = i; }
130  UT_Vector4i getClearInt() const { return myClearInt; }
131 
132  void setClearDepth(fpreal32 d) { myClearDepth = d; }
133  fpreal32 getClearDepth() const { return myClearDepth; }
134 
135  void getColorImages(UT_Array<const RV_VKImage*> &out_list);
136  int getNumColorImages() const;
137  RV_VKImage* getColorImage(int i=0);
138  RV_VKImage* getDepthImage();
139 
140  void setMultiview(bool enable) { myIsMultiview = enable; }
141  bool getMultiview() const { return myIsMultiview;}
142 
143  void setReadOnlyDepth(bool enable) { myIsReadOnlyDepth = enable; }
144  bool getReadOnlyDepth() const { return myIsReadOnlyDepth; }
145 
146  static const int ALL_LAYERS = -1;
147 
148  // Update Target info
149  bool attachImage(RV_Render* r,
150  RV_VKImage* img,
151  RV_AttachmentType buffer_type,
152  int buffer_target = 0,
153  int level = 0,
154  int layer = 0);
155 
156  RV_VKImagePtr createImage(RV_Render* r,
157  RV_GPUType type, int vec_size,
158  RV_AttachmentType attach_type,
159  int buffer_target = 0);
160 
161  void detachColorImage(RV_Render *r, int buffer_target = 0);
162  void detachDepthImage(RV_Render *r);
163 
164  const UT_StringHolder &name() const { return myName; }
165 
166  void writeToFiles(RV_Render *r,
167  const UT_StringHolder &base_name,
168  const UT_StringHolder &ext,
169  bool depth_too = false);
170 
171 protected:
172 
173  bool fillPipelineAttachments(RV_RenderPassFormatInfo& out_info);
175  { return myColorAttachments; }
177  { return myDepthAttachment; }
178 
179  virtual void attachmentsChanged();
180 
181  // typed to match VK structs
182  uint32_t myWidth = 0;
183  uint32_t myHeight = 0;
184 
185  uint32_t mySamples = 1;
186 
187  UT_Vector4F myClearColor = UT_Vector4F(0.f, 0.f, 0.f, 0.f);
188  UT_Vector4i myClearInt = UT_Vector4i(0, 0, 0, 0);
189  fpreal32 myClearDepth = 1.f;
190 
191  int myDrawMask = 0;
192  bool myIsMultiview = false;
193  bool myIsReadOnlyDepth = false;
194 
198 };
199 
201 {
202 public:
204  int w,
205  int h,
206  int samples = 1,
207  const UT_StringRef& name = UT_StringRef());
208  ~RV_DynamicFramebuffer() override;
209 
211 
212  bool fillPipelineInfo(RV_RenderPassFormatInfo& info) override;
213 
214  // Act on framebuffer
215  bool beginRendering(
216  RV_Instance *inst,
217  RV_VKCommandBuffer *cb,
218  RV_ImageOp img_op = RV_IMAGE_LOAD,
220 
221  void endRendering(
222  RV_Instance *inst,
223  RV_VKCommandBuffer *cb) override;
224 };
225 
227 {
228 public:
230  int w,
231  int h,
232  int samples = 1,
233  const UT_StringRef& name = UT_StringRef());
234  ~RV_RenderPassFramebuffer() override;
235 
236  bool fillPipelineInfo(RV_RenderPassFormatInfo& info) override;
237 
238  bool beginRendering(
239  RV_Instance *inst,
240  RV_VKCommandBuffer *cb,
241  RV_ImageOp img_op = RV_IMAGE_LOAD,
243 
244  void endRendering(
245  RV_Instance *inst,
246  RV_VKCommandBuffer *cb) override;
247 private:
248  void attachmentsChanged() override;
249 
250  bool myIsDirty = false;
251 
252  RV_ImageOp myLastLoadOp = RV_IMAGE_LOAD;
253  RV_RenderPassFormatInfo myLastFormat;
254  bool myLastMultiview = false;
255 
256  UT_UniquePtr<RV_VKRenderPass> myRenderPass;
257  UT_UniquePtr<RV_VKFramebuffer> myFramebuffer;
258 };
259 
261 {
262 public:
263  VkFramebuffer getVkFramebuffer() const { return myVkFramebuffer; }
264 
265  RV_VKFramebuffer(RV_Instance* inst, VkFramebuffer vk_handle)
266  : myInst(inst), myVkFramebuffer(vk_handle)
267  {}
268 
270  : myInst(other.myInst), myVkFramebuffer(other.myVkFramebuffer)
271  {
272  other.myInst = nullptr;
273  other.myVkFramebuffer = 0;
274  }
275 
276  // Disable move operator (since it would leave `rhs`) in null state
277  RV_VKFramebuffer& operator=(RV_VKFramebuffer&& rhs) noexcept = delete;
278 
279  void destroy()
280  {
281  UT_ASSERT(myInst || !myVkFramebuffer);
282  if (myInst && myInst->getDevice())
283  {
285  myInst->getDevice(), myVkFramebuffer, nullptr);
286  }
287  }
288 
289  virtual ~RV_VKFramebuffer() { destroy(); }
290 private:
291  RV_Instance* myInst = nullptr;
292  VkFramebuffer myVkFramebuffer = 0;
293 };
294 
296 {
297 public:
298  VkRenderPass getVkRenderPass() const { return myVkRenderPass; }
299 
301  RV_Instance* inst,
302  const RV_RenderPassFormatInfo& pass_info,
303  RV_ImageOp load_op);
304 
305  RV_VKRenderPass(RV_Instance* inst, VkRenderPass vk_handle)
306  : myInst(inst), myVkRenderPass(vk_handle)
307  {}
308 
310  : myInst(other.myInst), myVkRenderPass(other.myVkRenderPass)
311  {
312  other.myInst = nullptr;
313  other.myVkRenderPass = 0;
314  }
315 
316  // Disable move operator (since it would leave `rhs`) in null state
317  RV_VKRenderPass& operator=(RV_VKRenderPass&& rhs) noexcept = delete;
318 
319  void destroy()
320  {
321  UT_ASSERT(myInst || !myVkRenderPass);
322  if (myInst && myInst->getDevice())
323  {
325  myInst->getDevice(), myVkRenderPass, nullptr);
326  }
327  }
328 
329  virtual ~RV_VKRenderPass() { destroy(); }
330 private:
331  RV_Instance* myInst = nullptr;
332  VkRenderPass myVkRenderPass = 0;
333 };
334 
335 #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:469
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:461
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
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:44
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:156
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:476
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:300
UT_UniquePtr< rv_VKAttachment > rv_VKAttachmentPtr