Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
RenderPass.cpp
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 #include <cassert>
10 
11 #include "talvos/Image.h"
12 #include "talvos/RenderPass.h"
13 
14 namespace talvos
15 {
16 
17 const VkAttachmentDescription &RenderPass::getAttachment(uint32_t Index) const
18 {
19  assert(Index < Attachments.size());
20  return Attachments[Index];
21 }
22 
23 const Subpass &RenderPass::getSubpass(uint32_t Index) const
24 {
25  assert(Index < Subpasses.size());
26  return Subpasses[Index];
27 }
28 
30 {
31  // TODO: Mutex instead?
32  assert(!Rendering && "render pass overlapping not allowed");
33 
34  Rendering = true;
35 
37 
38  SubpassIndex = 0;
39  beginSubpass();
40 }
41 
43 {
44  // TODO: Handle stencil/preserve/resolve attachments too
45 
47 
48  // Loop over color attachments in the subpass, clearing them as necessary.
49  for (uint32_t AttachIndex = 0; AttachIndex < Subpass.ColorAttachments.size();
50  AttachIndex++)
51  {
52  uint32_t AttachRef = Subpass.ColorAttachments[AttachIndex];
53 
54  // Skip unused attachments and those that have been previously initialized.
55  if (AttachRef == VK_ATTACHMENT_UNUSED)
56  continue;
57  if (AttachmentsInitialized[AttachRef])
58  continue;
59 
60  const VkAttachmentDescription &AttachDesc = RP.getAttachment(AttachRef);
61  AttachmentsInitialized[AttachRef] = true;
62 
63  // Skip attachments if not clearing them.
64  if (AttachDesc.loadOp != VK_ATTACHMENT_LOAD_OP_CLEAR)
65  continue;
66 
67  // Generate integer clear value.
68  assert(AttachRef < ClearValues.size());
69 
70  // Store clear value to each pixel in attachment.
71  VkClearColorValue Color = ClearValues[AttachRef].color;
72  const ImageView *Attach = FB.getAttachments()[AttachRef];
73  for (uint32_t Layer = 0; Layer < FB.getNumLayers(); Layer++)
74  {
75  for (uint32_t Y = 0; Y < FB.getHeight(); Y++)
76  {
77  for (uint32_t X = 0; X < FB.getWidth(); X++)
78  {
79  Attach->write(Color, X, Y, 0, Layer);
80  }
81  }
82  }
83  }
84 }
85 
87 {
88  assert(Rendering);
89 
90  endSubpass();
91  Rendering = false;
92 }
93 
95 {
96  // TODO: Perform multisample resolve operations if necessary
97 }
98 
100 {
101  assert(Rendering);
102 
103  endSubpass();
104  ++SubpassIndex;
105  beginSubpass();
106 }
107 
108 } // namespace talvos
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
void write(const Image::Texel &T, uint32_t X, uint32_t Y=0, uint32_t Z=0, uint32_t Layer=0, uint32_t MipLevel=0) const
Write a texel to the image view at the specified coordinate.
Definition: Image.cpp:511
const Framebuffer & FB
The framebuffer associated with this render pass instance.
Definition: RenderPass.h:126
This structure describes the attachments used by a subpass.
Definition: RenderPass.h:59
void beginSubpass()
Helper used to update render pass state when a new subpass is started.
Definition: RenderPass.cpp:42
void endSubpass()
Helper used to update render pass state when a subpass completes.
Definition: RenderPass.cpp:94
uint32_t getHeight() const
Returns the height of this framebuffer in pixels.
Definition: RenderPass.h:38
This class represents a view into a range of image subresources.
Definition: Image.h:178
const RenderPass & RP
The render pass that this object instantiates.
Definition: RenderPass.h:123
uint32_t getWidth() const
Returns the width of this framebuffer in pixels.
Definition: RenderPass.h:44
This file declares data structures and functions for handling images.
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
This file declares the RenderPass class and related data structures.
void begin()
Initialize the render pass state in preparation for draw commands.
Definition: RenderPass.cpp:29
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
std::vector< bool > AttachmentsInitialized
Flags denoting whether each attachment has been initialized yet.
Definition: RenderPass.h:138
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< 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