#include <dali/graphics/vulkan/vulkan-shader.h>
#include <dali/graphics/vulkan/vulkan-descriptor-set.h>
#include <dali/graphics/vulkan/vulkan-framebuffer.h>
-#include <dali/graphics/vulkan/vulkan-graphics-controller.h>
+#include <dali/graphics/vulkan/api/vulkan-api-controller.h>
+#include <dali/graphics/vulkan/vulkan-pipeline-cache.h>
#include <dali/graphics-api/graphics-api-controller.h>
#define VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface"
#endif
-#include <iostream>
-
namespace Dali
{
namespace Graphics
const auto VALIDATION_LAYERS = std::vector< const char* >{
//"VK_LAYER_LUNARG_screenshot", // screenshot
- "VK_LAYER_RENDERDOC_Capture",
- "VK_LAYER_LUNARG_parameter_validation", // parameter
+ //"VK_LAYER_RENDERDOC_Capture",
+ //"VK_LAYER_LUNARG_parameter_validation", // parameter
//"VK_LAYER_LUNARG_vktrace", // vktrace ( requires vktrace connection )
- "VK_LAYER_LUNARG_monitor", // monitor
+ //"VK_LAYER_LUNARG_monitor", // monitor
"VK_LAYER_LUNARG_swapchain", // swapchain
"VK_LAYER_GOOGLE_threading", // threading
"VK_LAYER_LUNARG_api_dump", // api
"VK_LAYER_LUNARG_object_tracker", // objects
"VK_LAYER_LUNARG_core_validation", // core
"VK_LAYER_GOOGLE_unique_objects", // unique objects
+ "VK_LAYER_GOOGLE_unique_objects", // unique objects
"VK_LAYER_LUNARG_standard_validation", // standard
};
Graphics::Graphics() = default;
-
Graphics::~Graphics() = default;
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wframe-larger-than="
Platform Graphics::GetDefaultPlatform() const
{
{
if(!mGfxController)
{
- mGfxController = Dali::Graphics::Vulkan::Controller::New(*this);
+ mGfxController = Dali::Graphics::VulkanAPI::Controller::New(*this);
}
- return *mGfxController.get();
+ return *mGfxController;
}
std::vector<const char*> Graphics::PrepareDefaultInstanceExtensions()
mDeviceMemoryManager = GpuMemoryManager::New( *this );
}
-#pragma GCC diagnostic pop
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wframe-larger-than="
void Graphics::GetPhysicalDeviceProperties()
{
// store data on heap to keep object smaller
mPhysicalDeviceFeatures =
MakeUnique<vk::PhysicalDeviceFeatures>(mPhysicalDevice.getFeatures());
}
-#pragma GCC diagnostic pop
void Graphics::GetQueueFamilyProperties()
{
- mQueueFamilyProperties = std::move(mPhysicalDevice.getQueueFamilyProperties());
+ mQueueFamilyProperties = mPhysicalDevice.getQueueFamilyProperties();
}
FBID Graphics::CreateSurface(std::unique_ptr< SurfaceFactory > surfaceFactory)
{
- const auto vkFactory = dynamic_cast< const VkSurfaceFactory* >(surfaceFactory.get());
- if(!vkFactory)
+ // create surface from the factory
+ auto surfaceRef = Surface::New( *this, std::move(surfaceFactory) );
+
+ if( surfaceRef->Create() )
{
- return FBID{0u};
+
+ // map surface to FBID
+ auto fbid = ++mBaseFBID;
+ mSurfaceFBIDMap[fbid] = SwapchainSurfacePair{ SwapchainRef{}, surfaceRef };
+ return fbid;
}
+ return -1;
+}
- auto surface = vkFactory->Create(mInstance, mAllocator.get(), mPhysicalDevice);
+SwapchainRef Graphics::CreateSwapchainForSurface( SurfaceRef surface )
+{
+ auto swapchain = Swapchain::New( *this,
+ GetGraphicsQueue(0u),
+ surface, 4, 0 );
- // map surface to FBID
- auto fbid = ++mBaseFBID;
- mSurfaceFBIDMap[fbid] = MakeUnique<Surface>(*this, surface, 3u);
- return fbid;
+ // store swapchain in the correct pair
+ for( auto&& val : mSurfaceFBIDMap )
+ {
+ if( val.second.surface == surface )
+ {
+ val.second.swapchain = swapchain;
+ break;
+ }
+ }
+
+ return swapchain;
+}
+
+SwapchainRef Graphics::GetSwapchainForSurface( SurfaceRef surface )
+{
+ for( auto&& val : mSurfaceFBIDMap )
+ {
+ if( val.second.surface == surface )
+ {
+ return val.second
+ .swapchain;
+ }
+ }
+ return SwapchainRef();
+}
+
+SwapchainRef Graphics::GetSwapchainForFBID( FBID surfaceId )
+{
+ if(surfaceId == 0)
+ {
+ return mSurfaceFBIDMap.begin()->second.swapchain;
+ }
+ return mSurfaceFBIDMap[surfaceId].swapchain;
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wframe-larger-than="
std::vector< vk::DeviceQueueCreateInfo > Graphics::GetQueueCreateInfos()
{
// surface is needed in order to find a family that supports presentation to this surface
{
transferFamily = queueFamilyIndex;
}
- if(mPhysicalDevice.getSurfaceSupportKHR(queueFamilyIndex, mSurfaceFBIDMap.begin()->second.get()->GetSurfaceKHR())
+ if(mPhysicalDevice.getSurfaceSupportKHR(queueFamilyIndex, mSurfaceFBIDMap.begin()->second.surface->GetSurfaceKHR())
.value &&
presentFamily == -1u)
{
return queueInfos;
}
-#pragma GCC diagnostic pop
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wframe-larger-than="
void Graphics::CreateDevice()
{
auto queueInfos = GetQueueCreateInfos();
// todo: present queue
}
}
+
+ mPipelineDatabase = std::make_unique<PipelineCache>( *this );
}
-#pragma GCC diagnostic pop
vk::Device Graphics::GetDevice() const
{
Queue& Graphics::GetPresentQueue() const
{
- return *mPresentQueue.get();
+ // fixme: should be a dedicated presentation queue
+ return GetGraphicsQueue(0);
}
Handle< CommandPool > Graphics::CreateCommandPool(const vk::CommandPoolCreateInfo& info)
return cmdpool;
}
-Surface& Graphics::GetSurface( FBID surfaceId )
+SurfaceRef Graphics::GetSurface( FBID surfaceId )
{
// TODO: FBID == 0 means default framebuffer, but there should be no
// such thing as default framebuffer.
if( surfaceId == 0 )
{
- return *mSurfaceFBIDMap.begin()->second.get();
+ return mSurfaceFBIDMap.begin()->second.surface;
}
- return *mSurfaceFBIDMap[surfaceId].get();
+ return mSurfaceFBIDMap[surfaceId].surface;
}
// TODO: all this stuff should go into some vulkan cache
NotImplemented();
}
-Handle<Shader> Graphics::FindShader( vk::ShaderModule shaderModule )
+ShaderRef Graphics::FindShader( vk::ShaderModule shaderModule )
{
for( auto&& iter : mShaderCache )
{
return Handle<Shader>();
}
+ImageRef Graphics::FindImage( vk::Image image )
+{
+ for( auto&& iter : mImageCache )
+ {
+ if( iter->GetVkImage() == image )
+ {
+ return ImageRef(&*iter);
+ }
+ }
+ return ImageRef();
+}
+
+
} // namespace Vulkan
} // namespace Graphics