[Vulkan] Basic Vulkan backend
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / vulkan-framebuffer.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali/graphics/vulkan/vulkan-framebuffer.h>
19 #include <dali/graphics/vulkan/vulkan-graphics.h>
20 #include <dali/graphics/vulkan/vulkan-image.h>
21
22 namespace Dali
23 {
24 namespace Graphics
25 {
26 namespace Vulkan
27 {
28
29 struct Framebuffer::Impl
30 {
31   Impl( Framebuffer& owner, Graphics& graphics, uint32_t width, uint32_t height ) :
32     mInterface( owner ),
33     mGraphics( graphics )
34   {
35
36   }
37
38   // Framebuffer creation may be deferred
39   bool Initialise()
40   {
41     if(mInitialised)
42     {
43       return true;
44     }
45
46     if(!Validate())
47     {
48       return false;
49     }
50
51     /*
52     auto attRef = vk::AttachmentReference{};
53     attRef.setLayout();
54     attRef.setAttachment();
55
56     // creating single subpass per framebuffer
57     auto subpassDesc = vk::SubpassDescription{};
58     subpassDesc.setPipelineBindPoint( vk::PipelineBindPoint::eGraphics );
59     subpassDesc.setColorAttachmentCount(0);
60     subpassDesc.setInputAttachmentCount(0);
61     subpassDesc.setPDepthStencilAttachment(nullptr);
62     subpassDesc.setPColorAttachments( nullptr );
63     subpassDesc.setPInputAttachments( nullptr );
64     subpassDesc.setPPreserveAttachments( nullptr );
65     subpassDesc.setPResolveAttachments( nullptr );
66
67
68     auto rpInfo = vk::RenderPassCreateInfo{};
69     rpInfo.setAttachmentCount( mAttachments.size() );
70     //rpInfo.setPAttachments( )
71     rpInfo.setDependencyCount( 0 );
72     rpInfo.setPDependencies( nullptr );
73     rpInfo.setPSubpasses( &subpassDesc );
74     rpInfo.setSubpassCount( 1 );
75
76     auto fbInfo = vk::FramebufferCreateInfo{};
77     fbInfo.setWidth( mWidth );
78     fbInfo.setHeight( mHeight );
79     //fbInfo.setRenderPass( )
80     //fbInfo.setAttachmentCount( 0 );
81     //fbInfo.setPAttachments( ImageViews );
82     */
83     mInitialised = true;
84   }
85
86
87   void SetAttachment( Handle<Image> image, Framebuffer::AttachmentType type, uint32_t index )
88   {
89     std::vector<Handle<Image>>& attachments =
90       type == AttachmentType::COLOR ? mColorAttachments : mDepthStencilAttachments;
91
92     if( attachments.size() <= index )
93     {
94       attachments.resize( index+1 );
95     }
96     attachments[index] = image;
97   }
98
99   ImageRef GetAttachmentImage( AttachmentType type, uint32_t index ) const
100   {
101     return ImageRef();
102   }
103
104   ImageViewRef GetAttachmentImageView( AttachmentType type, uint32_t index ) const
105   {
106     return ImageViewRef();
107   }
108
109   bool Validate()
110   {
111     if( mWidth == 0u || mHeight == 0  )
112     {
113       return false;
114     }
115   }
116
117   ~Impl()
118   {
119
120   }
121
122   vk::RenderPass GetVkRenderPass() const
123   {
124     return mVkRenderPass;
125   }
126
127   vk::Framebuffer GetVkFramebuffer() const
128   {
129     return mVkFramebuffer;
130   }
131
132   Framebuffer&            mInterface;
133   Graphics&               mGraphics;
134
135   uint32_t mWidth;
136   uint32_t mHeight;
137   std::vector<Handle<Image>>      mColorAttachments;
138   std::vector<Handle<Image>>      mDepthStencilAttachments;
139
140   std::vector<ImageView>  mImageViewAttachments;
141   vk::Framebuffer         mVkFramebuffer;
142   vk::RenderPass          mVkRenderPass;
143
144   bool mInitialised { false };
145 };
146
147
148 Handle<Framebuffer> Framebuffer::New( Graphics& graphics, uint32_t width, uint32_t height )
149 {
150   return FramebufferRef();
151 }
152
153 void Framebuffer::SetAttachment( Handle<Image> image, Framebuffer::AttachmentType type, uint32_t index )
154 {
155   mImpl->SetAttachment( image, type, index );
156 }
157
158 uint32_t Framebuffer::GetWidth() const
159 {
160   return mImpl->mWidth;
161 }
162
163 uint32_t Framebuffer::GetHeight() const
164 {
165   return mImpl->mHeight;
166 }
167
168 Handle<Image> Framebuffer::GetAttachmentImage( AttachmentType type, uint32_t index ) const
169 {
170   return mImpl->GetAttachmentImage( type, index );
171 }
172
173 Handle<ImageView> Framebuffer::GetAttachmentImageView( AttachmentType type, uint32_t index ) const
174 {
175   return mImpl->GetAttachmentImageView( type, index );
176 }
177
178 } // Namespace Vulkan
179
180 } // Namespace Graphics
181
182 } // Namespace Dali