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  RV_VKImage* getDepthImage();
137 
138  void setMultiview(bool enable) { myIsMultiview = enable; }
139  bool getMultiview() const { return myIsMultiview;}
140 
141  void setReadOnlyDepth(bool enable) { myIsReadOnlyDepth = enable; }
142  bool getReadOnlyDepth() const { return myIsReadOnlyDepth; }
143 
144  static const int ALL_LAYERS = -1;
145 
146  // Update Target info
147  bool attachImage(RV_Render* r,
148  RV_VKImage* img,
149  RV_AttachmentType buffer_type,
150  int buffer_target = 0,
151  int level = 0,
152  int layer = 0);
153 
154  RV_VKImagePtr createImage(RV_Render* r,
155  RV_GPUType type, int vec_size,
156  RV_AttachmentType attach_type,
157  int buffer_target = 0);
158 
159  void detachColorImage(RV_Render *r, int buffer_target = 0);
160  void detachDepthImage(RV_Render *r);
161 
162  const UT_StringHolder &name() const { return myName; }
163 
164 protected:
165 
166  bool fillPipelineAttachments(RV_RenderPassFormatInfo& out_info);
168  { return myColorAttachments; }
170  { return myDepthAttachment; }
171 
172  virtual void attachmentsChanged();
173 
174  // typed to match VK structs
175  uint32_t myWidth = 0;
176  uint32_t myHeight = 0;
177 
178  uint32_t mySamples = 1;
179 
180  UT_Vector4F myClearColor = UT_Vector4F(0.f, 0.f, 0.f, 0.f);
181  UT_Vector4i myClearInt = UT_Vector4i(0, 0, 0, 0);
182  fpreal32 myClearDepth = 1.f;
183 
184  int myDrawMask = 0;
185  bool myIsMultiview = false;
186  bool myIsReadOnlyDepth = false;
187 
191 };
192 
194 {
195 public:
197  int w,
198  int h,
199  int samples = 1,
200  const UT_StringRef& name = UT_StringRef());
201  ~RV_DynamicFramebuffer() override;
202 
204 
205  bool fillPipelineInfo(RV_RenderPassFormatInfo& info) override;
206 
207  // Act on framebuffer
208  bool beginRendering(
209  RV_Instance *inst,
210  RV_VKCommandBuffer *cb,
211  RV_ImageOp img_op = RV_IMAGE_LOAD,
213 
214  void endRendering(
215  RV_Instance *inst,
216  RV_VKCommandBuffer *cb) override;
217 };
218 
220 {
221 public:
223  int w,
224  int h,
225  int samples = 1,
226  const UT_StringRef& name = UT_StringRef());
227  ~RV_RenderPassFramebuffer() override;
228 
229  bool fillPipelineInfo(RV_RenderPassFormatInfo& info) override;
230 
231  bool beginRendering(
232  RV_Instance *inst,
233  RV_VKCommandBuffer *cb,
234  RV_ImageOp img_op = RV_IMAGE_LOAD,
236 
237  void endRendering(
238  RV_Instance *inst,
239  RV_VKCommandBuffer *cb) override;
240 private:
241  void attachmentsChanged() override;
242 
243  bool myIsDirty = false;
244 
245  RV_ImageOp myLastLoadOp = RV_IMAGE_LOAD;
246  RV_RenderPassFormatInfo myLastFormat;
247  bool myLastMultiview = false;
248 
249  UT_UniquePtr<RV_VKRenderPass> myRenderPass;
250  UT_UniquePtr<RV_VKFramebuffer> myFramebuffer;
251 };
252 
254 {
255 public:
256  VkFramebuffer getVkFramebuffer() const { return myVkFramebuffer; }
257 
258  RV_VKFramebuffer(RV_Instance* inst, VkFramebuffer vk_handle)
259  : myInst(inst), myVkFramebuffer(vk_handle)
260  {}
261 
263  : myInst(other.myInst), myVkFramebuffer(other.myVkFramebuffer)
264  {
265  other.myInst = nullptr;
266  other.myVkFramebuffer = 0;
267  }
268 
269  // Disable move operator (since it would leave `rhs`) in null state
270  RV_VKFramebuffer& operator=(RV_VKFramebuffer&& rhs) noexcept = delete;
271 
272  void destroy()
273  {
274  UT_ASSERT(myInst || !myVkFramebuffer);
275  if (myInst && myInst->getDevice())
276  {
278  myInst->getDevice(), myVkFramebuffer, nullptr);
279  }
280  }
281 
282  virtual ~RV_VKFramebuffer() { destroy(); }
283 private:
284  RV_Instance* myInst = nullptr;
285  VkFramebuffer myVkFramebuffer = 0;
286 };
287 
289 {
290 public:
291  VkRenderPass getVkRenderPass() const { return myVkRenderPass; }
292 
294  RV_Instance* inst,
295  const RV_RenderPassFormatInfo& pass_info,
296  RV_ImageOp load_op);
297 
298  RV_VKRenderPass(RV_Instance* inst, VkRenderPass vk_handle)
299  : myInst(inst), myVkRenderPass(vk_handle)
300  {}
301 
303  : myInst(other.myInst), myVkRenderPass(other.myVkRenderPass)
304  {
305  other.myInst = nullptr;
306  other.myVkRenderPass = 0;
307  }
308 
309  // Disable move operator (since it would leave `rhs`) in null state
310  RV_VKRenderPass& operator=(RV_VKRenderPass&& rhs) noexcept = delete;
311 
312  void destroy()
313  {
314  UT_ASSERT(myInst || !myVkRenderPass);
315  if (myInst && myInst->getDevice())
316  {
318  myInst->getDevice(), myVkRenderPass, nullptr);
319  }
320  }
321 
322  virtual ~RV_VKRenderPass() { destroy(); }
323 private:
324  RV_Instance* myInst = nullptr;
325  VkRenderPass myVkRenderPass = 0;
326 };
327 
328 #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:412
GLint level
Definition: glcorearb.h:108
virtual ~RV_VKFramebuffer()
UT_UniquePtr< RV_VKImage > RV_VKImagePtr
Definition: RV_TypePtrs.h:51
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:404
UT_Vector4T< int32 > UT_Vector4i
GLfloat f
Definition: glcorearb.h:1926
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:38
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:37
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:419
RV_VKRenderPass(RV_VKRenderPass &&other)
UT_Vector4F getClearColor() const
type
Definition: core.h:1059
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:295
UT_UniquePtr< rv_VKAttachment > rv_VKAttachmentPtr