Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
RenderPass.h
Go to the documentation of this file.
1 // Copyright (c) 2018 the Talvos developers. All rights reserved.
2 //
3 // This file is distributed under a three-clause BSD license. For full license
4 // terms please see the LICENSE file distributed with this source code.
5 
8 
9 #ifndef TALVOS_RENDERPASS_H
10 #define TALVOS_RENDERPASS_H
11 
12 #include <vector>
13 
14 #include "vulkan/vulkan_core.h"
15 
16 namespace talvos
17 {
18 class Device;
19 class ImageView;
20 
23 {
24 public:
26  Framebuffer(Device &Dev, uint32_t Width, uint32_t Height, uint32_t NumLayers,
27  const std::vector<ImageView *> &Attachments)
28  : Dev(Dev), Width(Width), Height(Height), NumLayers(NumLayers),
29  Attachments(Attachments){};
30 
32  const std::vector<ImageView *> &getAttachments() const { return Attachments; }
33 
35  Device &getDevice() const { return Dev; }
36 
38  uint32_t getHeight() const { return Height; }
39 
41  uint32_t getNumLayers() const { return NumLayers; }
42 
44  uint32_t getWidth() const { return Width; }
45 
46 private:
48 
49  uint32_t Width;
50  uint32_t Height;
51 
52  uint32_t NumLayers;
53 
55  std::vector<ImageView *> Attachments;
56 };
57 
59 struct Subpass
60 {
61  std::vector<uint32_t> InputAttachments;
62  std::vector<uint32_t> ColorAttachments;
63  std::vector<uint32_t> ResolveAttachments;
64  std::vector<uint32_t> PreserveAttachments;
66 };
67 
70 {
71 public:
73  RenderPass(const std::vector<VkAttachmentDescription> &Attachments,
74  std::vector<Subpass> Subpasses)
75  : Attachments(Attachments), Subpasses(Subpasses){};
76 
78  const VkAttachmentDescription &getAttachment(uint32_t Index) const;
79 
81  uint32_t getNumAttachments() const { return (uint32_t)Attachments.size(); }
82 
84  const Subpass &getSubpass(uint32_t Index) const;
85 
86 private:
88  std::vector<VkAttachmentDescription> Attachments;
89 
91  const std::vector<Subpass> Subpasses;
92 };
93 
96 {
97 public:
100  const std::vector<VkClearValue> &ClearValues)
101  : RP(RP), FB(FB), ClearValues(ClearValues), Rendering(false){};
102 
104  void begin();
105 
107  void end();
108 
110  const Framebuffer &getFramebuffer() const { return FB; }
111 
113  const RenderPass &getRenderPass() const { return RP; }
114 
116  uint32_t getSubpassIndex() const { return SubpassIndex; }
117 
119  void nextSubpass();
120 
121 private:
123  const RenderPass &RP;
124 
126  const Framebuffer &FB;
127 
129  std::vector<VkClearValue> ClearValues;
130 
132  bool Rendering;
133 
135  uint32_t SubpassIndex;
136 
138  std::vector<bool> AttachmentsInitialized;
139 
141  void beginSubpass();
142 
144  void endSubpass();
145 };
146 
147 }; // namespace talvos
148 
149 #endif
uint32_t getSubpassIndex() const
Returns the index of the current subpass.
Definition: RenderPass.h:116
const Subpass & getSubpass(uint32_t Index) const
Returns the subpass at index Index.
Definition: RenderPass.cpp:23
bool Rendering
Flag used to indicate whether the instance is currently rendering.
Definition: RenderPass.h:132
const Framebuffer & FB
The framebuffer associated with this render pass instance.
Definition: RenderPass.h:126
uint32_t DepthStencilAttachment
Definition: RenderPass.h:65
This structure describes the attachments used by a subpass.
Definition: RenderPass.h:59
Device & getDevice() const
Returns the device that this framebuffer is associated with.
Definition: RenderPass.h:35
RenderPass(const std::vector< VkAttachmentDescription > &Attachments, std::vector< Subpass > Subpasses)
Create a render pass from sets of attachment and subpass descriptions.
Definition: RenderPass.h:73
void beginSubpass()
Helper used to update render pass state when a new subpass is started.
Definition: RenderPass.cpp:42
std::vector< uint32_t > ResolveAttachments
Definition: RenderPass.h:63
void endSubpass()
Helper used to update render pass state when a subpass completes.
Definition: RenderPass.cpp:94
Framebuffer(Device &Dev, uint32_t Width, uint32_t Height, uint32_t NumLayers, const std::vector< ImageView * > &Attachments)
Create a framebuffer.
Definition: RenderPass.h:26
uint32_t getHeight() const
Returns the height of this framebuffer in pixels.
Definition: RenderPass.h:38
const Framebuffer & getFramebuffer() const
Returns the framebuffer associated with this render pass instance.
Definition: RenderPass.h:110
This class represents an instance of a render pass being used for drawing.
Definition: RenderPass.h:95
std::vector< uint32_t > InputAttachments
Definition: RenderPass.h:61
const RenderPass & RP
The render pass that this object instantiates.
Definition: RenderPass.h:123
This class represents a framebuffer that can be used for rendering.
Definition: RenderPass.h:22
uint32_t getWidth() const
Returns the width of this framebuffer in pixels.
Definition: RenderPass.h:44
uint32_t NumLayers
The numbers of layers in the framebuffer.
Definition: RenderPass.h:52
This class represents a Vulkan render pass.
Definition: RenderPass.h:69
A Device instance encapsulates properties and state for the virtual device.
Definition: Device.h:29
void end()
Finalize the render pass state after completing all draw commands.
Definition: RenderPass.cpp:86
const std::vector< ImageView * > & getAttachments() const
Returns the list of attachments backing this framebuffer.
Definition: RenderPass.h:32
std::vector< ImageView * > Attachments
The framebuffer attachments.
Definition: RenderPass.h:55
const RenderPass & getRenderPass() const
Returns the render pass.
Definition: RenderPass.h:113
void begin()
Initialize the render pass state in preparation for draw commands.
Definition: RenderPass.cpp:29
RenderPassInstance(const RenderPass &RP, const Framebuffer &FB, const std::vector< VkClearValue > &ClearValues)
Create a render pass instance from a render pass and a framebuffer.
Definition: RenderPass.h:99
std::vector< uint32_t > ColorAttachments
Definition: RenderPass.h:62
std::vector< VkClearValue > ClearValues
The clear values used for this render pass instance.
Definition: RenderPass.h:129
uint32_t getNumLayers() const
Returns the number of layers in this framebuffer.
Definition: RenderPass.h:41
void nextSubpass()
Transition to the next subpass.
Definition: RenderPass.cpp:99
Device & Dev
The device this framebuffer belongs to.
Definition: RenderPass.h:47
std::vector< bool > AttachmentsInitialized
Flags denoting whether each attachment has been initialized yet.
Definition: RenderPass.h:138
uint32_t Height
The height of the framebuffer in pixels.
Definition: RenderPass.h:50
const std::vector< Subpass > Subpasses
The subpasses contained in this render pass.
Definition: RenderPass.h:91
uint32_t getNumAttachments() const
Returns the number of attachments in this render pass.
Definition: RenderPass.h:81
std::vector< uint32_t > PreserveAttachments
Definition: RenderPass.h:64
std::vector< VkAttachmentDescription > Attachments
The attachments used by this render pass.
Definition: RenderPass.h:88
const VkAttachmentDescription & getAttachment(uint32_t Index) const
Returns the attachment at index Index.
Definition: RenderPass.cpp:17
uint32_t SubpassIndex
The index of the current subpass.
Definition: RenderPass.h:135
uint32_t Width
The width of the framebuffer in pixels.
Definition: RenderPass.h:49